akhauriyash/Code-Regression huggingface dataset:
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define debug(args...){ string _s = #args;replace(_s.begin(),_s.end(),',', ' ');stringstream _ss(_s);istream_iterator<string>_it(_ss);err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}

#define ll              long long int
#define MAX             2134567891
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define rev(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define TC(t)           printf("Case %lld: ",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb              push_back
#define eb              emplace_back
#define ff              first
#define ss              second
#define NL              printf("\n");
#define bug(a)          cout<<#a<<" "<<a<<" ";
#define hlw             printf("hlw\n");
#define NN              111
#define MOD             1000000007///10^9
#define N               1000007 ///10^6->6 zero after 1 **



ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
bitset<N>B;
map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc=1,in,loc,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
//cin>>tc;
rep(t,tc)
{
    cin>>n;
    fr(i,n)
    {
        cin>>x[i];
        mp[x[i]]=i;
    }
    sort(x,x+n);
    fr(i,n)
    {
        loc=mp[x[i]];
        if(abs(loc-i)%2==1)ans++;
    }
    if(ans & 1)ans++;
    cout<<ans/2<<endl;
}
}
    return 0;
}

/*


*/
/// Check for constraint 0 or 1?
/// Division MOD needs BigMod(a,n-2)
/// long long or double? sqrt or division will work fine??
/// sort(begin(v), end(v), [] (int a, int b) { return a > b; });    /// Lambda Function for manual Sort


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


int main(){
    double n;
    long A;
    map<long, long> counter;
    vector<long> a_ls;
    cin >> n;
    vector<vector<vector<double>>> memo_ls(n+2, vector<vector<double >>(n+2, vector<double >(n+2, 0)));
    a_ls.resize(n);
    for(int i=0; i<3; i++){
        counter[i] = 0;
    }
    for(int i=0; i<n; i++){
        cin >> a_ls[i];
        counter[a_ls[i]]++;
    }
    long c_1 = counter[1];
    long c_2 = counter[2];
    long c_3 = counter[3];
    A = *max_element(a_ls.begin(), a_ls.end());
    for(long k=0; k<n+1; k++){
        for(long j=0; j<n+1; j++){
            for(long i=0; i<n+1; i++){
                if (i == 0 and j == 0 and k == 0){
                    continue;
                }
                memo_ls[i][j][k] = ((i / n) * memo_ls[max((long)0, i-1)][j][k] + (j / n) * memo_ls[i+1][max((long)0, j-1)][k] + \
                (k / n) * memo_ls[i][j + 1][max((long)0, k - 1)] + 1.0) * (n / (i + j + k));
                if(i == c_1 and j == c_2 and k == c_3){
                    break;
                }
            }
        }
    }
    cout << setprecision(15) << memo_ls[c_1][c_2][c_3] << endl;
}


Measured memory_bytes: 219904
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>


using namespace std;


static const int MAX = 100000;

vector<int> graph[MAX];
vector<bool> discovered(MAX, false);
vector<int> prenum(MAX, 0), parent(MAX, 0), lowest(MAX, 0);
int V, E;
int t = 0;


void dfs(int vertex, int prev)
{
    prenum[vertex] = lowest[vertex] = ++t;
    discovered[vertex] = true;

    for (auto it = graph[vertex].begin(); it != graph[vertex].end(); ++it) {
        if (!discovered[*it]) {
            parent[*it] = vertex;
            dfs(*it, vertex);
            lowest[vertex] = min(lowest[vertex], lowest[*it]);
        } else if (*it != prev) {
            lowest[vertex] = min(lowest[vertex], prenum[*it]);
        }
    }
}


set<int> arts;
void art_points()
{
    dfs(0, -1);

    int num_root_children = 0;
    for (int i = 1; i < V; i++) {
        int p = parent[i];
        if (p == 0)
            num_root_children++;
        else if (prenum[p] <= lowest[i]) {
            arts.insert(p);
        }
    }

    if (num_root_children > 1) {
        arts.insert(0);
    }

    for (auto it = arts.begin(); it != arts.end(); ++it)
        cout << *it << endl;
}


int main()
{
    cin >> V >> E;

    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    art_points();

    return 0;
}



Measured memory_bytes: 7492
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int n,ans=0;
	cin>>n;
	vector<string>s(10000000);
	vector<long long int>a(5);
	for(int i=0;i<n;i++){
		cin>>s[i];
		if(s[i][0]=='M'){
			a[0]++;
		}
		else if(s[i][0]=='A'){
			a[1]++;
		}
		else if(s[i][0]=='R'){
			a[2]++;
		}
		else if(s[i][0]=='C'){
			a[3]++;
		}
		else if(s[i][0]=='H'){
			a[4]++;
		}
	}
	ans=a[0]*a[1]*a[2]+a[0]*a[1]*a[3]+a[0]*a[1]*a[4]+a[0]*a[2]*a[3]+a[0]*a[2]*a[4]+a[0]*a[3]*a[4]+a[1]*a[2]*a[3]+a[1]*a[2]*a[4]+a[1]*a[3]*a[4]+a[2]*a[3]*a[4];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 83584
fun main(args : Array<String>) {
    val (n, p) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toInt() }
    val ae = aa.count { it % 2 == 0 }
    val ao = aa.count { it % 2 == 1 }

    val eSum = Math.pow(2.0, ae.toDouble()).toLong()

    var ans = 0L
    if (p == 0) {
        for (i in 0..ao step 2) {
            ans += eSum * comb(ao, i)
        }
    } else {
        for (i in 1..ao step 2) {
            ans += eSum * comb(ao, i)
        }
    }

    println(ans)
}

