akhauriyash/Code-Regression huggingface dataset:
N  = int (input())
As = [int(input()) for _ in range(N)]
# print(As)
As.sort()
if N == 1:
    print(0)

#小さい方から配置

elif N == 2:
    print(abs(As[0] - As[1]))
else:
    bottom_ind = 1
    upper_ind = N - 1

    l = r = As[0]

    MA = 1
    MI = 0
    mode = MA

    ans1 = 0
    while True:
        if mode == MA: #上から取る
            next1 = As[upper_ind]
            next2 = As[upper_ind -1]
            ans1 += max(abs(next1 - l ) + abs(next2 - r ),abs(next2 - r ) + abs(next1 - l ))
            r =  next1
            l = next2
            m = upper_ind  - 2
            upper_ind -= 2
            mode = MI

        else:
            next1 = As[bottom_ind]
            next2 = As[bottom_ind + 1]
            ans1 += max(abs(next1 - l) + abs(next2 - r), abs(next2 - r) + abs(next1 - l))
            m = bottom_ind + 2
            bottom_ind+= 2
            r = next1
            l = next2
            mode = MA #下から取る
        if bottom_ind >= upper_ind:
            break
    if N % 2 == 0:
        # m = As[N//2]
        m = As[m]
        ans1 += max( abs(m - l) ,abs(m - r))


    #大きい方から配置

    bottom_ind = 0
    upper_ind = N - 2

    l = r = As[N - 1]


    mode = MI

    ans2 = 0
    while True:
        if mode == MA: #上から取る
            next1 = As[upper_ind]
            next2 = As[upper_ind -1]
            ans2 += max(abs(next1 - l ) + abs(next2 - r ),abs(next2 - r ) + abs(next1 - l ))
            r =  next1
            l = next2
            m = upper_ind  - 2
            upper_ind -= 2
            mode = MI

        else:
            next1 = As[bottom_ind]
            next2 = As[bottom_ind + 1]
            ans2 += max(abs(next1 - l) + abs(next2 - r), abs(next2 - r) + abs(next1 - l))
            m = bottom_ind + 2
            bottom_ind+= 2
            r = next1
            l = next2
            mode = MA #下から取る
        if bottom_ind >= upper_ind:
            break
    if N % 2 == 0:
        # m = As[N//2]
        m = As[m]
        ans2 += max( abs(m - l) ,abs(m - r))





    print(max(ans1,ans2))

Measured memory_bytes: 51672
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N =int.Parse(ReadLine());
        var A =ReadLine().Split().Select(int.Parse).ToArray();
var ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if(i!=j)
                {
                    ans=Math.Max(Math.Abs(A[i]-A[j]),ans);
                }
            }
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
  int a[3];
  scanf("%d", &a[0]);
  scanf("%d", &a[1]);
  scanf("%d", &a[2]);
  if((a[0]+a[1]+a[2])>=22)
  {
    printf("bust");
  }
  else
  {
    printf("win");
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<deque>
#include<vector>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
#include<unordered_set>
//~ #include<unordered_map>
#include<stack>
 
#define pi 3.141592653
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt","w",stdout);
#define ii pair<int,int> 
#define fast_io cin.tie(0), cin.sync_with_stdio(false);
#define inf 0x3f3f3f3f
#define sup_inf 1e18
#define f first
#define s second
#define eps 1e-9

#define nl ( no << 1)
#define nr ( no << 1)|1
#define mid l+(( r-l)>>1)
 
using namespace std;
typedef long long ll;	
typedef long double ld;
typedef unsigned long long ull;
typedef  pair< long long , pair< int,int> > iii;

const int maxn = 2e5 + 100; 
const int MAX = 1010;
const int mod = 1e9 + 7;
const int MAXLV = 16;
 

using namespace std;

int main () {
  string str;
  cin >> str;
  int ans = 0;
  for(int i = 0;str[i];i++) {
   ans += ( str[i] - '0');
  }
  if ( ans % 9 == 0 ){
   cout << "Yes\n";
  }else {
   cout << "No\n";
  }
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int a,b;
  cin >> a >> b;
  if(a > b) swap(a,b);
  if(a == 1 & b == 2) cout << 3 << endl;
  else if(a == 1 & b == 3) cout << 2 << endl;
  else if(a == 2 & b == 3) cout << 1 << endl;
}


Measured memory_bytes: 3628
from bisect import bisect_right

def main():
    N = int(input())
    L = list(map(int, input().split()))
    sort_L = sorted(L)
    ans = 0
    for i in range(N-2):
        for j in range(i,N-1):
            if i == j:
                continue
            ok = j
            ng = N
            tmp = sort_L[i] + sort_L[j]
            while abs(ok - ng) > 1:
                mid = (ok + ng) // 2
                if sort_L[mid] < tmp:
                    ok = mid
                else:
                    ng = mid

            ans += ok - j

    print(ans)



if __name__ == "__main__":
    main()

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

int main(){
  int N;
  cin >> N;
  if(N>=195) cout << 5 << endl;
  else if(N>=189) cout << 4 << endl;
  else if(N>=165) cout << 3 << endl;
  else if(N>=135) cout << 2 << endl;
  else if(N>=105) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 764
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    char game[2000];
    while(cin>>game){
        int A=0,B=0;
        if(game[0]=='0')break;
        for(int i=1;i<strlen(game);i++){
            if(game[i]=='A')A++;
            else if(game[i]=='B')B++;
        }
        if(A>B)cout<<A+1<<" "<<B<<endl;
        else if(A<B)cout<<A<<" "<<B+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,y,ans=0;
  cin >> n >> x >> y;
  vector<int>a(n);  
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      a.at(min(j-i,abs(j-y)+abs(x-i)+1))++;
    }
  }
  for(int i=1;i<n;i++)cout <<a.at(i)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int N;
    cin >> N;
 
    int a[55] = {
        11, 31, 41, 61, 71, 101, 131, 151, 181, 191,
        211, 241, 251, 271, 281, 311, 331, 401, 421, 431,
        461, 491, 521, 541, 571, 601, 631, 641, 661, 691,
        701, 751, 761, 811, 821, 881, 911, 941, 971, 991,
        1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231,
        1291, 1301, 1321, 1361, 1381
    };
 
    for (int i = 0; i < N; ++i) cout << a[i] << " ";
    cout << endl;
 
    return 0;
}

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

int main () {
    int x;
    int num = 0;
    string S;
    for (int i = 0; i < 5; i++) {
	    cin >> x;
        if (x == 0) { num = i+1; }
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

const int MOD = 1000000007;
int main() {
    string t, s; cin >> s >> t;

    ll replace = s.size();
    rep(i, s.size() - t.size()+1) {
        ll count = 0;
        rep(j, t.size()) {
            if (t[j] == s[i+j]) count++;
        }
        ll rem = t.size() - count;
        replace = min(replace, rem);
    }
    cout << replace << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}

void out(vector<int> &v){
	for(int x : v) cout << x << " ";
}
void solve()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	int a[n];
	int x = 0, y = 0;
	int ans[h][w];
	bool rv = 0;
	rep(i, n) {
		cin >> a[i];
		while(a[i]--){
			ans[x][y] = i + 1;
			y += (!rv ? 1 : -1);
			if(y == w) y--, rv ^= 1, x++;
			if(y == -1) y++, rv ^= 1, x++;
		}
	}
	rep(i, h) rep(j, w) cout << ans[i][j] << " \n"[j == w - 1];

}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

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

int main(){
   int i,n,a[3],w,total,sum;
   int big[] = {60,80,100,120,140,160,0};
   int wai[] = {2,5,10,15,20,25,0};
   int price[] = {600,800,1000,1200,1400,1600,0};
   bool judge;
   while(cin >> n,n){
      sum = 0;
      while(n--){
         cin >> a[0] >> a[1] >> a[2] >> w;
         total = a[0] + a[1] + a[2];
         for(i=0;i<6;i++,judge = false){
            if(total > big[i]) judge = true;
            if(w > wai[i]) judge = true;
            if(!judge) break;
         }
         sum += price[i];
      }
      cout << sum << endl;
   }
}

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

int main() {
    //入力
    double n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int ans = 0;
        // x
        rep(x,n) {
            // y
            if (x*x + x + 4 > i) break;
            rep(y, n) {
                if (x*x + y*y + x*y + x + y + 1 > i) break;
                else if ((double)i -3*(x*x+y*y)/4 - x*y/2 <= 0) break;
                // z
                double z = - (x + y)/2 + sqrt((double)i -3*(x*x+y*y)/4 - x*y/2);
                if (z == (int)z) ans++;
            }
        }
        cout << ans << endl;
    } 
    return 0;
}

