akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
bool is_prime(long long n) {  //素数判定
  for(int64_t i = 2; i * i <= n; i++) {
    if(n % i == 0) return false;
  }
  return true;
}
int solve(){
  ll h;
  cin >> h;
  ll ans = 0;
  ll i = 1;
  ll H = h;
  while(H / 2 >= 1){
    ans += i;
    i *= 2;
    H /= 2;
  }
  ll tmp = 0;
  while(pow(2,tmp) <= h)tmp++;
  cout <<dec <<  (ll)(ans + (pow(2,tmp - 1))) << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n);
    int ans=0;
    REP(i,n){
        cin>>vec[i];
        while(vec[i]%2==0){
            vec[i]>>=1;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
    string s;
    cin>>s;
    
    int n=s.length();
    
    vector<int> a[2];
    for(int i=0;i<n;++i)
    {
        if(s[i]=='R')
            a[0].pb(i);
        else
            a[1].pb(i);
    }
    
    vector<int> freq(n,0);
    int pos,tmp;
    
    for(int i=0;i<n;++i)
    {
        if(s[i]=='R')
        {
            pos=upper_bound(all(a[1]),i)-a[1].begin();
            
            tmp=a[1][pos]-i;
            if(tmp%2)
                ++freq[a[1][pos]-1];
            else
                ++freq[a[1][pos]];
        }
        else
        {
            pos=upper_bound(all(a[0]),i)-a[0].begin();
            --pos;
            
            tmp=i-a[0][pos];
            if(tmp%2)
                ++freq[a[0][pos]+1];
            else
                ++freq[a[0][pos]];
            
        }
    }
    
    for(auto c:freq)
        cout<<c<<" ";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 2372
#include <stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int a[3000];
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=a[i]-1;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(int *a, int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}//ちいさい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	long long int a,b,L,j,n,m=0,i,prime[10000],prime_num[100000]={0},a_prime[100005]={0},b_prime[100005]={0},num=1;

scanf("%lld%lld",&a,&b);
  L=a;
  if(b>a){
    L=b;
  }
  for(i=2;i<=L;i++){
  if(prime_num[i]==2){
    
  continue;
  }
    prime_num[i]=1;
    //printf("2_%lld\n",i);
     m++;
    prime[m]=i;
   
    for(j=2;j*i<=L;j++){
    prime_num[j*i]=2;
    }
  }
  
  for(i=1;i<=m&&a!=0;i++){
    while(a!=0){
      
    if(a%prime[i]==0){
    a_prime[i]++;
      a=a/prime[i];
      //printf("a is %lld now\n",a);
    }
     else{ 
       break;
     }
    }
  }

  for(i=1;i<=m&&b!=0;i++){
    while(b!=0){
      
    if(b%prime[i]==0){
    b_prime[i]++;
      b=b/prime[i];
      //printf("b is %lld now\n",b);
    }
      else{
      break;
      }
    }
  }
  
  for(i=1;i<=m;i++){
    if(a_prime[i]!=0||b_prime[i]!=0){
    if(a_prime[i]>b_prime[i]){
      //printf("a%lld=>%lld\n",prime[i],a_prime[i]);
    for(j=0;j<a_prime[i];j++){
    num=num*prime[i];
      
    }
    }
      else{
        //printf("b%lld=>%lld\n",prime[i],b_prime[i]);
      for(j=0;j<b_prime[i];j++){
    num=num*prime[i];
        if(num>100000){
        //printf("%lld\n",num);
        }
    }
      }
    }

  }
  //printf("%lld\n",a_prime[1]);
	printf("%lld",num);
return 0;
}


Measured memory_bytes: 4100
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int W = scan.nextInt();
        int H = scan.nextInt();
        int N = scan.nextInt();
        
        //int white_area = W * H;
        int whiteBox[][] = new int [W][H];
        
        int x[] = new int[N];
        int y[] = new int[N];
        int a[] = new int[N];
        
        int cnt = 0;
        
        for( int i = 0 ; i < N ; i++ ){
          x[i] = scan.nextInt();
          y[i] = scan.nextInt();
          a[i] = scan.nextInt();
        }
        
        for( int i = 0 ; i < W ; i++ ){
          for( int j = 0 ; j < H ; j++ ){
            whiteBox[i][j] = 0;
          }
        }
        
        for(int i = 0 ; i < N ; i++){
          
          if(a[i]==1){//xiの内側を塗る
            for(int ww = 0 ; ww < x[i] ; ww++){
              for(int hh = 0 ; hh < H ; hh++){
                whiteBox[ww][hh] = 1;
              }
            }
          }
          
          else if(a[i]==2){//xiの外側を塗る
            for(int ww = x[i] ; ww < W ; ww++){
              for(int hh = 0 ; hh < H ; hh++){
                whiteBox[ww][hh] = 1;
              }
            }
          }
          
          else if(a[i]==3){//yiの内側を塗る
            for(int hh = 0 ; hh < y[i] ; hh++){
              for(int ww = 0 ; ww < W ; ww++){
                whiteBox[ww][hh] = 1;
              }
            }
          }
          
          else if(a[i]==4){//yiの外側を塗る
            for(int hh = y[i] ; hh < H ; hh++){
              for(int ww = 0 ; ww < W ; ww++){
                whiteBox[ww][hh] = 1;
              }
            }
          }
          
        }
        
        for( int i = 0 ; i < W ; i++ ){
          for( int j = 0 ; j < H ; j++ ){
            if(whiteBox[i][j] == 0)cnt++;
          }
        }
        
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 22100
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#ifndef ONLINE_JUDGE
	#define ONLINE_JUDGE
#endif

#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define pb push_back
#define mp make_pair
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,j,n) for(i=j;i<=n;i++)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<int> > graph;
const ll maxn = (ll) 1e5+9;
const ll mod = (ll) 1e9+7;
//ll a[maxn];
bool d[20];
//ll dp[1024][1024];
string s;
string dig = "0123456789";
void filldigits(int);
int main()
{
	std::ios::sync_with_stdio(0);
	ll i,j,k,t,q,m,l,r,n;
	cin>>s>>k;
	//ans=s;
	repr(i,1,k){cin>>j;d[j]=true;}
	bool f=1;
	for(i=s.size()-1;i>=0;i--) {
		if(f==0) {
			repr(t,(s[i]-'0')+1,9) {
				if(d[t]==false) {
					f=1;
					s[i]=dig[t];
					filldigits(i);
					break;
				}
			}
		}
		if(d[s[i]-'0']==true) {
			repr(j,(s[i]-'0')+1,9) {
				if(d[j]==false) {
					f=1;
					s[i]=dig[j];
					filldigits(i);
					break;
				}
			}
			if(d[s[i]-'0']==true) {
				repr(j,0,(s[i]-'0')-1) {
					if(d[j]==false) {
						f=0;
						s[i]=dig[j];
						break;
					}
				}
			}
		}
	}
	if(!f) {
		repr(j,1,9) {
			if(d[j]==false) {
				filldigits(-1);
				s=dig[j]+s;
				break;
			}
		}
	}
	cout<<s<<endl;
}

