akhauriyash/Code-Regression huggingface dataset:
n,k=[int(i) for i in raw_input().split()]
a=[int(i) for i in raw_input().split()]
s=0
for i in a:
    s+=i
val=(s+n+k-1)/(n+k)
for i in a:
    k-=i/val
if(k>=0):
    print val
else:
    k=abs(k)
    l=[]
    for i in a:
        x=i/val
        if(x>0):
            l.append((i+x-1)/x)
    l.sort()
    print l[k-1]


Measured memory_bytes: 103652
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define faster ios::sync_with_stdio(false)
#define ll long long int
#define sz 200005
#define mp(x,y) make_pair(x,y) 
#define pii pair<long long int,long long int>
#define tor ::iterator
#define letsgo long long  int i,j,k,q=0,t,tmp,n,flg=0,cntr=0,maxxer = 0
#define fi first
#define se second
#define be begin()
#define en end()
#define mod 1000000007
#define debug(x) cout<<" "<<x<<endl

ll dp[100005] ;
int val[100005][3];
int main(){
	faster;
	letsgo; 
	cin>>n>>k;
	vector <ll> v;
	for(i=0;i<n+1;i++)
		dp[i]=100000000005ll;
	for(i=0;i<n;i++){
		cin>>tmp;
		v.pb(tmp);
	}
	ll cnt=0;
	dp[0] = 0;
	for(i=1;i<n;i++){
		for(j=i-1;j>=max(0ll,i-k);j--){			
			dp[i] = min(dp[i],	 abs(v[i]-v[j])+dp[j]);	
		}
	}
	cout<<dp[n-1]<<endl;


}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();
		int left = 0;

		StringBuilder l = new StringBuilder("");
		StringBuilder r = new StringBuilder("");

		for (int i = 0; i < n; i++) {
			String ss = s.substring(i, i + 1);

			if (ss.equals("(")) {
				left++;
			} else {
				if (left == 0) {
					l.append("(");
				} else {
					left--;
				}

			}
		}

		for (int i = 0; i < left; i++) {
			r.append(")");
		}

		System.out.println(l.toString() + s + r.toString());

	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
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 ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 1; i < n; i++) {
        int a;
        cin >> a;
        a--;
        g[a].push_back(i);
    }
    for(int i = 0; i < n; i++) {
        cout << g[i].size() << endl;
    }
}

Measured memory_bytes: 14288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

/// Lib
///

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string n; cin >> n;
    int n_num = stoi(n);

    int ans = 0;
    for(int i = 1; i <= n_num; ++i){
        string tmp = to_string(i);
        int tmp_keta = tmp.size();
        if(tmp_keta % 2 != 0){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int dist[100005]={};
vector<int> adj[100005];
int d[100005]={};
void toposort()
{
	int u,i;
	vector<int>::iterator it;
	for(i=1;i<=n;i++)
	{
		for(it=adj[i].begin();it!=adj[i].end();it++)
			d[*it]++;
	}
	queue<int> q;
	for(i=1;i<=n;i++)
	{
		if(d[i]==0)
			q.push(i);
	}
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(it=adj[u].begin();it!=adj[u].end();it++)
		{
			d[*it]--;
			if(dist[*it]<(dist[u]+1))
				dist[*it]=dist[u]+1;
			if(d[*it]==0)
				q.push(*it);
		}
	}
}
int main()
{
	int m,max1=0,u,v,i;
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>u>>v;
		adj[u].push_back(v);
	}
	toposort();
	for(i=1;i<=n;i++)
	{
		if(dist[i]>max1)
			max1=dist[i];
	}
	cout<<max1<<endl;
}


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

int main() {
	int n;
	cin >> n;
	queue<int> que;
	que.push(3);
	que.push(5);
	que.push(7);
	int cnt = 0;
	auto f = [&](int a) {
		map<int, int> mp;
		while (a) {
			mp[a % 10]++;
			a /= 10;
		}
		if (mp[3] && mp[5] && mp[7]) return true;
		else return false;
	};
	while (que.size()) {
		int tmp = que.front(); que.pop();
		int res1 = tmp * 10 + 3;
		if (res1 <= n) {
			if (f(res1)) cnt++;
			que.push(res1);
		}
		else break;
		int res2 = tmp * 10 + 5;
		if (res2 <= n) {
			if (f(res2)) cnt++;
			que.push(res2);
		}
		else break;
		int res3 = tmp * 10 + 7;
		if (res3 <= n) {
			if (f(res3)) cnt++;
			que.push(res3);
		}
		else break;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d);
    
    return 0;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005;
const int mod=1e9+7;
char s[N];
int cnt[26];
int n;
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
		cnt[s[i]-'a']++;
	int ans=1;
    for(int i=0;i<26;i++)
		ans=1ll*ans*(cnt[i]+1)%mod;
    ans=(ans-1+mod)%mod;
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,x,y,z,i,j;
		cin>>n>>x>>y;		

		map<ll,ll> m;

		for(i=1;i<n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				if(i<=x)
				{
					z=min(j-i,((x-i+1+abs(y-j))));
					m[z]++;
				}
				else
				{
					z=min(j-i,(i-x+1+abs(y-j)));
					m[z]++;
				}
			}
		}

		for(i=1;i<n;i++)	cout<<m[i]<<endl;
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 384
N, T = map(int, input().split())
ct = []
for _ in range(N):
    c, t = map(int, input().split())
    if t > T:
        pass
    else:
        ct.append([c,t])
