akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((b / a > c) ? c : b / a) << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

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


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), k = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
    vector <int> ans;
    for (int i = 1; i < n; i++) {
    	if (a[i] + a[i + 1] >= k) {
    		cout << "Possible\n";
    		for (int j = 1; j < i; j++) {
    			cout << j << endl;
    		}
    		for (int j = n - 1; j  >= i + 1; j--) {
    			cout << j << endl;
    		}
    		cout << i << endl;
    		return 0;
    	}
    }
    cout << "Impossible";
	return 0;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q ; cin >> N >>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21728
import java.util.*;

import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);
    static boolean debug = false;

    static void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int cnt = 0;
        int f = -1;
        for (int i=0; i<n; i++) {
            a[i] = in.nextInt();
            if (i != 0) {
                if (f == -1) {
                    if (a[i-1] < a[i]) { f = 1;}
                    else if (a[i-1] > a[i]) {f = 2; }
                } else {
                    if (f == 1) {
                        if (a[i-1] > a[i]) {
                            f = -1;
                            cnt++;
                            // out.println(i);
                        }
                    } else if (f == 2) {
                        if (a[i-1] < a[i]) {
                            f = -1;
                            cnt++;
                            // out.println(i);
                        }
                    }
                }
            }
        }

        out.println((cnt+1));
    }

    public static void main(String[] args) {
        debug = args.length > 0;
        long start = System.nanoTime();

        solve();
        out.flush();

        long end = System.nanoTime();
        in.close();
        out.close();
    }

    static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

int main(){
  string S;
  cin>>S;

	if(S=="RRR")
      cout<<3<<endl;
    else if(S=="SSS")
      cout<<0<<endl;
    else if(S=="RRS" || S=="SRR")
      cout<<2<<endl;
    else
      cout<<1<<endl;        

}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std; 
int main() {
    cout << fixed << setprecision(6);
    double a,b,c; cin >> a >> b >> c;
    double s,l,h;
    const double pi = acos(-1.0);
    c= c*pi/180.0;
    s = a*b*sin(c)/2.0;
    l = a + b + sqrt(a*a+b*b-2*a*b*cos(c));
    h = 2*s/a;
    cout << s <<endl;
    cout << l<< endl;
    cout << h << endl;
    return 0;
}


Measured memory_bytes: 3504
def f(k):
    if k<=P:
        return True
    if A[k]+M<A[P]:
        return False
    num=A[k]+M
    zzz=M*V-(N-k+P)*M
    if zzz<=0:
        return True
    for j in range(P,k):
        zzz-=num-A[j]
    if zzz<=0:
        return True
    else:
        return False

N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
A=[float("inf")]+A
low=1
high=N
while high-low>=1:
    mid=(high+low)//2
    if f(mid):
        if low==mid:
            if f(high):
                low=high
            else:
                high=low
        else:
            low=mid
    else:
        high=mid
print(low)