void filldigits(int i) {
	int t,q;
	repr(t,i+1,s.size()-1) {
		repr(q,0,9) {
			if(d[q]==false) {
				s[t]=dig[q];
				break;
			}
		}
	}
}

Measured memory_bytes: 256
import Data.Sequence ((|>),(<|))
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.List

readInts = map (fst . fromJust . B.readInt) . B.words

main = do
 getLine
 as <- readInts <$> B.getLine
 let q = (pushpush as)
 let l = Q.length q
 let ret = if odd l then Q.reverse q else q
 putStrLn $ unwords $ Q.foldrWithIndex (\_ a acc -> show a : acc) [] ret

pushpush = fst . foldl' addq (Q.empty, False)

addq (q,False) a = (q |> a, True)
addq (q, True) a = (a <| q, False)

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

int main()
{
	int n = 0, a = 0, min = 1000001, max = -1000001;
	long ttl = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;
		if (min > a)
			min = a;
		if (max < a)
			max = a;
		ttl += a;
	}

	cout << min << " " << max << " " << ttl << endl;

    return 0;
}

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

int main(){
  
int N,a,b,count,countsum;
cin >> N >> a >> b;
count=0;
countsum=0;

for(int i = 1;i<=N ;++i){
    int j = i;
    count=0;                   

    while(j>0) {
        count += j % 10;
        j /= 10;
    }

    if(count >= a && count <= b) {
    countsum += i;
    }
}

cout << countsum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
vector<int>d(N);
for(int i=0;i<N;++i){
    cin>>d[i];
    }
sort(d.begin(),d.end());

int K = d[d.size()/2]-d[d.size()/2-1];
    cout<<K<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long a;

	std::cin >> a;

	std::cout << a * 2 * 3.141592 << std::endl;

	return 0;
}

