akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 pre[200005];

ll f(ll x){
    if(x == 0) return 0;
    if(pre[x] > 0) return pre[x];
    ll div = 0;
    rep(j,30){
        if(x>>j & 1) ++div;
    }
    if(div == 0) return 0;
    ll ret = f(x%div) + 1;
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    memset(pre, 0, sizeof(pre));
    pre[1] = 1;
    for(int i = 2; i <= 200002; ++i){
        pre[i] = f(i);
    }
    ll pc = 0;
    rep(i,n){
        if(s[i] == '1') ++pc;
    }
    ll lc = pc - 1, uc = pc + 1;
    if(pc <= 1) lc = 1;
    ll lx = 0, ux = 0;
    rep(i,n){
        lx = (lx * 2) % lc;
        ux = (ux * 2) % uc;
        if(s[i] == '1'){
            lx = (lx + 1) % lc;
            ux = (ux + 1) % uc;
        }
    }
    vector<ll> ans(n);
    ll tl = 1, tu = 1;
    for(int i = n-1; i >= 0; --i){
        ll num = 0;
        if(s[i] == '1'){
            if(pc == 1) num = 200010;
            else num = (lx + lc - tl) % lc;
        }
        else{
            num = (ux + tu) % uc;
        }
        ans[i] = num;
        tl = (tl * 2) % lc;
        tu = (tu * 2) % uc;
    }
    pre[200010] = -1;
    rep(i,n) cout << pre[ans[i]] + 1 << endl;
    return 0;
}


Measured memory_bytes: 6728
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        int ans = 7;

        switch (s) {
            case "SUN":
                break;
            case "MON":
                ans = 6;
                break;
            case "TUE":
                ans = 5;
                break;
            case "WED":
                ans = 4;
                break;
            case "THU":
                ans = 3;
                break;
            case "FRI":
                ans = 2;
                break;
            case "SAT":
                ans = 1;
                break;
        }

        System.out.println(ans);
    }
}

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

