akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

ll dp[5000];

int main(){
    rep(i,5000) dp[i]=LINF; 
    int n,m;
    scanf("%d%d",&n,&m);
    vector<ll> money(m),get(m);
    rep(i,m){
        ll a;
        int b;
        scanf("%lld%d",&a,&b);
        ll res=0;
        rep(j,b){
            int c;
            scanf("%d",&c);
            --c;
            res+=1<<c;
        }
        money[i]=a;
        get[i]=res;
    }
    dp[0]=0;
    rep(i,m){
        for(int bit=0;bit<(1<<n);bit++){
            dp[bit|get[i]] = min(dp[bit]+money[i],dp[bit|get[i]]);
        }
    }
    printf("%lld\n",(dp[(1<<n)-1]==LINF?-1:dp[(1<<n)-1]));
    return 0;
}

Measured memory_bytes: 3836
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] buttons = new int[N];
        for (int i = 0; i < N; i++) buttons[i] = int.Parse(Console.ReadLine());
        int ans = 0;
        int count = 0;
        int next = 0;
        for (int i = 0; i < N; i++)
        {
            if (buttons[next] - 1 == 1) { count++; break; }
            next = buttons[next] - 1;
            count++;
        }
        ans = count;
        if (count == buttons.Length) ans = -1;

        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13280
function Main(input) {
  var args = input.split("\n").filter(f => !!f);
  var times = args.map(t => parseInt(t));
  var timeMods = times.map(t => (t - 1) % 10);
  var timeSep = times.map(t => Math.ceil(t / 10) * 10);
  var min = null;
  var minDef;
  var sum = 0;
  for (var i = 0; i < timeMods.length; i ++) {
    if (min === null || timeMods[i] < min) {
      min = timeMods[i];
      minDef = times[i] - timeSep[i];
    }
    sum += timeSep[i];
  }
  console.log((sum + minDef));

}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    int N,M;
    int ans;
    scanf("%d %d",&N,&M);

    ans = (N-1)*N/2 + (M-1)*M/2;
    printf("%d",ans);

    return 0;
}


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


const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[] = {0, -1, 0, 1, -1, 1, -1, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k%2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
    return 0;
}



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

int main() {
  int a[4][3][10] = {{{0}}};
  int n, b, f, r, v;
  string str(20, '#');
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    a[b - 1][f - 1][r - 1] += v;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << " " << a[i][j][k];
      }
      cout << "\n";
    }
    if (i != 3) cout << str << "\n";
  }
  return 0;
}


