akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cfloat>
using namespace std;
int mod = 1e9+7;
long long int inf = 1e18;

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

  vector< vector<int> > b = a;
  for(int i=1; i<n; i++){
    b[0][i] += b[0][i-1];
  }
  for(int i=1; i<n; i++){
    b[1][n-1-i] += b[1][n-i];
  }
  int mx = -1;
  for(int i=0; i<n; i++){
    mx = max(mx, b[0][i]+b[1][i]);
  }
  cout << mx << endl;

  return 0;
}

//


Measured memory_bytes: 256
import math 

def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,a,b = map(int, input().split())
vl = list(map(int, input().split()))

vl.sort(reverse=True)
if vl[0] == vl[a-1]:
    v = vl[0]
    print(v)
    v_cnt = vl.count(v)
    max_r = min(v_cnt,b)
    ans = 0
    for r in range(a,max_r+1):
        ans += com(v_cnt,r)
    print(ans)

else:
    print(sum(vl[:a])/a)
    last_val = vl[a-1]
    last_val_cnt = vl[0:a].count(last_val)
    all_last_val_cnt = vl.count(last_val)
    print(com(all_last_val_cnt,last_val_cnt))

Measured memory_bytes: 64216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;

int n,m;
int dp[100005];

int rec(vector<vector<int>>& G,int v)
{
  if(dp[v]!=-1) return dp[v];
  int res = 0;
  for(auto nv: G[v]){
    res = max(res, rec(G, nv)+1);
  }
  return dp[v] = res;
  
}

int main()
{
  cin >> n >> m;
  vector<vector<int>> G(n);
  REP(i,m){
    int a,b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
  }
  REP(i,n) dp[i] = -1;
  int res = 0;
  REP(i,n) res = max(res, rec(G, i));
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 8192
#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()
{
  ll X;
  cin >> X;
  ll money = 100;
  ll year = 0;
  while (true) {
    year++;
    money = money + floor(money * 0.01);
    if (X <= money ) {
      break;
    }
  }
  cout << year << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
#define l first
#define r second
#define diff(x) (max(diff_(x),0l))
#define diff_(x) ((x).second-(x).first+1)
#define mp make_pair
int solve(const int& n,const vector<pi>& prob){
  vector<pi> mei(n,prob[0]),med(n,prob[n-1]);
  for(int i=1;i<n-1;++i){
    mei[i].l=max(prob[i].l,mei[i-1].l);
    mei[i].r=min(prob[i].r,mei[i-1].r);
  }
  for(int i=n-2;i>0;--i){
    med[i].l=max(prob[i].l,med[i+1].l);
    med[i].r=min(prob[i].r,med[i+1].r);
  }
  int res=0;
  for(int i=0;i<n-1;++i){
    res=max(res,diff(mei[i])+diff(med[i+1]));
  }
  return res;
}
signed main(){
  int n;
  cin>>n;
  vector<pi> prob(n);
  for(auto &p:prob)cin>>p.l>>p.r;
  sort(prob.begin(),prob.end(),[](pi a,pi b){return diff(a)==diff(b)?(a.l==b.l?a.r<=b.r:a.l<b.l):diff(a)<diff(b);});
  int resd=solve(n,prob);
  sort(prob.begin(),prob.end(),[](pi a,pi b){return a.l==b.l?a.r<b.r:a.l<b.l;});
  int resL1=solve(n,prob);
  sort(prob.begin(),prob.end(),[](pi a,pi b){return a.l==b.l?a.r>b.r:a.l<b.l;});
  int resL2=solve(n,prob);
  sort(prob.begin(),prob.end(),[](pi a,pi b){return a.r==b.r?a.l<b.l:a.r<b.r;});
  int resR1=solve(n,prob);
  sort(prob.begin(),prob.end(),[](pi a,pi b){return a.r==b.r?a.l>b.l:a.r<b.r;});
  int resR2=solve(n,prob);
  cout<<max({resd,resL1,resL2,resR1,resR2});
}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<long> a(N);

  for(int i=0;i<N;i++) cin>>a[i];
  long ans=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(K>0){
      K--;
      continue;
    }
    else{
      ans+=a[i];
    }
    }

cout<<ans<<endl;

}


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

int compare_int(const void *a, const void *b){
return *(long long*)a - *(long long*)b;
}