int main(){
    int i, j;
    string s;
    cin >> s;
    for(i=1; i<s.size()/2; i++){
        for(j=0; j<s.size()/2-i; j++){
            if(s[j] != s[j+s.size()/2-i]){
                j = 200;
            }
            if(j == s.size()/2-i-1){
                cout << s.size()-2*i;
                return 0;
            }
        }
    }
    cout << 0;
    return 0;
}

Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin); i < (end); i++)
#define _irep3(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  int N;
  string S, T;
  cin >> N >> S >> T;
  string ans = "";
  for (int i = 0; i < N; i++) {
    ans += S[i];
    ans += T[i];
  }
  out(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main(){
    i64 n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n<k) cout<<n*x<<endl;
    else cout<<k*x+(n-k)*y<<endl; 
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const ll INF = 1e15;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  ll ans = INF;
  for (ll i = 1; i < sqrt(N) + 1; ++i)
  {
    if (N % i == 0)
      ans = min(ans, i + N / i - 2);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure main is
   R: Integer;
   Pi: Float;
begin
   Pi := 3.14159;
   get(R);
   put(Float(R) * 2.0 * Pi, 0, 2, 0);
end main;

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    rep(i, n+1, 1)
    {
        double q = sqrt(i);
        if ((ll)q == q)
            return cout << i, 0;
    }
    return 0;
}

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

void sort(int* num, int n);
void output(int* num, int n);

int main(){
  int n;
  cin >> n;
  int* num;
  num = new int[n];
  for(int i = 0; i < n; i++) cin >> num[i];
  sort(num, n);
  output(num, n);
  delete[] num;
  return 0;
}

void sort(int* num, int n){
  for(int i = 1; i <= n - 1; i++){
    output(num, n);
    int v = num[i];
    int j = i - 1;
    while(j >= 0 && num[j] > v){
      num[j + 1] = num[j];
      j--;
    }
    num[j + 1] = v;
  }
}

void output(int* num, int n){
  for(int i = 0; i < n; i++){
    if(i == n - 1) cout << num[i];
    else cout << num[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 3072
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
 
import java.util.*;
class Main {
 
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
 
        System.out.printf("%.6f %.6f",r*r*Math.PI,2 * Math.PI*r);
    }
}


Measured memory_bytes: 28384
#include<bits/stdc++.h>
#define int long long
using namespace std;
int mod=1e9+7;
string lcs(string s,string t){	
	int x=s.size(), y=t.size();
	int arr[x+1][y+1];
	for(int i=0;i<=x;++i){
		for(int j=0;j<=y;++j){
			if(i==0 || j==0)
			arr[i][j]=0;
			else if(s[i-1]==t[j-1])
			arr[i][j]=1+arr[i-1][j-1];
			else 
			arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
		}
	}
	string ret="";
	int i=x,j=y;
	while(i>0 && j>0){
		if(arr[i][j]-arr[i-1][j-1]==1 && s[i-1]==t[j-1]){
			ret+=s[i-1];
			i--; j--;
		}else if(arr[i][j]==arr[i-1][j]){
			i--; 
		}else 
		j--;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
void grid1(){
	int h,w;
	cin>>h>>w;
	string s[h];
	for(int i=0;i<h;++i) cin>>s[i];
	int ways[h][w];
	for(int i=0;i<h;++i)
	for(int j=0;j<w;++j)
	ways[i][j]=0;
	bool fg=false;
	for(int i=0;i<w;++i){
		if(s[0][i]=='#')
		fg=true;
		if(fg) ways[0][i]=0;
		else ways[0][i]=1;
	}
	fg=false;
	for(int i=0;i<h;++i){
		if(s[i][0]=='#')
		fg=true;
		if(fg) ways[i][0]=0;
		else ways[i][0]=1;
	}
	for(int i=1;i<h;++i)
	for(int j=1;j<w;++j)
	if(s[i][j]=='#')
	ways[i][j]=0;
	else{
		ways[i][j]=ways[i-1][j]+ways[i][j-1];
		ways[i][j]%=mod;
	} 
	cout<<ways[h-1][w-1];
}
void knapsack2(){
	int n,w;
	cin>>n>>w;
	int we[n],val[n];
	for(int i=0;i<n;++i)
	cin>>we[i]>>val[i];
	bool poss[100005];
	int wei[100005];
	for(int i=0;i<100005;++i){
		poss[i]=false;
		wei[i]=LLONG_MAX;
	}
	poss[0]=true;
	wei[0]=0;
	for(int i=0;i<n;++i){
		for(int j=100004;j>=0;--j){
			if(j<val[i])
			break;
			if(poss[j-val[i]]){
				poss[j]=true;
				wei[j]=min(wei[j],wei[j-val[i]]+we[i]);
			}
		}
	}	
	for(int i=100004;i>=0;--i){
		if(poss[i] && wei[i]<=w){
			cout<<i;
			return ;
		}
	}
}
void solve(){
	int n; cin>>n;
	vector<int> v(n); 
	for(int i=0;i<n;++i)
	cin>>v[i];
	sort(v.begin(),v.end());
	int f=v[n-1];
	for(int i=1;i*i<=f;++i){
		 if(f%i==0){ 
			 int ano=f/i;
			 if(ano!=i)
			 {
				 for(int j=n-1;j>=0;--j)
				 if(v[j]==ano){ v[j]=-1; break;}
				 for(int j=n-1;j>=0;--j)
				 if(v[j]==i){ v[j]=-1; break;}
			 }
			 else
			 	 for(int j=n-1;j>=0;--j)
				 if(v[j]==ano){ v[j]=-1; break;}
		}
	}
	sort(v.begin(),v.end());
	int pp=v.size();
	cout<<f<<" "<<v[pp-1];
}
int32_t main(){
	grid1();
	return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  if (y % 2) {
    cout << "No\n";
    return 0;
  }
  y /= 2;
  int b = y - x;
  int a = x - b;
  if (0 <= a && 0 <= b) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3656
n,k=map(int,input().split())
a=tuple(map(int,input().split()))
if k==1 or n==1:
    print(0)
    exit()
m=pow(10,12)
l=len(a)-1
for i in range(2**(n-1)):
    cnt=1
    h=a[0]
    num=0
    for j in range(l):
        if (i>>j)&1:
            num+=max(0,h-a[j+1]+1)
            if a[j+1]<=h:
                h+=1
            else:
                h=a[j+1]
            cnt+=1
        else:
            if a[j+1]>h:
                cnt+=1
                h=a[j+1]
    if cnt>=k:
        m=min(m,num)
print(m)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  string str; cin >> str;
  rmsame(str);

  ll v=0,h=0;
  rep(i,str.size()){
    if (str[i] == 'E' ) h++;
    if (str[i] == 'N' ) v++;
    if (str[i] == 'S' ) v--;
    if (str[i] == 'W' ) h--;
  }
  if(v == 0 && h == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
    
  //cout << fixed << setprecision(16) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
L,R = map(int, input().split())
MOD = 2019
min_mod=MOD
for i in range(L, R):
    for j in range(i+1, R+1):
        min_mod=min(i*j%MOD, min_mod)
        if min_mod==0:
            print(0)
            exit()
print(min_mod)


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

int main() {
  int N, i = 1000;
  cin >> N;
  for (int j = 0; j < N; j++){
    int A, k = 0, l = 2;
    cin >> A;
    while (A % l == 0){
      l *=2;
      k++;
    }
    if (k < i)
      i = k;
  }
  cout << i << endl;
}

Measured memory_bytes: 3480
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }
  for(j=0;j<n;j++){
    scanf("%d",&A[j+1]);
    C[A[j+1]]++;
  }
  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);
  return 0;
}



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

#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define INF 1e9 + 1;
#define MOD 1e9 + 7;

typedef long long ll;
//typedef pair<int, int > P;
//typedef pair<ll, ll > LP;

using namespace std;

int n;
int odd[100001], even[100001];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;

    int v[n];
    REP(i, 0, n){
        cin >> v[i];
    }  
    
    map<int, int > no, ne;
    REP(i, 0, 100001){
        odd[i] = 0;
        even[i] = 0;
    }
    REP(i, 0, n/2) even[v[i*2]] += 1;
    REP(i, 0, n/2) odd[v[i*2 + 1]] += 1;
    int omax = 0;
    int omax_idx = 0;
    int emax = 0;
    int emax_idx = 0;
    int ans = 0;
    REP(i, 0, n/2){
        if(omax < odd[v[i*2 + 1]]){
            omax = odd[v[i*2 + 1]];
            omax_idx = v[i*2 + 1];
        }
        if(emax < even[v[i*2]]){
            emax = even[v[i*2]];
            emax_idx = v[i*2];
        }
    }
    if(omax_idx == emax_idx){
        int omax_rm = omax;
        int emax_rm = emax;
        int omax_rm_idx = omax_idx;
        int emax_rm_idx = emax_idx;
        omax = 0;
        emax = 0;
        REP(i, 0, n/2){
            if(omax < odd[v[i*2 + 1]] && v[i*2+1] != omax_rm_idx){
                omax = odd[v[i*2 + 1]];
                omax_idx = v[i*2 + 1];
            }
            if(emax < even[v[i*2]] && v[i*2] != emax_rm_idx){
                emax = even[v[i*2]];
                emax_idx = v[i*2];
            }
        }
        if(omax_rm > emax_rm){
            omax =  omax_rm;
        }else if(emax_rm > omax_rm){
            emax = emax_rm;
        }else if(omax > emax){
            emax = emax_rm;
        }else{
            omax = omax_rm;
        }
    }

    cout << (n/2 - emax) + (n/2 - omax) << '\n';

}


Measured memory_bytes: 1408
# coding: utf-8
def make_buildings():
    return [[[0 for room in range(10)] for floor in range(3)] for building in range(4)]

def print_building(building):
    return "\n".join(map(lambda floor: " " + " ".join(map(str, floor)),building))
    
line_number = int(input())
regidents_data = [list(map(int, input().split(" "))) for i in range(line_number)]
buildings = make_buildings()

for data in regidents_data:
    b, f, r, v = data
    buildings[b-1][f-1][r-1] += v

print("\n####################\n".join(map(print_building, buildings)))

Measured memory_bytes: 7756
A,B,H,M = gets.chomp.split.map(&:to_i)


base = 60*12.0
bunshi = H * 60 + M


a = bunshi/base
b = M/60.0

# p Math.cos(a)

theta = (a-b).abs * 360



theta = [theta, 360 - theta].min

ans_r = A**2 + B**2 - 2*A*B*Math.cos(Math::PI * theta/180)

p Math.sqrt(ans_r)


Measured memory_bytes: 14684
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
using namespace std;
#define ll long long
int main()
{
    int n,k;
    ll cnt = 0;
    cin>>n>>k;
    for(int i=k+1;i<=n;i++){
        cnt += 1ll*(i-k)*(n/i);
        cnt += 1ll*max(0 , n%i - k + 1);
    }
    if(k == 0){
        cnt -= n;
    }
    cout<<cnt<<endl;

    return 0;
}


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

int tate[4]={0,-1,0,1};
int yoko[4]={-1,0,1,0};
int h,w;

void dfs(const vector<vector<char>> &maze, vector<vi> &arrived, int sx, int sy, vector<pair<int,int>> &t, int count){
    t.push_back({sx,sy});
    if(arrived[sx][sy]==-1) arrived[sx][sy]=count;
    for(int i=0;i<4;i++){
        int next_x=sx+tate[i];
        int next_y=sy+yoko[i];
        if(maze[next_x][next_y]=='#') continue;
        if(arrived[next_x][next_y]!=-1) continue;
        arrived[next_x][next_y]=count;
        t.push_back({next_x,next_y});
        dfs(maze,arrived,next_x,next_y,t,count);       
    }
    return;
}

void warp(const vector<vector<char>> &maze, vector<vi> &arrived, int sx, int sy,queue<pair<int,int>> &que){
    for(int i=-2;i<=2;i++){
        for(int j=-2;j<=2;j++){
            if(sx+i<1||sx+i>h) continue;
            if(sy+j<1||sy+j>w) continue;
            if(maze[sx+i][sy+j]=='#') continue;
            if(arrived[sx+i][sy+j]!=-1) continue;
            que.push({sx+i,sy+j});
        }
    }
}

int main(){
    cin >> h >> w;
    vector<vector<char>> maze(h+2,vector<char>(w+2,'#'));
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> maze[i][j];
        }
    }
    vector<vi> arrived(h+2,vi(w+2,-1));
    arrived[sx][sy]=0;
    queue<pair<int,int>> que;
    que.push({sx,sy});
    int count=0;
    while(!que.empty()){
        vector<pair<int,int>> t;
        while(!que.empty()){
            pair<int,int> v=que.front();
            que.pop();
            dfs(maze,arrived,v.first,v.second,t,count);
        }
        for(pair<int,int> x:t){
            warp(maze,arrived,x.first,x.second,que);
        }
        count++;
    }
    /*
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cout << arrived[i][j] << " ";
        }
        cout << endl;
    }
    */
    cout << arrived[gx][gy] << endl;    
}

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

int main(){
	ll p,q,r; cin >> p >> q >> r;
	cout << min(p+q,min(p+r,q+r)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,r;
	while(1){
		scanf("%d",&n);
		if(n==-1){
			break;
		}else if(n<10){
			r=1150;
		}else if(n<20){
			r=1150+125*(n-10);
		}else if(n<30){
			r=2400+140*(n-20);
		}else{
			r=3800+160*(n-30);
		}
		printf("%d\n",4280-r);
	}
	return 0;
}

Measured memory_bytes: 2672
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int last[26];
int c[26];
int s[365][26];
int a[365];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    for(int i=0;i<26;i++){
    	cin >> c[i];
    }
    for(int i=0;i<d;i++){
    	for(int j=0;j<26;j++){
    		cin >> s[i][j];
    	}
    }
    for(int i=0;i<d;i++){
    	int mx=0;
    	int id=0;
    	for(int j=0;j<26;j++){
    		if(mx<(i+1-last[j])*c[j]+s[i][j]){
    			mx=(i+1-last[j])*c[j]+s[i][j];
    			id=j;
    		}
    	}
    	a[i]=id+1;
    	last[id]=i+1;
    }
    for(int i=0;i<26;i++){
    	last[i]=0;
    }
    int res=0;
    for(int i=0;i<d;i++){
    	res+=s[i][a[i]-1];
    	last[a[i]-1]=i+1;
    	for(int j=0;j<26;j++){
    		res-=c[j]*(i+1-last[j]);
    	}
    }
    for(int i=0;i<1e6;i++){
    	int day,qq;
    	day=myRand(d)+1;
    	qq=myRand(26)+1;
    	int resres=res;
    	int qqq=a[day-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres+=c[qq-1]*(i+1-last[qq-1]);
            resres+=c[qqq-1]*(i+1-last[qqq-1]);
        }
        a[day-1]=qq;
        resres-=s[day-1][qqq-1];
        resres+=s[day-1][qq-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres-=c[qq-1]*(i+1-last[qq-1]);
            resres-=c[qqq-1]*(i+1-last[qqq-1]);
		}
		if(resres>=res){

		}
		else{
			a[day-1]=qqq;
		}
    }
    for(int i=0;i<d;i++){
    	printf("%d\n",a[i]);
    }
}



Measured memory_bytes: 3816
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define vll vector<ll>
#define dou(s) atof(s.c_str())
#define lon(s) atoll(s.c_str())
#define str(n) to_string(n)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define line "\n"
#define mav(a) (*max_element(ALL(a)))
#define miv(a) (*min_element(ALL(a)))
#define vfind(a,n) (find(ALL(a),n)-a.begin())
#define prque priority_queue
#define MOD 1000000007ll
using namespace std;
void solve();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

//nCk(mod p)
/*ll fac[510000], finv[510000], inv[510000];
void cmodf(ll p = MOD) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, 510000) {
		fac[i] = fac[i - 1] * i%p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i - 1] * inv[i] % p;
	}
}
ll cmod(ll n, ll k, ll p = MOD) {
	return fac[n] * (finv[k] * finv[n - k] % p) % p;
}*/

//最大公約数
ll gcd(ll n, ll m) {
	ll k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return m;
}
ll gcd(vector<ll> a) {
	rep(i, 1, a.size()) {
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
	}
	return a.back();
}

//最小公倍数
ll lcm(ll n, ll m) {
	ll t = n * m, k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return t / m;
}
ll lcm(vector<ll> a) {
	ll n;
	rep(i, 1, a.size()) {
		n = a[i - 1] * a[i];
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
		n /= a[i];
		a[i] = n;
	}
	return n;
}

//keyの小さい方から探していった時に初めてvalueがjoken以上になる時のkey（keyが増えたらvalueも増えるか同じになるとき）
ll value(ll key) {
	/*変更*/
	return 0;
}
ll mini(ll lkey, ll rkey/*ここも調べる*/, ll joken) {
	ll mkey;
	while (lkey != rkey) {
		mkey = (lkey + rkey) / 2;
		if (value(mkey) >= joken)rkey = mkey;
		else lkey = mkey + 1;
	}
	return rkey;
}

//ペア配列の整理
struct pea { ll n, m; };
void msort(vector<pea> &a, bool k = true) {
	struct hikakukansu {
		static bool unstable(const pea &x, const pea &y) { return x.m < y.m; }
		static bool stable(const pea &x, const pea &y) { return (x.m == y.m ? x.n < y.n : x.m < y.m); }
	};
	if (k)sort(ALL(a), hikakukansu::unstable);
	else sort(ALL(a), hikakukansu::stable);
}

//変数定義

//再帰関数

//アルゴリズム
void solve() {
	ll n; cin >> n;
	vll a(n+1,1);
	rep(i, 2, n+1)a[i] = a[i - 1] + a[i - 2];
	cout << a[n] << line;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  int N; ll D, A;
  cin >> N >> D >> A; D*=2;
  vector<pair<ll,ll>> Edata(N);
  RPT(i,0,N){
    ll a, b;
    cin >> a >> b;
    b = (b+A-1)/A;
    Edata[i]={a,b};
  }
  sort(Edata.begin(),Edata.end());
  vector<int> R(N,0);
  {
    int right = 0;
    FOR(left,0,N){
      while(right < N-1 &&  Edata[right+1].first<=Edata[left].first+D ){
        ++right;
      }
      R[left] = right;
    }
  }
  queue<pair<int,ll>> Q;
  ll dm = 0, ans = 0; 
  FOR(i,0,N){
    while(!Q.empty() && Q.front().first < i){
      dm -= Q.front().second;
      Q.pop();
    }
    if(dm >= Edata[i].second) continue;
    ll newdm = Edata[i].second - dm;
    ans += newdm;
    Q.push({R[i],newdm});
    dm += newdm;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int, int> par;
typedef pair<par, int> prr;
#define x first
#define y second
int dp[305][305][305];
int main(){
    string S, T;
    cin >> S;
    T = S;
    reverse(T.begin(), T.end());
    int n = S.size();
    S = "a" + S;
    T = "a" + T;
    int maxx;
    scanf("%d", &maxx);
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
        for (int k = 0; k <= maxx; k++) {
            dp[i][j][k] = max(dp[i][j - 1][k], dp[i - 1][j][k]);
            if (S[i] == T[j]) dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + 1);
            else {
                if (k) dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - 1] + 1);
            }
        }
    }
    int ans = 0;
    for (int mid = 1; mid <= n; mid++) {
        int a = mid;
        int b = n - mid;
        for (int i = 0; i <= maxx; i++) {
            int tmp = dp[a][b][i] * 2;
            ans = max(ans, tmp);
        }
    }
    for (int mid = 1; mid <= n; mid++) {
        int a = mid - 1;
        int b = n - mid;
        for (int i = 0; i <= maxx; i++) {
            int tmp = dp[a][b][i] * 2 + 1;
            ans = max(ans, tmp);
        }
    }

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


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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a