try:
    print(sorted(ct, key=lambda x: x[0])[0][0])
except IndexError:
    print('TLE')

Measured memory_bytes: 3060
import java.util.Scanner;


/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int diceO[][];
		int diceC[][];
		int n = 0;
		int num1;
		int num2 = 1;
		String str = "";
		Boolean breakp = null;
		
		n = as.nextInt();
		
		diceO = new int[n][6];
		diceC = new int[n][6];
		
		for(int i=0;i<n;i++){
			for(int j=0;j<6;j++){
				
				diceO[i][j] = as.nextInt();
				
			}
		}
		diceC = diceO;
		for(num1=0;num1<n;num1++){
			for(num2=num2+num1;num2<n;num2++){
				
				breakp = Spin.DoubleCheck(diceO, diceC, num1, num2);
				
				if(breakp){
					
					str = "No";
					break;
					
				}
				else{
					
					str = "Yes";
					
				}		
				
			}
			if(breakp){
				
				break;
				
			}
		}
		
		System.out.println(str);

	}

}

class Spin{
	
	public static int[][] diceSpin(int[][] dice,String spn,int num2) {
	
		int tre = 0;	
			
		switch (spn){
		case "x":
			tre = dice[num2][4];
			dice[num2][4] = dice[num2][0];
			dice[num2][0] = dice[num2][1];
			dice[num2][1] = dice[num2][5];
			dice[num2][5] = tre;
			break;
			
		case "y":
			tre = dice[num2][3];
			dice[num2][3] = dice[num2][0];
			dice[num2][0] = dice[num2][2];
			dice[num2][2] = dice[num2][5];
			dice[num2][5] = tre;
			break;
			
		case "z":
			tre = dice[num2][2];
			dice[num2][2] = dice[num2][1];
			dice[num2][1] = dice[num2][3];
			dice[num2][3] = dice[num2][4];
			dice[num2][4] = tre;
			break;
					
		}
			
		return dice;
		
	  }
	
	public static Boolean Samecheck(int[][] dice1,int[][] dice2,int num1,int num2){
		
		Boolean flag = null;
		
		for(int i=0;i<6;i++){
			
			if(dice1[num1][i] != dice2[num2][i]){
				
				flag = false;
				break;
			}
			else{
				
				flag = true;
				
			}
			
		}
		
		return flag;
		
	}
	
	public static Boolean Check(int[][] dice1,int[][] dice2,int sp,int num1,int num2){
		
		Boolean flag = null;
		String spn = null;
		
		switch (sp){
		case 0:
			spn = "x";
			break;
			
		case 1:
			spn = "y";
			break;
			
		case 2:
			spn = "z";
			break;
			
		}
		
		for(int j=0;j<4;j++){		
			
			dice2 = Spin.diceSpin(dice2, spn,num2);
			if(Spin.Samecheck(dice1, dice2,num1,num2)){
				
				flag = true;
				break;
			
			}
			
			flag = false;
			
		}
		
		return flag;
		
	}
	
	public static Boolean DoubleCheck(int[][] dice1,int[][] dice2,int num1,int num2){
		
		Boolean breakp = null;
		
		for(int i=0;i<3;i++){
			for (int j=0;j<4;j++){
				
				for(int k=0; k<j; k++){
					
					dice2 = Spin.diceSpin(dice2, "x",num2);
					
				}
				
				breakp = Spin.Check(dice1, dice2, i,num1,num2);
				
				if(breakp == true){
					
					break;
					
				}
				
			}
			
			if(breakp == true){
				
				break;
				
			}
		
		}
		
		return breakp;
		
	}
	
}

Measured memory_bytes: 28656
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long int;
using namespace std;