fun comb(n: Int, k: Int): Long {
    if (n == 0 || k == 0) return 1L
    if (k > n / 2) return comb(n, n-k)
    val fact = (2..k).fold(1L) { acc, i -> acc * i }
    return perm(n, k) / fact
}

fun perm(n: Int, k: Int): Long {
    require(n > 0 && k >= 0)
    return (n - k + 1 .. n).fold(1L) { acc, i -> acc * i }
}

Measured memory_bytes: 37868
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define INF (1<<24)
#define MAX_N 50
struct state{
  int pi,pj,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;  
  }
};

int n;
int d[MAX_N][4];
int t[MAX_N],u[MAX_N];

void solve(){
  for(int i=0;i<MAX_N;i++)
    for(int j=0;j<4;j++)d[i][j]=INF;
  d[0][0]=0;
  priority_queue<state> Q;
  Q.push((state){0,0,0});

  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[s.pi][s.pj])continue;
    if(s.pi==n+1){cout<<"OK "<<s.cost<<endl;return;}
   
    int k=s.pj+1;

    int di=abs(t[s.pi]-t[s.pi+1]);
    
    if(s.pj<3){
      int td=di*k;
      if(d[s.pi+1][s.pj+1]>s.cost+di){
	if(td<=u[s.pi+1]-u[s.pi]){
	  d[s.pi+1][s.pj+1]=s.cost+di;
	  Q.push((state){s.pi+1,s.pj+1,s.cost+di});
	}
      }
    }
    

    int td=t[s.pi]*k;
    for(int i=1;i<=s.pj;i++){
      int nk=k-i;
      int td2=t[s.pi+1]*nk;
      if(td+td2>u[s.pi+1]-u[s.pi])continue;
      if(s.cost+t[s.pi]+t[s.pi+1]<d[s.pi+1][nk]){
	d[s.pi+1][nk]=t[s.pi]+t[s.pi+1]+s.cost;
	Q.push((state){s.pi+1,nk,d[s.pi+1][nk]});
      }
    }
  }
 
  for(int i=0;i<=n;i++){
    bool flg=false;
    for(int j=0;j<4;j++)
      if(d[i][j]!=INF)flg=true;
    if(!flg){
      cout<<"NG "<<i<<endl;return;
    }
  }
 
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=n;i++)cin>>t[i]>>u[i];
    t[n+1]=0;
    u[n+1]=INF;
    solve();
  }
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
#define testcases ll t; cin>>t; while(t--)

using namespace std;

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

    int n;
    cin>>n;
    vector<ld> p(n+1);
    for(int i=1;i<=n;i++) cin>>p[i];

    vector<vector<ld>> dp(n+1,vector<ld>(n+1,0.0));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++) dp[i][0]=dp[i-1][0]*(1-p[i]);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            dp[i][j]=p[i]*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];
          //  cout<<dp[i][j]<<" ";
        }
        //cout<<"\n";
    }
    ld sum=0;

    for(int i=n;i>n/2;i--) sum+=dp[n][i];
    cout<<setprecision(10)<<fixed<<sum;
    return 0;
}



Measured memory_bytes: 141056
#import <iostream>
using namespace std;
int main(){
	long long  N,M,reverse;
	cin>>N>>M;
	//四隅のカードは絶対最後は表(例え一列でも)
	//N>=2,M>=2の時辺に位置する場合それは表
	//どっちかが1なら裏
	//全方位にカードあれば裏
	if(N>=3 && M>=3){
		reverse=(N-2)*(M-2);
	}else if(N==2 || M==2){
		reverse=0;
	}else{
		if(N>M)reverse=N-2;
		else if(M>N)reverse=M-2;
		else reverse=1;
	}
	cout<<reverse<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

//?????????????????¨??????
//left-child right-sibling representation
struct node{
    int parent;
    int left;
    int right;
};

node T[MAX];
int depth[MAX];
int n;

void print(int u){
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].parent<<", ";
    cout<<"depth = "<<depth[u]<<", ";

    if(T[u].parent == NIL)
        cout<<"root, ";
    else if(T[u].left == NIL)
        cout<<"leaf, ";
    else
        cout<<"internal node, ";

    cout<<"[";

    for(int i=0,c=T[u].left;c!=NIL;i++,c=T[c].right){
        if(i)
            cout<<", ";
        cout<<c;
    }
    cout<<"]"<<endl;
}

// ????????°?±???±???
void rec(int u,int p){
    depth[u]=p;
    //?????§???????????????????????±???
    if(T[u].right!=NIL)
        rec(T[u].right,p);
    //????????§??????????????±?????????????????±?????±???+1
    if(T[u].left!=NIL)
        rec(T[u].left,p+1);
}

