akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#define MAX_D 10
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int D, G;
  cin >> D >> G;
  G /= 100;
  int P[MAX_D];
  int C[MAX_D];
  rep(i, D) {
    int p, c;
    cin >> p >> c;
    P[i] = p;
    C[i] = c / 100;
  }

  int PA[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int Ans = INT32_MAX;
  do {
    int Ans0 = 0;
    int Sum = 0;
    for (int i = 0; i < D; i++) {
      // Phase1
      int add = min((G - Sum) / (PA[i] + 1), P[PA[i]]);
      Ans0 += add;
      Sum += (PA[i] + 1) * add;
      // Phase2
      if (add == P[PA[i]])
        Sum += C[PA[i]];
      if (Sum >= G)
        break;
    }
    Ans = min(Ans, Ans0);
  } while (next_permutation(PA, PA + D));

  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 384
def nikkei2019_qual_b():
    n = int(input())
    a = input()
    b = input()
    c = input()

    count = 0
    for i in range(n):
        if a[i] == b[i] == c[i]:
            continue
        elif a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
            count += 1
        else:
            count += 2

    print(count)


nikkei2019_qual_b()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	vector<int> v(2);
	v[0] = n * a;
	v[1] = b;
	sort(v.begin(), v.end());
	cout << v[0];
}

Measured memory_bytes: 256
n = int(input())

tn = 0
xn = 0
yn = 0
j = True
for i in range(n):
    td, xd, yd = map(int, input().split())
    t = td - tn
    x = abs(xd - xn)
    y = abs(yd - yn)
    xn = xd
    yn = yd
    tn = td
    if t%2 == (x + y)%2 and (x + y) <= t:
        continue
    j = False
if j:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 73856
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);++i)
const int MOD = 1e9+7;

ll dp[100001][2];
int main() {
  string L; cin >> L;
  int N = L.size();

  rep(i, N+1)
    dp[i][0] = dp[i][1] = 0;

  dp[0][0] = 1;
  rep(i, N) {
    if (L[i] == '0') {
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1] * 3;
    } else {
      dp[i+1][0] += dp[i][0] * 2;
      dp[i+1][1] += dp[i][0] + dp[i][1] * 3;
    }
    dp[i+1][0] %= MOD;
    dp[i+1][1] %= MOD;
  }
  cout << (dp[N][false] + dp[N][true]) % MOD << endl;

  return 0;
}


Measured memory_bytes: 2048
n, k = map(int, input().split())
num = []
s = [input() for i in range(2*k)]

for i in range(1,n + 1):
  num.append(i)
  
for j in range(k):
  rm_tg = s[2*j+1].split()
  for m in range(int(s[2*j])):
    for sin in num:
      if sin == int(rm_tg[m]):
        num.remove(int(rm_tg[m]))

        
print(len(num))

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll Q;
ll func(ll a,ll b,ll n){
	ll ret=(a+n-1)*(b-(n-1));
	return ret;
}
ll fmax(ll a,ll b,ll from,ll to){
	ll mid=(b-a+2)/2;
	ll cmp1=max(func(a,b,from),func(a,b,to));
	ll cmp2=max(func(a,b,max(from,mid)),func(a,b,min(to,mid+1)));
	return max(cmp1,cmp2);
}

bool isOK(ll a,ll b,ll x){
	ll maxmul=0;
	if(x>=a&&x>=b){
		if(x+1-b<a-1){
			ll c1=fmax(1,x+1,1,x+1-b);
			ll c2=fmax(1,x,x+2-b,a-1);
			ll c3=fmax(2,x,a,x);
			maxmul=max(c1,max(c2,c3));
		}
		if(x+1-b==a-1){
			ll c1=fmax(1,x+1,1,a-1);
			ll c2=fmax(2,x,a,x);
			maxmul=max(c1,c2);
		}
		if(x+1-b>a-1){
			ll c1=fmax(1,x+1,1,a-1);
			ll c2=fmax(2,x+1,a,x+1-b);
			ll c3=fmax(2,x,x+2-b,x);
			maxmul=max(c1,max(c2,c3));
		}
	}
	if(x>=a&&x<b){
		ll c1=fmax(1,x,1,a-1);
		ll c2=fmax(2,x,a,x);
		maxmul=max(c1,c2);
	}
	if(x<a&&x>=b){
		ll c1=fmax(1,x+1,1,x+1-b);
		ll c2=fmax(1,x,x+2-b,x);
		maxmul=max(c1,c2);
	}
	if(x<a&&x<b){
		ll c=fmax(1,x,1,x);
		maxmul=c;
	}
	if(maxmul>=a*b) return true;
	else return false;
}
ll bin_search(ll a,ll b){
    ll ng=-1; 
    ll ok=1e10+3; 
    while (abs(ok-ng)>1) {
        ll mid=(ok+ng)/2;
        if (isOK(a,b,mid)) ok=mid;
        else ng=mid;
    }
    return ng;
}