int main() {
    fastio;
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

bool prime[100002];
int sum[100001];

#define MAX_N 100000

void Prime_Number() {
	memset(prime, true, sizeof(prime));
	prime[0] = false;
	FOR(i, 1, sqrt(MAX_N)) {
		if(prime[i]) {
			for(int j = (i + 1); (i + 1) * j <= MAX_N; ++j) {
				prime[(i + 1) * j - 1] = false;
			} 
		}
	}
}

int q;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    Prime_Number();
    rep(i, MAX_N) {
        int latte = (i + 2) / 2;
        if(prime[i] && prime[latte - 1]) ++sum[i];
    }
    rep(i, MAX_N) sum[i + 1] += sum[i];
    cin >> q;
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        cout << sum[b - 1] - sum[a - 2] << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>

int main (){
   //shiritori check with A,B,C strings
   char aaa[10] = {0};
   char bbb[10] = {0};
   char ccc[10] = {0};
   
   scanf("%s %s %s",aaa,bbb,ccc);
   int an = 0;
   while(aaa[an]!=0){
      an++;
   }
   int bn = 0;
   while(bbb[bn]!=0){
      bn++;
   }
   int cn = 0;
   while(ccc[cn]!=0){
      cn++;
   }
   
   if(aaa[an-1] == bbb[0] && bbb[bn-1] == ccc[0]){
      printf("YES\n");
   }else{
      printf("NO\n");
   }

   return EXIT_SUCCESS;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c,d,e;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>ch;
	if(ch=='A'){cout<<"T";}
	else if(ch=='T'){cout<<"A";}
	else if(ch=='G'){cout<<"C";}
	else if(ch=='C'){cout<<"G";}




	cout<<endl;
} 


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static final String AC = "AC";
    private static final String WA = "WA";
    private static final String TLE = "TLE";
    private static final String RE = "RE";

    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for (int i = 0; i < n; i++) {
            final String s = scanner.next();
            switch (s) {
                case AC:
                    ac++;
                    break;
                case WA:
                    wa++;
                    break;
                case TLE:
                    tle++;
                    break;
                case RE:
                    re++;
                    break;
            }
        }

        System.out.println(AC + " x " + ac);
        System.out.println(WA + " x " + wa);
        System.out.println(TLE + " x " + tle);
        System.out.println(RE + " x " + re);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

Measured memory_bytes: 48488
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;

const int N = 1010;
char s[15][N];
int num[15][N];


int main()
{
	int h, w, k , ans = 0;
	scanf("%d%d%d", &h, &w, &k);
	for (int i = 1; i <= h; i++) {
		scanf("%s", s[i] + 1);
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++)
			num[i][j] = num[i - 1][j] + num[i][j - 1] - num[i - 1][j - 1] + s[i][j] - '0';
	}
	if (h == 1) {
		int st = 0;
		for (int i = 1; i <= w; i++) {
			if (num[1][i] - num[1][st] == k && i < w ) {
				ans++;
				st = i;
			}
			printf("%d\n", ans);
			return 0;
		}
	}
	ans = h * w;
	for (int i = 0; i < (1 << (h - 1)); i++) {
		int c = 0, r;
		int res = __builtin_popcount(i);
		bool g  = 0;
		for (int j = 1; j <= w; j++) {
			bool f  = 0;
			r = 0;
			for (int u = 1; u <= h; u++) {
				if ((1 & (i >> (u - 1))) || u == h) {
					int t = num[u][j] + num[r][c] - num[r][j] - num[u][c];
					r = u;
					if (t > k) f = 1;
				}
			}
			if (f && j == c + 1) {
				g = 1;
				break;
			}
			if (f)
			{
				res++;
				c = j - 1;
			}
		}
		if (!g) ans = min(res, ans);
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
N,T = map(int,input().split())
L = input().split()
M = list(map(int,L))
s = M[N-1]
M.append(s)
ans = 0
c = 0
k = 0
while c<N:
  if M[c]+T >= M[c+1]:
    c += 1
    k += 1
  else:
    if k == 0:
      ans += T
      c += 1
    else:
      ans += T+M[c]-M[c-k]
      c += 1
      k = 0
ans += T+M[c]-M[c-k]
print(ans)

Measured memory_bytes: 25712
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int x;
    cin >> x;
    int ans = 0;
    for(int i = 1; i <=  x * x; i++){
        if(i * (i + 1) / 2 >= x){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}
int k = read();
int ans[520][520] , nex[520];
int main()
{
	if(k <= 500)
	{
		cout << k << '\n';
		for(int i = 1 ; i <= k ; ++i) for(int j = 1 ; j <= k ; ++j) cout << i << (j == k ? '\n' : ' ');
		return 0;
	}
	else
	{
		cout << 500 << '\n'; k -= 500; int id = 0;
		for(int i = 1 ; i <= 500 ; ++i) nex[i] = i + 1; nex[500] = 1;
		for(int i = 1 ; i <= 500 ; ++i)
		{
			int a = ++id , b = (k == 0 ? id : ++id); if(a != b) k--;
			for(int x = 1 , y = i ; x <= 500 ; x++ , y = nex[y])
				ans[x][y] = x & 1 ? a : b;
		}
		for(int i = 1 ; i <= 500 ; ++i) for(int j = 1 ; j <= 500 ; ++j) cout << ans[i][j] << (j == 500 ? '\n' : ' ');
	}
	return 0;
}



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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var list = new List<int>();

            list.Add(str[0] * 10 + str[1] + str[2]);
            list.Add(str[0] + str[1] * 10 + str[2]);
            list.Add(str[0] + str[1] + str[2] * 10);

            Console.WriteLine(list.Max());
        }
    }
}