int main(){
    int d;
    int v;
    int c;
    int l;
    int r;
    cin>>n;
    for(int i=0;i<n;i++)
        T[i].parent=T[i].left=T[i].right=NIL;
    for(int i=0;i<n;i++){
        cin>>v>>d;
        for(int j=0;j<d;j++){
            cin>>c;
            if(j==0)
                T[v].left=c;
            else
                T[l].right=c;
            l=c;
            T[c].parent=v;
        }
    }
    for(int i=0;i<n;i++)
        if(T[i].parent==NIL)
            r=i;
    rec(r,0);
    for(int i=0;i<n;i++)
        print(i);
}

Measured memory_bytes: 7780
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
int main(){
    char c;
    cin >> c;
    if(c=='A')cout << "T"<< endl;
    if(c=='T')cout << "A"<< endl;
    if(c=='C')cout << "G"<< endl;
    if(c=='G')cout << "C"<< endl;

    return 0;
}

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

int main() {
  float Ans = 0;  // 回答：
  int R; cin >> R;  // 半径

//  cout << Ans << setprecision(7);	// 計算前に桁数指定
//  Ans = R * 2 * 3.1415926;
  Ans = R * 2 * 314159;
  Ans /= 100000;
  cout << Ans << endl;
}


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

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


	int R;
	cin>>R;

	double cir = 2 * 3.14159265 * R;

	cout<<cir<<endl;

	return 0;
}

Measured memory_bytes: 3804
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		
		System.out.println(Main.abbrev(str));
		sc.close();
	}

	static String abbrev(String s) {
		// Ascii code for blank is 32
		StringBuilder sb = new StringBuilder();
		int len = s.length();
		sb.append(s.charAt(0));
		
		for (int i = 1; i < len; i++) {
			if ( s.charAt(i) == ' ' )
				sb.append(s.charAt(++i));
		}
		return sb.toString();
	}
}


Measured memory_bytes: 10064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class107
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            int[] L = new int[M];
            int[] R = new int[M];
            int min = int.MinValue;
            int max = int.MaxValue;
            for(int i = 0; i < M; i++)
            {
                var r = Console.ReadLine().Split().Select(int.Parse).ToArray() ;
                min = Math.Max(min, r[0]);
                max = Math.Min(max, r[1]);
            }
            int ans = max - min + 1;
            if (ans < 0) ans = 0;
            Console.WriteLine(Math.Min(N,ans));
        }
    }
}


