akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    if(s.size()%2){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,s.size()/2){
        if(s[i]=='h'&&s[i+1]=='i'){
            i++;
            continue;
        }
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}



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

namespace abc155_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine()); //N個の書類
            var As = Console.ReadLine().Split(' '); 

            for (int i = 0; i < As.Length; i++)
            {
                var A = int.Parse(As[i]);
            
                if (A % 2 == 0) //偶数で割れるか？
                {
                    if (!(A % 3 == 0 || A % 5 == 0)) //3または5で割れるか？
                    {
                        Console.WriteLine("DENIED");
                        Console.Read();
                        return;
                    }
                }
            }

            Console.WriteLine("APPROVED");
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e5;
const int maxn = 2e5 + 10;
long double iq[maxn], q[maxn], p[maxn], ip[maxn], ans;
int main()
{
	/*
	q[0] = 0.5;
	for(int i = 1; i <= maxm; ++i)
	{
		for(int j = i; j; --j)
		{
			q[j] = ((j - 0.5) * q[j - 1] + (i - j + 0.5) * q[j]) / (i + 1);
			iq[j] = q[j] * j;
			p[i] += q[j];
			ip[i] += iq[j];
		}
		cout << i << ' ' << ip[i] << ' ' << (i + 2) * ip[i - 1] / (i + 1) + p[i - 1] / (2.0 * (i + 1)) + 1 / (4.0 * (i + 1)) << endl;
	}
	*/
	for(int i = 1; i <= maxm; ++i) 
	{
		p[i] = p[i - 1] + 1 / (4.0 * (i + 1));
		ip[i] = (i + 2) * ip[i - 1] / (i + 1) + p[i - 1] / (2.0 * (i + 1)) + 1 / (4.0 * (i + 1));
	}
	int n;
	double d1, x;
	scanf("%d%lf%lf", &n, &d1, &x);
	for(int i = 1; i <= n; ++i)
	{
		int m = min(maxm, n - i);
		long double tmpr = (d1 + (2 * i - 1) * x) * 0.5;
		tmpr += (2 * d1 + 4 * i * x - 3 * x) * p[m];
		tmpr += 4 * x * ip[m];
		
		m = min(maxm, i - 1);
		long double tmpl = (d1 + (2 * i - 2) * x) * 0.5;
		tmpl += (2 * d1 + 4 * i * x - 3 * x) * p[m];
		tmpl -= 4 * x * ip[m];
		//cout << (double)tmpl << ' ' << (double)tmpr << endl;
		ans += tmpl + tmpr;
	}
	double o = ans;
	printf("%.10lf\n", o);
	return 0;
}
		

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

using namespace std;