Measured memory_bytes: 62576
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    A = lmi()
    aa = [(A[i], i + 1)for i in range(N)]
    aa.sort()
    ans = [aa[i][1]for i in range(N)]
    print(*ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 65004
n,m=[int(i) for i in input().split()]

ab_list=[]
for i in range(n):
    a,b=[int(i) for i in input().split()]
    ab_list.append([a,b])
    
cd_list=[]
for i in range(m):
    c,d=[int(i) for i in input().split()]
    cd_list.append([c,d])
    
    
for i in range(n):
    len_list=[]
    for j in range(m):
        len=abs(ab_list[i][0]-cd_list[j][0])+abs(ab_list[i][1]-cd_list[j][1])
        len_list.append(len)
    print(len_list.index(min(len_list))+1)
        

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && a != c){
        cout << "Yes" << endl;
    }else if(b == c && b != a){
        cout << "Yes" << endl;
    }else if(c == a && c != b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 1e5 + 7; 

ll a[maxn];
ll b[maxn];
vector<int> G[maxn];
bool ok;

void dfs(int x,int pi) {
	if (G[x].size() > 1) a[x]*=2;
	for (int j = 0; j < G[x].size(); j++) {
		int y = G[x][j];
		if (y == pi) continue;
		dfs(y,x);
		if (!ok) return;
	}

	ll l = a[x] - b[x];
	if (pi < 0) {
		if (l != 0) ok = false;
		return;
	}
	if ((l > a[pi]/2) || (l + b[pi] > a[pi]) || (G[x].size() > 1 && l > a[x]/2)) { ok = false; return; }
	b[pi] += l;
}

int main() {
	int n; sd(n); ok = true;
	for (int i = 1; i <= n; i++) {
		sl(a[i]); b[i] = 0;
	}
	for (int i = 1; i < n; i++) {
		int x,y; sd(x); sd(y);
		G[x].pb(y); G[y].pb(x);
	}
	if (n == 2) {
		printf((a[1] == a[2]) ? "YES\n" : "NO\n");
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		if (G[i].size() > 1) {
			dfs(i,-1); break;
		}
	}
	printf(ok?"YES\n":"NO\n");
}


Measured memory_bytes: 12672
from collections import defaultdict, deque
N, M = map(int, input().split())
dic = defaultdict(list)
for i in range(M):
  u, v = map(int, input().split())
  dic[u-1] += [v-1]
S, T = map(int, input().split())
S -= 1
T -= 1
dist = [[float('inf')]*3 for i in range(N)]
dist[S][0] = 0
q = deque([(S,0)])
flag = False
cnt = 0
while q:
  cnt += 1
  e, m = q.popleft()
  n = (m+1)%3
  for p in dic[e]:
    if p==T:
      flag = True
    if dist[p][n]>dist[e][m]+1:
      dist[p][n] = dist[e][m]+1
      q += [(p,n)]
if flag:
  ans = dist[T][0] if dist[T][0]!=float('inf') else -1
  print(ans//3)
else:
  print(-1)

Measured memory_bytes: 94936
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
D = read_ints()

if D[0] != 0:
    print(0)
    exit()


# 飛んだらアウト
# 個数を数えてどうにかする
# D.sort()
# if D[1] == 0:
#     print(0)
#     exit()

# now = 0
# cnt = 0
# ans = 1
# pre_cnt = 0
# for d in D:
#     if d == now + 1:
#         ans *= cnt
#         pre_cnt = now
#         now = d
#         cnt = 0
#     elif d == now:
#         cnt += 1


from collections import Counter
dic = Counter(D)
ans = 1

if dic[0] != 1:
    print(0)
    exit()
# print(dic)
for i in range(max(D)):
    # もし連続してなかったらだめ
    try:
        dic[i + 1]
    except:
        print(0)
        exit()

    ans *= dic[i]**dic[i + 1]
    if ans > 998244353:
        ans = ans % 998244353

print(ans)


Measured memory_bytes: 19684
a = input()
b = input()
c = input()
 
A = len(a)
B = len(b)
C = len(c)
 
def judge(s, t):
	X = [0] * 20000
	ns, nt = len(s), len(t)
	for i in range(ns):
		for j in range(nt):
			if s[i] != t[j] and s[i] != '?' and t[j] != '?':
				X[i-j+8000] = 1
	return X
 
ab = judge(a, b)
bc = judge(b, c)
ac = judge(a, c)
r = A + B + C
for i in range(-4000, 4001):
	for j in range(-4000, 4001):
		if (not ab[i+8000]) and (not ac[j+8000]) and (not bc[j-i+8000]):
			st = min(i, j, 0)
			en = max(i+B, j+C, A)
			r = min(en-st, r)
print(r)

Measured memory_bytes: 53980
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}ll a[1000001];
main()
{
    IO
    ll n;
    cin>>n;
    ll f;
    memset(a,0,sizeof(a));
    for(int x=0;x<n;x++)
        cin>>f,++a[f];
        bool r=true;
    for(int x=2;x<=1e6;x++)
    {    ll e=0;
        for(int y=x;y<=1e6;y+=x)
            e+=a[y];
        if(e>1)r=false;
        if(e==n)
        {   cout<<"not coprime\n";
            return 0;
        }
    }
    if(r)cout<<"pairwise coprime\n";
    else cout<<"setwise coprime\n";
}


Measured memory_bytes: 11460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)
#define SUMV(v)		(accumulate(v.begin(),v.end(),0.0))

#define INF 		2000000007
#define MOD			1000000007

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;

//int dp[MAX];