Measured memory_bytes: 17432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string S;
  cin >> S;
  if (S[0] == S[1] && S[0] == S[2]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 2e9;
int N, K;
ll Point[30];
typedef pair<int, ll> P;
vector<P> D[30];

int main() {
  INCANT;
  cin >> N >> K;
  int l2 = log2(K);
  vector<int> kouho;
  kouho.push_back(K);
  for (int i=l2; i>=0; i--) {
    if (1<<i & K) {
      int k = K ^ (1 << i);
      k |= (1 << i)-1;
      kouho.push_back(k);
    }
  } 
  int a,b;
  vector<P> X(N);
  rep(i, N) {
    cin >> a >> b;
    X[i] = P(a,b);
  }
  ll ans = 0ll;
  for(auto k: kouho) {
    ll sm = 0ll;
    for (auto x: X) {
      if ((k | x.first)==k) sm+=x.second;
    }
    ans = max(ans, sm);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4936
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int main(){

int r=0,c=0;
int matrix[120][120]={};
cin >> r >> c;

for(int i=0;i<r;i++){
  for(int j=0;j<c;j++){
    cin >> matrix[i][j];                   //??????????´?
  }
}

for(int i=0;i<r;i++){
  for(int j=0;j<c;j++){
      matrix[i][c]+= matrix[i][j];                     //???????????????????????????????´?
      matrix[r][j]+= matrix[i][j];                     //???????????????????????????????´?
  }
}

for(int i=0;i<r;i++){
  matrix[r][c] +=matrix[i][c];                         //?????¨????????????????´???????????????????????????????????????????????´?
}

for(int i=0;i<r+1;i++){
  for(int j=0;j<c+1;j++){
    if(j==0){
        cout << matrix[i][j];                        //?????????????????????????????¨???
      }
      else{
        cout << ' ' << matrix[i][j];                //????????\??????????????¨???
      }
    }
    cout << endl;
}
return 0;
}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

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

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    ll sm = 0;
    rep(i,n)cin >> a[i];
    rep(i,n)sm+=a[i];
    bool f = 1;
    if((sm-n)%2==1){
        cout << "First" << endl;
        return 0;
    }else{
        while(1){
        int cnt= 0;
        int k;
        rep(i,n){
            if(a[i]%2==1){
                cnt++;
                k = i;
            }
        }
        if(cnt!=1||a[k]==1){
            if(f)cout << "Second" << endl;
            else cout << "First" << endl;
            return 0;
        }
        a[k]--;
        int s = a[0];
        rep(i,n-1)s = gcd(s,a[i+1]);
        rep(i,n){
            a[i]/=s;
        }
        sm = 0;
        rep(i,n)sm+=a[i];
        if((sm-n)%2==1){
            if(f)cout << "Second" << endl;
            else cout << "First" << endl;
            return 0;
        }
        f = !f;
        }
    }  
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
  int m,f,b;
  scanf("%d %d %d",&m,&f,&b);
  if(m>=b) printf("0\n");
  else{
    if(f>=b-m) printf("%d\n",b-m);
    else printf("NA\n");
  }
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,t;
	cin>>n;
	n--;
	vector<int>c(n),st(n),fr(n);
	rep(i,n)cin>>c[i]>>st[i]>>fr[i];
	rep(i,n){//for each start
	    t=0;
	    for(int j=i;j<n;j++){
	        if(t<=st[j])t=st[j];
	        else t=fr[j]*((t-1)/fr[j]+1);
	        t+=c[j];
	    }
	    cout<<t<<endl;
	}
	cout<<0<<endl;
	return 0;
}


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

int     main() {
	string S, T;
	cin >>S >>T;
	int N=S.size();
	for (int i=0; i<N; i++) {
		int j;
		for (j=0; j<N; j++) {
			if (S.at((i+j)%N)!=T.at(j)) break;
		}
		if (j==N) {
			cout <<"Yes" <<endl;
			return 0;
		}
	}
	cout <<"No" <<endl;
	return 0;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int H,W,INF=1e9;
char s[1005];
int t[1005][1005];
int dp[2][1005][16];

int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++){
    scanf("%s",s);
    for(int j=0;j<W;j++){
      if(s[j]!='.')t[i+1][j+1]=s[j]-'0';
    }
  }
  int ans=INF;
  fill((int*)dp,(int*)dp[2],INF);
  dp[1][1][0]=0;
  for(int i=1;i<=H;i++){
    int ai=i%2,bi=1-ai;
    for(int j=1;j<=W;j++){
      for(int bit=0;bit<(1<<4);bit++){
        if(dp[ai][j][bit]==INF)continue;
        int cost=dp[ai][j][bit];
        int a=bit>>0&1,b=bit>>1&1,c=bit>>2&1,d=bit>>3&1;
        int nbit,ncost;
        
        nbit=b+2*0+4*1+8*1;
        ncost=cost+t[i][j]+t[i+1][j]+t[i][j-1]*(1-c);
        dp[ai][j+1][nbit]=min(dp[ai][j+1][nbit],ncost);
        
        nbit=1*b+2*0+4*1+8*0;
        ncost=cost+t[i][j]+t[i-1][j]*(1-a)+t[i][j-1]*(1-c);
        dp[ai][j+1][nbit]=min(dp[ai][j+1][nbit],ncost);
        
        nbit=1*b+2*0+4*1+8*1;
        ncost=cost+t[i][j]+t[i-1][j]*(1-a)+t[i+1][j];
        dp[ai][j+1][nbit]=min(dp[ai][j+1][nbit],ncost);
        
        nbit=1+2*1+4*d+8*0;
        ncost=cost+t[i][j]+t[i][j+1]+t[i][j-1]*(1-c);
        dp[bi][j][nbit]=min(dp[bi][j][nbit],ncost);
        
        nbit=1+2*0+4*d+8*0;
        ncost=cost+t[i][j]+t[i-1][j]*(1-a)+t[i][j-1]*(1-c);
        dp[bi][j][nbit]=min(dp[bi][j][nbit],ncost);

        nbit=1+2*1+4*d+8*0;
        ncost=cost+t[i][j]+t[i-1][j]*(1-a)+t[i][j+1];
        dp[bi][j][nbit]=min(dp[bi][j][nbit],ncost);

        if(i==H&&j==W)ans=min(ans,ncost);
      }
    }
    fill((int*)dp[ai],(int*)dp[ai+1],INF);
  }
  
  printf("%d\n",ans);
  return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N, K;
ll ans;
vector<ll> mi,pl;

int main() {
    cin>>N>>K;
    ll a;
    REP(i,0,N) {
        cin>>a;
        if(a<0) mi.push_back(-a);
        else pl.push_back(a);
    }
    ans = inf;
    reverse(ALL(mi));
    if(mi.size()>=K) ans=min(ans,mi[K-1]);
    if(pl.size()>=K) ans=min(ans,pl[K-1]);
    REP(i,0,mi.size()){
        if(K-i-2>=0&&K-i-2<pl.size()) {
            ans = min(ans, mi[i]+pl[K-i-2]+min<ll>(mi[i],pl[K-i-2]));
        }
    }
    p(ans);
    return 0;
}

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

#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl

typedef long long ll;

using namespace std;

void solve() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    vector<vector<int>> D(M);

    REP(i, A) cin >> a[i];
    REP(i, B) cin >> b[i];
    REP(i, M) {
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        D[i].push_back(x);
        D[i].push_back(y);
        D[i].push_back(c);
    }

    int mina = 1001001001;
    for (int i = 0; i < A; i++) {
        mina = min(mina, a[i]);
    }
    int minb = 1001001001;
    for (int i = 0; i < B; i++) {
        minb = min(minb, b[i]);
    }

    int ans = mina + minb;

    for (int i = 0; i < M; i++) {
        int x = D[i][0];
        int y = D[i][1];
        int c = D[i][2];
        ans = min(a[x] + b[y] - c, ans);
    }

    print(ans);
}

signed main() {
    solve();
}


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

int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    arr.push_back(0);
    for(int i=0;i<n-1;i++)
    {
        int x ;cin>>x;arr.push_back(x);
    }
    vector<int> ans(n,0);
    map<int,int> mp;
    for(int i=0;i<n;i++){
       
        int x = arr[i];
        if(x==0)
        continue;
        
        ans[x-1]++;
    }
    
    for(int i=0;i<ans.size();i++)
    {
    cout<<ans[i]<<endl;    
    }
}