Measured memory_bytes: 13268
N = int(input())
max_value = 10**18
answer = 1
over = False
a = list(map(int, input().split()))


for i in range(N):
    answer *= a[i]
    if answer > max_value:
        over = True
        break

if 0 in a:
    print(0)
else:
    if not over:
        print(answer)
    else:
        print(-1)
    

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

int main(){
  vector<int> vec(3);
  int sum = 0;
  for (int i = 0; i < 3; i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  if (sum <= 21) {
    cout << "win" << endl;
  }
  else{
   cout << "bust" << endl;
  }
}

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

using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n,happiness=0;
  cin >> n;
  
  while(n >=5){
    if(n >= 500) happiness+=1000,n-=500;
    else happiness+=5,n-=5;
  }
  
  printf("%d",happiness);
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int a,b;cin>>a>>b;
    cout<<a*b;    
    
}

Measured memory_bytes: 3652
N, M, Q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for _ in range(Q):
    abcd = list(map(int, input().split()))
    a.append(abcd[0]-1)
    b.append(abcd[1]-1)
    c.append(abcd[2])
    d.append(abcd[3])

import itertools
ans = 0
for p in itertools.combinations_with_replacement([i for i in range(1, M+1)], N):
    tmp_ans = 0
    for i in range(Q):
        if p[b[i]] - p[a[i]] == c[i]:
            tmp_ans += d[i]
    if tmp_ans > ans:
        ans = tmp_ans
print(ans)


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