int main(void) {
    string X[3];
    int i;
    for (i=0; i<3; i++)
        cin >> X[i];

    unsigned int x[3]={};
    int next=0;
    while (true) {
        if (X[next].length() == x[next]) {
            printf("%c\n", next+'A');
            return 0;
        }
        x[next]++;
        next = X[next][x[next]-1]-'a';
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N,M=list(map(int,raw_input().split()))

nl=[[0]*(N+1) for i in range(N+1)]
a=[0]*M
for i in range(M):
	x,y=map(int,raw_input().split())
	nl[x][y]=1
	nl[y][x]=1
	a[i]=[x,y]	
#print nl
#print a

def dfs(v,p):
	#print v
	F[v]=1
	for j in range(N+1):
		#頂点 v に隣接しているかつ未訪問
		if nl[v][j]!=0 and F[j]==0:
			#print v,j,nl[v][j]
			#DFS(次の頂点i, 次に親となる頂点v, d+ 頂点vと頂点iの間の辺のコスト)
			dfs(j,v)


#Connected graph
c_graph=[1]*(N+1)
c_graph[0]=0
#print "# c_graph"
#print c_graph

cnt=0
#print "# visit"
for i in range(M):
	F=[0]*(N+1)
	x=a[i][0]
	y=a[i][1]
	nl[x][y]=0
	nl[y][x]=0
	#print nl
	dfs(1,-1)
	#print F
	if F!=c_graph:
		#print "Not connect"
		cnt+=1
	#Initalize neighbor list
	nl[x][y]=1
	nl[y][x]=1

print cnt



Measured memory_bytes: 2696
module Main where

import           Data.List

toInt :: String -> Int
toInt s = read s :: Int

anySame :: Eq a => [a] -> Bool
anySame [] = False
anySame (x : y : xs) | x == y    = True
                     | otherwise = anySame (y : xs)
anySame [x] = False

main :: IO ()
main = do
  getLine
  l <- getLine
  let ll = map toInt $ words l
  putStrLn $ if anySame $ sort ll then "NO" else "YES"


Measured memory_bytes: 79356
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


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


def main():
    N = I()
    AArray = LI()
    MOD = 1000000007
    aSum = sum(AArray)
    nowAsum = 0
    ans = 0

    for i in range(N-1):
        a = AArray[i]
        nowAsum += a
        asum = aSum-nowAsum
        asum %= MOD
        ans += a*asum % MOD
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32484
#include <iostream>
#include<vector>
#define MAX_N 300
using namespace std;

int N;
char S[MAX_N][MAX_N];

int solve() {
vector<int> ks;

for(int k=0; k<N; k++) {
bool sw = true;
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)

if(S[i][j]!=S[(j-k+N)%N][(i+k+N)%N])
sw=false;

if(sw) ks.push_back(k);
}

int res=0;
for(int k : ks)
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
if((i-j+N)%N==k)
res++;

return res;
}

int main() {
	cin >> N;
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin >> S[i][j];

    cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 384
a, b, k = map(int, input().split())
for i in range(k):
  if i % 2 == 0:
    if a % 2 != 0:
      a = a - 1
    a = a // 2
    b = b + a
  else:
    if b % 2 != 0:
      b = b - 1
    b = b // 2
    a = a + b
print(a, end=" ")
print(b)

Measured memory_bytes: 9112
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
struct node{int x,y,z;};
int f[100005][20],n,h[100005],ans[100005],c[100005],co[100005],de[100005]; 
V<node> v[100005],q[100005];
void get(int p){
	h[p]=h[f[p][0]]+1;
	for(auto u:v[p]){
		if(u.x!=f[p][0]){
			f[u.x][0]=p;de[u.x]=de[p]+u.z;
			get(u.x);
		}
	}
}
int lca(int x,int y){
	if(h[x]>h[y])swap(x,y);
	int t=h[y]-h[x];
	FOR(i,0,17){
		if(t&(1<<i))y=f[y][i];
	}
	if(x==y)RE x;
	for(int i=17;i>=0;i--){
		if(f[x][i]!=f[y][i]){
			x=f[x][i];y=f[y][i];
		}
	}
	RE f[x][0];
}
void dfs(int p){
	for(auto u:q[p]){
		if(u.x>0){
			ans[u.x]+=de[p]+c[u.y]*u.z-co[u.y];
		}else{
			ans[-u.x]-=2*(de[p]+c[u.y]*u.z-co[u.y]);
		}
	}
	for(auto u:v[p]){
		if(u.x==f[p][0])continue;
		c[u.y]++;co[u.y]+=u.z;
		dfs(u.x);
		c[u.y]--;co[u.y]-=u.z;
	} 
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x,y,c,d,m;
	cin>>n>>m;
	FOR(i,2,n){
		cin>>x>>y>>c>>d;
		v[x].PB({y,c,d});
		v[y].PB({x,c,d});
	}
	get(1);
	FOR(i,1,17)FOR(j,1,n)f[j][i]=f[f[j][i-1]][i-1];
	FOR(i,1,m){
		cin>>c>>d>>x>>y;
		q[x].PB({i,c,d});
		q[y].PB({i,c,d});
		q[lca(x,y)].PB({-i,c,d});
	}
	dfs(1);
	FOR(i,1,m)cout<<ans[i]<<'\n';
	RE 0;
}



Measured memory_bytes: 27576
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b,i,j,k;
    cin>>a>>b;
    for(i=0;i<=a;i++){
        for(j=0;j<=a;j++){
            k=a-i-j;
            if(k>=0&&i+j+k==a&&i*10000+j*5000+k*1000==b) {
                    cout<<i<<' '<<j<<' '<<k<<endl;
                    break;}
        }
        if(i+j+k==a&&i*10000+j*5000+k*1000==b) break;
    }
    if(i*10000+j*5000+k*1000!=b) cout<<"-1"<<' '<<"-1"<<' '<<"-1"<<endl;
}


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

int index(char c){
	return (int)c - 48;
}

int main(){
	string s;
	while(cin >> s){
		for(string::iterator iter = s.begin();
			iter != s.end(); iter++)
		{
			if(*iter == '@'){
				iter++;
				int n = index(*iter);
				iter++;
				for(int i = 0; i < n; i++){
					cout << *iter;
				}
			}else{
				cout << *iter;
			}
		}
		cout << endl;
	}
	return 0;
}

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

void make(int x,int y,int n,int num,int map[15][15]){
  if(num > (n*n)){
    return;
  }

  if(x > (n-1)){
    return make(0,y,n,num,map);
  }else if(x < 0){
    return make(n-1,y,n,num,map);
  }else if(y > (n-1)){
    return make(x,0,n,num,map);
  }

  if(map[y][x] != 0){
    return make(x-1,y+1,n,num,map);
  }else{
    map[y][x] = num;
    return make(x+1,y+1,n,num+1,map);
  }
}

int main(int argc,char* argv[]){
  
  int magic[15][15];
  
  for(;;){
    int n,i,j;
    scanf("%d",&n);
    if(n == 0){
      break;
    }
    
    memset(magic,0,sizeof(magic));

    make(n/2,(n+1)/2,n,1,magic);
    
    for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
	printf("%4d",magic[i][j]);
      }
      printf("\n");
    }
    
  }
  
  return 0;
  
}

Measured memory_bytes: 0
S=int(input())
arr=[]
h={}
def calc(n):
  if n % 2 ==0:
    return n/2
  else:
    return 3*n+1

