akhauriyash/Code-Regression huggingface dataset:
/*#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

//色々計算する用
vector<ll>C(26),last2(26),T(365),Tans(365),V(365),Vorigin(365);
vector<vector<ll>>S(365,vector<ll>(26)),
                last(365,vector<ll>(26)),
                last_sim(365,vector<ll>(26));
ll D,vmax,dadd_best,steps=0;

//リセット用の関数S
void R26(vector<ll>&A){
    for(int i=0;i<26;++i)A[i]=0;
}

void R365(vector<ll>&A){
    for(int i=0;i<365;++i)A[i]=0;
}

void R365_26(vector<vector<ll>>&A){
    for(int i=0;i<365;++i)for(int j=0;j<26;++j)A[i][j]=0;
}

void greedy(){
    ll dadd,i,j,k,l,i_calc,tbest,score,vbest;
    for(dadd=0;dadd<=26;++dadd){
        //リセット
        R26(last2);
        R365_26(last);

        for(i=0;i<D;++i){
            i_calc=min(i+dadd+1,D);
            for(j=0;j<26;++j){
                //得点の初期化
                if(i==0){
                    V[i]=0;
                }else{
                    V[i]=V[i-1];
                }
                
                //lastの初期化
                if(i==0)R26(last[i]);
                else last[i]=last[i-1];

                last[i][j]=i+1;
                V[i]+=S[i][j];

                for(k=0;k<26;++k)
                    for(l=i;l<i_calc;l++)V[i]-=C[k]*(l+1-last[i][k]);

                if(j==0||V[i]>=vmax){
                    vmax=V[i];
                    tbest=j;
                }
            }
            if(i==0)R26(last[i]);
            else last[i]=last[i-1];
            T[i]=tbest+1;
            last[i][tbest]=i+1;
        }

        //得点の再計算
        score=0;
        R26(last2);

        for(i=0;i<D;++i){
            score+=S[i][T[i]-1];
            last2[T[i]-1]=i+1;
            for(j=0;j<26;j++)score-=C[j]*(i+1-last2[j]);
        }

        if(dadd==0||(dadd!=0 && score>vbest)){
            dadd_best=dadd;
            vbest=score;
            Tans=T;
            last_sim=last;
        }
    }

    vmax=vbest;
    T=Tans;
    last=last_sim;
}

int main(){
    int i,j;
    cin>>D;
    for(i=0;i<26;++i)cin>>C[i];
    for(i=0;i<D;++i)for(j=0;j<26;++j)cin>>S[i][j];

    //初期解の生成    
    greedy();

    for(i=0;i<D;++i)cout<<T[i]<<"\n";
    return 0;
}

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


N = int(input())
alpha = 'zabcdefghijklmnopqrstuvwxy'


def dogname(n, udn=''):
    rem = n % 26
    dn = udn + alpha[rem]
    quo = n // 26 if rem != 0 else (n - 1) // 26
    if quo == 0:
        return dn[::-1]
    else:
        return dogname(quo, dn)


print(dogname(N))


Measured memory_bytes: 9052
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=305;
ll a[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	ll s=0;
	for(int i=3;i<=n;i++){
		s^=a[i];
	}
	ll sum=a[1]+a[2];
	ll ans=0;
	sum-=s;
	if(sum<0){
		printf("-1");
		return 0;
	}
	for(int i=60;i>=0;i--){
		if(s&(1ll<<i)){
			
		}
		else{
			if(sum>=2ll*(1ll<<i)){
				sum-=2ll*(1ll<<i);
				ans+=1ll<<i;
			}
		}
	}
	if(sum>0){
		printf("-1");
		return 0;
	}
	for(int i=60;i>=0;i--){
		if(s&(1ll<<i)){
			if(ans+(1ll<<i)<a[1]){
				ans+=1ll<<i;
			}
		}
	}
	if(ans==0||ans>a[1]){
		printf("-1");
		return 0;
	}
	printf("%lld",a[1]-ans);
}

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

int dfs(int vertex, vector<int>*v, int *dp, bool *visited)
{
    if(dp[vertex] != -1)
        return dp[vertex];
    //visited[vertex] = true;
    for(int i=0; i<v[vertex].size(); i++)
    {
        int des = v[vertex][i];
        //cout<<"VERTEX: "<<vertex<<endl;
        //cout<<des<<endl;
            dp[vertex] = max(dp[vertex], 1 + dfs(des, v, dp, visited));
    }
    if(dp[vertex] == -1)
        dp[vertex] = 0;
    return dp[vertex];
}

int main()
{
    int n, m, src, des;
    cin>>n>>m;
    vector<int>v[n+1];
    for(int i=0; i<m; i++)
    {
        cin>>src>>des;
        v[src].push_back(des);
    }
    bool visited[n+1];
    int dp[n+1];
    for(int i=0; i<=n; i++)
        visited[i] = false, dp[i] = -1;
    for(int i=1; i<=n; i++)
    {
        if(!visited[i])
            dfs(i, v, dp, visited);
    }
    //for(int i=1; i<=n; i++)
    //    cout<<dp[i]<<"  ";
    cout<<*max_element(dp, dp+n+1);
}


Measured memory_bytes: 8960
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[5];
	int a2 = 0;
	int ans = 0;
	for(int i = 0;i < 5;i++){
		cin >> a[i];
		a2 = max((((a[i] - 1) / 10) + 1) * 10 - a[i], a2);
		ans += (((a[i] - 1) / 10) + 1) * 10;
	}
	cout << ans - a2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdint.h>

using namespace std;

int64_t max (int64_t a, int64_t b)
{
  return (a>b)? a : b;
}

int main()
{
  int64_t N, K;
  cin >> N >> K;

  int64_t cnt=0;

  for (int64_t b=K; b <= N; ++b) {
    if (b==0)
      continue;
    cnt += (N+1)/b*(b-K) + max(0,(N+1)%b-K) + ((K==0)?-1:0);
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i).sort
s = 10 ** 10
ans = 0
(a.size-1).times{|e|
    if  s >= ((a[-1]/2).to_i - a[e]).abs
        s = ((a[-1]/2).to_i - a[e]).abs
        ans = a[e]
    end
}
puts "#{a[-1]} #{ans}"


Measured memory_bytes: 10112
#include <cstdio>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, C;
int D[30][30];
int c[500][500];
int num[3];
std::map<int, int> cnt[3];

int main()
{
  scanf( "%d%d", &N, &C );
  rep( i, C ) rep( j, C )
    scanf( "%d", &D[i][j] );
  
  rep( i, N ) rep( j, N )
    scanf( "%d", &c[i][j] ), --c[i][j];

  rep( i, N ) rep( j, N )
  {
    int m = (i+j) % 3;

    ++num[m];
    ++cnt[m][c[i][j]];
  }

  int ans = 1<<30;

  rep( i, C ) rep( j, C ) rep( k, C ) if( i != j && j != k && i != k )
  {
    int sum = 0;

    for( auto it = cnt[0].begin(); it != cnt[0].end(); ++it )
      sum += D[it->first][i]*it->second;
    for( auto it = cnt[1].begin(); it != cnt[1].end(); ++it )
      sum += D[it->first][j]*it->second;
    for( auto it = cnt[2].begin(); it != cnt[2].end(); ++it )
      sum += D[it->first][k]*it->second;

    ans = std::min( ans, sum );
  }

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

  return 0;
}

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

vector <int> from[100010];
int in[100010];
int dp[100010];
queue <int> q;

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int u, v;
		scanf("%d%d", &u, &v);
		from[u].push_back(v);
		in[v]++;
	}
	for (int i = 1; i <= n; i++){
		if (!in[i]) q.push(i);
	}
	int ans = 0;
	while (!q.empty()){
		int u = q.front(); q.pop();
		for (int i = 0; i < from[u].size(); i++){
			int v = from[u][i];
			in[v]--, dp[v] = max(dp[v], dp[u] + 1);
			if (!in[v]) q.push(v);
		}
	}
	for (int i = 1; i <= n; i++){
		ans = max(ans, dp[i]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() 
#define rall(v)(v).rbegin(), (v).rend()
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }

int main() {
    LL N,K;cin >> N >> K;
    vector<LL> P(N);
    rep(i,N){
        LL tmp;cin >> tmp;
        P[i] = tmp -1;
    }
    vector<LL> C(N);
    rep(i,N)cin >> C[i];

    vector<LL> onecy_val(N);
    vector<LL> onecy_ct(N);

    rep(i,N){
        LL tmp = C[P[i]];
        LL now = P[i];
        LL ct = 1;
        while(now != i){
            ct++;
            tmp += C[P[now]];
            now = P[now];
        }
        onecy_val[i] = tmp;
        onecy_ct[i] = ct;        
    }
    LL ans = -100000000000000000;
    rep(i,N){
        LL val = onecy_val[i];
        LL ct = onecy_ct[i];
        LL tmp = 0;
        if(K >= ct){
            if(val > 0){

                tmp += ((K/ct)-1)*val;
                LL now = i;
                ans = max(ans,tmp);
                rep(j,K-((K/ct)-1)*(ct)){
                    tmp += C[P[now]];
                    now = P[now];
                    ans = max(ans,tmp);
                }
            }
            else if(val <= 0){
                LL now = i;
                rep(j,ct){
                    tmp += C[P[now]];
                    now = P[now];
                    ans = max(ans,tmp);
                }
            }
        }
        else{
            LL now = i;
            rep(j,K){
                tmp += C[P[now]];
                now = P[now];
                ans = max(ans,tmp);
            }            
        }
        ans = max(ans,C[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3724
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0

for i in range(0,N,1):
    flag =0
    minj =i
    for j in range(i,N,1):
        if num_list[j] < num_list[minj]:
            minj = j
            flag = 1
    c += flag
    num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c

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


int main()
{

    ll n,x,t,c=0;
    cin>>n>>x>>t;

    if(n%x==0){cout<<(n/x)*t;}
    else {cout<<(n/x+1)*t;}
    return 0;
}


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

int main() {
    //
    int D;
    cin >> D;

    vector<int> vec(D);

    for (int i = 0; i < D; i++) cin >> vec.at(i);

    for (int i = 0; i < D; i++) { cout << 1 << endl; }

    //
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ld long double
ld ans[3005][3005];
ld p[3005];
int main()
{
 int n;
 cin>>n;
 for(int i=0;i<n;i++)cin>>p[i];
 ans[0][0]=1-p[0];
 ans[1][0]=p[0];
 for(int i=2;i<=n;i++)ans[i][0]=0;
    for(int i=1;i<n;i++){ /// index
        for(int j=0;j<=n;j++){ /// no of heads
            if(j<=i+1){
                if(j)
                    ans[j][i]=ans[j][i-1] *(1-p[i])
                                +ans[j-1][i-1]*p[i];
                else
                    ans[j][i]=ans[j][i-1]*(1-p[i]);
            }
            else{
                ans[j][i]=0;
            }
         //  cout<<ans[j][i]<<" ";
        }
        //cout<<endl;
    }

    ld sol=0;
    for(int i=(n+1)/2;i<=n;i++){
    sol+=ans[i][n-1];
    }
    cout<<fixed<<setprecision(12)<<sol<<endl;
}



/*3 10 40 70 20 50 80 30 60 90*/