using ll = long long;

int main() {
    char a;
    IN(int, n);
    IN(string, s);
    REP(i, s.length()){
        a = (s[i]-'A'+n)%26+'A';
        cout << a;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    if dp[i-1]+abs(h[i]-h[i-1])>=dp[i-2]+abs(h[i]-h[i-2]):
        dp[i]=dp[i-2]+abs(h[i]-h[i-2])
    else:
        dp[i]=dp[i-1]+abs(h[i]-h[i-1])
print(dp[n-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007

ll ss[MAXX];

int main()
{
	FAST;
	ll a, b;
    cin >> a >> b;
    ll x = a*b;
    x -= b;
    x -= (a-1);
    cout << x;
	return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int ways[ 10*N ];

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        ways[0] = 1;
        vector <int> coin = { 100 , 101 , 102 , 103 , 104 , 105 };
        for( int i = 0; i < 6; i++ ) {
                for( int j = coin[i]; j <= 1000000; j++ ) {
                        ways[j] |= ways[ j - coin[i] ];
                }
        }
        int n;
        cin >> n;
        cout << ways[n] << endl;
        return 0;
}










Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, s.size()) ans += (s[i] != t[i]);
    printf("%d\n", ans);
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#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 pb push_back
#define mp make_pair
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> VL;
typedef set<ll> SL;
typedef pair<ll, ll> p2;
const ll M = 1000000007;
const ll M2= 998244353;

void solve()
{
	ll n;
	cin>>n;
	VL v(n, 0);
	ll f=0;
	for(int i=0;i<n;i++)
	{
		 cin>>v[i]; if(v[i]==0) f=1;
	 }
	if(f)
	{
		cout<<0;
		return;
	}
	long double fu=0;
	ll p=1, o=1e18;
	
	for(int i=0;i<n;i++)p*=v[i], fu+=log10(v[i]);
	if(fu>18.1)cout<<-1;
	else if(p>o)cout<<-1;
	else cout<<p;
	
		
}
 
int main()
{
    IOS
    int _=1;
    //cin>>_;
    while(_--)
    {
	    solve();
    }
    
    return 0;
}


Measured memory_bytes: 3968
package main
import (
    "fmt"
    "math"
    "strconv"
)
func main(){
    var s string
    fmt.Scan(&s)
    fmt.Println(math.Min(Count(s), Count(Reverse(s))))
}

func Count(s string) float64 {
    var zero, one float64
    for i := 0; i< len(s); i++{
        if strconv.Itoa(i%2) == string(s[i]){
            zero ++
        }else{
            one ++
        }
    }
    return math.Min(zero, one)
}

func Reverse(s string) string{
    runes := []rune(s)
    for i, j := 0, len(runes)-1; i<j; i, j= i+1, j-1{
        runes[i], runes[j] = runes[j], runes[i]
    }
    return string(runes)
}


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

struct UnionFind {
    vector<int> data; int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) { return false; }
        if (data[x] > data[y]) { swap(x, y); }
        data[x] += data[y]; data[y] = x; sz--; return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n);
    for (int i = 0; i < k; i++) {
        int a, b; cin >> a >> b; a--; b--;
        uf1.unionSet(a, b);
    }
    for (int i = 0; i < l; i++) {
        int a, b; cin >> a >> b; a--; b--;
        uf2.unionSet(a, b);
    }
    
    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; i++) {
        int r1 = uf1.root(i), r2 = uf2.root(i);
        mp[make_pair(r1, r2)]++;
    }
    
    for (int i = 0; i < n; i++) {
        int r1 = uf1.root(i), r2 = uf2.root(i);
        cout << mp[make_pair(r1, r2)] << "\n";
    }
    return 0;
}

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