int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>Q;

rep(i,Q){
	ll A,B;
	cin>>A>>B;
	if(A==1&&B==1){
		cout<<0<<endl;
	}
	else if(A==B){
		cout<<bin_search(A,B)+1<<endl;
	}else{
		cout<<bin_search(A,B)<<endl;
	}
}

}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define fastio 	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	fastio;

    string s;
    cin >> s;

    int cnt = 0;
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'S') cnt = 0;
        else cnt++;
        ans = max(ans, cnt);
    }
    cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,y=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++)
	    for(int j=0;j<=b;j++)
	        if(x-i*500-j*100>=0&&x-i*500-j*100<=c*50)
	            y++;
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int n; cin >> n;
	int k=(-1+sqrt(1+8*n))/2;
	int l = n-(k-1)*k/2;
	for(int i=k-1;i>0;i--)
	{
		int a=0;
		if( l-1>k )
		{
			a++;
			l--;
		}
		cout<<i+a<<endl;
	}
	cout<<l<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    string S;
    cin >> N >> S;
    ll ans = 1;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) {
            ans++;
        }
    }
    cout << ans << '\n';
}

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


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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    if (S=="SUN") cout << 7 << endl;
    else if (S=="MON") cout << 6 << endl;
    else if (S=="TUE") cout << 5 << endl;
    else if (S=="WED") cout << 4 << endl;
    else if (S=="THU") cout << 3 << endl;
    else if (S=="FRI") cout << 2 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
using namespace std;
using ll = long long;

ll w, h, x, y;
int main() {
	scanf("%lld %lld %lld %lld", &w, &h, &x, &y);
	printf("%lf %d\n", (w*h)/2.0, x*2==w && y*2==h);
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin
from collections import deque

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

s, t = list(map(str, stdin.readline().split()))
a, b = na()
u = ns()
if s==u:
    print(a-1, b)
else:
    print(a, b-1)


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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    rep(i, N) cin >> l[i];
    sort(l.rbegin(), l.rend());
    int total = 0;
    rep(i, K) total += l[i];
    cout << total << endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> dp(m+1,vector<ll>(n+1,0)),dp2(m+1,vector<ll>(n+1,0));
    dp2[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[0][i]=1;
    }
    for(int i=0;i<m;i++){
        for(int t=0;t<=n;t++){
            dp[i][t]%=MOD;
            dp2[i][t]%=MOD;
            if(t!=0){
                if(t!=1){
                    dp[i+1][t]+=dp[i][t];
                    dp[i+1][t-1]+=dp[i][t];
                }
                else{
                    dp2[i+1][t]+=dp[i][t];
                    dp2[i+1][t-1]+=dp[i][t];
                }
                dp2[i+1][t]+=dp2[i][t];
                dp2[i+1][t-1]+=dp2[i][t];
            }
            if(t!=n){
                dp[i+1][t]+=dp[i][t];
                dp[i+1][t+1]+=dp[i][t];
                dp2[i+1][t]+=dp2[i][t];
                dp2[i+1][t+1]+=dp2[i][t];
            }
        }
    }
    ll ans=0;
    for(auto &I:dp2[m]){(ans+=I)%=MOD;}
    cout<<ans<<endl;
    

    return 0;
}


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int main(){
	int a[3],K;
	rep(i,3)cin>>a[i];
	cin>>K;
	int cnt=0;
	for(int i=1;i<3;i++){
		while(a[i-1]>=a[i]){
			a[i]*=2;cnt++;
		}
	}
	if(cnt<=K)puts("Yes");
	else puts("No");
}

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

namespace AtCoder.DP
{
    class EDPC_P
    {
        static int mod = 1000000007;

        class Node
        {
            public List<int> Next = new List<int>();
            public int Number;
            public int Parent;
            public long BlackN;
            public long WhiteN;
            public Node(int number)
            {
                Number = number;
            }
        }

        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            if (n == 1)
            {
                Console.WriteLine(2);
                return;
            }

            var nodes = new Node[n];

