akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector<double> vd;
typedef std::vector<std::string> vs;
typedef std::vector<pii> vpii;
typedef std::vector<vi> vvi;
typedef std::vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { rep(i,v.size()) is >> v[i]; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

typedef std::vector<Edge> Edges;
typedef std::vector<Weight> Array;
typedef std::vector<Array> Matrix;

class Graph {
  std::vector<Edges> g;

public:
  Graph(const int &size = 0) : g(size) {}
  int size() const { return g.size(); }
  const Edges &operator[](const int &i) const { return g[i]; }
  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
};

template<int inf = std::numeric_limits<Weight>::max() / 8> std::pair<std::vector<Weight>, std::vector<int>> dijkstra(const Graph &g, const int &src) {
  using state = std::pair<Weight, int>;
  std::priority_queue<state, std::vector<state>, std::greater<state>> q;
  std::vector<Weight> dist(g.size(), inf);
  std::vector<int> via(g.size());
  dist[src] = 0;
  q.emplace(0, src);
  while (q.size()) {
    Weight d;
    int v;
    std::tie(d, v) = q.top();
    q.pop();
    if (dist[v] < d) continue;
    for (auto &e : g[v]) {
      if (cmin(dist[e.dst], dist[v] + e.weight)) {
        via[e.dst] = v;
        q.emplace(dist[e.dst], e.dst);
      }
    }
  }
  return {dist, via};
}

main {
  int n;
  while (cin >> n, n) {
    Graph g(10);
    set<int> s;
    rep(i, n) {
      int a, b, c;
      cin >> a >> b >> c;
      s.insert(a), s.insert(b);
      g.addEdge(a, b, c);
    }
    vi v(s.size());
    copy(all(s), v.begin());
    Matrix dist(10, Array(10));
    rep(i, 10) {
      vector<Weight> d = dijkstra<INF>(g, i).first;
      rep(j, 10) dist[i][j] = d[j];
    }
    int ms = INF, mp;
    rep(i, 10) {
      int s = 0;
      for (int j : v) s += dist[i][j];
      if (cmin(ms, s)) mp = i;
    }
    cout << mp << ' ' << ms << endl;
  }
}

Measured memory_bytes: 3044
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 65;
const int MOD = 1e9 + 7;

LL N;

void input()
{
    read(N);
}

#define GE(x, g) (((x) > t) || (((x) == t) && (g)))

void solve()
{
    static int dp[MAXN][2][2][2];

    int n = log2(N) + 1;

    dp[0][0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
        int t = N >> i & 1;
        for (int j = 0; j < 2; ++j) {
            for (int ug = 0; ug < 2; ++ug) {
                for (int vg = 0; vg < 2; ++vg) {
                    if (!dp[i][j][ug][vg])
                        continue;
                    // u = 0, v = j
                    (dp[i + 1][0][GE(0, ug)][GE(j, vg)] += dp[i][j][ug][vg]) %= MOD;
                    (dp[i + 1][1][GE(0, ug)][GE(j, vg)] += dp[i][j][ug][vg]) %= MOD;
                    // u = 1, v = j^1
                    (dp[i + 1][j][GE(1, ug)][GE(j^1, vg)] += dp[i][j][ug][vg]) %= MOD;
                }
            }
        }
    }

    int ans = dp[n][0][0][0];
    printf("%d\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 唯有门前镜湖水，春风不改旧时波。
//     -- 贺知章《回乡偶书二首》


Measured memory_bytes: 512
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b, c;
  cin >> a >>b >> c;
  cout << min(c, b/a);
  return 0;
}


Measured memory_bytes: 256
import sys

while True:
	a, op, b = sys.stdin.readline().split( " " )
	if "?" == op:
		break
	a = int( a )
	b = int( b )
	if "+" == op:
		print( "{:d}".format( a+b ) )
	elif "-" == op:
		print( "{:d}".format( a-b ) )
	elif "*" == op:
		print( "{:d}".format( a*b ) )
	elif "/" == op:
		print( "{:d}".format( a//b ) )

Measured memory_bytes: 6724
#include <iostream>
#include <cmath>

using namespace std;

bool is_prime(int p) {
    if (p == 2) {
        return true;
    } else if (p % 2 == 0) {
        return false;
    }
    int limit = sqrt(p);
    for (int i=3; i<=limit; i+=2) {
        if (p % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    int ns[10000];

    cin>>n;
    for (int i=0; i<n; ++i) {
        cin>>ns[i];
    }

    int count = 0;
    for (int i=0; i<n; ++i) {
        if (is_prime(ns[i])) {
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}



Measured memory_bytes: 3128
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(){
	string S;
  	cin >> S;
  	ll dp[13];
	
  	reverse(S.begin(), S.end());
  	fill(dp, dp+13, 0);
  	dp[0] = 1;
  	int mul = 1;
  	for(int i = 0; i < S.size(); i++){
      	ll nextdp[13];
      	fill(nextdp, nextdp+13, 0);
    	if(S[i] != '?'){
        	int a = (S[i]-48)*mul;
          	for(int j = 0; j < 13; j++){
           		nextdp[(j+a)%13] += dp[j];
              	nextdp[(j+a)%13] %= MOD;
            }
        } else {
        	for(int k = 0; k < 10; k++){
            	int	b = k*mul;
              	for(int j = 0; j < 13; j++){
                	nextdp[(j+b)%13] += dp[j];
                 	nextdp[(j+b)%13] %= MOD;
                }
            }
        }
      	memcpy(dp, nextdp, sizeof(dp));
      	mul *= 10;
      	mul %= 13;
    }
  	cout << dp[5] << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int dice_1[] = new int[6];
		int dice_2[] = new int[6];
		int pip[] = new int[6];
		int count = 0;
		int order = 0;
		boolean bdice_front = false;
		int dice_front = 0;
		boolean bdice_up = false;
		int dice_up = 0;
		boolean judge = false;
		
		//サイコロの目の入力
		dice_1 =  make_dice(scanner);
		dice_2 =  make_dice(scanner);
		
		pip = dice_1;
		
		//命令数実行
		do {
			dice_up = dice_2[0];
			dice_front = dice_2[1];
			bdice_front = false;
			bdice_up = false;
			
			for( int i = 0; i < 4; i ++ ){
				for( int j = 0; j < 2; j ++ ){
					if(!bdice_front) {
						for( int k = 0; k < 4; k ++ ){
							if( !bdice_front ) {
								pip = diceroll_s(pip);
								if( pip[1] == dice_front ){
									bdice_front = true;
								}
							}
						}
						pip = diceroll_e(pip);
					}
				}
				if( pip[0] == dice_up ){
					bdice_up = true;
					break;
				}
				pip = diceroll_e(pip);
				
			}
			
			if( dice_2[2] == pip[2] ){
				if( dice_2[3] == pip[3] ){
					if( dice_2[4] == pip[4] ){
						if( dice_2[5] == pip[5] ){
							judge = true;
						}
					}
				}
			}
			//右面出力
			if( judge ){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
			
			count ++;
			if( count >= order){
				break;
			}
		}while(true );
		
		scanner.close();
	}
	
	public static int[] make_dice ( Scanner scanner){
		int dice[] = new int[6];
		
		for(int i = 0; i < 6; i ++){
			dice[i] = scanner.nextInt();
		}
		
		return dice;
	}

	public static int[] diceroll_n(int[] pip){
		int dice[] = new int[6];
		for(int i = 0; i < 6; i ++){
			dice[i] = pip[i];
		}
		pip[0] = dice[1];
		pip[1] = dice[5];
		pip[2] = dice[2];
		pip[3] = dice[3];
		pip[4] = dice[0];
		pip[5] = dice[4];
		
		return pip;
	}

	public static int[] diceroll_e (int[] pip){
		int dice[] = new int[6];
		for(int i = 0; i < 6; i ++){
			dice[i] = pip[i];
		}
		pip[0] = dice[3];
		pip[1] = dice[1];
		pip[2] = dice[0];
		pip[3] = dice[5];
		pip[4] = dice[4];
		pip[5] = dice[2];
		
		return pip;
	}

	public static int[] diceroll_w (int[] pip){
		int dice[] = new int[6];
		for(int i = 0; i < 6; i ++){
			dice[i] = pip[i];
		}
		pip[0] = dice[2];
		pip[1] = dice[1];
		pip[2] = dice[5];
		pip[3] = dice[0];
		pip[4] = dice[4];
		pip[5] = dice[3];
		
		return pip;
	}

	public static int[] diceroll_s (int[] pip){
		int dice[] = new int[6];
		for(int i = 0; i < 6; i ++){
			dice[i] = pip[i];
		}
		pip[0] = dice[4];
		pip[1] = dice[0];
		pip[2] = dice[2];
		pip[3] = dice[3];
		pip[4] = dice[5];
		pip[5] = dice[1];
		
		return pip;
	}
	
}



Measured memory_bytes: 26368
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    int a=read(),b=read(),c=read(),n=read(),ans=0;
    ans+=min(n,a);n=max(n-a,0);
    n=max(n-b,0);
    ans-=min(n,c);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3764
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String a = input.readLine();
        String b = input.readLine();
        b = b + b;
        System.out.println(b.contains(a) ? "Yes" : "No");
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <fstream>
#include <unordered_map>

using namespace std;

ifstream fin("../data.txt");

vector<string> v = {"eraser", "erase", "dreamer", "dream"};
string s;
int pos;

int main() {

  getline(cin, s);
  for (int i = 0; i < 4; i++) {
    while((pos = s.find(v[i])) != -1) {
      s.replace(pos, v[i].size(), "");
    }
  }
  if(s == "") {
    cout << "YES";
  } else cout << "NO";
  return 0;
}


Measured memory_bytes: 3756
using System;
class Practice
{
    public static void Main()
    {
        while (true)
        {
            string[] inp = Console.ReadLine().Split(' ');
            if (inp[1] == "?") break;
            int x = int.Parse(inp[0]), y = int.Parse(inp[2]);
            Console.WriteLine(inp[1] == "+" ? x + y : inp[1] == "-" ? x - y : inp[1] == "*" ? x * y : x / y);
        }
    }
}


Measured memory_bytes: 15928
k,n = (int(i) for i in input().split())
a = [int(i) for i in input().split()]

a.sort()
b=[a[0]+k-a[n-1]]
ans = a[0]+k-a[n-1]

for i in range(n-1):
	ans+=a[i+1]-a[i]
	b.append(a[i+1]-a[i])

ans-=max(b)

print(ans)


Measured memory_bytes: 25452
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp1
{
    public class Program
    {
        static void Main()
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);
            WriteLine(Hoge(ReadLine()));
            Out.Flush();
        }

        public static string Hoge(string s)
        {
            var ab = s.Split(' ').Select(short.Parse);
            var answer = "";

            if (ab.All(x => x <= 8))
            {
                answer = "Yay!";
            }
            else
            {
                answer = ":(";
            }

            return answer;
        }
    }




}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;cin >> n;
    map<long long, int> mp;
    for (int i = 0; i < n; i++){
        long long a;cin >> a;
        mp[a]++;
    }
    string ans = "YES";
    for(auto a :mp)if(a.second > 1)ans = "NO";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16112
fun main(args: Array<String>) {
    abc056b()
}

fun abc056b() {
    val (w, aLeft, bLeft) = readLine()!!.split(" ").map { it.toInt() }
    val aRight = aLeft + w
    val bRight = bLeft + w

    val answer = if (bRight in aLeft..aRight || bLeft in aLeft..aRight) 0 else {
        if (aRight < bRight) bLeft - aRight else aLeft - bRight
    }

    println(answer)
}


Measured memory_bytes: 37784
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

vc = [V[i]-C[i] for i in range(N)]
vc.sort(reverse=True)

ans = 0
for v in vc:
    if v < 0:
        break
    ans += v
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		String s;
		Scanner in = new Scanner(System.in);
		s = in.nextLine();
		if (s.equals("Sunny"))
			System.out.println("Cloudy");
		else if (s.equals("Cloudy"))
			System.out.println("Rainy");
		else
			System.out.println("Sunny");
	}
}

Measured memory_bytes: 18900
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
x = list(map(int, readline().split()))
memo = sorted(x)
dx = memo[n // 2]
for xx in x:
    print(memo[n // 2 - 1] if dx <= xx else dx)


Measured memory_bytes: 21908
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int s=a+b+c;
  int m=max(a,max(b,c));
  if(m==s-m){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int main(){
	int n, m;
  	cin >> n >> m;
	vector<int> a(n);
  	int total = 0;
	rep(i, n) {
      cin >> a[i];
      total +=  a[i];
    }
  
  	int ans = 0;
  	rep(i, n){
    	if(a[i] * 4 * m >= total) ans++;
    }
  
  
  	cout << (ans >= m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  for (int h = 1; h <= 3500; h++)
  {
    for (int n = 1; n <= 3500; n++)
    {
      ll denom = 4 * h * n - N * (h + n);
      if (denom == 0)
        continue;
      ll frac = N * h * n;
      if (h == 1 && n == 2)
        cerr << denom << " " << frac << endl;
      if (frac % denom == 0)
      {
        ll w = frac / denom;
        if (0 < w && w <= 3500)
        {
          cout << h << " " << n << " " << w;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod = 1e9+7;
const int maxn = 3e5+10;
const int inf = 0x3f3f3f3f;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<'\n';
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm> 
#include <cmath>
#include <numeric>
using namespace std;


int main(void){
    // Your code here!
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    vector<int> b(n);
    b[0] = a[0] + (k-a[n-1]);
    for(int i=1; i<n; i++) b[i] = a[i]-a[i-1];
    auto it = max_element(b.begin(), b.end());
    auto index = distance(b.begin(), it);
    int maxv = b[index];
    
    cout << accumulate(b.begin(), b.end(), 0) - maxv << endl;
    return 0;
}


Measured memory_bytes: 1792
n,m = map(int,input().split())
k = []
s = []
for i in range(m):
    l = list(map(int,input().split()))
    k.append(l[0])
    s.append(l[1:])
p = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    l = []
    for j in range(n):
        l.append(i>>j&1)
    cnt = 0
    for j in range(m):
        c = 0
        for h in s[j]:
            c += l[h-1]
        if c%2 == p[j]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Measured memory_bytes: 41712
#include<stdio.h>
int main(){
  int n,i,c=0;
  int a[1000000],use[1000000];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  i=1;
  while(use[i]==0){
    use[i]=1;
    i=a[i];
    c++;
    if(i==2){
      printf("%d\n",c);
      return 0;
    }
  }
  puts("-1");
  return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
int a,b,c,N,buhin[500],mei[2000][5],karibuhin[500];
int main(){
    while(1){
        fill(buhin,buhin+400,2);
        int fl=1;
        cin>>a>>b>>c;
        if(a+b+c==0)break;
        cin>>N;
        for(int i=0;i<N;i++){
            cin>>mei[i][0]>>mei[i][1]>>mei[i][2]>>mei[i][3];
            mei[i][0]--;mei[i][1]--;mei[i][2]--;
        }
        while(1){
            for(int f=0;f<a+b+c;f++){
                karibuhin[f]=buhin[f];
            }
            if(fl==0)break;
            fl=0;
            for(int i=0;i<N;i++){
                if(mei[i][3]==1){
                    buhin[mei[i][0]]=1;
                    buhin[mei[i][1]]=1;
                    buhin[mei[i][2]]=1;
                }else if(mei[i][3]==0){
                    if(buhin[mei[i][0]]==1&&buhin[mei[i][1]]==1){buhin[mei[i][2]]=0;}
                    if(buhin[mei[i][1]]==1&&buhin[mei[i][2]]==1){buhin[mei[i][0]]=0;}
                    if(buhin[mei[i][2]]==1&&buhin[mei[i][0]]==1){buhin[mei[i][1]]=0;}
                }
                for(int f=0;f<a+b+c;f++){
                    if(karibuhin[f]!=buhin[f]){fl++;}
                }
            }
        }for(int lk=0;lk<a+b+c;lk++){
            cout<<buhin[lk]<<endl;
        }
    }
}

Measured memory_bytes: 3112
#include <iostream>
using namespace  std;

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 26464
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> xe(n);
    vector<int> ye(m);
    string ans = "No War";
    for (int i = 0; i < n; ++i) {
        cin >> xe[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> ye[i];
    }

    int xm = *max_element(xe.begin(), xe.end());
    int ym = *min_element(ye.begin(), ye.end());

    xm = (x < xm) ? xm : x;
    ym = (y > ym) ? ym : y;
    if (ym - xm < 1) ans = "War";

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	int N, num, count, sum = 0, ans = 10000000;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> num;
		count = 0;
		while (true)
		{

			if ((num & 1) ==0)
			{
				count++;
				num = num >> 1;
			}
			else
			{
				break;
			}

		}
		ans = min(ans, count);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		String ans = a * b % 2 == 0 ? "Even" : "Odd";

		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n = int.Parse(Console.ReadLine());
            //string[] str = Console.ReadLine().Split(' ');
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            int k = int.Parse(str[3]);

            if (k < a) Console.WriteLine(k);
            else if (k <= a + b) Console.WriteLine(a);
            else Console.WriteLine(a-(k-a-b));


            //ここまで
        }

        static long Max(long a, long b)
        {
            if (a > b) return a;
            else return b;
        }


    }

}


Measured memory_bytes: 27544
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string N;
  cin >> N;
  int S = N.size();
  rep(i,S-1)
  {
    if(N[i]=='A'&&N[i+1]=='C')
    {
      cout << "Yes" << endl;
      return 0;
    }
    
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=100000+5;
int n, a[N], ans;

int main() {
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d",&a[i]);
    sort(a+1, a+n+1);
    reverse(a+1, a+n+1);
    for(int i=1; i<=n; i++) if(i+1>a[i+1]) {
		for(int j=i+1; a[j]==i; j++) ans^=1;
		ans|=(a[i]-i)&1;
		puts(ans?"First":"Second");
		return 0;
    }
    return 0;
} 

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll X,M=100,ans=0;

cin >> X;

while(M < X){
    M = double(M)*double(1.01);
    ++ans;
}

cout << ans << endl;

return 0;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	string s;
	int q;
	cin>>s>>q;
	
	map<int,char> mp;
	REP(i,s.size()) mp[i]=s[i];
	int l=-1, r=s.size();
	bool jud=true;
	
	int t;
	REP(i,q){
		scanf("%d",&t);
		if(t==1){
			jud=(jud)?false:true;
		}else{
			int f;
			char c;
			scanf("%d %c",&f,&c);
			f--;
			if(f xor jud) mp[l--]=c;
			else mp[r++]=c;
		}
	}
	
	if(jud) for(int i=l+1;i<r;++i) cout<<mp[i];
	else for(int i=r-1;i>l;--i) cout<<mp[i];
	cout<<endl;
}

Measured memory_bytes: 14720
import math

L,R=map(int, input().split())
d=R-L
r=R%2019
l=L%2019

if d>=2019 or r<l:
  print(0)
  
else:
  k=2020
  for i in range(l,r+1):
    for j in range(i+1,r+1):
      k=min(k,i*j%2019)
  print(k)



Measured memory_bytes: 9176
#include <iostream>
#include <vector>
using namespace std;

using int64 = long long;
const int64 kMod = 1000000007;

int64 Sum(const vector<int64>& x) {
  const int64 n = x.size();
  int64 ret = 0;
  int64 sum = 0;
  for (int64 i = 1; i < n; ++i) {
    sum += (x[i] - x[i - 1]) * i;
    ret += sum;
  }
  return ret % kMod;
}

int64 Solve(const vector<int64>& x, const vector<int64>& y) {
  return Sum(x) * Sum(y) % kMod;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int64> x(n), y(m);
  for (int i = 0; i < n; ++i)
    cin >> x[i];
  for (int i = 0; i < m; ++i)
    cin >> y[i];
  cout << Solve(x, y) << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	
	double n;
	
	while(scanf("%lf",&n)!=EOF){
		n=n/9.8;
		n=n*n*4.9;
		int i;
		for(i=1;i*5-5<n;i++);
		cout<<i<<endl;
	}
	return 0;
}
  

Measured memory_bytes: 1232
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int a , b , d , r ;
    a = b = d = r = 0;
    cin >> a  >> b  ;
    d = a / b;
    r = a % b;
    double f = ((double) a ) / b;
    cout << d << " " << r << " " ;
    cout << fixed;
    cout << setprecision(5)  << f << endl;
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main(){
	double n,x;
	int t;
	cin>>n>>x>>t;
	int tt = ceil (n/x);
	cout<<tt*t;
	return 0;   
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a > 8 || b > 8) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }
}

Measured memory_bytes: 23636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

#define llong long long

using namespace std;
const int IINF = 2147483647;
const llong LLINF = 9223372036854775807;

class UNF {
 private:
  int s;
  vector<int> tree, rank;
  int getP(int i) {
    if (tree[i] == -1){
      return i;
    }
    else
      return tree[i] = getP(tree[i]);
  }

 public:
  UNF(int n) {
    s = n;
    tree.resize(s, -1);
    rank.resize(s, 1);
  }
  int size() { return s; }
  long connect(int a, int b) {
    a = getP(a);
    b = getP(b);
    if(a==b)return 0L;
    long ret=(int)rank[a]*(int)rank[b];
    if (rank[a] >= rank[b]) {
      tree[b] = a;
      rank[a] += rank[b];
    } else {
      tree[a] = b;
      rank[b] += rank[a];
    }
    return ret;
  }
  bool check(int a, int b) { return getP(a) == getP(b); }
};

int main(){
  long n, m;
  cin >> n >> m;
  UNF uf(n);
  vector<pair<int, int>>brg(m);
  for(int i=0; i<m; i++){
    cin >> brg[i].first >> brg[i].second;
    brg[i].first--;
    brg[i].second--;
  }
  vector<long>ret(m+1, 0);
  ret[m]=n*(n-1)/2;
  for(int i=m-1; i>=1; i--){
    long d=uf.connect(brg[i].first, brg[i].second);
    ret[i]=ret[i+1]-d;
  }
  for(int i=1; i<=m; i++){
    cout << ret[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
const int N=188;
int dp[N][N][N][17];
int sum[N][N],n,m;
int query(int lx,int rx,int ly,int ry){
	return sum[rx][ry]-sum[lx-1][ry]-sum[rx][ly-1]+sum[lx-1][ly-1];
}
bool check(int lx,int rx,int ly,int ry){
	int s=query(lx,rx,ly,ry);
	if (s==0||s==(rx-lx+1)*(ry-ly+1)) return true;
	return false;
}
char a[N][N];
int main (){
	scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf ("%s",a[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]+(a[i][j]=='.')-sum[i-1][j-1];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m+1;j++)
			for (int k=0;k<17;k++)
				dp[i][j][j-1][k]=1<<30;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			for (int k=j;k<=m;k++){
				int now=i-1,l=i,r=n;
				while (l<=r){
					int mid=(l+r)>>1;
					if (check(i,mid,j,k)) now=mid,l=mid+1;
					else r=mid-1;
				}
				dp[i][j][k][0]=now;
			}
	int ans=1;
	for (;dp[1][1][m][ans-1]<n;ans++){
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++)
				for (int k=j;k<=m;k++)
					dp[i][j][k][ans]=dp[dp[i][j][k][ans-1]+1][j][k][ans-1];
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++)
				for (int k=j,p=j;k<=m;k++){
					while (p<k&&min(dp[i][j][p][ans-1],dp[i][p+1][k][ans-1])<=min(dp[i][j][p+1][ans-1],dp[i][p+2][k][ans-1])) ++p;
					dp[i][j][k][ans]=max(dp[i][j][k][ans],min(dp[i][j][p][ans-1],dp[i][p+1][k][ans-1]));
				}
	}
	printf ("%d",ans-1);
	return 0;
}


Measured memory_bytes: 436608
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};



int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec fac, finv;
Vec memo;

ll PowMod(ll a, ll n){
	if(n < 0) return PowMod(PowMod(a, -n), MOD-2);
	if(n == 0) return 1;
	if(n == 1) return a;
	if(n%2 == 0) return PowMod(a*a%MOD, n/2);
	return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll inv(ll n){
	return PowMod(n, MOD - 2);
}

void init(ll n = 2e6){
	fac.resize(n+1);
	fac[0] = 1;
	repn(i, n) fac[i] = fac[i-1]*i%MOD;
	finv.resize(n+1);
	finv[n] = PowMod(fac[n], MOD-2);
	repr(i, n) finv[i] = finv[i+1]*(i+1)%MOD;
	finv[0] = 1;
}

ll combi(ll n, ll k){
	return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(void){
	ll n, s;
	cin >> n >> s;

	Vec prev(s + 1, 0), cur(s + 1, 0);
	cur[0] = 1;

	rep(i, n){
		swap(prev, cur);
		ll a;
		cin >> a;
		rep(i, s + 1) cur[i] = prev[i] * 2;
		repn(i, s) if (i >= a) cur[i] += prev[i - a];
		rep(i, s + 1) cur[i] %= MOD;
	}
	co(cur[s]);

	return 0;
}


Measured memory_bytes: 3676
#include "bits/stdc++.h"
using namespace std;

int n;
int h[100005], dp[100005];

// dp[i] = min cost to go from i to n

int rec(int idx)
{
    if (dp[idx] != -1)
        return dp[idx];

    if (idx == 0)
        dp[idx] = 0;
    else if (idx == 1)
        dp[idx] = abs(h[idx] - h[idx - 1]);
    else
        dp[idx] = min(rec(idx - 2) + abs(h[idx] - h[idx - 2]), rec(idx - 1) + abs(h[idx] - h[idx - 1]));
    return dp[idx];
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> h[i];

    for (int i = 0; i < n; i++)
        dp[i] = -1;

    int ans = rec(n - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int H, N;
    cin >> H >> N;
    rep(i,N) {
        int A;
        cin >> A;
        H -= A;
    }

    if (H <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
long long INF = 1e18;
struct edge{
    int from;
    int to;
    long long cost;
};
void solve(int N, int M, vector<edge> &es, int s, int t){
    vector<long long> d(N);//各頂点までの距離
    for(int i = 0; i < N; i++) d[i] = INF;
    d[s] = 0;
    long long k = 0;
    long long ans = 1e18;
    while(true){
        bool flag = false;
        bool flag2 = false;
        for(int i = 0; i < M; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                flag = true;
                if(e.to == t) flag2 = true; 
            }
        }
        if(!flag) break;
        ans = min(ans, d[t]);
        k++;
        if(k == N && flag2){//閉路があって無限に更新される場合はinf
            cout << "inf" << endl;
            return;
        }
        else if(k == N && !flag2) break;
    }
    cout << -ans << endl;
}
int main(){
    int N, M;
    cin >> N >> M;
    vector<edge> es(M);
    for(int i = 0; i < M; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        edge e = {a, b, -c};
        es[i] = e;
    }
    solve(N, M, es, 0, N - 1);
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, ans; string S;
char now[3];

int Judge(){
  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (now[cnt] == S[i]) cnt++; 
    if (cnt == 3){
      ans++; return 0;
    }
  }
  return 0;
}

int Solve(int turn){
  if (turn == 3){
    Judge(); return 0;
  }

  for (char i = '0'; i <= '9'; i++){
    now[turn] = i;
    Solve(turn + 1);
  }
  return 0;
}

int main(){
  cin >> N >> S;
  Solve(0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3684
#include<iostream>
using namespace std;
int main()
{
	int sum,flag=0;
	cin >> sum;
	if (sum <= 10000)
		for (int a = 0; a <= sum / 100; a++)
			for (int b = 0; b <= sum / 101; b++)
				for (int c = 0; c <= sum / 102; c++)
					for (int d = 0; d <= sum / 103; d++)
						for (int e = 0; e <= sum / 104; e++)
							for (int f = 0; f <= sum / 102; f++)
							{
								if (a * 100 + b * 101 + c * 102 + d * 103 + e * 104 + f * 105 == sum)
								{
									flag = 1;
									break;
								}
							}
	else flag = 1;
	cout << flag << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

int n,x,ans;
int t[30];
char dp[1000001];
char p[1000001];

void mkPrime(void){
	memset(p,1,sizeof(p));
	p[0] = p[1] = 0;

	for(int i=2;i<=1000000;i++){
		if(p[i]){
			for(int j=i*2;j<=1000000;j+=i){
				p[j] = 0;
			}
		}
	}
}

void solve(void){
	dp[0] = 1;
	for(int i=0;i<x;i++){
		if(dp[i]){
			for(int j=0;j<n;j++){
				int sum = i + t[j];
				if(sum <= x){
					dp[sum] = 1;
				}
			}
		}
	}

	for(int i=0;i<=x;i++){
		if(dp[i] && p[i] && i > ans) ans = i;
	}
}

int main(void){
	mkPrime();

	while(cin>>n>>x && (n||x)){
		for(int i=0;i<n;i++) cin>>t[i];

		memset(dp,0,sizeof(dp));
		ans = 0;

		solve();

		if(ans == 0) cout<<"NA\n";
		else cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 2816
from collections import defaultdict
import math
dic=defaultdict(int)
n,m=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
c=0
count=0
for i in l:
  c=(c+i)%m
  if c==0:
    count+=1
  dic[c]+=1
for i in dic:
  if dic[i]==1:
    pass
  else:
    count+=math.factorial(dic[i])//(2*math.factorial(dic[i]-2))
print(count)  

Measured memory_bytes: 14924
#include <bits/stdc++.h>
//<(") 
#define ll long long  
using namespace std;
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
 
const ll mod = 1e9 + 7;
const ll siz = 3e5 + 10;
const ll base = 32;
const ll MAXX = 1e18;

ll n;
vector<ll> hold;

priority_queue<ll> lar;
priority_queue<ll, vector<ll>, greater<ll>> sma;

ll ma[siz], mi[siz];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	cin >> n;
	hold.resize(3 * n + 1);
	for (ll i = 1; i <= 3 * n; i++) {
		cin >> hold[i];
	}
	ll sum = 0;
	for (ll i = 1; i <= n; i++) {
		sma.push(hold[i]);
		sum += hold[i];
	}
	ma[n] = sum;
	//cerr << sum << ' ';
	for (ll i = n + 1; i <= 2 * n; i++) {
		if (hold[i] > sma.top()) {
			sum -= sma.top();
			sma.pop();
			sum += hold[i];
			sma.push(hold[i]);
		}
		ma[i] = sum;
		//cerr << sum << ' ';
	}
	//cerr << '\n';
	sum = 0;
	for (ll i = 3 * n; i > 2 * n; i--) {
		lar.push(hold[i]);
		sum += hold[i];
	}
	//cerr << sum << ' ';
	mi[2 * n + 1] = sum;
	for (ll i = 2 * n; i > n; i--) {
		if (hold[i] < lar.top()) {
			sum -= lar.top();
			lar.pop();
			sum += hold[i];
			lar.push(hold[i]);
		}
		mi[i] = sum;
		//cerr << sum << ' ';
	}
	//cerr << '\n';
	ll ans = -MAXX;
	for (ll i = n; i <= 2 * n; i++) {
		ans = max(ans, ma[i] - mi[i + 1]);
	}
	cout << ans << '\n';
	return 0;
}  	 	   		  	

Measured memory_bytes: 8968
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) (a).begin(), (a).end()

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}


int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<pair<int,int>, int>> da(m);
    rip(i,m,0){
        cin >> da[i].first.first >> da[i].first.second >> da[i].second;
    }
    vector<ll> ma(n + 1, LLONG_MIN/2);
    ma[1] = 0;
    rip(i,n,0){
        rip(i,m,0){
            ma[da[i].first.second] = max(ma[da[i].first.second], ma[da[i].first.first] + da[i].second);
        }
    }
    ll memo = ma[n];
    rip(i,n,0){
        rip(i,m,0){
            ma[da[i].first.second] = max(ma[da[i].first.second], ma[da[i].first.first] + da[i].second);
        }
    }
    if(memo < ma[n]){
        cout << "inf" << endl;
    }
    else{
        cout << ma[n] << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
li = [[0]*n for i in range(26)]
for i in range(n):
    S = list(input())
    for x in S:
        li[ord(x)-97][i] += 1
ans = []
for i in range(26):
    num = min(li[i])
    ans += [chr(i+97)] * num
print(''.join(ans))

Measured memory_bytes: 38640
#include<iostream>
#include<string>
using namespace std;
int main(){
long i,n=0,k,l;
string s;
string::size_type p,q;
while(cin>>s){
l=s.size();
for(q=-1;;){
p=s.find_first_of("0123456789",q+1);
if(p==string::npos)break;
q=s.find_first_not_of("0123456789",p);
if(q==string::npos)q=l;
for(i=p,k=0;i<q;i++){k*=10;k+=s[i]-48;}
n+=k;
}
}
cout<<n<<endl;
return 0;
}

Measured memory_bytes: 1184
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    B = [0] * (N+1)
    c = 0
    for a in A:
        if a > N:
            c += 1
        elif B[a] < a:
            B[a] += 1
        else:
            c += 1

    for i in range(N+1):
        if B[i] < i:
            c += B[i]

    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14648