int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a%10!=0){
        a=a+10;
    }
    if(b%10!=0){
        b=b+10;
    }
    if(c%10!=0){
        c=c+10;
    }
    if(d%10!=0){
        d=d+10;
    }
    if(e%10!=0){
        e=e+10;
    }
                        if(a%10==1||b%10==1||c%10==1||d%10==1||e%10==1){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-9 <<endl;
                        } else if(a%10==2||b%10==2||c%10==2||d%10==2||e%10==2){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-8 <<endl;
                        } else if(a%10==3||b%10==3||c%10==3||d%10==3||e%10==3){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-7 <<endl;
                        } else if(a%10==4||b%10==4||c%10==4||d%10==4||e%10==4){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-6 <<endl;
                        } else if(a%10==5||b%10==5||c%10==5||d%10==5||e%10==5){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-5 <<endl;
                        } else if(a%10==6||b%10==6||c%10==6||d%10==6||e%10==6){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-4 <<endl;
                        } else if(a%10==7||b%10==7||c%10==7||d%10==7||e%10==7){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-3 <<endl;
                        } else if(a%10==8||b%10==8||c%10==8||d%10==8||e%10==8){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-2 <<endl;
                        } else if(a%10==9||b%10==9||c%10==9||d%10==9||e%10==9){
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10-1 <<endl;
                        } else {
                            cout<< (a/10)*10+(b/10)*10+(c/10)*10+(d/10)*10+(e/10)*10 <<endl;
                        }
}