            for (int i = 0; i < n - 1; i++)
            {
                var xy = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray();
                if (nodes[xy[0]] == null)
                    nodes[xy[0]] = new Node(xy[0]);
                if (nodes[xy[1]] == null)
                    nodes[xy[1]] = new Node(xy[0]);
                nodes[xy[0]].Next.Add(xy[1]);
                nodes[xy[1]].Next.Add(xy[0]);
            }

            var sorted = new int[n];
            var queue = new Queue<int>();
            queue.Enqueue(0);

            int m = n - 1;
            while (queue.Any())
            {
                var i = queue.Dequeue();
                sorted[m--] = i;
                foreach (var next in nodes[i].Next)
                {
                    if (next == nodes[i].Parent)
                        continue;
                    nodes[next].Parent = i;
                    queue.Enqueue(next);
                }
            }

            nodes[0].Parent = -1;
            nodes[0].Next.Add(-1);
            for (int i = 0; i < n; i++)
            {
                var node = nodes[sorted[i]];
                node.WhiteN = 1;
                node.BlackN = 1;

                if (node.Next.Count == 1)
                    continue;

                foreach (var next in node.Next)
                {
                    if (next == node.Parent)
                        continue;
                    node.WhiteN = node.WhiteN * ((nodes[next].WhiteN + nodes[next].BlackN) % mod) % mod;
                    node.BlackN = node.BlackN * (nodes[next].WhiteN % mod) % mod;
                }
            }
        
            Console.WriteLine((nodes[0].BlackN + nodes[0].WhiteN) % mod);
        }
    }
}


Measured memory_bytes: 34116
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream f("A.in");
ofstream g("A.out");
typedef long long ll;
typedef pair<int,int> pi;
int t,T;
const int dim=2e5+10;
int viz[dim],n,m,a,b,ans;

vector  < int > V[dim];

int BFS(int start)
{
    int nodes=0;
    queue < int > qu;
    viz[start]=1;
    qu.push(start);
    while(!qu.empty())
    {
        int nod=qu.front();
        nodes++;

        qu.pop();

        viz[nod]=2;

        for(unsigned int i=0;i<V[nod].size();i++)
        {
            int vecin=V[nod][i];
            if(!viz[vecin])
            {
                viz[vecin]=1;
                qu.push(vecin);
            }
        }
    }
    return nodes;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a>>b;
        V[a].pb(b);
        V[b].pb(a);
    }
    for(int i=1;i<=n;i++)
    if(!viz[i])
    {
        ans=max(ans,BFS(i));
    }
    cout<<ans;

    return 0;
}


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

#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int a[N];
map<int, int> b;
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    long long res = 0;
    for(int i = 1; i <= n; i ++){
        res += b[i - a[i]];
        b[a[i] + i] ++;
    }
    cout << res << "\n";
}


Measured memory_bytes: 21444
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    S = [input().rstrip()[::-1] for i in range(N)]
    S.sort(key=len)
    P = 2**61 - 1

    from collections import defaultdict
    D = defaultdict(lambda: [0]*26)

    ans = 0
    for s in S:
        l = ord(s[-1]) - ord('a')
        a = 0
        tmp = [0] * 26
        for c in s[:-1]:
            i = ord(c) - ord('a')
            if a in D:
                for j in range(26):
                    tmp[j] += D[a][j]
            ans += tmp[i]
            tmp[i] = 0
            a = (a*27 + i + 1) % P
        ans += tmp[l]
        D[a][l] += 1

    print(ans)
solve()

Measured memory_bytes: 73128
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

//素集合データ構造
// ref:https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
struct union_find {
    // parent[v]==w(>=0):vの親はw
    // parent[v]==k(<0):vは根&&vの属するグループの要素数は-k
    vector<long long int> parent;
    //コンストラクタ
    union_find(long long int n) {
        parent.assign(n, -1);
    }
    // vの根を求める
    //求めると同時に親を根に置き換える(木の圧縮)
    long long int root(long long int v) {
        if (parent[v] < 0) {
            return v;
        } else {
            parent[v] = root(parent[v]);
            return parent[v];
        }
    }
    // vが属するグループの要素数を求める
    long long int size(long long int v) {
        return -parent[root(v)];
    }
    // vとwを繋げる
    void unite(long long int v, long long int w) {
        v = root(v);
        w = root(w);
        if (v == w) return;
        if (parent[v] < parent[w]) swap(v, w);
        parent[w] += parent[v];
        parent[v] = w;
    }
    // vとwが同値か判定
    bool isSame(long long int v, long long int w) {
        return root(v) == root(w);
    }
};

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

int n, m;

