akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


#define loop(i,n) for(int lc=i;lc<=n;lc++)
#define tloop(tn) for(int tlc=1;tlc<=tn;tlc++)
#define loop2(i2,n2) for(int lc2=i2;lc2<=n2;lc2++)
#define bloop(n,bn) for(int blc=n;blc>=bn;blc--)
#define il() while(true)
#define pi acos(-1)
#define rad_to_deg(angl) ((180*angl)/pi)
#define ll long long
#define caseno printf("Case %d: ",tlc);

#define sfi(def_var) scanf("%d",&def_var)
#define sfii(def_var,def_var2) scanf("%d %d",&def_var,&def_var2)
#define sfll(def_var,def_var2) scanf("%lld %lld",&def_var,&def_var2)

#define sfl(def_var) scanf("%lld",&def_var)
#define sfd(def_var) scanf("%lf",&def_var)
#define sfs(def_var) scanf("%s",&def_var)

#define pfie(def_var) printf("%d\n",def_var)
#define pfi(def_var) printf("%d",def_var)
#define pfl(def_var) printf("%lld",def_var)
#define pfd(def_var) printf("%lf",def_var)
#define nl printf("\n");


int n,w;
int a[110][2];
ll dp[110][100100];

int c=0;
ll find_ans(int i,int cost)
{
    //c++;
    if(i==n+1) return 0;
    if(dp[i][cost]>0) return dp[i][cost];
    ll profit1=-1,profit2=-1;
    if(cost+a[i][0]<=w) profit1=a[i][1]+find_ans(i+1,cost+a[i][0]);
    profit2=find_ans(i+1,cost);

    dp[i][cost]= max(profit1,profit2);
    return dp[i][cost];
}
int main()
{
    sfii(n,w);
    loop(1,n)
    {
        sfii(a[lc][0],a[lc][1]);
    }
    c=0;
    cout << find_ans(1,0);
    //cout << "call : " << c << endl;
}


Measured memory_bytes: 78080
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;

int main()
{
   int N,M; cin>>N>>M;
   vector<int> a(N);
   for(int i=0;i<N;i++) cin>>a[i],a[i]--;

   vector<lint> imos0(2*M+1),imos1(2*M+1);
   auto add=[&](int l,int r,int a,int b)
   {
      imos1[l]+=a; imos1[r+1]-=a;
      imos0[l]+=b; imos0[r+1]-=b;
   };

   for(int i=0;i<N-1;i++){
      int s=a[i],t=a[i+1];
      if(t<s) t+=M;
      add(s+1,t,-1,t+1);
      add(t+1,s+M,0,t-s);
   }
   for(int i=1;i<2*M;i++) imos0[i]+=imos0[i-1],imos1[i]+=imos1[i-1];

   lint ans=(lint)N*M;
   for(int i=0;i<M;i++){
      lint sum=(imos1[i]*i+imos0[i])+(imos1[i+M]*(i+M)+imos0[i+M]);
      ans=min(ans,sum);
   }
   cout<<ans<<endl;
   return 0;
}


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

int main() {
  string str;
  int index = 0;
  long long cnt = 0;
  long long bCnt = 0;
  bool chk = true;
  
  cin >> str;
  
  index = str.size()-1;
  
  for(int i = 0; i <= index; i++){
    if(str.at(i) == 'W'){
      cnt += bCnt;
    }else{
      bCnt++;
    }
  }
  
  cout << cnt;
}


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

int main() {
  int N, Y;

  cin >> N >> Y;
  Y /= 1000;

  string ans = "-1 -1 -1";
  bool ok = false;
  for (int i = N; i >= 0; --i) {
    for (int j = N - i; j >= 0; --j) {
      if (i * 10 + j * 5 + (N - i - j) == Y) {
        ans = to_string(i) + " " + to_string(j) + " " + to_string(N - i - j);
        ok = true;
      }
      if (ok) break;
    }
    if (ok) break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())

a_list = []
b_list = []
for i in range(n):
    tmp_a, tmp_b = list(map(int, input().split()))

    a_list.append(tmp_a)
    b_list.append(tmp_b)

z = zip(b_list, a_list)
z = sorted(z)
b_list, a_list = zip(*z)

sum_t = 0

flag = True
for a, b in zip(a_list, b_list):
    sum_t += a

    if sum_t > b:
        flag = False
        break

print('Yes') if flag else print('No')

Measured memory_bytes: 49164
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

class unionFindWeight{
      private:
      vector<int> par;
      vector<int> rank;
      vector<int> diff_weight;
      
      int root(int x){
            if(par[x] == x) return x;
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];//累積和
            par[x] = r;
            return par[x];
      }
      int weight(int x){
            root(x);//経路圧縮
            return diff_weight[x];
      }
      public:
      unionFindWeight(int n){
            rep0(i,n){
                  par.push_back(i);
                  rank.push_back(0);
                  diff_weight.push_back(0);
            }
      }
      int diff(int x,int y){
            return weight(y) - weight(x);
      }
      bool issame(int x,int y){
            return root(x) == root(y);
      }
      bool merge(int x,int y,int w){
            //xとyそれぞれについてrootとの重み差分を補正
            w += weight(x); w -= weight(y);
            x = root(x); y = root(y);
            if(x == y) return false;
            //rank[x]>=rank[y]となるように入れ替える
            if(rank[x] < rank[y]) swap(x,y),w = -w;
            //yのrootをxのrootの下にくっつける
            if(rank[x] == rank[y]) rank[x]++;
            par[y] = x;
            diff_weight[y] = w;
            return true;
      }

};
int main (){
      int N,M;
      cin>>N>>M;
      unionFindWeight u(N);
      bool ok=1;
      rep0(i,M){
            int l,r,d;
            cin>>l>>r>>d;
            l--,r--;
            if(u.issame(l,r)){
                  if(u.diff(l,r)!=d){
                        ok=0;
                  }
            }
            else{
                  u.merge(l,r,d);
            }
      }
      cout<<(ok? "Yes":"No")<<endl;
      return 0;
}


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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	ll x,k,d;
	scanf("%lld%lld%lld",&x,&k,&d);
	x = abs(x);
	if(x/d >= k)
		return 0*printf("%lld\n",x - k*d );
	printf("%lld\n",abs(x - (x/d + ((k - x/d)&1))*d));
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll cnt[4];

