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

public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int L = sc.nextInt();
	int R = sc.nextInt();
	int d = sc.nextInt();
	if (L%d == 0 && R%d == 0) {
	    System.out.print(R/d - L/d + 1);
	} else {
	    System.out.print(R/d - L/d);
	}
    }
}



Measured memory_bytes: 35700
#include <stdio.h>
#include <string.h>
int main (){
    char s[202],p[101],x[101];
    scanf("%s %s",s,p);
    strcpy(x,s);
    strcat(s,x);
    if(strstr(s,p) == NULL)printf("No\n");
    else printf("Yes\n");
    return 0;
}



Measured memory_bytes: 2092
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int N, A, X[51];
long long ans = 0, dp[51][51][3000];

int main() {

	cin >> N >> A;

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

	for (int j = 1; j <= N; j++) {
		for (int k = 0; k <= N; k++) {
			for (int s = 0; s <= 51*51; s++) {
				//cout << "j: " << j << " k: " << k << " X[j]: " << X[j] << endl;
				if (s < X[j]) {
					dp[j][k][s] = dp[j - 1][k][s];
				}
				else if (X[j] <= s && 1 <= k) {	//k>=1でないと、選ぶ選ばないの話ができない
					dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k-1][s-X[j]];
				}else{
					dp[j][k][s] = 0;
				}
			}
		}
	}

	for (int k = 1; k <= N; k++) {
		ans += dp[N][k][k*A];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 60032
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		sc.close();
		long ans = (long)Math.pow(n / k, 3);
		if(k % 2 == 0) {
			ans += (long)Math.pow((n + k / 2) / k, 3);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a,b;
    cin >> a >> b;
    for(int i = 0; ; i++){
        if(a * i - (i - 1) >= b){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
using System;

class sample 
{
		static void Main()
		{
				string[] input = Console.ReadLine().Split(' ');
				string[] input2 =Console.ReadLine().Split(' ');
				int[] N = new int[2];
				N[0] = Convert.ToInt32(input2[0]);
				N[1] = Convert.ToInt32(input2[1]);
				string U = Console.ReadLine();

				N[Array.IndexOf(input,U)] -= 1;

				Console.WriteLine(N[0]+" "+N[1]);
		}
}




Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int A, B;
int main () {
	cin  >> A >> B;
	if (A==1) A+=13;
	if (B==1) B+=13;
	if (A > B) {
		cout << "Alice" << endl;
	}
	if (A<B){
		cout << "Bob" << endl;
	}
	if (A==B){
		cout << "Draw" << endl;
	}

}

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

int N, M;

int main() { 
	scanf("%d%d", &N, &M);
	if (abs(N - M) >= 2) {
		printf("0\n");
		return 0;
	}
	long long ans = 1;
	for (int i = 1; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	for (int i = 1; i <= M; i++) {
		ans *= i;
		ans %= MOD;
	}
	if (N == M) {
		ans *= 2;
		ans %= MOD;
	}
	printf("%lld\n", ans);
}


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

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    string S;
    cin >> S;

    string ans = "AC";
    if(S[0] != 'A') ans = "WA";
    int nC = 0;
    FOR(i, 2, S.size() - 1){
        if(S[i] == 'C') nC++;
    }
    if(nC != 1) ans = "WA";
    int small = 0;
    FOR(i, 0, S.size()){
        int x = (int)(S[i] - 'a');
        if(0 <= x && x < 26) small++;
    }
    if(small != S.size() - 2) ans = "WA";

    cout << ans;
    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	// Scanner sc=new Scanner(System.in);
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	int INF=1<<28;
	double EPS=1e-12;

	int n, m;
	int[] a;

	void run(){
		try{
			String[] ss=br.readLine().split(" ");
			n=Integer.parseInt(ss[0]);
			m=Integer.parseInt(ss[1]);
			ss=br.readLine().split(" ");
			a=new int[n];
			for(int i=0; i<n; i++){
				a[i]=Integer.parseInt(ss[i]);
			}
			solve();
		}catch(IOException e){}
	}

	int logM;
	int[] sum;

	void solve(){
		logM=31-Integer.numberOfLeadingZeros(m)+1;
//		debug(m, logM);
		dp=new int[logM][3*n];
		sum=new int[3*n];
		for(int i=0; i<3*n-1; i++){
			sum[i+1]=sum[i]+a[i%n];
		}
		check(4);
		int left=0, right=(int)1e8;
//		if(false)
			for(; right-left>1;){
				int mid=(left+right)/2;
				if(check(mid)){
					right=mid;
				}else{
					left=mid;
				}
			}
//		debug("left", left, "right", right);
		println(right+"");
	}

	int[][] dp;

	boolean check(int t){
		if(t==0){
			return false;
		}
		for(int i=0; i<logM; i++){
			fill(dp[i], -1);
		}
		for(int i=0; i<3*n; i++){
			// dp[0][i]
			// [i,?)
			int index=binarySearch(sum, sum[i]+t);
//			debug(i, sum[i]+t, index);
			if(index<0){
				index=-index-1;
				index--;
			}
			dp[0][i]=index;
		}
//		debug("dp0", dp[0]);
		for(int j=1; j<logM; j++){
			for(int i=0; i<3*n; i++){
				dp[j][i]=dp[j-1][dp[j-1][i]];
			}
//			debug("dp",j,dp[j]);
		}
		for(int i=0; i<n; i++){
			int now=i;
			for(int b=0; b<logM; b++){
				if((m>>b&1)==1){
					now=dp[b][now];
//					debug("b",b,m);
				}
			}
//			debug("i",i,"now",now);
			if(now-i>=n){
				// テ」ツ?イテ」ツつε」ツ?」テ」ツ?サテ」ツ??
				return true;
			}
		}
		// dp[k][i]:iテ」ツ?凝」ツつ嘉・ツァツ凝」ツつ?」ツ?ヲkテ」ツδ。テ」ツδ凝」ツδ・テ」ツδシテ」ツ?ァテ」ツ??」ツ?妥」ツつ凝ヲツ慊?・ツ、ツァ
//		debug("out");
		return false;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 21000
D=int(input())
c=list(map(int,input().split()))
last=[0 for i in range(26)]
cost=[0 for i in range(26)]
degree=[0 for i in range(26)]
score=0
s=[]
t=[]
for _ in range(D):
  s.append(list(map(int,input().split())))
for _ in range(D):
  t.append(int(input()))
for d in range(D):
  for i in range(26):
    cost[i]+=c[i]*(d+1-last[i])
  k=t[d]-1
  cost[k]-=c[k]*(d+1-last[k])
  last[k]=d+1
  score+=s[d][k]
  print(score-sum(cost))

Measured memory_bytes: 9396
n,x=[int(i)  for i in input().split()]
a=[1]
p=[1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
    if n==0:
        if x==0:
            return 0
        else:
            return 1
    elif n>=1:
        if x==1:
            return 0
        elif 1<x<=1+a[n-1]:
            return f(n-1,x-1)
        elif x==a[n-1]+2:
            return p[n-1]+1
        elif 2+a[n-1]<x<=2*a[n-1]+2:
            return p[n-1]+1+f(n-1,x-2-a[n-1])
        else:
            return 2*p[n-1]+1

print(f(n,x))

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	vector< pair<int , int> >vp ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x , y ;
		cin>>x ;
		vp.push_back({x , i}) ;
	}
	sort(vp.begin() , vp.end()) ;
	for(auto &i : vp)
		cout<<i.second+1<<" ";
	return 0 ;
}

Measured memory_bytes: 1780
import java.util.*;                                                                                  

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 20000; i++) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int a = Integer.parseInt(l[0]);
          String op = l[1];
          int b = Integer.parseInt(l[2]);

          if(op.equals("?")) {
            break;
          } else if(op.equals("+")) {
            System.out.println(a + b); 
          } else if(op.equals("-")) {
            System.out.println(a - b); 
          } else if(op.equals("*")) {
            System.out.println(a * b); 
          } else if(op.equals("/")) {
            System.out.println(a / b); 
          }   
        }   
    }   
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<i64> l(2 * n);
    for (auto& e : l) cin >> e;
    sort(all(l));
    i64 ans = 0;
    for (i64 i = 0; i < 2 * n; i += 2) ans += l[i];
    cout << ans << endl;
}

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


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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);

    for (int i = 0; i < N; i++) {
        cin >> L.at(i);
    }

    sort(L.begin(), L.end());

    int count = 0;


    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = N - 1; k > j; k--) {

                if (L.at(k) < L.at(i) + L.at(j)) {
                    count += k - j;

                    break;
                }

            }

        }
    }

    cout << count << endl;

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, k = MI()
    X = LI()


    ans = INF
    for i in range(n + 1 - k):
        xl = X[i]
        xr = X[i+(k-1)]

        d_l = abs(xl)
        d_r = abs(xr)
        d_d = abs(xl - xr)
        ans = min(ans, min(d_l + d_d, d_r + d_d))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14564