int main() {
    cin >> n >> m;
    union_find uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int sz = uf.size(i);
        chmax(ans, sz);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4772
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		List<Character> ans = new ArrayList<>();
		
		char[] chas = s.toCharArray();
		
		for(int i=1, len=s.length(); i<len+1; i++ ) {
			if(i % 2 != 0) {
				ans.add(chas[i-1]);
			}
		}
		
		for(char item: ans) {
			System.out.print(item);
		}
		
		
		sc.close();
	}
}


Measured memory_bytes: 30396
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    int n;
    cin>>n;
    int f=n/100;
    int b=n%100;
    bool f_ok = 0 < f && f < 13;
    bool b_ok=  0 < b && b < 13;
    if(f_ok){
        if(b_ok){
            cout<<"AMBIGUOUS";
        }
        else{
            cout<<"MMYY";
        }
    }
    else{
        if(b_ok){
            cout<<"YYMM";
        }
        else{
            cout<<"NA";
        }
    }
}
/*

*/


Measured memory_bytes: 3564
n, k = map(int, input().split())
P = list(map(int, input().split()))

me = [0]
for i in range(n):
    p = (P[i] * (P[i] + 1) / 2) / P[i]
    me.append(me[(i+1)-1]+p)

ans = 0
for i in range(k, n+1):
    ans = max(ans, me[i]-me[i-k])
print(ans)


Measured memory_bytes: 24556
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=2e5+10;
int n,a[N];
set<pii >S;
//
bool check(int x){
	S.clear();
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1])continue;
		if(a[i]<=a[i-1]){
			bool ok=false;
			set<pii >::iterator it=S.upper_bound(mp(a[i]-1,INF));
			while(it!=S.end()){
				S.erase(it);
				it=S.upper_bound(mp(a[i]-1,INF));
			}
			for(int j=a[i]-1;j>=0;j--){
				it=S.lower_bound(mp(j,-INF));
				if(it==S.end()){
					if(x==1)return false;
					S.insert(mp(j,1));
					ok=true;
					break;
				}
				if(it->second==x-1){
					S.erase(it);
					continue;
				}
				else{
					int x=it->second;
					S.erase(it);
					S.insert(mp(j,x+1));
					ok=true;
					break;
				}
			}
			if(!ok)return false;
		}
	}
	return true;
}
int main(){
    n=getint();
	rep(i,n)a[i]=getint();
	int lb=0,rb=n;
	while(rb-lb>1){
		int mid=(lb+rb)>>1;
		if(check(mid))rb=mid;
		else lb=mid;
	}
	printf("%d\n",rb);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt(); 
            int f = sc.nextInt(); 
            int r = sc.nextInt(); 
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1){
                System.out.println("F");
            }else if(m+f >= 80){
                System.out.println("A");
            }else if(m+f >= 65){
                System.out.println("B");
            }else if(m+f >= 50){
                System.out.println("C");
            }else if(m+f >= 30){
                if(r >= 50){
                    System.out.println("C");
                }else{
                System.out.println("D");                                
                }
            }else{
                System.out.println("F");
            }
        }
    }
}


Measured memory_bytes: 26432
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

const int MAX = 200005;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    ll x = (M * N * (M + N) * (M * N - 1)) / 6;
    x %= MOD;
    if (K == 2) {
        cout << x << endl;
        return 0;
    }
    else {
        COMinit();
        ll y = COM(M * N - 2, K - 2);
        cout << (x * y) % MOD << endl;
        return 0;
    }

}


Measured memory_bytes: 4992
import math
while True:
    n=int(input())
    if n==0:
        break
    else:
        x=math.factorial(n)
        y=str(x)
        l=len(y)
        s=0
        for i in range(l-1,-1,-1):
            if y[i]=="0":
                s+=1
            else:
                break
        print(s)


Measured memory_bytes: 5828
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int N;
string S;
vi A;

void dfs(int x, int depth){
	if(x > N) return;

	int a = x;
	set<int> s;
	while(a){
		s.insert(a%10);
		if(s.size()==3) break;
		a/=10;
	}

	if(s.size()==3) A.push_back(x);

	if(depth >= S.size()) return;

	dfs(x*10+3, depth+1);
	dfs(x*10+5, depth+1);
	dfs(x*10+7, depth+1);
}