for i in range(1000000):
  if i == 0:
    a = S
  else:
    a = calc(arr[i-1])
  if a in h:
    print(i+1)
    exit(0)
  arr.append(a)
  h[a]=i+1


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
vector<int> v[30];
int p[30];
int mp(char c)
{
	return int(c - 'a' + 1);
}
int main(int argc, char const *argv[])
{
	string s,t;
	cin>>s>>t;
	for(int i = 0;i < s.size(); ++i)
	{
		v[mp(s[i])].push_back(i);
		p[mp(s[i])] = 1;
	}
	for(int i = 0;i < t.size(); ++i)
	{
		if(p[mp(t[i])] == 0)
		{
			printf("-1\n");
			return 0;
		}
	}
	int nowpos = -1;
	int ans = 0;
	for(int i = 0;i < t.size(); ++i)
	{
		char now = t[i];
		int ai = mp(now);
		int pos = upper_bound(v[ai].begin(),v[ai].end(),nowpos) - v[ai].begin();
		// printf("%c %d\n",now,pos);
		if(pos == int(v[ai].size()))
		{
			++ans;
			nowpos = v[ai][0];
		}
		else
		{
			nowpos = v[ai][pos];
		}
	}
	printf("%lld\n",ll(ans) * ll(int(s.size())) + ll(nowpos) + 1ll);
	return 0;
}

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