Measured memory_bytes: 384
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_10_C: Longest Common Subsequence

#include <algorithm>
#include <cstdio>
#include <cstring>

static unsigned int lcs(const char* x, const char* y)
{
  auto m = static_cast<int>(std::strlen(x));
  auto n = static_cast<int>(std::strlen(y));
  unsigned int c1[m+1][n+1]; // extend for -1
  auto c = reinterpret_cast<int(*)[n+1]>(&c1[1][1]); // tricky?

  for (auto i = -1; i < m; ++i) c[i][-1] = 0u;
  for (auto j = 0; j < n; ++j) c[-1][j] = 0u;
  for (auto i = 0; i < m; ++i) {
    for (auto j = 0; j < n; ++j) {
      c[i][j] = (x[i] == y[j])
        ? c[i-1][j-1] + 1
        : std::max(c[i][j-1], c[i-1][j]);
    }
  }
  return c[m-1][n-1];
}

int main()
{
  unsigned int q;
  std::scanf("%u", &q);
  const unsigned int MAX_LEN = 1000;
  char x[MAX_LEN+1], y[MAX_LEN+1];
  for (auto i = 0u; i < q; ++i) {
    std::scanf("%1000s", x);
    std::scanf("%1000s", y);
    auto l = lcs(x, y);
    std::printf("%u\n", l);
  }
}