#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 int64_t Int;

int main(){ 
  int K; cin >> K;
  
  if (K == 32) cout << 51 << endl;
  else if (K == 24) cout << 15 << endl;
  else if (K == 16) cout << 14 << endl;
  else if (K == 8 || K == 12 || K == 18 || K == 20 || K == 27) cout << 5 << endl;
  else if (K == 28 || K == 30) cout << 4 << endl;
  else if (K == 4 || K == 6 || K == 9 || K == 10 || K == 14 || K == 21 || K == 22 || K == 25 || K == 26) cout << 2 << endl;
  else cout << 1 << endl;
}


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

int main(void){
    ll n; cin >> n;
    vector<ll>p_num;
    for(int i=1;i<=(ll)pow(n,0.5);i++){
        if(n%i==0) p_num.push_back(i);
    }
    ll ans = max_num;
    for(int i=0;i<p_num.size();i++){
        ll tmp = max(log10(p_num[i])+1,log10(n/p_num[i])+1);
        if(tmp < ans) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
a = input().split()
if int(a[0]) == 0:
    if int(a[1]) != 100:
        print(int(a[1]))
    else:
        print(101)
elif int(a[0]) == 1:
    if int(a[1]) != 100:
        print(int(a[1]) * 100)
    else:
        print(10100)
else:
    if int(a[1]) != 100:
        print(int(a[1]) * 10000)
    else:
        print(1010000)

Measured memory_bytes: 3064
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

if len(c) > 3:
    print("No")
    exit()
elif len(c) == 3:
    if n % 3 != 0:
        print("No")
        exit()
    p = []
    for k , v in c.items():
        if v != n//3:
            print("No")
            exit()
        p.append(k)
    if (p[0] ^ p[1]) ^ p[2] != 0:
        print("No")
        exit()
elif len(c) == 2:
    if n % 3 != 0:
        print("No")
        exit()
    for k,v in c.items():
        if k == 0:
            if v != n//3:
                print("No")
                exit()
        else:
            if v != 2*n//3:
                print("No")
                exit()
elif len(c) == 1:
    for k in c.keys():
        if k != 0:
            print("No")
            exit()
            
print("Yes")

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

bool ss(string s){
    if(s.size()%2 == 1){
        return false;
    }
    string s1="",s2="";
    for(int i=0; i<s.size(); i++){
        if(i<s.size()/2)
            s1 += s.at(i);
        else
            s2 += s.at(i);
    }
    if(s1 == s2)
        return true;
    else
        return false;
}

int main(){
    string s; cin>>s;
    while(s.size()>0){
        s.pop_back();
        if(ss(s)){
            cout<<s.size()<<endl;
            return 0;
        }
    }
}


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

int main(){
  int a,b,k;
  cin >> a >>b;

  k = (a*b)%2;

  if(k==1){
    cout << "Odd" <<endl;
  }

  if(k==0){
    cout << "Even" <<endl;
  }
}

  



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n,t,a,h[1000];
    scanf("%d %d\n%d\n",&n,&t,&a);
    for(int i=0;i<n;i++){
        int b;
        scanf("%d",&b);
        h[i]=b;
    }
    /*printf("%d\n%d\n%d\n",n,t,a);
    for(int i=0;i<n;i++){
        printf("%d ",h[i]);
    }*/
    
    
    long int x,z;
    x=(a-t)*1000+h[0]*6;
    int j=0;
    for(int i=0;i<n;i++){
        long int y=(a-t)*1000+h[i]*6;
        int f=0;
        if(0<=y&&y<=x) f=1;
        else if(x>=y&&y>=0) f=1;
        else if(-x<=y&&y<=x) f=1;
        else if(x<=y&&y<=-x) f=1;
        
        if(f==1) x=y,j=i;
    }
    
    
    printf("%d\n",j+1);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() 
{
	ll n,w;
	cin>>n>>w;
	ll wt[n],val[n],i,j;
	for(i=0;i<n;i++)
	cin>>wt[i]>>val[i];
	ll dp[n+1][w+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
			if(i==0 || j==0)
			dp[i][j]=0;
			else if(wt[i-1]<=j)
			{
				dp[i][j]=max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
			}
			else
			dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w];
	return 0;
}

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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9+7;

vector<int> adj[100005];
vector<ll> height;

int main(){
	int n, m;
	cin>>n>>m;
	height.resize(n+1, 0);
	for(int i=0;i<n;i++){
		cin>>height[i+1];
	}
	for(int i=0;i<m;i++){
		int a, b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		int maxi = 0;
		for(int j=0;j<adj[i].size();j++){
			if(height[adj[i][j]] > maxi){
				maxi = height[adj[i][j]];
			}
		}
		if(height[i] > maxi)
			cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 9032
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

a.sort(reverse=True)
print(2*sum([x for i, x in enumerate(a) if i % 2 == 0])-sum(a))


Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        ll prod = K;
        rep(i, 1, N) {
                prod *= (K - 1);
        }
        cout << prod << endl;
}

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

bool ub(string s, int a, int b){
  vector<char> chr(1,s.at(a-1));
  vector<int> cnt(1,1);
  for(int i = a; i < b; i++){
    for(int j = 0; j < chr.size(); j++){
      if(s.at(i) == chr.at(j)){
        cnt.at(j) ++;
        break;
      }
      else if(j = chr.size()-1){
        chr.push_back(s.at(i));
        cnt.push_back(1);
        break;
      }
    }
  }
  sort(cnt.begin(), cnt.end());
  if(2*cnt.at(cnt.size()-1) > b-a+1)
    return true;
  else
    return false;
}

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int a = -1;
  int b = -1;
  bool bk = false;
  for(int i = 1; i < 4; i++){
    for(int j = 1; j+i <= n; j++){
      if(ub(s,j,j+i)){
        a = j;
        b = j+i;
        bk = true;
        break;
      }
    }
    if(bk)
      break;
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int n, m, time;
  	scanf("%d%d", &n, &m);
  	time = 1800 * m + 100 * n;
  	for (int i = 0; i < m; i++){
    	time *= 2;
    }
  	printf("%d", time);
}

Measured memory_bytes: 128
K = int(input())

import math
from functools import reduce

sum = 3*(K-1)*(K-1) + 3*(K-1) + 1

for i in range(2, K + 1):
    for j in range(2, K + 1):
        for k in range(2, K + 1):
            sum += math.gcd(math.gcd(i,j),k)

print(sum)

Measured memory_bytes: 74380
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long int
#define FILEIO  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
#define maxn 1000000
 

using namespace std;

int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}

signed main() {
//FILEIO;
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int t = 1;
int ans;
while(t <= 5)
{
    int a;
    cin>>a;
    if(a == 0)
        ans = t;
    t++;
}
cout<<ans;










    return 0;
}


Measured memory_bytes: 3632
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    d,g = readInts()
    P = []
    C = []
    for i in range(d):
        p,c = readInts()
        P.append(p)
        C.append(c)
    res = float('inf')
    for bit in range(1 << d):
        # とりあえず全部まとめて入れる場合を考える
        sum = 0
        num = 0
        for i in range(d):
            if bit & (1 << i):
                sum += C[i] + P[i] * 100 * (i + 1)
                num += P[i]
        if sum >= g:
            res = min(res,num)
        else:
            for i in range(d-1,-1,-1):
                if bit & (1 << i):
                    continue
                for j in range(P[i]):
                    if sum >= g:
                        break
                    sum += 100 * (1 + i)
                    num += 1
            res = min(res,num)
    print(res)
if __name__ == '__main__':
  main()


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

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }

    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; }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll N, M; cin >> N >> M;
    vector<ll> A(N), S(N+1);
    rep(i, N){
        cin >> A[i];
        S[i+1] = S[i] + A[i];
    }
    rep(i, N+1){
        S[i] %= M;
    }

    // print(S);

    map <ll, ll> m;
    m[0] = 1;
    ll ans = 0;
    rep2(i, 1, N+1){
        // print(S[i], d[0]);
        ll num = S[i];
        if(S[i] == 0){
            ans += m[0];
        }
        else{
            ans += m[num];
        }
        m[S[i]]++;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 5760
using System;

namespace ABC100D
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int[] ints = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int n = ints[0];
            int m = ints[1];

            Cake[] cakes = new Cake[n];
            for (int i = 0; i < n; i++)
            {
                long[] line = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                cakes[i] = new Cake(line[0], line[1], line[2]);
            }


            long score = 0;
            for (int xt = -1; xt < 2; xt += 2)
            {
                for (int yt = -1; yt < 2; yt += 2)
                {
                    for (int zt = -1; zt < 2; zt += 2)
                    {
                        Score[] scores = new Score[m + 1];
                        scores[0] = new Score(0, 0, 0);
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = m; j > 0; j--)
                            {
                                if (scores[j - 1] == null)
                                {
                                    continue;
                                }

                                if (scores[j] == null)
                                {
                                    scores[j] = scores[j - 1].Add(cakes[i]);
                                    continue;
                                }

                                if (scores[j - 1].Add(cakes[i]).Calc(xt, yt, zt) > scores[j].Calc(xt, yt, zt))
                                {
                                    scores[j] = scores[j - 1].Add(cakes[i]);
                                }
                            }
                        }
                        
                        score = Math.Max(score, scores[m].Calc(xt, yt, zt));
                    }
                }

            }

            Console.WriteLine(score);
        }
    }

    class Cake
    {
        public long X;
        public long Y;
        public long Z;

        public Cake(long x, long y, long z)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }

    class Score
    {
        public long X;
        public long Y;
        public long Z;

        public Score(long x, long y, long z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public Score Add(Cake cake)
        {
            return new Score(X + cake.X, Y + cake.Y, Z + cake.Z);
        }

        public long Calc(int xt, int yt, int zt)
        {
            return X * xt + Y * yt + Z * zt;
        }
    }
}