int main(){
	cin>>S;
	N = stoi(S);
	dfs(0,0);
	ote(A.size());
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<lld,int> Pd;
typedef pair<lld,lld> P;
#define INF ((lld)1<<50)

int main(){
  int n,m; cin >> n >> m;
  int A[5010],B[5010];
  for(int i=0;i<n;i++) cin >> A[i];
  for(int i=0;i<m;i++) cin >> B[i];
  int ret = 0;
  for(int i=0;i<m;i++){
    int cnt = 0;
    int now = i;
    for(int j=0;j<n;j++){
      if(B[now] == A[j]){
	now++;
	cnt++;
      }
    }
    ret = max(ret,cnt);
  }
  cout << ret << endl;
}

Measured memory_bytes: 1200
import Control.Applicative
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readIntBS = fst . fromJust . BS.readInt

main :: IO ()
main = do
  
  [n,x] <- map read . words <$> getLine :: IO [Int]
  xs <- map (abs . (+ (-x)) . readIntBS) . BS.words <$> BS.getLine :: IO [Int]

  print $ foldl1 gcd xs


Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

const int maxn = 1234;

int main(int argc, char const *argv[])
{
    // freopen("input.txt", "r", stdin);
    ll A, B, K;
    cin>>A>>B>>K;
    if(A<=K)K-=A, A=0;
    else A-=K, K=0;
    // cout<<K<<endl;
    if(B<=K)K-=B, B=0;
    else B-=K;
    cout<<A<<" "<<B<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

long min(long a, long b){
  if(a < b) return a;
  else return b;
}

int f(long a,long b){

  long c = max(a,b);
  int keta = 1;
  for(int i = 0; i < 10; ++i){
    if( c/10 > 0 ){
      keta ++;
      c /= 10;
    }
  }
  return keta;
}

int main(){

  long n;
  int minimum = 11;
  scanf("%ld",&n);
  for(long a = 1; a*a <= n ; ++a){
    long b = 0;
    if( n % a == 0 ){
      b = n/a;
      b = f(a,b);
      minimum = min(minimum,b);
    }
  }
  printf("%ld",minimum);
  return 0;

}


Measured memory_bytes: 128
def solve():
  size = 101
  n = int(input())
  points = []
  for _ in range(n):
    x, y, h = map(int, input().split())
    # h=0の点はスキップ ←勾配がないので高さ計算に使えない
    if h == 0: continue
    else: points.append((x, y, h))

  if len(points) == 1:
    # 必ず頂上が1つに定まる制約なので、測定点が1つしかなければそれが答え
    ans = points[0]
    return ans

  ans = (-1, -1, -1)
  for i in range(size):
    for j in range(size):
      # 高いほうに持ち上げるよう試みて、整合性とれなければ却下
      max_h = None
      succ = True
      for x, y, h in points:
        tmp = abs(i-x) + abs(j-y) + h
        if max_h == None:
          max_h = tmp
          continue
        else:
          if max_h != tmp:
            succ = False
            break
      # 成り立っているなかでの最高点を更新していく
      if succ:
        if ans[2] < max_h:
          ans = (i, j, max_h)
  # すべて終了
  return ans

ans = solve()
print('{} {} {}'.format(ans[0], ans[1], ans[2]))

Measured memory_bytes: 3064
n=int(input())
inpt=list(map(int,input().split()))
inpv=list(map(int,input().split()))

t=inpt+[0]
v=inpv+[0]

T=sum(t)
M=[0]

nowt=2*t[0]
nowmaxv=v[0]
nowv=M[0]
i=0

for time in range(2*T):
    if nowv+0.5<=v[i]:
        M.append(nowv+0.5)
    else:
        M.append(nowv)
    nowt-=1
    nowv=M[-1]
    if nowt==0:
        i+=1
        nowt=2*t[i]
        nowmaxv=v[i]
        nowv=min(nowv,nowmaxv)
        
t=list(reversed(inpt))+[0]
v=list(reversed(inpv))+[0]
m=[0]

nowt=2*t[0]
nowmaxv=v[0]
nowv=M[0]
i=0

for time in range(2*T):
    if nowv+0.5<=v[i]:
        m.append(nowv+0.5)
    else:
        m.append(nowv)
    nowt-=1
    nowv=m[-1]
    if nowt==0:
        i+=1
        nowt=2*t[i]
        nowmaxv=v[i]
        nowv=min(nowv,nowmaxv)

ans=[min(M[i],m[-i-1]) for i in range(len(M))]
print(sum([min(ans[i],ans[i+1])+(ans[i+1]-ans[i])**2 for i in range(len(ans)-1)])/2)

Measured memory_bytes: 4932
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, flag = 0;
  scanf("%d", &n);
  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      if (i * j == n)
        flag = 1;
    }
  }
  puts(flag == 0 ? "No" : "Yes");
}

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

#define int long long