Measured memory_bytes: 3684
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 1e5 + 7;
const ld pi = 3.14159265359;
const int INF = (1 << 20) + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

ll n, a[N], mx, mn;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> n;
  
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  mx = *max_element(a + 1, a + 1 + n);
  mn = *min_element(a + 1, a + 1 + n);

  cout << mx - mn;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include <stdlib.h>
#define M 100000
using namespace std;
  
int main(){
    int n, m,l = 0;
    int pos = 0;
    int ans = 0;
    int x[100010];
    scanf("%d %d",&n,&m);
    x[0] = 0;
    for (int i = 1; i < n; i++){
        scanf("%d", &x[i]);
        x[i] += x[i - 1];
    }
    while (m--){
        scanf("%d", &l);
        ans += abs(x[pos + l] - x[pos]);
        ans %= M;
        pos += l;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	ll n; cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	sort(a.begin(), a.end());

	deque<ll> d1, d2, d3, d4;

	int l = 0, r = n-1;
	while(l < r){
		d1.push_back(a[l]);
		++l;
		if(l == r) break;
		d1.push_back(a[r]);
		--r;
	}
	d3 = d1;
	d1.push_front(a[l]);
	d3.push_back(a[l]);

	l = 0, r = n-1;
	while(l < r){
		d2.push_back(a[r]);
		--r;
		if(l == r) break;
		d2.push_back(a[l]);
		++l;
	}
	d4 = d2;
	d2.push_front(a[l]);
	d4.push_back(a[l]);

	ll a1 = 0, a2 = 0, a3 = 0, a4 = 0;
	for(int i = 1; i < n; ++i) a1 += abs(d1[i] - d1[i-1]);
	for(int i = 1; i < n; ++i) a2 += abs(d2[i] - d2[i-1]);
	for(int i = 1; i < n; ++i) a3 += abs(d3[i] - d3[i-1]);
	for(int i = 1; i < n; ++i) a4 += abs(d4[i] - d4[i-1]);

	cout << max(a1, max(a2, max(a3, a4))) << endl;
	return 0;
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] hash = new int[m + 1];
		for (int i = 0; i < n; i++) {
			int x =in.nextInt();
			for (int j = 0; j < x; j++) {
				hash[in.nextInt()]++;

			}

		}
		int ans = 0;
		for (int i = 0; i < hash.length; i++) {
			if (hash[i] == n) {
				++ans;
			}
		}
		out.println(ans);
		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = nextInt();
			}
			return ret;
		}

		public long[] nextIntLong(int n) throws IOException {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = nextLong();
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 21332
x, n = map(int, input().split())
p = [int(_) for _ in input().split()]

arr = [0] * 1000
for i in p:
    arr[i] = 1

ans1 = 0
for i in range(x, -1, -1):
    if arr[i] == 0:
        ans1 = i
        break

# print(arr)

ans2 = 0
for i in range(x, 102):
    if arr[i] == 0:
        ans2 = i
        break

if abs(ans1 - x) <= abs(x - ans2):
    print(ans1)
else:
    print(ans2)


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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {
	
	ll n;
	cin >> n;
	n = sqrt(n);

	cout << n*n<< endl;

	return 0;

}

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

  int A,B,C,D;
  A=W/1000;
  B=W%1000/100;
  C=W%1000%100/10;
  D=W%1000%100%10;
  for(int tmp=0; tmp<(1<<3); tmp++){
    int ans=A;
    vector<char> op(3);
    bitset<3> S(tmp);
    vector<int> judge(3);
    for(int i=0; i<3; i++){
      if(S.test(i)){
        judge.at(i)=1;
      }
      else{
        judge.at(i)=0;
      }
    }
    if(judge.at(0)==1){
      ans+=B;
      op.at(0)='+';
    }
    else{
      ans-=B;
      op.at(0)='-';
    }
    if(judge.at(1)==1){
      ans+=C;
      op.at(1)='+';
    }
    else{
      ans-=C;
      op.at(1)='-';
    }
    if(judge.at(2)==1){
      ans+=D;
      op.at(2)='+';
    }
    else{
      ans-=D;
      op.at(2)='-';
    }
    if(ans==7){
      cout << A << op.at(0) << B << op.at(1) << C << op.at(2) << D << "=" << 7 << endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
public class Main{
	static boolean[] visited=new boolean[100000*2];
	static ArrayList<ArrayList<Integer>> list=new ArrayList<>();
	static long xc;
	static long yc;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0; i<100000*2; i++){
			ArrayList<Integer> tmp=new ArrayList<>();
			list.add(tmp);
		}
		int[] x=new int[n];
		for(int i=0; i<n; i++){
			x[i]=sc.nextInt()-1;
			int y=sc.nextInt()-1+100000;
			list.get(x[i]).add(y);
			list.get(y).add(x[i]);
		}
		long sum=0;
		for(int i:x){
			xc=0;
			yc=0;
			dfs(0,i);
			sum+=xc*yc;
		}
		System.out.println(sum-n);
	}
	static void dfs(int count,int i){
		if(!visited[i]){
			visited[i]=true;
			if(count%2==0){
				xc++;
			}else{
				yc++;
			}
			for(int j:list.get(i)){
				dfs(count+1,j);
			}
		}
	}
}


Measured memory_bytes: 125016
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			string n = Console.ReadLine();
			int m = n.Length;

			int ans = 0;
			for (int i = 0; i < m; i++) {
				ans += n[i] - '0';
			}

			for (int i = 0; i < m; i++) {
				if (n[i] - '0' == 0) {
					continue;
				}
				
				int temp = 0;
				for (int j = 0; j < i - 1; j++) {
					temp += n[i] - '0';
				}	

				temp += n[i] - '0' - 1;
				for (int j = i + 1; j < m; j++) {
					temp += 9;
				}

				ans = Math.Max(ans, temp);
			}

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 25956
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 610000;
const int K = 19;
const int mod = 1e9 + 7;
int f[N], invf[N], inv2, inv3, a[N], b[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int win = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (a[i] % 2) win = 1;
    }
    if (win) cout << "first"; else cout << "second";
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    double l; cin >> l;
    double x = l/3;
    cout << fixed << setprecision(10) << x*x*x << endl;
}