int main(){
    long N;
    long K;
    long h;
    long cnt=0;
    cin>>N>>K;
    for(int i=0;i<N;++i){
        cin>>h;
        if(h>=K){
            ++cnt;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
K = int(input())
print(a[K-1])

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

#define ll long long
#define pb push_back
void solve(ll k, ll a, ll b)

{
	ll j;
	bool boo = false;
	for (ll i = 1; ; i++)
	{   
		if (k*i >= a && k*i <= b)
		{
			cout << "OK" << endl;
			break;
		}

		if (k*i > b)
		{
			boo = true;
			break;
		}
	}

	if (boo == true) cout << "NG" << endl;

}

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

}

Measured memory_bytes: 3624
N,M=[int(s) for s in input().split()]
lst=[]
for i in range(M):
  a,b=[int(s) for s in input().split()]
  lst.append([a,b,i])
lst.sort()
city=0
count=1
for e in lst :
  if e[0]>city :
    city=e[0]
    count=1
  e[0]=10**12+e[0]*10**6+count
  count=count+1
lst=sorted(lst,key=lambda e:e[2])
for e in lst :
  print(str(e[0])[1:])

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

bool f(int n)
{
    return (n % 3 != 0 && n % 5 != 0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    unsigned long long sum = 0;
    for (int i = 1; i <= n; ++i) {
        if (f(i)) {
            sum += i;
        }
    }
    cout << sum << endl;

}



Measured memory_bytes: 3652
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
   
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int T;
	T=1;
	while(T--)
	{
		string s;
		cin>>s;
		int k=0;
		for(int i=0;i<s.size();i++)
		{
			k=(k+(s[i]-48))%9;
		}
		if(k==0) cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 3728
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int h = Integer.parseInt(s[0]);
			int w = Integer.parseInt(s[1]);
			if( h==0 && w==0 ) break;
			
			// ???????????°?????????
			for( int i=1 ; i<=h ; i++ ){
				// ????????°?????????
				for( int j=1 ; j<=w ; j++ ){
					if( i==1 || i==h ){
						builder.append("#");
					}else{
						if( j==1 || j==w ){
							builder.append("#");
						}else{
							builder.append(".");
						}
					}
				}//???
				builder.append("\n");
			}//??????
			builder.append("\n");
		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 25532
n=int(input())
a=list(map(int,input().split()))

c=[0 for i in range((n+1)//2)]
if n%2:
  c[0]+=1

for i in a:
  if i%2==n%2:
    break
  c[i//2]+=1

f=True
for i in c:
  if i!=2:
    f=False
    break
print(pow(2,n//2,10**9+7) if f else 0)


Measured memory_bytes: 86164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}

long long kaijou(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

int a[100005];
int b[100005];


int main(void){
    int n, h;
    int i;
    int max = 0;
    int throwing = 0;
    int throwing_total = 0;
    int ans;
    scanf("%d %d", &n, &h);
    for (i = 0; i < n; i++){
        scanf("%d %d", &a[i], &b[i]);
        max = max>a[i]?max:a[i];
    }
    qsort(b, n, sizeof(int), descending_compare);
    for (i = 0; i < n; i++){
        if (max<b[i]){
            throwing++;
            throwing_total += b[i];
        }
    }
    if (h<=throwing_total){
        throwing_total = 0;
        throwing = 0;
        for (i = 0; i < n; i++){
            throwing_total += b[i];
            throwing++;
            if(throwing_total >= h){
                printf("%d\n", throwing);
                return 0;
            }
        }
    }else if((h-throwing_total)%max == 0){
        ans = (h-throwing_total)/max;
        ans += throwing;
    }else{
        ans = (h-throwing_total)/max;
        ans++;
        ans += throwing;
    }

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



    return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    string s;
    cin >> s;
    int n = s.size();

    if(s[n-1] == '1' || s[n-2] == '0' || s[0] == '0'){
        cout << -1 << endl;
        return 0;
    }
    rep(i,n-1)if(s[i] != s[n-i-2]){
        cout << -1 << endl;
        return 0;
    }

    j = n-1;
    for(i = n-2; i >= 0; i--){
        cout << i+1 << " " << j+1 << endl;
        if(s[i] == '1') j = i;
    }

}


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 3e3 + 10;
const ll mod = 1e9 + 7;

int n;
char s[maxN];
ll dp[maxN][maxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> (s + 1);
    dp[1][1] = 1;
    fore(i, 2, n)
    {
        for1(j, i)
        {
            dp[i][j] = dp[i][j - 1];
            if (s[i - 1] == '<')
            {
                dp[i][j] += dp[i - 1][j - 1];
            }
            else
            {
                dp[i][j] += dp[i - 1][i - 1] - dp[i - 1][j - 1];
            }
            dp[i][j] = (dp[i][j] % mod + mod) % mod;
        }
    }
    cout << dp[n][n];
    return 0;
}


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

#define int long long
#define REP(i, l, r) REPEAT(i,l,r,true) // [l, r)
#define rep(i, n) REP(i,0,n)           // [0, n)
#define REPEAT(i, l, r, condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n, l, r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...) true
#define showlr(n,l,r) true
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int, int>;

struct io {
    io() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.tie(0);
        cout << fixed << setprecision(20);
    }
} io;

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &e:v)is >> e;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, vector<T> v) {
    os << "{";
    for (T &e:v)os << e << (v.size() - (int) (&e - &v[0]) > 1 ? ", " : "");
    os << "}";
    return os;
}

void _DEBUG() {}

template<typename H, typename... T>
void _DEBUG(H a, T...b) {
    cerr << a << (sizeof...(b) ? "," : "\n");
    _DEBUG(b...);
}

inline void in() {}

template<typename H, typename... T>
void in(H &a, T &... b) {
    cin >> a;
    in(b...);
}

inline void out() {}

template<typename H, typename... T>
void out(H a, T... b) {
    cout << a << (sizeof...(b) ? " " : "\n");
    out(b...);
}

template<class T>
void resz(int n, T &v) { v.resize(n); }

template<class H, class... T>
void resz(int n, H &a, T &... b) {
    a.resize(n);
    resz(n, b...);
}

template<typename V, typename H>
void resize(vector<V> &v, const H a) { v.resize(a); }

template<typename V, typename H, typename... T>
void resize(vector<V> &v, const H &a, const T... b) {
    v.resize(a);
    for (auto &v:v) resize(v, b...);
}

const int INF = 1LL << 55;
const int MOD = 1000000007;
const double EPS = 1e-8;

/*------------end of definitions------------*/

int N;
vi A;
multiset<int> colors;

signed main() {

    in(N);
    A.resize(N);
    in(A);
    colors.insert(A[0]);
    REP(i, 1, N) {
        auto iter = colors.lower_bound(A[i]);
        if (iter != colors.begin()) {
            iter--;
            colors.erase(iter);
        }
        colors.insert(A[i]);

    }
    out(colors.size());

    return 0;
}


Measured memory_bytes: 5760
def C_BeTogether():
    N = int(input())
    a = list(map(int,input().split()))
    average = round(sum(a) / N)
    ans = 0
    for x in range(N):
        ans += pow(a[x] - average, 2)
    print(ans)
    
if __name__ == "__main__":
    C_BeTogether()

Measured memory_bytes: 3060
fn b() {
    input! {
        n: usize,
        L: [i64; n]
    }

    let mut ans = 0;

    for i in 0..n {
        let i_n = L[i];
        for j in i..n {
            let j_n = L[j];
            for k in j..n {
                let k_n = L[k];
                if i_n != j_n && j_n != k_n && i_n != k_n &&
                    i_n < (j_n + k_n) &&
                    j_n < (i_n + k_n) &&
                    k_n < (i_n + j_n){
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}

use proconio::{input, marker::Chars};

fn main() {
    b();
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = ((int)a) - 1; i >= ((int)a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

void dump_impl(string s) {}
template <class H, class... T>
void dump_impl(string s, H head, T... tail) {
    int p = 0;
    rep(i, 0, sz(s)) {
        char x = s[i];
        if (p == 0 && x == ',') {
            cerr << "=" << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << x;
            if (x == '(') p++;
            if (x == ')') p--;
        }
    }
}
#ifdef LOCAL
#define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0) 
#else
#define dump(...)
#endif

constexpr int DY[8] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr int DX[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(int W, int H) {
    vector<string> S(H);
    rep(i, 0, H) cin >> S[i];

    int black = 0, white = 0;

    vvi vis(H, vi(W, -1));
    rep(i, 0, H) {
        rep(j, 0, W) {
            if (vis[i][j] != -1) continue;
            if (S[i][j] != '.') continue;
            queue<pii> q;
            q.push({i, j});
            vis[i][j] = 1;
            set<char> chars;
            int cnt = 0;
            while (sz(q)) {
                int y, x;
                tie(y, x) = q.front(); q.pop();
                assert(S[y][x] == '.');
                cnt++;

                rep(dir, 0, 4) {
                    int yy = y + DY[dir];
                    int xx = x + DX[dir];
                    if (yy < 0 || yy >= H || xx < 0 || xx >= W) continue;
                    if (vis[yy][xx] != -1) continue;
                    if (S[yy][xx] != '.') {
                        chars.insert(S[yy][xx]);
                        continue;
                    }
                    vis[yy][xx] = 1;
                    q.push({yy, xx});
                }
            }

            dump(i, j, cnt, sz(chars));

            if (sz(chars) == 1) {
                if (*chars.begin() == 'B') black += cnt;
                if (*chars.begin() == 'W') white += cnt;
            }
        }
    }

    cout << black << " " << white << endl;
}

signed main() {
    while (1) {
        int W, H;
        cin >> W >> H;
        if (W == 0 && H ==0) break;
        solve(W, H);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'

#define MAX 100001

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

    int k;
    cin >> k;
    cout << (k + 1) / 2 * (k / 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
 string s;
 cin>>s;
 int i;
 if(s.at(0) !='A'){ 
  cout<<"WA"<<endl;
 }
 else{
  int kaunto=0;
  int omozi=0;
  int p=s.size();
  int q=p-1;

  if(s.at(1)=='Q'||s.at(1)=='A'||s.at(1)=='Z'||s.at(1)=='W'||
s.at(1)=='S'||s.at(1)=='X'||s.at(1)=='E'||s.at(1)=='D'||
s.at(1)=='R'||s.at(1)=='F'||s.at(1)=='V'||s.at(1)=='T'||
s.at(1)=='G'||s.at(1)=='B'||s.at(1)=='Y'||s.at(1)=='H'||
s.at(1)=='N'||s.at(1)=='U'||s.at(1)=='J'||s.at(1)=='M'||
s.at(1)=='I'||s.at(1)=='K'||s.at(1)=='O'||s.at(1)=='L'||
s.at(1)=='P'||s.at(1)=='C'||s.at(q)=='Q'||s.at(q)=='A'||
s.at(q)=='Z'||s.at(q)=='W'||s.at(q)=='S'||s.at(q)=='X'||
s.at(q)=='E'||s.at(q)=='D'||s.at(q)=='R'||s.at(q)=='F'||
s.at(q)=='V'||s.at(q)=='T'||s.at(q)=='G'||s.at(q)=='B'||
s.at(q)=='Y'||s.at(q)=='H'||s.at(q)=='N'||s.at(q)=='U'||
s.at(q)=='J'||s.at(q)=='M'||s.at(q)=='I'||s.at(q)=='K'||
s.at(q)=='O'||s.at(q)=='L'||s.at(q)=='P'||s.at(q)=='C')omozi++;

  for(i=2;i<s.size()-1;i++){
   if(s.at(i)=='C') kaunto++;
   if(s.at(i)=='Q'||s.at(i)=='A'||s.at(i)=='Z'||s.at(i)=='W'||
s.at(i)=='S'||s.at(i)=='X'||s.at(i)=='E'||s.at(i)=='D'||
s.at(i)=='R'||s.at(i)=='F'||s.at(i)=='V'||s.at(i)=='T'||
s.at(i)=='G'||s.at(i)=='B'||s.at(i)=='Y'||s.at(i)=='H'||
s.at(i)=='N'||s.at(i)=='U'||s.at(i)=='J'||s.at(i)=='M'||
s.at(i)=='I'||s.at(i)=='K'||s.at(i)=='O'||s.at(i)=='L'||
s.at(i)=='P')omozi++;
}
  if(kaunto==1&&omozi==0)cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
 }
}

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

#define int long long
// logic: Print, Help, For, Equal, eXclusive, Decrease
#define P(x) cout << x << endl
#define H(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(n); i++)      // [0,n)
#define FE(i,n) for (int i=0; i<=(n); i++)    // [0,n]
#define FX(i,a,b) for (int i=(a); i<(b); i++) // [a,b)
#define D(i,n) for (int i=(n); --i>=0;)       // (n,0]
#define DX(i,a,b) for (int i=(b); --i>=(a);)  // (b,a]
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define V vector
#define pb push_back
#define mt make_tuple

using namespace std;

int n, c[600], s[600], f[600];

int solve(int i){
	int curs = i, curt = 0;
	while(curs < n-1){
		if(curt < s[curs]) curt = s[curs] + c[curs], curs++;
		else if(curt % f[curs] == 0) curt += c[curs], curs++;
		else curt = ((1 + curt / f[curs]) * f[curs]) + c[curs], curs++;
	}
	return curt;
}

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

	cin >> n;
	F(i,n-1) cin >> c[i] >> s[i] >> f[i];
	F(i,n) cout << solve(i) << endl;
}


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

int main() {
  
  int x = 1;
  
  int N, K;
  cin >> N >> K;
  
  int counter = N;
  
  while (x < K) {
    if (counter == 0) break;
    x *= 2;
    counter -= 1;
  }
  
  while (counter > 0){
    x += K;
    counter -= 1;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <stack>

using namespace std;

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;}

typedef long long LL;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef vector<int> VI;

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

int main(void){
  int n, m;
  unordered_set<int> bad_tenboes;

  cin >> n >> m;
  VI h(n, 0);

  rep(i, n) {
    cin >> h[i];
  }

  rep(i, m) {
    int r1, r2;
    int h1, h2;
    cin >> r1 >> r2;
    h1 = h[r1-1];
    h2 = h[r2-1];
    if (h1 > h2) {
      bad_tenboes.insert(r2);
    } else if (h1 < h2) {
      bad_tenboes.insert(r1);
    } else {
      bad_tenboes.insert(r1);
      bad_tenboes.insert(r2);
    }
  }

  cout << n - bad_tenboes.size();

  return 0;
};

Measured memory_bytes: 5980
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int n;
    cin>>n;
    V<int> a(n);
    cinf(n,a);
    bool ok=1;
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%3==0||a[i]%5==0) continue;
            else ok=0;
        }
    }
    if(ok) cout<<"APPROVED";
    else cout<<"DENIED";
}

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

const ll base = 1e6;
int D;
int C[30];
int S[400][30];

ll score(vector<int>& t)
{
  vector<int> last(30, 0);
  ll s = 0LL;
  REP(i,D){
    s += S[i][t[i]];
    last[t[i]] = (i+1);
    REP(j,26){
      s -= C[j] * (i+1-last[j]);
    } 
  }
  return s;
}

vector<int> init(int sub)
{
  vector<int> t(D);
  REP(i,D) t[i] = (i+sub)%26;
  return t;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  cin >> D;
  REP(i,26) cin >> C[i];
  REP(i,D) REP(j,26) cin >> S[i][j];

  auto T = init(0);
  ll max_score = 0LL;
  REP(sub,26){
    auto tmp = init(sub);
    ll sc = max(base+score(tmp), 0LL);
    if(max_score<sc){
      max_score = sc;
      T = tmp;
    }
  }
  REP(i,D) cout << T[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3708
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

#define inf 10000000000 + 5

int a, b;
int answer;

int main(){
  cin >> a >> b;
  if(a > b){
    answer += a;
    a--;
  }else{
    answer += b;
    b--;
  }
  if(a > b){
    answer += a;
    a--;
  }else{
    answer += b;
    b--;
  }
  cout << answer << endl;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
int main()
  {int a,b;
   cin>>a>>b;
   if(a>b)
   {for(int i=0;i<a;i++)
     cout<<b;
   }
   else
   {for(int i=0;i<b;i++)
     cout<<a;
   }
  }

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def solve(input: String): String = {
    val sc: Scanner = new Scanner(input)
    val n = sc.nextInt
    val a = List.fill(n)(sc.nextInt)
    (a.max - a.min).toString
  }

  val tests = List(
    """4
      |1 4 6 3""".stripMargin -> """5""",
    """2
      |1000000000 1""".stripMargin -> """999999999""",
    """5
      |1 1 1 1 1""".stripMargin -> """0"""
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}

Measured memory_bytes: 26916
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    char c;
    cin>>c;
    if(isupper(c)){
        cout<<"A"<<endl;
    }
    else{
        cout<<"a"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n;
vl v;

void check(vl &v) {
    rep(i, n) {
        char c = v[i] + 'a';
        cout << c;
    }
    cout << "\n";
}

void dfs(ll depth, ll ma) {
    if(depth == n) {
        check(v);
        return;
    }
    exrep(i, 0, ma+1) {
        v[depth] = i;
        if(i == ma+1) {
            dfs(depth+1, ma+1);
        }
        else {
            dfs(depth+1, ma);
        }
    }
}

int main() {

    cin >> n;

    v.resize(n);
    dfs(0, -1);

    re0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  cout << ((e - a <= k) ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
int main(void){
    int n;cin>>n;
    cout<<(n-2)*180;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;






int main() {

    
    ll x, y;
    cin >> x >> y;

    int ans = 0;
    while (x <= y) {
        x *= 2;
        ++ans;
    }

    out(ans);

    return 0;
}




//              g++ -std=c++1z






Measured memory_bytes: 888
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

inp = AC.inputInt(" ")
A = inp[0]
B = inp[1]

X = A*B
tmp = 0

if A < B:
    tmp = A
    A  = B
    B = tmp

R = A%B

while R != 0:
    A = B
    B = R
    R = A%B

print(int(X/B))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, X;
  int n_500, n_5;
  int U;
  
  n_500=0;
  n_5=0;
  
  cin >> X;
  
  x = X;
  
  while(x >= 500){
    x = x - 500;
    n_500 = n_500 + 1;
  }

  while(x >= 5){
    x = x - 5;
     n_5 = n_5 + 1;
  }
  
  U = n_500 * 1000 + n_5 * 5;
  cout << U << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  n=n%10;
  if(n==3) cout<<"bon";
  else if(n==0|| n==1|| n==6|| n==8) cout<<"pon";
  else cout<<"hon";
  return 0;
}

Measured memory_bytes: 3632
import fractions
# import math as fractions
mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

g = fractions.gcd(a[0], a[1]) # 最大公約数
f = a[0]*a[1]//g # 最小公倍数
ans = a[0]//g+a[1]//g

for i in range(2, n):
    # print(ans, g, f)
    h = fractions.gcd(f, a[i])
    g = a[i] // h
    f = f*a[i]// h
    ans *= g
    ans += f // a[i]
    ans %= mod
print(ans%mod)


Measured memory_bytes: 6072
#include<stdio.h>

int main(){
	int i,n,count = 0,prime[10001]={2};
	long x;
	
	for( x = 3; count < 10000; x += 2 ){
		for( i = 0; prime[i] < x; i++ ){
			if( prime[i] == 0 ){
				prime[i] = x;
				count++;
				break;
			}
			if( x % prime[i] == 0 ) break;
		}
	}
	
	while( scanf("%d", &n), n != 0 ){
		long total = 0;
		for( i = 0; i < n; i++ ) total += prime[i];
		printf("%ld\n", total);
	}
	return 0;
}

Measured memory_bytes: 644
//author : Yogi79

#include<bits/stdc++.h>
using namespace std;

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   long n;
   cin>>n;
   long long dp[n+1],a[n+1];
   memset(dp,0,sizeof(dp));

   for(int i=1;i<n+1;i++)
    cin>>a[i];
long long p=0,q=0;

dp[1]=0;
dp[2]=abs(a[1]-a[2]);

    for(int i=3;i<n+1;i++)
    {
            p = dp[i-1]+abs(a[i-1]-a[i]);
            q = dp[i-2]+abs(a[i-2]-a[i]);
        dp[i] += min(p,q);
    }

cout<<dp[n];
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int N = Integer.parseInt(s[0]);
    int W = Integer.parseInt(s[1]);
    int[] weight = new int[N];
    int[] value = new int[N];
    for(int i = 0; i < N; i++){
      String[] t = sc.nextLine().split(" ");
      weight[i] = Integer.parseInt(t[0]);
      value[i] = Integer.parseInt(t[1]);
    }
    
    long[][] dp = new long[N+1][W+1];
    for(int i = 0; i <= N; i++){
      for(int j = 0; j <= W; j++){
        if(i == 0 || j == 0){
          dp[i][j] = 0;
        }else if(weight[i-1] > j){
          dp[i][j] = dp[i-1][j];
        }else{
          dp[i][j] = Math.max(dp[i-1][j], value[i-1]+dp[i-1][j-weight[i-1]]);
        }
      }
    }
    System.out.println(dp[N][W]);
  }
}

Measured memory_bytes: 126804
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	}
}

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

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;

int a[maxn];

int main()
{
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  int sum = 0;
  for(int i = 0 ; i < n ; i++)
  {
    cin >> a[i];
    if( i & 1)
      sum -= a[i];
    else
      sum += a[i];
  }
  int x1 = sum;
  cout << x1 << ' ';
  for(int i = 1; i < n; i++)
  {
    int val = 2*a[i-1] - x1;
    cout << val << ' ';
    x1 = val; 
  }

  cout << endl;



  return 0;
}

Measured memory_bytes: 4024
import java.io.*;
import java.util.*;
import java.lang.Math.*;

public class Main{ 
    
    public static void main(String[] args)throws IOException{
	try{
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br=new BufferedReader(isr);
	String line;
	/*
	  y=y2-y1/x2-x1  (x-x1)+y1
	  y(x2-x1)=(y2-y1)(x-x1)+y1(x2-x1)
	  (x2-x1)(y-y1)=(y2-y1)(x-x1)
	*/
	while((line=br.readLine())!=null){
	    StringTokenizer st=new StringTokenizer(line,",");
	    double[] x=new double[4];
	    double[] y=new double[4];
	    for(int i=0;i<4;i++){
		x[i]=Double.parseDouble(st.nextToken());
		y[i]=Double.parseDouble(st.nextToken());
	    }
	    f(x,y);
	}
	}catch(java.lang.NumberFormatException e){
	    System.out.println(e);
	}
    }

    static void f(double[] x,double[] y){
	if(	(((x[2]-x[0])*(y[1]-y[0])-(y[2]-y[0])*(x[1]-x[0]))*((x[2] -x[0])*(y[3]-y[0])-(y[2]-y[0])*(x[3]-x[0])))<0){
	    if((((x[3]-x[1])*(y[0]-y[1])-(y[3]-y[1])*(x[0]-x[1]))*((x[3]-x[1])*(y[2]-y[1])-(y[3]-y[1])*(x[2]-x[1])))<0){
		System.out.println("YES");
	    }
	    else System.out.println("NO");
	}
	else System.out.println("NO");
    }
}

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

ans = n
w2r = 0
r2w = s.count("R")
ans = min(ans, max(w2r, r2w))

for i in range(n):
    if s[i]=="W":
        w2r += 1
    else:
        r2w -= 1
    ans = min(ans, max(w2r, r2w))
    
print(ans)

Measured memory_bytes: 9376
import math
n = int(input())

a = 1
b = 1

'''
def get_prime(num):
    primes = {}
    origin_num = num
    primes[1] = 1

    tmp = int(math.sqrt(num) + 1)

    for i in range(2, tmp):
        while num % i == 0:
            num //= i

            if not (i in primes.keys()):
                primes[i] = 0
            primes[i] += 1

    if num != 1:
        primes[num] = 1

    if num == origin_num:
        primes[num] = 1

    return primes


prime_dic = get_prime(n)
prime_sorted = sorted(prime_dic.items(), key=lambda x: x[0], reverse=True)

for k, v in prime_sorted:
    for i in range(v):
        if a <= b:
            a *= k
        else:
            b *= k
'''


tmp = int(math.sqrt(n) + 1)

for i in range(1, tmp):
    if n % i == 0:
        a = i

b = int(n / a)

f = max(len(str(a)), len(str(b)))

print(f)



Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("acornistnt");
            WillReturn.Add("peanutbomb");
            WillReturn.Add("constraint");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2");
            WillReturn.Add("oneplustwo");
            WillReturn.Add("ninemodsix");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5");
            WillReturn.Add("abaaaaaaaa");
            WillReturn.Add("oneplustwo");
            WillReturn.Add("aaaaaaaaba");
            WillReturn.Add("twoplusone");
            WillReturn.Add("aaaabaaaaa");
            //4
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        checked {
            List<string> InputList = GetInputList();

            var SDict = new Dictionary<string, int>();
            for (int I = 1; I <= InputList.Count - 1; I++) {
                char[] wkArr = InputList[I].ToCharArray();
                Array.Sort(wkArr);
                string SortedStr = new string(wkArr);

                if (SDict.ContainsKey(SortedStr)) {
                    SDict[SortedStr]++;
                }
                else {
                    SDict[SortedStr] = 1;
                }
            }
            int MaxCnt = SDict.Values.Max();

            //三角数の値を求める
            var SankakuDict = new Dictionary<int, long>();
            long SankakuSum = 0;
            for (int I = 1; I <= MaxCnt; I++) {
                SankakuSum += I;
                SankakuDict[I] = SankakuSum;
            }

            long Answer = 0;
            foreach (var EachPair in SDict) {
                if (EachPair.Value == 1) continue;
                Answer += SankakuDict[EachPair.Value - 1];
            }
            Console.WriteLine(Answer);
        }
    }
}


Measured memory_bytes: 33492
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int x, y, z;
    cin >> x >> y >> z;
    x -= z;
    cout << x/(y+z) << "\n";
    return 0;
}

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

int main(){
    int x;
    int i = 1;
    
    while(1){
        cin >> x;
        if(x == 0) break;
        cout << "Case " << i <<": " << x << endl;
        i ++;
        
        
        
    }
    return 0;
}


Measured memory_bytes: 2980
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<iterator>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

class Graph{
    public:
    typedef struct Edge{
        ll from, to, cost;
        Edge(ll f, ll t, ll c): from(f),to(t),cost(c){}
    } Edge;

    bool isDirected;
    ll INF = 1 << 30;
    ll v; // 頂点数
    std::vector<Edge> edges;  // 辺のリスト
    std::vector<std::vector<std::pair<ll,ll>>> list;  // 隣接リスト
    //std::vector<std::vector<ll>> matrix; // 隣接行列

    Graph(ll n, bool isDirected=false) : isDirected(isDirected) { init(n); }
    void init(ll n){
        v=n;
        edges.clear();
        list.assign(n, std::vector<std::pair<ll,ll>>());
        //matrix.assign(n, std::vector<ll>(n, INF));
    }
    void connect(ll from, ll to){
        con(from, to, 1);
        if(!isDirected) con(to, from, 1);
    }
    void connect(ll from, ll to, ll cost){
        con(from, to, cost);
        if(!isDirected) con(to, from, cost);
    }
    void con(ll from, ll to, ll cost){
        edges.push_back(Edge(from,to,cost));
        list[from].push_back(std::make_pair(to, cost));
        //matrix[from][to] = cost;
    }
};

std::vector<std::vector<ll>> WarshallFloyd(Graph G, ll inf){
    std::vector<std::vector<ll>> matrix;
    matrix.assign(G.v, std::vector<ll>(G.v, inf));
    for(ll i=0; i<G.v; i++)matrix[i][i]=0;
    for(auto i : G.edges){ matrix[i.from][i.to] = i.cost; }
    for(ll k=0; k<G.v; k++)for(ll i=0; i<G.v; i++)for(ll j=0; j<G.v; j++){
        if(matrix[i][k]==inf || matrix[k][j]==inf) continue;
        matrix[i][j] = std::min(matrix[i][j], matrix[i][k]+matrix[k][j]);
    }
    return matrix;
}

int main(){
    int v,e, s,t,d;
    cin >> v >> e;
    Graph gr(v, true);
    REP(i,e){
        cin >> s >> t >> d;
        gr.connect(s,t,d);
    }
    ll inf = 1LL<<62;
    std::vector<std::vector<ll>> ans = WarshallFloyd(gr, inf);
    bool negative = false;
    REP(i,v)if(ans[i][i]!=0)negative=true;
    if(negative){cout<< "NEGATIVE CYCLE"<<endl; return 0;}
    for(auto i : ans){
        REP(j,v){
            if(i[j]==inf) cout << "INF";
            else cout << i[j];
            if(j!=v-1)cout << " ";
            else cout << endl;
        }
    }
}


Measured memory_bytes: 3828