int main(){
		int n,i,ans=0;
		long long c,k,a[100000];
		scanf("%d%lld%lld",&n,&c,&k);
		if(c==1){
				printf("%d\n",n);
				return 0;
		}
		for(i=0;i<n;i++)scanf("%lld",&a[i]);
		qsort(a,n,sizeof(long long),compare_int);
		long long tmp=a[0];
		int cc=1;
		for(i=1;i<n;i++){
				cc++;
				if(cc>c){
						ans++;
						tmp=a[i];
						cc=1;
				}
				if(a[i]-tmp>k){
						ans++;
						tmp=a[i];
						cc=1;
				}
		}
		ans++;
		printf("%d\n",ans);
		return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, v, w, t; cin >> a >> v >> b >> w >> t;
	int c = abs(a - b);
	if (a == b) {
		cout << "YES" << endl;
		return 0;
	}
	if (w > v) {
		cout << "NO" << endl;
		return 0;
	}
	if (c <= (long long)t * (v - w)) {
		cout << "YES" << endl;
		return 0;
	}
	cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 3608
import numpy as np

N,M = map(int,input().split())

fig = []
for i in range(N):
  fig.append(list(input()))
fig = np.array(fig)
fig=np.where(fig ==".", 0, fig)
fig=np.where(fig =="#", 1, fig)
fig=fig.astype("int32")

template = []
for i in range(M):
  template.append(list(input()))
template = np.array(template)
template=np.where(template ==".", 0, template)
template=np.where(template =="#", 1, template)
template=template.astype("int32")

F = False
for i in range(fig.shape[0]-template.shape[0]+1):
  for j in range(fig.shape[1]-template.shape[1]+1):
    F = F|np.allclose(fig[i:i+template.shape[0],j:j+template.shape[1]] , template)

print("Yes" if F else "No")

Measured memory_bytes: 12508
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    vector<string>v;
    ll n,l;
    string x;
    cin>>n>>l;
    while(n--)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n,a,b;cin>>n>>a>>b;
    if(((a-b)%2+2)%2==0){
        cout<<"Alice"<<endl;
    }else{
        cout<<"Borys"<<endl;
    }
    
    
    return 0;
}






Measured memory_bytes: 256
n = int(input())

felicidade = []

for x in range(n):
    felicidade.append(list(map(int,input().split())))

DP = [0,0,0]

if n == 1:
    print(max(felicidade[0]))

else:

    for x in range(3):
        DP[x] = felicidade[0][x]


    for dia in range(1,n):
        m = [0] * 3
        for x  in range(3):
            for y  in range(3):
                if x != y:
                    m[x] = max(m[x], DP[y] + felicidade[dia][x])
        DP = m

    print(max(DP))


Measured memory_bytes: 61656
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::char;
use std::collections::HashMap;
fn main() {

    input! {
        s: chars,
    }
    let mut m = (0..26).map(|x| (x + b'a') as char).map(|c| (c, 0)).collect::<HashMap<_, _>>();
    for i in 0..s.len() {
        //m[&s[i]]+=1;
        if let Some(st) = m.get_mut(&s[i]) {
            *st+=1;
        }
    }

    let mut x: Vec<char> = Vec::new();

    let v = (0..26).map(|x| (x + b'a') as char).collect::<Vec<_>>();
    for i in 0..v.len() {
        if m[&v[i]] == 0 {
            x.push(v[i]);
        }
    }

    if x.is_empty() {
        println!("None");
    } else {
        x.sort();
        println!("{}", x[0]);
    }
}

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