// eof

Measured memory_bytes: 6596
#include <iostream>
using namespace std;main(){int n=0,s,j,k,i=0,a[11][46];for(;n<506;n++)a[n%11][n/11]=0;for(;i<1024;){for(j=i++,n=s=k=0;j>0;j/=2,k++)n+=j%2,s+=j%2*k;a[n][s]++;}for(cin>>n>>s;n;s<46?cout<<a[n][s]:cout<<0,cout<<endl,cin>>n>>s);}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner scan=new Scanner(System.in);
long a[]=new long[100000];
int x=0;
long b=scan.nextInt();
long c=0;
long z=0;
long min=0;
long max=0;
long sun=0;
do{if(b==0) {
	break;
}
	do {

	if(x==b){
		break;
	}
	c=scan.nextInt();
	a[x]=c;
	x++;
}while(true);
x=0;
min=100000010;
do {
	if(x==b){
		break;
	}
	if(a[x]<=min){
		min=a[x];
	}
	x++;
}while(true);
 max=-10000001;
x=0;
do {
	if(x==b){
		break;
	}
	if(a[x]>=max){
		max=a[x];
	}
	x++;
}while(true);
sun=0;
x=0;
do {
	if(x==b){
		break;
	}
	sun+=a[x];
	x++;
}while(true);
}while(z!=0);
System.out.println(min+" "+max+" "+sun);
scan.close();
	}
}

Measured memory_bytes: 43228
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll dp[100005];