int main(){
	ll n;
	cin >> n;
	string s[n];
	cinf(s,n);
	rep(i,n){
		if(s[i][0]=='A')
			cnt[0]++;
		else if(s[i][0]=='W')
			cnt[1]++;
		else if(s[i][0]=='T')
			cnt[2]++;
		else
			cnt[3]++;
	}
	cout << "AC x " << cnt[0] << endl;
	cout << "WA x " << cnt[1] << endl;
	cout << "TLE x " << cnt[2] << endl;
	cout << "RE x " << cnt[3] << endl;
}

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

typedef  long long ll;
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;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    cin>>n;
    vector<int> h(n);
    rep(i,n)cin>>h.at(i);
    if(n==1){cout<<"Yes"<<endl;return 0;}
    else{
        int heightest=h.at(0);
        rep(i,n){
            if(h.at(i)<=(heightest-2)){
                cout<<"No"<<endl;
                return 0;
            }
            if(heightest<h.at(i))heightest=h.at(i);
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}




Measured memory_bytes: 640
function main(input) {
  const args = input.trim().split("\n");
  let n, m;
  [n, m] = args[0].split(" ").map((x) => Number(x));

  let a = new Array(n);
  for (let i = 0; i < n; i++) {
    a[i] = args[i + 1].split(" ").map((x) => Number(x));
  }

  let b = new Array(m);
  for (let i = 0; i < m; i++) {
    b[i] = Number(args[n + 1 + i]);
  }

  for (let i = 0; i < n; i++) {
    let ans = 0;
    for (let j = 0; j < m; j++) {
      ans += a[i][j] * b[j];
    }
    console.log(ans);
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
 int N,M;
 cin>>N>>M;
 int a[N];
 for(int i=0;i<N;i++) cin>>a[i];
 sort(a,a+N,greater<int>());
 int sum=0;
 for(int i=0;i<N;i++){
     sum+=a[i];
 }
 float num=(float)sum/(4*M);
 if(a[M-1]>=num){
     cout<<"Yes"<<endl;
 }else{
     cout<<"No"<<endl;
 }
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 1624.cc: Income Inequality
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  for (int n; scanf("%d", &n) == 1 && n > 0;) {
    int sum = 0;
    for (int i = 0; i < n; i++)
      scanf("%d", as + i), sum += as[i];
    sort(as, as + n);

    int k = upper_bound(as, as + n, sum / n) - as;
    printf("%d\n", k);
  }
  return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
     
        long n;
        cin >> n;
     
        long x[n];
        long x_copy[n];
     
        for (long i = 0; i < n; i++) {
            cin >> x[i];
            x_copy[i] = x[i];
        }
        sort(x_copy, x_copy + n);
        long small_mean = x_copy[n / 2 - 1];
        long large_mean = x_copy[n / 2 ];
     
        for (long i = 0; i < n; i ++) {
            if (x[i] <= small_mean) {
                cout << large_mean << "\n";
            } else {
                cout << small_mean << "\n";
            }
        }
     
        return 0;
    }

Measured memory_bytes: 5376
import itertools
import numpy as np

N,M,X = map(int, input().split())
lista = [list(map(int,input().split())) for i in range(N)]

lista = np.array(lista)
judge = [X]*M
cost = 120000000000
data = [a for a in range(1,N+1)] # [1,2,3,...,N]

for i in range(1,N+1):
    j = list(itertools.combinations(data, i))
    for k in j:
        result = np.array([0]*(M+1))
        for l in k:
            result = result + lista[l-1]
        if all(result[1:]>=judge):
            if result[0]<cost:
                cost = result[0]
                m = k
c = 0

try:
    for i in m:
        c +=lista[i-1][0]
    
    print(c)
except:
    print(-1)

Measured memory_bytes: 27560
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
 
using namespace std;
 
//#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;
const int maxN = 1e3;
 
int gcd(int a, int b) {
    return !b ? a : gcd(b, a % b);
}
 
void solve() {
    int k;
    cin >> k;
    ll sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    //srand(time(0));
    while (t--) solve();
}

Measured memory_bytes: 3648
#include <stdio.h>
int main (){
	int n,min,max,a;
	long int sum;
	//jgn lupa inisialisasi
	max=-1000000;
    min=1000000;
    sum=0;
	scanf ("%d",&n);
	for (int i=0;i<n;i++){
		// a bkn i variable beda woiii
		scanf ("%d",&a);
		sum=sum+a;
		if (a<min){
		min=a;
		}
		if (a>max){
		max=a;
		}
	}
	printf ("%d %d %ld\n",min,max,sum);

	return 0;
}


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

signed main() {
  int A, B, C; cin >> A >> B >> C;
  
  rep(i, 100) {
    if((A*(i+1))%B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  
  

}

Measured memory_bytes: 256
import java.util.*;

// ARC 84-A
// https://beta.atcoder.jp/contests/arc084/tasks/arc084_a

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

		int N = in.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N];
		
		TreeSet<Integer> aSet = new TreeSet<Integer>();
		TreeSet<Integer> bSet = new TreeSet<Integer>();
		TreeSet<Integer> cSet = new TreeSet<Integer>();
		
		for (int i = 0; i < N; i++) {
			A[i] = in.nextInt();
			aSet.add(A[i]);
		}
		for (int i = 0; i < N; i++) {
			B[i] = in.nextInt();
			bSet.add(B[i]);
		}
		for (int i = 0; i < N; i++) {
			C[i] = in.nextInt();
			cSet.add(C[i]);
		}
		
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		
		long[] temp = new long[N];
		for (int i = 0; i < N; i++) {
			Integer c = cSet.higher(B[i]);
			
			if (c != null) {
				int index = binarySearch2(C, c);
				temp[i] = (long) (N - index);
			}
		}
		
		for (int i = N - 2; i >= 0; i--) {
			temp[i] += temp[i + 1];
		}
		
		long answer = 0;
		for (int i = 0; i < N; i++) {
			Integer b = bSet.higher(A[i]);
			
			if (b != null) {
				int index = binarySearch2(B, b);
				answer += temp[index];
			}
		}
		System.out.println(answer);
	}
	
	public static int binarySearch1(int[] arr, int n) {
		int low = 0;
		int high = arr.length - 1;
		
		while (low <= high) {
			int mid = (low + high) / 2;
			
			if (arr[mid] == n && (mid == arr.length - 1 || arr[mid + 1] != arr[mid])) {
				return mid;
			} else if (arr[mid] > n) {
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
		return -1;
	}
	
	public static int binarySearch2(int[] arr, int n) {
		int low = 0;
		int high = arr.length - 1;
		
		while (low <= high) {
			int mid = (low + high) / 2;
			
			if (arr[mid] == n && (mid == 0 || (mid > 0 && arr[mid - 1] != arr[mid]))) {
				return mid;
			} else if (arr[mid] < n) {
				low = mid + 1;
			} else {
				high = mid - 1;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 111316
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])cout <<"Yes";
    else  cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("ouut.txt","w",stdout);
  #endif
}
///////////U L R D
int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};


int main() 
{ 
    fast_io
    go();
   string s;cin>>s;
   int i=0,j=s.size()-1;
   int n=s.size()-1;
   while(i<j)
   {
    if(s[i]!=s[j])
    {
      cout << "No" <<"\n";
      return 0;
    }
    i++;j--;
   }
   int a=0,b=n/2-1,c=n/2+1,d=n;
   //cout << a << " " <<b<<" "<<c<<" "<<d <<endl;
   while(a<b)
   {
    if(s[a]!=s[b])
    {
      cout << "No" <<"\n";
      return 0;
    }
    a++;b--;
   }
   while(c<d)
   {
    if(s[c]!=s[d])
    {
      cout << "No" <<"\n";
      return 0;
    }
    c++;d--;
   }
   cout << "Yes" <<'\n'; 
}

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
	ll N;
	ll a[300300];
	ll ans=0;
	cin >> N;
	for (ll i = 0; i < 3*N; ++i)
	{
		scanf("%lld",&a[i]);
	}
	sort(a,a+3*N);
	for (ll i = 3*N-2; i >= N; i-=2)
	{
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int D;
    cin>>D;
    int papapa;
    for(int i=0;i<26;i++)cin>>papapa;
    for(int i=0;i<365;i++){
        int ma=0,manum=0;
        for(int i=0;i<26;i++){
            int p;
            cin>>p;
            if(ma<p){
                ma=p;
                manum=i+1;
            }
        }
        cout<<manum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

set<char> s;
int n;
char c;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
	cin>>n;
	while(n--)
	{
		cin>>c;
		s.insert(c);
	}
	if(s.size()==3)
		cout<<"Three";
	else
		cout<<"Four";
}
	

Measured memory_bytes: 3528
import sys
import itertools

s = sys.stdin.readline().rstrip()
n = len(s)


ans = 0
for i in range(n):
    combs = list(map(list, itertools.combinations(range(1, n), i)))
    res2 = 0
    for c in combs:
        c.insert(0, 0); c.append(n)
        res1 = 0
        for j in range(1, i+2):
            res1 += int(s[c[j-1]:c[j]])
        res2 += res1
    ans += res2

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Node {
    int id;
    Node *left;
    Node *right;
};

int n;
Node nodes[25];
Node *root;
bool hasparent[25];

inline void walk_preorder(Node *node) {
    printf(" %d", node->id);
    if (node->left) {
        walk_preorder(node->left);
    }
    if (node->right) {
        walk_preorder(node->right);
    }
}

inline void walk_inorder(Node *node) {
    if (node->left) {
        walk_inorder(node->left);
    }
    printf(" %d", node->id);
    if (node->right) {
        walk_inorder(node->right);
    }
}

inline void walk_postorder(Node *node) {
    if (node->left) {
        walk_postorder(node->left);
    }
    if (node->right) {
        walk_postorder(node->right);
    }
    printf(" %d", node->id);
}

int main(void) {

    cin >> n;

    for (int i = 0, id, left, right; i < n; ++i) {
        scanf("%d %d %d", &id, &left, &right);
        Node& pnode = nodes[id];
        pnode.id = id;
        if (left != -1) {
            pnode.left = &nodes[left];
            hasparent[left] = true;
        }
        if (right != -1) {
            pnode.right = &nodes[right];
            hasparent[right] = true;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!hasparent[i]) {
            root = &nodes[i];
            break;
        }
    }

    assert(root != NULL);

    printf("Preorder\n");
    walk_preorder(root);
    printf("\n");

    printf("Inorder\n");
    walk_inorder(root);
    printf("\n");

    printf("Postorder\n");
    walk_postorder(root);
    printf("\n");

    return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
  int n;
  cin >>n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0;i<n;i++){//hennkou
    string r,l;
    for(int j=0;j<i;j++){
      r+=s.at(j);
    }
    for(int j=i;j<n;j++){
      l+=s.at(j);
    }
    string che ="abcdefghijklmnopqrstuvwxyz";
    int z = 0;
    for(int j=0;j<che.size();j++){
      bool rr =false,LL=false;
      for(int k=0;k<r.size();k++){
        if(che.at(j)==r.at(k))rr=true;
      }
      for(int k=0;k<l.size();k++){
        if(che.at(j)==l.at(k))LL=true;
      }
      if(rr&&LL)z++;
    }
    ans = max(ans,z);
  }
  cout << ans << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> ans(h, vector<int>(w));
    vector<int> v;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < a[i]; j++) {
            v.push_back(i + 1);
        }
    }
    for(int i = 0; i < v.size(); i++) {
        ans[i / w][i % w] = v[i];
    }
    for(int i = 0; i < h; i++) {
        if(i % 2 == 1) {
            reverse(all(ans[i]));
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

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

using namespace std;

int main()
{
	int d;
	double area;
	int x;
	//int y;
	while(cin >> d)
	{
		x = 0;
		//d = 0;
		area = 0;
		while(x <= 600 - d)
		{
			area += pow(x,2.0) * d;
			x += d;
			//cout << x << endl;
		}
		printf("%ld\n",(long int)area );
		//cout << area << endl;
	}
	//cout << area << endl;
}

Measured memory_bytes: 1148
#include <iostream>
using namespace std;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin >> n >> s;
	ll cnt = 0;
	REP(i, n){if (s[i]=='E') cnt++;}
	ll ans = INF;
	REP(i, n){
		if(s[i] == 'E'){cnt--;}
		if(s[i-1]=='W'){cnt++;}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

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

int main(){
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2+y1-y2 << endl;
  cout << y2-x1+x2 << endl;
  cout << x1+y1-y2 << endl;
  cout << x2-x1+y1 << endl;
}
  

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]-=1
kai=[-1 for i in range(n)]
nx=0
now=0
kai[0]=0

if k<=n:
  for i in range(k):
    nx=a[now]
    now=nx
    #print(nx)
  ans=nx+1
else:
  for i in range(n):
    nx=a[now]
    if kai[nx]==-1:
      kai[nx]=i+1
      now=nx
    else:
      T=i+1-kai[nx]
      break
  times=kai[nx]+(k-kai[nx])%T
  now=0
  nx=0
  for i in range(times):
    nx=a[now]
    now=nx
    #print(nx)
  ans=nx+1
print(ans)

Measured memory_bytes: 32364
#include<stdio.h>
int main()
{
    int n, four, two, other, i, x;
    four = 0;
    two = 0;
    other = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &x);
        if(x % 4 == 0)four++;
        else if(x % 2 == 0)two++;
        else other++;
    }
    two = two > 0 ? 1 : 0;
    if(other + two <= four + 1)printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
A = ['a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','q','w','e','r','t','y','u','i','o','p']
S = list(set(input()))
for i in S:
    A.remove(i)
A.sort()
try:
    print(A[0])
except:
    print("None")


Measured memory_bytes: 9160
#include <iostream>
#include <deque>

using namespace std;

typedef deque <int> Deq;

bool flag;
int ball[10], a;

void dfs(Deq B, Deq C, int deep)
{
	if (flag) return;
	if (deep == 10){
		// cout << "B : " << B.size() << " / ";
		// for (int i = 0; i < B.size(); i++){
		// 	cout << B[i] << " ";
		// }
		// cout << endl << "C : " << C.size() << " / ";
		// for (int i = 0; i < C.size(); i++){
		// 	cout << C[i] << " ";
		// }
		// cout << endl;
		bool bf = true, cf = true;
		for (int i = 0; i+1 < B.size(); i++){
			if (B[i] > B[i+1]) bf = false;
		}
		for (int i = 0; i+1 < C.size(); i++){
			if (C[i] > C[i+1]) cf = false;
		}
		flag |= (bf && cf);
		return;
	}

	B.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	B.pop_back();

	C.push_back(ball[deep]);
	dfs(B, C, deep + 1);
	C.pop_back();
	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		flag = false;
		Deq B, C;
		dfs(B, C, 0);

		if (flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void readInto(T...)(ref T ts) {
    auto ss = readln.split;
    foreach(ref t; ts) {
        t = ss.front.to!(typeof(t));
        ss.popFront;
    }
}

void main() {
    int[char] a;
    const string s = readln.chomp;
    foreach(c; s) {
        a[c]++;
    }

    if (a.length == 2 && a[s[0]] == 2) {
        writeln("Yes");
    } else {
        writeln("No");
    }
}


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

typedef long long ll;
int main(){
    ll a,b,n,score=0;
    cin>>a>>b>>n;
    /*
    for(int i=1; i<=min(b,n); i++){
        //cout<<">"<<a*i/b-a*(i/b)<<endl;
        score=max(a*i/b-a*(i/b),score);
    }
    */
    ll x=min(n,b-1);
    cout<<a*x/b-a*(x/b)<<endl;
    return 0;
}

Measured memory_bytes: 3588
R,G,B,N = map(int,input().split())
r_max = N//R

ans =0
for i in range(r_max+1):
    n_r = N-(R*i)
    if n_r==0:
        ans+=1
    else:
        g_max = n_r//G
        for j in range(g_max+1):
            n_g = n_r-G*j
            if n_g==0:
                ans+=1
            else:
                if n_g%B==0:
                    ans+=1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int N= 1000005 ;
const long long mod = 1.0e9+7;
int mp[N],vis[N];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,m,i,x,y,z;
        cin>>n;
        int arr[n+1];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
            mp[arr[i]]++;
        }
        sort(arr,arr+n);
        int cnt=0;
        if(arr[0]==1 && mp[arr[0]]==1) {
            cout<<"1"<<endl;
            return 0;
        }
        if(arr[0]==1 && mp[arr[0]]>1) {
            cout<<"0"<<endl;
            return 0;
        }
        for(i=0;i<n;i++) {
            //cout<<arr[i]<<" "<<vis[arr[i]]<<endl;
            if(vis[arr[i]]==0) {
                if(mp[arr[i]]==1)
                cnt++;
                for(int j=1;(j*arr[i])<=N &&(j*arr[i])<=arr[n-1];j++) {
                    if(mp[(j*arr[i])]>0)
                        vis[(j*arr[i])]++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 20728
import sys
N,K = map(int,input().split())
int_array = list(map(int,input().split()))

if N < 0 or K < 0 or N > 50 or K > 50:
    sys.exit()
for I in int_array:
    if I > 50:
        sys.exit()

rev_sort_int_array = sorted(int_array,reverse=True)
result = 0
for J in range(K):
    result += rev_sort_int_array[J]

print(result)

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, M;
vector<int> G[100010];
bool used[100010][2];

int main(){

    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<pii> q;
    q.push(pii(0, 0));
    used[0][0] = true;
    while(q.size()){
        pii p = q.front(); q.pop();
        int pos = p.first;
        int flg = p.second;
        for(int npos : G[pos]){
            if(used[npos][flg^1]) continue;
            q.push(pii(npos, flg^1));
            used[npos][flg^1] = true;
        }
    }
    
    ll zero = 0;
    ll one = 0;
    ll zo = 0;
    for(int i = 0; i < N; i++){
        if(used[i][0] && used[i][1]) zo++;
        else if(used[i][0] && !used[i][1]) zero++;
        else if(!used[i][0] && used[i][1]) one++;
    }
    ll sum = zero * one + zo * zero + zo * one + zo * (zo - 1) / 2;
    sum -= M;
    cout << sum << endl;

    return 0;
}


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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

class UnionFind
{
  private:
    vector<int> par;
    vector<int> sizes;

  public:
    UnionFind(int N) : par(N), sizes(N, 1)
    {
        rep(i, N) par[i] = i;
    }

    int find(int x)
    {
        if (x == par[x])
            return x;

        return par[x] = find(par[x]);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (sizes[x] < sizes[y])
            swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    int size(int x)
    {
        return sizes[find(x)];
    }
};

int main()
{
    int N, M;
    while (cin >> N >> M, N)
    {
        vector<T> edges;

        rep(i, M)
        {
            int a, b, cost;
            cin >> a >> b >> cost;

            edges.push_back(make_tuple(cost, a, b));
        }

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

        UnionFind uf(N);

        int ans = 0;

        for(auto e : edges)
        {
            int to, from, cost;
            tie(cost, to, from) = e;

            if(uf.same(from, to)) continue;

            uf.unite(from, to);

            ans += cost;

        }

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


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int x,y;
   cin>>x>>y;
   vector<int>t={1,3,1,2,1,2,1,1,2,1,2,1,};
   //左からの番号の値がその番号の所属。
   if(t[x-1]==t[y-1]){cout<<"Yes"<<endl;}
   else{cout<<"No"<<endl;}
   
return 0;}

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

int main(){
  int N,M;
  cin >> N;
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin >> T.at(i);
  }
  cin >> M;
  vector<int> P(M),X(M);
  for(int i=0;i<M;i++){
    cin >> P.at(i) >> X.at(i);
  }
  for(int i=0;i<M;i++){
    long long time=0;
    for(int j=0;j<N;j++){
      if(j!=P.at(i)-1){
        time+=T.at(j);
      }
      else{
        time+=X.at(i);
      }
    }
    cout << time << endl;
  }
}

Measured memory_bytes: 3640
package main

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

type work struct{ time, limit int }
type works []work

func (w works) Len() int           { return len(w) }
func (w works) Swap(i, j int)      { w[i], w[j] = w[j], w[i] }
func (w works) Less(i, j int) bool { return w[i].limit < w[j].limit }

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	ws := works(make([]work, n))
	for i := range ws {
		sc.Scan()
		ws[i].time, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		ws[i].limit, _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(ws)
	sum := 0
	for _, w := range ws {
		sum += w.time
		if sum > w.limit {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

/*
 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} */

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


int main() {
  unsigned long long ans;
  ll N;
  cin >> N;
  vector<unsigned long long> A(N);
  //vector<vector<int>> data(3, vector<int>(4));

 

  for (ll i=0; i < N; i++){
    cin >> A[i];
  }

  for (ll i=0; i < N; i++){
    if(A[i]==0){
      cout << "0" << endl;
      return 0;
    }
  }
  
  
  ans = A[0];

  for (ll i=1; i < N; i++){
/*     ll ans_tmp = log10(ans)+1;
    ll ans_a = log10(A[i])+1;
    if(ans_tmp + ans_a -1 >= 19){ //　かける値の桁数に着目
      cout << "-1" << endl;
      return 0;
    } */
    
      if(A[i] <= 1000000000000000000/ans){
        ans *= A[i];
    } else{
      cout << "-1" << endl;
      return 0;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4064
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	long long n,a=26,b[10000]={};
	cin>>n;
	int c=0;
	while(n>=a/26){
		long long d;
		d=n%a;
		if(d==0){
			d=a;
		}
    	n-=d;
		d/=(a/26);
		b[c]=d;
		a*=26;
		c++;
	}
	for(int i=c-1;i>=0;i--){
		char e='a'+b[i]-1;
		cout<<e;
	}
	cout<<endl;
    return(0);
}

Measured memory_bytes: 3684
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int H, N, sum=0;
vector<int> A(1e5+1);

int main()
{
    ios::sync_with_stdio(false);
    cin >> H >> N;
    REP(i,0,N) cin >> A[i];
    REP(i,0,N) sum +=A[i];
    if(H <= sum) CO("Yes");
    else CO("No");
    return 0;
}

Measured memory_bytes: 640
def main():
    N, M = map(int, input().split())

    cards = [0] * (N + 1)

    for _ in range(M):
        l, r = [int(v) - 1 for v in input().split()]
        cards[l] += 1
        cards[r+1] -= 1

    count = 0
    if cards[0] == M:
        count += 1

    for i in range(1, N+1):
        cards[i] += cards[i - 1]
        if cards[i] == M:
            count += 1

    print(count)


main()


Measured memory_bytes: 6900
class UnionFind:
    def __init__(self, n=1):
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
        self.number = [1] * n
    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.parent[y] = x
            res = self.number[x] * self.number[y]
            self.number[x] += self.number[y]
            return res
        else:
            return 0


N, M = map(int, input().split())
uf = UnionFind(N)
AB = []
for i in range(M):
  AB.append(list(map(int, input().split())))

ans = [N*(N-1)//2]
while AB:
  a, b = AB.pop()
  decrease = uf.union(a-1, b-1)
  _ans = ans[-1] - decrease
  ans.append(_ans)
  if _ans == 0:
    break

ans += [0] * (M - len(ans))
ans = ans[::-1]
ans = ans[-M:]
print(*ans, sep='\n')

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a%3==0 || b%3==0 || (a+b)%3==0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}


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

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

    map<string, int> dict;
    rep(i, N) {
        string S;
        cin >> S;
        dict[S]++;
    }

    int maxv = 0;
    for (auto x: dict) {
        int v = x.second;
        if (v > maxv) maxv = v;
    }
    for (auto d = dict.begin(); d != dict.end(); d++) {
        if (maxv == d->second) cout << d->first << endl;
    }

    return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	ll r, D, x; cin >> r >> D >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - D;
		cout << x << endl;
	}

	return 0;
}

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

class Fountain{
    int X,Y;
    public Fountain(int x,int y){
        X = x;
        Y = y;
    }
}

class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int x1 = scan.nextInt();
        int y1 = scan.nextInt();
        int x2 = scan.nextInt();
        int y2 = scan.nextInt();

        if(x1>x2){
            int tmp = x1;
            x1 = x2;
            x2 = tmp;
            tmp = y1;
            y1 = y2;
            y2 = tmp;
        }
        int N = scan.nextInt();
        Fountain[] fountain = new Fountain[N];
        for(int i=0;i<N;++i){
        fountain[i] = new Fountain(scan.nextInt(), scan.nextInt());
        }
        if(y1 > y2){
            y1 = (int)1e8 -1 - y1;
            y2 = (int)1e8 -1 - y2;
            for(int i=0;i<N;++i){
                fountain[i].Y = (int)1e8 -1 -fountain[i].Y;
            }
        }
        Arrays.sort(fountain, (a,b) -> a.X-b.X);
        int[] lis = new int[N+1];
        Arrays.fill(lis,Integer.MAX_VALUE);
        lis[0] = 0;
        for(int i=0;i<N;++i){
            if(fountain[i].X < x1 || fountain[i].X > x2)continue;
            if(fountain[i].Y < y1 || fountain[i].Y > y2)continue;
            int left = 0;
            int right = N+1;
            while(true){
                int center = (left+right)/2;
                if(lis[center] > fountain[i].Y){
                    right = center;
                }else{
                    left = center;
                }
                if(right - left ==1)break;
            }
            lis[right] = fountain[i].Y;
        }
        for(int i=N;i>=0;i--){
            if(lis[i] < Integer.MAX_VALUE){
                double ans = (double)(x2 - x1 + y2 - y1) * 100;
                ans -= i*(20 - 5*Math.PI);
                if(i > Math.min(x2-x1,y2-y1)){
                    ans += 10*Math.PI - 20;
                    ans += 20 - 5*Math.PI;
                }
                System.out.println(ans);
                break;
            }
        }



    }
}

Measured memory_bytes: 110620
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    bool ret = true;
    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i + 1])ret = false;
    }
    cout << (ret ? "Good" : "Bad") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int n,int k,int *hate){
  int i;
  for(i=0;i<k;i++){
    if(n==hate[i]){
      return 1;
    }
  }
  return 0;
}

int main(){
  int hate[9];
  int n,k,i,ok=0,tmp;
  
  scanf("%d %d",&n,&k);
  for(i=0;i<k;i++){
    scanf("%d",&hate[i]);
  }
  
  while(ok==0){
    ok=1;
    tmp=n;
    while(0<tmp){
      if(search(tmp%10,k,hate)==1){
        ok=0;
        n++;
        break;
      }
      tmp=tmp/10;
    }
  }
  
  printf("%d",n);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
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...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

const int N = 1 << 18, MID = 1 << 10, MAX = 1e5;
int dp[MID + 1][MAX + 1];
int val[N], w[N], h[N];
int main() {
	run();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> val[i] >> w[i];
		h[i] = h[i >> 1] + 1;
	}
	for (int i = 1; i <= n && i <= MID; i++)
		for (int j = 0; j <= MAX; j++) {
			dp[i][j] = dp[i >> 1][j];
			if (j >= w[i])
				dp[i][j] = max(dp[i][j], dp[i >> 1][j - w[i]] + val[i]);
		}
	int q;
	cin >> q;
	while (q--) {
		int v, l;
		cin >> v >> l;
		vector<pair<int, int>> tmp;
		while (v > MID) {
			tmp.push_back( { val[v], w[v] });
			v >>= 1;
		}
		int rt = dp[v][l];
		for (int i = 1; i < (1 << sz(tmp)); i++) {
			int sumVal = 0, sumWig = 0;
			for (int j = 0; j < sz(tmp); j++) {
				if (i & (1 << j))
					sumWig += tmp[j].second, sumVal += tmp[j].first;
			}
			if (sumWig <= l)
				rt = max(rt, dp[v][l - sumWig] + sumVal);
		}
		cout << rt << endl;
	}
}


Measured memory_bytes: 406728
#include <stdio.h>

/*
 * jyjfÅ é©Ì»èÖ
 *
 * ßèl
 *   - 1 : jyjfÅ é
 *   - 0 : jyjfÅÈ¢
 */
int isMSPrime(int x){
	int i = 6;

	while(i*i <= x){
		if(x % i == 0) return 0;
		if(i % 7 == 1){
			i += 5;
		} else{
			i += 2;
		}
	}
	return 1;
}

int main(void){
	int i,flg;
	int x; //üÍl

	while(1){
		scanf("%d",&x);
		if(x == 1) break;

		printf("%d:",x);

		flg = 0;
		i = 6; //êÔÅÌjyjf
		while(i < x){
			if(x % i == 0 && isMSPrime(i)){
				printf(" %d",i);
				flg = 1;
			}

			if(i % 7 == 1){
				i += 5;
			} else{
				i += 2;
			}
		}
		if(flg == 0) printf(" %d",x);
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    cout<<3*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
import collections
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = [0] + list(itertools.accumulate(A))
d = collections.defaultdict(int)
for i in range(N+1):
    d[B[i]%M] += 1
d = list(d.items())
ans = 0
for i in d:
    ans += i[1]*(i[1]-1)//2
print(ans)

Measured memory_bytes: 19364
#include <iostream>
#include <utility> //swap()を使うためインクルード
using namespace std;

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p - 1;
    for(int j = p; j <r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
            /*int tmp1 = A[i];
            A[i] = A[j];
            A[j] = tmp1;*/
        }
    }
    swap(A[i + 1], A[r]);
    /*int tmp2 = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp2;*/

    return (i + 1);
}

int main(void){
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    
    int p = partition(A, 0, n - 1);

    for(int k = 0; k < n; k++){
        if(k != 0) cout << " ";
        if(k == p)cout << "[" << A[k] << "]";
        else cout << A[k];
    }
    cout << endl;
}



Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 50005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;

  vector<ll> arr[m + 5], rarr[n + 5];

  for (ll i = 1; i <= m; i++) {
    ll x;
    cin >> x;
    while (x--) {
      ll y;
      cin >> y;
      arr[i].push_back(y);
      rarr[y].push_back(i);
    }
  }

  ll arr2[m + 5];
  for (ll i = 1; i <= m; i++)
    cin >> arr2[i];

  ll res = 0;
  for (ll i = 0; i < (1 << n); i++) {

    ll val[m + 5];
    memset(val, 0, sizeof(val));
    ll arr3[n + 5];
    for (ll j = 0; j < n; j++) {
      if (i & (1 << j)) {
        arr3[j + 1] = 1;
      } else
        arr3[j + 1] = 0;

      for (ll x : rarr[j + 1])
        val[x] += arr3[j + 1];
    }
    ll cnt = 0;
    for (ll i = 1; i <= m; i++) {
      if ((val[i] & 1) == arr2[i])
        cnt++;
    }
    res += (cnt == m);
  }
  cout << res << en;

  return 0;
}

/*
1
11 5 8 3 4
NEESSWWNESE
 */

Measured memory_bytes: 256
#include <iostream>
long long mod=1000000007,A,d[100][256];
int main(){
  int N;
  std::cin>>N;
  for(int i=0;i<256;i++)d[0][i]=(i/4==0);
  for(int i=1;i<N;i++){
    for(int j=0;j<1024;j++)d[i][j%256]+=d[i-1][j/4]%mod;
    if(i>1)for(int j=0;j<256;j+=64)d[i][j+6]=d[i][j+18]=d[i][j+9]=0;
    if(i>2)d[i][22]=d[i][54]=d[i][30]=0;
  }
  for(int i=0;i<256;i++)A+=d[N-1][i];
  std::cout<<A%mod;
}



Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int n, m;
	int ans = 0;

	scanf("%d %d", &n,&m);
	ans = (100 * n) + (1800 * m);
	f(i, m){
		ans = ans * 2;
	}

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


	return 0;
}

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

using namespace std;

#define LIMIT 100
typedef pair<int64_t, int64_t> ii;
typedef int64_t ll;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

int a[2][100];
int n;
int dfs(int x, int y){
  if (x< 0 || y>= n || x >1 || y < 0) return INT_MIN;
  if(x == 1 && y == n-1) return a[x][y];
  return a[x][y] + max(dfs(x+1, y), dfs(x, y+1));
}

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;

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

  std::cout << dfs(0, 0) << std::endl;

  return 0;
}



Measured memory_bytes: 256
/*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
   #include <bits/stdc++.h>
   using namespace std;
   #define ll long long
   #define w(t) int t; cin>>t; while(t--)
   #define fo(i,n) for(int i=0;i<n;i++)
   #define endl "\n" 
   #define MOD 1000000007
   const ll inf=1e18;
   void Tez(){
      ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
   }
   int main(){
      Tez();
      ll a,b,c,d;
      cin>>a>>b>>c>>d;
      ll ans=-inf;
      ans=max({a*c,a*d,b*c,b*d});
      cout<<ans;

      return 0;
   }



Measured memory_bytes: 3628