Measured memory_bytes: 3788
n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
  if (ta[i-1][0]<=ta[i][0]) and (ta[i-1][1]<=ta[i][1]):
    pass
  else:
    l=ta[i-1][0]//ta[i][0]
    if ta[i-1][0]%ta[i][0]!=0:
      l+=1
    r=ta[i-1][1]//ta[i][1]
    if ta[i-1][1]%ta[i][1]!=0:
      r+=1
    ta[i][0]*=max(l,r)
    ta[i][1]*=max(l,r)
print(sum(ta[-1]))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
bool bo[10001000],vis[410];
int st[410],mp[410][410],part[410],top,js0,js1;
bool isprime(int p)
{
	if ((p<=2)||(!(p&1))) return false;
	for (int i=2;i*i<=p;i++) if (p%i==0) return false;
	return true;
}
bool search(int s)
{
	vis[s]=true;
	for (int i=1;i<=top;i++) if (mp[s][i])
	{
		if (!part[i]) {part[i]=s;return true;}
		else if ((!vis[part[i]])&&(search(part[i]))) {part[i]=s;return true;}
	}
	return false;
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) {int w;scanf("%d",&w);bo[w]=true;}
	for (int i=1;i<=10000001;i++) if (bo[i]^bo[i-1]) {st[++top]=i;if (i&1) js1++;else js0++;}
	for (int i=1;i<=top;i++) if (st[i]&1)
	for (int j=1;j<=top;j++) if (isprime(abs(st[i]-st[j]))) mp[i][j]=1;
	int sum=0;
	for (int i=1;i<=top;i++) if (st[i]&1)
	{
		memset(vis,0,sizeof(vis));
		sum+=search(i);
	}
	js0-=sum;js1-=sum;
	cout<<sum+js0+js1+(js0&js1&1)<<endl;
}

Measured memory_bytes: 8832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
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 Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    int N; cin >> N;
    vector<int> p(N), q(N);
    rep(i,N) cin >> p[i];
    rep(i,N) cin >> q[i];
    
    vector<int> order(N);
    rep(i,N) order[i] = i+1;

    bool flag;
    int p_num, q_num;
    int num = 0;
    do {
        flag = true;
        rep(i,N) if (p[i] != order[i]) flag = false;
        if (flag) p_num = num;
        flag = true;
        rep(i,N) if (q[i] != order[i]) flag = false;
        if (flag) q_num = num;
        ++num;
    } while (next_permutation(order.begin(), order.end()));
    
    out(abs(p_num - q_num));

    return 0;
}










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

d = collections.Counter(D)
t = collections.Counter(T)

for i in T:
  if d[i] < t[i]:
    print("NO")
    exit()
    
print("YES")
    

Measured memory_bytes: 127572
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main(){
ll a[3];
  cin >>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  ll ans=a[2]-a[1];
  ans+=a[1]-a[0];
  cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll a,b;
  cin >>a>>b;
  if(a>=13)cout <<b<<endl;
  else if(6<=a&&a<=12) cout <<b/2<<endl;
  else if(a<=5) cout <<0<<endl;
}


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

using ll = long long;