int main(){
    ll N,K; cin >> N >> K;
    vector<ll> h(N);
    for(int i=0;i<N;i++) cin >> h[i];

    for(int i=0;i<100005;i++) dp[i] = LINF;
    dp[0] = 0;

    for(int i=0;i<N;i++){
        for(int j=1;j<=K;j++){
            if(i+j >= N) break;
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }

    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define ROW    3
#define COLUMN 3

int main(void)
{
	int a[ROW][COLUMN];
	int b, n;
	int i, j, k;

	/* ビンゴカードに数字を書く */
	for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COLUMN; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}

	/* n個の数を選ぶ */
	scanf("%d", &n);

	for (k = 0; k < n; k++)
	{
		scanf("%d", &b);
		/* 選ばれた数に印を付ける */
		for (i = 0; i < ROW; i++)
		{
			for (j = 0; j < COLUMN; j++)
			{
				if (b == a[i][j]) {
					a[i][j] = -1;
				}
			}
		}
	}

	/* 横列のビンゴを確認する */
	for (i = 0; i < ROW; i++)
	{
		if (a[i][0] == a[i][1] && a[i][1] == a[i][2])
		{
			printf("Yes\n");
			return 0;
		}
	}

	/* 縦列のビンゴを確認する */
	for (i = 0; i < COLUMN; i++)
	{
		if (a[0][i] == a[1][i] && a[1][i] == a[2][i])
		{
			printf("Yes\n");
			return 0;
		}
	}

	/* 斜めのビンゴを2通り確認する */
	if (a[0][0] == a[1][1] && a[1][1] == a[2][2])
	{
		printf("Yes\n");
		return 0;
	}

	if (a[0][2] == a[1][1] && a[1][1] == a[2][0])
	{
		printf("Yes\n");
		return 0;
	}

	printf("No\n");

	return 0;
}

Measured memory_bytes: 128
N=parse(Int,chomp(readline()))
AP=map(x->parse(Int,x),split(chomp(readline())," "))

flag="APPROVED"

for i in AP
  if mod(i,2)==0
    if !(mod(i,3)==0 || mod(i,5)==0)
      flag="DENIED"
      break
    end
  end
end
print(flag)


Measured memory_bytes: 111600
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

d,t,s = map(int,input().split())
m  = t * s
if d <= t * s:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 65292
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const toA = Math.abs(s[0] - s[1]);
  const toB = Math.abs(s[0] - s[2]);
  const ans = (toA < toB) ? 'A' : 'B';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include<stdio.h>
#include<stdlib.h>
int exsearch(int*, int, int);
main()
{
        int i, n, q, m, *a;
        scanf("%d", &n);
        a = (int*)malloc(sizeof(int) * n);
        for(i = 0; i < n; i++){
        scanf("%d%*c", &a[i]);
        }
        scanf("%d", &q);
        for(i = 0; i < q; i++){
                scanf("%d%*c", &m);
                if(exsearch(a, m, n)){
                        printf("yes\n");
                }else{
                        printf("no\n");
                }
        }
        free(a);
}
int exsearch(int *a, int m, int n)
{
        int result = 0;
        if(!m){
                result = 1;
        return result;
        }else if(!n || m < 0 ){
                result = 0;
                return result;
        }else{
                result += exsearch(a, m - a[n - 1], n - 1);
                result += exsearch(a, m, n - 1);
        }
        return result;
}

Measured memory_bytes: 1816
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)

int main() {
  int n;
  cin >> n;
  rep(_,n) {
    string s;
    cin >> s;
    map<string, bool> dic;
    for (int i = 1; i < s.size(); i++) {
      string ls = s.substr(0,i);
      string rs = s.substr(i);

      dic[ls+rs] = dic[rs+ls] = true;
      reverse(ls.begin(), ls.end());
      dic[ls+rs] = dic[rs+ls] = true;
      reverse(rs.begin(), rs.end());
      dic[ls+rs] = dic[rs+ls] = true;
      reverse(ls.begin(), ls.end());
      dic[ls+rs] = dic[rs+ls] = true;
    }
    cout << dic.size() << endl;
  }


  return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    bool ok = false;
    while(n>0){
        if(n%10==7){
            ok = true; break;
        }
        n /= 10;
    }
    if(ok){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define forin(i,n) for(int i=0;i<n;i++)
#define forisn(i,s,n) for(int i=s;i<n;i++)
#define mostrar(x,v) for(auto x : v)cout<<x<<" ";
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    vi posW;
    forin(i,s.size())
    {
        if(s[i]=='W')posW.push_back(i);
    }
    ll sum=0;
    for(ll i=0;i<posW.size();i++)
    {
            sum+=(posW[i]-i);
           // cout<<sum<<"\n";
           // cout<<posW[i]<<"\n";
    }
    cout<<sum<<"\n";

    return 0;
}

Measured memory_bytes: 1552
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
const int nax=1e5+5;
pair<int,int> arr[nax];
vector<vector<pair<int,pair<int,ll>>>> v(nax);
int vis[nax]={0};
vector<unordered_map<int,unordered_map<int,int>>> pre(nax);
int level[nax];
int parent[nax];
int dp[nax][20];
struct s{
	int a,b,c,d;
};
int find(int x, int d){
	for(int i=19;i>=0;i--){
		if(d < (1<<i)) continue;
		x=dp[x][i];
		d-=(1<<i);
	}
	return x;
}
void dfs(int ci, int l){
	vis[ci]=1;
	level[ci]=l;
	if(l==0) parent[ci]=ci;
	for(auto x : v[ci]){
		if(vis[x.first]==1) continue;
		parent[x.first]=ci;
		dfs(x.first,l+1);
	}
}
int lca(int a, int b){
	int p=a; int q=b;
	if(level[a] > level[b]){
		p=b; q=a;
	}
	q=find(q,abs(level[a]-level[b]));
	if(p==q) return p;
	for(int i=19;i>=0;i--){
		if(dp[p][i]==dp[q][i]) continue;
		p=dp[p][i];
		q=dp[q][i];
	}
	return dp[p][0];
}
void dfs1(int ci, int sum, int col, int val){
	vis[ci]=1;
	for(auto x : pre[ci]){
		for(auto y: x.second){
			pre[ci][x.first][y.first]=sum-(ll)arr[x.first].second+arr[x.first].first*y.first;
		}
	}
	for(auto x : v[ci]){
		if(vis[x.first]==1) continue;
		arr[x.second.first].first++;
		arr[x.second.first].second+=x.second.second;
		dfs1(x.first,sum+x.second.second,x.second.first,x.second.second);
	}
	if(col != -1){
		arr[col].first--;
		arr[col].second-=val;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--; b--; c--;
		v[a].push_back({b,{c,d}});
		v[b].push_back({a,{c,d}});
		arr[i]={0,0};
	}

	dfs(0,0);
	for(int i=0;i<n;i++){
		vis[i]=0;
		dp[i][0]=parent[i];
	}
	for(int j=1;j<20;j++){
		for(int i=0;i<n;i++) dp[i][j]=dp[dp[i][j-1]][j-1];
	}
	vector
 query;
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--; c--; d--;
		query.push_back({a,b,c,d});
		pre[c][a][b]=0;
		pre[d][a][b]=0;
		pre[lca(c,d)][a][b]=0;
	}
	dfs1(0,0,-1,-1);
	for(auto x : query){
		cout<<pre[x.c][x.a][x.b]+pre[x.d][x.a][x.b]-2*pre[lca(x.c,x.d)][x.a][x.b]<<"\n";
	}
}