Measured memory_bytes: 256
#set
kazu = gets.chomp.to_i
takoyakis = Array.new
takoyakis = gets.chomp.split(" ").map(&:to_i)
power = 0

#main
(0 .. kazu - 2).each do |i|
    (i + 1 .. kazu - 1).each do |j|
    power += takoyakis[i] * takoyakis[j]
    end
end

print ("#{power}\n")

Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main() {
	int t, i=0, j, k;
	int a, b=0, c=0 ,d,n,F=0,Ma=0,Mb=0,Mc=0;
	string A,D,E;
	char B;
	cin >> a>>b;
	vector <int>C(a);
	for (i = 0; i < a; i++) {
		cin >> C[i];
	}

	sort(C.begin(), C.end(), std::greater<int>());

	for (i = 0; i < b; i++) {
		c += C[i];
	}
	
	cout << c << endl;


	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
    using System.IO;
#endif

public class Program {
    public static void Main() {
        #region SetAutoFlushIsFalse
#if !DEBUG
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
#endif
        #endregion
        var n = ReadLib.ReadAsInt();
        var aArr = ReadLib.ReadNTimesAsInt(n);

        var val = CalcVal(n, aArr);
        Console.WriteLine(val);
        #region Flush
#if !DEBUG
        Console.Out.Flush();
        sw.Close();
#endif
        #endregion

    }


    private static int CalcVal(int n, int[] aArr) {
        HashSet<int> history = new HashSet<int>() { 0 };
        int p = 0;
        while (true) {
            p = aArr[p] - 1;

            if (p == 1) {
                return history.Count();
            }

            if (!history.Add(p)) {
                return -1;
            }
            
        }
    }
}

static class ReadLib {
    public static long ReadAsLong() {
        return long.Parse(Console.ReadLine());
    }

    public static int ReadAsInt() {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadAsIntArray() {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    public static long[] ReadAsLongArray() {
        return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    public static ulong[] ReadAsULongArray() {
        return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
    }

    public static string[] ReadAsStringArray() {
        return Console.ReadLine().Split(' ');
    }

    public static int[] ReadNTimesAsInt(int n) {
        return Enumerable.Range(1, n).Select(s => int.Parse(Console.ReadLine())).ToArray();
    }

    public static int[][] ReadNTimesAsIntArray(int n) {
        return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray();
    }

}

Measured memory_bytes: 20960
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  lint h, w, s;
  scanf("%ld %ld", &h, &w);
  if(h == 1 && w == 1) s = 1;
  else if(h == 1) s = w-2;
  else if(w == 1) s = h-2;
  else s = (h-2)*(w-2);
  printf("%ld", s);
  return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n, k; cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << n-k << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll K,S;cin>>K>>S;
    ll ans=0;
    for(ll x=0;x<=K;x++){
        for(ll y=0;y<=K;y++){
            ans+=(0<=S-x-y && S-x-y<=K);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3572
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();
        if(N<B) System.out.println((A*N)/B-A*(N/B));
        else System.out.println((A*(B-1))/B-A*((B-1)/B));
    }
}

Measured memory_bytes: 35776
a,v = map(int,input().split())
b,w = map(int,input().split())

T = int(input())

if a==b:
    print("YES")

elif a<b:
    if v<=w:
        print("NO")
    else:
        if a+v*T>=b+w*T:
            print("YES")
        else:
            print("NO")

else:
    if v<=w:
        print("NO")
    else:
        if a-v*T<=b-w*T:
            print("YES")
        else:
            print("NO")

Measured memory_bytes: 61692
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;

int main(){
    ll N;
    cin >> N;
    ll ans = INF;
    ll a = 1;
    while(N >= a*a){
        if(N%a == 0){
            ll b = N/a;
            ans = min(ans,a+b-2);
        }
        a++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        string[] t = s.Split(' ');
        int[] a = new int[N];
        //数値を当てはめていく
        for (int i = 0; i < N; i++) {
            a[i] = int.Parse(t[i]);
        }
        
        float sum = 0;  //全体の合計
        float ave = 0;  //全体の平均

        //合計及び平均を求める
        for (int i = 0; i < N; i++) {
            sum += a[i];
        }

        //平均値との差をとっていき、最小の値及びその時のiの値を保存する
        float diff = Math.Abs(sum - a[0] * N);  //暫定的な、平均値との差
        int ans = 0;  //暫定的な、平均に一番近い番号
        for (int i = 0; i < N; i++) {
            //最小値を更新したとき
            if (diff > Math.Abs(sum - a[i] * N)) {
                diff = Math.Abs(sum - a[i] * N);
                ans = i;
            }
        }

        //出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <climits>

using namespace std;

int main()
{
    int a,min = INT_MAX,max=INT_MIN;
    long sum=0;
    int n;

    cin >> n;

    for(int i=0;i<n;i++){
        cin >> a;
        if (a<min)
            min = a;
        if (a>max)
            max = a;
        sum += a;
    }

    cout << min << " " << max << " " << sum <<endl;

    return 0;
}



Measured memory_bytes: 3116
import sys
sys.setrecursionlimit(10**5)
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n-1)]

edges = [[] for _ in range(n)]
for u, v, w in uvw:
    u-=1
    v-=1
    edges[u].append([v, w%2])
    edges[v].append([u, w%2])

res = [[] for _ in range(n)]
def dfs(v, p, c):
    res[v] = c
    for e in edges[v]:
        if e[0] == p: continue
        if e[1]%2==1: dfs(e[0], v, 1-c%2)
        else: dfs(e[0], v, c)

dfs(0, -1, 1)
print('\n'.join(list(map(str, res))))

Measured memory_bytes: 110480
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	string n;
	cin>>n;
	int l=n.length();
	for(int i=0;i<l;i++){
		if(n[i]=='7'){
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}

signed main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n;
    cin >> n;

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

    ll num = 0;
    ll ans = 0;
    for(int i = 0; i < n-1; i++){
        if(a[i] >= a[i+1]){
            num++;
        }else{
            num = 0;
        }
        ans = max(ans, num);
    }

    cout << ans << endl;
    return 0;

}


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

int main(){
    int x;
    cin >> x;
    int ans = 1;
    for(int i=2;i<=40;i++){
        for(int j=2;j<=10;j++){
            if(x>= pow(i,j)){
                if(ans < pow(i,j)){
                    ans = pow(i,j);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, D = list(map(int, input().split()))
X = []
for _ in range(N):
    x = list(map(int, input().split()))
    X.append(x)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        s = [xi - xj for xi, xj in zip(X[i], X[j])]
        e = [ss**2 for ss in s]
        t = sum(e)
        for k in range(40*40*D+1):
            if t == k**2:
                ans += 1
                break
print(ans)



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<pair<string, int>> playlist(n);
    for (int i=0; i<n; i++) {
        cin >> playlist.at(i).first >> playlist.at(i).second;
    }
    string x;
    cin >> x;
    int ans = 0;
    bool isSleeping = false;
    for (int i=0; i<n; i++) {
        if (isSleeping) {
            ans += playlist.at(i).second;
        } else if (playlist.at(i).first == x) {
            isSleeping = true;
        }
    }
    cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define ll long long int 
#define pii pair<int, int>
#define fi first
#define se second
#define maxn 200019
#define M 998244353
using namespace std;

int n;
int num[maxn];

ll power(ll x, ll y){
	ll ans = 1, con = x;
	while (y){
		if (y & 1) ans = ans * con % M;
		con = con * con % M;
		y >>= 1;
	}
	return ans;
}

int main(){
	int x;
	scanf("%d", &n);
	scanf("%d", &x);
	if (x) {
		printf("0");
		return 0;
	}
	num[0]++;
	rep(i, 2, n) scanf("%d", &x), num[x]++;
	if (num[0] != 1) {
		printf("0");
		return 0;
	}
	int last = 1;
	ll ans = 1;
	int f = -1;
	rep(i, 1, n) if (!num[i]) {f = i; break;} 
	rep(i, f + 1, n - 1){
		if (num[i]) {
			printf("0");
			return 0;
		}
	}
	rep(i, 1, n - 1){
		if (num[i] == 0) break;
		ans = ans * power(last, num[i]) % M;
		last = num[i];
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int A, B;
    int start = 1;
    
    scanf("%d", &A);
    scanf("%d", &B);
    
    for(int i=0;i<A;i++) {
    	if ((start*2)<(start+B)) {
    		start*=2;
		} else {
			start+=B;
		}
	}
    printf("%d", start);
    return 0;
}

Measured memory_bytes: 1688
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



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

int main(){
  bool grid[100][100];
  int t,n;

  cin >> t;

  while(t--){
    cin >> n;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)grid[i][j] = false;
    }

    bool f[4];
    for(int i=0;i<4;i++)f[i] = true;
    int x = 0, y = n-1;
    grid[y][x] = true;

    while(f[0] || f[1] || f[2] || f[3]){
      for(int i=0;i<4;i++)f[i] = false;

      while(1){
	y--;
	if(y < 0 || (x+1 < n && grid[y][x+1]) || (x-1 >= 0 && grid[y][x-1]) || (y-1 >= 0 && grid[y-1][x]) ){
	  y++;
	  break;
	}
	f[0] = true;
	grid[y][x] = true;
      }

     while(1){
	x++;
	if(x >= n || (y+1 < n && grid[y+1][x]) || (y-1 >= 0 && grid[y-1][x]) || (x+1 < n && grid[y][x+1]) ){
	  x--;
	  break;
	}
	f[1] = true;
	grid[y][x] = true;
      }
  
     while(1){
	y++;
	if(y >= n ||(x-1 >= 0 && grid[y][x-1]) || (x+1 < n && grid[y][x+1]) || (y+1 < n && grid[y+1][x]) ){
	  y--;
	  break;
	}
	f[2] = true;
	grid[y][x] = true;
      }

      while(1){
	x--;
	if(x < 0 || (y+1 < n && grid[y+1][x]) || (y-1 >= 0 && grid[y-1][x]) || (x-1 >= 0 && grid[y][x-1]) ){
	  x++;
	  break;
	}
	f[3] = true;
	grid[y][x] = true;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(grid[i][j])cout << "#";
	else cout << " ";
      }
      cout << endl;
    }
    if(t)cout << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	int b=0,c[a];
	for(int i=0;i<a;i++){
		cin>>c[i];
		if(c[i]!=i+1){
			b++;
		}
	}
	if(b<=2)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
#n,k=map(int,input().split())
l=[int(i) for i in input().split()]
res=[]
for i in range(-1,-n-1,-2):
    res.append(l[i])
for i in range(0+n%2,n,2):
    res.append(l[i])

print(*res)

Measured memory_bytes: 26020
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{
    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int inputCount = inpt[0];
        int timeLimit = inpt[1];

        string ans = "TLE";
        int min = int.MaxValue;
        for (int i = 0; i < inputCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            if(inpt[1]>timeLimit) {
                continue;
            }
            if(min > inpt[0]) {
                min = inpt[0];
                ans = min.ToString();
            }
        }
        Console.WriteLine(ans);


    }




    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



5 9
25 8
5 9
4 10
1000 1000
6 1


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	ll k,n;cin>>k>>n;
	ll arr[n];
	for(int i=0;i<n;i++){
		int a;cin>>a;
		arr[i] = a;
	}
	ll dis[n]; dis[0] = arr[0];
	ll sum = arr[0];
	for(int i=1;i<n;i++){
		dis[i] = arr[i] - arr[i-1];
		sum += dis[i];
	}
	dis[0] += k-sum;
	ll ans = k - *max_element(dis,dis+n);
	cout<<ans<<endl;
}

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

int main() {
	double a, b;
	int h, m;
	cin >> a >> b;
	cin >> h >> m;
	double tm = 6.0 * m;
	double th = (60.0 * h + m) / 2.0;
	double t = min(abs(tm - th), 360-abs(tm - th));
	t = t * acos(-1) / 180;
	double ans = a * a + b * b - 2.0 * a * b * cos(t);
	// cout << cos(t) << " " << t << endl;
	ans = sqrt(ans);
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 4192
c = [list(map(int,input().split())) for _ in range(3)]
a = []
b = []
for i in range(3):
    a.append(abs(c[i][0]-c[i][1]))
    a.append(abs(c[i][1]-c[i][2]))
for i in range(3):
    b.append(abs(c[0][i]-c[1][i]))
    b.append(abs(c[1][i]-c[2][i]))
if a[0] == a[2] and a[2] == a[4] and b[0] == b[2] and b[2] == b[4] \
    and a[1] == a[3] and a[3] == a[5] and b[1] == b[3] and b[3] == b[5]:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3064
card = [input() for _ in range(3)]
a = 0
b = -1
c = -1
check = card[0][0]
while a != len(card[0]) or b != len(card[1]) or c != len(card[2]):
    if check == 'a':
        a += 1
        try:
            check = card[0][a]
        except IndexError:
            ans = 'A'
            break
    elif check == 'b':
        b += 1
        try:
            check = card[1][b]
        except IndexError:
            ans = 'B'
            break
    else:
        c += 1
        try:
            check = card[2][c]
        except IndexError:
            ans = 'C'
            break
print(ans)


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

#define ll long long

using namespace std;

template <typename T, ll mod>
struct z {
    T val;
    z(T val) : val(val % mod) {};
};

#define OPER(X) \
    template <typename T, ll mod> \
    z<T, mod> operator X(const z<T, mod> & a, const z<T, mod> & b) { \
        return z<T, mod>((ll)a.val X b.val); \
    }

OPER(+)
OPER(*)

template <typename T>
struct sq_matrix : vector< vector<T> > {
    sq_matrix(int n, bool id = false) : vector< vector<T> > (n, vector<T>(n, 0)) {
#if 0
        if(id)
            for(int i = 0; i < n; i++)
                this[i][i] = T(1);
#endif
    }
};

template <typename T>
sq_matrix<T> operator*(const sq_matrix<T> & a, const sq_matrix<T> & b) {
    assert(a.size() == b.size());

    sq_matrix<T> c(a.size());
    for(int i = 0; i < a.size(); i++)
        for(int j = 0; j < a.size(); j++) {
            T x = 0;
            for(int k = 0; k < a.size(); k++)
                x = x + a[i][k] * b[k][j];
            c[i][j] = x;
        }

    return c;
}

template <typename T>
T pow(T base, ll exp) {
    //if(exp == 0) return T(base.size(), true);
    if(exp == 1) return base;
    if(exp % 2 == 1) return base * pow(base, exp - 1);
    T tmp = pow(base, exp / 2);
    return tmp * tmp;
}

int main() {
    std::ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    constexpr ll mod = 1'000'000'000 + 7;
    sq_matrix< z<ll, mod> > M(n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> M[i][j].val;
    const auto & N = pow(M, k);
    z<ll, mod> res = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            res = res + N[i][j];
    cout << res.val << "\n";

    return 0;
}


Measured memory_bytes: 2816
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,m,h[2010][2010],l[2010][2010],r[2010][2010],ans;
char s[2010][2010];
int main()
{
	scanf("%d %d",&n,&m);getchar();
	ans=max(n,m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(j==1||i==1) h[i][j]=1;
			else h[i][j]=((s[i][j]==s[i][j-1])==(s[i-1][j]==s[i-1][j-1]))?h[i-1][j]:i;
		}
	for(int i=1;i<=n;i++)
	{
		if(i==1) for(int j=1;j<=m;j++) l[i][j]=1,r[i][j]=m;
		else
		{
			l[i][1]=1;for(int j=2  ;j<=m;j++) l[i][j]=(s[i][j]==s[i-1][j])==(s[i][j-1]==s[i-1][j-1])?l[i][j-1]:j;
			r[i][m]=m;for(int j=m-1;j>=1;j--) r[i][j]=(s[i][j]==s[i-1][j])==(s[i][j+1]==s[i-1][j+1])?r[i][j+1]:j;
		}
		for(int j=1;j<=m;j++)
		{
			if(h[i][j]==i) l[i][j]=1,r[i][j]=m;
			else l[i][j]=max(l[i][j],l[i-1][j]),r[i][j]=min(r[i][j],r[i-1][j]);
			int N=i-h[i][j]+1,M=r[i][j]-l[i][j]+1;
			ans=max(ans,N*M);
		}
	}
	printf("%d",ans);
}

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

void Main() {
  int n, m;
  cin >> n >> m;

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

  long long b[n + 1];
  b[0] = 0;
  map<int, long long> amari;
  for (int i = 0; i < n; i++) {
    b[i + 1] = b[i] + a[i];

    amari[b[i + 1] % m]++;
  }

  long long ans = 0;
  for (auto am: amari) {
    //cout << am.first << " " << am.second << endl;
    ans += am.second * (am.second - 1) / 2;
  }
  ans += amari[0];
  cout << ans << 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: 5504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
const int mod = 1000000007;
string s,t,u;
int a,b;
int main(){
  cin >> s >> t >> a >> b >> u;
  cout << (u == s? a-1:a) << " " << (u == t ? b-1:b) << endl; 
}


Measured memory_bytes: 256
#include <stdio.h>

int selectionSort(int A[], int N) {
  int n = 0, i, j, tmp, min;

  for(i = 0;i < N;i++) {
    min = i;
    for(j = i;j < N;j++)
      min = A[j] < A[min] ? j : min;

    if(min != i) {
      tmp = A[min];
      A[min] = A[i];
      A[i] = tmp;

      n++;
    }
  }

  return n;
}

int main() {
  int n, m, i, a[100];

  scanf("%d", &n);
  for(i = 0;i < n;i++)
    scanf("%d", &a[i]);

  m = selectionSort(a, n);

  for(i = 0;i < n - 1;i++)
    printf("%d ", a[i]);
  printf("%d\n", a[i]);
  printf("%d\n", m);

  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    char c; cin >> c;
    char ans = c + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  ll r = 0;
  int N;
  cin >> N;
  vector<ll> A(1e5+1);
  REP(i, N) {
    int a;
    cin >> a;
    r += a;
    A.at(a)++;
  }

  int Q;
  cin >> Q;
  REP(i, Q) {
    ll B, C;
    cin >> B >> C;
    r += A.at(B) * (C - B);
    A.at(C) += A.at(B);
    A.at(B) = 0;
    cout << r << endl;
  }
}


Measured memory_bytes: 4028