Measured memory_bytes: 141184
N = input()
K = int(input())

dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0][0] = 1
for i in range(len(N)):
    n = int(N[i])
    for j in range(2):
        for k in range(K + 1):
            for d in range((9 if j == 1 else n) + 1):
                if k + int(d != 0) <= K:
                    dp[i + 1][j | (d < n)][k + int(d != 0)] += dp[i][j][k]

n_self = int(len(N) - N.count("0") == K)
print(dp[-1][-1][-1] + n_self)


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

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}


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

  int n;
  cin >> n;
  int r = n%1000;
  if(r == 0)cout << 0 << endl;
  else cout << 1000 - r << endl;
}

Measured memory_bytes: 3648
# encoding:utf-8
def main():
	n = int(input())
	nums = [list(map(int, input().split())) for _ in range(n)]
	a = [x[0] for x in nums]
	b = [x[1] for x in nums]

	if a == b:
		print(0)
		return 
	min_b = min([x[1] for x in nums if x[0] > x[1]])
	print(sum(a) - min_b)
	return 

if __name__ == '__main__':
	main()

Measured memory_bytes: 8180
#include <bits/stdc++.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int unsigned long long
        //#define __int128 long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
        #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(pair<int,int>a,pair<int,int>b)
        {
            if(a.second==b.second)
            return a.first<b.first;
            return a.second<b.second;
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int n;
            cin>>n;
            int answer=n/500;
            int answer2=(n%500)/5;
            cout<<answer*1000+answer2*5;
            return 0;
        }