signed main()
{
    string s;
    string left = "qwertasdfgzxcvb";
    while(cin>>s, s!="#") {
        int f = -1;
        int cnt = 0;
        for(int i=0; i<s.size(); ++i) {
            int lf = 0;
            auto iter = find(left.begin(), left.end(), s[i]);
            if(iter!=left.end()) lf = 1;
            if(f==-1) f = lf;
            else {
                if(f!=lf) {
                    f = lf;
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3164
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    a,b = LI()
    print(a*b)


if __name__ == '__main__':
    main()

Measured memory_bytes: 68976
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n = sc.nextInt();
        sc.nextLine();
        int[] L = toArray(sc.nextLine());
        System.out.println(solve(n, L));
    }

    private static int solve(int n, int[] L) {
        Arrays.sort(L);
        int sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                int sup = L[i] + L [j];
                int inf = L[j] - L[i];
                int last = Math.max(getFirstElement(L, sup),j);
                int first = Math.max(getLastElement(L, inf), j);
                sum += Math.max(0, last - first -1);
            }
        }
        return sum;
    }

    private static int getFirstElement(int[] L, int val) {
        int idx = Arrays.binarySearch(L, val);
        if(idx < 0) return -idx-1;
        while (idx >= 1 && L[idx] == L[idx-1]) {
            idx--;
        }
        return idx;
    }

    private static int getLastElement(int[] L, int val) {
        int idx = Arrays.binarySearch(L, val);
        if(idx < 0) return -idx-1;
        while (idx < L.length-1 && L[idx] == L[idx+1]) {
            idx++;
        }
        return idx;
    }

    private static int[] toArray(String line) {
        return Arrays.stream(line.split(" ")).filter(l -> !"".equals(l)).mapToInt(Integer::valueOf).toArray();
    }
}

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

#define ii pair<int,int> 
const int MAXN = 1005;

int n, m, ans, dist[MAXN][MAXN];
int adjR[] = {1, 0, -1, 0}, adjC[] = {0, 1, 0, -1};
string grid[MAXN];
bool visited[MAXN][MAXN];
queue<ii> lis;

bool out(ii v){
	return (v.first < 0 || v.first >= n || v.second < 0 || v.second >= m);
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 0; i < n; ++i){
		cin >> grid[i];
		for(int j = 0; j < m; ++j){
			if(grid[i][j] == '#'){
				lis.push(ii(i, j));
				visited[i][j] = true;
			}
		}
	}
	while(!lis.empty()){
		ii top = lis.front(); lis.pop();
		for(int i = 0; i < 4; ++i){
			ii nex = ii(top.first+adjR[i], top.second+adjC[i]);
			if(out(nex) || visited[nex.first][nex.second])
				continue;
			visited[nex.first][nex.second] = true;
			dist[nex.first][nex.second] = dist[top.first][top.second]+1;
			lis.push(nex);
		}
	}
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			ans = max(ans, dist[i][j]);
		}
	}
	printf("%d\n", ans);
}

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

#define ll long long
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fr1(i,b,a) for(int i=b;i>=a;i--)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
long double infd=1.0/0.0;
const double pi=2*acos(0.0);
const int MOD=1e9+7;