Measured memory_bytes: 20592
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate
    from collections import Counter

    n = int(readline())
    a = list(map(int, readline().split()))
    counter = Counter()
    counter[0] += 1

    acc = list(accumulate(a))
    ans = 0

    for x in acc:
        ans += counter[x]
        counter[x] += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 135216
N, x = [int(x) for x in input().split()]
a_s = [int(x) for x in input().split()]

a_s.sort()
ans = 0
X = 0
for a in a_s[:-1]:
    if X + a <= x:
        X += a
        ans += 1
    else:
        break
if a_s[-1] == x - X:
    ans += 1

print(ans)


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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if ((W < r + x) || (0 > x - r)){
        cout << "No" << endl;
    }
    else if ((H < r + y) || (0 > y - r)){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
class RMQ:
    INF = int((1<<31)-1)
    
    def __init__(self, n_:int):
        """param: n_(int) 葉の要素数"""
        # 葉の要素数を2のべき乗に
        n = 1
        while n<n_: n*=2
        self.n = n
        # 木全体では n + n/2 + ... = 2n-1
        self.dat = [self.INF]*(2*n-1)
    
    def update(self, k:int, a:int):
        k += self.n - 1
        self.dat[k] = a
        
        while k>0:
            k = (k-1)//2
            self.dat[k] = min(self.dat[2*k+1], self.dat[2*k+2])
            
    def dfs(self, a:int, b:int, k:int, l:int, r:int):
        """
        param a,b(int): 区間[a,b)
        param k(int):   節点の番号
        param l,r(int): 節点kが区間[l,r)に対応"""
        if r<=a or b<=l: return self.INF
        
        if a<=l and r<=b: 
            return self.dat[k]
        else:
            vl = self.dfs(a, b, 2*k+1, l, (l+r)//2)
            vr = self.dfs(a, b, 2*k+2, (l+r)//2, r)
            return min(vl, vr)
    
    def query(self, a:int, b:int):
        return self.dfs(a, b, 0, 0, self.n)
    
####
n,q = map(int, input().split())
rmq = RMQ(n)
for _ in range(q):
    com,x,y = map(int, input().split())
    if com==0:
        rmq.update(x,y)
    else:
        print(rmq.query(x,y+1))
        


Measured memory_bytes: 8708
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<ll,ll> M;

int main(){
  ll X,Y,C=0;cin>>X>>Y;
  while(X<=Y){
    C++;
    X*=2;
  }
  cout << C << endl;
}

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

int H,W;
int INF = 2000000000;
char fid[310][310];
int dp[310][310];
int cost[310][310];

int ans = 0;

int main()
{
    cin >> H >> W;
    for(int i = 0; i < H; i++)for(int j = 0; j < W; j++)cin >> fid[i][j];

    for(int i = 0; i < W - 1; i++)
    {
        for(int j = 0; j < 310; j++)for(int k = 0; k < 310; k++)
        {
            dp[j][k] = INF;
            cost[j][k] = 0;
        }

        for(int j = 0; j <= H; j++)for(int k = 0; k <= H; k++)
        {
            if(j == 0 || k == 0)cost[j][k] = 0;
            else cost[j][k] = cost[j - 1][k - 1] + (fid[j - 1][i] == fid[k - 1][i + 1]);
            //cout << "[" <<j << " " << k << "]" << " : " << cost[j][k] << endl;
        }

        for(int j = 0; j <= H; j++)for(int k = 0; k <= H; k++)
        {
            if(j == 0 || k == 0)dp[j][k] = 0;
            else
            {
                int tmp = INF;
                if(j != 0)tmp = min(tmp, dp[j - 1][k] + cost[j][k]);
                if(k != 0)tmp = min(tmp, dp[j][k - 1] + cost[j][k]);
                dp[j][k] = tmp;
            }
        }

        ans += dp[H][H];
        //cout << i << ":" << dp[H][H] << endl;
    }

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


Measured memory_bytes: 1152
/* ***********************************************
Author        :yang12138
Created Time  :2017年05月18日 星期四 11时00分40秒
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=1005;
const ll INF=1e18;

struct Edge{
	int to,nex,cost;
}e[N<<1];

int head[N],cnt;
void add_edge(int u,int v,int w){
	e[cnt].to=v,e[cnt].nex=head[u],e[cnt].cost=w,head[u]=cnt++;
}

void init(){
	mem(head,-1),cnt=0;
}

ll dis[N];
bool vis[N];
int n;
bool find_negative_loop(){
	for(int i=2;i<=n;i++) dis[i]=INF;
	dis[1]=0;
	for(int k=0;k<n;k++){
		for(int u=1;u<=n;u++){
			for(int i=head[u];~i;i=e[i].nex){
				int v=e[i].to;
				if(dis[v]>dis[u]+e[i].cost){
					dis[v]=dis[u]+e[i].cost;
					if(k==n-1) return 1;
				}
			}
		}
	}
	return 0;
}

ll spfa(){
	for(int i=2;i<=n;i++) dis[i]=INF;
	dis[1]=0;
	queue<int>que;
	que.push(1);
	mem(vis,0);
	while(!que.empty()){
		int u=que.front();
		que.pop();
		vis[u]=0;
		for(int i=head[u];~i;i=e[i].nex){
			int v=e[i].to;
			if(dis[v]>dis[u]+e[i].cost){
				dis[v]=dis[u]+e[i].cost;
				if(!vis[v]) que.push(v),vis[v]=1;
			}
		}
	}
	return dis[n];
}

void bfs(int s,bool* can){
	mem(can,0);
	can[s]=1;
	queue<int>que;
	que.push(s);
	while(!que.empty()){
		int u=que.front();
		que.pop();
		for(int i=head[u];~i;i=e[i].nex){
			int v=e[i].to;
			if(can[v]) continue;
			can[v]=1,que.push(v);
		}
	}
}

int u[N<<1],v[N<<1],w[N<<1];

void solve(){
	init();
	int m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u[i]>>v[i]>>w[i];
		add_edge(v[i],u[i],w[i]);
	}

	bfs(n,vis);
	mem(head,-1),cnt=0;
	for(int i=1;i<=m;i++){
		if(vis[u[i]] && vis[v[i]]){
			add_edge(u[i],v[i],-w[i]);
		}
	}

	if(find_negative_loop()) printf("inf\n");
	else printf("%lld\n",-spfa());
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
   	solve(); 
    return 0;
}


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

signed main() {
  int N; cin >> N;
  vector<int> A(N);
  //vector<pair<int,int>> A(N);
  unordered_map<int,int> map;
  rep(i, N) {
    cin >> A[i];
    map[i-A[i]]++;
  }
  /*rep(i, N) {
    int a; cin >> a;
    A[i] = make_pair(a, i);
  }*/
  

  int ans = 0;
  rep(i, N) {
    int k = i+A[i];
    ans += map[k];
  }
  cout << ans << endl;
}


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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  map<int,int> m;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;

    for(int i = -1; i <= 1; i++){
      int tmp2 = tmp + i;
      if(m.count(tmp2) == 0){
        m[tmp2] = 1;
      } else { 
        m[tmp2]++;
      }
    }
  }

  int max_val = 0;
  for(auto x: m){
    max_val = max(max_val, x.second);
  }
  cout << max_val << endl;
}


Measured memory_bytes: 4736
#include <cmath>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

#define MOD 1000000007

int main()
{
	ios::sync_with_stdio(false);

	ll n, m;
	cin >> n >> m;
	vector<ll> x(n), y(m);	
	for(int i=0; i<n; ++i)
		cin >> x[i];
	for(int i=0; i<m; ++i)
		cin >> y[i];
	

	ll ans1 = 0;
	for(int i=0; i<n; ++i)
		ans1 = (ans1 + (i-(n-i-1))*x[i]%MOD) % MOD;

	ll ans2 = 0;
	for(int i=0; i<m; ++i)
		ans2 = (ans2 + (i-(m-i-1))*y[i]%MOD) % MOD;
		
	cout << ans1*ans2%MOD << "\n";

	return 0;
}


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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll = V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define INF 1e16
#define mod 1e9+7


int main(){
  ll n;
  cin>>n;
  vll count(2);
  ll a=n%100;
  ll b=n/100;
  str ans;
  if(a<13&&a!=0){
    count[1]++;
  }
  if(b<13&&b!=0){
    count[2]++;
  }
  if(count[1]==0){
    if(count[2]==0){
      ans="NA";
    }
    else{
      ans="MMYY";
    }
  }
  if(count[1]==1){
    if(count[2]==0){
      ans="YYMM";
    }
    else{
      ans="AMBIGUOUS";
    }
  }
  co(ans);
}


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

int main() {
  int s;
  cin >> s;
  vector<int> a(1000010);
  a.at(0)=s;
  if(s==1 || s==2){
  cout << 4 << endl; return 0;
  }

	  for(int i=1;i<1000010;i++){
	   if(a.at(i-1)==4){
	  cout << i+3 << endl; 
	  return 0;
	  }
	  if(a.at(i-1)%2==0){
	  a.at(i)=a.at(i-1)/2;
	  }

	  if(a.at(i-1)%2==1){
	  a.at(i)=3*a.at(i-1)+1;
	  }
  }
  
 

	
  }




Measured memory_bytes: 4096
def sub_cnt(c, b):
    cnt = 0
    for i in b:
        while c >= i:
            c -= i
            cnt += 1
    return cnt

n = int(input())

b6 = [6**i for i in range(6, -1, -1)]
b9 = [9**i for i in range(5, -1, -1)]

ans = 10**9
n9 = n // 9
for c9 in range(n9+1):
    cnt = 0
    cn = n - c9*9
    c6 = cn // 6
    c1 = cn % 6
    
    cnt += sub_cnt(c9, b9)
    cnt += sub_cnt(c6, b6)
    cnt += c1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 73796
#include <bits/stdc++.h>
using namespace std;
# define fastio std::ios_base::sync_with_stdio(false)
# define ll long long int
# define endl "\n"

int main() {
    fastio;
    ll n , t;
  cin>>n>>t;
  ll min=1001;
  while(n--)
  {
    ll x,y;
    cin>>x>>y;
    if(y<=t)
    {
      if(x<min)
        min=x;
    }}
  
  if(min==1001)
  {
    cout<<"TLE"<<endl;
  }
  else
    cout<<min<<endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

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

typedef unsigned long long ull;
using namespace std;

ull dp[21], dp2[21];
int a[110];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	while (cin >> n) {
		rep(i, n) cin >> a[i];
		rep(i, 21) dp[i] = 0;
		dp[a[0]] = 1;
		REP(i, 1, n-1) {
			rep(j, 21) dp2[j] = 0;
			rep(j, 21) {
				if (j+a[i] < 21) dp2[j+a[i]] += dp[j];
				if (j-a[i] >= 0) dp2[j-a[i]] += dp[j];
			}
			rep(j, 21) dp[j] = dp2[j];
		}
		cout << dp[a[n-1]] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n,m;
    cin>>n>>m;
    int mat[n][n];
    int lim=10000000;
    int x[m], y[m], d[m];
    rep(i,n)rep(j,n)mat[i][j]=lim;
    rep(i,m){
        int ta,tb,tc;
        cin>>ta>>tb>>tc;
        ta--;
        tb--;
        x[i] = ta;
        y[i] = tb;
        d[i] = tc;
        mat[ta][tb]=tc;
        mat[tb][ta]=tc;
    }
    rep(k,n)rep(i,n)rep(j,n){
        if(mat[i][j]>mat[i][k]+mat[k][j]){
            mat[i][j]=mat[i][k]+mat[k][j];
        }
    }
    int res=0;
    rep(i,m){
        if(d[i] > mat[x[i]][y[i]]){
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int res = n;

        for(int i=0; i<=n; i++) {
            int n6 = i;
            int n9 = n - i;

            int d9 = 9 * 9 * 9 * 9 * 9;
            int d6 = 6 * 6 * 6 * 6 * 6 * 6;

            int sum = 0;
            while(d9 >= 1) {
                int div = n9 / d9;
                sum += div;
                n9 %= d9;
                d9 /= 9;
            }
            while(d6 >= 1) {
                int div = n6 / d6;
                sum += div;
                n6 %= d6;
                d6 /= 6;
            }

            res = Math.min(res, sum);

        }

        System.out.println(res);
    }

}


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

#define pb push_back
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, l;
    cin >> n >> l;

    vector<string> s(n);

    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    
    sort(s.begin(), s.end());
    for (string ss : s) {
        cout << ss;
    }
    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int r;
	cin >> r;
	if (r < 1200) cout << "ABC" << endl;
	else if (r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}

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


def solve(N: int, s: "List[str]"):
    x = 0
    a = 0
    b = 0
    for i in s:
        if(i[0] == 'B' and i[-1] == 'A'):
            x += 1
        elif(i[-1] == 'A'):
            a += 1
        elif(i[0] == 'B'):
            b += 1
    
    
    ####   AC   #####    
    # if(x == 0):
    #     ans1 = min(a,b)
    # else:
    #     ans1 = max(0,x-1)+min(a,b)
    #     if(a > 0 or b > 0):
    #         ans1 += 1
    ans1 = max(0,x-1) + min(a,b)
    if((a > 0 or b >0) and x > 0):
        ans1 += 1
    # if(a == b):
    #     if(x != 0 and a > 0):
    #         ans1 += 1
    # else:
    #     if(a > 0 or b > 0):
    #         ans1 += 1
             

    
    # ans1 = max(0,x-1) 
    # if(a == b):
    #     ans1 += min(a,b)
    # else:
    #     if(x == 0):
    #         ans1 += min(a,b)
    #     else:
    #         ans1 += min(a,b)+1 
    

    ans2 = 0
    for i in s:
        ans2 += i.count('AB')

    print(ans1+ans2)
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn main() {
    input! { h, w, n, mut xy: [(usize1, usize1); n] };
    xy.sort_by_key(|&(_x, y)| y);
    let mut p = vec![vec![]; h + 1];
    for &(x, y) in &xy {
        p[x].push(y);
    }
    let mut ans = 0;
    let (mut i, mut j) = (0, 0);
    loop {
        ans += 1;
        if i == h - 1 || p[i + 1].len() >= 1 && p[i + 1][0] <= j {
            break;
        }
        i += 1;
        if !(j == w - 1 || p[i].len() >= 1 && p[i][0] == j + 1) {
            j += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 24824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int K, N; cin >> K >> N;
  vector<int> A(N); rep(i, N) cin >> A.at(i);
  int difmax = 0;
  for(int i = 0; i < N-1; i++){
    difmax = max(difmax, A.at(i+1) - A.at(i));
  }
  difmax = max(difmax, A.at(0) + K - A.at(N-1));
  cout << K - difmax << endl;
  return 0;
}


Measured memory_bytes: 1024
n,m = map(int,input().split())
path = []
for i in range(n+1):
    path.append([])
for i in range(m):
    a,b = map(int,input().split())
    path[a].append(b)
    path[b].append(a)
for i in range(1,n+1):
    print(len(path[i]))


Measured memory_bytes: 38384
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
double pi=3.14159265;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    cout << a[n-1];
    for(int i=n-2;i>=0;i--){
        cout << ' ' << a[i];
    }
    cout << endl;
}


Measured memory_bytes: 3088
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Point struct {
	x int
	y int
}

type Points []Point

func (l Points) Len() int {
	return len(l)
}

func (l Points) Less(i, j int) bool {
	return l[i].x < l[j].x
}

func (l Points) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func main() {
	s := wordScanner()

	var n int
	scanInts(s, &n)

	reds := make(Points, n)
	for i := range reds {
		scanInts(s, &reds[i].x, &reds[i].y)
	}

	blues := make(Points, n)
	for i := range blues {
		scanInts(s, &blues[i].x, &blues[i].y)
	}

	sort.Sort(reds)
	sort.Sort(blues)

	c := 0
	for _, b := range blues {
		i := -1
		for j, r := range reds {
			if isInner(r, b) {
				if i == -1 || reds[i].y < reds[j].y {
					i = j
				}
			}
		}
		if i != -1 {
			c++
			reds = append(reds[:i], reds[i+1:]...)
		}
	}
	fmt.Println(c)
}

func isInner(inner, outer Point) bool {
	return outer.x > inner.x && outer.y > inner.y
}

func wordScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func scanInts(s *bufio.Scanner, vals ...*int) {
	for i := range vals {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		*vals[i] = n
	}
}


Measured memory_bytes: 640