akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int h , w ;
	cin >> h >> w;
	char arr[h][w];
	for(int i = 0 ; i < h ; i++)
		for(int j = 0 ; j  < w ; j++)
			cin >> arr[i][j] ;
	int step[h][w] = {0};
	for(int i = 0 ; i < h ; i++)
		for(int j = 0 ; j < w ; j++)
			step[i][j]=0;
	for(int i = 0 ; i < h ; i++)
	{
		if(arr[i][0]=='#')
			break;
		else
			step[i][0] = 1;
	}
	for(int i = 0 ; i < w ; i++)
	{
		if(arr[0][i]=='#')
			break;
		else
			step[0][i] = 1;
	}
	for(int i = 1 ; i < h ; i++)
		for(int j = 1 ; j < w ; j++)
		{
			if(arr[i][j]=='#')
				step[i][j]=0;
			else
				step[i][j] = (step[i-1][j]+step[i][j-1])%1000000007;
		}
		
	cout << step[h-1][w-1];
	return 0;
}

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

int main()
{
	int len, i, ok;
	char str[80];

	while(gets(str)){
		ok = 0;
		len = strlen(str);

		while(1){
			for (i = 0; i < len; i++){
				if((str[i] == 't' && str[i+1] == 'h' && str[i+2] == 'e') ||
					(str[i] == 't' && str[i+1] == 'h' && ((str[i+2] == 'i' && str[i+3] == 's') || (str[i+2] == 'a' && str[i+3] == 't')))) {ok = 1; break;}
			}

			if(ok == 1) {printf("%s\n", str); break;}
			else{
				for (i = 0; i < len; i++){
					if(str[i] >= 'a' && str[i] <= 'z'){
						if(str[i] == 'z') str[i] = 'a';
						else str[i]++;
					}
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
import math


def main():
    K = int(input())
    s = 0
    for i in range(1, K+1):
        for j in range(1, K + 1):
            tmp = math.gcd(i, j)
            for k in range(1, K + 1):
                s += math.gcd(tmp, k)

    print(s)


if __name__=="__main__":
    main()


Measured memory_bytes: 67696
#!/usr/bin/env python3
import sys
import re


def solve(H: int, W: int, S: "List[str]"):

    
    L = [[0] * W for i in range(H)]
    R = [[0] * W for i in range(H)]
    U = [[0] * W for i in range(H)]
    D = [[0] * W for i in range(H)]
    
    for i in range(H):
        for j in range(W):
            # 左
            if(S[i][j] =='#'):
                L[i][j] = 0
            elif(j == 0):
                L[i][j] = 1
            elif(j >= 1):
                L[i][j] = L[i][j-1] + 1

            # 上
            if(S[i][j] =='#'):
                U[i][j] = 0
            elif(i == 0):
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1


    for i in range(H-1,-1,-1):
        for j in range(W-1,-1,-1):
            # 右
            if(S[i][j] =='#'):
                R[i][j] = 0
            elif(j == W-1):
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1

            # 下
            if(S[i][j] =='#'):
                D[i][j] = 0
            elif(i == H-1):
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
    

    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)

    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 176136
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

int main() {
  int w, d;
  while (scanf("%d%d", &w, &d), w|d) {
    int h, ans = 0;
    int hist1[21] = {}, hist2[21] = {};
    REP(i, w) { scanf("%d", &h); hist1[h]++; ans += h; }
    REP(i, d) { scanf("%d", &h); hist2[h]++; ans += h; }
    REP(h, 21) { ans -= h * min(hist1[h], hist2[h]); }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
n = gets.to_i
ans = Array.new(10**4 + 1, 0)

## x <= y <= zとする。

max_x = Math.sqrt(n/6).to_i + 1
max_y = Math.sqrt(n/3).to_i + 1
max_z = Math.sqrt(n).to_i + 1


(1..max_x).each do |x|
  (x..max_y).each do |y|
    break if x**2 + y**2 + x*y + x + y + 1 > n
    (y..max_z).each do |z|
      result = x**2 + y**2 + z**2 + x*y + y*z + z*x
	  break if result > n
      if x == y && x == z
	      plus_cnt = 1
      elsif x == y || y == z || z == x
          plus_cnt = 3
      else
          plus_cnt = 6
      end
	      ans[result] += plus_cnt if result <= n
    end
  end
end

(1..n).each do |i|
  puts ans[i]
end


Measured memory_bytes: 14184
/*B以下の最大のKの倍数→A以下か*/

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

int main(){
  int a,b,k;
  cin >> k >> a >> b;
  int max = (b/k) * k;
  if(max >= a) cout << "OK" << endl;
  else cout << "NG" << endl;
}
 


Measured memory_bytes: 3580
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
left, right = 0, 0
for i in range(X,N+1):
    if i in A:
        right += 1
for j in range(X,0,-1):
    if j in A:
        left += 1
print(min(left,right))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,p[110];
	cin>>n;
	ll cnt=0;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		if(p[i]!=i){
			cnt++;
		}
	}
	cout<<(cnt<=2?"YES":"NO")<<endl;
	return 0;
}


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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define vll vector<ll> 
#define vpll vector<pair<ll,ll>>
#define tc ll t=0;cin>>t;while(t--)
#define pb push_back
#define pop pop_back
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define max *max_element
#define min *min_element
#define f first
#define s second
#define vli vll::iterator 
#define mp make_pair
#define max_val 99999999
#define min_val -99999999
#define mod 1000000007

int main()
{
    IOS
    #ifdef LOCAL
            freopen("C:\\Users\\Just Coding Things\\Codeforces\\input.txt","r",stdin);
            freopen("C:\\Users\\Just Coding Things\\Codeforces\\output.txt","w",stdout);
        #endif
    
    ll n,m,i,sum=0;
    cin>>n>>m;
    vll v(m);
    for(i=0;i<m;i++)
    {
        cin>>v[i];
        
    }
    for(i=0;i<m;i++)
    sum+=v[i];
    if(sum==n)cout<<"0";
    else if(sum>n) cout<<"-1";
    else if (sum<n)cout<<n-sum;
    cout<<endl;
    return 0;
}

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

using ll=long long;
#define int ll

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

int read(){
  int i;
  scanf("%lld",&i);
  return i;
}

bool is_prime(int n){
  if(n==0||n==1) return false;
  if(n==2) return true;
  for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
  }
  return true;
}

signed main(){
  while(true){
    int N=read(),P=read();
    if(N==-1&&P==-1) break;
    vector<int> prime;
    vector<int> matsuzaki;
    ++N;
    while(1){
      if(is_prime(N)){
        prime.push_back(N);
        REP(j,prime.size()){
          matsuzaki.push_back(prime[j]+N);
        }
        if(prime.size()>=P){
          break;
        }
      }
      N++;
    }
    // cerr << "----prime----" << endl;
    // REP(i, prime.size()) {
    //   cerr << prime[i] << endl;
    // }
    sort(matsuzaki.begin(),matsuzaki.end());
    // cerr << "----matsuzaki----" << endl;
    // REP(i, matsuzaki.size()) {
    //   cerr << matsuzaki[i] << endl;
    // }
    cout << matsuzaki[P - 1] << endl;
  }    
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  ll M;
  cin >>N>>M;
  
  if(2*N>M) {
    cout<<M/2<<endl;
  }
  else if(2*N<=M) {
    cout<<N+(M-2*N)/4<<endl;
  }
}
    


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

int memo[21][11][156];

int rec(int n, int k, int s){
    if(n == 0 || k == 0) return (k==0 && s==0 ? 1 : 0);
    // if(memo[n][k][s] != -1) return memo[n][k][s];
    int res = 0;
    for(int i=1;i<=min(n,s);i++){
        res += rec(i-1, k-1, s-i);
    }
    return memo[n][k][s] = res;
}

bool solve(){
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0) return true;
    memset(memo, -1, sizeof(memo));
    cout << rec(n, k, s) << endl;
    return false;
}

int main(){
    while(!solve());
    return 0;
}


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

int main() {
    int n;
    ll x;
    cin >> n >> x;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] + a[i - 1] > x) {
            ll dif = a[i] + a[i - 1] - x;
            ans += dif;
            a[i] = max(a[i] - dif, 0LL);
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ll num[60];
ll num_p[60];

ll calc(ll n, ll x){
    if(x == 0){
        return 0;
    }
    if(n == 0){
        return 1;
    }
    if(floor(num[n] / 2.0) >= x){
        return calc(n - 1, x - 1);
    }else if(ceil(num[n] / 2.0) <= x){
        return calc(n - 1, x - ceil(num[n] / 2.0)) + num_p[n-1] + 1;
    }
}

int main(void){
    ll n, x;
    cin >> n >> x;

    num[0] = 1;
    num_p[0] = 1;
    rep(i, 1, 51){
        num[i] = 2 * num[i-1] + 3;
        num_p[i] = 2 * num_p[i-1] + 1;
    }

    ll ans = calc(n, x);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
map<int,int> mi;
void bfs(list<int> v[],ll n,ll s)
{
    vector<bool> visi(n+1,false);
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        s=q.front();
        q.pop();
        visi[s]=true;
        list<int>::iterator it;
        for(it=v[s].begin();it!=v[s].end();it++)
        {
            if(!visi[*it])
            {
                mi[*it]=s;
                q.push(*it);
                visi[*it]=true;
            }
        }
    }
}
int main()
{
ll m,n;
cin>>n>>m;
list<int> v[n+1];
for(ll i=0;i<m;i++)
{
    ll x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
}
bfs(v,n,1);
    cout<<"Yes"<<endl;
    for(ll i=2;i<=n;i++)
        cout<<mi[i]<<endl;
}


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

int main(){
  char s[300], p[300], t[300];
  cin >> s;
  cin >> p;
  strcpy(t, s);
  strcat(s, t);
  if (strstr(s, p)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>
int main(void) {
    int n,max[2]={0},num,fish,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&num,&fish);
        if(i==0||fish>max[1]||(fish==max[1]&&num<max[0])) {
            max[0]=num;
            max[1]=fish;
        }
    }
    printf("%d %d\n",max[0],max[1]);
    return 0;
}

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

using namespace std;
typedef long long int ll;
char s[1000000];
int main() 
{
    
    string s1;
    cin>>s1;ll i,j;
    i=500000;
    j=i-1;

ll q;
cin>>q;ll c=0;
while(q--)
{
    
    ll x;
    cin>>x;
    
    
    
    if(x==2)
    {
       ll y;
       cin>>y;
       
       
       if(y==1)
       {
           
           if(c%2==0)
           {
           char q;cin>>q;
       s[j]=q;
       j--;
           }
           else
           {
                char q;cin>>q;
       s[i]=q;
       i++;
           }
           
       }
       else  if(y==2)
       {
       
       if(c%2==0)
       {
           char q;cin>>q;
       s[i]=q;
       i++;
       }
       else
       {char q;cin>>q;
       s[j]=q;
       j--;
           
           
           
           
       }
       
       
       }
       else
       {
       
       
           
           
       }
       
        
        
    }
    else if(x==1)
    {
        c++;
    }
    else
    {
        
    }
    
    
    
    
    
    
}


if(c%2==0)
{
    ll j1=j+1;
    while(j1<=500000-1)
    {
        cout<<s[j1];
        
        j1++;
    }
    cout<<s1;
    ll i1=500000;
    while(i1<=i-1)
    {
        cout<<s[i1];
        i1++;
    }
    
}
else
{
    //cout<<"lol!!";
    ll i1=i-1;
    while(i1>=500000)
    {
        
        cout<<s[i1];
        
        
        i1--;
    }
    ll o=s1.length()-1;
    while(o>=0)
    {
        
        cout<<s1[o];
        o--;
    }
    
    
    
    
    
    ll j1=500000-1;
    while(j1>=j+1)
    {
        cout<<s[j1];
        
        j1--;
    }
    
    
}

return 0;    
}

Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<ll,int>
#define vi vector<double>
#define vvi vector<vector<double>>
#define vpii vector<pii>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
 
    int t=1;
   // cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        int u=max((a+b),max(a-b,a*b));
        cout<<u<<endl;
    }
    return 0;
} 