int main()
{
	char x, y;
	cin >> x >> y;
	if (y - x > 0) {
		cout << '<' << endl;
	}
	else {
		if (x - y == 0) {
			cout << '=' << endl;
		}
		else {
			cout << '>' << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import math

def comb(n, k, m):
  f = [1] * (n+1)
  for i in range(1, n+1):
    f[i] = f[i-1] * i % m
  return f[n] * pow_mod(f[k]*f[n-k]%m, m-2, m) % m

def pow_mod(a, b, m):
  if b == 0:
    return 1
  elif b%2 == 0:
    d = pow_mod(a, b//2, m) % m
    return d * d % m 
  else:
    d = pow_mod(a, (b-1)//2, m)
    return  d * d * a % m

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]

ans = 0
mod = 10**9 + 7

if (x + y) % 3 != 0:
  ans = 0
else:
  n = (x + y) // 3
  if min(x, y) < n:
    ans = 0
  elif min(x,y) == n:
    ans = 1
  else:
    r = min(x, y) - n
    ans = comb(n, r, mod)

print(ans)

Measured memory_bytes: 29428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// Author - Kevin Mathew
// Birla Institute of Technology, Mesra

ll n, a[100010];

void te(){
	cin >> n;
	for(ll i=0;i<n;i++)
		cin >> a[i];

	priority_queue<ll> pq;
	vector<ll> v;

	for(ll i=0;i<n;i++){
		pq.push(-a[i]);
	}

	while(!pq.empty()){
		ll smallest = -pq.top();
		pq.pop();
		while(!pq.empty()){
			v.push_back((-pq.top()) % smallest);
			pq.pop();
		}

		for(ll i=0;i<v.size();i++){
			// cout << v[i] << " ";
			if(v[i] != 0)
				pq.push(-v[i]);
		}

		// cout << "\n";

		v.clear();

		if(pq.empty()){
			cout << smallest << "\n";
			return;
		}

		pq.push(smallest);
	}
}

int main()
{
	//freopen("input.txt", "r", stdin);		//Comment
	//freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	te();

	return 0;
}

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

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

using namespace std;

signed main(){
  int A, B;
  cin >> A >> B; 
  int sum = 0; 
  for(int i=0;i<2;i++){
    if(A>B){
      sum += A;
      A--;
    }else{
      sum += B;
      B--;
    }
  }  
  
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std ;
int N , ptr , res ;
int A[100000];
int main ()
{
scanf("%d",&N );
for ( int i=0; i < N ; i++) scanf("%d" ,&A[i]);
sort(A , A + N);
while( ptr < N )
{
int cc = A[ptr] , f =0;
while ( ptr < N && A[ptr]== cc ) f++ , ptr++;
res += f%2;
}
printf ("%d\n" , res );
}

Measured memory_bytes: 640
////////////////////////////////////////////////
//  ********  *      *    *******    * *      //                 :
//  *         *      *   *       *   *   *    //     64 BITS     C     64 BITS
//  *****     *      *  *         *  *     *  //                 +
//  *         *      *  ***********  *     *  //:  16 - 6 - 2020 +   16 - 6 - 2020 :
//  *         *      *  *         *  *   *    //                 1
//  *         ********  *         *  * *      //     64 BITS     7     64 BITS
////////////////////////////////////////////////                 :
#define ll long long
#define ui unsigned int
#define ud unsigned double
#define mp make_pair
#define pii pair<int,int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pdi pair<double,int>
#define pb push_back
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
const double pi = acos(-1.0);
int main()
{
    int b;
    int g;
    scanf("%d%d", &b,&g);
    if (b <= 10){
        cout<<g+(100*(10-b))<<"\n";
    }
    else{
        cout<<g<<"\n";
    }
    return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int R,G,B,N;
  cin >> R >> G >> B >> N;
  int cnt=0;
  rep(r,N+1){
    rep(g,N+1){
      int tmp = N-r*R-g*G;
      if(tmp >= 0 && tmp%B==0)cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main(){
  string str;
  bool chk = true;
  
  cin >> str;
  
  for(int i = 0; i < str.size(); i++){
    if(i % 2 == 0){
      if(str.at(i) == 'L') chk = false;
    }else{
      if(str.at(i) == 'R') chk = false;
    }
  }
  
  if(chk == true) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<int,pair<int,int> >PII;


const int mx=1e5+10;
priority_queue< int, vector<int> , greater<int> > a[mx];
vector<int>adj[mx];
ll arr[mx];
int vis[mx];
void dfs(int nd,int cmp)
{
	vis[nd]=cmp;
	a[cmp].push(arr[nd]);
	for(int k:adj[nd])
	{
		if(vis[k]==-1)
		{
			dfs(k,cmp);
		}
	}
}
int main()
{
	int n,m,l,r;
	cin>>n>>m;
	rept(i,0,n)cin>>arr[i];
	rept(i,0,m)
	{
		cin>>l>>r;
		adj[l].PB(r);
		adj[r].PB(l);
	}
	memset(vis,-1,sizeof vis);
	int cnt=0;
	rept(i,0,n)
	{
		//cout<<i<<"==== "<<endl;
		if(vis[i]==-1)
		{
			dfs(i,cnt++);
		}
	}
//	cout<<cnt<<endl;
	if(2*cnt-2>n)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	else if(cnt==1)
	{
		cout<<0<<endl;
		return 0;
	}
	else
	{
		ll ans=0;
		rept(i,0,cnt)
		{
			ans+=a[i].top();
			a[i].pop();
		}
		rept(i,0,cnt)
		{
			while(!a[i].empty())
			{
				a[mx-1].push(a[i].top());
				a[i].pop();
			}
		}
		cnt-=2;
		while(cnt--)
		{
			ans+=a[mx-1].top();
			a[mx-1].pop();
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;

/* 
    b>0 d>0
    b<0 d>0
    b>0 d<0
    b<0 d<0


*/
int main() {
    long long int a, b, c, d, ans = 0;
    cin>>a>>b>>c>>d;

    long long x, y;

    long long prod[4];

    prod[0] = a*c;
    prod[1] = a*d;
    prod[2] = b*c;
    prod[3] = b*d;

    cout<<*max_element(prod, prod+4)<<endl;

    return 0;
}

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

int n, tw[1001], mn[1001], inf = 1e9;
vector<int> tr[1001];

inline void up(vector<int> &d1, vector<int> &d2, int i, int j, int c){
	j += i;
	if (j > 5000)return;
	d2[j] = min(d2[j], d1[i] + c);
}

void go(int v = 1){
	vector<vector<int> > dp(tr[v].size() + 1, vector<int>(5001, 1e9));
	dp[0][0] = 0;
	f(ed, 0, tr[v].size()){
		int u = tr[v][ed];
		go(u);
		for (int i = 5000; i >= 0; --i){
			up(dp[ed], dp[ed + 1], i, tw[u], mn[u]);
			up(dp[ed], dp[ed + 1], i, mn[u], tw[u]);
		}
	}
	mn[v] = inf;
	f(i, 0, tw[v] + 1)mn[v] = min(mn[v], dp[tr[v].size()][i]);
	if (mn[v] == inf)printf("IMPOSSIBLE\n"), exit(0);
}

int main(){
	scanf("%d", &n);
	f(i, 2, n + 1){
		int t;
		scanf("%d", &t);
		tr[t].push_back(i);
	}
	f(i, 1, n + 1)scanf("%d", tw + i);
	go();
	printf("POSSIBLE\n");
}

Measured memory_bytes: 20928
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s =new Scanner(System.in);
		int x,y;
		while(true){
			x = Integer.parseInt(s.next());
			y = Integer.parseInt(s.next());
			if(x==0&&y==0)break;
			if(x<=y)System.out.println(x+" "+y);
			else System.out.println(y+" "+x);
		}
	}
}
			

Measured memory_bytes: 35660
#include <iostream>
using namespace std;
 
int main() {
  int H, N;
  cin >> H >> N;
  int all = 0;
  for (int i = 0; i < N;i++) {
    int A;
    cin >> A;
    all += A;
  }
  if (H <= all) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    N, W = list(map(int, input().strip().split()))
    items = [[0, 0]]
    for i in range(N):
        items.append(list(map(int, input().strip().split())))
    dp = [[0]*(W+1) for _ in range(N+1)]
    for i in range(1, N+1):
        for j in range(1, W+1):
            if j-items[i][1] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-items[i][1]]+items[i][0])
    print(dp[N][W])

if __name__ == '__main__':
    main()



Measured memory_bytes: 25572
#include <bits/stdc++.h>
using namespace std;
int main() {
	long int n; cin >> n;
	string s[100005];
	char c[100005];
	int a[26];
	for(int i=0;i<26;i++){
		a[i] = 0;
	}
	for(int i=0;i<n;i++){
		cin >> s[i];
		c[i] = s[i][0];
		//cout << c[i] << endl;
		a[c[i]-'A']++;
	}
	long long int m[5];
	long long int ans = 0;
	m[0] = a['M'-'A'];
	m[1] = a['A'-'A'];
	m[2] = a['R'-'A'];
	m[3] = a['C'-'A'];
	m[4] = a['H'-'A'];
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				ans += m[i]*m[j]*m[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6144
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<int>());
    if (s < t) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define ll long long

int main(void){

    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%2==1)ans++;
    }
    if(ans>=k)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


    return 0;
}

Measured memory_bytes: 256
#横にn個入力
a, b = map(int, input().split())
if a % 3 == 0:
    print("Possible")
    exit()
elif b % 3 == 0:
    print("Possible")
    exit()
elif (a + b) % 3 == 0:
    print("Possible")
    exit()
print("Impossible")

Measured memory_bytes: 2940
S = list(input())
S1 = int("".join(S[0:2]))
S2 = int("".join(S[2:4]))
 
if (12 >= S1 and S1 >= 1) and (12 >= S2 and S2 >= 1):
  print('AMBIGUOUS')
elif (12 >= S1 and S1 >= 1):
  print('MMYY')
elif (12 >= S2 and S2 >= 1):
  print('YYMM')
else :
  print('NA')


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
    int m, f, r;
    while (1) {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1) { break; }
        if (m == -1 || f == -1) {
            printf("F\n");
        } else if (m + f >= 80) {
            printf("A\n");
        } else if (m + f >= 65) {
            printf("B\n");
        } else if (m + f >= 50) {
            printf("C\n");
        } else if (m + f >= 30) {
            if (r >= 50) {
            printf("C\n");
            } else {
                printf("D\n");
            }
        } else {
            printf("F\n");
        }
    }
    return 0;
}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n;
vector<int> a;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  a.resize(n);
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  vector<int> A;
  for (int i=0; i<n; i++) {
    A.push_back(abs(i - (n-1-i)));
  }
  sort(A.begin(), A.end());
  sort(a.begin(), a.end());

  if (a != A) out(0);

  auto pw = [](ll x, ll y) {
    const ll mod = 1e9+7;
    ll res = 1;
    while (y) {
      if (y%2) {
	res *= x;
	res %= mod;
      }
      y=y/2;
      x *= x;
      x %= mod;
    }
    res %= mod; res += mod; res %= mod;
    return res;
  };

  ll ans = pw(2,n/2);
  cout<<ans<<endl;
  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) {}
#endif






int main(){
	ll n;
	cin >> n;
	
	ll sum = 0;
	for ( int i = 1; i <= n; i++ ){
		ll y = n/i; // y: 約数iが何回カウントされるか
		sum += (y*(y+1)/2) * i;
	}
	
	
	
	cout << sum << endl;
	
	
	return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;


int main(){
    ll n,h;
    cin>>n>>h;
    vector<ll> b(n);
    ll a=0;
    for(ll i=0;i<n;i++){
        ll A;
        cin>>A>>b[i];
        a=max(a,A);
    }
    sort(b.begin(),b.end());
    ll ans=0;
    for(ll i=n-1;i>=0 && h>0 && b[i]>a;i--){
        ans++;
        h-=b[i];
    }
    if(h>0) ans+=(h+a-1)/a;
    cout<<ans<<endl;

}

Measured memory_bytes: 4052
#include "iostream"
#include "cstring"
#include "cstdio"
using namespace std;
typedef long long ll;
char s[2];
int main(void)
{
	int n, x, y;
	scanf("%d", &n);
		ll sum = 0;
		for(int i = 1; i <= n; ++ i){
			scanf("%d %s %d", &x, s, &y);
			if(s[0] == '(') sum += y;
			else sum -= y;
			if(sum == 0ll){
				puts("Yes");
			}else{
				puts("No");
			}
		}
	
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

	
int main() {

	ll N, M;
	cin >> N >> M;

	ll x[MAX], y[MAX], z[MAX];

	repn(i, N) cin >> x[i] >> y[i] >> z[i];

	ll ans = -INF;

	rep(i, 8) {
		ll d[3];
		d[0] = i % 2 * 2 - 1;
		d[1] = i / 2 % 2 * 2 - 1;
		d[2] = i / 4 % 2 * 2 - 1;

		ll v[MAX];

		repn(i, N) {
			v[i] = d[0] * x[i] + d[1] * y[i] + d[2] * z[i];
		}

		sort(v + 1, v + 1 + N);

		ll m = 0;
		repn(i, M) m += v[N + 1 - i];

		ans = max(ans, m);

	}

	cout << ans;


	
	
	

	
	system("PAUSE");
}

Measured memory_bytes: 7028
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

vector<int> C, D;

// dijkstra O(ElogV)
// verify : https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
// ※拡張ダイクストラ
template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; T time; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();

    // s から i の最小コスト
    // 経路がない場合は inf
    vector<vector<T>> d; // (頂点,銀貨枚数) ※

    Dijkstra(int V) : V(V) {
        G.resize(V);
    }

    // 辺の追加
    // 有向の場合　directed = true
    void add_edge(int from, int to, T cost, T time, bool directed = false) {
        G[from].push_back({to,cost,time});
        if (!directed) G[to].push_back({from,cost,time});
    }

    // gin 持ち銀貨
    void build(int s, int gin) {
        d.assign(V, vector<T>(2501, inf)); // ※
        typedef tuple<T, int, int> P; //(距離,頂点,銀貨枚数) ※
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s][gin] = 0; // ※
        pq.push(P(d[s][gin], s, gin)); // ※
        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = get<1>(p);
            int moti = get<2>(p);
            // ※
            if (d[v][moti] < get<0>(p)) continue; // ※
            //cout << v << " " << moti << " " << d[v][moti] << endl;
            if (d[v][moti] == inf) cout << v << " " << moti << endl;
            if (d[v][min(2500, moti + C[v])] > d[v][moti] + D[v]) {
                d[v][min(2500, moti + C[v])] = d[v][moti] + D[v];
                pq.push(P(d[v][min(2500, moti + C[v])], v, min(2500, moti + C[v])));
            }
            for (const edge &e : G[v])
            {
                // ※
                if (moti - e.cost >= 0 && d[e.to][moti - e.cost] > d[v][moti] + e.time) {
                    d[e.to][moti - e.cost] = d[v][moti] + e.time;
                    pq.push(P(d[e.to][moti - e.cost], e.to, moti - e.cost));
                }
            }
        }
    }
};

int main() {
    int n, m, s; cin >> n >> m >> s;
    s = min(s, 2500);
    Dijkstra<ll> g(n);
    for (int i = 0; i < m; i++) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--; v--;
        g.add_edge(u, v, a, b);
    }
    C.resize(n);
    D.resize(n);
    for (int i = 0; i < n; i++) {
        int c, d; cin >> c >> d;
        C[i] = c;
        D[i] = d;
    }
    g.build(0, s);
    constexpr long long LLINF = 1e18 + 1;
    for (int i = 1; i < n; i++) {
        ll ans = g.inf;
        for (int j = 0; j <= 2500; j++) {
            ans = min(ans, g.d[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)



int main(){
	LL N,P; cin >> N >> P;
	LL ans = 1;
	if(N == 1) return cout << P << endl, 0;
	vector<LL> prime(1e6+5,0);
	for(LL i = 2 ; i * i <= P ; ++i){
		if(prime[i]) continue;
		LL m = 0;
		while(P%i == 0){
			P /= i;
			++m;
		}
		m = m/N;
		repp(k,0,m) ans *= i;
		for(LL k = i*i ; k < 1e6+5 ; k += i) prime[k] = 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8064
from collections import defaultdict


def main():
    N = int(input())
    d = defaultdict(int)
    s = 0
    for i in range(N):
        d["".join(sorted(input()))] += 1

    for k in d.keys():
        s += d[k]*(d[k]-1)/2

    print(int(s))


if __name__ == '__main__':
    main()

Measured memory_bytes: 18236
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', (chunk) => {
    const input = chunk.split(' ').map(el => Number(el));
    
    const rectangle = {
        area(arr) { 
            return arr.reduce((a, b) => a * b);
        },
        
        len(arr) {
            return arr.reduce((a, b) => a * 2 + b * 2);
        }
    };
    
    console.log(rectangle.area(input), rectangle.len(input));
});


Measured memory_bytes: 15312
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for (int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i=0;i<n;i++){
        if (v[i] > x) break;
        ans++;
        x -= v[i];
    }
    if (ans == n && x > 0) ans--;
    cout << ans;
}


Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]_){Scanner S=new Scanner(System.in);Stack<Long> s=new Stack<Long>();Long t;for(s.push(S.nextLong());S.hasNext();){t=S.nextLong();if(t>0)s.push(t);else System.out.println(s.pop());}}}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};


struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string str; scan(str);
      std::string str2 = "YAKI";
      bool res = str.size() >= 4;
      for(Int i = 0; i < (Int)str.size() and i < 4; ++i) {
         if( str[i] != str2[i] ) res = false;
      }
      puts(res ? "Yes" : "No");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

vector<long> mult(vector<long> a, vector<long> b) {
    vector<long> c(4, MAX_LONG / 2);
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                c[i * 2 + k] = min(c[i * 2 + k], a[i * 2 + j] + b[j * 2 + k]);
            }
        }
    }
    return c;
}

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

    string s;
    int k;
    cin >> s >> k;
    int n = s.size();

    vector<int> a(1, 1);
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            a.back()++;
        } else {
            a.push_back(1);
        }
    }
    long c = 0;
    for (int x : a) {
        c += x / 2;
    }
    c *= k;
    if (s[0] == s[n - 1]) {
        if (a.size() == 1) {
            cout << (1ll * n * k) / 2;
        } else {
            if (a[0] % 2 == 1 && a.back() % 2 == 1) {
                c += (k - 1);
            }
            cout << c;
        }
    } else {
        cout << c;
    }

    return 0;
}