Measured memory_bytes: 256
gets;A=$<.map{|l|l.split.map(&:to_i).sort}.sort;(q,*,r),b=A.transpose;t=q-u=b.max;p [(b.min-u)*(q-r),*A.map{|x,y|m=[x,u].min-r;u>y&&u=y;r<y&&r=y;m*t}].min

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

int main()
{
	string abc;
	cin >> abc;
	for(int i = 0; i < abc.length(); i++)
	{
		if (i%2==0 && abc[i] == 'L') {
			cout << "No\n";
			return 0;
		}
		if (i%2==1 && abc[i] == 'R') {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

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

using namespace std;

int main(void)
{
  string s; cin>>s;
  sort(s.begin(),s.end());
  
  if((s[0]==s[1])&&(s[1]==s[2])){puts("No"); return 0;}
  
  if((s[0]+s[2])==(s[1]+s[3])){puts("Yes");}
  else{puts("No");}
  
  return 0;
}

Measured memory_bytes: 256
#[derive(Debug)]
struct BIT<T> {
    table: Vec<T>,
}
impl<T: std::default::Default + Clone + Copy + std::ops::AddAssign> BIT<T> {
    fn new(n: usize) -> BIT<T> {
        BIT {
            table: vec![T::default(); n + 1],
        }
    }
    // 1..i番目の要素までの和を求める
    fn sum(&self, mut i: usize) -> T {
        let mut sum: T = T::default();
        while i != 0 {
            sum += self.table[i];
            i &= i - 1;
        }
        sum
    }

    fn add(&mut self, mut i: usize, x: T) {
        if i == 0 {
            panic!("0 is given to BIT");
        }
        while (i as usize) < self.table.len() {
            self.table[i as usize] += x;
            i += i - (i & (i - 1));
        }
    }
}

fn main() {
    let (n, q): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut bit0 = BIT::<i64>::new(n);
    let mut bit1 = BIT::<i64>::new(n);
    for _ in 0..q {
        let c: usize = read();
        if c == 0 {
            let (l, r, x): (usize, usize, i64) = (read::<usize>(), read::<usize>(), read::<i64>());
            bit0.add(l, -x * (l - 1) as i64);
            bit1.add(l, x);
            bit0.add(r + 1, x * r as i64);
            bit1.add(r + 1, -x);
        } else if c == 1 {
            let (l, r): (usize, usize) = (read::<usize>(), read::<usize>());
            println!(
                "{}",
                (bit0.sum(r) + bit1.sum(r) * r as i64)
                    - (bit0.sum(l - 1) + bit1.sum(l - 1) * (l - 1) as i64)
            );
        } else {
            unreachable!();
        }
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



Measured memory_bytes: 7096
// Problem : B - Comparison
// Contest : AtCoder - AtCoder Beginner Contest 059
// URL : https://atcoder.jp/contests/abc059/tasks/abc059_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string a ,b;
	cin >> a >> b;
	int n1 = a.size(), n2 = b.size();
	if(n1>n2){
	    cout << "GREATER";
	}
	else if(n1<n2){
	    cout << "LESS";
	}
	else{
	    for(int i = 0; i < n1;i++){
	        if(a[i]>b[i]){
	            cout << "GREATER";
	            return 0;
	        }
	        else if(a[i]<b[i]){
	            cout << "LESS";
	            return 0;
	        }
	    }
	    cout << "EQUAL";
	}
	return 0;
}

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

using namespace std;

int dist(int a)
{
	if (a >= 0)
		return a;
	else
		return -a;
}

int main(void)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (dist(a - c) <= d)
	{
		cout << "Yes" << endl;
		return 0;
	}

	if (dist(a - b) <= d && dist(b - c) <= d)
	{
		cout << "Yes" << endl;
		return 0;
	}

	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++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


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

  int n;
  cin >> n;
  map<char, ll> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s[0]] ++;
  }
  ll ans = 0;
  char c[5] = {'M', 'A', 'R', 'C', 'H'};
  rep(i,3) {
    for(int j = i+1; j < 4; j++) {
      for(int k = j+1; k < 5; k++) {
        ans += mp[c[i]] * mp[c[j]] * mp[c[k]];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    
    val a = readInt()
    val s = read()
    println(if(a >=3200) s else "red")
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 31972
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, *data = map(int, readlines())
    d = [int(i) for i in data]
    mi = min(d)
    mx = max(d)
    if mi > n:
        print(5)
        return
    n = (n+mi-1)//mi
    print(n+4)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

from collections import Counter
cntD = Counter(D)
cntT = Counter(T)

for key, value in cntT.items():
    if cntD[key] < value:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 56800
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;

	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int sum = 0;
	vector<int> suffix(n, 0);
	suffix[n - 1] = arr[n - 1] % mod;
	for (int i = n - 2; i >= 0; i--) {
		suffix[i] = (suffix[i + 1] + arr[i]) % mod;
	}
	for (int i = 0; i < n - 1; i++)
		sum = (sum + (suffix[i + 1] * arr[i]) % mod) % mod;
	cout << sum % mod;
	return 0;
}

Measured memory_bytes: 6316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = (int) 1e6 + 10;
const int MOD = (int) 1e9 + 7;

int n;
string s;
bool check(int x) {
	map <string, int> mp;
	for (int i=0; i<=n-x; i++) {
		string now = s.substr(i, x);
		if (mp[now]) {
			if (i+1 - mp[now] >= x) return 1;
		} else mp[now] = i+1;
	}
	return 0;
}

int main(){
	scanf("%d", &n);
	cin >> s;
	int l = 0, r = n/2, best;
	while (l <= r) {
		int m = (l + r) / 2;
		if (check(m)) {
			l = m + 1;
			best = m;
		} else r = m - 1; 
	}
	printf("%d\n", best);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0; i<N; i++)cin >> A.at(i);
  
  vector<int>kisuu(N);
  for(int i=0; i<N; i++){
    if(A.at(i)%2==0)kisuu.at(i)=2;
    else kisuu.at(i)=1;
  }
  
  int kaijo = std::pow(3, N);
  int odd=1;
  for(int i=0; i<N; i++)odd*=kisuu.at(i);
  
  cout << kaijo - odd << endl;
}

Measured memory_bytes: 4048
/*
  AUTHOR:SOURABH
  CREATED:09:02:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,v,i;
    set<ll> b;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        fn(i,n)
        {
            cin>>v;
            b.insert(v);
        }
        if(b.size()==n)
            cout<<"YES\n";
            else
            cout<<"NO\n";

    }
    return 0;
}



























Measured memory_bytes: 9600
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;
// char alphabet[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
void swap(int* a,int* b){
    int temp = *a;
    *a=*b;
    *b=temp;
}
bool check(string s){
	int n=s.size();
	int i=0,j=n-1;
	while(i<j){
		if(s[i]!=s[j])return 0;
		i++;j--;
	}
	return 1;
}
int32_t main(){
 	fastIO;
 	int n;cin>>n;
 	vector<int> a(n);
 	set<int> st;
 	map<int,int> cnt;
 	for(int i=0;i<n;i++){
 		cin>>a[i];
 		st.insert(a[i]);
 		cnt[a[i]]++;
 	}
 	int ans=0;
 	for(auto aa:st){
 		if(cnt[aa]>1){
 			ans+=(cnt[aa]*(cnt[aa]-1))/2;
 		}
 	}
 	for(int i=0;i<n;i++){
 		if(cnt[a[i]]==1)cout<<ans<<endl;
 		else{
 			cout<<ans-(cnt[a[i]]*(cnt[a[i]]-1)/2)+((cnt[a[i]]-1)*(cnt[a[i]]-2))/2<<endl;
 		}
 	}
} 	

Measured memory_bytes: 17024
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <stack>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> da(n);
    for(int i=0;i<n;i++){
        cin >> da[i];
    }
    vector<int> dp(n);
    for(int i=2;i<n;i++){
        if(da[i]==i+1){
            dp[i]=dp[i-2]+1;
        }
        else{
            dp[i]=dp[i-1];
        }
    }
    if(da[0]==1){
        dp[n-1]++;
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
from itertools import accumulate
from fractions import gcd


N = int(input())
A = list(map(int, input().split()))

cum_gcd_l = list(accumulate(A, gcd))
cum_gcd_r = list(accumulate(reversed(A), gcd))[::-1]

ans = 0
for i in range(N):
    if i == 0:
        tmp = cum_gcd_r[1]
    elif i == N-1:
        tmp = cum_gcd_l[-2]
    else:
        tmp = gcd(cum_gcd_l[i-1], cum_gcd_r[i+1])
    ans = max(tmp, ans)

print(ans)



Measured memory_bytes: 16116
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define N_MAX 6002

using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

int N, X;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    cin >> N >> X;
    ll ans = 0;
    for(int i = 0; i <= 2*N; i++){
        if(i < X){
            for(int j = 0; j <= i; j++){
                int r = i-j;
                if(r%2 != 0) continue;
                int cnt = j+r/2;
                ll cb = comb(j+r/2, j);
                ll hcb = comb(N, cnt);
                ans += (cb*hcb)%MOD;
                ans %= MOD;
            }
        }
        else if(i%2 == X%2){
            continue;
        }else{
            int m = 2*max((i-(X-1))/2, 0);
            int rem = i-(m*2);
            // cout << i << ' ' << rem << ' ' << m << endl;
            if(rem < 0){
                if(i%2 == 0){
                    ll cb = comb(N, i/2);
                    ans += cb;
                    ans %= MOD;
                }
            }
            for(int j = 0; j <= rem; j++){
                int r = rem-j;
                if(r%2 == 1 || r < 0) continue;
                int cnt = m+j+r/2;
                if(cnt > N) continue;
                // cout << j << ' ' << cnt << endl;
                ll cb = comb(j+r/2, j);
                ll hcb = comb(N, cnt);
                ans += (cb*hcb)%MOD;
                ans %= MOD;
            }
        }
        // cout << i << "->" << ans << endl;
    }
    cout << ans << endl;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    string s;
    lli n, m;
    string flag = "Yes";

    cin >> n >> m;
    string n_arr[n], m_arr[m];
    for(lli i=0; i<n; i++){
        cin >> s;
        n_arr[i] = s;
    }
    for(lli i=0; i<m; i++){
        cin >> s;
        m_arr[i] = s;
    }
    for(lli i=0; i<m; i++){
        for(lli j=0; j<n; j++){
            if(n_arr[j].find(m_arr[i])>50)
                flag = "No";
        }
    }
    cout << flag << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int i, n;
double sum, avg;
double s[1000];

int main(void){
    while (1){
        scanf("%d", &n);
        if (n == 0) break;
        for (i = 0; i < n; i++){
            scanf("%lf", &s[i]);
            sum += s[i];
        }
        avg = sum / n;
        sum = 0;
        for (i = 0; i < n; i++){
            sum += (s[i] - avg)*(s[i] - avg);
        }
        double sd = sqrt(sum/n);
        printf("%f\n", sd);
        sum = 0;
    }
    return 0;
}

Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		sc.nextLine();

		String[] s = new String[H];
		for(int i=0;i<H;i++) {
			s[i] = sc.nextLine();
		}

		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {

				if(s[i].charAt(j) == '#') {

					if( (i > 0 && s[i-1].charAt(j) == '.') &&
						(i < H-1 && s[i+1].charAt(j) == '.') &&
						(j > 0 && s[i].charAt(j-1) == '.') &&
						(j < W-1 && s[i].charAt(j+1) == '.')) {

						System.out.println("No");
						return;
					}
				}
			}
		}

		System.out.println("Yes");
	}

}


Measured memory_bytes: 23636
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize, 
        A: usize,
        B: usize,
        h: [usize; N],
    }

    let mut max = (h.iter().max().unwrap()+B-1)/B;
    let mut min = 1;
    while min < max {
        let t = (max + min) / 2;
        let times = h.iter()
        .fold(0, |acc, hi| acc + (hi.saturating_sub(t*B)+A-B-1)/(A-B));
        if times <= t {
            max = t;
        } else {
            min = t+1;
        }
    }
    println!("{}", max);
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
main(){
  int n,k,a;
  int node1=0,node2,max;
  int ruiseki[100001]={0};
  while(1){
    cin>>n>>k;
    if(n==0&&k==0)break;
    node2=k;
    for(int i=1;i<=n;i++){
      cin>>a;
      ruiseki[i]=ruiseki[i-1]+a;
      if(i>=k){
	if(i==k){
	  max=ruiseki[node2]-ruiseki[node1];
	}
	else if(max<ruiseki[node2]-ruiseki[node1]){
	  max=ruiseki[node2]-ruiseki[node1];
	}
	node1++;
	node2++;
      }
    }
    cout<<max<<endl;
    node1=0;
  }
}

Measured memory_bytes: 1560
const main = (inputs) => {
  const array = inputs[0].split(' ');
  const A = array[0];
  const B = array[1];
  const M = Number(array[2]);

  const array_A = inputs[1].split(' ');
  const array_B = inputs[2].split(' ');
  var answer = 0;


  const minPrice_A = Math.min.apply(null, array_A);
  const minPrice_B = Math.min.apply(null, array_B);

  for (var i = 3; i < 3 + M; i++) {
    var array_M = inputs[i].split(' ');
    var price = Number(array_A[array_M[0] - 1]) + Number(array_B[array_M[1] - 1]) - Number(array_M[2]);
    if (i === 3 || price < answer) {
      answer = price;
    }
  }
  answer = answer < minPrice_A + minPrice_B ? answer : minPrice_A + minPrice_B;
  console.log(answer);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

Measured memory_bytes: 56184
dic = {}
dic['AC']=0
dic['WA']=0
dic['TLE']=0
dic['RE']=0
for I in range(int(input())):
    s = input()
    dic[s]+=1

print("AC x %d"%(dic['AC']))
print("WA x %d"%(dic['WA']))
print("TLE x %d"%(dic['TLE']))
print("RE x %d"%(dic['RE']))


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
long long i,j,n,m,a,b,c,d,k,x;
int main()
{
  cin>>d>>n;
  if(d==0)cout<<(n==100?101:n);
  else if(d==1)cout<<(n==100?10100:n*100);
  else cout<<(n==100?1010000:n*10000);
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  for (int i = 0; i < m; i++) cin >> l.at(i) >> r.at(i);
  int maxc = 0, minc = n + 1;
  for (int i = 0; i < m; i++) {
    maxc = max(maxc, l.at(i));
    minc = min(minc, r.at(i));
  }
  if (minc >= maxc) cout << minc - maxc + 1<< endl;
  else cout << 0 << endl;
}

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

int main(){
    int N,i;
    cin >> N;
    int x=N;
    vector<int> v(N);
    for(i=0;i<N;i++){
        cin >> v.at(i);
    }
    
    sort(v.begin(),v.end());
    
    for(i=0;i<(N-1);i++){
        if(v.at(i) == v.at(i+1)){
            x--;
        }
    }
    cout << x <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;
template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll H, W;
    cin >> H >> W;
    mat A(H, vec(W)), B(H, vec(W));
    Rep (i, H) {
        Rep (j, W) {
            cin >> A[i][j];
        }
    }
    Rep (i, H) {
        Rep (j, W) {
            cin >> B[i][j];
        }
    }

    mat C(H, vec(W));
    Rep (i, H) {
        Rep (j, W) {
            C[i][j] = abs(A[i][j] - B[i][j]);
        }
    }

    vector<vector<vector<bool>>> grid(H, vector<vector<bool>>(W, vector<bool>(7000, false)));
    grid[0][0][C[0][0]] = 1;

    Rep (i, H) {
        Rep (j, W) {
            Rep (k, 7000) {
                if (grid[i][j][k]) {
                    if (i+1 < H) {
                        if (abs(k+C[i+1][j]) < 7000) grid[i+1][j][abs(k+C[i+1][j])] = true;
                        if (abs(k-C[i+1][j]) < 7000) grid[i+1][j][abs(k-C[i+1][j])] = true;
                    }
                    if (j+1 < W) {
                        if (abs(k+C[i][j+1]) < 7000) grid[i][j+1][abs(k+C[i][j+1])] = true;
                        if (abs(k-C[i][j+1]) < 7000) grid[i][j+1][abs(k-C[i][j+1])] = true;
                    }
                }
            }

            // for (ll e : grid[i][j]) {
            //     ll a = max((ll)1000, 100*(160-i-j));
            //     if (i+1 < H) {
            //         if (abs(e+C[i+1][j]) < a) grid[i+1][j].insert(e+C[i+1][j]);
            //         if (abs(e-C[i+1][j]) < a) grid[i+1][j].insert(e-C[i+1][j]);
            //     }
            //     if (j+1 < W) {
            //         if (abs(e+C[i][j+1]) < a) grid[i][j+1].insert(e+C[i][j+1]);
            //         if (abs(e-C[i][j+1]) < a) grid[i][j+1].insert(e-C[i][j+1]);
            //     }
            // }
        }
    }

    ll ans = inf;
    Rep (i, 7000) {
        if (grid[H-1][W-1][i]) {
            ans = i;
            break;
        }
    }

    cout << ans << "\n";
}

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

#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)

using ll = long long;
#define INF 1e9

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

int N;
vector<int> a;
bool ans = true;
void isE(int a, int b){
  if(!(a == b)){
    ans = false;
  }
}

int main(){
  int w = 3, h = 3;
  vector<vector<int>> c(w, vector<int>(h));
  REP(i, w){
    REP(j, h){
      cin >> c[i][j];
    }
  }

  REP(i, h-1){
    REP(j, w-1){
      isE(c[i][j]-c[i+1][j], c[i][j+1]-c[i+1][j+1]);
      isE(c[i][j]-c[i][j+1], c[i+1][j]-c[i+1][j+1]);
    }
  }
  
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> numBottomost = new ArrayList<Integer>();
		String buf;
		while((buf = br.readLine()) != null){
			int[] array = new int[10];
			char[] n = buf.toCharArray();
			for(int i = 0; i < n.length; i++){
				array[i] = n[i] - '0';
			}
			numBottomost.add(getNumBottommost(array));
		}
		
		for(int n : numBottomost){
			System.out.println(n);
		}
	}
	private static int getNumInTheOnePlace(int x, int y){
		int sum = x + y;
		return sum % 10;
	}
	private static int[] getNextArray(int[] array){
		int[] n = new int[array.length - 1];
		for(int i = 0; i + 1 < array.length; i++){
			n[i] = getNumInTheOnePlace(array[i], array[i + 1]);
		}
		return n;
	}
	public static int getNumBottommost(int[] array){
		int length = array.length;
		int[] n = array;
		while(length != 1){
			n = getNextArray(n);
			length = n.length;
		}
		return n[0];
	}
}

Measured memory_bytes: 9364
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n,k;
vector<int> A(1000000,0);

int main(){
    cin>>n>>k;
    rep(i,0,n){
        int a;cin>>a;
        A[a-1]++;
    }
    sort(A.begin(),A.end(),greater<int>());
    
    int ans=0;
    rep(i,k,n){
        ans+=A[i];
    }

    cout<<ans<<endl;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int L = a+b;
    int R = c+d;

    if(L > R){
        cout << "Left" << endl;
    }else if(L < R){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
    return 0;
}

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

#define ll long long

const int maxn = 350;

int n,k;
string str;

int main(){
    cin>>n>>k;
    cin>>str;
    str[k-1]=tolower(str[k-1]);
    cout<<str<<endl;
}


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

using namespace std;

int wt[100001], v[100001];
long long dp[101][100001];

const int INF = 1e9 + 7;

int solve(int V, int n)
{
	if (V == 0)
		return 0;
	if (n == 0)
		return INF;
	if (dp[n][V] != -1)
		return dp[n][V];
	if (V < v[n - 1])
		return dp[n][V] = solve(V, n - 1);
	else
		return dp[n][V] = min(wt[n - 1] + solve(V - v[n - 1], n - 1), solve(V, n - 1));
}

int main()
{
	int n, V, W;
	cin >> n >> W;
	for (int i = 0; i < n; i++)
		cin >> wt[i] >> v[i];
	V = 0;
	for (int i = 0; i < n; i++)
		V += v[i];
	memset(dp, -1, sizeof(dp));
	int ans = 0;
	for (int i = V; i >= 0; i--)
	{
		if (solve(i, n) <= W)
		{
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p, m, y;
string s, t;
ld w;
ll a, b;

ll c[11][11];

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> m;
	for(ll i=0;i<10;i++) {
		for(ll j=0;j<10;j++) {
			cin >> c[i][j];
		}
	}

	vll cnt(10);
	vll dist(10,INF);
	vll vis(10,0);
	ll ans = 0;

	dist[1] = 0;

	for(ll i=0;i<n;i++) {
		for(ll j=0;j<m;j++) {
			cin >> x;
			if(x!=-1) {
				cnt[x]++;
			}
		}
	}

	n = 10;
	while(n--) {
		ll val,mini = INT_MAX;
		for(ll i=0;i<10;i++) {
			if(vis[i]==0 && dist[i]<mini) {
				val = i;
				mini = dist[i];
			}
		}

		vis[val] = 1;
		//cout<<val<<" ";
		for(ll i=0;i<10;i++) {
			if(vis[i]==0) {
				dist[i] = min(dist[i],c[i][val] + dist[val]);
			}
		}
	}	
	//DISP(dist);
	for(ll i=0;i<10;i++) {
		ans += cnt[i]*dist[i];
	}

	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

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

typedef unsigned long long ull;

ull len[51];
ull p_num_list[51];

ull calc_len(int n){
    if(n==0){
        len[n] = 1;
        return 1;
    }
    else{
        ull l = calc_len(n-1)*2+3;
        len[n] = l;
        return l;
    }
}

ull calc_p_num(int n){
    if(n==0){
        p_num_list[n] = 1;
        return 1;
    }
    else{
        ull l = calc_p_num(n-1)*2+1;
        p_num_list[n] = l;
        return l;
    }
}


ull func(int n, ull x){
    if(n==1){
        if(x==1)
          return 0;
        else if(x <= 4)
          return x-1;
        else
          return 3;
    }

    if(x <= 1){
        return 0;
    }
    else{
        x--;
        ull res = 0;
        if(x <=len[n-1]){
            //cout << n << ", " << x << " : test1" << endl;
            return func(n-1, x);
        }
        else if(x == len[n-1]+1){
            //cout << n << ", " << x << " : test2" << endl;
            return p_num_list[n-1] + 1;
        }
        else{
            x = x - len[n-1]-1;
            //cout << n << ", " << x << " : test3" << endl;
            return func(n-1, min(x, len[n-1])) + 1 + p_num_list[n-1];
        }
    }
}


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

    calc_len(50);
    for(int i=0;i<=50;i++){
        //cout << len[i] << endl;
    }

    calc_p_num(50);
    for(int i=0;i<=50;i++){
        //cout << p_num_list[i] << endl;
    }

    ull ans = func(N, X);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256