void solve(long long N){
    ll ans = 0;
    vector<int> cnt(N + 1);
    //ll cou = 0;
    for(ll i = 1;i <= N;i++){
        ll cntt = 1;
        while(cntt * i <= N){
            cnt[cntt * i]++;
            cntt++;
            //cou++;
        }
        ans += (ll)cnt[i] * i;
    }
    //cout<<cou<<endl;
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 42304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll f[maxn],invf[maxn];
ll qpow(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1)
            res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
void init()
{
    invf[0]=f[0]=1;
    for(ll i=1;i<maxn;i++)
        f[i]=f[i-1]*i%mod;
    invf[maxn-1]=qpow(f[maxn-1],mod-2);
    for(ll i=maxn-2;i>0;i--)
        invf[i]=invf[i+1]*(i+1)%mod;
}
ll c(ll a,ll b)
{
    ll n=a+b-2;
    ll m=a-1;
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int main()
{
    init();
    int h,w,a,b;
    while(~scanf("%d%d%d%d",&h,&w,&a,&b))
    {
        ll ans=0;
        for(int i=b+1;i<=w;i++)
        {
            ans=(ans+c(h-a,i)*c(a,w-i+1)%mod)%mod;
        }
        printf("%lld\n",ans);
    }
}



Measured memory_bytes: 3328
use std::io;
use std::io::prelude::*;

fn dfs(m: u64, n: u64) -> usize {
    if m > n {
        return 0;
    }
    let m_str = m.to_string();
    let flag = m_str.contains('3') && m_str.contains('5') && m_str.contains('7');
    return if flag { 1 } else { 0 }
        + dfs(m * 10 + 3, n)
        + dfs(m * 10 + 5, n)
        + dfs(m * 10 + 7, n);
}

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let n: u64 = buf.trim().parse().unwrap();

    println!("{}", dfs(0, n));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int MOD = 1e9 + 7;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int h,n;
ll dp[10010];

int main(){
    cin >> h >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    ll nin = INF;
    rep(i,n){
        nin = min(nin,a[i]);
    }
    // cout << nin << endl;
    rep(i,10010){
        dp[i] = INF;
    }
    dp[0] = 0;
    // rep(i,nin){
    //     dp[i] = 0;
    // }
    // int tmp = 1;
    for(int i=1;i<10010;i++){
        for(int j=0;j<n;j++){
            //dp更新式
            if(i-a[j]>=0&&dp[i]>dp[i-a[j]]+b[j]){
                for(int k=0;k<=i;k++){
                    dp[k] = min(dp[k],dp[i-a[j]]+b[j]);
                }
                //tmp更新
            }
            // else
                // dp[i] = min(dp[i],dp[i-1]);
        }
        // if(dp[tmp]!=INF)
            // tmp = i+1;

    }
    ll ans = dp[h];
    ll ans2 = dp[4000];
    cout << dp[h] << endl;
    return 0;    
}

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

int main() {
	int da, n,p=0,q=0;
	cin >> da >> n;
	int hot[210] = {0};
	int wear[3][210];
	int d[210][210] = {0};
	int kiroku[2][210] = {0};
	for (int i = 0; i < da; i++) {
		cin >> hot[i];
		
	}
	for (int i = 0; i < n; i++) {
		cin >> wear[0][i] >> wear[1][i] >> wear[2][i];
		
	}
	for (int i = 0; i < da; i++) {

		p = 0;
		for (int j = 0; j < n; j++) {
			
		
			if (wear[0][j] <= hot[i] && wear[1][j] >= hot[i]) {
				
				if (i == 0) {
					d[i][j] = wear[2][j];
					kiroku[1][p] = j;
					
				}
				else if (i == 1) {
					for (int k = 0; k<q; k++) {
						int a;
						if (wear[2][kiroku[0][k]] < wear[2][j]) {
							a = wear[2][j] - wear[2][kiroku[0][k]];
						}
						else {
							a = wear[2][kiroku[0][k]] - wear[2][j];
						}
				
						if (a  > d[i][j]) {
							d[1][j] = a ;
						}
						
						kiroku[1][p] = j;
						
						
					}
				}
				else {
					for(int k=0;k<q;k++){
						int a;
						if (wear[2][kiroku[0][k]] < wear[2][j]) {
							a=wear[2][j] - wear[2][kiroku[0][k]];
						}
						else {
							a = wear[2][kiroku[0][k]] - wear[2][j];
						}
						
						if (a + d[i - 1][kiroku[0][k]] > d[i][j]) {
							d[i][j] = a + d[i - 1][kiroku[0][k]];
							kiroku[1][p] = j;
							
						}
						
						kiroku[1][p] = j;

						
					}
				}
				p++;
				

			}

			
			
		}
		q = p;
		
		for (int k = 0; k < q; k++) {
			
			kiroku[0][k] = kiroku[1][k];
		}
		
	}
	int max = d[da - 1][0];
	for (int i = 1; i < n; i++) {
		if (d[da - 1][i] > max) {
			max = d[da - 1][i];
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll power(ll x, ll n) {
  if (n == 0) {
    return 1;
  } else if (n > 0 && n % 2 == 0) {
    return ((power(x, n / 2) % MOD) * (power(x, n / 2) % MOD)) % MOD;
  } else if (n > 0 && n % 2 != 0) {
    return ((power(x, (n - 1) / 2) % MOD) * (power(x, (n - 1) / 2) % MOD) * x) %
           MOD;
  } else {
    return -1;
  }
}

ll abc050c(ll n, vector<ll> a) {
  ll i;

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

  if (n % 2 == 0) {

    for (i = 0; i < n; i += 2) {
      if (a[i] != i / 2 * 2 + 1 || a[i + 1] != i / 2 * 2 + 1) {
        return 0;
      }
    }
    return power(2, n / 2);

  } else {

    if (a[0] != 0) {
      return 0;
    }

    for (i = 1; i < n; i += 2) {
      if (a[i] != i / 2 * 2 + 2 || a[i + 1] != i / 2 * 2 + 2) {
        return 0;
      }
    }
    return power(2, (n - 1) / 2);
  }
}

int main() {
  ll i, n;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << abc050c(n, a) << "\n";
  return 0;
}

Measured memory_bytes: 1792
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())

n = make_divisors(N)
n.sort()
mannaka_ = int(len(n)/2)
mannaka = mannaka_ - 1
#print(n)
if len(n)%2 == 0:
    print((n[mannaka_]-1)+ (n[mannaka]-1))
else:
    print(n[mannaka_] * 2 - 2)

Measured memory_bytes: 3296
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e16;
	const ll MOD = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	ll dp[102][10];

	signed main(){
		IOS;
		ll h, w, k;
		cin >> h >> w >> k;
		Fill(dp,0);
		dp[0][0] = 1;
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				ll left = 0;
				ll right = 0;
				ll center = 0;
				for(int t = 0;t < (1 << w - 1);t++){
					bitset<7> bi(t);
					bool ok = true;
					for(int s = 0;s < w - 2;s++){
						if(bi[s] && bi[s + 1])ok = false;
					}
					if(ok && j != 0 && bi[j - 1])left++;
					if(ok && j != w - 1 && bi[j])right++;
					if(ok && !bi[j - 1] && !bi[j])center++;
				}
				if(j != w - 1)dp[i + 1][j] += dp[i][j + 1] * right;
				if(j != 0)dp[i + 1][j] += dp[i][j - 1] * left;
				dp[i + 1][j] += dp[i][j] * center;
				dp[i + 1][j] %= MOD;
			}
		}
		dump(dp[h][k - 1]);
	}

Measured memory_bytes: 256
#include <bitset>
#include <utility>
#include <tuple>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <map>
#include <iterator>
#include <algorithm>
#include <iostream>

int main() {
    int A,B,C,K, sum = 0;
    std::cin >> A >> B >> C >> K;

    if (A < K) {
        K -= A;
        sum += A;
    } else {
        sum += K;
        std::cout << sum;
        return 0;
    }
    if (B < K) {
        K -= B;
    } else {
        K = 0;
    }
    if (K > 0) {
        sum -= K;
    }
        
    std::cout << sum;
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end();
int main() {
  int a,b,c=0,d,sum=0;
  cin >> a >> b;
  rep(i,a){
    cin >> d;
    sum += d;
    if(b<sum)break;
    c++;
  }
  cout << c+1;
}

Measured memory_bytes: 3528
#include<iostream>
using namespace std;
typedef long long ll;
signed main(){
  ll n,time,at=0,bt=0;
  cin >> n;
  ll a[n],b[n],asum=0,bsum=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    asum+=a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
    bsum+=b[i];
  }
  time = bsum-asum;
  if(time<0){
    cout <<"No\n";
    return 0;
  }
  for(int i=0;i<n;i++){
    if(a[i]>b[i]){
      bt+=a[i]-b[i];
    }else if(a[i]<b[i]){
      at+=(b[i]-a[i])/2;
    }
  }
  if(at>=bt){
    cout <<"Yes\n";
  }else{
    cout <<"No\n";
  }
}


Measured memory_bytes: 384
# coding: utf-8
# Your code here!
s = input()
t = input()


ok=1
sset=[[] for i in range(26)]
for i in range(len(s)):
    n=ord(s[i])-ord("a")
    sset[n].append(i)

tset=[[] for i in range(26)]
for i in range(len(t)):
    n=ord(t[i])-ord("a")
    tset[n].append(i)

for i in sset:
    if i not in tset:
        ok=0
#print(sset)
#print(tset)
if ok==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20656
#include <stdio.h>

int main(void) {
  int x, y, z, n;
  
  scanf("%d %d %d",&x, &y, &z);
  
  n = x % (z + y);
  if (n < z){
  printf("%d", (x / (z + y) - 1));
  }else{
    printf("%d", (x / (z + y)));
  }
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int i, j, x, y;
  int n, mgsq[15][15];

  scanf("%d", &n);

  while(n != 0){
    /* ????????£????????? */
    for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
        mgsq[i][j] = 0;
      }
    }
    /* ????????£?????? */
    x = n/2;
    y = n/2+1;
    mgsq[x][y] = 1;
    for(i = 2; i <= n*n; i++){
      x++;
      y++;
      while(1){
        if(x >= n){
          x = 0;
        }else if(x < 0){
          x = n-1;
        }else if(y >= n){
          y = 0;
        }else if(mgsq[x][y] != 0){
          x--;
          y++;
        }else{
          mgsq[x][y] = i;
          break;
        }
      }
    }
    /* ????????£?????? */
    for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
        printf("%4d", mgsq[j][i]);
      }
      printf("\n");
    }
    scanf("%d", &n);
  }
  
  return 0;
}

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