Measured memory_bytes: 4844
#include<stdio.h>

int equal(const char str1[], const char str2[]){
	int i;
	for(i = 0;str1[i] == str2[i];i++)
		if(str1[i] == '\0') 
            return 1;
		return 0;
}

int main(void){
	int i,j;
	int N,M;
	int cnt = 0;
	
	
	char blue[100][11];
	char red[100][11];
	
	scanf("%d", &N);
	
	for(i = 0;i < N;i++){
		scanf("%s", blue[i]);
	}
	
	scanf("%d", &M);
	
	for(i = 0;i < M;i++){
		scanf("%s", red[i]);
	}
	
	for(i = 0;i < N;i++){
		int index = 0;
		for(j = i;j < N;j++){
			if(equal(blue[i] , blue[j]))
				index++;
		}
		
		for(j = 0;j < M;j++){
			if(equal(blue[i] , red[j]))
				index--;
		}
		
		if(cnt < index)
			cnt = index;
	}
	
	printf("%d", cnt);
	
	return 0;

}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		String S = in.nextLine();
		int l = S.length();
		while(true){
			S = S.substring(0, l -2);
			l = l-2;
			//System.out.println(S.substring(0,l/2));
			//System.out.println(S.substring(l/2,l));
			if(S.substring(0,l/2).equals(S.substring(l/2,l))){
				System.out.println(l);
				break;
			}
		}
		
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <map>

using namespace std;

using ll = long long;

int N;
vector<ll> a;

void solve() {
    map<ll, ll> ma;
    for (int i = 0; i < N; ++i) ma[a[i]]++;
    ll res = 0;
    for (auto it : ma) res += it.second * (it.second - 1) / 2;
    for (int i = 0; i < N; ++i) {
        ll val = ma[a[i]];
        ll before = val * (val - 1) / 2;
        ll after = (val - 1) * (val - 2) / 2;
        cout << res + after - before << endl;
    }
}

int main()
{
    cin >> N;
    a.resize(N);

    for (int i = 0; i < N; ++i) cin >> a[i];
    solve();
}

Measured memory_bytes: 11008
N = input()
Y = int(N)

a = Y%10

if a==3:
    print("bon")

elif a==0:
    print("pon")

elif a==1:
    print("pon")

elif a==6:
    print("pon")

elif a==8:
    print("pon")

elif a==2:
    print("hon")

elif a==4:
    print("hon")

elif a==5:
    print("hon")

elif a==7:
    print("hon")

else:
    print("hon")


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

typedef struct node{
  int p;
  int left;
  int right;
}Node;