int main(){
    nimble;
    int tt=1;//cin>>tt;
    while(tt--){
        int a,b;
        cin>>a>>b;
        if(a>b)
            swap(a,b);
        if(a==2){
            cout<<1;
            return 0;
        }
        if(a==1&&b==2){
            cout<<3;
            return 0;
        }
        if(a==1&&b==3){
            cout<<2;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[5],tmp,i,j;
  for(i=0;i<5;i++)scanf("%d",&a[i]);
  for(i=0;i<4;i++){
    for(j=4;j>i;j--){
      if(a[j]>a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
    }
  }
  printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    /*
    レート 1-399：灰色
    レート 400-799：茶色
    レート 800-1199：緑色
    レート 1200-1599：水色
    レート 1600-1999：青色
    レート 2000-2399：黄色
    レート 2400-2799：橙色
    レート 2800-3199：赤色
    */
    
    int result[9] = {};
    
    int n;
    cin >> n;
    
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        result[min(a/400,8)]++;
    }
    
    int res = 0;
    for(int i = 0; i < 8; i++){
        res += (!(!(result[i])));
    }
    
    cout << max(res,1) << " " << res+result[8] << endl;
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPEQ(i, n) FOREQ(i, 0, n)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline int size(const T& x) { return x.size(); }
typedef long long ll;

ll calc(ll n) {
  ll n_3 = 0, n_5 = 0, n_15 = 0, len = 0;
  for (ll i = 1, j = 10; ; ++i, j *= 10) {
    ll k = min(j - 1, n);
    ll m_3 = k / 3 - n_3, m_5 = k / 5 - n_5, m_15 = k / 15 - n_15;
    len += 4 * (m_3 + m_5);
    len += i * (k - j / 10 + 1 - m_3 - m_5 + m_15);
    n_3 = k / 3; n_5 = k / 5; n_15 = k / 15;
    if (j > n) break;
  }
  return len;
}

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

  ll s;
  while (cin >> s) {
    ll lo = 1, hi = 1e18;
    while (lo < hi) {
      ll m = (lo + hi) / 2;
      if (calc(m) < s)
        lo = m + 1;
      else
        hi = m;
    }

    string ans;
    REP(i, 21) {
      ll j = lo + i;
      if (j % 15 == 0)
        ans += "FizzBuzz";
      else if (j % 3 == 0)
        ans += "Fizz";
      else if (j % 5 == 0)
        ans += "Buzz";
      else {
        char str[1024];
        sprintf(str, "%lld", j);
        ans += str;
      }
    }
    ll len = calc(lo - 1);
    cout << ans.substr(s - len - 1, 20) << endl;
  }
}

Measured memory_bytes: 1244
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 3e4 + 100;
int n;
int p[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
    p[i]--;
  }
  return true;
}

int a[maxn], b[maxn];

void solve() {
  for (int i = 0; i < n; i++) {
    a[i] = 3e4 * i + 10;
    b[i] = 3e4 * (n - i) + 10;
  }
  for (int i = 0; i < n; i++) {
    a[p[i]] += i;
  }
  for (int i = 0; i < n; i++) {
    printf("%d%c", a[i], " \n"[i == n - 1]);
  }
  for (int i = 0; i < n; i++) {
    printf("%d%c", b[i], " \n"[i == n - 1]);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

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

int main(){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
}


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


int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    if(N % 2 != 0){
        cout << "No" << endl;
    }
    else{
        bool flag = true;
        for(int i = 0; i < N/2; ++i){
            if(S[i] != S[i + N/2]) flag = false;
        }
        if(flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// atcoder/abc17173/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    if (n % 1000) cout << 1000 - n % 1000 << endl;
    else cout << 0 << endl;
  }

  return 0;
}


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;

void solve(){
   long long  x;
   cin>>x;
   vector<long long >v(x+1);
   v[0]=2;
   v[1]=1;
   for(long long i=2;i<=x;i++)
        v[i]=v[i-1]+v[i-2];
   cout<<v[x];
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<b){
    for(int i=0;i<b;i++){
		cout<<a;
    }
   }else{
     for(int i=0;i<a;i++){
       cout<<b;
     }
   }
  cout<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

vector<string> s;
vector<vector<int>> G;
int n;
bool is_bipartite_graph(int v, int d) {
	static vector<int> depth;
	if (depth.size() == 0) {
		depth.resize(n, -1);
	}
	if (depth[v] != -1) return depth[v] == d;
	depth[v] = d;
	rep2(nv, G[v]) {
		if (!is_bipartite_graph(nv, d ^ 1))return false;
	}
	return true;
}
int main() {
	cin >> n;
	s.resize(n);
	G.resize(n);
	rep(i, 0, n) {
		cin >> s[i];
		rep(i2, 0, s[i].size()) {
			if (s[i][i2] == '1')G[i].push_back(i2);
		}
	}
	if (!is_bipartite_graph(0, 0)) {
		puts("-1");
		return 0;
	}
	vector<vector<int>> w(n, vector<int>(n, INF));
	rep(i, 0, n)w[i][i] = 0;
	rep(i, 0, n)rep2(v, G[i])w[i][v] = w[v][i] = 1;
	int ans = 0;
	rep(k, 0, n) {
		rep(s, 0, n) {
			if (w[s][k] == INF)continue;
			rep(e, 0, n) {
				if (w[k][e] == INF)continue;
				w[s][e] = min(w[s][e], w[s][k] + w[k][e]);
			}
		}
	}
	rep(s, 0, n)rep(e, 0, n)ans = max(ans, w[s][e]);
	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 4036
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]) {
    val n = sc.nextInt
    val s = sc.next
    var (leftE, rightW) = (0, s.count(_ == 'W'))
    var max = leftE + rightW
    for (i <- 0 until n) {
      s(i) match {
        case 'E' => leftE += 1
        case 'W' => rightW -= 1
      }
      max = math.max(max, leftE + rightW)
    }
    println(n - max)
  }
}


Measured memory_bytes: 31528
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int main()
{
	char S[4] = {0};
	scanf("%s", S);

	int i = 0;
	int count = 0;
	int flag = 0;
	if (S[0] == 'S') {
		flag = 1;
	} else {
		count = 1;
		flag = 2;
	}
	for (i = 1; i < 3; i++) {
		if (S[i] == 'S') {
			flag = 1;
		} else if ((S[i] == 'R') && (flag == 2)) {
			count++;
			flag = 2;
		} else if ((S[i] == 'R') && (flag ==1)) {
			if (count != 2) {
				count = 1;
			}
		    flag = 2;
		}
	}
	printf("%d\n", count);
	//yesno(ans);
	//okng(ans);
	return 0;
}


Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c;
	int x, y;
	cin>>a>>b>>c>>x>>y;
	c*=2;

	int ans;
	if(a+b<c) {
		ans=a*x+b*y;
	}
	else {
		if(x>y)ans=min(c*y+a*(x-y),c*x);
		else ans=min(c*x+b*(y-x),c*y);
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    int login=0;
    cin >> a >> b >> c;
    rep(i,1000000){
        if(c-a>0){ c-=a; login++;}
        else{ login++; break; }
    
        if(c-b>0){
            if((i+1)%7==0) c-=b;
        }else{
            if((i+1)%7==0) break;
        }    
    }
    cout << login <<endl;
}



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


int main(){
    int A,B,C;
    cin >> A >>B >> C;
    auto a=A;
    auto b=B;
    auto c=C;
    if(a==b){
        printf("%d\n",c);
    }
    else if(b==c){
        printf("%d\n",a);
    }
    else printf("%d\n",b);
}


Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al = sorted(al, reverse=True)
bl = sorted(bl, reverse=True)
cl = sorted(cl, reverse=True)
q = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
ans = [[al[0] + bl[0] + cl[0], 0, 0, 0]]
c = -1
#while True:
    #c += 1
for i in range(d):
    #print(c)
    #print(len(ans))
    s, aq, bq, cq = map(int, q.pop())
    if len(al) > aq+1:
        if [al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq] not in ans:
            q.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])
            ans.append([al[aq+1] + bl[bq] + cl[cq], aq+1, bq, cq])

    if len(bl) > bq+1:
        if [al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq] not in ans:
            q.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])
            ans.append([al[aq] + bl[bq+1] + cl[cq], aq, bq+1, cq])

    if len(cl) > cq+1:
        if [al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1] not in ans:
            q.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])
            ans.append([al[aq] + bl[bq] + cl[cq+1], aq, bq, cq+1])

    q = sorted(q)

    #if len(ans) > d:
    #    ans = sorted(ans, reverse=True)
    #    if ans[d-1][0] > q[len(q)-1][0]:
    #       break