Measured memory_bytes: 3140
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;
    vector<int> cntS(27), cntT(27);
    rep(i, S.size()) { cntS[S[i] - 'a']++; }
    rep(i, T.size()) { cntT[T[i] - 'a']++; }
    sort(All(cntS));
    sort(All(cntT));
    rep(i, 27) {
        if(cntS[i] != cntT[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define nn '\n'
#define db(x) cout << "(DB)-> " << x << nn

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> k;
  int r = -1;
  if (k % 7 == 0) k /= 7;
  if (__gcd(10, k) != 1) {
    cout << r;
    return 0;
  }
  int i = 1;
  ll x = i % k;
  while (x != 0) {
    x = (10 * x + 1) % k;
    i++;
  }
  cout << i;
  return 0;
}


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

int main() {
    string S; cin >> S;
    int n = S.size();
    vector<char> v;
    int T = 0;

    for(int i = 0; i < n; ++i) {
        if(S[i] == 'S') {
            v.push_back(S[i]);
        } else {
            if(v.empty())
                T++;
            else
                v.pop_back();
        }
    }

    cout << v.size() + T << "\n";
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()


int main(){
    int n; cin>>n;
    int w[n];
    rep(i,0,n) cin>>w[i];
    int dif=1001001;
    rep(i,1,n){
        // int i=2;
        int s1=0,s2=0;
        rep(j,0,i) s1+=w[j];
        rep(j,i,n) s2+=w[j];
        dif=min(dif,abs(s1-s2));
    }
    cout<<dif<<endl;
    // cout<<s1<<endl<<s2<<endl;
}

Measured memory_bytes: 256
import sys
import math

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")


def main():
    d, g = MI()
    pc = [LI() for _ in range(d)]

    ans = inf
    for bit in range(2 << d):
        c = 0
        score = 0
        for i in range(d):
            if bit & (1 << i):
                c += pc[i][0]
                score += pc[i][0] * 100 * (i + 1) + pc[i][1]

        if score >= g:
            ans = min(ans, c)
        else:
            for i in reversed(range(d)):
                if bit & (1 << i):
                    continue
                res = math.ceil((g - score) / (100 * (i + 1)))
                if res < pc[i][0]:
                    ans = min(ans, c + res)
                break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var P, Q, R int
	fmt.Scanf("%d %d %d", &P, &Q, &R)
	var min int
	min = P + Q
	if min > Q+R {
		min = Q + R
	}
	if min > P+R {
		min = P + R
	}
	fmt.Print(min)
}


Measured memory_bytes: 512
#辞書型リスト作成
dic ={
  "a":list(input()),
  "b":list(input()),
  "c":list(input())
}
#print(dic)

now = "a"
while True:
  if len(dic[now]) == 0:
    print(now.upper()) #大文字変換
    break
  now = dic[now].pop(0) #値削除

Measured memory_bytes: 61828
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

x = int(input())

m = 500
aa = [0]*(m*2)
for i in range(-m,m):
    j = -m+i
    aa[j] = i**5

for i in range(m*2):
    for j in range(m*2):
        if aa[i] - aa[j] == x:
            print(-m+i,-m+j)
            exit()


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << 180 * (n - 2) << ln;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In,' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            

            bool existAnswer = false;
            var ans = 0;
            for (var i = 1; i <= 1000; i++) 
            {
                int checkA = (int)(i * 0.08);
                int checkB = (int)(i * 0.10);
                if (checkA == A && checkB == B) 
                {
                    existAnswer = true;
                    ans = i;
                    break;
                }
            }
            
            WriteLine(existAnswer ? ans : -1) ;
        }

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    string s;
    cin >> s;
    //cerr << "s -> " << s << endl;
    int ans = 0;
    rep(i, 0, s.size() / 2) {
        //cerr << "i -> " << i << endl;
        //cerr << "i2 -> " << ((s.size()) - i - 1)<< endl;
        if (s[i] != s[s.size() - i - 1]) {
            ++ans;
        }
    }

    cout << ans << '\n';
    


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans = 0;
		if(n >= m) {
			ans = 10;
		}
		System.out.println(ans);
		sc.close();
	}


}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	int A[400000] = {};
	char ima = S[0];
	int kazu = -1;
	int doko = 0;
	rep(i, N) {
		if (S[i] == ima) {
			kazu++;
		}
		else {
			ima = S[i];
			A[doko] = kazu + 1;
			kazu = 0;
			doko++;
		}
	}
	A[doko] = kazu + 1;

	int dotti = S[0] - '0';
	int kotae = 0;
	int kari = 0;
	rep(i, 2 * K + 1) kari += A[i];
	if (dotti) kotae = kari;
	else kotae = kari - A[2 * K];
	rep(i, N) {
		kari += A[i + 2 * K + 1];
		kari -= A[i];
		if(dotti == i % 2) kotae = max(kotae, kari);
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 2048
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    return {2} | {2 * i + 1 for i in range(1, m) if p[i]}


def main():
    primes = prime_numbers(10 ** 5)
    A = [n % 2 and n in primes and (n + 1) // 2 in primes for n in range(10 ** 5 + 1)]
    A = tuple(accumulate(A))

    Q, *LR = map(int, read().split())
    ans = []
    for l, r in zip(LR[::2], LR[1::2]):
        ans.append(A[r] - A[l - 1])

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 29000
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 200010
#define INF 9999999
using namespace std;
int n,pos[233],_next[maxn][27],dp[maxn],now;
char s[maxn];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	dp[n+1]=1;
	for (int i=0;i<26;++i) pos[i]=-1;
	for (int i=n;i>=1;--i)
	  {
	  	pos[s[i]-'a']=i;
	  	for (int j=0;j<26;++j)
	  	  _next[i][j]=pos[j];
	  }
	for (int i=n;i>=1;--i)
	{
		int tmp=INF;
		for (int j=0;j<26;++j) 
		tmp=min(tmp,dp[_next[i][j]+1]);
	    dp[i]=tmp+1;
	}
	now=1;
	while (now>0)
	{
		for (int j=0;j<26;++j)
		  if (dp[now]==dp[_next[now][j]+1]+1)
		  {
		  	  now=_next[now][j]+1;
		  	  printf("%c",'a'+j);
			  break;
		  }
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 22272
'use strict'

function main(input) {
  const n = Number(input)
  let ans = 0
  let tmpmax = 0
  if (n == 1) {
    console.log(1)
    return
  }
  for (let i = 1; i <= n; i++) {
    if (i % 2 > 0) {
      continue
    } else {
      //何回割り切れるか
      let j = i
      let cnt = 0
      while (j % 2 == 0) {
        cnt++
        j = j / 2
      }
      if (tmpmax < cnt) {
        tmpmax = cnt
        ans = i
      }
    }
  }

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 11468
#include<stdio.h>

int main (void) {
  char S[256], T[256], U[256];
  scanf ("%s", S);
  scanf ("%s", T);
  
 int A, B; 
  scanf ("%d", &A);
  scanf ("%d", &B);
  scanf ("%s", U);
  
  if (strcmp(U,S) == 0){
    printf ("%d ", A-1);
    printf ("%d\n", B);
  }
  else{
    printf ("%d ", A); 
    printf ("%d\n", B-1);
  }
  return 0;
}
  
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    string s1, s2;
    rep(i, atoi(b.c_str())){
        s1 += a;
    }
    rep(i, atoi(a.c_str())){
        s2 += b;
    }
    cout << min(s1, s2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  int a,b;

  scanf("%d %d", &a, &b);

  if(a > 2*b) printf("%d\n", a - 2*b);

  else printf("0\n");
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=305; 
pii find_num[MAX_N*MAX_N];
int cost[MAX_N*MAX_N];
int grid[MAX_N][MAX_N];
int H,W,D;
int dist(pii p1,pii p2)
{
	return abs(p1.fi-p2.fi)+abs(p1.se-p2.se);
}
int main()
{
//	freopen("input.txt","r",stdin);
	cin>>H>>W>>D;
	For(i,1,H)
	{
		For(j,1,W)
		{
			cin>>grid[i][j];
			find_num[grid[i][j]]=mp(i,j);
		}
	}
	For(i,D+1,H*W)
	{
		cost[i]=cost[i-D]+dist(find_num[i],find_num[i-D]);
	}
	int Q;
	cin>>Q;
	while(Q--)
	{
		int L,R;
		cin>>L>>R;
		cout<<cost[R]-cost[L]<<endl;
	}
	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N; string S;
  cin >> N >> S;

  int ans = 0;

  for(int i=0; i<=N-3; i++){
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
      ans++;
    }
  }

  cout << ans << endl;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  char s[n];
  cin >> s;
  k--;
  s[k] += 0x20;
  for(int i=0; i<n; i++){
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

int dfs(const int v, const UnWeightedGraph &G, vector<int> &dp){
  if(dp[v]!=-INF<int>){
    return dp[v];
  }

  int res = 0;
  for(auto nv: G[v]){
    chmax(res, dfs(nv,G,dp)+1);
  }

  return dp[v]=res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,M;
  cin>>N>>M;
  UnWeightedGraph G(N);
  REP(i,M){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
  }

  vector<int> dp(N, -INF<int>);
  int ans = 0;
  REP(i,N){
    chmax(ans, dfs(i,G,dp));
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 8832
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}*/
int main()
{
	while (1)
	{
		bool m[14][14] = {};
		int ans = 0;
		for (int i = 1; i <= 12; i++)
		{
			string s;
			if (cin >> s); else return 0;
			for (int l = 0; l < 12; l++)
			{
				m[i][l+1] = s[l] == '1';
			}
		}
		for (int i = 1; i <= 12; i++)
		{
			for (int l = 1; l <= 12; l++)
			{
				if (m[i][l])
				{
					ans++;
					m[i][l] = false;
					queue<pii> que;
					que.push(pii(i, l));
					while (!que.empty())
					{
						pii now = que.front(); que.pop();
						for (int k = 0; k < 4; k++)
						{
							int x = now.first + dx[k];
							int y = now.second + dy[k];
							if (m[x][y])
							{
								m[x][y] = false;
								que.push(pii(x, y));
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1196
//   AtCoder Beginner Contest 072 A-Sandglass2

#include<stdio.h>

int main(void)
{

    int X, t, a;

    scanf("%d %d", &X, &t);

    if(X - t > 0) a = X - t;
    else a = 0;

    printf("%d\n", a);

    return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=998244353;

ll test_pow4(ll x, ll n)
{
	ll ret = 1;
	while(0 < n)
	{
		if((n % 2) == 0)
		{
			x = x*x%MOD;
			n >>= 1;
		}
		else
		{
			ret = ret*x%MOD;
			--n;
		}
	}
	return ret;
}
signed main(){
    llin(n);
    vllin(d,n);
    vll s(n,0);
    if(d[0]>0){
        sal(0)
        return 0;
    }
    FOR(i,0,n-1){
        s[d[i]]++;
    }
    ll k=1;
    ll c=0;
    FOR(i,1,n-1){
            k=(k*test_pow4(s[i-1],s[i]))%MOD;
        c+=s[i];
        if(c>=n-1){
            break;
        }
    }
    if(c<n-1) k=0;
    sal(k)
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
      
      
int main(){
  ll ans=0;
  int n;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){ans+=i;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = 0;
		if(n % 2 == 0) {
			a = n / 2 - 1;
		}
		else{a = n / 2;}
		System.out.println(a);
     }
}

Measured memory_bytes: 21460
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int main(){
  int so[200000]={};
  int f;
  so[2]=1;
  for(int i=2;i<200000;i++){
    f=0;
    for(int j=2;j*j<=i;j++){
      if(i%j==0){
	f=1;
	break;
      }
    }
    if(f==0)so[i]=1;
  }
  int s,n;
  //
  while(1){
    cin >> s >> n;
    if(s==-1&&n==-1)break;
    vector<int>a;
    multiset<int>st;
    int k=s+1;
    for(int i=0;i<=n;i++){
      while(1){
	if(so[k]==0)k++;
	else{
	  a.push_back(k);
	  k++;
	  break;
	}
      }
    }
    int l=0;
  
    for(int i=0;i<a.size();i++){
      for(int j=0;j<=i;j++){
	st.insert(a[i]+a[j]);
	//	  cout << a[i]+a[j]<<endl;
      }
      //cout << a[i]*2<<endl;
    }
    int co=0;

    for( set<int>::iterator itr = st.begin(); itr != st.end() ; ++itr){
      co++;
       if(co==n){
	cout << *itr << endl;
		break;
	 }
    }
  }
  return 0;
}

	

Measured memory_bytes: 4148
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Map.Entry;

/**
 * https://abc065.contest.atcoder.jp/tasks/arc076_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		Point[] points = new Point[N];
		for(int i=0; i<N; i++){
			points[i] = new Point(i, Integer.parseInt(sc.next()), Integer.parseInt(sc.next()));
		}
		sc.close();
		
		Node[] nodes = new Node[N];
		for(int i=0; i<N; i++) nodes[i] = new Node(i);
		Arrays.sort(points, (o1,o2) -> o1.x-o2.x);
		for(int i=1; i<N; i++){
			Point p1 = points[i-1];
			Point p2 = points[i];
			int c = Math.min(Math.abs(p2.x-p1.x), Math.abs(p2.y-p1.y));
			Node a = nodes[p1.i];
			Node b = nodes[p2.i];
			a.neighbor.put(b, c);
			b.neighbor.put(a, c);
		}
		Arrays.sort(points, (o1,o2) -> o1.y-o2.y);
		for(int i=1; i<N; i++){
			Point p1 = points[i-1];
			Point p2 = points[i];
			int c = Math.min(Math.abs(p2.x-p1.x), Math.abs(p2.y-p1.y));
			Node a = nodes[p1.i];
			Node b = nodes[p2.i];
			a.neighbor.put(b, c);
			b.neighbor.put(a, c);
		}
		
		Node[] mst = buildMST(nodes);
		
		long ans = 0;
		for(Node n:mst){
			for(int c:n.neighbor.values()){
				ans += c;
			}
		}
		
		System.out.println(ans);
		
	}
	
	static class Node{
		int id;
		Map<Node,Integer> neighbor = new HashMap<>();
		int color = -1;
		int status = -1;
		int inDegree = 0;
		long cost;
		Node(int id){
			this.id = id;
		}
	}
	
	static class Point{
		int i;
		int x;
		int y;
		Point(int i, int x, int y){
			this.i = i;
			this.x = x;
			this.y = y;
		}
	}
	
	static class Edge{
		Node from;
		Node to;
		int cost;
		Edge(Node parent, Node child, int cost){
			this.from = parent;
			this.to = child;
			this.cost = cost;
		}
	}
	
	static Node[] buildMST(Node[] nodeList) {
		Node base = nodeList[0];
		Node[] mst = new Node[nodeList.length];
		PriorityQueue<Edge> que = new PriorityQueue<>(new Comparator<Edge>(){
			public int compare(Edge e1, Edge e2) {
				return e1.cost < e2.cost ? -1 : 1;
			}
		});
		mst[base.id] = new Node(base.id);
		for(Entry<Node, Integer> n: base.neighbor.entrySet()){
			que.add(new Edge(base, n.getKey(), n.getValue()));
		}
		for(int i=1; i<mst.length; i++){
			Edge minEdge = null;
			while(true){
				minEdge = que.remove();
				if(mst[minEdge.to.id]==null) break;
			}
			mst[minEdge.to.id] = new Node(minEdge.to.id);
			mst[minEdge.from.id].neighbor.put(mst[minEdge.to.id], minEdge.cost);
			for(Entry<Node, Integer> entry: minEdge.to.neighbor.entrySet()){
				if(mst[entry.getKey().id]==null)
					que.add(new Edge(minEdge.to, entry.getKey(), entry.getValue()));
			}
		}
		return mst;
	}

}

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

int main() {
  int H,W,D;
  cin>>H>>W>>D;
  vector<vector<int>>p(H*W+1,vector<int>(2));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int a;
      cin>>a;
      p.at(a).at(0)=i,p.at(a).at(1)=j;
    }
  }
  vector<int>z(H*W+1);
  for(int i=0;i<D;i++){
    for(int j=1+i;j<=H*W-D;j+=D){
      z.at(j+D)=z.at(j)+abs(p.at(j+D).at(0)-p.at(j).at(0))+abs(p.at(j+D).at(1)-p.at(j).at(1));
    }
  }
  int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    cout<<z.at(r)-z.at(l)<<endl;
  }
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int a;
int c[1050000];

/*
signed main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1]-='A';
  s[k-1]+='a';
  cout<<s<<endl;
  return 0;
}
*/
signed main(){
  char c;
  int y=0;
  int d=0;
  lp(i,2){
    cin>>c;
    y+=c-'0';
    y*=10;
  }
  lp(i,2){
    cin>>c;
    d+=c-'0';
    d*=10;
  }
  y/=10;
  d/=10;
  if(1<=y&&y<=12&&1<=d&&d<=12) cout<<"AMBIGUOUS"<<endl;
  else if(1<=y&&y<=12) cout<<"MMYY"<<endl;
  else if(1<=d&&d<=12) cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX 2000000
 
int H,A[MAX+1];
 
void maxHeapify(int i){
  int l,r,largest,C;
  l=2*i;
  r=2*i+1;
 
  if(l<=H&&A[l]>A[i])largest=l;
  else largest = i;
  if(r<=H&&A[r]>A[largest])largest=r;
 
  if(largest!=i){
    C=A[i];
    A[i]=A[largest];
    A[largest]=C;
    maxHeapify(largest);
  }
}
 
int main(){
  int i;
 
  scanf("%d",&H);
 
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  for(i=H/2;i>=1;i--)maxHeapify(i);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
 
  printf("\n");
   
  return 0;
}



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

int main() {
  int N;
  cin>>N;

  int A[N],B[N],C[N-1];
  for (int i = 0; i < N ; i++) cin>>A[i];
  for (int i = 0; i < N ; i++) cin>>B[i];
  for (int i = 0; i < N-1 ; i++) cin>>C[i];


  int Arev[N] = {};
  for (int i = 0; i < N; i++) {
    for (int j = 0; j<N;j++) {
      if (A[j] == i+1) Arev[i] = j;
    }
  }
  // for (int i = 0; i < N;i++) cout<<Arev[i]<<endl;

  int val = 0;
  for (int i = 0;i<N-1;i++) {
    if (Arev[i+1]-Arev[i]==1) val += C[i];
  }
  for (int i = 0;i<N;i++) {
    val += B[i];
  }
  cout<<val<<endl;
  // cout<<pow(N,3)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)
        cout<<"Possible"<<endl;
    else
        cout<<"Impossible"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int x,y;
  cin >> x >> y;
  for (int i = 0; i <= x; i++){
    for (int j = 0; j <= x; j++){
      if (i + j == x && 2 * i + 4 * j == y){
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;cin>>s;
    ll n = s.size();
    for(ll i=0;i<n-1;i++)if(s[i]==s[i+1])return cout<<i+1<<" "<<i+2 , 0;
    for(ll i=0;i<n-2;i++)if(s[i]==s[i+2])return cout<<i+1<<" "<<i+3 , 0;
    cout<<"-1 -1";
}

Measured memory_bytes: 512
n = gets.chomp.to_i
$hluca = {}
def luca(i)
  case i
  when 0
    2
  when 1
    1
  else
    if $hluca[i]
      $hluca[i]
    else
      $hluca[i] = luca(i-1) + luca(i-2)
    end
  end
end
puts luca(n)


Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){
  int m[2001]={0};
  int n,c;
  for(int i=0;i<1001;++i){
    for(int j=0;j<1001;++j) ++m[i+j];
  }
  while(cin>>n){
    c=0;
    for(int i=0;i<2001;++i){
      if(n-i<0) break;
      if(n-i<2001) c+=m[i]*m[n-i];
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
from collections import defaultdict
# dfs, check path len, count paths                                                                                                                           
# test = 2                                                                                                                                                   
n, m = map(int, input().split())
edges = [map(int, input().split()) for i in range(m)]
graph = defaultdict(list)
for k,v in edges:
    graph[k].append(v)
    graph[v].append(k)

cnt = 0
# dfs                                                                                                                                                        
def dfs(node, visited):
    global cnt
    if node in visited:
        return None
    elif len(visited) + 1 == n:
        cnt += 1
        return None
    else:
        for v in graph[node]:
            dfs(v, visited+[node])
dfs(1, [])
print(cnt)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
void divider_s(set<ll> &s, ll n) {
	for (ll i = 1; i*i <= n; i++) {
		if (!(n % i)) {
			s.insert(i);
			if (i*i != n) s.insert(n / i);
		}
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	set<ll> s1;
	set<ll> s2;

	ll a, b; cin >> a >> b;
	divider_s(s1, a);
	divider_s(s2, b);

	vector<ll> v;
	for (set<ll>::iterator it = s1.begin(); it != s1.end(); it++) {
		if (s2.count(*it) != 0) {
			v.push_back(*it);
		}
	}

	ll V = v.size();
	ll ans = 0;
	ll X = 1;
	rep(l, 0, V) {
		if (gcd(X, v[l]) == 1) {
			X *= v[l];
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstring>
#include <iostream>

using namespace std;

#define MAX_N 210

int N, A[3][MAX_N], P[MAX_N];

int main()
{
	memset(P, 0, sizeof(P));

	cin >> N;

	for (int i = 1; i <= N; i++)
	{
		cin >> A[0][i] >> A[1][i] >> A[2][i];
	}

	for (int d = 0; d < 3; d++)
	{
		for (int i = 1; i <= N; i++)
		{
			bool found = false;

			for (int j = 1; j <= N; j++)
			{
				if (i != j)
				{
					if (A[d][i] == A[d][j])
					{
						found = true;
					}
				}
			}

			if (found == false)
			{
				P[i] += A[d][i];
			}
		}
	}

	for (int i = 1; i <= N; i++)
		cout << P[i] << endl;

	return 0;
}

Measured memory_bytes: 1164
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL a, b, q;
	cin >> a >> b >> q;
	vector<LL> s(a), t(b);
	for (int i = 0; i < a; ++i) {
		cin >> s[i];
	}
	for (int i = 0; i < b; ++i) {
		cin >> t[i];
	}
	for (int i = 0; i < q; ++i) {
		LL x;
		cin >> x;
		LL ans = 1LL << 60;
		int y = (int)(lower_bound(s.begin(), s.end(), x) - s.begin());
		for (int j = max(0, y - 1); j <= min(y, (int)s.size() - 1); ++j) {
			LL yc = abs(x - s[j]);
			int z = (int)(lower_bound(t.begin(), t.end(), s[j]) - t.begin());
			for (int k = max(0, z - 1); k <= min(z, (int)t.size() - 1); ++k) {
				LL zc = yc + abs(s[j] - t[k]);
				ans = min(ans, zc);
			}
		}
		y = (int)(lower_bound(t.begin(), t.end(), x) - t.begin());
		for (int j = max(0, y - 1); j <= min(y, (int)t.size() - 1); ++j) {
			LL yc = abs(x - t[j]);
			int z = (int)(lower_bound(s.begin(), s.end(), t[j]) - s.begin());
			for (int k = max(0, z - 1); k <= min(z, (int)s.size() - 1); ++k) {
				LL zc = yc + abs(t[j] - s[k]);
				ans = min(ans, zc);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
n = int(input())
H = list(map(int, input().split()))
DP = [0] * n
DP[1] = abs(H[1] - H[0])
for i in range(2, n):
    DP[i] = min(DP[i - 1] + abs(H[i] - H[i - 1]), DP[i - 2] + abs(H[i] - H[i - 2]))

print(DP[-1])

Measured memory_bytes: 13980
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=sum(a)
cd=set(())
for i in range(1,int(m**0.5)+2):
  if m%i==0:
    cd.add(i)
    cd.add(m//i)
cd=list(cd)
cd.sort(reverse=True)
def func(x):
  r=[ai%x for ai in a]
  r.sort()
  tmp=0
  sr=[0]
  for ri in r:
    tmp+=ri
    sr.append(tmp)
  for i in range(n+1):
    tmp0=sr[i]
    tmp1=(n-i)*x-(sr[-1]-sr[i])
    if tmp0==tmp1 and tmp0<=k:
      return True
  return False


for x in cd:
  if x==1:
    print(1)
    exit()
  if func(x):
    print(x)
    exit()

Measured memory_bytes: 9528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());
            string[] item = new string[input];
            for(int i = 0; i < input; i++)
            {
                item[i] = Console.ReadLine();
            }
            System.Collections.Generic.HashSet<string> hs1 = new System.Collections.Generic.HashSet<string>(item);
            string[] result_item = new string[hs1.Count];
            hs1.CopyTo(result_item, 0);
            Console.WriteLine(result_item.Length);
            Console.Read();
        }
    }
}


Measured memory_bytes: 42844
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int n;
string s;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	{
		cin>>s;
		mp[s]++;
	}
	printf("AC x %d\n",mp["AC"]);
	printf("WA x %d\n",mp["WA"]);
	printf("TLE x %d\n",mp["TLE"]);
	printf("RE x %d\n",mp["RE"]);
	return 0;
}

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

int main()
{
	int N;
	cin >> N;

	vector<pair<int, int> >v(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> v[i].first;
		v[i].second = i;
	}

	sort(v.begin(), v.end());
	
	for (int i = 0; i < N; ++i)
	{
		if (v[N-1].second != i)
			cout << v[N - 1].first << '\n';
		else
			cout << v[N - 2].first << '\n';
	}
	return 0;
}

Measured memory_bytes: 3200
s = input()
op1 = ['+', '-']
op2 = ['+', '-']
op3 = ['+', '-']

for o1 in op1:
    for o2 in op2:
        for o3 in op3:
            f = s[0] + o1 + s[1] + o2 + s[2] + o3 + s[3]
            if eval(f) == 7:
                print(f+"=7")
                exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(void){
    ll n;
    cin >> n;
    vector<ll>h(n);
    ll ans;
    cin >> h[0];
    ans = h[0];
    for(int i=1;i<n;i++){
        cin >> h[i];
        if(h[i-1]<h[i]){
            ans += (h[i]-h[i-1]);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readLine.toInt
    val as = StdIn.readLine.split(" ").map(_.toInt)

    //(0 +: as :+ 0).foreach {println}  // 別にこれいらないか

    val l = Array.fill(n + 2)(0)
    val r = Array.fill(n + 2)(0)

    for (i <- 1 to n) {
      l(i) = gcd(l(i - 1), as(i - 1))
    }

    for (i <- n to 1 by -1) {
      r(i) = gcd(r(i + 1), as(i - 1))
    }

    println((1 to n).toList.map(i => gcd(l(i - 1), r(i + 1))).max)
  }

  def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
}

Measured memory_bytes: 50596
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int h[110000][3];
int dp[110000][3];

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> h[i][0] >> h[i][1] >> h[i][2];
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + h[i][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 3; i++)
        ans = max(ans, dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 2560
n = int(input())
a_list = [int(x) for x in input().split()]

node = 1
flg = False
node_list = [node]

for i in range(len(a_list)-1):
  num = a_list[i]
  next = node-num
  if next < 0:
    flg = True
    break
  node = next*2
  node_list.append(node)

if node - a_list[-1] < 0:
  flg = True
else:
  diff = a_list[-1]
  res_list = [a_list[-1]]
  for i in range(len(a_list)-2,-1,-1):
    v = node_list[i] - a_list[i] # 枝の数
    diff = min(diff,v) + a_list[i]
    res_list.append(diff)

if flg:
  print(-1)
else:
  print(sum(res_list))

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

using namespace std;

typedef long long ll;

const int maxn=1e5+5,mod=1e4+7;
const double pi=acos(-1);

int main()
{
    ll X;
    while(cin>>X)
    {
        ll sum=0;
        sum+=X/500*1000;
        X-=X/500*500;
        sum+=X/5*5;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int func(int x, int per) {
	return x * (100 + per) / 100;
}

int main() {
	int x, y, s;
	while (cin >> x >> y >> s, x || y || s) {
		int ans = 0;
		FOR(i, 1, 1001) FOR(j, 1, 1001) {
			if (func(i, x) + func(j, x) != s) continue;
			chmax(ans, func(i, y) + func(j, y));
		}
		
		if (debug) printf("@ ");
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

char N;
string str;
P t[4][13];
int sum[2];
int change(char ch){
  int a;
  if(ch=='S')a=0;
  else if(ch=='H')a=1;
  else if(ch=='D')a=2;
  else if(ch=='C')a=3;
  return a;
}
int change2(char ch){
  int b;
  if(ch=='T')b=10;
  else if(ch=='J')b=11;
  else if(ch=='Q')b=12;
  else if(ch=='K')b=13;
  else if(ch=='A')b=14;
  else b=ch-'0';
  return b;
}

int main(){
  while(1){
    cin>>N;
    if(N=='#')break;
    for(int i=0;i<4;i++){
      for(int j=0;j<13;j++){
	cin>>str;
	t[i][j].first=change(str[1]);
	t[i][j].second=change2(str[0]);
      }
    }
    sum[0]=sum[1]=0;
    int id=0;
    
    for(int i=0;i<13;i++){

      int rank[4]={};
      rank[change(N)]=3;
      rank[t[id][i].first]=2;
      P maxm=P(0,0);
      for(int j=0;j<4;j++){
	P p=t[j][i];
	p.first=rank[p.first]*100+p.second;
	p.second=j;
	maxm=max(maxm,p);
      }
      sum[maxm.second%2]++;
      id=maxm.second;
    }
    
    if(sum[0]>sum[1])cout<<"NS"<<' '<<sum[0]-6<<endl;
    else cout<<"EW"<<' '<<sum[1]-6<<endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	if(n==1) { cout << "Hello World" << endl; return 0; }
	int a,b; cin>>a>>b;
	cout << a+b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int x=0,y=0,answer,i=0,z[100]={},j=0,count=0;
    char a[100];
    while(scanf("%s",a)==1){
        if(a[i]=='+'){
            answer=z[j-2]+z[j-1];
            z[j-2]=answer;
            j=j-1;
        }
        else if(a[i]=='-'){
            answer=z[j-2]-z[j-1];
            z[j-2]=answer;
            j=j-1;
        }
        else if(a[i]=='*'){
            answer=z[j-2]*z[j-1];
            z[j-2]=answer;
            j=j-1;
        }
        else{
             x=atoi(a+i);
             z[j]=x;
             j++;
        }
    }
    printf("%d\n",answer);   
    return 0;
}


Measured memory_bytes: 2096
import java.util.*;
import java.io.*;

public class Main {

  private static final int MOD = 1_000_000_007;

  private static void solve() {
    int h = nextInt();
    int w = nextInt();

    long[][] dp = new long[h][w];

    char[][] g = new char[h][w];

    for (int i = 0; i < h; i++) {
      g[i] = next().toCharArray();
    }

    dp[0][0] = 1;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i + 1 < h && g[i + 1][j] == '.') {
          dp[i + 1][j] += dp[i][j];
          dp[i + 1][j] %= MOD;
        }
        if (j + 1 < w && g[i][j + 1] == '.') {
          dp[i][j + 1] += dp[i][j];
          dp[i][j + 1] %= MOD;
        }
      }
    }

    System.out.println(dp[h - 1][w - 1]);
  }

  private static void run() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

  private static String next() {
    while (st == null || !st.hasMoreElements()) {
      String s;
      try {
        s = br.readLine();
      } catch (IOException e) {
        return null;
      }
      st = new StringTokenizer(s);
    }
    return st.nextToken();
  }

  private static int nextInt() {
    return Integer.parseInt(next());
  }

  private static long nextLong() {
    return Long.parseLong(next());
  }

  public static void main(String[] args) {
    run();
  }
}

Measured memory_bytes: 39572
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll K, A, B;
  cin >> K >> A >> B;
  for (ll i = A; i <= B; ++i) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3636