Measured memory_bytes: 256
package main
import "fmt"
func main() {
  const mod int64 = 1000000007
  const u int = 60
  var n int64
  fmt.Scan(&n)
  var dp [][]int64 = make([][]int64,u+1)
  for i:=0;i<u+1;i++ {
    dp[i] = make([]int64,3)
  }
  dp[u][0] = 1
  for i:=u-1;i>-1;i-- {
    for j:=0;j<3;j++ {
      for k:=0;k<3;k++ {
        var t int64 = int64(2*j-k)+(n>>uint(i)&1)
        if t > 2 { t = 2 }
        if t > -1 {
          dp[i][t] += dp[i+1][j]
          dp[i][t] %= mod
        }
      }
    }
  }
  fmt.Println((dp[0][0]+dp[0][1]+dp[0][2])%mod)
}

Measured memory_bytes: 512
n=int(input())
A=[int(i) for i in input().split()]
B=[]
if n%2==0:
  for i in range(n//2):
    B.append(2*i+1)
    B.append(2*i+1)
  print(pow(2,n//2,10**9+7) if B==sorted(A) else 0)
else:
  B=[0]
  for i in range((n-1)//2):
    B.append(2*(i+1))
    B.append(2*(i+1))
  print(pow(2,(n-1)//2,10**9+7) if B==sorted(A) else 0)

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

ans = float('inf')
for k in range(n):
    ans = min(ans, sum(a) + x*k)
    a = [min(a, b) for a, b in zip(a, a[-1:]+a[:-1])]
print(ans)

Measured memory_bytes: 9332
S = input()
s_list = list(S)
s_list_i = [int(s) for s in s_list ]
a = int(s_list[0] + s_list[1])
b = int(s_list[2] + s_list[3])

if 1 <= a <= 12 or 1 <= b <= 12:
    if 1 <= a <= 12 and not 1 <= b <= 12:
        print('MMYY')
    elif not 1 <= a <= 12 and 1 <= b <= 12:
        print('YYMM')
    elif 1 <= a <= 12 and 1 <= b <= 12:
        print('AMBIGUOUS')
else:
    print('NA')


Measured memory_bytes: 3064
def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        if t[i+1] - t[i] < T:
            ans += t[i+1] - t[i]
        else:
            ans += T
    print(ans + T)


if __name__ == '__main__':
    main()


Measured memory_bytes: 102964
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  bool flag=false;
  for(int i=0;i<(int)s.size()-1;i++){
    for(int j=i+1;j<(int)s.size();j++){
      if(s[i]==s[j])flag=true;
    }
  }
  if(flag){
    P("no");
  }else{
    P("yes");
  }
  return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

n,m,c=MI()
b=LI()
A=LLI(n)

ans=0
for a in A:
    s=0
    for i in range(m):
        s+=a[i]*b[i]
    s+=c
    if s>0:
        ans+=1
print(ans)

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    ll n,w;
    cin>>n>>w;
    ll a[110],b[110];
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll dp[120][10020];
    rep(i,110)rep(j,10010) dp[i][j]=0;
    rep(i,n){
        rep(j,w+1){
            chmax(dp[i+1][j],dp[i][j]);
            if(j+b[i]<=w){
                // dp[i+1][j]=dp[i][j];
                chmax(dp[i+1][j+b[i]],dp[i][j]+a[i]);
            }
        }
    }
    ll ans=0;
    rep(i,w+1){
        chmax(ans,dp[n][i]);
    }
    /*
    rep(i,n+1){
        rep(j,w+1){
            cerr<<dp[i][j]<<" ";
        }
        cerr<<endl;
    }
    */
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    vl x(n);rep(i,n)cin>>x[i];
    ll ans=INF;
    rep(j,101){
        ll tmp=0;
        rep(i,n){
            tmp+=(x[i]-j)*(x[i]-j);
        }
        chmin(ans,tmp);
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
a_to_i = {a: i for i, a in enumerate(A, start=1)}

L = list(range(-1, N + 1))
R = list(range(1, N + 3))

ans = 0
for a in reversed(range(1, N + 1)):
    i = a_to_i[a]
    ans += a * (R[i] - i) * (i - L[i])
    L[R[i]] = L[i]
    R[L[i]] = R[i]

print(ans)

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int n;
vvi G;

int dfs(int node, int cost, vi& dv, vi& used){
  dv[node] = cost; used[node] = 1;
  rep(i, sz(G[node])){
    int x = G[node][i];
    if (!used[x]) dfs(x, cost+1, dv, used);
  }
  return 0;
}

int solve(){
  cin>>n;
  int a,b;
  G = vvi(n, vi(0));
  rep(i, n-1){
    cin>>a>>b;a--;b--;
    G[a].pb(b);
    G[b].pb(a);
  }

  vi used(100000);
  vi df(n, INF);  //fenc
  dfs(0, 0, df, used);
  dump(df);

  vi ds(n, INF);  //snuke
  used = vi(100000, 0);
  dfs(n-1, 0, ds, used);
  dump(ds);

  int fenc=0; int snuke=0;
  rep(i, n){
    if (df[i] <= ds[i]) fenc++;
    else snuke++;
  }
  cout << (fenc>snuke ? "Fennec" : "Snuke") << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}



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

int main() {
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll min_ans=100100100100;
  rep(i,100010){
    ll ans;
    ans=i*2*c+max(0,x-i)*a+max(0,y-i)*b;
    min_ans=min(min_ans,ans);
  }
  cout<<min_ans<<endl;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;

i64 n;
pair<i64, i64> a[MAXN];
map<i64, map<i64, vector<i64>>> q;

set<pair<i64, i64>> l[3];
set<pair<i64, i64>> r[3];


i64 R;

void ans() {
    i64 r0 = r[0].empty() ? 0 : max(0ll, r[0].begin()->first - l[0].rbegin()->first + 1);
    i64 r1 = r[1].empty() ? 0 : max(0ll, r[1].begin()->first - l[1].rbegin()->first + 1);

    R = max(R, r0 + r1);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    for (i64 i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }

    for (i64 i = 0; i < n; i++) {
        R = max(R, a[i].second - a[i].first + 1);
    }

    for (i64 i = 0; i < n; i++) {
        l[2].insert({ a[i].first, i });
        r[2].insert({ a[i].second, i });
    }

    for (i64 i = 0; i < n; i++) {
        l[2].erase({ a[i].first, i });
        r[2].erase({ a[i].second, i });

        R = max(R, (a[i].second - a[i].first + 1) + max(0ll, r[2].begin()->first - l[2].rbegin()->first + 1));

        l[2].insert({ a[i].first, i });
        r[2].insert({ a[i].second, i });
    }

    sort(a, a + n);

    // ---------------------------
    for (i64 i = 0; i < n; i++) {
        q[a[i].first][0].push_back(i);
        q[a[i].second][1].push_back(i);
    }

    for (i64 i = 0; i < n; i++) {
        l[1].insert({ a[i].first, i });
        r[1].insert({ a[i].second, i });
    }


    for (const auto& t : q) {
        i64 x = t.first;
        if (t.second.count(0)) {
            const auto& opn = t.second.at(0);

            for (auto i : opn) {
                l[0].insert({ a[i].first, i });
                r[0].insert({ a[i].second, i });

                l[1].erase({ a[i].first, i });
                r[1].erase({ a[i].second, i });

                ans();
            }
        }

        if (t.second.count(1)) {
            const auto& cls = t.second.at(1);

            for (auto i : cls) {
                l[1].insert({ a[i].first, i });
                r[1].insert({ a[i].second, i });

                l[0].erase({ a[i].first, i });
                r[0].erase({ a[i].second, i });

                ans();
            }
        }
    }

    cout << R << endl;


    return 0;
}

Measured memory_bytes: 67456
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
typedef bitset<64> b64;
int main(){
	b64 b;
	int n,x;
	cin>>n;
	vector<b64> v(n);
	for(int i=0,j;i<n;i++)for(cin>>j;j--;v[i][x]=1)cin>>x;
	int q,a;
	for(cin>>q;q--;){
		cin>>a;
		if(a==0)cin>>x,cout<<b[x]<<endl;
		if(a==1)cin>>x,b|=v[x];
		if(a==2)cin>>x,b&=~v[x];
		if(a==3)cin>>x,b^=v[x];
		if(a==4)cin>>x,cout<<((b&v[x])==v[x])<<endl;
		if(a==5)cin>>x,cout<<(b&v[x]).any()<<endl;
		if(a==6)cin>>x,cout<<(b&v[x]).none()<<endl;
		if(a==7)cin>>x,cout<<(b&v[x]).count()<<endl;
		if(a==8)cin>>x,cout<<(b&v[x]).to_ulong()<<endl;
	}
}


Measured memory_bytes: 3088
import java.util.Scanner;

/**
 * http://abc042.contest.atcoder.jp/tasks/arc058_a
 * @author Cummin
 */
public class Main {
        static int D[] = new int[10] ;
        
        public static void main(String[] args) {
        int N, K ;

         // データの読み込み
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        for (int i=0 ; i<K; i++) {
            D[sc.nextInt()]= 1 ;  // 嫌いな数字は D[n]=1
        }
        int NN[] = new int[5] ;
        int ND = 1 ; // Nの桁数
        int ANS ;
        ANS = N;
        for (int i=0 ; i<5 ;i++) {
            NN[i] = N % 10 ;
            N= N/10 ;
            if (N>0) ND++ ;
        }
        
        int NNst[] = new int[5] ;
        for (int i=0 ; i<ND; i++) {
            if (D[NN[i]]==0) NNst[i]= 0 ; //嫌いな数字でなければNNst[n]=0
                    else  NNst[i] = -1 ;
        }
        int MIN_D= -1 ;
        int MIN_D_nonzero = -1 ;
        int MAX_D= -1 ;
        for (int i=0 ; i<10; i++) {
            if ((MIN_D==-1)&&(D[i]==0)) MIN_D=i ;
            if ((0<i)&&(MIN_D_nonzero==-1)&&(D[i]==0)) MIN_D_nonzero=i ;
            if (D[i]==0) MAX_D=i ;
        }
        
        int Leftmost_D = -1 ;
        for (int i=0 ; i<ND ;i++) {
            if (NNst[i]==-1) {
                Leftmost_D = i ;
                if (NN[i] >= MAX_D) NNst[i+1] = -1 ;
            }
        }
        if (Leftmost_D==-1) ANS = ANS ;
        
        if (Leftmost_D==(ND-1)) { //最上位桁
            if (NN[Leftmost_D]<MAX_D) ANS = getnext(NN[Leftmost_D]) ;
            else ANS = MIN_D_nonzero *10 + MIN_D ;
            for (int j= 0 ; j<Leftmost_D; j++) {
                ANS =ANS * 10 + MIN_D ;
            }
        }
        else if (0<=Leftmost_D) {
            for (int j= ND-1 ; 0<=j ; j--) {
                if (j>Leftmost_D) ANS = ANS*10 + NN[j] ;
                else ANS =ANS*10 + getnext(NN[j]) ;
            }
        }
        System.out.println(ANS) ;
  
    }
    static int getnext(int a) {
        for (int i=a+1; i<10; i++){
            if (D[i]==1) continue ;
            else return i ;
        }
        return -1 ;
    }
}


Measured memory_bytes: 8788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    int num = 1;
    for (int i = 0; i < N; i++){
        if (num > K){
            num = num + K;
        }
        else {
            num = num + num;
        }
    }
    cout << num <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
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;
}

int main(){
    int n;
    cin >> n;
    int res = 0;
    for(int i=1;i<=n;i++){
        res += (n-1)/i;
    }
    cout << res << endl;
    return 0;
}

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

var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    lines.push(line);
});
reader.on('close', () => {
    const radius = parseInt(lines[0])
    const circle = radius * radius
    console.log(circle)
});

Measured memory_bytes: 7628
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  int ans=0;

  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i),ans+=a.at(i)-1;

  cout<<ans<<endl;
}

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

long long getNumberOfChange(long long size) {
	return size / 2;
}

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

	string s;
	long long k;

	cin >> s;
	cin >> k;

	bool single_pattern = true;
	for (int i = 0; i < s.size() - 1; ++i) {
		if (s[i] != s[i+1]) {
			single_pattern = false;
			break;
		}
	}
	if (single_pattern) {
		cout << getNumberOfChange(s.size() * k) << endl;
		return 0;
	}

	int start = 0;
	int end = s.size() - 1;

	while (s[start] == s[0]) ++start;
	while (s[end] == s[s.size()-1]) --end;

	long long res = 0;
	char prev = s[start];
	int count = 1;
	for (int i = start + 1; i <= end; ++i) {

		if (s[i] == prev) {
			++count;
		} else {
			res += getNumberOfChange(count) * k;
			prev = s[i];
			count = 1;
		}
	}
	res += getNumberOfChange(count) * k;

	if ((k == 1) || (s[0] != s[s.size()-1])) {
		res += getNumberOfChange(start) * k;
		res += getNumberOfChange(s.size() - 1 - end) * k;
	} else {
		res += getNumberOfChange(start);
		res += getNumberOfChange(s.size() - 1 - end);
		res += getNumberOfChange(start + s.size() - 1 - end) * (k-1);
	}

	cout << res << endl;

	return 0;
}


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

int n;
string s;
int a[100005]; //0 sheep, 1 wolf

bool able(){
    for(int i = 2; i < n; i++){
        if(a[i - 1] == 0){
            if(s[i - 1] == 'o') a[i] = a[i - 2];
            else a[i] = 1 - a[i - 2];
        }
        else{
            if(s[i - 1] == 'o') a[i] = 1 - a[i - 2];
            else a[i] = a[i - 2];
        }
    }
    bool f, g;
    if(a[n - 1] == 0){
        if(s[n - 1] == 'o') f = (a[0] == a[n - 2]);
        else f = (a[0] == 1 - a[n - 2]);
    }
    else{
        if(s[n - 1] == 'o') f = (a[0] == 1 - a[n - 2]);
        else f = (a[0] == a[n - 2]);
    }
    if(a[0] == 0){
        if(s[0] == 'o') g = (a[n - 1] == a[1]);
        else g = (a[1] == 1 - a[n - 1]);
    }
    else{
        if(s[0] == 'o') g = (a[1] == 1 - a[n - 1]);
        else g = (a[1] == a[n - 1]);
    }
    return f && g;
}

int main()
{
    cin >> n >> s;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            a[0] = i;
            a[1] = j;
            if(able()){
                for(int i = 0; i < n; i++){
                    if(a[i] == 0) cout << 'S';
                    else cout << 'W';
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];

    ll ans = 1;
    vector<int> hat(3);

    REP(i,n) {
        REP(j,4) {
            if (j == 3) {
                ans = 0; break;
            }
            if (v[i] == hat[j]) {
                ll m = 0;
                for(auto x:hat) {
                    if (x == v[i]) m++;
                }
                //cerr << m << endl;
                ans = modm(ans,m);
                hat[j]++;
                break;
            }
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>

typedef long long ll;

using namespace std;

int main() {
    ll N, P;
    cin >> N >> P;

    ll p = P;
    map<ll, int> primes;
    for (ll i = 2; i * i <= P; i++) {
        int k = 0;
        while (p % i == 0) {
            p /= i;
            k++;
        }
        if (k > 0) {
            primes[i] = k;
        }
    }
    if (p > 1) {
        primes[p] = 1;
    }

    ll output = 1;
    for (auto p : primes) {
        int k = p.second;
        while (k >= N) {
            output *= p.first;
            k -= N;
        }
    }
    cout << output << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a;
    Integer[] array = new Integer[n];
    double sum = 0;

    for(int i=0; i<n; i++){
      a = sc.nextInt();
      array[i] = a;
    }
    Arrays.sort(array,Comparator.reverseOrder());
    //for(int k=0; k<n; k++){
      //System.out.println(array[k]);
    //}
    for(int k=0; k<n-1; k++ ){
      double sub_sum = array[k]/Math.pow(2,k+1) ;
      sum += sub_sum;
      //System.out.println("sum:"+sum);
    }
    sum += array[n-1]/Math.pow(2,n-1);
    System.out.println(sum);
  }
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            HashSet<char> check = new HashSet<char>();

            foreach(char c in S)
            {
                if (!check.Add(c))
                {
                    Console.WriteLine("no");
                    return;
                }
            }
            Console.WriteLine("yes");
        }
    }
}


Measured memory_bytes: 13396
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 5*10**5 #Nの最大値
g1 = [1, 1] #元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, M = map(int, input().split())
ans = 0
for i in range(N+1):
    ans += cmb(N,i,mod)*((-1)**i)*g1[M]*g2[M-i]*((g1[M-i]*g2[M-N])**2)
    ans %= mod
print(ans)

Measured memory_bytes: 68288
//
//  main.cpp
//  112
//
//  Created by 耿英俊 on 2019/10/27.
//  Copyright © 2019 耿英俊. All rights reserved.
//

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char * argv[]) {
    int a;
    loop1:while(cin>>a){
//        for(int i=1;i<=9;i++){
//            for(int j=1;j<=9;j++){
//                if(a==i*j){
//                    cout<<"YES"<<endl;
//                    goto loop1;
//                }
//                if(a>81){
//                    cout<<"NO"<<endl;
//                    goto loop1;
//                }
//            }
//            if(i>9){
//                cout<<"NO"<<endl;
//                goto loop1;
//            }
//        }
        int s[81];
        int temp=0;
        int flag =0;
        for(int i=1;i<10;i++)
            for(int j=1;j<10;j++)
                s[temp++]=i*j;
        for(int temp=0;temp<81;temp++)
            if(a!=s[temp])
                flag=0;
            else{
                cout<<"Yes"<<endl;
                flag=1;
                break;
            }
        if(flag==0)
            cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s[200010];
int main(){
	int n,ans=0,l=0,r,flag;
	scanf("%d",&n);
	scanf("%s",s);
	while(s[l]=='R'){
		l++;
	}
	r=n-1;
	while(l<r){
		if(s[r]=='R'){
			flag=0;
			s[l]='R';
			s[r]='W';
			ans++;
			r--;
			for(int j=l+1;j<=r;j++){
				if(s[j]=='W'){
					l=j;
					flag=1;
					break;
				}
			}
			if(flag==0){
				l=r;
				break;
			} 
//			printf("%d %d %s\n",l,r,s);
		}
		else{
			r--;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1e9
using namespace std;
typedef long long ll;

int n;
vector <ll> vx;
ll x[200100];

int main(){
  cin >> n;
  rep(i,1,n+1){
    cin >> x[i];
    vx.push_back(x[i]);
  }
  sort(all(vx));
  ll med1 = vx[n/2-1];
  ll med2 = vx[n/2];
  rep(i,1,n+1){
    int hoge = lower_bound(all(vx), x[i])-vx.begin()+1;
    if(hoge <= n/2)std::cout << vx[n/2] << '\n';
    else std::cout << vx[n/2-1] << '\n';
    // if(x[i] > med1)std::cout << med1 << '\n';
    // else std::cout << med2 << '\n';
  }
}


Measured memory_bytes: 5488
#include <stdio.h>

#define MAX 101

int a[MAX][MAX];

int main(){
  int i,j,n,u,k,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(a[i][j] == NULL)a[i][j]=0;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      printf("%d ",a[i][j]);
    }
    printf("%d",a[i][n]);
    printf("\n");
  }
return 0;

}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int H, W, a = 0, cnt = 0;
		ArrayList<Integer> h = new ArrayList<Integer>();
		ArrayList<Integer> w = new ArrayList<Integer>();
		Scanner sc = new Scanner(System.in);
		while(a < 300){
			H = sc.nextInt();
			W = sc.nextInt();
			if(H == 0 && W == 0)
				break;
			h.add(new Integer(H));
			w.add(new Integer(W));
			a++;
		}
		for(cnt = 0; a > cnt; cnt++){
			if(cnt != 0)
				System.out.print("\n");
			for(int i = 0; i != h.get(new Integer(cnt)); i++){
				for(int j = 0; j != w.get(new Integer(cnt)); j++){
					if(i == 0 || i == h.get(new Integer(cnt)) - 1)
						System.out.print("#");
					else if(j == 0 || j == w.get(new Integer(cnt)) - 1)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.print("\n");
			}
		}
		System.out.print("\n");
	}
}

Measured memory_bytes: 39188
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))

import queue


def solve():
    N = int(input())
    As = list(map(int, input().split()))
    As.sort(reverse=True)

    score = 0

    q = queue.Queue()
    q.put(As[0])

    for a in As[1:]:
        score += q.get()
        q.put(a)
        q.put(a)

    return score


def main():
    print(solve())


if __name__ == "__main__":
    main()


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

int main(){
  int k,j=0;
  int set[10000];
  while(1){
    int i;
    scanf("%d",&i);
    if(i==0){
      break;
    }else{
      set[j]=i;
      j++;
    }    
  }
  for(k=0;k<j;k++){
    printf("Case %d: %d\n",k+1,set[k]);
  }
  return 0;
}



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

int x, y;
int res;

int main()
{
    cin >> x >> y;
    if (x <= 3) res += 4 - x;
    if (y <= 3) res += 4 - y;
    if (x == 1 && y == 1) res += 4;
    cout << res * 100000 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,ans=0;
    string s;
    cin>>n>>s;
    ll dp[5010][5010];
    rep(i,5010)rep(j,5010) dp[i][j]=0;
    for(ll i=n-1;i>=0;i--){
        for(ll j=n-1;j>i;j--){
            if(s[i]==s[j]){
                dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1);
            }
            ans = max(ans,min(dp[i][j],j-i));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 196480
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int dp[101][101];
int num[101][101];
bool comp(string a,string b){
	for(int i=0;i<min(a.size(),b.size());i++){
		if(a[i]-'a'<b[i]-'a'){
			return true;
		}else if(b[i]-'a'<a[i]-'a'){
			return false;
		}
	}
	return a.size()<b.size();
}
map<string,vector<int> >ma;
int main(){
	int cou=0;
	string str;
	int n;
	while( cin >> str !='\0'){
		scanf("%d",&n);
		ma[str].push_back(n);
	}
	map<string,vector<int> >::iterator ite;
	for(ite=ma.begin();ite!=ma.end();++ite){
		cout << ite->first << endl;
		vector<int>yu=ite->second;
		sort(yu.begin(),yu.end());
		cout << yu[0];
		for(int i=1;i<yu.size();i++){
			cout <<" " << yu[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1272