ans = sorted(ans, reverse=True)
for i in range(d):
    print(ans[i][0])


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

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 100005;
const int MOD = 1e9 + 7;

int n, m;
vector <int> s[10];
int p[10];

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x; cin >> x; s[i].resize(x);
        for (int &j : s[i]) cin >> j, j--;
    }
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }
    int res = 0;
    for (int i = 0; i < (1 << n); i++) {
        vector <int> cur(n);
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cur[j] = 1;
            } else {
                cur[j] = 0;
            }
        }
        int ok = 1;
        for (int j = 0; j < m; j++) {
            int cnt = 0;
            for (int k : s[j]) {
                cnt += cur[k];
            }
            if (cnt % 2 != p[j]) {
                ok = 0; break;
            }
        }
        res += ok;
    }
    cout << res << endl;
    return 0;
}


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

ll f(vector<P> p) {
  int n = p.size();
  rep(i,n) p[i].first = min(p[i].first, n);
  vector<vector<int>> s(n+1);
  rep(i,n) s[p[i].first].push_back(p[i].second);

  ll res = 0;
  priority_queue<int> q;
  for (int i = n; i >= 1; --i) {
    for (int x : s[i]) q.push(x);
    if (q.size() > 0) {
      res += q.top();
      q.pop();
    }
  }
  return res;
}

void solve() {
  int n;
  cin >> n;
  vector<P> pl, pr;
  ll ans = 0;
  rep(i,n) {
    int k, l, r;
    cin >> k >> l >> r;
    int m = min(l,r);
    ans += m;
    l -= m; r -= m;
    if (l > 0) pl.emplace_back(k,l);
    else pr.emplace_back(n-k,r);
  }
  ans += f(pl);
  ans += f(pr);
  cout << ans << endl;
}

int main() {
  int ts;
  cin >> ts;
  rep(ti,ts) solve();
  return 0;
}


Measured memory_bytes: 10504