using namespace std;

int main() {
   while(true){
       int x, y; cin >> x >> y;
       if((x == 0) && (y == 0)) {
           break;
        }else if(x <= y) {
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
}


Measured memory_bytes: 3116
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=0;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	string c;
	cin>>c;
	if(c=="a" ||c=="i" ||c=="u" ||c=="e" ||c=="o"){
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    vector<int> v{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};
    int k; cin >> k;
    cout << v[k-1];

}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<vector>

using namespace std;
const int maxn = 3005;
const long long inf = 10000000000007;
struct Node{
	vector<int> t;
	vector<int> c;
}node[maxn];
int vis[maxn];
long long ans[maxn];
int to[maxn*maxn];
void init()
{
	for(int i=0;i<maxn;i++)
	{
		ans[i]=-inf;
		vis[i]=0;
	}
}
long long BFS(int n,int m)
{
	to[0]=1;
	int l=0;
	int r=0;
	while(l<=r)
	{
		int temp=to[l];
		for(int i=0;i<node[temp].t.size();i++)
		{
			if(vis[node[temp].t[i]]<=m)
			{
				vis[node[temp].t[i]]++;
				if(l==0)ans[node[temp].t[i]]=max((long long)node[temp].c[i],ans[node[temp].t[i]]);
				else ans[node[temp].t[i]]=max(ans[temp]+node[temp].c[i],ans[node[temp].t[i]]);
				to[++r]=node[temp].t[i];
			}
			if(node[temp].t[i]==1&&ans[1]>0)return -inf;
		}
		l++;
	}
	return ans[n];
}
int main(){
	init();
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		node[a].t.push_back(b);
		node[a].c.push_back(c);
	}
	long long ans1=BFS(n,n-1);
	long long ans2=BFS(n,n);
	if(ans1!=ans2||ans1==-inf||ans2==-inf)
	{
		printf("inf\n");
	}
	else printf("%lld\n",ans2);
	return 0;
} 

Measured memory_bytes: 4608
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0206

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        L = int(input())
        if L == 0:
            break
        ans = 'NA'
        for i in range(1, 12+1):
            if ans == 'NA':
                M, N = map(int, input().split())
                L -= (M - N)
                if L <= 0:
                    ans = i
            else:
                _ = input()
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7752
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: usize,
        p: [(isize, isize); n],
    }

    let mut ans = 0;
    for (x, y) in p {
        if x * x + y * y <= (d * d) as isize {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7856
#include <bits/stdc++.h>
using namespace std;
struct unionfind {

    int par[10005];
    int rank[100005];

    void init (int N) {
        for(int i=0; i<N; i++) {
            par[i]=i;
            rank[i]=0;
        }
    }

    int  root(int x) {
        if(par[x]==x) {
            return x;
        }
        else {
            return par[x]=root(par[x]);
        }
    }

    void unite (int x, int y) {
        x=root(x);
        y=root(y);
        if(x==y) return;
        if(rank[x]<rank[y]) {
            par[x]=y;
        }
        else {
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return root(x)==root(y);
    }
};

int main() {
    int n, q, a, b, t;
    cin >> n >> q;

    unionfind tree;
    tree.init(n);
    for(int i=0; i<q; i++) {
        cin >> t >> a >> b;
        if(t==0) {
            tree.unite(a,b);
        }
        else {
            if(tree.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3208
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            calc = a * 500 + b * 100 + c * 50
            if calc == X:
                res += 1

print(res)

Measured memory_bytes: 3060
//実装できなくて答え見た
//きれいなコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  int table[n-1][3];
  rep(i,n-1){
    rep(j,3){
      cin >> table[i][j];
    }
  }
  vector<int> ans(n);
  rep(i,n-1){
    int now=table[i][1]+table[i][0];
    for(int j=i+1;j<n-1;j++){
      if(table[j][1]>=now)
        now=table[j][1];
      else{
        int a=table[j][1];
        while(1){
          a+=table[j][2];
          if(now<=a){
            now=a;
            break;
          }
        }
      }
      now+=table[j][0];
    }
    ans[i]=now;
  }
  rep(i,n)
    cout << ans[i] << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<char> c(n);
  rep(i,n) cin >> c[i];
  int r=0;
  rep(i,n){
    if(c[i]=='R') ++r;
  }
  int fw=0;
  rep(i,r) if(c[i]=='W') ++fw;
  int lr=0;
  for(int i=r;i<=n;++i) if(c[i]=='R')++lr;
  int ans;
  if(fw>lr) ans=fw;
  if(fw<=lr) ans=lr;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3560
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
//FizzBuzz
public class Main{
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int n = sc.nextInt();
            if((m|n)==0)break;
            List<Integer> p = new ArrayList<Integer>();
            for(int i=1;i<=m;i++)p.add(i);
            int k = 1;
            int pos = 0;
            while(n--!=0){
                String s = sc.next();
                if(p.size()==1)continue;
                String c = k+"";
                if(k%15==0)c="FizzBuzz";
                else if(k%5==0)c="Buzz";
                else if(k%3==0)c="Fizz";
                if(c.equals(s))pos=(pos+1)%p.size();
                else {
                    p.remove(pos);
                    pos %= p.size();
                }
                k++;
            }
            boolean h = true;
            for(int x:p){
                if(!h)System.out.print(" ");
                h = false;
                System.out.print(x);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 71364
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


/*
vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}
*/

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}


int main(){
	ll n,m,s[M],t[M];
	cin>>n>>m;
	ll dp[2001][2001]={};
	rep(i,0,n)cin>>s[i];
	rep(i,0,n+1)dp[i][0]=1;
	rep(j,0,m)cin>>t[j];
	rep(j,0,m+1)dp[0][j]=1;

	rep(i,1,n+1){
		rep(j,1,m+1){
			dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
			if(s[i-1]==t[j-1])dp[i][j]+=dp[i-1][j-1];
			dp[i][j]=(dp[i][j]+inf)%inf;
		}
	}

	print(dp[n][m]);
}


Measured memory_bytes: 34688
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int x,ans=0;
  cin>>x;

  ans+=(x/500)*1000;
  x=x%500;
  ans+=(x/5)*5;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi h(n), dp(n, 1000000010);
  rep(i, n) cin >> h[i];
  dp[0] = 0;
  rep(i, n - 1){
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    if(i != n - 2) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(void)
{
    long long n, d; cin >> n >> d;
    long long x, y, r2;
    long long ans = 0;
    long long flag;
    for (long long i = 0; i < n; i++)
    {
        cin >> x >> y;
        r2 = x * x + y * y;
        if (d*d >= r2) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a;
  cin >> a;
  if (a==3 || a==5 || a==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main() {
    int N;
    map<ll, int> mp;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        mp[A]++;
    }
    int ans = 0;
    for (auto ite = mp.rbegin(); ite != mp.rend(); ++ite) {
        if (ite->second == 0) continue;

        ll x = pow(2, floor(log2(ite->first)) + 1);
        auto ite1 = mp.lower_bound(x - ite->first);

        if (ite1->first + ite->first == x) {
            if (ite1->first == ite->first) {
                int c = ite->second / 2;
                ite->second -= c;
                ite1->second -= c;
                ans += c;
            } else {
                int c = min(ite->second, ite1->second);
                ite->second -= c;
                ite1->second -= c;
                ans += c;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int strlen = s.size();
  char first = s.at(0),
  	   last = s.at(strlen - 1);
  strlen -= 2;
  string len = to_string(strlen);
  
  string sum = first + len + last;
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = LLONG_MAX;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }

int main()
{
    int N;
    cin >> N;
    cout << 24-N + 24 << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}
map<int , int >mp;
set<int  > st;
multiset<string> :: iterator it;
deque <char> q ;
int vis [10000000];
pair<int,int> a[2020];
int main()
{
    fast ;
    ll n;
    cin >> n;

    map<ll,ll>m;
    ll  c = 0;
    for ( int i=1; i<=n; i++)
    {
        ll f;cin>> f;
        m[f]++;
        c+=f;
    }
    w(t)
    {
        ll a ,b;
        cin >> a >> b;
        c -= m[a]*a;
        c+=m[a]*b;
        m[b] += m[a];
        m[a]=0;
        cout << c <<endl;


    }



}



Measured memory_bytes: 9452
const input = require("fs").readFileSync("/dev/stdin", "utf8")

const lines = input.split('\n')
let [a, b, c, d] = lines[0].split(' ').map(BigInt)

function max () {
    let res = arguments[0]
    for (var i = 1; i < arguments.length; i++) {
        res = res > arguments[i] ? res : arguments[i]
    }
    return res
}

console.log(max(a * c, a * d, b * c, b * d).toString())


Measured memory_bytes: 29676
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (100010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
typedef vector<int> vc;
int n,m;
vc a,b,inva,invb,t[N],tmp,tmp2,ans;
vc getinv(vc a){
	vc t; t.resize(n+1);
	for(int i=1;i<=n;i++)
	t[a[i]]=i;
	return t;
}
vc mul(vc a,vc b){
	vc c; c.resize(n+1);
	for(int i=1;i<=n;i++)
	c[i]=a[b[i]];
	return c;
}
vc ksm(vc a,int p){
	vc res; res.resize(n+1);
	for(int i=1;i<=n;i++)res[i]=i;
	while(p){
		if(p&1)res=mul(res,a);
		a=mul(a,a),p>>=1;
	}
	return res;
}
int main(){
	read(n),read(m),a.resize(n+1),b.resize(n+1); 
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1;i<=n;i++)read(b[i]);
	inva=getinv(a),invb=getinv(b);
	t[1]=a,t[2]=b;
	for(int i=3;i<=6;i++)t[i]=mul(t[i-1],getinv(t[i-2]));
	tmp=mul(mul(mul(b,inva),invb),a); tmp2=getinv(tmp); int K=(m-1)/6;
	ans=mul(mul(ksm(tmp,K),t[(m-1)%6+1]),ksm(tmp2,K));
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);
}

Measured memory_bytes: 14960
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int D[500][500];
int c[500][500];
map <int, int> color_count_map[3];
int main(){
   int N;
   int C;
   cin >> N >> C;
   for(int i = 0; i < C; i++){
       for(int j = 0; j < C; j++){
           cin >> D[i][j];
       }
   }
   for(int i = 0; i < N; i++){
       for(int j = 0; j < N; j++){
           cin >> c[i][j];
       }
   }

   for(int i = 0; i < N; i++){
       for(int j = 0; j < N; j++){
           int mod3 = (i + j) % 3;
           if(color_count_map[mod3].find(c[i][j]) != color_count_map[mod3].end()){
               color_count_map[mod3][c[i][j]] += 1;
           } else {
               color_count_map[mod3][c[i][j]] = 1;
           }
       }
   }

    int ans = INT_MAX;
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            for(int k = 0; k < C; k++){
                if(i == j || j == k || i == k){
                    continue;
                }
                int tmp_cost = 0;
                vector <int> tmp_colors{i, j, k};
                for(int l = 0; l < 3; l++){
                    for(auto it = color_count_map[l].begin(); it != color_count_map[l].end(); it++){
                        tmp_cost += it->second * D[it->first - 1][tmp_colors[l]];
                    }
                }
                ans = min(ans, tmp_cost);

            }
        }
    }
    cout << ans << endl;
   return 0;
}


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

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

int main()
{
  int n; cin >> n;
  vector<int> data(n); REP(i,n) cin >> data[i];
  vector<ll> dp(100010);  REP(i,n) dp[i] = INF;
 
  dp[0] = 0;
  
  REP(i,n){
    chmin(dp[i],dp[i-1]+abs(data[i] - data[i-1]));
    if(i > 1)
    chmin(dp[i],dp[i-2]+abs(data[i] - data[i-2]));
    
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;main(){int N,A,B,C,D;string S;cin>>N>>A>>B>>C>>D;cin>>S;if(S.substr(A-1,C-A+1).find("##")==string::npos&&S.substr(B-1,D-B+1).find("##")==string::npos){if(C<D){cout<<"Yes"<<'\n';}else if(S.substr(B-2,D-B+3).find("...")!=string::npos){cout <<"Yes"<<'\n';}else{cout<<"No"<<'\n';}}else{cout<<"No"<<'\n';}}

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


def solve(A: int, B: int):
    print("error" if A + B >= 10 else A + B)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int k,x;
	cin >> k >> x;
	if ((500 *k) >= x) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256