Measured memory_bytes: 256
// https://abc043.contest.atcoder.jp/tasks/arc059_a
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> vi;

int main() {
	int n;
	cin >> n;
	vi v(n);
	int s = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		s += v[i];
	}
	int m = round(double(s) / double(n));
	s = 0;
	for (int i = 0; i < n; i++) {
		int d = v[i] - m;
		s += d * d;
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool palincheck(string a){
	string b=a;
	reverse(a.begin(),a.end());
	if(b==a){
		return true;
	}
	return false;
}
int main(){
	string s;
	cin>>s;
	int n=s.length();
	if(n%2==0){
		cout<<"NO"<<endl;
	}else{
		string x1=s.substr(0,(n-1)/2);
		string x2=s.substr((n+1)/2,(n-1)/2);
		if(palincheck(s)&&palincheck(x1)&&palincheck(x2)){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> Point;
typedef pair<Point, Point> Line;
const double EPS = 1e-10;

// 内積 |a||b|cosθ
double dot(Point a, Point b){
	// return a.real() * b.real() + a.imag() * b.imag();
	return (conj(a) * b).real();
}
// 外積、符号付面積の２倍　|a||b|sinθ
double cross(Point a, Point b){
	// return a.real() * b.imag() - a.imag() * b.real();
	return (conj(a) * b).imag();
}
// 点の位置関係　2点a,bから見た点cの位置関係
int ccw(Point a, Point b, Point c){
    // COUNTER_CLOCKWISE
    if(cross(b - a, c - a) > EPS) return 1;
    // CLOCKWISE
    if(cross(b - a, c - a) < -EPS) return -1;
    // ONLINE_BACK
    if(dot(b - a, c - a) < -EPS) return 2;
    // ONLINE_FRONT
    if(abs(b - a) + EPS < abs(c - a)) return -2;
    // ON_SEGMENT
    return 0;
}
// 点と直線の距離
double line_to_point_dis(Line l, Point p){
    Point a = l.first, b = l.second, c = p;
    return fabs(cross(c - a, b - a)) / fabs(abs(b - a));
}
// 点と線分の距離
double seg_to_point_dis(Line l, Point p){
    Point a = l.first, b = l.second, c = p;
    if(dot(b - a, c - a) < EPS) return abs(c - a);
    if(dot(a - b, c - b) < EPS) return abs(c - b);
    return line_to_point_dis(l, p);
}
// 線分の交差判定
bool is_cross(Line a, Line b){
    if(ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second) <= 0 && ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second) <= 0){
        return true;
    }
    return false;
}
// 線分と線分の距離
double seg_to_seg_dis(Line a, Line b){
    double res = seg_to_point_dis(a, b.first);
    res = min(res, seg_to_point_dis(a, b.second));
    res = min(res, seg_to_point_dis(b, a.first));
    res = min(res, seg_to_point_dis(b, a.second));
    // 線分aと線分bが交差している場合
    if(is_cross(a, b)) res = 0.0;
    return res;
}

int main(){
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        double x, y;
        Point p[4];
        for(int j = 0; j < 4; j++){
            cin >> x >> y;
            p[j] = {x, y};
        }
        Line s1 = {p[0], p[1]};
        Line s2 = {p[2], p[3]};
        double len = seg_to_seg_dis(s1, s2);
        printf("%.10f\n", len);
    }
}


Measured memory_bytes: 3352
N = int(input())
H_ = list(map(int,input().split()))
def dp_solver(x):#x番の足場に行くための最小コスト
    H = H_
    dp = [0]*len(H)
    dp[1] = abs(H[0]-H[1])
    for i in range(len(H)-2):
        dp[i+2] = min(dp[i]+abs(H[i+2]-H[i]),dp[i+1]+abs(H[i+2]-H[i+1]))
    return dp[x]
    
print(dp_solver(N-1))

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
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) cout << fixed << setprecision(10) << s << endl;