int main()
{
	long N;
	cin >> N;

	long zoroCount = 0;
	bool isFound = false;
	for (long i = 0; i < N; ++i)
	{
		long d1;
		cin >> d1;
		long d2;
		cin >> d2;

		if (d1 == d2)
		{
			zoroCount++;
			if (zoroCount == 3)
			{
				isFound = true;
				break;
			}
		}
		else
		{
			zoroCount = 0;
		}
	}

	if (isFound)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
char s[mx];
int main(){
  int n,a,b;
  scanf("%d %d %d %s",&n,&a,&b,s);
  int c=0,o=0;
  for(int i=0;i<n;i++){
    bool ok=false;
    if(s[i]=='a'){
      if(c<a+b){
        ok=true;
        c++;
      }
    }
    else if(s[i]=='b'){
      if(c<a+b && o<b){
        ok=true;
        o++;
        c++;
      }
    }
    if(ok)puts("Yes");
    else puts("No");
  }
  return 0;
}


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

int main()
{
	string  word; //string型直接代入できる
	char change[1200] = { 0 };

	getline(cin, word);//空白が入ってても1行分読み込める

	for (int i = 0; i < word.length(); i++)
	{
		if (word[i] >= 'A' && word[i] <= 'Z') change[i] = word[i] + 32;
		else if (word[i] >= 'a' && word[i] <= 'z') change[i] = word[i] - 32;
		else change[i] = word[i];
		cout << change[i];
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 3156
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    counts = [0] * 62
    for val in A:
        i = 0
        while val > 0:
            counts[i] += val % 2
            val //= 2
            i += 1
    ret = 0
    for i, cnt in enumerate(counts):
        ret += (2 ** i) * (cnt) * (N - cnt)
        ret %= MOD
    print(ret)
    return

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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 121832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  cin>>n;
  if(n==0){cout<<0;return 0;}
  vector<int> a;
  i=-2;
  while(n){
    int b=n%i?1:0;
    a.push_back(b);
    n-=b;
    n/=-2;
  }
  reverse(a.begin(),a.end());
  for(int i=0;i<a.size();i++){
    cout<<a[i];
  }
  return 0;
}

Measured memory_bytes: 256
a = [float(input()) for i in range(6)]

limit = []
for i in range(5):
    limit.append(a[i + 1])

neck = min(limit)

if a[0] % neck == 0:
    ans = a[0] // neck + 4
else:
    ans = a[0] // neck + 5


print(int(ans))

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

int main(){
    int x, y;

    cin >> x >> y;

    int a = y - 2 * x;

    if (a < 0){
        cout << "No" << endl;
        return 0;
    }

    if (a % 2 == 0){
        int b = a / 2;
        if (b <= x ){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
 }

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] stickArr = new int[n];
		for(int i = 0; i < n; i++) {
			stickArr[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(stickArr);
		int ans = 0;
		for(int i = stickArr.length - 1; i >= stickArr.length - k; i--) {
			ans += stickArr[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<string.h>
int main()
{
	char s[200001];
	std::cin >> s;
	int len = strlen(s);
	int a, z;
	for(int i = 0;; i++)
	{
		if(s[i] == 'A')
		{
			a = i;
			break;
		}
	}
	for(int i = len - 1;; i--)
	{
		if(s[i] == 'Z')
		{
			z = i;
			break;
		}
	}
	std::cout << z - a + 1 << std::endl;
	return 0;
}

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

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

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

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto& e : s) cin >> e;

    i64 ans = 0;
    vector<i64> dxy { 0, 1, 0, -1, 0 };
    for (i64 i = 0; i < h; i++) {
        for (i64 j = 0; j < w; j++) {
            if (s[i][j] == '_') continue;

            queue<p64> q;
            q.emplace(i, j);
            i64 bcnt = 0, wcnt = 0;
            while (!q.empty()) {
                auto [ y, x ] = q.front(); q.pop();
                if (s[y][x] == '_') continue;
                (s[y][x] == '#' ? bcnt : wcnt)++;
                for (i64 k = 0; k < 4; k++) {
                    i64 ny = y + dxy[k], nx = x + dxy[k + 1];
                    if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
                    if (s[ny][nx] == '_' || s[y][x] == s[ny][nx]) continue;
                    q.emplace(ny, nx);
                }
                s[y][x] = '_';
            }
            ans += bcnt * wcnt;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3840
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

ll n, ans[maxn], c[maxn], sz[maxn];
unordered_map<ll, ll> cnt[maxn];
vector<ll> g[maxn];
bool vis[maxn];

void dfs(ll v){
	ll u;
	vis[v] = 1;
	sz[v] = 1;
	for(ll i = 0; i < g[v].size(); i++){
		u = g[v][i];
		if(vis[u]) continue;
		dfs(u);
		sz[v] += sz[u];
		ll x = sz[u] - cnt[u][c[v]];
		ans[c[v]] += x * (x + 1) / 2;
		if(cnt[v].size() < cnt[u].size()) cnt[v].swap(cnt[u]);
		for(unordered_map<ll, ll>::iterator it = cnt[u].begin(); it != cnt[u].end(); it++){
			cnt[v][it -> F] += it -> S;
		}
	}
	cnt[v][c[v]] = sz[v];
	return;
}

int main(){
	ll v, u;
	fast_io;
	
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> c[i];
	}
	for(ll i = 1; i < n; i++){
		cin >> v >> u;
		g[v].pb(u);
		g[u].pb(v);
	}
	dfs(1);
	for(ll i = 1; i <= n; i++){
		ll x = n - cnt[1][i];
		ans[i] += x * (x + 1) / 2;
		cout << n * (n + 1) / 2 - ans[i] << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 73216
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<string.h>
using namespace std;
int main()
{
   string s;
   cin>>s;
   int count=0;
   int count1=0;
   for(int i=0;i<3;i++)
   {
       if(s[i]=='A')
       count++;
       else if(s[i]=='B')
       count1++;
   }
   if(count==3||count1==3)
   cout<<"No"<<endl;
   else
   cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import itertools
num = int(input())
p = tuple(input().split())
q = tuple(input().split())
lister = [str(s) for s in range(1,num+1)]
comb = list(itertools.permutations(lister))
memory1 = 0
memory2 = 0
for t in range(len(comb)):
    if p == comb[t]:
        memory1 = t+1
    if q == comb[t]:
        memory2 = t+1
print(abs(memory1-memory2))

Measured memory_bytes: 8052
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
//typedef long long ll;
const int N=2000005;
int f[N];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int a[N];
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >>n>>m;
	for(int i=1;i<=n;i++){int tmp;cin >>tmp;a[tmp]=i;f[i]=i;}
	for(int j=1;j<=m;j++)
	{
		int u,v;
		cin >>u>>v;
		if(find(u)!=find(v))f[find(u)]=find(v);
	}
	int ans=0;
	for(int i=1;i<=n;i++)if(find(i)==find(a[i]))ans++;
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
// #include<chrono>
using namespace std;
// using namespace std:chrono;
#define ll long long
#define pb push_back
#define mk make_pair
#define fori0 for(ll i=0;i<n;i++)
#define fori1 for(ll i=1;i<=n;i++)
#define modu 1000000007
ll mod_power(ll n,ll x,ll mod)
{
	ll res = 1; 
	n=n%mod;
	if(n==0)
	{
		return 0;
	}  
    while(x>0) 
    {   
        if(x&1)
        { 
            res=(res*n)%mod; 
        }   
        x=x>>1; 
        n=(n*n)%mod;
    } 
    return res; 
}
ll power(ll n,ll x)
{
	ll res = 1;   
    while(x>0) 
    {   
        if(x&1)
        { 
            res=res*n; 
        }   
        x=x>>1; 
        n=n*n;
    } 
    return res; 
}
ll countDigit(ll n) 
{ 
    if (n == 0) 
        return 0; 
    return 1 + countDigit(n / 10); 
} 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w", stdout);
	ll t;
	// cin>>t;
	t=1;
    ll z=t;
    while(t--)
    {
        ll n,x,t;
        cin>>n>>x>>t;
        if(n%x==0)
        {
            cout<<t*(n/x)<<"\n";
        }  
        else
        {
            // cout<<"Harsh";
            ll ans=n/x;
            ans++;
            cout<<ans*t<<"\n";
        }
    }
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    
    vector<int> ans;
    int l=0,r=0;
    for(int i=0;i<=s.size();i++){
        if((i==s.size()) or (s[i]=='R' and i!=0 and s[i-1]=='L')){
            
            ans.push_back(1+(r/2)+((l-1)/2));
            
            ans.push_back(1+(l/2)+((r-1)/2));
            l=0; r=1;
            
        }
        else if(s[i]=='R') r++;
        else l++;
    }
    int j=0;
    for(int i=0;i<s.size();i++){
        if((i==s.size()-2 and s[i]=='R') or (s[i]=='R' and s[i+1]=='L')){
            cout<<ans[j++]<<" "<<ans[j++]<<" ";
            i++;
        }
        else cout<<"0 ";
    }
    cout<<"\n";
}

Measured memory_bytes: 1096
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m, r[110000];
vector<ll> s;

bool solve(int index) { //条件判定
	ll cnt = 0;
	REP(i, n) {
		cnt += s.end() - lower_bound(ALL(s), index - s[i]) - 1;
	}
	return (cnt >= m);
}

int nibutan() { //ちゃろー！

	int ng = 300000; //最大値ならs.size()
	int ok = 0; // 最大値なら0

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (solve(mid)) ok = mid;
		else ng = mid;
	}
	return ok; //満たさない最大ならng
}
int main() {
	cin >> n >> m;
	s.resize(n);
	REP(i, n)cin >> s[i];
	
	s.push_back(INF);
	sort(ALL(s));
	REPR(i, n - 1) {
		r[i] += s[i];
		r[i] += r[i + 1];
	}
	ll t = nibutan();
	ll tcnt = 0, ans = 0;
	REP(i, n) {
		ll now = lower_bound(ALL(s), t + 1 - s[i]) - s.begin();
		tcnt += n - now;
		ans += s[i] * (n - now) + r[now];
		//cout << now << " "  << r[now] << endl;
	}
	cout << ans + (m - tcnt) * t << endl;


}





Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),a=nxt(),b=nxt();
    cout<<min(n*a,b)<<endl;
    
    
    return 0;   
}


 
 


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

#define int long long
#define INF 9223372036854775807
#define M_PI 3.14159265358979323846
#define double long double

int mod = INF;

int fastPow(int b, int e){int r = 1;while(e){if(e%2 == 1){r*=b;r%=mod;}b*=b;b%=mod;e/=2;}return r;}
int pgcd(int a, int b){ if(a%b == 0) return b; else return pgcd(b, a%b);}
int sign(int a){if(a < 0){ return -1;}if(a == 0) {return 0;}if(a > 0) {return 1;}}
bool isPrime(int a){if(a == 1) {return false;}int f = sqrt(a);for(int i = 2; i<=f; i++){if(a%i == 0){return false;}}return true;}
int toInt(string s){int tot = 0;for(int i = s.size()-1; i >= 0; i--){tot+=((s[i]-'0')%mod)*fastPow(10,i);tot%=mod;}return tot;}
string toString(int a){string s = "";while(a){s = (char)('0'+a%10) + s;a/=10;}return s;}

vector<int> we(109);
vector<int> v(109);

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, w;
    cin >> n >> w;
    for(int i = 1; i <= n; i++){
        cin >> we[i] >> v[i];
    }
    vector<int> memo(w+1,0);
    for(int i = 1; i <= n; i++){
        for(int j = w-we[i]; j >= 0; j--){
            memo[j+we[i]] = max(memo[j+we[i]], memo[j]+v[i]);
        }
    }
    cout << memo[w] << endl;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

ans = 0
for d in range(62):
    mask = (1 << d)
    zero = len([0 for a in A if (a & mask) == 0])
    ans += zero * (N - zero) * mask % MOD
print(ans % MOD)


Measured memory_bytes: 42212
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
seq = [0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=='<':
        seq[i+1] = seq[i]+1
for j in range(len(S)-1,-1,-1):
    if S[j]=='>':
        seq[j] = max(seq[j],seq[j+1]+1)
print(sum(seq))


Measured memory_bytes: 23336
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010 
using namespace std;
int a[N], b[N], c[N];
int main()
{
	int n;
	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]);
	for (int i = 1; i < n; i ++ ) 
		scanf("%d", &c[i]);
	int ans = 0;
	for (int i = 1; i <= n; i ++ ) 
		ans += b[a[i]];
	for (int i = 2; i <= n; i ++ ) 
		if (a[i] == a[i - 1] + 1) 
			ans += c[a[i] - 1];
	printf("%d", ans);
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int main() {

	FAST;

	int a;
	cin >> a;
	cout << a + a * a + a * a * a << '\n';
	return 0;
}

Measured memory_bytes: 3564
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
const int maxn = 1e4;
const int inf = 1<<30;
typedef long long LL;
int n,m;
int main(){
	cin >> n >> m;
	map<int,int>mp;
	map<int,bool>ans;
	ans[1] = true;
	for(int i = 2;i<=n;i++)
		ans[i] = false;
	for(int i = 1;i<=n;i++)
		mp[i] = 1;
	for(int i = 1;i<=m;i++){
		int a,b;
		cin >> a >> b;
		mp[a]--;
		mp[b]++;
		if(ans[a]) ans[b] = true;
		if(mp[a]==0) ans[a] = false;
	}
	int cont = 0;
	for(int i = 1;i<=n;i++){
		if(ans[i]) cont++;
	}
	cout << cont << endl;
	return 0;
}

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

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

	vector<int> button(N+1);
	for(int i = 1; i <= N; i++)
		cin >> button.at(i);

	int count = 0;
	int push = 1;
	while(1){
		count++;
		if(button.at(push) == 2){
			cout << count << endl;
			break;
		}else if(button.at(push)){
			int tmp = push;
			push = button.at(push);
			button.at(tmp) = 0;
		}else{
			cout << "-1" << endl;
			break;
		}
	}
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
int N;
cin >> N;
vector<int>d(N);
REP(i, N) cin >> d.at(i);
sort(all(d));

int cnt = 0;
int max_d;
for(int i = N - 1; i >= 0; i--){ 
   if(i == N - 1) {
     max_d = d.at(i);
     cnt++;
     continue;
   }
   if(d.at(i) != max_d){
     max_d = d.at(i);
     cnt++;
   }
}
print(cnt);
 }

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



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

typedef long long ll;
typedef pair<int,int> P;
typedef unsigned int uint;
typedef vector<int> V;
typedef vector<vector<int> > VV;
typedef pair<int,pair<P,int> > PP;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

const int INF = 1 << 28;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0,-1};
const int dy[] = {1, 0,-1, 0};

int main()
{
    int n, m;
    while (cin >> n >> m, m || n) {
        VV d(m, V(n));
        rep(i,m) rep(j,n) {
            cin >> d[i][j];
        }

        V c(4);
        rep (i, 4) {
            cin >> c[i];
        }

        vector<vector<vector<int> > > v(m, VV(n, V(4, INF)));
        VV dp (m, V(n, INF));
        dp[0][0] = v[0][0][0] = 0;
        priority_queue<PP, vector<PP>, greater<PP> >  que;
        que.push(PP(0, pair<P,int>(P(0,0), 0)));

        while (!que.empty()) {
            PP pp = que.top(); que.pop();
            int x = pp.second.first.first;
            int y = pp.second.first.second;
            int d_ = pp.second.second;

            if (v[x][y][d_] < pp.first) continue;

            rep (i,4) {
                int dir = (i + d_) % 4;
                int cost = (i == d[x][y] ? 0 : c[i]) + v[x][y][d_];
                int nx = dx[dir] + x, ny = dy[dir] + y;
                if (0 <= nx && nx < m && 0 <= ny && ny < n && v[nx][ny][dir] > cost) {
                    v[nx][ny][dir] = cost;
                    dp[nx][ny] = min(dp[nx][ny], cost);
                    que.push(PP(cost, pair<P,int>(P(nx,ny), dir)));
                }
            }
        }

        cout << dp[m-1][n-1] << endl;
    }


    return 0;
}

Measured memory_bytes: 1388
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int N,K,T,U,V,L;
const int MAX_N = 200;
int d[MAX_N];

const double EPS = 1e-8;
bool eq(double a,double b){return abs(a-b) < EPS;}

int main(){
  cin >> N >> K >> T >> U >> V >> L;
  for(int i = 0 ; i < N ; i++)cin >> d[i];

  int buf = 0;
  double t = 0.0;
  double res = 0.0;
  int cnt = 0;

  for(int i = 0 ; i < L ; i++){

    if(!eq(t,0.0)){
      if(i == d[cnt]){
	if(buf == K)t = T;
	else buf++;
	cnt++;
      }
    }
    else {
      if(i == d[cnt]){t = T,cnt++;} 
      else if(buf){
	buf--;
	t = T;
      }
    }

    if(!eq(t,0.0)){
      res += 1.0/V;
      t -= 1.0/V;
      if(t < 0.0){
	res -= V*(-t);
	res += U*(-t);
	t = 0.0;
      }
    }      
    else{
      res += 1.0/U;
    }
  }
  printf("%.8f\n",res);
  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
using namespace std;
int main(){
  int n,a[]={1,3,5,7,9,11,15,17,19,21,23,25};
  cin >>n;
  cin.ignore();
  while(n--){
    string s,ss;
    getline(cin,s);
    ss = s;
    for(int p=0; p<12; p++){
      for(int q=0; q<26; q++){
	for(int i=0; i<s.size(); i++){
	  if(s[i]>='a' && s[i]<='z') ss[i] = ((s[i]-'a')*a[p]+q)%26+'a';
	}
	if(ss.find("this") != string::npos){cout<<ss<<endl;goto flag;}
	if(ss.find("that") != string::npos){cout<<ss<<endl;goto flag;}
      }
    }
  flag:;
  }
  return 0;
}

Measured memory_bytes: 1216
import numpy as np
import sys

#inp = list(map(int, input().split())
#inp = list(input())


n = int(input())
count = 0
count2 = 0

#m = n - 1
for i in range(1, n):
    count += int(n / i)
    if n % i == 0:
        count -= 1

print(count)

Measured memory_bytes: 27148
n = int(input())
s = []
for i in range(n):
    dat = input().split(" ")
    if dat[0] in s:
        s[s.index(dat[0])+1] += int(dat[1])
    else:
        s.append(dat[0])
        s.append(int(dat[1]))
for i in range(len(s)//2):
    s[i] = [s[i],s[i+1]]
    del s[i+1]
s.sort(key = lambda x: x[0])
s.sort(key = lambda x: len(x[0]))
for i in range(len(s)):
    print(s[i][0],s[i][1])


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x,t;cin >> x >> t;
	cout << max(0,x-t) << endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M);
  int homeworkAllDays = 0;
  for(int i = 0; i < M; i++){
    cin >> a.at(i);
    homeworkAllDays += a.at(i);
  }
  
  if(N - homeworkAllDays < 0) cout << "-1" << endl;
  else cout << N -homeworkAllDays << endl;
  
  return 0;
}

Measured memory_bytes: 3516
#include<stdio.h>

int main(void)
{
   int a,b,c,i;

   scanf("%d%d",&a,&b);

   if(a==0)
      c=1;

   if(a==1)
      c=100;

   if(a==2)
      c=10000;
   
   if(b==100)
      printf("%d\n",c*(b+1));
   else
      printf("%d\n",c*b);
   return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,x; cin >> n >> x;
  vector<int> v(n); cin >> v;
  ll ans = 0;
  for(int i = 0; i < n-1; ++i){
    if(v[i] + v[i+1] > x){
      ans += v[i] + v[i+1] - x;
      v[i+1] -= min(v[i]+v[i+1]-x,v[i+1]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3788
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
count = 0
for i in s:
    for j in range(w):
        if i[j] == "#":
            count += 1

def bfs():
    
    d = [[float("inf")] * w for i in range(h)]
    
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((0, 0))
    d[0][0] = 0

    while que:

        p = que.popleft()

        if p[0] == h - 1 and p[1] == w - 1:
            break

        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[h - 1][w - 1]

ans = bfs()
if ans == float("inf"):
    print(-1)
else:
    print((h*w) - (ans+1) - count)

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

char c2c[128];

void init() {
  c2c[' '] = ' ';
  c2c['i'] = 'i';
  c2c['w'] = 'w';
  c2c['('] = ')';
  c2c[')'] = '(';
}

int main() {
  string str;
  
  init();
  getline(cin, str);
  int n = str.size();
  int cnt = 0;
  for(int i=0; i<n/2+1; i++) {
    if(n-i-1<i) break;
    if(c2c[str[i]]!=str[n-i-1]) {
      // cout << str[i] << " " << c2c[str[i]] << " " << str[n-i-1] << endl;
      cnt ++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1176