akhauriyash/Code-Regression huggingface dataset:
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import bisect


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N, M, K = LI()
    AArray = LI()
    BArray = LI()

    aSum = [AArray[0]]
    bSum = [BArray[0]]

    cnt = 0

    for i in range(1, N):
        aSum.append(aSum[i-1]+AArray[i])
    for i in range(1, M):
        bSum.append(bSum[i-1]+BArray[i])

    for i in range(N):
        a = aSum[i]
        if a > K:
            break
        if a == K:
            cnt = max(cnt, i+1)
            break
        sa = K-a
        b = bisect.bisect_right(bSum, sa)
        cnt = max(cnt, i+1+b)

    for i in range(M):
        b = bSum[i]
        if b > K:
            break
        if b == K:
            cnt = max(cnt, i+1)
            break
        sa = K-b
        a = bisect.bisect_right(aSum, sa)
        cnt = max(cnt, i+1+a)

    print(cnt)


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

vvi g; 		// n 頂点グラフ（木）
vll data; 	// dfs で足していくデータ
vll ans;

void dfs(int v, int p = -1){
	for(auto u:g[v]){
    	if(u==p) continue;
      	data[u] += data[v];
      	ans[u] += data[v];
      	dfs(u, v);
    }  	
}

void Main()
{
	int n, q; 
  	cin >> n >> q;
  
  	g.resize(n);
  	rep(i,n-1) {
      	int a, b;
		cin >> a >> b;
      	a--; b--;
    	g[a].pb(b);
      	g[b].pb(a);
    }
  	
  	data.resize(n,0);
  	rep(i,q){
      	int p, x;
    	cin >> p >> x;
      	p--;
      	data[p] += x;
    }
  	
  	ans = data;
  	dfs(0);
  
	rep(i,n) cout << ans[i] << " ";
  	cout << endl;
	return;
}

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

Measured memory_bytes: 25856
#include<bits/stdc++.h> 
using namespace std; 
#define int long long

