akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    private int[] c;
    private List<List<Integer>> g;

    private long[] cnt;
    private long[] ans;

    private int dfs(int u, int fa) {
        cnt[c[fa]] = 0;
        int total = 1;
        long before = cnt[c[u]];
        for(int v : g.get(u)) {
            if (v != fa) {
                total += dfs(v, u);
            }
        }

        if (c[u] != c[fa]) {
            long r = total - cnt[c[fa]];
            ans[c[fa]] += r * (r + 1) / 2;
        }
        cnt[c[u]] += total - (cnt[c[u]] - before);
        return total;
    }

    private void solve() {
        int n = sc.nextInt();
        c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt() - 1;
        }

        g = new ArrayList<>();
        add(g, n);

        for (int i = 1; i < n; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            g.get(u).add(v);
            g.get(v).add(u);
        }

        cnt = new long[n];
        ans = new long[n];

        int total = 1;
        for (int v : g.get(0)) {
            total += dfs(v, 0);
        }

        for (int k = 0; k < n; k++) {
            if (k != c[0]) {
                long r = total - cnt[k];
                ans[k] += r * (r + 1) / 2;
            }
        }



        long all = (long) n * (n + 1) / 2;

        for (long v : ans) {
            out.println(all - v);
        }
    }

    private void add(List<List<Integer>> a, int n) {
        for (int i = 0; i < n; i++) {
            a.add(new ArrayList<>());
        }
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 124176
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

int main() {
    int N,count=0;
    cin >> N;
    char a[N],b[N],c[N];
    cin>> a>>b>>c;
    for(int i=0;i<N;i++){
        if(a[i]==b[i] && a[i]==c[i])
            count+=0;
        else if((a[i]==b[i] && a[i]!=c[i]) || (a[i]==c[i] && a[i]!=b[i])|| (c[i]==b[i] && a[i]!=c[i])){
            count+=1;
        }
        else
            count+=2;
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  string n;
  cin>>n;
  int a[2] = {1,9};
  int s[3] = {1,1,1};
  if(n[0]=='9') s[0]=0;
  if(n[1]=='9') s[1]=0;
  if(n[2]=='9') s[2]=0;
  cout<<a[s[0]]<<a[s[1]]<<a[s[2]];
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

int main() {
	int a1, a2, a3;cin >> a1 >> a2 >> a3;
	if(a1+a2+a3 < 22){
		cout << "win" << endl;
	} else {
		cout << "bust" << endl;
	}
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)
#define pb push_back

#define test if(!true)
#define N 100007
#define MOD (ll)(1e9 + 7)

ll dp[2007][2007];
ll a[2007];
ll b[2007];
int n, m;

ll fun(int i, int j)
{
    if(dp[i][j] != -1)
    {
        return dp[i][j];
    }

    ll one = fun(i+1, j) - fun(i+1, j+1);
    ll two = fun(i, j+1) - fun(i+1, j+1);
    one = (one + MOD) % MOD;
    two = (two + MOD) % MOD;

    dp[i][j] = (one + two + fun(i+1, j+1)) % MOD;

    if(a[i] == b[j])
    {
        dp[i][j] = (dp[i][j] + 1 + fun(i+1, j+1)) % MOD;
    }

    //cout << i << " " << j << " : " << dp[i][j] << "\n";
    return dp[i][j];
}

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

    frt(i, 0, n)
    {
        cin >> a[i];
    }

    frt(j, 0, m)
    {
        cin >> b[j];
    }

    frt(i, 0, n)
    {
        frt(j, 0, m)
        {
            dp[i][j] = -1;
        }
    }
    cout << (fun(0, 0) + 1) % MOD << "\n";


    
    return 0;
}

Measured memory_bytes: 32000
#include<bits/stdc++.h>
using namespace std;
int h,n,a,ans;
int main()
{
	cin>>h>>n;
	for (int i=0;i<n;i++)
	{
		cin>>a;
		ans+=a;
	}
	if (ans>=h) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

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

#define loopinc(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define loop(i, a, b) for(int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define endl "\n"
#define all(c) (c).begin(),(c).end()
//#define lloopinc(i, a, b, inc) for(ll i = a; i < (b); i += inc)
//#define lloop(i, a, b) for(ll i = a; i < (b); i++)
//#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
//typedef pair<ll, ll> pll;
typedef vector<int> vi;
//typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

vi arr;
int n;
int cost(int b) {
	int total = 0;
	rep(i, n) {
		total += abs(arr[i] - (b+i+1));
	}
	return total;
}
signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	arr.resize(n);
	rep(i, n) cin >> arr[i];

	vi ar2(n);
	rep(i, n) ar2[i] = arr[i]-i-1;

	sort(all(ar2));
	cout << cost(ar2[n/2]) << endl;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include<iomanip>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define mp(i,j) make_pair(i,j)

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

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

vector<P> paths;

void Main()
{
	int N, M; cin >> N >> M;
	rep(i,M) {
		int a, b; cin >> a >> b;
		--a, --b;
		paths.push_back(mp(b, a));
	}
	sort(paths.begin(), paths.end());
	int ans = 0;
	int last = 0;
	for (auto path : paths) {
		if (last <= path.second) {
			++ans;
			last = path.first;
		}
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 1400
#include<stdio.h>
#define N 500

static const int INFTY = (1<<21);

int main(){
  int n,i,j,a,b,x,y,sum,minv;
  int A[N][N],d[N],p[N],v[N];

  scanf("%d",&n);
  for(i=0; i<n; i++){
    for (j=0; j<n; j++){
      A[i][j] = INFTY;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&a,&x);
    for (j=0; j<x; j++){
      scanf("%d %d",&b,&y);
      A[a][b] = y;
    }
  }

  for(i=0; i<n; i++){
    d[i] = INFTY;
    v[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    a = -1;
    for(i=0; i<n; i++){
      if (minv > d[i] && !v[i]){
        a = i;
        minv = d[i];
      }
    }
    if(a == -1)
      break;

    v[a] = 1;
    for(b=0; b<n; b++){
      if(!v[b] && A[a][b] != INFTY){
        if(d[b] > d[a]+A[a][b]){
          d[b] = d[a]+A[a][b];
        }
      }
    }
  }

  for (i=0; i<n; i++){
    printf("%d %d",i,(d[i]==INFTY?-1:d[i]));
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2060
import java.util.*;
public class Main{
	static int greatestCommonFactor(int a, int b, int c)
	{
		int limit;
	    limit = Math.min(a, b);
	    limit = Math.min(limit, c);
	    for(int n = limit; n >= 2; n--)
	    {
	        if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
	            return n;
	        }
	    }

	    return 1;
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt();
		int sum=0;
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int z=1;z<=k;z++) {
					sum+=greatestCommonFactor(i,j,z);
				}
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 27140
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = [1]
for i in range(99):
    if n < 1 + 3*G[-1]:
        break
    G.append(1 + 3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
    insertionSort(A, n, G[i])

print(m)
print(*G)
print(cnt)
print(*A, sep='\n')

Measured memory_bytes: 63052
// 9:51
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <tuple>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)
#define STRING(str) #str
#define DEBUG 0
#if DEBUG
    #define dump(var) dump2(STRING(var), var)
#else
    #define dump(var)
#endif

template <typename T>
void dump2(const string& name, const T& value)
{
    cerr << name << ": " << value << endl;
}
void dump2(const string& name, const tuple<ll,ll,ll>& value)
{
    ll a,b,c;
    tie(a,b,c) = value;
    cerr << name << ": (" << a << ", " << b << ", " << c << ")" << endl;
}

void solve()
{
    string S;
    cin >> S;
    while(true) {
        ll len = S.length();
        dump(S);
        if (len == 0) {
            cout << "YES" << endl;
            return;
        }
        if (len >= 5 && S.substr(len-5,5) == "dream") {
            S = S.substr(0,len-5);
        }
        else if (len >= 7 && S.substr(len-7,7) == "dreamer") {
            S = S.substr(0,len-7);
        }
        else if (len >= 5 && S.substr(len-5,5) == "erase") {
            S = S.substr(0,len-5);
        }
        else if (len >= 6 && S.substr(len-6,6) == "eraser") {
            S = S.substr(0,len-6);
        }
        else {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "NO" << endl;
}

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


Measured memory_bytes: 512
n = int(input())
l = []
for i in range(n):
    s, p = list(input().split())
    l.append([s, int(p), i + 1])
l.sort(key=lambda x: x[1], reverse=True)
l.sort(key=lambda x: x[0])
for i in l:
    print(i[2])

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

int main(){
    bool ans = 1;
    string x;
    cin >> x;
    for(int i = 1;i < 4;i++){
        if(x.at(i) == x.at(i - 1)){
            ans = 0;
        }
    }
    /**/
    if(ans){
        cout << "Good" << endl;
    }
    else{
        cout << "Bad" << endl;
    }
}

Measured memory_bytes: 256
s=[(26-(ord(i)-ord("a")))%26for i in list(input())]
k=int(input())
c=""
for i in range(len(s)-1):
    if k>=s[i]:
        k-=s[i]
        c+="a"
    else:
        c+=chr((26-s[i])%26+ord("a"))
print(c+chr(((26-s[-1])%26+k)%26+ord("a")))

Measured memory_bytes: 4792
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static String question, answer;
    public static void main(String[] args) {
        while(read()){
            solve();
        }

    }

    static boolean read(){
        question = sc.next();
        answer = sc.next();
        if(question.equals("0") && answer.equals("0"))return false;
        return true;
    }

    static void solve(){
        int hit = 0, brrow = 0;
        boolean hit_flag = false;
        for(int i = 0; i < question.length(); i++){
            if(question.charAt(i) == answer.charAt(i)){
                hit++;
                hit_flag = true;
            }
            if(hit_flag == false){
                for(int j = 0; j < answer.length(); j++){
                        if(question.charAt(i) == answer.charAt(j)){
                            brrow++;
                        }
                }
            }
            hit_flag = false;
        }
        System.out.println(hit +" "+ brrow);
    }

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, T, Ans, A[5100];
int main() {
	cin >> N >> K ;
	for(register int i = 1; i <= N; i ++ ) cin >> A[i];
	sort(A+1, A+N+1);
	for(register int i = N; i >= 1; i -- )
		if(T+A[i] >= K) Ans = 0;
		else Ans++, T += A[i];
	cout << Ans << endl;
}

Measured memory_bytes: 256
a, b, c, n = map(int, input().split(" "))
if a > b:
    a, b = b, a
if b > c:
    b, c = c, b
if a > b:
    a, b = b, a

ans = 0
for numc in range(n//c + 1):
    left = n - c * numc
    for numb in range(left//b + 1):
        if (left - b*numb) % a == 0:
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<iterator>
#include<math.h>
#include<cstring>
using namespace std;
void lets_play()
 
{
   int n,m,l,c=0;
   cin>>n>>m>>l;
 
  if(m==7)
    c++;
    if(n==7)
        c++;
    if(l==7)
        c++;
    if(c==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    }
 
int main()
{
        lets_play();
 
}

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

int main()
{
    int n, x, cnt;
    for (;;)
    {
        cnt = 0;
        cin >> n >> x;
        if (n == 0 && x == 0)
            break;
        for (; n > 0; n--)
        {
            for (int i = 1; i < n; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    if (x - n == i + j)
                    {
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>

#define MASU 8
#define Q 1
#define FREE -1
#define ENTERED 1
int A[MASU][MASU];
int row[MASU],col[MASU],dpos[2 * MASU-1],dneg[2 * MASU-1];

void Queenprint(){
  int i,j;
  for(i=0; i<MASU; i++){
    for(j=0; j<MASU; j++){
      if(A[i][j]==Q){
	if(row[i] != j)return;
      }
    }
    }

  for(i=0;i<MASU;i++){
    for(j=0; j<MASU; j++){
      if(row[i]==j)printf("Q");
      else printf(".");
      }
    printf("\n");
  }
}


void setQueen(int x){
  int i,j,k,l,t,v;
  
  if(x == MASU){
    Queenprint();
    return;
  }
  
  for(j=0; j<MASU; j++){
    if(col[j]==ENTERED || dpos[x+j] == ENTERED || dneg[x-j+MASU-1] ==ENTERED)continue;


    //(i,j)にQueenを配置
    row[x] = j;
    col[j] = dpos[x+j] = dneg[x-j+MASU-1] = ENTERED;
    //次の行を試す
    setQueen(x+1);
    //(i,j)にあるQueenを排除
    row[x]=col[j] =dpos[x+j]=dneg[x-j+MASU-1] = FREE;
  }
  //Queenの配置に失敗
}


int main(){
  int n,i,j,gyou,retsu;
  for(i=0;i<MASU;i++){
    for(j=0;j<MASU; j++){
      A[i][j]=FREE;
    }
    row[i] =FREE;
    col[i] =FREE;
  }
  for(i=0;i<2*MASU-1;i++){
    dpos[i] =FREE;
    dneg[i] =FREE;
  }
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d %d",&gyou,&retsu);
    A[gyou][retsu]=Q;
  }

  // printf("setQueen開始\n");
  setQueen(0);

  // printf("Queenprint開始\n");

  return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int min =1000000;
		int max = -1000000;
		long sum = 0;
		
		int line = sc.nextInt();
		int L[] = new int[line];
		
		for(int i = 0; i < line; i++){
			int value = sc.nextInt();
			
			if(min > value){
				min = value;
			}
			if(max < value){
				max = value;
			}
			sum += value;
		}
		System.out.println(String.format("%d %d %d", min, max, sum));
		sc.close();
	}
}

Measured memory_bytes: 42584
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main(){
  int n,m,q;cin>>n>>m>>q;
  map<pii,int> mp;
  for(int i=0;i<m;i++){
    int l,r;cin>>l>>r;
    mp[make_pair(l,r)]++;
  }
  int s[502][502];
  for(int i=0;i<=501;i++)s[501][i]=0;
  for(int i=500;i>=1;i--){
    int sum=0;
    for(int j=1;j<=500;j++){
      sum+=mp[make_pair(i,j)];
      s[i][j]=s[i+1][j]+sum;
    }
  }
  for(int i=0;i<q;i++){
    int a,b;cin>>a>>b;
    cout<<s[a][b]<<endl;
  }
}

Measured memory_bytes: 17536
#include <cstdio>

int N, x;

int main() {
	scanf("%d%d", &N, &x);
	if (x == 1 || x == N + N - 1) return puts("No"), 0;
	puts("Yes");
	if (N == 2) return puts("1\n2\n3\n"), 0;
	if (x == 2) {
		for (int i = 1; i <= N - 2; ++i) printf("%d\n", N - i + 1);
		printf("1\n2\n");
		for (int i = N + 1; i <= N + N - 1; ++i) printf("%d\n", i);
	} else if (x == N + N - 2) {
		for (int i = 1; i <= N - 2; ++i) printf("%d\n", N + i - 1);
		printf("%d\n%d\n", N + N - 1, N + N - 2);
		for (int i = N + 1; i <= N + N - 1; ++i) printf("%d\n", N + N - i);
	} else {
		int val = 1;
		for (int i = 1; i <= N - 3; ++i) {
			if (val == x - 2) val = x + 3;
			printf("%d\n", val++);
		}
		printf("%d\n%d\n%d\n%d\n%d\n", x + 2, x - 1, x, x + 1, x - 2);
		for (int i = N + 3; i <= N + N - 1; ++i) {
			if (val == x - 2) val = x + 3;
			printf("%d\n", val++);
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    N, K = IL(int)
    A = IL(lambda x: int(x) - 1)
    memo = [0]
    visited = [False] * N
    i = 0
    while(not visited[A[i]]):
        memo.append(A[i])
        visited[A[i]] = True
        i = A[i]
    if K < len(memo):
        print(memo[K] + 1)
    else:
        loop = memo[memo.index(A[i]):]
        print(loop[(K - (len(memo) - len(loop))) % len(loop)] + 1)


solve()


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

typedef long long ll;

const int MAXN = 200005;
const int MAXBIT = 29;

int n;
int A[MAXN], B[MAXN];
int AA[MAXN], BB[MAXN];

ll count(int L, int R) {
    ll res = 0;
    for (int i = 1; i <= n; i++)
        res += lower_bound(BB + 1, BB + n + 1, R - AA[i]) - lower_bound(BB + 1, BB + n + 1, L - AA[i]);
    return res;
}

bool solve(int T) {
    sort(BB + 1, BB + n + 1);
    return (count(T, T << 1) + count(3 * T, T << 2)) & 1;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", A + i);
    for (int i = 1; i <= n; i++)
        scanf("%d", B + i);

    int ans = 0;
    for (int b = 0, T; b < MAXBIT; b++) {
        T = 1 << b;
        for (int i = 1; i <= n; i++) {
            AA[i] = A[i] % (T << 1);
            BB[i] = B[i] % (T << 1);
        }
        ans += solve(T) << b;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <vector>
#include <algorithm>

#define MAX_SIZE 1500000

using namespace std;


int main(){
	int dansu,kansu,shelf[20],book[100],min_size,left,right,m,dansu_index;

	while(true){
		scanf("%d %d",&dansu,&kansu);
		if(dansu == 0 && kansu == 0)break;

		for(int i = 0; i < kansu; i++){
			scanf("%d",&book[i]);
		}

		min_size = MAX_SIZE;
		left = 0,right = MAX_SIZE;
		m = (left+right)/2;
		int i;

		while(left < right){

			shelf[0] = m;
			dansu_index = 0;
			for(i = 0; i < kansu && dansu_index < dansu;){
				if(book[i] > m)break;
				if(shelf[dansu_index] >= book[i]){
					shelf[dansu_index] -= book[i];
					i++;
				}else{
					dansu_index++;
					if(dansu_index < dansu)shelf[dansu_index] = m;
				}
			}

			if(i < kansu){
				left = m + 1;
				m = (left + right)/2;
			}else{
				right = right - 1;
				m = (left + right)/2;
			}
		}

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

	}

    return 0;
}

Measured memory_bytes: 2600
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main(){
  int n,l;
  cin>>n>>l;
  int azi=0;
  int mi=0;
  int ani=1;
  for(int i=1;i<=n;i++) azi+=(l+i-1);
  mi=abs(azi-(azi-l));
  for(int i=2;i<=n;i++){
    int tmp=abs(azi-(azi-(l+i-1)));
    if(mi>tmp) {
      mi=tmp;
      ani=i;
    }
  }
  cout<<azi-(l+ani-1);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;

int sum(int a, int b)
{
  int sum = 0;
  REP(i, b - a + 1)
    sum += a + i;
  return sum;
}

int main()
{
  int N;
  int ans;
  while(1){
    cin >> N;
    if(N == 0){
      break;
    }else{
      ans = 0;
      for(int i = 1; i <= N / 2; i++)
        for(int j = i + 1; j <= N / 2 + 1; j++)
          if(sum(i, j) == N)
            ans++;
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 1160
using System;

namespace ABC046A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);


            if (a == b && b == c)
                Console.WriteLine("1");

            else if (a == b || b == c || a == c)

                Console.WriteLine("2");

            else
                Console.WriteLine("3");

            Console.ReadKey();
        }
    }
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, 0, N) {
    cin >> A[i];
  }
  vector<ll> ans(N);
  ll allA = 0;
  rep(i, 0, N) {
    allA += A[i];
  }
  ll halfallA = allA / 2ll;

  ll x0 = halfallA;
  for (int i = 1; i < N -1; i+=2) {
    x0 -= A[i];
  }
  ans[0] = x0;
  rep(i, 1, N) {
    ans[i] = A[i - 1] - ans[i - 1];
  }
  rep(i, 0, N) {
    printf("%d\n", ans[i] * 2);
  }

};


Measured memory_bytes: 2944
import sys
import bisect
input = sys.stdin.readline

n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]

ll = [[] for _ in range(n)]

for v in l:
    ll[v[0] - 1].append(v[1])
    
for i in range(len(ll)):
    ll[i].sort()
    
for v in l:
    index = bisect.bisect_right(ll[v[0] - 1], v[1])
    print("{:0=6}{:0=6}".format(v[0], index))

Measured memory_bytes: 36756
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp  make_pair
#define ff first
#define ss second
#define pq priority_queue
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
int inf = (1e9) + 7;


int main(){

	int dist[201][201];

	int n,m,r;

	cin >> n >> m >> r;


	vi rs;
	int aux;
	for (int i = 0; i < r; ++i)
	{
		sf1(aux);
		aux--;
		rs.pb(aux);

	}

	int a,b,c;

	sort(rs.begin(),rs.end());
	for (int i = 0; i < 201; ++i)
	{
		for (int j = 0; j < 201; ++j)
		{
			dist[i][j] = inf;
		}
	}


	for (int i = 0; i < n; ++i)
	{
		dist[i][i] = 0;
	}
	for (int i = 0; i < m; ++i)
	{
		sf3(a,b,c);
		a--;
		b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}


	for (int k = 0; k < n; ++k)
	{
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}


	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			// printf("%d %d  = %d\n",i,j,dist[i][j]);
		}
	}

	ll mn = inf;
	int cont = 0;
	while(next_permutation(rs.begin(),rs.end())){
		ll acc  = 0;
		cont++;

		for (int i = 0; i < r-1; ++i)
		{
			acc += dist[rs[i]][rs[i+1]];
		}
		mn = min(mn,acc);
	}

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

}	

Measured memory_bytes: 384
import Data.List

naive_solver::[Int]->Int
naive_solver ls = let grpd = group (sort ls) in
                  foldl (\ count -> \ el -> count + (if (head el)>(length el)then (length el) else (length el)-(head el)) ) 0 grpd

main::IO()
main=do
  _<-getLine
  datc<-getLine
  let dat = map read (words datc)
  print (naive_solver dat)

Measured memory_bytes: 39548
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int N,K;
    cin>>N>>K;

    if(K!=1){
        cout<<N-K<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

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


namespace Test1 {


    class island :IComparable{
        public int hasi = 0;
        public int takara = 0;
        public island(int has, int takar) { hasi = has; takara = takar; }
        public int CompareTo(object obj) {
            island isl = (island) obj;
            return hasi-isl.hasi;
        }
    }

    class ClassMain {


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];
                int n = int.Parse(line);
                if(n==0){break;}
                List<island> isls = new List<island>();
                for (int i = 0; i < n; i++) {
                    int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    isls.Add(new island(ints[1],ints[0]));
                }
                isls.Sort();
                int sum = 0;
                bool canpass=true;
                for(int i =0; i<n; i++){
                    island isis = isls.ElementAt(i);
                    //Console.WriteLine(isis.takara + " , " + isis.hasi);
                    sum+=isis.takara;
                    if(sum>isis.hasi){canpass=false; break;}
                }
                if(canpass){Console.WriteLine("Yes");}
                else{Console.WriteLine("No");}
            
            }
            
        }

        
    }

    

    
}

Measured memory_bytes: 6040
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T> 
struct BIT{
  int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(int i){
    T s=0;
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  
  int lower_bound(int w){
    if(w<=0) return 0;
    int x=0,r=1;
    while(r<n) r<<=1;
    for(int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
	w-=bit[x+k];
	x+=k;
      }
    }
    return x+1;
  }
  
  T sum0(int i){
    return sum(i+1);
  }
  void add0(int i,T a){
    add(i+1,a);
  }
};
//END CUT HERE

signed AOJ_DSL2B(){
  int n,q;
  cin>>n>>q;
  BIT<Int> bit(n+100,0);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<bit.sum(y)-bit.sum(x-1)<<endl;
    else bit.add(x,y);
  }
  return 0;
}
/*
  verified on 2017/12/31
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
*/

// lower_bound
signed ARC033_C(){
  int q;
  cin>>q;
  BIT<int> bit(2e5,0);
  while(q--){
    int t,x;
    cin>>t>>x;
    if(t==1) bit.add(x,1);
    if(t==2){
      int k=bit.lower_bound(x);
      bit.add(k,-1);
      cout<<k<<endl;
    }
  }
  return 0;
}
/*
  verified on 2017/12/31
  https://beta.atcoder.jp/contests/arc033/tasks/arc033_3
*/

signed main(){
  AOJ_DSL2B();
  //ARC033_C();
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
 
using namespace std;
 
// max 16
int main() {
    char N;
    cin >> N;
    if(N == 'A') cout << 'T';
    if(N == 'C') cout << 'G';
    if(N == 'G') cout << 'C';
    if(N == 'T') cout << 'A';
}

Measured memory_bytes: 256
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define F first
#define S second   
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).end()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef vector<int> vi;
typedef pair<int, int> pii; 
typedef pair<int , pii> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve()
{
    int a[3][3] , m[3][3];
    rep(i , 3) rep(j , 3) cin >> a[i][j];
    int cnt[100] = {};
    int n ;
    cin >> n ;
    rep(i ,n){
        int x;
        cin >> x;
        cnt[x]++;
    }
    rep(i , 3) rep(j , 3) m[i][j] = !!(cnt[a[i][j]]);
    rep(i , 3){
        int cnt=  0 ;
        rep(j , 3) cnt += m[i][j] ;
        if(cnt == 3){
            cout << "Yes";
            return;
        }
    }
    rep(i , 3){
        int cnt=  0 ;
        rep(j , 3) cnt += m[j][i] ;
        if(cnt == 3){
            cout << "Yes";
            return;
        }
    }

    rep(i , 1){
        int cnt=  0 ;
        rep(j , 3) cnt += m[j][j] ;
        if(cnt == 3){
            cout << "Yes";
            return;
        }
    }


    rep(i , 1){
        int cnt=  0 ;
        rep(j , 3) cnt += m[2-j][j] ;
        if(cnt == 3){
            cout << "Yes";
            return;
        }
    }

    cout << "No";
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int L[100];
    long count = 0;
    
    scanf("%d",&N);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d",&L[i]);
    }
    
    sort(L, L+N, std::greater<int>());
    
    for(int i = 0; i < N-2; i++)
    {
        for(int j = i+1; j < N-1; j++)
        {
            if(L[i] != L[j])
            {
                for(int k = j+1; k < N; k++)
                {
                    if(L[j] != L[k])
                    {
                        if(L[i] < L[j] + L[k])
                            count++;
                    }
                }
            }
        }
    }
    
    printf("%ld\n", count);
}


Measured memory_bytes: 3864
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 1010101
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
ll dp[1010101][3];
int main()
{
	ll n;
	scanf("%lld", &n);
	invinit();
	dp[1][0] = 3;
	for (int i = 2; i <= n + 10; i++)
	{
		for (int j = 0; j < 3; j++)dp[i][j] = (dp[i - 1][(j + 1) % 3] + dp[i - 1][(j + 2) % 3]) % mod;
	}
	ll r = 0;
	for (int k = 1; k <= n; k++)
	{
		ll s1 = com(n, k)*(n - 1) % mod*(dp[k][0] + dp[k][2]) % mod*k%mod;
		ll s2 = inv[k] * inv[k] % mod*inv[n] % mod*inv[n - 1] % mod;
		//printf("%lld %lld\n", s1, (n - 1)*n % mod*k%mod*k%mod);
		r = (r + s1*s2) % mod;
	}
	for (int i = 0; i < n + 1; i++)r = r*inv[3] % mod;
	printf("%lld\n", r);
}

Measured memory_bytes: 47360
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
#define INF 1000000000

int memo[50][860][860];
int N;
int sum = 0;
vector<int> t;

int dfs(int i, int x, int y){
	if(i == N){
		int z = sum - x - y;
		return max({x,y,z});
	}
	if(memo[i][x][y]>=0) return memo[i][x][y];
	int ans = INF;
	if(x+t[i]<860) ans = min(ans,dfs(i+1,x+t[i],y));
	if(y+t[i]<860) ans = min(ans,dfs(i+1,x,y+t[i]));
	ans = min(ans,dfs(i+1,x,y));
	memo[i][x][y] = ans;
	return ans;
}

int main(void){
	memset(memo,-1,sizeof(memo));
	cin >> N;
	t.resize(N);
	for(int i = 0; i < N; ++i){
		cin >> t[i];
		sum += t[i];
	}
	cout << dfs(0,0,0) << endl;
	return 0;
}


Measured memory_bytes: 147552
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
    string s,t;cin >> s >> t;
    vector<int> start(26,-1);
    vector<int> end(26,-1);
    rep(i,s.size()){
        int a = s[i]-'a';
        int b = t[i]-'a';
        if(start[a]!=-1||end[b]!=-1){
            if(start[a]!=b||end[b]!=a){
                cout << "No" << endl;
                return 0;
            }
        }
        start[a] = b;
        end[b] = a;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  long long in(a, b, c);
  int in(k);
  long long target = max(max(a, b), c);
  long long tmp = a + b + c - target;
  rep(i, k) {
    target *= 2;
  }
  out(target + tmp);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int no=1,n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        if(no*2<=no+k)no*= 2;
        else no+=k;
    }
    cout<<no<<endl;
    return 0;
}


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

using ll = long long;
#define FOR(i,a,b) for(ll (i)=(a);i<(ll)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)((x).size())

int N, W;

int main() {
    cin >> N >> W;
    vector<int> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    vector<ll> a, b, c, d;
    rep(i, N) {
        if (w[i] == w[0] + 0) a.push_back(v[i]);
        if (w[i] == w[0] + 1) b.push_back(v[i]);
        if (w[i] == w[0] + 2) c.push_back(v[i]);
        if (w[i] == w[0] + 3) d.push_back(v[i]);
    }
    sort(RALL(a));
    sort(RALL(b));
    sort(RALL(c));
    sort(RALL(d));

    rep(i, SZ(a) - 1) a[i + 1] += a[i];
    rep(i, SZ(b) - 1) b[i + 1] += b[i];
    rep(i, SZ(c) - 1) c[i + 1] += c[i];
    rep(i, SZ(d) - 1) d[i + 1] += d[i];

    ll ans = 0;
    rep(i, SZ(a) + 1) rep(j, SZ(b) + 1) rep(k, SZ(c) + 1) rep(l, SZ(d) + 1) {
        ll sw = 1LL * i*w[0] + j*(w[0] + 1) + k*(w[0] + 2) + l*(w[0] + 3);
        if (sw <= W) {
            ll sv = 0;
            if (i != 0) sv += a[i - 1];
            if (j != 0) sv += b[j - 1];
            if (k != 0) sv += c[k - 1];
            if (l != 0) sv += d[l - 1];
            ans = max(ans, sv);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main()
{
    ll ans = 1;
    ll a;
    double b;
    cin >> a >> b;
    ll ib = b * 100 + 0.5;
    ans = a * ib / 100;
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int m, f, r;
    int score = 0;

    do {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        score = 0;
        if (m != -1) {
            score += m;
        }
        else {
            cout << "F" << endl;
            continue;
        }
        if (f != -1) {
            score += f;
        }
        else {
            cout << "F" << endl;
            continue;
        }
        if (score >= 80) {
            cout << "A" << endl;
        }
        else if (score >= 65 && score < 80) {
            cout << "B" << endl;
        }
        else if ((score >= 50 && score < 65) || r >= 50) {
            cout << "C" << endl;
        }
        else if (score >= 30 && score < 50) {
            cout << "D" << endl;
        }
        else {
            cout << "F" << endl;
        }
    } while (m != -1 || f != -1 || r != 1);
}



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

using namespace std;

using ll = long long int;

int main() {
    ll N,M; cin >> N >> M;
    vector<pair<ll, ll>> keys;
    for(ll i=0;i<M;i++) {
        ll A,B; cin >> A >> B;
        ll s = 0;
        for(ll j=0;j<B;j++) {
            ll C; cin >> C; C--;
            s |= (1 << C);
        }
        keys.emplace_back(s, A);
    }

    ll twoN = (1<<N);
    vector<ll> dp(twoN, 2e10);
    dp[0] = 0;

    for(ll i=0;i<twoN;i++) {
        for(ll j=0;j<M;j++) {
            ll next = i | keys[j].first;
            dp[next] = min(dp[next], dp[i] + keys[j].second);
        }
    }
    ll ans = dp[twoN-1];
    if(ans == 2e10)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();

        int h = sc.nextInt();
        int w = sc.nextInt();

        sc.close();

        int ans = (H - h) * (W - w);

        System.out.println(ans);
    }

}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
	private Scanner sc;

	int[][] path;
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine()) {
			int n = Integer.parseInt(sc.nextLine());
			if (n == 0) break;
			
			int m = Integer.parseInt(sc.nextLine());

			path = new int[m][4];
			for (int i = 0; i < path.length; i++) {
				String[] nico = sc.nextLine().split(",");

				for (int j = 0; j < 3; j++) {
					path[i][j] = Integer.parseInt(nico[j]);
				}
				path[i][2] = path[i][2] / 100 - 1;
				path[i][3] = 0;
			}
			
			
			boolean[] flag = new boolean[n];
			for (int i = 0; i < flag.length; i++) {
				flag[i] = false;
			}
			flag[path[0][0]] = true;
			flag[path[0][1]] = true;
			path[0][3] = 1;
			
			int total = path[0][2];
			
			int marked = 2;
			while (marked != n) {
				for (int i = 1; i < path.length; i++) {
					if (flag[path[i][0]] != flag[path[i][1]]) {
						flag[path[i][0]] = true;
						flag[path[i][1]] = true;
						total = total + path[i][2];
						path[i][3] = 1;
						
						marked++;
					}
				}
			}
			
			boolean changed = true;
			while (changed == true) {
				changed = false;
				
				for (int i = 0; i < path.length; i++) {
					if (path[i][3] == 0) {
						int max = i;
						
						for (int j = 0; j < path.length; j++) {
							if ((path[j][3] == 0) || (i == j)) continue;
							if ((path[j][0] != path[i][0]) && (path[j][0] != path[i][1])
									&& (path[j][1] != path[i][0]) && (path[j][1] != path[i][1])) continue;
							
							int checknode = -1;
							if ((path[j][0] == path[i][0]) || (path[j][0] == path[i][1])) checknode = path[j][1];
							else checknode = path[j][0];
							
							if ((path[max][2] < path[j][2]) && (check(checknode) >= 2)) {
								changed = true;
								max = j;
							}
						}
						
						total = total + path[i][2] - path[max][2];
						path[i][3] = 1;
						path[max][3] = 0;
					}
				}
			}
			
			System.out.println(total);
		}
	}
	
	private int check(int index) {
		int ans = 0;
		for (int i = 0; i < path.length; i++) {
			for (int j = 0; j < 2; j++) {
				if (path[i][j] == index) ans++;
			}
		}
		
		return ans;
	}
}

Measured memory_bytes: 45376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   string s;
   cin >> s;
   if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
   cout << "Bad" << endl;
   else 
   cout << "Good" << endl;
 }

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int n,k;
int main(){
    read(n),read(k);
    int ans=1;
    for(;n--;){
        int a=ans*2,b=ans+k;
        ans=min(a,b);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
N=int(input())
A=int(input().replace(' ',''))
B=int(input().replace(' ',''))
seed = [str(i+1) for i in range(N)]
L = {int(''.join(x)):i for i,x in enumerate(itertools.permutations(seed, N))}
print(abs(L[A]-L[B]))

Measured memory_bytes: 7272
x = []
y = range(1,14)

for val in y:
	x.append("S " + str(val))
	
for val in y:
	x.append("H " + str(val))
	
for val in y:
	x.append("C " + str(val))
	
for val in y:
	x.append("D " + str(val))
	
r = input()
n = range(1,r + 1)
m = range(1,53-r)

for val in n:
	x.remove(raw_input())
for val in x:
	print val

Measured memory_bytes: 4228