int main(){
	int N;cin>>N;
	
	int cnt=0;
	while(N){
		cnt += N%10;
		N /=10;
	}
	cout << (cnt!=1 ? cnt : 10) << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

// x : 開始の数(初項)
// d : 足す数(公差)
// n : x から何個後まで見るか(第 n 項)
// 例) x = 3, d = 1, n = 4 の場合 3+4+5+6=18
ll AriProSum(ll x, ll d, ll n) {
    return n * (2 * x + (n - 1) * d) / 2;
}

string S;

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

    cin >> S;

    vector<int> con_len(S.length(), 0); // 連続する同じ記号の長さ
    char prev = S[0];
    int cur = 0;
    int ind = 0;
    REP(i, S.length()) {
        if(prev != S[i]) {
            con_len[ind] = cur;
            con_len[i - 1] = cur;
            cur = 0;
            ind = i;
        }
        cur++;
        prev = S[i];
    }
    con_len[ind] = cur;
    con_len[S.length() - 1] = cur;

    int ans = 0;

    REP(i, S.length() - 1) {
        if(S[i] == '<' && S[i+1] == '>') {
            ans += max(con_len[i], con_len[i + 1]);
            ans += AriProSum(0, 1, con_len[i]);
            ans += AriProSum(0, 1, con_len[i + 1]);
        }
    }
    if(S[0] == '>') {
        ans += AriProSum(1, 1, con_len[0]);
    }
    if(S[S.length()-1] == '<') {
        ans += AriProSum(1, 1, con_len[S.length()-1]);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve()
{
    ll x,temp=100,year=0;
    cin>>x;
    while(1)
    {
        if(temp>=x) break;
        year++;
        temp+=temp/100;
    }
    cout<<year;
}

int main()
{
    fast;
    int t;
    solve();
}


Measured memory_bytes: 3640
/* Square Route */

#include<cstdio>
#define MAX 1500000

int A[MAX], B[MAX], C[MAX], D[MAX];
				
void CountingSort(int A[], int B[]){
	int i;
	for(i = 1;i < MAX;i++)
		B[i] = 0;
	for(i = 0;i < MAX;i++)
		B[A[i]]++;
}

int main(void){
	for(;;){
		int N, M, i, j, k = 0, square = 0;
		scanf("%d %d", &N,&M);
		if(N == 0 && M == 0)
			return 0;
		else{
			int E[N], F[M];
			for(i = 0;i < N;i++)
				scanf("%d", &E[i]);
			for(i = 0;i < M;i++)
				scanf("%d", &F[i]);
			for(i = 0;i < N;i++){
				A[k] = E[i];
				k++;
				for(j = i + 1;j < N;j++){
					A[k] = A[k-1] + E[j];
					k++;
				}
			}
			for(i = k;i < MAX;i++)
				A[i] = 0;
			k = 0;
			for(i = 0;i < M;i++){
				C[k] = F[i];
				k++;
				for(j = i + 1;j < M;j++){
					C[k] = C[k-1] + F[j];
					k++;
				}
			}
			for(i = k;i < MAX;i++)
				C[i] = 0;
			CountingSort(A, B);
			CountingSort(C, D);
			for(i = 1;i < MAX;i++)
			square += B[i] * D[i];
			printf("%d\n", square);
		}
	}
}

Measured memory_bytes: 26000
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int n,m;
int dis[Max],pre[Max];
void init()
{
	for(int i=0;i<=n;i++)
		pre[i]=i;
}
int Find(int x)
{
	if(x!=pre[x])
	{
		int fa=pre[x];
		pre[x]=Find(pre[x]);
		dis[x]+=dis[fa];
		//printf("%d\n",x);
	}
	return pre[x];

}
int main()
{
	scanf("%d%d",&n,&m);
	int x,y,d;
	int fx,fy;
	init();
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&x,&y,&d);
		fx=Find(x);fy=Find(y);
		//printf("%d %d\n",fx,fy);
		if(fx==fy)
		{
			if(abs(dis[x]-dis[y])!=d)
			{
				printf("No\n");
				return 0;
			}
		}
		else
		{
			pre[fy]=fx;
			dis[fy]=dis[x]-dis[y]+d;
		}
	}
	/*for(int i=1;i<=n;i++)
		printf("%d %d\n",pre[i],dis[i]);*/
	printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
"""this is python work script"""

def find_score(N, card_list):
    """return score list about a and b"""
    sum_a, sum_b = 0, 0
    card_list.sort()
    for i in range(N):
        if i % 2 == 0:
            sum_a += card_list.pop()
        else:
            sum_b += card_list.pop()
    return sum_a, sum_b

def solve(num, card_list):
    """solve problem"""
    a_score, b_score = find_score(num, card_list)
    diff_score = a_score - b_score
    return diff_score

def main():
    """main method"""
    num_cards = int(input())
    list_cards = list(map(int, input().split(' ')))
    answer = solve(num_cards, list_cards)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

int n;
int a[2020];

int dp[2020][2];
int f(int i, int t) {
    int &r = dp[i][t];
    if (r != -1) return r;
    int ret = abs(a[i] - a[n]);
    FOR(k, i + 1, n) {
        if (t) chmin(ret, f(k, t ^ 1));
        else chmax(ret, f(k, t ^ 1));
    }
    return r = ret;
}

int main() {
    cin >> n >> a[0] >> a[0];
    rep(i, n) cin >> a[i + 1]; // 1...
    memset(dp, -1, sizeof(dp));
    cout << f(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 384
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)

if x2 == 0:
    print(2)

if x3 == 0:
    print(3)

if x4 == 0:
    print(4)

if x5 == 0:
    print(5)


Measured memory_bytes: 9152
#include <iostream>

using namespace std;

void bubbleSort(int* A, int N){
    int flag = 1;
    int count = 0;
    while(flag){
        flag = 0;
        for(int j = N - 1; j > 0; j--){
            if(A[j] < A[j-1]){
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }
    for(int i = 0; i < N; i++){
        cout << A[i];
        if(i < N - 1){
            cout << " ";
        }
    }
    cout << endl;
    cout << count << endl;
}

int main(){
    int N;
    int A[1000];
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A[i] = a;
    }
    bubbleSort(A, N);
    return 0;
}


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

static const int N=100;
static const int INFTY=2001;
static const int WHITE=0;//未探索
static const int GRAY=1;//MSTに隣接
static const int BLACK=2;//MSTに含まれる

int n,v,M[N][N];

int prim(){
    int sum_weight; //MSTの辺の重みの総和
    int cost[N]; //MSTから頂点に伸びている辺の重みの最小値をその頂点に保持する
    int color[N]; //MSTか、MSTに隣接しているか、それ以外か
    //初期化
    for(int i=0;i<n;i++){
        cost[i]=INFTY;
        color[i]=WHITE;
    }
    cost[0]=0;
    color[0]=GRAY;
    sum_weight=0;

    while(true){
        int vertex=-1;//次に含む頂点の候補
        int min_cost=INFTY;//次に選ぶ辺の最小コスト
        for(int i=0;i<n;i++){
            //MSTに隣接した頂点から最小コストのものを探す
            if(color[i]==GRAY&&cost[i]<min_cost){
                min_cost=cost[i];
                vertex=i;
            }
        }
        //T(部分グラフ)＝Vなら終了
        if(vertex==-1) break;
        //該当の頂点がある場合
        color[vertex]=BLACK;
        sum_weight+=cost[vertex];

        //vertexをMSTに含めたために、それによる他の頂点の最小コストの変化と状態を更新
        for(int i=0;i<n;i++){
            if(color[i]!=BLACK&&M[vertex][i]<INFTY){
                color[i]=GRAY;
                if(cost[i]>M[vertex][i]) cost[i]=M[vertex][i];
            }
        }
    }
    return sum_weight;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>v;
            if(v==-1) M[i][j]=INFTY;
            else M[i][j]=v;
        }
    }

    cout<<prim()<<endl;
}


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

const int mod = 1e9+7;
const int INF = 2000000;
const double PI = acos(-1.0);

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

    int a[1000001];
    a[1] = 7 % K;
    for(int i = 2; i <= K; i++) a[i] = (10*a[i-1] + 7) % K;

    int ans = -1;

    for(int i = 1; i <= K; i++) {
        if(a[i] == 0) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 7540
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    bool approved = true;
    for (int i=0; i<N; i++) {
        int n;
        cin >> n;
        if (n % 2 == 0) {
            if (n % 3 != 0 && n % 5 != 0) {
                approved = false;
                break;
            }
        }
    }

    if (approved) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;

int main()
{
    string s;
    cin >> s;

    for (int i = 0; i < 3; i++) {
        if (s[i] == '1') {
            s[i] = '9';
        }
        else {
            s[i] = '1';
        }
    }

    cout << s << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3628
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while((line = in.readLine()) != null){
			int size = Integer.parseInt(line);
			for(int i=0; i<size; i++){
				line = in.readLine();
				String[] tmp = line.split(":");
				int h = Integer.parseInt(tmp[0]);
				int m = Integer.parseInt(tmp[1]);
				double sangle = 30.0 * h + 0.5 * m;
				double langle = 6.0 * m;
				double theta = Math.abs(sangle - langle);
				if(theta > 180.0) theta = 360.0 - theta;

				if(theta < 30.0){
					System.out.println("alert");
				}
				else if(theta < 90.0){
					System.out.println("warning");
				}
				else{
					System.out.println("safe");
				}
			}
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=2e5+10;
const ll INF=1e18;


int main(){
	int N;
	cin>>N;
	ll A[MAX], B[MAX];
	bool same=true;
	rep(i,N){
		cin>>A[i]>>B[i];
		if(A[i]!=B[i])same=false;
	}
	if(same){
		cout<<0<<endl;
	}
	else{
		ll ans=0;
		ll dif=INF;
		rep(i,N){
			ans+=A[i];
			if(A[i]>B[i])dif=min(dif, B[i]);
		}
		ans-=dif;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {

int a,b,c;
 
  cin >> a >>b;
 
   
  for(int i =0;i<30;i++){
   
    c = (i)*a+1-i;
    
    if(c>=b){
      cout <<  i << endl;
      
      return 0;
    }
  }
    
  
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <functional>
#include <cstring>
using namespace std;
#define MAX_V 10240
 
// 从?点from指向?点to的???cost的?
typedef struct edge
{
	int to, distance, cost;
	edge(){}
	edge(int to, int distance, int cost) : to(to), distance(distance), cost(cost){}
	bool operator > (const edge & b) const
	{
		return distance != b.distance  ? distance > b.distance : cost > b.cost;
	}
} P;
 
// first 最短路径，second?点?号
 
// ?
vector<edge> G[MAX_V];
 
// V是?点数
int V;
bool visited[MAX_V];
 
// 求解从?点s出?到所有点的最短花?
int dijkstra(int s)
{
	int result = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	memset(visited, 0, V * sizeof(bool));
	que.push(P(0, 0, 0));
 
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.to;
		if (visited[v]) continue;
		visited[v] = true;
		result += p.cost;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge e = G[v][i];
			que.push(P(G[v][i].to, p.distance + G[v][i].distance, G[v][i].cost));
		}
	}
 
	return result;
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
	int /*N = V,*/ M;
	while (cin >> V >> M && V)
	{
		for (int i = 0; i < V; ++i)
		{
			G[i].clear();
		}
		for (int i = 0; i < M; ++i)
		{
			int u, v, d, c;
			cin >> u >> v >> d >> c;
			--u, --v;
			G[u].push_back(edge(v, d, c));
			G[v].push_back(edge(u, d, c));
		}
 
		cout << dijkstra(0) << endl;
	}
	return 0;
}

Measured memory_bytes: 5356
from collections import deque
def main():
    n,q = map(int,input().split())
    values = [0]*n
    links = [[] for _ in range(n)]
    for _ in range(n-1):
        a,b = map(int,input().split())
        links[a-1].append(b-1)
        links[b-1].append(a-1)
    
    for _ in range(q):
        p,x = map(int,input().split())
        values[p-1] += x
    d = deque()
    d.append((0,-1))
    
    while len(d) != 0:
        i,p = d.popleft()
        for j in links[i]:
            if j==p:
                continue
            values[j] += values[i]
            d.append((j,i))
    print(*values)
    
main()

Measured memory_bytes: 62260
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define bg begin()
#define en end()
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)
    return b;
    else
    return gcd(b%a,a);
}
ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = -1000000000000000, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 
ll countPairs(ll arr[], ll n) 
{ 
    map<ll, ll> map; 
    for (ll i = 0; i < n; i++) {
        if (map.find(arr[i]-i) == map.end()) { 
            map[arr[i]-i] = 1; 
        } 
        else { 
            map[arr[i]-i]++; 
        } 
    }
    ll res = 0; 
    for (auto x : map) { 
        ll cnt = x.second; 

        res += ((cnt * (cnt - 1)) / 2); 
    } 
  
    return res; 
} 
ll findSubarraySum(ll arr[], ll n, ll sum) 
{ 
    unordered_map<ll, ll> prevSum; 
  
    int res = 0; 
  
    int currsum = 0; 
  
    for (int i = 0; i < n; i++) { 
        currsum += arr[i]; 
        if (currsum == sum)  
            res++;         
  
        if (prevSum.find(currsum - sum) !=  
                                  prevSum.end())  
            res += (prevSum[currsum - sum]);
        prevSum[currsum]++; 
    } 
  
    return res; 
} 
ll sod(ll x){
    ll r,sum=0;
    while(x>0){
        r=x%10;
        x/=10;
        sum+=r;
    }
    return sum;
}
long long modpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    fast
    ll x,k,d,s;
    cin>>x>>k>>d;
    s=abs(x);
    ll r=s/d;
    if(r>=k){
        cout<<abs(s-k*d);
    }
    else{
        if((k-r)%2==0){
            cout<<abs(s-r*d);
        }
        else{
            cout<<abs(d-s%d);
        }
    }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s; cin>>s;
    ll f = 0;
    ll n = sz(s);
    rep(i, n) {
        f += s[i] - '0';
    }
    if (stoi(s) % f == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl; 
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
    int n,k;
    scanf("%d", &n);
    scanf("%d",&k);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n,INF);
    dp[0] = 0;
    int i;
    for(i=0; i<n;i++)
    {
        for (int j = i+1;j <=i+k;j++ ){
            if (j<n){
                dp[j] =  min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
        
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
N = int(input())
v = list(map(int,input().split()))
V = sorted(v)
sum = 0
if N >= 3:
  for i in range(N-1):
    sum += (2**(i))*V[i+1]/2**(N-1)
  sum += V[0]/2**(N-1)

elif N == 2:
  sum = (V[0]+V[1])/2

print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k, a, b;
    cin >> k >> a >> b;
    int cur = k;
    while (cur  <= b) {
        if (cur >= a && cur <= b) {
            cout << "OK";
            return 0;
        }
        cur += k;
    }
    cout << "NG";
    
}

Measured memory_bytes: 3660
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 20:56:51 2019

@author: shuto
"""

# -*- coding: utf-8 -*-
A, B = map(int, input().split())

tmp = 0
if(A >= B):
    tmp += A
    A = A-1
else:
    tmp = B
    B = B-1
 
if(A >= B):
    tmp += A

else:
    tmp += B

    

print(tmp)

Measured memory_bytes: 2940
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

signed main(){
/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/

  int X, Y;
  cin >> X >> Y;
  for (int i = 0; i <= X; i++) {
    for (int j = 0; j <= X; j++) {
      if (i + j > X)
        break;
      if (i + j == X && (2 * i + j * 4 == Y)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  vector<double> A(N);
  REP(i,N) cin>>A[i];
  sort(A.begin(), A.end());
  double ans = (A[0] + A[1]) / 2.0;
  for(int i = 2; i < N; i++) {
    ans = (ans + A[i]) / 2.0;
  }
  printf("%0.10f\n", ans);
  return 0;
}


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

int main(){
  int n;
  cin>> n;
  vector<int> a(n+1),b(n);
  for (int i=0; i<n+1; i++) cin>> a.at(i);
  for (int i=0; i<n; i++) cin>> b.at(i);
  
  int64_t ans=0; //int型だと桁が足りない？
  int ability,kill1,kill2;
  for (int i=0; i<n; i++){
    ability=b.at(i);
    kill1=min(a.at(i),ability);
    kill2=min(a.at(i+1),ability-kill1);
    ans+=kill1+kill2;
    a.at(i+1)-=kill2;
  }
  cout<< ans << endl;
}

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}

};
vector<ll> TopologicalSort(ConnectNodeInfo& connect){
	int N=connect.size();
	stack<ll> vertex;
	vector<ll> input(N),sorted;
	REP(i,N){
		for(auto& x:connect[i]) input[x.first]++;
	}
	REP(i,N){
		if(input[i]==0) vertex.push(i);
	}
	while(!vertex.empty()){
		auto v=vertex.top();vertex.pop();
		sorted.push_back(v);
		for(auto& x:connect[v]){
			input[x.first]--;
			if(!input[x.first]) vertex.push(x.first);
		}
	}
	if(sorted.size()!=N) sorted.clear();
	return sorted;
}

ll CalcLongestPathOnDAG(ConnectNodeInfo& connect,vector<ll>& DAG){
	int N=connect.size();
	vll dist(N,-1);
	ll maxD=0;
	REP(i,N){
		if(dist[DAG[i]]<0) dist[DAG[i]] = 0; 
		for(auto& x:connect[DAG[i]]){
			dist[x.first] = max(dist[x.first],dist[DAG[i]]+x.second);
			maxD = max(maxD,dist[x.first]);
		}
	}
	return maxD;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	vvll L(N,vll(N,-1));
	int index=0;
	REP(i,N){
		FOR(j,i+1,N){
			L[i][j] = index++;
			L[j][i] = L[i][j];
		}
	}
	ConnectNodeInfo connect(index);
	REP(i,N){
		ll s=in()-1;
		REP(j,N-2){
			ll t=in()-1;
			connect.AddDirectionalConnection(L[i][s],L[i][t],1);
			s = t;
		}
	}
	auto DAG = TopologicalSort(connect);
	if(DAG.empty()){
		out(-1);
		return 0;
	}

	ll maxD = CalcLongestPathOnDAG(connect,DAG);
	out(maxD+1);
	return 0;
}


Measured memory_bytes: 55024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    string s;
    cin >> s;
    for (int i=0; i<s.size()-1;i++) {
        if (s[i] != s[i+1]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  if (s=="SUN"){
    cout << 7 << endl;
  }
  if (s=="MON"){
    cout << 6 << endl;
  }
  if (s=="TUE"){
    cout << 5 << endl;
  }
  if (s=="WED"){
    cout << 4 << endl;
  }
  if (s=="THU"){
    cout << 3 << endl;
  }
  if (s=="FRI"){
    cout << 2 << endl;
  }
  if (s=="SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    int n = s.length();
    
    for(int i = 0; i < n; i++) {
    	System.out.print("x");
    }
    
    System.out.println();
    
    sc.close();
    
    
    
  }
}


Measured memory_bytes: 22996
N, M = map(int, input().split())
S = []

money = 0

for i in range(N):
	A, B = map(int, input().split())
	S.append([A, B])
	
S.sort()

while M > 0:
	for i in range(N):
		if S[i][1] <= M:
			money += S[i][0] * S[i][1]
			M -= S[i][1]
		else:
			money += S[i][0] * M
			M -= M
			break
print(money)

Measured memory_bytes: 20056
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
const ll INFLL=(ll)4e18, MOD=1e9+7; const int INF=0x3f6f6f6f;
//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color, level; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}


///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());


int n,k; cin>>n>>k;
ll dp[2][k+1];
vi a(n); for(int i=0;i<n;++i) cin>>a[i];
memset(dp, 0, sizeof(dp));
int turn=0;
dp[0][0]=1;
for(int i=0;i<n;++i){
	int nturn=turn^1;
	for(int j=1;j<=k;++j) dp[turn][j]=(dp[turn][j]+dp[turn][j-1])%MOD;
	for(int j=0;j<=k;++j){
		if(j-a[i]-1<0) dp[nturn][j]=(MOD+dp[turn][j])%MOD;
		else dp[nturn][j]=(dp[turn][j]-dp[turn][j-a[i]-1]+MOD)%MOD;
	}
	turn = nturn;
}
cout<<dp[turn][k]<<el;


return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		scan.close();
		if(X==7 || X==5 || X==3) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string S;

	cin >> S;
	cout << "\n";

	int judge = 0;

	int N = S.size();

	char eg[200];

	int i = 1;
	while(i <= N){
		eg[i] = S[i-1];
		i++;
	}

	i = 1;
	while(i <= N){
		if(eg[i] != eg[N-i+1]){
			judge++;
//			cout << "1\n";
			break;
		}
		i++;
	}

	i = 1;
	while(i <= (N-1)/2){
		if(eg[i] != eg[(N-1)/2+1-i]){
			judge++;
			break;
//			cout << "2\n";
		}
		i++;
	}

	i = (N+3)/2;
	int j = i-1;
	while(i <= N){
		if(eg[i] != eg[N+1-i+j]){
			judge++;
//			cout << "3\n";
			break;
		}
		i++;
	}

	if(judge == 0){
		cout << "Yes";
	}
	else{
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
 
using namespace std;
 
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pii pair<int,pi>
#define X first
#define Y second
#define pb push_back
#define ab(x) ((x)<0?(-(x)):(x))
#define xx(x) ((x)*(x))
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vpi vector<pi>
#define vpll vector<pll>
#define ALL(x) (x).begin(),(x).end()
#define Max (1<<30)
#define LLMax (1ll<<60)
template<class T>string ToString(T t){stringstream s;s<<t;return s.str();}
template<class T>void ToOther(T&t,string a){stringstream s(a);s>>t;}
 

int h,w;
vi v[1005];
vi c[1005];
int wh[55][55];
int E=0;
vpi ed;
int d[1005];
int tt[2][2005];
int ttt[3005];
int dis[1005];

void add(int x,int y){
	v[x].pb(y);v[y].pb(x);
	
	c[x].pb(ed.size());
	c[y].pb(ed.size());

	ed.pb( pi(x,y) );
}



void di(int st,int no,int d[1005]){
	if(no==3){
		st=st;
	}
	priority_queue< pi , vector<pi> , greater<pi> > q;
	q.push( pi(0,st) );
	d[st]=0;

	while(q.size()){
		int k=q.top().Y;
		int dis=q.top().X; q.pop();

		if(d[k]<dis)continue;

		for(int i=0;i<v[k].size();i++)if(c[k][i]!=no){
			int t=v[k][i];

			if(d[t]>dis+1){
				d[t]=dis+1;
				q.push( pi(d[t],t) );
			}
		}
	}
}

int main(){
	//freopen("input.txt","r",stdin);
	while(cin>>h>>w,h){
		E=0;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)wh[i][j]=E++;

		for(int i=0;i<h*2-1;i++){
			int y=i/2;
			if(i%2==0){
				for(int j=0;j<w-1;j++){
					int k;cin>>k;
					if(k==0)add(wh[y][j],wh[y][j+1]);
				}
			}else{
				for(int j=0;j<w;j++){
					int k;cin>>k;
					if(k==0)add(wh[y][j],wh[y+1][j]);
				}
			}
		}

		
		memset(ttt,-1,sizeof(ttt));

		for(int i=0;i<ed.size();i++){
			memset(dis,63,sizeof(dis));
			
			if(ed[i].X==5){
				i=i;
			}

			di(ed[i].X,i,dis);
			ttt[ed[i].X]=max(ttt[ed[i].X],dis[E-1]);

			if(ed[i].Y==5){
				i=i;
			}

			memset(dis,63,sizeof(dis));
			di(ed[i].Y,i,dis);
			ttt[ed[i].Y]=max(ttt[ed[i].Y],dis[E-1]);
		}
		

		memset(d,63,sizeof(d));
		d[E-1]=0;
		//for(int i=0;i<E;i++)d[i]=ttt[i];
		for(int C=0;C<E;C++)for(int i=0;i<ed.size();i++){
			int s=ed[i].X;
			int e=ed[i].Y;

			d[e]=min(d[e],max(d[s]+1,ttt[e]));
			d[s]=min(d[s],max(d[e]+1,ttt[s]));
			continue;
			
			int r1=max(d[s]+1,tt[0][i]);
			int r2=max(d[e]+1,tt[1][i]);
			
			if(s==E-1)r2=tt[1][i];
			if(e==E-1)r1=tt[0][i];

			if(d[s]<1000)d[e]=min(d[e],r1);
			if(d[e]<1000)d[s]=min(d[s],r2);
		}
		if(d[0]>10000)d[0]=-1;
		cout<<d[0]<<endl;

		ed.clear();
		for(int i=0;i<1000;i++)v[i].clear(),c[i].clear();
	}
}

Measured memory_bytes: 1368