int32_t main(){
	int n;cin>>n;
	for(int i = 0; i  < n; i++){
		int x; cin>>x;
		if(x % 2 == 0){
			if(x % 3 != 0 && x % 5 != 0){
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    std::string s;
    std::cin >> s;

    int num_paper = 0, num_rock = 0;

    int count = 0;
    for (auto c : s) {
        switch (c) {
        case 'p':
            if (num_paper < num_rock) {
                num_paper++;
            } else {
                num_rock++;
                count--;
            }
            break;
        case 'g':
            if (num_paper < num_rock) {
                num_paper++;
                count++;
            } else {
                num_rock++;
            }
            break;
        }
    }

    std::cout << count << std::endl;
}


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

int main(){
    long long N;
    cin >> N;
    long long A[N+1];
    long long i, j;
    for(i=0; i<=N; i++){
        cin >> A[i];
    }
    if(N==0){
        if(A[0]==1){
            cout << 1 << endl;
        }else{
            cout << -1 << endl;
        }
    }else{
        long long S[N+1];
        S[N]=A[N];
        for(i=N-1; i>=1; i--){
            S[i] = S[i+1]+A[i];
        }
        bool trueend=0;
        long long kosu=1;
        long long sum=1;
        for(i=0; i<=N-1; i++){
            kosu=kosu-A[i];
            if(kosu<=0){
                break;
            }
            if(S[i+1]<=2*kosu){
                for(j=i+1; j<=N; j++){
                    sum += S[j];
                }
                trueend = 1;
                break;
            }
            else{
                kosu = 2*kosu;
                sum += kosu;
            }
        }
        if(trueend==1){
            cout << sum << endl;
        }else{
            cout << -1 << endl;
        }
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
int N;
int deg[100001];
int par[100001];
int sib[100001];
int Depth(int);
int Height(int);
int main() {
  int j,i;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    par[i] = -1;
    sib[i] = -1;
    deg[i] = 0;
  }
  for(i = 0; i < N; i++) {
    int id, lef, rig;
    scanf("%d %d %d", &id, &lef, &rig);
    if(lef != -1) {
      par[lef] = id;
      sib[lef] = rig;
      deg[id]++;
    }
    if(rig != -1) {
      par[rig] = id;
      sib[rig] = lef;
      deg[id]++;
    }
  }
 
  for(i = 0; i < N; ++i) {
    int depth = Depth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, par[i], sib[i], deg[i], depth, Height(i));
    if(depth == 0) {
      printf("root\n");
    } else if(deg[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}

int Depth(int i) {
  if(par[i] == -1) return 0;
  return Depth(par[i]) + 1;
}
 
int Height(int i) {
  int j, h;
  h = 0;
  for(j = 0; j < N; ++j) {
    if(par[j] == i) {
      int tmp = Height(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}

Measured memory_bytes: 620
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	ll a0, b0 = b;

	a0 = a - k;

	if (a0 < 0)
	{
		b0 = b + a0;
		a0 = 0;
	}

	if (b0 < 0)
	{
		b0 = 0;
	}

	println(a0 << " " << b0);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = [0]*200000
for i in a:
    if i == 0:
        l[0] += 1
        l[1] += 1
    else:
        l[i-1] += 1
        l[i] += 1
        l[i+1] += 1
print(max(l))

Measured memory_bytes: 20880
#include <stdio.h>

#define HASH 10007

typedef struct List {
	struct List *next;
	char s[11];
} list;

int hash_string(char* s)
{
	long long x = 0;
	int i;
	for (i = 0; s[i] != 0; i++) {
		x += s[i] - 'a';
		x = x << 5;
	}
	return x % HASH;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int h, i, j, N, count = 0;
	char S[11];
	list *p, *hash[HASH] = {}, d[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", S);
		h = hash_string(S);
		for (p = hash[h]; p != NULL; p = p->next) if (lex_smaller(p->s, S) == 0) break;
		if (p == NULL) {
			count++;
			for (j = 0; S[j] != 0; j++) d[i].s[j] = S[j];
			d[i].s[j] = 0;
			d[i].next = hash[h];
			hash[h] = &(d[i]);
		}
	}
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
using lint = long long;
const int INF = 1 << 29;
const double EPS = 1e-9;
using namespace std;

using Graph = vector<vector<pair<int, int>>>;

void dfs(Graph &g, vector<bool> &cs, int v, int p, bool c) {
  cs[v] = c;
  allrep(nv, g[v]) {
    if (nv.first == p) continue;
    bool next_c = (nv.second & 1) ? !c : c;
    dfs(g, cs, nv.first, v, next_c);
  }
}

int main(void) {
  int n;
  cin >> n;
  Graph graph(n);
  vector<bool> colors(n);
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    --u;
    --v;
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  dfs(graph, colors, 0, -1, 0);
  allrep(c, colors) {
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    int l = n%2,r = s[0] == s[n-1];
    cout << (l^r ? "First" : "Second") << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    ll x;
    cin >> x;
    cout << 1 + (x-1)*2/11 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);
  
  if((b % a) >= 1)
  {
    b -= a;
  }
  else
  {
    b += a;
  }
  printf("%d", b);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
   
  // static Scanner sc = new Scanner(System.in);
  
    private final static int mod = (int) (1e9 + 7);
    private final static int N = (int) (1e6);
    public static List<Integer>[] edges ;
    public static long[][] dp;
    
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 int n = sc.nextInt();
	 long W = sc.nextLong();
	 int[] w = new int[n+1];
	 int[] v = new int[n+1];
	 int totalv = 0;
	 for(int i=0;i<n;++i) {
		 w[i+1] = sc.nextInt();
		 v[i+1] = sc.nextInt();
		 totalv+=v[i+1];
	 }
	 
	 long[] dp = new long[totalv+1];
	 Arrays.fill(dp,Integer.MAX_VALUE);
	 dp[0] = 0;
	 for(int i=1;i<=n;++i) {
		 for(int j = totalv;j>=v[i];--j) {
			 dp[j] = Math.min(dp[j],dp[j-v[i]] + w[i]);
		 }
	 }
	
	 int ans = 0;
	 for(int i = 1;i<=totalv;++i) {
		 if(dp[i] <= W) {
			 ans = i;
		 }
	 }
	 
	 out.println(ans);
	 out.close();
	 
    
	}
	
	
    
	

	
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long 
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
 // #define forn(i, n) for (int i = 0; i < int(n); i++)
  
  int32_t main()
  { 
     #ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
     #endif
    
    IOS
    int t;
    cin >> t;
    cout<<fixed<<setprecision(12)<<2*3.141592653589793*t;
    return 0;
   
}



Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

int main(void)
{
	string s;
	int n;
	string smax,smin;
	int imax;
	int imin;

	int j;
	int ss;

	while(1){
		cin >> s >> n;
		if(s=="0" && n==0) break;

		while(s.size()<n){
			s += "0";
		}

		vector<string > a;
		vector<string>::iterator it;

		while(1){
			if(!a.empty()){
				it = find(a.begin(), a.end(),s);
				if(it!=a.end()) break;
			}
			//cout << s << endl;
			a.push_back(s);

			sort(s.begin(), s.end());
			smin = s;
			reverse(s.begin(), s.end());
			smax = s;

			/* string to int */
			istringstream istrmin(smin);
			istrmin >> imin;
			istringstream istrmax(smax);
			istrmax >> imax;

			/* int to string */
			ostringstream ostr;
			ostr << imax-imin;
			s = ostr.str();

			while(s.size()<n){
				s = "0" + s;
			}
		}

		j=it-a.begin();
		istringstream istr(s);
		istr >> ss;
		cout << j << " " << ss << " " << a.size()-j << endl;
	}

	return 0;
}

Measured memory_bytes: 1260
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a*b/2<<endl;
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,l,a[100111];
int main()
{
	get2(n,l);for(int i=1;i<=n;i++)get1(a[i]);
	int id=0;for(int i=1;i<n;i++)if(a[i]+a[i+1]>=l)id=i;
	if(!id){puts("Impossible");return 0;}
	puts("Possible");for(int i=1;i<id;i++)printf("%d\n",i);for(int i=n-1;i>id;i--)printf("%d\n",i);printf("%d\n",id);
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;


class Main {



	public static void main(String[] args) {   

		Scanner scanner = new Scanner(System.in);
		
		while (true) {	
		String n= scanner.nextLine();
		
		if(n.equals("-")){
			break;//終了条件
		}
		int m= Integer.parseInt(scanner.nextLine());

		char[] N; 
		N=new char[n.length()];//入力された文字列Nを格納する配列
		char[] box; 
		box=new char[n.length()];
		
		for(int i=0;i<n.length();i++){
			N[i]=n.charAt(i);//各文字列をchar型の配列N[]に格納
			}

		
		for(int i=0;i<m;i++){
			int h=Integer.parseInt(scanner.nextLine());
			
			for(int ii=0;ii<n.length();ii++){
				if(h == n.length()){
					h=0;
					box[ii]=N[h];
					
					h=h+1;
				}
				else{
					box[ii]=N[h];
					h=h+1;
				}
			}
			for(int iii=0;iii<n.length();iii++){
				N[iii]=box[iii];
			}
				
			}
          for(int i=0;i<n.length();i++){
		    System.out.print(String.valueOf(N[i]));
			if(i == n.length()-1)
		    System.out.println("");
		
		}
		}


	}
}



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

int main()
{
ll n ;
cin >> n  ;
ll v[1002][1002]={};
rep(i,n){
  ll l , r ;
  cin >> l >> r ;
  ll x , y ;
  cin >> x >> y ;
  v[l][r]++;
  v[x][y]++;
  v[l][y]--;
  v[x][r]--;
}
rep(i,1001){
  ll te=v[i][0];
  rep(j,1001){
    te+=v[i][j+1];
    v[i][j+1]=te;
  }
}
rep(i,1001){
  ll te=v[0][i];
  rep(j,1001){
    te+=v[j+1][i];
    v[j+1][i]=te;
  }
}
rep(i,1002)rep(j,1002){
  ans=max(ans,v[i][j]);
}

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


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

int main(){
    stack<int> S1;
    stack< pair <int,int> > S2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch  ; ++i) {
        if( ch == '\\')S1.push(i);
        else if (ch == '/' and S1.size() >0){
            int j = S1.top();
            S1.pop();
            sum += i-j;
            int a = i-j;
            while(S2.size() > 0 and S2.top().first > j){
                a += S2.top().second;
                S2.pop();
            }
                S2.push(make_pair(j,a));
        }
    }

    vector<int> ans;
    int t =0;
    while(S2.size()>0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size() ; ++i) {
        cout << " ";
        t += ans[i];
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1010;
int n, m;
int a[maxn];
ll sum, sum2;
void solve() {
	//scanf("%d%d", &n, &m);

	//printf("%d\n", n - 2 * m >= 0 ? n - 2 * m : 0);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}
	for (int i = 1; i <= n; ++i) {
		sum += a[i]; //a[i]*a[i]
		sum2 += 1ll * a[i] * a[i];
	}
	sum = (sum * sum - sum2) >> 1;
	printf("%lld\n", sum);
}
int main() {
	solve();

	return 0;
}

Measured memory_bytes: 256
module strPiyo
      implicit none
      
      contains
      function checkStr( n,str ) result( flag )
        implicit none
        logical flag
        integer :: n
        character(n) :: str
        integer :: i
        
        do i = 1,n/2
          if( str(i:i)/=str(n+1-i:n+1-i) )then
            flag = .false.
            return
          end if
        end do
        
        flag = .true.
      end function
      
      end module
      
      
      
      PROGRAM piyo
      use strPiyo
      IMPLICIT NONE
      character(99) :: s
      integer :: n
      
      read*,s
      n = len_trim(s)
      
      if( .not. checkStr(n,s(1:n)) )then
        print*,'No';stop
      end if
      
      if( .not. checkStr((n-1)/2,s(1:(n-1)/2)) )then
        print*,'No';stop
      end if
      
      if( .not. checkStr(n-(n+3)/2+1,s((n+3)/2:n)) )then
        print*,'No';stop
      end if
      
      print*,'Yes'
      
      END PROGRAM

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

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

	set<string> st;

	rep(i, n) {
		string s;
		cin >> s;
		st.insert(s);
	}

	cout << st.size() << endl;
}


Measured memory_bytes: 19048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define forn1(i, n) for (ll i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
const ld eps = 1e-9;
//#define DEBUG
int main()
{
  //FastIO;
  #ifdef DEBUG
    freopen("input.txt", "r", stdin);
  #endif
  ld a, b, c;
  cin >> a >> b >> c;
  ld l = M_PI / 2, r = 0;
  for (int i = 0; i < 1000; ++i){
    ld m = (l + r) / 2;
    ld salpha = sin(m);
    ld calpha = sqrt(1 - salpha * salpha);
    //cout << salpha << " " << calpha << "\n";
    ld h = b * salpha;
    ld ha = a * calpha;
    ld s = 0;
    if (ha - h > 0)
    {
      ha = h / calpha;
      s = 0.5 * b * ha * a;
      if (s > c){
        l = m;
      }
      else{
        r = m;
      }
    }
    else
    {
      ha = ha / salpha;
      s = a * a * b - 0.5 * a * ha * a;
      if (s > c){
        l = m;
      }
      else{
        r = m;
      }
    }
    //cout << l << " " << r << " " << s << "\n";
  }
  cout << fixed << setprecision(10) << 90 - l / M_PI * 180;
  return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


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


Measured memory_bytes: 256
/*input
40
ferelibenterhominesidquodvoluntcredunt
*/

#include <bits/stdc++.h>

using namespace std;

int k;
string s;

int main() {
	cin >> k >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		cout << s.substr(0, k) << "..." << endl;
	}
}

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

double EPS = 1e6;
class P{
public:
    int x, y;
    P(){};
    P(int x, int y): x(x), y(y){};
    
    bool operator < (const P &r)const{
        return 0 < x*r.y - y*r.x;
    }
    bool operator == (const P &r)const{
        return 0 == x*r.y - y*r.x;
    }
};

typedef pair<P, P> Span;

int H, W;
vector<string> field;

//up, down, right, left
int dh[] = {1, -1, 0, 0};
int dw[] = {0, 0, 1, -1};

Span make_span(double h, double w, int dir){
    P l, r;
    if(dir == 0){ //up
        l = P(w+1, h+1);
        r = P(w, h+1);
    }
    if(dir == 1){ //down
        l = P(w+1, h);
        r = P(w, h);
    }
    if(dir == 2){ //right
        l = P(w+1, h);
        r = P(w+1, h+1);
    }
    if(dir == 3){ //left
        l = P(w, h);
        r = P(w, h+1);
    }
    return Span(l, r);
}

int main(){
    cin >> H >> W;
    field.resize(H+1);
    for(int i=0; i<W+1; i++)
        field[H] += '.';
    
    for(int i=0; i<H; i++){
        cin >> field[H-1-i];
        field[H-1-i] += '.';
    }
    
    vector<Span> spans; //??????
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++) if(field[h][w] == '#'){
            for(int i=0; i<4; i++){
                int nh = h + dh[i];
                int nw = w + dw[i];
                if(nh<0 || nw<0 || H<nh || W<nw || field[nh][nw]!='.') continue;
                
                spans.push_back(make_span(h, w, i));
            }
        }
    }
    vector<P> tmp;
    for(auto span: spans)
        tmp.push_back(span.first), tmp.push_back(span.second);
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());

    vector<int> cum(tmp.size());
    for(auto &span: spans){
        int l = lower_bound(tmp.begin(), tmp.end(), span.first) - tmp.begin();
        int r = lower_bound(tmp.begin(), tmp.end(), span.second) - tmp.begin();
        for(int i=l; i<r; i++)
            cum[i]++;
    }
    
    int ans = 0;
    for(int i=0; i<cum.size(); i++)
        ans = max(ans, cum[i]);
    if(field[0][0] == '#')
        ans++;
    cout << ans/2 + 1 << endl;
    
    return 0;
}

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

int main(){	
	long long int a,b,c,suma;
	vector<long long int >x(3);
	int veces;
	
	scanf("%lld%lld%lld%d",&x[0],&x[1],&x[2],&veces);
	sort(x.begin(),x.end());
	for(int i=0; i<veces; i++)
	     x[2]+=x[2];
         suma=x[0]+x[1]+x[2];
  	printf("%lld\n",suma);
	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

ans = 0

for k,v in cnt.items():
    if v > k:
        ans += (v-k)
        
    elif v < k:
        ans += v
        
print(ans)

Measured memory_bytes: 18336
#include <stdio.h>
int main (void){
    int l,m,n,i,sa,kei,ans;
    for(;;){
        scanf("%d",&l);
        if(l==0)break;
        kei=0,ans=15;
        for(i=0;i<12;i++){
            scanf("%d%d",&m,&n);
            sa=m-n;
            kei+=sa;
            if(kei>=l&&ans>i){
                ans=i+1;
            }
        }
        if(ans<=12){
            printf("%d\n",ans);
        }
        else{
            printf("NA\n");
        }
    }
return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = (a); i <(b); i++)
#define forn(i,a,b) for (int i = (a); i >(b); i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

long long int modular_exponentiation(long long int x,long long int n)
{
    if(n==1)
    return x;

    if(n%2)
    {
        return (x*(modular_exponentiation(x,(n-1)/2)%mod)*(modular_exponentiation(x,(n-1)/2)%mod))%mod;
    }
    else
    {
        return ((modular_exponentiation(x,n/2)%mod)*(modular_exponentiation(x,n/2)%mod))%mod;
    }
}
// <----- Actual solve() function to print output -----> //
void solve()
{
   ll n,p,q,x,y,k=0;
cin>>n;
  int a[n][2];
  k=0;
  q=0;
  forp(i,0,n)
  {
     cin>>a[i][0]>>a[i][1];
    if(a[i][0]==a[i][1])
    {
      k++;
    }
    else
    {
      q=max(q,k);
      k=0;
    }
  }
  q=max(q,k);
if(q>2)
  cout<<"Yes";
  else
    cout<<"No";
   //cout<<"\n";      //if t>1 uncomment this
}
 
// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
 
  single_testcase_t
  //multiple_testcases_t
return 0;
}


Measured memory_bytes: 3636
# https://atcoder.jp/contests/abc066/tasks/abc066_b
s = input()

while True:
    s = s[:-1]
    if len(s) % 2 == 1:
        continue
    mid = len(s) // 2
    if s[:mid] == s[mid:]:
        print(len(s))
        break


Measured memory_bytes: 38384
n = int(input())
h = list(map(int,input().split()))

t = 0
result =0

for i in range(n-1):
  if h[i] >= h[i+1]:
    t += 1
  else:
    result = max(t,result)
    t = 0

result = max(t, result)

print(result)
  

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

long long floor_sum(long long n, long long m, long long a, long long b) {
	long long ans = 0;
	if (a >= m) {
		ans += (n - 1) * n * (a / m) / 2;
		a %= m;
	}
	if (b >= m) {
		ans += n * (b / m);
		b %= m;
	}

	long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
	if (y_max == 0) return ans;
	ans += (n - (x_max + a - 1) / a) * y_max;
	ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
	return ans;
}

using namespace std;
int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		long long n, m, a, b;
		scanf("%lld %lld %lld %lld", &n, &m, &a, &b);
		printf("%lld\n", floor_sum(n, m, a, b));
	}
	return 0;
}


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

int dp[1001][10001];

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; i++)
        cin >> v[i] >> w[i];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j - w[i] < 0) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}



Measured memory_bytes: 6992
/*  ex7_3
    potter0723sw  */

#include <stdio.h>
#include <stdlib.h>
void error(void){
    fprintf(stderr, "memory allocation error.\n");//エラー出力を定義
}

int main(void){
    int row,column,i,j,*rowblack,*colblack;
    char **matrix;
    scanf("%d %d",&row,&column);
//matrixを確保
    matrix = (char**)calloc(row, sizeof(char*));
    if(matrix == NULL){
        error;
        exit(1);
    }
    for(i=0; i < row; i++){
        matrix[i] = (char*)calloc(column, sizeof(char));
        if(matrix[i] == NULL){
            error;
            exit(1);
        }
    }
//rowblackとcolblackも確保
    rowblack = (int*)calloc(row, sizeof(int));
    if(rowblack == NULL){
        error;
        exit(1);
    }
    colblack = (int*)calloc(column, sizeof(int));
    if(colblack == NULL){
        error;
        exit(1);
    }
//黒マスのある行と列を記憶
    for(i=0; i < row; i++){
        for(j=0; j<column;j++){
            scanf(" %c", &matrix[i][j]);
            if(matrix[i][j] == '#'){
                rowblack[i] += 1;
                colblack[j] += 1;
            }
        }
    }
//同じ行にも同じ列にも黒マスのあるマスのみ出力
    for(i=0; i < row; i++){
        for(j=0; j < column; j++){
            if(rowblack[i] != 0 && colblack[j] != 0){
                printf("%c", matrix[i][j]);
            }
        }
        if(rowblack[i] != 0){
            printf("\n");
        }
    }
//メモリ解放
    for(i=0; i < row; i++){
        free(matrix[i]);
    }
    free(matrix);
    free(rowblack);
    free(colblack);
    return 0;
}


Measured memory_bytes: 1676
#include <iostream>
#include <string>
#include <sstream>

int main() {
	int a,b;
	while(std::cin >> a >> b){
		int sum = a+b;
		std::stringstream ss;
		ss << sum;
		std::string str = ss.str();
		std::cout << str.length() <<std::endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#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=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec l(n);
  for(ll i=0;i<n;i++) {
    cin >> l[i];
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    for(ll j=i+1;j<n;j++) {
      if(l[i]==l[j]) continue;
      for(ll k=j+1;k<n;k++) {
        if(l[i]==l[k]||l[j]==l[k]) continue;
        if(abs(l[i]-l[j])<l[k]&&l[k]<l[i]+l[j]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>

void trace(int *A, int n){
  int i;
  for(i = 0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int  *A, int n){
  int i,j,temp;
  for(i = 1;i<n;i++){
    temp = A[i];
    j = i-1;
    while(j>=0 && A[j] > temp){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = temp;
    trace(A,n);
  }
}

int main(){
  int i,j,n,A[1000];

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

  trace(A,n);
  insertionSort(A,n);

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

ll t[100001] = {};
int main() {
	ll n; cin >> n;
	rep(i, 0, n)cin >> t[i];

	ll ans = 1;
	rep(i, 0, n) {
		ans = lcm(t[i], ans);
	}
	cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i,s.size()) {
        mp[s[i]]++;
    }
    if (mp.size() == 2 && mp.begin()->second == 2 && next(mp.begin())->second == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3584
fun main(args: Array<String>) {
    val s = readLine()
    
    val month = s!!.substring(5, 7).toInt()
    val day = s!!.substring(8, 10).toInt()
    val res = if((month > 4) || (month == 4 && day > 30)){
        "TBD"
    } else {
        "Heisei"
    }
    println(res)
}


Measured memory_bytes: 33724
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for(int & v : p) cin >> v;
	sort(p.begin(), p.end());
	int sum = 0;
	for(int i = 0; i < k; i++)
		sum += p[i];
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if (s.back() == '2' || s.back() == '4' || s.back() == '5' || s.back() == '7' || s.back() == '9')
    {
        cout << "hon";
    }
    else if (s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8')
    {
        cout << "pon";
    }
    else
    {
        cout << "bon";
    }
    return 0;
}

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

using namespace std;

vector<int> heap;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		heap.push_back(t);
	}
	make_heap(heap.begin(),heap.end());
	for(int i=0;i<n;i++)
		printf(" %d",heap[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 4820
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        double l = Double.parseDouble(scanner.next());
        double total = l /3;


        System.out.println(Math.pow(total, 3));
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int H,W; cin>>H>>W;
  vector<string> S(H+2);
  rep(i,0,W+2){
    S[0]+='.';
    S[H+1]+='.';
  }
  rep(i,1,H+1){
    string X; cin>>X;
    S[i]+='.';
    S[i]+=X;
    S[i]+='.';
  }
  REP(i,1,H){
    REP(j,1,W){
      if(S[i][j]=='#')
        cout<<'#';
      else{
        int count=0;
        REP(k,i-1,i+1){
          REP(l,j-1,j+1){
            if(S[k][l]=='#')
              count++;
          }
        }
        cout<<count;
      }
    }
    cout<<endl;
  }
  }


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1e9 + 7;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, M;
    cin >> N >> M;
    vector<uint16_t> Ss(M);
    rep(i, M)
    {
        ll k;
        cin >> k;
        uint16_t S = 0;
        rep(j, k)
        {
            ll s;
            cin >> s;
            --s;
            S |= 1 << s;
        }
        Ss[i] = S;
    }
    vector<ll> p(M);
    rep(i, M) cin >> p[i];

    // スイッチの状態を巡回
    ll ans = 0;
    for (uint16_t bits = 0; bits < (1 << N); ++bits)
    {
        bool okay = true;
        rep(i,Ss.size())
        {
            uint16_t ss = Ss[i] & bits;
            if (bitset<16>(ss).count() % 2 != p[i])
            {
                okay = false;
                break;
            }
        }
        if (okay)
        {
            ++ans;
        }
    }
    cout << ans;
    //
    return 0;
}

Measured memory_bytes: 3172
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		long cnt = 0;
		long A = a / x;
		long B = b / x;
		if(a % x == 0)
		{
			A = A - 1;
		}
		cnt = B - A;
		System.out.println(cnt);
	}

}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int d,g;
	cin >>d >>g;
	vector<VI> p(d, VI(2));
	rep(i, d) cin >>p[i][0] >>p[i][1];
	
	ll ans = 1LL<<60;
	rep(i, 1<<d){
		ll sm =0, su =0;
		rep(j, d) if(i>>j &1){
			su += p[j][0];
			sm += p[j][0] * (j+1)*100 + p[j][1];
		}
		for(int j=d-1; sm < g && j>=0; j--) if(!(i>>j &1)){
			int adsu=(g - sm + (j+1)*100 -1)/((j+1)*100);
			sm += (j+1)*100 * min(adsu, p[j][0]);
			su += min(adsu, p[j][0]);
		}
		if(sm>=g) ans = min(ans, su);
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
pS = [list(input().split()) for i in range(M)]

correct_questions = [False] * N
incorrect_questions = [0] * N
num_of_correct = 0
num_of_penalties = 0
for pi, Si in pS:
    nth = int(pi) - 1
    
    if Si == 'AC' and correct_questions[nth] is False:
        correct_questions[nth] = True
        num_of_correct += 1
        num_of_penalties += incorrect_questions[nth]
    elif Si == 'WA' and correct_questions[nth] is False:
        incorrect_questions[nth] += 1

print("{} {}".format(num_of_correct, num_of_penalties))


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

using namespace std;

typedef long long ll;

set<int> s1,s2;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y;
    s1.insert(4);
    s1.insert(6);
    s1.insert(9);
    s1.insert(11);
    s2.insert(2);
	cin >> x >> y;
	if((s1.find(x)!=s1.end() && s1.find(y)!=s1.end()) || (s2.find(x)!=s2.end() && s2.find(y)!=s2.end())){
		cout << "Yes\n";
	}else if(s1.find(x)==s1.end() && s2.find(x)==s2.end() && s1.find(y)==s1.end() && s2.find(y)==s2.end()){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
    
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=deque(list(sorted([ii() for _ in range(n)])))
cop=deque(deepcopy(list(arr)))
mat=deque([])

for i in range(n):
    if i%4==0:
        p=arr.popleft()
        mat.append(p)
    elif i%4==1:
        p=arr.pop()
        mat.appendleft(p)
    elif i%4==2:
        p=arr.pop()
        mat.append(p)
    else:
        p=arr.popleft()
        mat.appendleft(p)

mat2=deque([])
for i in range(n):
    if i%4==0:
        p=cop.pop()
        mat2.append(p)
    elif i%4==1:
        p=cop.popleft()
        mat2.appendleft(p)
    elif i%4==2:
        p=cop.popleft()
        mat2.append(p)
    else:
        p=cop.pop()
        mat2.appendleft(p)

ans=0
ans1=0
chk=list(mat)
chk1=list(mat2)
for i in range(n-1):
    ans+=abs(chk[i]-chk[i+1])
    ans1+=abs(chk1[i]-chk1[i+1])
print(max(ans,ans1))






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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    int ans = 0;
    vector<int> tmp;
    rep(i,N) {
        int a;
        cin >> a;
        ans+=a;
        if (a%10!=0) {
            tmp.push_back(a);
        }
    }
    if (ans%10!=0) {
        cout << ans << endl;
    }
    else if (tmp.size()!=0) {
        sort(tmp.begin(),tmp.end());
        ans-=tmp.front();
        cout << ans << endl;
    }
    else {
        cout << 0 << endl;
    }
}



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

using namespace std;

void DrawRectangle(int H, int W);

int main()
{
	int H, W;

	while(1){
		cin >> H >> W;
		if ((H == 0) && (W == 0))
			break;

		DrawRectangle(H, W);
		cout << endl;
	}


	return 0;
}

void DrawRectangle(int H, int W)
{
	char* str = new char[W + 1];
	for (int i = 0; i < W; i++)
		str[i] = '#';
	str[W] = '\0';

	for (int i = 0; i < H; i++)
		cout << str << endl;

	delete[] str;
}


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

int main() {
  long int N, S;
  cin >> N;
  
  S = 0;
  
  for (int i = 1; i < N+1; i++) {
    if ( i%3 != 0 && i%5 != 0 ) {
      S = S + i;
    }
  }
    
  cout << S << endl;
  
}


Measured memory_bytes: 3628
gets
s = gets.chomp

l = 0
r = s[1..-1].count('E')
t = l + r

for i in 1..s.size
  l += 1 if s[i - 1] == 'W'
  r -= 1 if s[i] == 'E'

  t = [t, l + r].min
end

puts t

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

int main(){
    int n;
    
    while(cin >> n&&n!=0){
        vector<long long > p(40);
        for(int i=0;i<n;i++){
            int c;
            cin >> c;
            for(int j=0;j<c;j++){
                int d;
                cin >> d;
                p[d] |= 1LL<<i;
            }
        }
        vector<long long>s(n,0);
        for(int i=0;i<n;i++){
            s[i] |=1LL<<i;
        }
        for(int i=0;i<40;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    if(p[i]&(1LL<<j)){
                        if(p[i]&(1LL<<k)){
                            s[j]|=s[k];
                            s[k]|=s[j];
                        }
                    }
                }
            }
            for(int j=0;j<n;j++){
                if(s[j]==(1LL<<n)-1){
                    cout << i << endl;
                    goto lll;
                }                    
            }
        }
        cout << -1 << endl;
        lll:;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100000];

int calc(int sdir) {
int pos = n / 2;
	int low = 0, high = n - 1;
	static bool used[100000];
	int dir = sdir;
	int ans = 0;
	
	for (int i = 0; i < n; i++) used[i] = false;
	
	used[pos] = true;
	while (true) {
		if (dir == -1) {
			if (used[low]) break;
			ans += a[pos] - a[low];
			//cout << pos << " " << low << endl;
			pos = low;
			used[pos] = true;
			low++;
			dir = 1;
		}
		else {
			if (used[high]) break;
			ans += a[high] - a[pos];
			//cout << pos << " " << high << endl;
			pos = high;
			used[pos] = true;
			high--;
			dir = -1;
		}
	}
	return ans;
}

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	
	int ans1 = calc(-1);
	int ans2 = calc(1);
	
	
	cout << max(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 1152