Measured memory_bytes: 71472
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let m: u64 = iter.next().unwrap().parse::<u64>().unwrap();
    let mut pair: Vec<(u64, u64)> = Vec::with_capacity(n);
    
    for _ in 0..n {
        pair.push((
            iter.next().unwrap().parse::<u64>().unwrap(),
            iter.next().unwrap().parse::<u64>().unwrap()
        ));
    }

    pair.sort();
    let mut money = 0u64;
    let mut num = 0u64;
    for i in 0..n {
        if num + pair[i].1 < m {
            money += pair[i].0 * pair[i].1;
            num += pair[i].1;
        } else {
            let k = m - num;
            money += pair[i].0 * k;
            break;
        }
    }
    println!("{}", money);
}

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

typedef long long ll;

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    int n;
    scanf("%d", &n);
    ll t[n];

    for (int i = 0; i < n; i++) {
        scanf("%lld", &t[i]);
    }

    ll ans = t[0];
    for (int i = 1; i < n; i++) {
        ans = lcm(ans, t[i]);
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 3784
#include<stdio.h>

int N;
int a[3000];
long long dp[3000][3000];

long long dfs(int l, int r){
  if(dp[l][r] != -1) return dp[l][r];
  if(l == r) return dp[l][r] = ((N & 1) ? a[l] : -a[l]);
  
  long long left, right;
  if((N - (r - l)) & 1){
    left = dfs(l + 1, r) + a[l];
    right = dfs(l, r - 1) + a[r];
    if(left > right) dp[l][r] = left;
    else dp[l][r] = right;
  }else{
    left = dfs(l + 1, r) - a[l];
    right = dfs(l, r - 1) - a[r];
    if(left < right) dp[l][r] = left;
    else dp[l][r] = right;
  }
  
  return dp[l][r];
}

int main(){
  scanf("%d", &N);
  
  for(int i = 0; i < N; i++) scanf("%d", &a[i]);
  
  for(int l = 0; l < N; l++){
    for(int r = l; r < N; r++){
      dp[l][r] = -1;
    }
  }
  
  printf("%lld\n", dfs(0, N - 1));
  
  return 0;
}

Measured memory_bytes: 70016
#include <stdio.h>
#include <string.h>
#define M 1046527
#define L 14

char H[M][L];

int getChar(char);
long long getKey(char *);
int find(char *);
int insert(char *);

int main(){
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0] =='i'){
      insert(str);
    }
    else{
      if(find(str)){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }
  return 0;
}
int getChar(char ch){
if(ch=='A')return 1;
 else if(ch=='C')return 2;
 else if(ch=='G')return 3;
 else return 4;
}

long long getKey(char *str){
  long long sum = 0,p = 1,i;
  for(i=0;i<strlen(str);i++){
    sum +=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}

int A(int key){return key %M;}
int B(int key){return 1+(key%(M-1));}

int find(char *str){
  long long key,i,a;
  key=getKey(str);
  for(i=0;;i++){
    a=(A(key)+i*B(key))%M;
    if(strcmp(H[a],str)==0)
      return 1;
    else if(strlen(H[a])==0)
      return 0;
  }
  return 0;
}
int insert (char *str){
  long long key,i,a;
  key=getKey(str);
  for(i=0;;i++){
    a=(A(key)+i*B(key))%M;
    if(strcmp(H[a],str)==0)return 1;
    else if(strlen(H[a])==0){
      strcpy(H[a],str);
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 16976