int main()
{
  int n,i,j,id,k,c,r,depth;
  Node *tree;

  scanf("%d",&n);

  tree = (Node *)malloc(sizeof(Node)*n);

  for(i = 0; i < n; i++){
    tree[i].p = -1;
    tree[i].left = -1;
    tree[i].right = -1;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d",&id,&k);

    for(j = 0; j < k; j++){
      scanf("%d",&c);
      tree[c].p = id;

      if(j == 0){
	tree[id].left = c;
      }
      else if(j > 0){
	tree[r].right = c;
      }
      r = c;
    }
  }

  for(j = 0; j < n; j++){
    depth = 0;
    i = tree[j].p;

    while(i != -1){
      i = tree[i].p;
      depth++;
    }

    if(depth == 0){
      printf("node %d: parent = %d, depth = %d, root, ",j,tree[j].p,depth);
    }
    else if(tree[j].left == -1){
      printf("node %d: parent = %d, depth = %d, leaf, ",j,tree[j].p,depth);
    }
    else {
      printf("node %d: parent = %d, depth = %d, internal node, ",j,tree[j].p,depth);
    }

    i = tree[j].left;
    printf("[");
    if(i != -1){
      printf("%d",i);
    }
    while(i != -1){
      i = tree[i].right;
      if(i != -1){
	printf(", %d",i);
      }
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 1788
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int k = parseInt(sc.next());
		int s = parseInt(sc.next());
		sc.close();
		int cnt=0;
		for (i = 0; i <= k; i++) {
			for (j = 0; j <= k; j++) {
				if(0<=s-(i+j) && s-(i+j)<=k)cnt++;
			}
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 23252
N,M = map(int,input().split(' '))
tree_list = [[] for _ in range(N) ]
for _ in range(M):
    L,R,C = map(int,input().split(' '))
    tree_list[R-1].append([C,L-1])
inf = float('inf')
dp = [inf] * N
dp[N-1] = 0
current_num = -1
flag = False
if len(tree_list[N-1]) > 0: 
    for i in reversed(range(N)):
        if dp[i] == inf:
            flag = True
            break
        current_start_paths = tree_list[i]
        if len(current_start_paths) > 0:
            current_start_paths.sort()
            for path in current_start_paths:
                if dp[path[1]] > dp[i] + path[0]:
                    for j in range(path[1],i):
                        if (dp[i] + path[0]) < dp[j]:
                            dp[j] = dp[i] + path[0]
                        else:
                            break
    if dp[0] == inf or flag:
        print(-1)
    else:
        print(dp[0])
else:
    print(-1)

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

int main() {
  string A,B;
  cin>>A>>B;
  string merged = A+B;
  int num = atoi(merged.c_str());
  //cout<<num<<endl;
  if(sqrt(num)-int(sqrt(num))==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}


Measured memory_bytes: 384
n=int(input())
s=input()

if n%2==1:
    print("No")
else:
    han=n//2
    swit=0
    for i in range(han):
        if s[i]!=s[i+han]:
            swit=1
    if swit==1:
        print("No")
    else:
        print("Yes")

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

int main() {
	int a, b;
	int value;
	cin >> a >> b;
	if (b <= 9)value = 10 * a + b;
	else if (b <= 99)value = 100 * a + b;
	else value = 1000 * a + b;
	for (int i = 1; i*i <= 100100; i++) {
		if (i*i == value) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

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

  int left;
  int right;
  left = a + b;
  right = c + d;

  if (left > right) {
    cout << "Left" << endl;
  }

  else if (left < right) {
    cout << "Right" << endl;
  }

  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include <string.h>
using namespace std;
void change( char* a,int c)
{
	int b,i;
	
	for(i=0;i<strlen(a);i++)
	{
		b=a[i];
		b=b+c;
		if(b>=91)
			b=b-26;
		a[i]=b;
		cout<<a[i];
	}
	cout<<endl;
}
int main()
{
	int x;
	char a,str[10001];
	cin>>x;
	cin.get(a);
	cin.getline(str,10001);
	change(str,x);
	return 0;
}

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

int SumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  int res = 0;
  for (int i = 1; i <= N; i++) {
    res = SumOfDigits(i);
    if (A <= res && res <= B) {
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
k = min(k,n-1)
mod=10**9+7
fact = [1]*(5*10**5+1)
for i in range(2,5*10**5+1):
  tmp = fact[i-1]*i
  tmp%=mod
  fact[i]=tmp
fact_inv = [0]*(5*10**5+1)
for i in range(5*10**5+1):
  fact_inv[i]=pow(fact[i],mod-2,mod)
  
ans=0
def comb(a,b):
  tmp = (fact[a]*fact_inv[a-b]%mod)*fact_inv[b]
  tmp%=mod
  return tmp


for i in range(k+1):
  tmp = comb(n,i)*comb(n-1,i)
  tmp%=mod
  ans+=tmp
  ans%=mod
  
print(ans%mod)

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

void solve()
{
  int n;
  cin>>n;
  if(n<1200){cout<<"ABC"<<endl;}
  else cout<<"ARC"<<endl;
}

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

        solve();

    return 0;
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  lint p, q; cin >> p >> q;
  V<lint> c(n); for (auto&& e : c) cin >> e;
  lint curr = accumulate(begin(c), end(c), 0LL), res = curr;
  V<> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) { return p * i + c[i] < p * j + c[j]; });
  int t = 0;
  for (int i : idx) {
    curr += p * (q - i + t) - c[i];
    t += 2;
    res = max(res, curr);
  }
  cout << res << '\n';
}


Measured memory_bytes: 8636
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << '\n';
}

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

// 1 つの証言を表す構造体
using pint = pair<int,int>; // 「人」と「0 or 1」

// 入力
int N;
vector<vector<pint>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
    
    // i 人目の証言を検証する
    for (int i = 0; i < N; ++i) {
        
        // i 人目が「不親切」だったら、証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        // それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            // y = 1 なのに「不親切」だったらダメ
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0 なのに「正直者」だったらダメ
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}


int main() {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first; // 0-indexed に
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        
        // 矛盾 check
        if (judge(bit)) {
            
            // bit に含まれる人数を数える
            int count = 0;
            for (int i = 0; i < N; ++i) {
                if (bit & (1 << i)) ++count;
            }
            res = max(res, count);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        int N = sc.nextInt();
        System.out.println(N*N*N);

    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
    
        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 20052
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll func(int x){
    return x*(1+x) / 2;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
ll dp[10010];

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    std::cout << std::defaultfloat << std::setprecision(10);

    int N,K; cin >> N >> K;
    vector<int> P(N);
    REP(i,N) cin >> P[i];

    vector<ll> S(N+1, 0);
    REP(i,N) S[i+1] = S[i] + P[i];

    ll max = -10;
    int ansnumber;

    for(int i=0; i<N-K+1; i++){
        ll res = S[i+K] - S[i];
        if(res > max){
            max = res;
            ansnumber = i;
        }
    }

    double ans=0;

    //cout << ansnumber << endl;

    if(K==1){
        //cout << "here" << endl;
        ans += double(func(P[ansnumber])) / double(P[ansnumber]);
        cout << ans << endl;
        return 0;
    }

    for(int i=ansnumber; i<ansnumber+K; i++){
        ans += double(func(P[i])) / double(P[i]);
        //cout << "ans= " << ans << endl;
    }

    cout << ans << endl;
    //    cout << max << endl;

    return 0;
}


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

c = {}
def f(x,y,z):
    return x**2+y**2+z**2+(x*y)+(y*z)+(z*x)

for i in range(1,n+1):
    t3 = f(i,1,1)
    if t3>n:
        break
    for j in range(i,n+1):
        t2 = f(i,j,1)
        if (t2>n):
            break
        for k in range(j,n+1):
            t = f(i,j,k)
            if t>n:
                break
            else:
                if t not in c:
                    c[t]=0
                if i==j and j==k:
                    c[t]+=1
                elif i==j or j==k or i==k:
                    c[t]+=3
                else:
                    c[t]+=6
for i in range(1,n+1):
    if i not in c:
        print(0)
    else:
        print(c[i])


        

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

// 前回のあらすじ
// n番目を抜き去ったgcdを求めるgcd()関数を作り、その後にmaxのループにぶち込もうと考えた俺氏。
// しかし、一見完璧に見えたその作戦にも穴があったのだ。

// ためしに、maxループの中にgcd関数を入れてみてほしい。
// すると、実行速度はO(N^2)に比例することがすぐに分かるだろう。

// ここで俺氏は力尽きたのだった。

// そこで、新たな改善案として、累積和っぽいメモ化を使って、左側gcdと右側gcdを作り出すことにした。
// これ自体は模範解答の中に存在したのだが、俺氏はこの手法の何が優れているのかをきちんと理解できていなかった。
// この手法の優れているところは、左と右を一組選び出すことが可能なことである。
// つまり、O(N)のオーダー（NlogAかもしれん）の前処理一回、maxループのオーダーO(N)を足したもの、
// すなわち、O(NlogA + NlogA)もしくはO(2N)で完了することが出来る点が優れているのである。

// 以上をかくぞ

// leftは　i　までのgcd　すなわち　i-1　のgcdを取得。
// なので、i == 0 の時はそのままイコール


// 追記
// std::gcd() は　C++17　で追加されたライブラリである。
// 競技プログラミングではC++14環境なので、自前で用意する必要がある。
// その際に、混同しないようにGCDと大文字表記しておくとよさそう。

int GCD(int a,int b){ //ユークリッドの互助法で最大公約数
    if (a%b == 0){
        return b;
    }
    else {
        return GCD(b,a%b);
    }
}

int main(){
    long long int N,A;
    cin >> N;
    long long int Z[N+1]; // 整数がつまってる

    for (long long int i = 0; i < N ;i++){ // 標準入力で配列にぶちこむ
        cin >> A;
        Z[i] = A;
    }

    vector<long long int> left(N+1,1);
    vector<long long int> right(N+1,1);

    long long int temp = Z[0];

    for(long long int j = 0; j < N;j++){ //gcdリスト取得 left
        if(j == 0){
            left[j] = 1 ;
            continue;
        }
        if(j == 1){
            left[j] = Z[j-1];
            continue;
        }
        temp = GCD(temp,Z[j-1]) ;
        left[j] = temp;
    }

    
    temp = Z[N-1] ;
    for(long long int k = N-1; k >= 0 ;k--){ //gcdリスト取得 right
        if(k == N-1){
            right[k] = 1;
            continue;
        }
        if(k == N-2){
            right[k] = Z[k+1];
            continue;
        }
        temp = GCD(temp,Z[k+1]);
        right[k] = temp;
    }


    temp = 0;
    long long int maxz = 0;

    for(long long int l = 0;l < N;l++){ // max_roop
        if(l == 0){
            temp = right[l] ; //特殊な場合を除く
        }
        else if(l == N-1){ //特殊な場合を除く
            temp = left[l] ;
        }
        else { // メインの比較
            temp = GCD(left[l],right[l]);
        }

        // maxz の書き換え

        if(temp > maxz){
            maxz = temp;
        }
        else {
            continue;
        }     
    }


    cout << maxz << endl;
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

int prime_table[55555];
vi prime;

void sieve(void)
{
    prime_table[0] = prime_table[1] = 1;
    rep(i, 55555) {
        if (!prime_table[i]) {
            for (int j = 2; j * i < 55555; j++) {
                prime_table[i*j] = 1;
            }
        }
    }
    rep(i, 55555) {
        if (!prime_table[i]) prime.pb(i);
    }
}

bool dfs(vi &yui, set<int> &funami, int pos, int num, int sum)
{
    if (!num) {
        funami.insert(sum);
    } else {
        for (int i = pos; i < yui.size(); i++) {
            dfs(yui, funami, i+1, num-1, sum += yui[i]);
        }
    }
}

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

    sieve();

    Int(n);
    rep(i, prime.size()) {
        if (!n) break;
        if (prime[i] % 5 == 1) {
            cout << prime[i] << " ";
            n--;
        }
    }

    cout << endl;

    return 0;
}






Measured memory_bytes: 768
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        String s;
        int tmp_A,tmp_Z;
        tmp_A=0;
        tmp_Z=0;
        s=scan.next();
        tmp_A=0;
        for(int i =0;i<s.length();i++){
            if(s.charAt(i)=='A'){
                tmp_A=i;
                break;
            }
        }
        for(int i=s.length()-1;i>=0;i--){
            if(s.charAt(i)=='Z'){
                tmp_Z=i;
                break;
            }
        }
        System.out.println(tmp_Z-tmp_A+1);
    }
}

Measured memory_bytes: 26416
import java.util.*;

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

        int r = sc.nextInt();
        int c = sc.nextInt();

        int[][] t = new int[r+1][c+1];
        
        for (int row = 0; row < r; row++)
            for (int col = 0; col < c; col++)
                t[row][col] = sc.nextInt();

        for (int row = 0; row < r; row++) {
            int sum = 0;
            for (int col = 0; col < c; col++)
                sum += t[row][col];
            t[row][c] = sum;
        }

        for (int col = 0; col <= c; col++) {
            int sum = 0;
            for (int row = 0; row < r; row++)
                sum += t[row][col];
            t[r][col] = sum;
        }

        for (int row = 0; row <= r; row++) {
            for (int col = 0; col <= c; col++)
                System.out.print((col == 0) ? t[row][col] : " " + t[row][col]);
            System.out.println();
        }
    }
}


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

using namespace std;

int main()
{
    vector<int> color(3);
    for (int i = 0; i < 3; i++) {
        cin >> color[i];
    }

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

    if (color[0] == color[1] && color[1] == color[2]) {
        cout << "1" << endl;
    } else if ((color[0] != color[1] && color[1] == color[2])
                || (color[0] == color[1] && color[1] != color[2])) {
        cout << "2" << endl;
    } else {
        cout << "3" << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long 
#define pb push_back
#define fr first
#define sc second
#define sz(v) ((int)(v).size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repd(i,a,p) for(int i=a-1;i>=p;i--) 
#define M 1000000007
#define vi vector<int>
#define vp vector<pair<int,int> >
#define ml map<int,int>
#define MPI 3.1415926536
using namespace std;
//priority_queue is best for traversing elements when it is needed in a sorted order
//dsu is pel concept
int n,m,k=0,t,i,c=0,x,s=0,a,b;string s1;
signed main()
{vi v(5);
		
		rep(i,0,6)
		{
			cin>>v[i];
			if(v[i]==0)
			k=i;
		}
cout<<k+1;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string text,in,dum;
int cur,len;

int main()
{
	int CS, n;
	cin >> CS; getline(cin, dum);
	for (int cs = 0; cs < CS; cs++) {
		getline(cin,text);
		cin >> n; getline(cin, dum);
		len = text.size();
		cur = 0;
		for (int i = 0; i < n; i++) {
			getline(cin, in);
			if (in == "forward char")
				cur = min(cur+1,len);
			else if (in == "backward char")
				cur = max(cur-1,0);
			else if (in == "forward word") {
				while (cur < len && text[cur] == ' ') cur++;
				while (cur < len && text[cur] != ' ') cur++;
			} else if (in == "backward word") {
				while (cur > 0 && text[cur-1] == ' ') cur--;
				while (cur > 0 && text[cur-1] != ' ') cur--;
			} else if (in == "delete char") {
				if (cur >= len) continue;
				text.erase(text.begin()+cur);
				len--;
			} else if (in.find("insert") != in.npos) {
				int s = in.find('"'), t = in.find('"',s+1);
				int l = t-s-1;
				text = text.substr(0,cur) + in.substr(s+1,l) + text.substr(cur);
				cur += l;
				len += l;
			} else if (in == "delete word") {
				int s = cur, t;
				while (text[s] == ' ') s++;
				if (s >= len) continue;
				while (text[s] != ' ' && s < len) s++;
				text = text.substr(0,cur) + text.substr(s);
				len -= s-cur;
			}
		}
		cout << text.substr(0,cur) << "^" << text.substr(cur) << endl;
	}
	return 0;
}

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

int main(){
  int n,x;
  scanf("%d%d",&n,&x);
  int num=0;
  int m[1001];
  for(int i=0;i<n;i++){
    scanf("%d",&m[i]);
  }
  int min = 9999;
  for(int i=0;i<n;i++){
    if(min>m[i])min=m[i];
    num+=m[i];
  }

  int diff=x-num;
  int make=diff/min;

  int ans=make+n;
  
//  if(s[0]=='o')num+=100;
  //if(s[1]=='o')num+=100;
  //if(s[2]=='o')num+=100;

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


  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
const int N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
int n;
int arr[N];
ll dp[N];
class f{
	vector<ll> v;
	public:
		f(){};
		f(int n){v.assign(n+1,0);}
		ll rsq(ll b){
			ll sum=0; for(;b;b-=ls(b)) sum=max(sum,v[b]); return sum;}
		int rsq(int a,int b){
			return rsq(b)- (a==1? 0: rsq(a-1));}
		void ad(int k,ll val){
		for(;k<(int)v.size();k+=ls(k)) v[k]=max(v[k],val);}
};
int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
f ft(N);
for(int i=1;i<=n;i++)cin>>arr[i];
ll ans=0;
  for(int i=1;i<=n;i++)
  {
  	ll x;
  	cin>>x;
  	ll y=ft.rsq(arr[i])+x;
  	ans=max(ans,y);
  	ft.ad(arr[i],y);
  }
  cout<<ans;
}

Measured memory_bytes: 2560