string res;

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

    println(n * n - m);
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int x;
  cin>>x;
  int ans=8;
  for(int i=600;i<=2000;i+=200){
    if(x<i){
      cout<<ans<<endl;
      return 0;
    }
    ans--;
  }

  return 0;
}


Measured memory_bytes: 3632
N = int(input())
nums = list(map(int,input().split()))
tmp = []
for i in range(N):
  tmp.append(nums[i]-(i+1))
tmp.sort()
b = tmp[N//2]
total = 0
for j in range(N):
  total += abs(nums[j] - b - (j+1))
print(total)

Measured memory_bytes: 26708
import sys
from string import ascii_lowercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = read_str()

res = 1
count = [0 for _ in range(26)]
alpha = ascii_lowercase

for i in range(N):
    st = alpha.find(S[i])
    count[st] += 1
    if count[st] > 1:
        res += res // count[st]
    else:
        res *= 2
res -= 1
big = 10**9 + 7
print(res % big)


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

int main()
{
    int a, b, c, d;
    int count[101] = {0};
    int i, ans = 0, judge = 0;
    
    cin >> a >> b >> c >> d;
    
    if(a == c) {
        count[a] = 2;
    } else {
        count[a] = 1;
        count[c] = 1;
    }
    if(b == d) {
        count[b] = -2;
    } else {
        count[b] = -1;
        count[d] = -1;
    }
    
    for(i = 0; i < 101; i++) {
        judge = judge + count[i];
        
        if(judge == 2) {
            ans++;
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool flag[1000000];
int ans[10001];

int main()
{
	int cnt=1;
	for(int i = 2; i < 1000000; ++i)
	{
		if(!flag[i])
		{
			ans[cnt]=ans[cnt-1]+i;
			cnt++;
			if(cnt==10001) break;
			for(int j = i*2; j < 1000000; j+=i)
			{
				flag[j]=true;
			}
		}
	}
	int n;
	while(cin>>n,n) cout<<ans[n]<<endl;
  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;

  ll a[2020],b[2020],c[2020];
  for(int i=0;i<M;i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    c[i]=-c[i];
  }
  ll dp[1010];
  const ll INFA=1LL<<50;

  for(int i=0;i<1010;i++){
    dp[i]=INFA;
  }
  dp[0]=0;

  for(int i=0;i<N-1;i++){
    for(int j=0;j<M;j++){
      if(dp[a[j]]==INFA) continue;
      if(dp[b[j]]>dp[a[j]]+c[j]){
        dp[b[j]]=dp[a[j]]+c[j];
      }
    }
  }
  ll ans=dp[N-1];

  for(int i=0;i<N-1;i++){
    for(int j=0;j<M;j++){
      if(dp[a[j]]==INFA) continue;
      if(dp[b[j]]>dp[a[j]]+c[j]){
        dp[b[j]]=dp[a[j]]+c[j];
      }
    }
  }
  if(dp[N-1]!=ans) cout << "inf" << endl;
  else cout << -ans << endl;
  return 0;
}

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

#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) lp(i, 0, n)
#define rlp(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rlp(i, 0, n)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(c) begin(c), end(c)

typedef long long ll;
typedef unsigned long long ull;

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

template<typename T>
inline bool chmin(T &a, T b){
	if (a <= b) return false;
	a = b; return true;
}

template<typename T>
inline bool chmax(T &a, T b){
	if (a >= b) return false;
	a = b; return true;
}

template<typename T>
inline void unique(T &c){
	sort(all(c));
	c.erase(unique(all(c)), end(c));
}

template<typename T>
inline T sq(T a){
	return a * a;
}

template<typename T>
inline size_t index_of(vector<T> &c, T x){
	return lower_bound(all(c), x) - begin(c);
}

int m, n;
vector<tuple<char, int, int>> v;
vector<int> zx, zy;
char g[160][160];

int main()
{
	cin >> m >> n;
	rep(i, m) rep(j, n){
		char c;
		cin >> c;
		if (c != '.'){
			v.eb(c, i, j);
			lp(k, -1, 2){
				zx.pb(i + k); zy.pb(j + k);
			}
		}
	}
	unique(zx); unique(zy);
	m = zx.size(); n = zy.size();
	memset(g, '.', sizeof(g));
	for (auto &t : v){
		char c; int x, y;
		tie(c, x, y) = t;
		g[index_of(zx, x)][index_of(zy, y)] = c;
	}
	int res = 0;
	rep(k, 26) rep(x, m) rep(y, n){
		if (g[x][y] != '.') continue;
		map<char, vector<pair<int, int>>> cnt;
		rep(dir, 4){
			int xx = x, yy = y;
			while (true){
				xx += dx[dir], yy += dy[dir];
				if (xx < 0 || xx >= m || yy < 0 || yy >= n) break;
				if (g[xx][yy] != '.'){
					cnt[g[xx][yy]].eb(xx, yy);
					break;
				}
			}
		}
		for (auto &t : cnt){
			if (t.second.size() < 2) continue;
			for (auto &p : t.second){
				g[p.first][p.second] = '.';
			}
			res += 2;
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 1260
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, mut b, mut c) = (v[0], v[1], v[2]);
    let k = read::<usize>();
    let mut num = 0;
    while b <= a {
        b *= 2;
        num += 1;
    }
    while c <= b {
        c *= 2;
        num += 1;
    }
    if num <= k {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

void read() {
	int tot=0;
	int f=1;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {tot+=c-'0';c=getchar();}
    if(tot%9==0) printf("Yes");
    else printf("No");
}


int main() {
	read();
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int left = a + b;
        int right = c + d;
        if(left > right) {
            System.out.println("Left");
        } else if (left == right) {
            System.out.println("Balanced");
        } else {
            System.out.println("Right");
        }
    }
}

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

int main(){
    char r,g,b;
    cin >> r >> g >> b;
    int x;

    x= 100 * ( (int) r - '0' ) + 10 * ( (int) g - '0' ) +  ( (int) b - '0' );

    if( x%4 == 0 ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

void solve() {
    int N; cin >> N;
    vector<int64> A(N);
    rep(i, N) cin >> A[i];
    int64 ans = 0;
    for(int d = 62; d >= 0; --d) {
        int64 mask = (1LL << d);
        int64 cnt = 0;
        rep(i, N) if(mask & A[i]) ++cnt;
        mask %= MOD;
        int64 t = mask * cnt % MOD;
        t = t * (N - cnt) % MOD;
        ans += t;
        ans %= MOD;
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std;
int A[200005], c[200005];
int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        memset(c, 0, sizeof(c));
        int ans = 0, m = 0, a, a2, b, b2;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &A[i]);
            m = max(m, A[i]);
        }
        int tmpa = 0, tmpa2 = 0, tmpb = 0, tmpb2 = 0;
        for(int i = 1; i <= n; i += 2)
            c[A[i]]++;
        for(int i = 1; i <= m; i++)
        {
            if(c[i] > tmpa)
            {
                swap(tmpa2, tmpa);
                swap(a, a2);
                tmpa = c[i];
                a = i;
            }
            else if(c[i] > tmpa2)
            {
                tmpa2 = c[i];
                a2 = i;
            }
        }
        memset(c, 0, sizeof(c));
        for(int i = 2; i <= n; i += 2)
            c[A[i]]++;
        for(int i = 1; i <= m; i++)
        {
            if(c[i] > tmpb)
            {
                swap(tmpb2, tmpb);
                swap(b, b2);
                tmpb = c[i];
                b = i;
            }
            else if(c[i] > tmpb2)
            {
                tmpb2 = c[i];
                b2 = i;
            }
        }
        if(a == b)
        {
            ans = n - max(tmpa + tmpb2, tmpb + tmpa2);
        }
        else
            ans = n - tmpa - tmpb;
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 1408