akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
    int n,i,flag=0,count=0;
    scanf("%d",&n);
    int a[n];
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    while(flag == 0){
        for(i=0; i<n; i++){
            if(a[i]%2==0){
                a[i] = a[i] / 2;
            }else{
                flag = 1;
            }
        }
        if(flag==0) count++;
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
n = gets.chomp.to_i
a = []
ans = false
count = 0
i = 1
n.times do
    a << gets.chomp.to_i
end

n.times do
    i = a[i-1]
    count += 1
    if i == 2 then
        ans = true
        break
    end
end

puts ans ? count : -1

Measured memory_bytes: 2684
#include<stdio.h>

int main(){
  while(1){
    int n,i;
    int sum = 1;
    int top = 1;
    int front = 2;
    int right = 3;

    scanf("%d", &n);
    if(n == 0)break;
    for(i = 0;i < n;i++){
      char str[10];
      scanf("%s", str);
      int nt = top;
      int nf = front;
      int nr = right;
      switch(str[0]){
      case 'N':
	nt = front;
	nf = 7 - top;
	break;
	
      case 'E':
	nt = 7 - right;
	nr = top;
	break;
	
      case 'W':
	nt = right;
	nr = 7 - top;
	break;
	
      case 'S':
	nt = 7 - front;
	nf = top;
	break;
	
      case 'R':
	nf = right;
	nr = 7 - front;
	break;
	
      case 'L':
	nf = 7 - right;
	nr = front;
	break;
      }
      top = nt;
      front = nf;
      right = nr;
      sum += top;
    }
    printf("%d\n", sum);
  }
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define END(s) {cout<<s;return 0;}
#define CON(s) {cout<<s;continue;}
#define BRE(s) {cout<<s;break;}
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
#define fi first
#define se second
#define LOCAL_JUDGE 1 //remember to change
using namespace std;
int main(){
	string s;
	rep(i,9) cin>>s[i];
	cout<<s[0]<<s[4]<<s[8];
	return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

sum = 0
for n_i in range(1, n + 1):
	n_orders_sum = 0
	for n_order_i in str(n_i):
		n_orders_sum += int(n_order_i)
	if a <= n_orders_sum <= b:
		sum += n_i
print(sum)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
char c[1001][1001];
string p1[4]={"aacd","bbcd","hgee","hgff"};
string p2[6]={"aab.ee","d.bf..","dccf..",".eeaab","f..d.b","f..dcc"};
string p3[7]={"a.bb.cc","aw..xx.",".w.pp.d","h.q...d","h.q..y.",".zz..ye","gg.ff.e"};
string p4[3]={".aa","b..","b.."};
int main(){
	ios::sync_with_stdio(false);int n;
	cin >> n;
	if(n==2) return cout << "-1\n",0;
	if(n==5) return cout << "abbxx\na.dyy\nccdzz\npqr..\npqr..\n",0;
	if(n==3) return cout << ".aa\nb..\nb..\n",0;
	if(n==9){
		for(int i=0; i<9 ;i++){
			for(int j=0; j<9 ;j++){
				if(i/3==j/3) cout << p4[i%3][j%3];
				else cout << ".";
			}
			cout << '\n';
		}
		return 0;
	}
	for(int i=1; i<=n ;i++){
		for(int j=1; j<=n ;j++){
			c[i][j]='.';
		}
	}
	if(n%4==0){
		for(int i=1; i<=n/4 ;i++){
			for(int j=0; j<4 ;j++){
				for(int k=0; k<4 ;k++){
					c[i*4-3+j][i*4-3+k]=p1[j][k];
				}
			}
		}
	}
	else if(n%2==0){
		for(int i=0; i<6 ;i++){
			for(int j=0; j<6 ;j++){
				c[i+1][j+1]=p2[i][j];
			}
		}
		for(int i=1; i<=n/4-1 ;i++){
			for(int j=0; j<4 ;j++){
				for(int k=0; k<4 ;k++){
					c[i*4+3+j][i*4+3+k]=p1[j][k];
				}
			}
		}
	}
	else if(n%4==3){
		for(int i=0; i<7 ;i++){
			for(int j=0; j<7 ;j++){
				c[i+1][j+1]=p3[i][j];
			}
		}
		for(int i=1; i<=n/4-1 ;i++){
			for(int j=0; j<4 ;j++){
				for(int k=0; k<4 ;k++){
					c[i*4+4+j][i*4+4+k]=p1[j][k];
				}
			}
		}
	}
	else{
		for(int i=0; i<7 ;i++){
			for(int j=0; j<7 ;j++){
				c[i+1][j+1]=p3[i][j];
			}
		}
		for(int i=0; i<6 ;i++){
			for(int j=0; j<6 ;j++){
				c[i+8][j+8]=p2[i][j];
			}
		}
		for(int i=1; i<=n/4-3 ;i++){
			for(int j=0; j<4 ;j++){
				for(int k=0; k<4 ;k++){
					c[i*4+10+j][i*4+10+k]=p1[j][k];
				}
			}
		}
	}
	for(int i=1; i<=n ;i++){
		for(int j=1; j<=n ;j++){
			cout << c[i][j];
		}
		cout << '\n';
	}
}

Measured memory_bytes: 2176
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const int N = 1e2 + 7;
const int mod = 1e9 + 7;

int n, a, b, ans;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> a >> b;
    b -= 1;
    while ( b > 0 ) {
        b -= (a - 1);
        ans++;
    }
    cout << ans;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

std::string s;

int main(){
    std::cin >> s;
    if(s == "ABC"){
        printf("ARC\n");
    }else{
        printf("ABC\n");
    }
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n;
  cin>>n;

  for(int i=0;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    long long cnt=0;
    while(1){
      if(b==1&&c==1)break;
      cnt++;
      c++;
      
      if(a%3==0){
	if(c==21){
	  c=1;b++;
	}
      }else{
	if(b%2==1&&c==21){
	  c=1;b++;
	}else if(b%2==0&&c==20){
	  c=1;b++;
	}
      }
      
      if(b==11){
	b=1;
	a++;
      }
      if(debug)cout<<a<<" "<<b<<" "<<c<<endl;
    }

    for(int j=a;j<1000;j++){
      if(j%3==0)cnt+=200;
      else cnt+=195;
    }
    
    cout<<cnt<<endl;
  }
  
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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*b/gcd(a, b);
}

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

int main()
{
    cout << fixed << setprecision(15);

    ll H, W;
    cin >> H >> W;

    vector<vector<char> > S(H+1, vector<char>(W+1));
    for(ll i=1; i<=H; i++) {
        for(ll j=1; j<=W; j++) {
            cin >> S[i][j];
        }
    }
 
    ll ans = 0;

    for(ll i=1; i<=H; i++){
        for(ll j=1; j<=W; j++){
            // キューを準備
            queue<P> que;
            // 探索の初期値を入れる
            que.push(P(i, j));

            vector<vector<ll>> v(H+2, vector<ll>(W+2, -1));
            // // vの初期化
            // REP(ii, H) {
            //     REP(jj, W) {
            //         v[ii][jj] = -1;
            //     }
            // }
            // 初期探索位置
            v[i][j] = 0;
            if(S[i][j] == '#') continue;
            
            while(true) {
                //　もしも探索地点がゴールならば現在の歩数を探索終了
                if(que.empty()) {
                    // cout << "empty" << endl;
                    break;
                }
                // キューの中身を取り出す
                P p = que.front(); que.pop();
                int x = p.first;
                int y = p.second;
                int s = v[x][y];

                
                // 4方向へ繰り返す
                REP(k, 4) {
                    int nx = x+dx[k];
                    int ny = y+dy[k];
                    // 移動すると範囲外になったり、#だったり、探索済みだったら終了する
                    if(nx <= 0 || nx > H || ny <= 0 || ny > W
                        || v[nx][ny] != -1 || S[nx][ny] == '#') continue;
                    // 未探索だったら、キューに入れて現在の距離を記録
                    que.push(P(nx, ny));
                    v[nx][ny] = s+1;
                    // cout << s << endl;
                }
            }
            // cout << "aaa " << i << " " << j << endl;
            // vの初期化
            for(ll ii=1; ii<=H; ii++) {
                for(ll jj=1; jj<=W; jj++) {
                    ans = max(ans, v[ii][jj]);
                }
            }
            // cout << ans << endl;
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

long long int n,m;
int main()
{
	scanf("%lld%lld",&n,&m);
	if(n > m) std::swap(n,m);
	if(n == 1) {
		if(m == 1) printf("1\n");
		else if(m == 2) printf("0\n");
		else printf("%lld\n",m-2);
	} else if(n == 2) {
		printf("0\n");
	} else {
		printf("%lld\n",(n-2)*(m-2));
	}
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
S = [list(input()[:-1]) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            cnt = 0
            
            for dx in range(-1, 2):
                for dy in range(-1, 2):
                    ni = i+dx
                    nj = j+dy
                    
                    if 0<=ni<H and 0<=nj<W and S[ni][nj]=='#':
                        cnt += 1
            
            S[i][j] = str(cnt)
    
for Si in S:
    print(''.join(Si))

Measured memory_bytes: 40432
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

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

  int h, w;
  cin >> h >> w;

  int n; cin >> n;

  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }

  int color[102][102] = { 0 };

  int y = 0, x = 0, aa = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i]; j++) {
      color[y][x] = i+1;
      x += aa;
      if ( x == w && aa == 1 ) {
        y++;
        x--;
        aa = -1;
      }
      if ( x == -1 && aa == -1) {
        y++;
        x++;
        aa = 1;
      }
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cout << color[y][x];
      cout << (x == (w-1) ? "\n" : " ");
    }
  }

  return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<long long> a(n);
  for(int i=0; i<n; i++)cin>>a.at(i);

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

  long long x=0, y=0;
  int z=0;
  for(int i=n-1; i>0; i--){
    if(a.at(i)==a.at(i-1)){
      x=a.at(i);
      z=i-1;
      break;
    }
  }
  for(int i=z-1; i>0; i--){
    if(a.at(i)==a.at(i-1)){
      y=a.at(i);
      break;
    }
  }

  cout<<x*y<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,ans=0;
    cin>>n>>k;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n,greater<>());
    for(int i=0;i<k;i++){
        ans+=s[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


enum L = 2001;

void main() {
    int n, k;
    scan(n, k);

    auto a = readln.split.to!(int[]);

    int I;

    foreach (i ; 1 .. n) {
        foreach (j ; 0 .. i) {
            if (a[j] > a[i]) {
                I++;
            }
        }
    }

    long ans = 1L * I * k % mod;


    auto c = new int[](L);

    foreach (i ; 0 .. n) {
        c[a[i]]++;
    }

    auto cc = new int[](L + 1);

    foreach (i ; 1 .. L + 1) {
        cc[i] = cc[i - 1] + c[i - 1];
    }

    long p;

    foreach (i ; 0 .. L) {
        p += c[i] * cc[i] % mod;
        p %= mod;
    }

    ans += p * (1L * k * (k - 1) / 2 % mod) % mod;
    ans %= mod;

    writeln(ans);
}

















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int X; cin>>X;

    int ans;
    if(X<600) ans=8;
    else if(X<800) ans=7;
    else if(X<1000) ans=6;
    else if(X<1200) ans=5;
    else if(X<1400) ans=4;
    else if(X<1600) ans=3;
    else if(X<1800) ans=2;
    else if(X<2000) ans=1;

    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 1e9+10
using namespace std;
map <char,int>leta;
map <char,int>letb;
string s,t;
int num=1,sn[200005],tn[200005],yes=1;
int main(){
    cin>>s;
    cin>>t;
    for(int i=0;i<s.size();i++){
        if(!leta[s[i]])
            leta[s[i]]=num++;
        sn[i]=leta[s[i]];
    }
    num=1;
    for(int i=0;i<t.size();i++){
        if(!letb[t[i]])
            letb[t[i]]=num++;
        tn[i]=letb[t[i]];
    }
    for(int i=0;i<s.size();i++){
        if(sn[i]!=tn[i]||s.size()!=t.size()){
            yes=0;
            break;
        }
    }
    if(yes)
        printf("Yes");
    else
        printf("No");

}


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

//const INF = 1e9+5

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

    int n,w;
    cin>>n>>w;
    vector<ll> dp(w+1);
    //dp[i] = the maximum total value of items with total weight exactly equal to i
    for(int i=0;i<n;i++){
        ll weight,value;
        cin>>weight>>value;
        for (ll curweight = w-weight; curweight >= 0; --curweight) {
            dp[curweight+weight]=max(dp[curweight+weight],dp[curweight]+value);
        }
    }
    ll ans=0;
    for(int i=0;i<=w;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n,q;
  cin >> n;
  vector<int> A(n);
  vector<int> num(100001,0);
  rep(i,n){
    cin >> A[i];
    num[A[i]]++;
  }
  cin >> q;
  vector<int> B(q);
  vector<int> C(q);
  rep(i,q){
    cin >> B[i] >> C[i];
  }

  ll sum =0;
  rep(i,n){
    sum +=A[i];
  }

  rep(i,q){
    sum += num[B[i]]*(C[i]-B[i]);
    cout << sum <<endl;
    num[C[i]]+=num[B[i]];
    num[B[i]]=0;
  }

  return 0;
}


Measured memory_bytes: 4844
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
	ll dp[700] = {}, *dp0 = dp+100, *dp1 = dp+400;
	dp1[0] = 1;
	int n; cin >> n;
	while (n--) {
		char c; cin >> c;
		if (c == '-') continue;
		for (int j = 0; j < 210; j++) {
			dp0[j] = (j*dp1[j] +
				((c == 'U') ? dp1[j-1] : (j+1)*(j+1)*dp1[j+1])) % (ll)(1e9+7);
		}
		swap(dp0, dp1);
	}
	cout << dp1[0] << endl;
	return 0;
}

Measured memory_bytes: 1160
#coding:UTF-8
import math
def Count(x):
    if x == 2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=math.sqrt(x):
        if x%i==0:
            return 0
        i+=2
    return 1

def PN(n,a):
    count=0
    for i in range(n):
        count+=Count(a[i])
    print(count)
    
if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    PN(n,a)

Measured memory_bytes: 8076
#include<iostream>
using namespace std ;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a<<" "<<b<<" "<<3*c-a-b<<" "<<endl;
    cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<" "<<endl;
    cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<" "<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int a[10];

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


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N,M,city;
  cin>>N>>M;
  vector<int> road(N,0);
  for (int i=0;i<2*M;i++){
    cin>>city;
    for(int k=0;k<N;k++){
      if(k+1==city){
        road.at(k)+=1;
      }
    }
  }
  for (int i=0;i<N;i++){
    cout<<road.at(i)<<endl;
  }
}

Measured memory_bytes: 3596
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int total = scan.nextInt();
        int hour = total / 3600;
        int min = (total % 3600) / 60;
        int sec = (total % (60));
        System.out.println(hour+":"+min+":"+sec);
    }
    
}


Measured memory_bytes: 26180
n=int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split( ))
  a.append(x-y)
j=3
check=0
for i in range(n-2):
  if a[i:j]==[0,0,0]:
    print("Yes")
    check=1
    break
  j+=1
if not check:
  print("No")

Measured memory_bytes: 9128
// ※※※ 解答不能 ※※※
// latte0119氏.
// https://atcoder.jp/contests/abc142/submissions/7743536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF = 1001001001;
int A[1111], b[1111];

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    rep(i, M){
        int n;
        scanf("%d %d", &A[i], &n);
        rep(j, n){
            int c;
            scanf("%d", &c);
            c--;
            b[i] |= (1 << c);
        }
    }
    vector<int> dp(1 << N, INF);
    dp[0] = 0;
    rep(i, M) repr(j, (1 << N) - 1) chmin(dp[j | b[i]], dp[j] + A[i]);
    int ans = dp[(1 << N) - 1];
    if(ans == INF) printf("%d", -1);
    else           printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[105];
int main()
{
  ll n, m, ans = 0, p, x;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
    ans += a[i];
  }
  scanf("%lld", &m);
  for (int i = 0; i < m; i++)
  {
    ll tmp = ans;
    scanf("%lld%lld", &p, &x);
    tmp += x - a[p - 1];
    printf("%lld\n", tmp);
  }
  return 0;
}


Measured memory_bytes: 128
<?php
    
    $num_a = intval(trim(fgets(STDIN)));
    $array_a = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $num_b = intval(trim(fgets(STDIN)));
    $array_b = array_map('intval',explode(" ",trim(fgets(STDIN))));
        
    
    //探索したい値の数分調べていく
    for($i=0;$i<$num_b;$i++){
        //対象の探索配列の最小と最大をleft rightとする。
        $left=0;
        $right=count($array_a)-1;
        
        while($left <= $right){
            $mid = floor(($left+$right)/2);
        
            if($array_a[$mid]== $array_b[$i]){
                
                $flg[$i]=1;
                $ans[] = $array_b[$i];
                //一戸でも見つかった次の数の探索をする
                break;
            
            }elseif($array_b[$i] < $array_a[$mid]){
                
                $right = $mid-1;
                
            }else{
                //このプラス1は重要?
                $left= $mid+1;
            }
        }
    }
    // var_dump($ans);
    echo array_sum($flg)."\n";
?>


Measured memory_bytes: 42036
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long N, X[101], i, j, ans=INF, num;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> X[i];
    }

    for(i=1; i<=100; i++){ // Pの座標
        num = 0;

        for(j=1; j<=N; j++){
            num += (X[j]-i)*(X[j]-i);
        }

        chmin(ans, num);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())


word_list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA'

new_list = ''
for i in S:
	fd = word_list.find(i)
	new_list += word_list[fd + N]
	
print(new_list)


Measured memory_bytes: 3060
n, m = map(int, input().split())
ans = 0
if n > m:
    n, m = m, n
if n == 1 and m == 1:
    ans = 1
elif n == 1 or m == 1:
    ans = max(0, m - 2)
elif n == 2 or m == 2:
    ans = 0
else:
    ans = (n - 2) * (m - 2)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
int a;
  string s;
  cin>>a>>s;
  if(a>=2800 && a<3200)
    cout<<"red"<<endl;
  else if(a>=3200 && a<5000)
    cout<<s<<endl;
  else
    cout<<"wrong"<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int gcd(int x,int y)
	{
		return y>0?gcd(y,x%y):x;
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int k=sc.nextInt();
		int max=0;
		int g=0;
		for (int i = 0; i < n; i++) {
			int x=sc.nextInt();
			g=gcd(g, x);
			max=Math.max(max, x);
		}
		if(k%g==0 &&max>=k)
			System.out.println("POSSIBLE");
		else
			System.out.println("IMPOSSIBLE");
	}

}


Measured memory_bytes: 46888
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn Dijkstra_dist(N:usize,E:&Vec<HashMap<usize,usize>>,start:usize) -> Vec<isize>{
    let mut D = (0..N).map(|_| -1).collect::<Vec<_>>();
    let mut hq = BinaryHeap::new();
    hq.push((0,start));
    while hq.len()>0{
        let (d0,i) = hq.pop().unwrap();
        let d0 = -d0;
        if D[i] != -1 {continue;}
        D[i] = d0;
        for (&j,&c) in E[i].iter(){
            if D[j] != -1 {continue;}
            hq.push((-(d0+c as isize),j));
        }
    }
    D
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let N = iter.next().unwrap().parse::<usize>().unwrap();
    let M = iter.next().unwrap().parse::<usize>().unwrap();
    let s = iter.next().unwrap().parse::<usize>().unwrap()-1;
    let t = iter.next().unwrap().parse::<usize>().unwrap()-1;
    let UVAB = (0..M).map(|_| (
        iter.next().unwrap().parse::<usize>().unwrap()-1,
        iter.next().unwrap().parse::<usize>().unwrap()-1,
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap()
    )
    ).collect::<Vec<_>>();

    let mut Ea = (0..N).map(|_| HashMap::new()).collect::<Vec<_>>();
    let mut Eb = (0..N).map(|_| HashMap::new()).collect::<Vec<_>>();
    for &(u,v,a,b) in &UVAB{
        Ea[u].insert(v,a);
        Ea[v].insert(u,a);
        Eb[u].insert(v,b);
        Eb[v].insert(u,b);
    }

    let Da = Dijkstra_dist(N,&Ea,s);
    let Db = Dijkstra_dist(N,&Eb,t);

    let mut ans = (0..N).map(|_| 0).collect::<Vec<_>>();
    ans[N-1] = Da[N-1]+Db[N-1];
    for i in 0..N-1{
        let i = N-2-i;
        ans[i] = min(ans[i+1], Da[i]+Db[i]);
    }
    for i in 0..N{
        println!("{}",1e15 as isize - ans[i]);
    }
}

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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> cnt(4, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ++cnt[ a[i] % 4 ];
    }
    bool res;
    if (cnt[2] == 0) {
        res = (cnt[1] + cnt[3]) <= cnt[0] + 1;
    } else {
        res = (cnt[1] + cnt[3]) <= cnt[0];
    }

    if (res) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

}


Measured memory_bytes: 640
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const int inf = 1<<30;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N;i++)
        cin >> A[i];
    map<ll, ll> d;
    rep(i,N){
        d[A[i]]++;
    }
    vector<ll> e = {0, 0}, m = {0, 0};
    for (auto it : d)
    {
        if(it.second>=2)
            e.push_back(it.first);
        if(it.second>=4)
            m.push_back(it.first);
    }
    sort(All(e),greater<ll>());
    sort(All(m), greater<ll>());
    ll a = e[0] * e[1], b = m[0] * m[0];
    //cout << a << ' ' << b << endl;
    cout << max(a, b) << endl;
}

Measured memory_bytes: 7296
# swag
from collections import deque
class SWAG_Stack():
    def __init__(self, F):
        self.stack1 = deque()
        self.stack2 = deque()
        self.F = F
        self.len = 0

    def push(self, x):
        if self.stack2:
            self.stack2.append((x, self.F(self.stack2[-1][1], x)))
        else:
            self.stack2.append((x, x))
        self.len += 1

    def pop(self):
        if not self.stack1:
            while self.stack2:
                x, _ = self.stack2.pop()
                if self.stack1:
                    self.stack1.appendleft((x, self.F(x, self.stack1[0][1])))
                else:
                    self.stack1.appendleft((x, x))
        self.stack1.popleft()
        self.len -= 1

    def sum_all(self):
        if self.stack1 and self.stack2:
            return self.F(self.stack1[0][1], self.stack2[-1][1])
        elif self.stack1:
            return self.stack1[0][1]
        elif self.stack2:
            return self.stack2[-1][1]
        else:
            raise IndexError

n,m = map(int, input().split())
s = input()

stack = SWAG_Stack(min)
stack.push((0,n))
turn = [-1]*(n+1)
turn[-1] = 0
for i in range(n-1, -1, -1):
    if s[i] == "1":
        stack.push((float("inf"), i))
    else:
        cost, ind = stack.sum_all()
        if cost == float("inf"):
            break
        turn[i] = cost+1
        stack.push((cost+1, i))
    if stack.len > m:
        stack.pop()
# print(turn)

if turn[0] == -1:
    print(-1)
    exit()
prev_turn=turn[0]
prev_ind = 0
ans = []
for i in range(1, n+1):
    if prev_turn-turn[i] == 1:
        ans.append(i-prev_ind)
        prev_ind = i
        prev_turn = turn[i]
print(*ans)


Measured memory_bytes: 59484
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int solve(const string& S){
    const int N = S.size();
    if(N == 1) return 1;
    vector<vector<int>> a(N+2, vector<int>(2, 0));
    a[0][0] = a[1][1] = 1;
    for(int i=0;i<S.size();i++){
        for(int j=0;j<2;j++){
            a[i+2-j][1-j] = max(a[i+2-j][1-j], a[i][j]+1);
            if(j == 0 && i+1 < N && S[i] != S[i+1]) a[i+1][0] = max(a[i+1][0], a[i][j]+1);
            if(j == 1 && i+2 < N && i-1 >= 0 && (S[i-1] != S[i+1] || S[i] != S[i+2])) a[i+2][1] = max(a[i+2][1], a[i][j]+1);
        }
    }
    return max(a[N-1][0], a[N-1][1]);
}

int main(){
    string S; cin >> S;
    cout << solve(S) << endl;
}

Measured memory_bytes: 11396
(function(input) {
  var p = input.replace(/\n$/, '').split('\n').map(Number);
  var array = [];
  while (p.length > 0) {
    var n = p.shift();
    if (n === 0) {
      console.log(array.pop());
      continue;
    }
    array.push(n);
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7640
let () =
  Scanf.scanf "%d %d %d" @@ fun n _ w ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  max (abs (a.(n-1) - w)) (if n <= 1 then 0 else abs (a.(n-2) - a.(n-1)))
  |> Printf.printf "%d\n"

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static boolean isOdd(int val) {
		return ((val & 1) != 0);
	}

	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			final int N = in.nextInt();
			final long[] A = new long[N];
			for (int i = 0; i < N; ++i) {
				A[i] = in.nextInt();
			}

			final int halfN = N / 2;
			long result = 0L;
			Arrays.sort(A);
			if (isOdd(N)) {

				long r1 = 0;
				r1 -= 2 * Arrays.stream(A, 0, halfN).sum();
				r1 += 2 * Arrays.stream(A, halfN, N).sum();
				r1 -= A[halfN];
				r1 -= A[halfN + 1];

				long r2 = 0;
				r2 -= 2 * Arrays.stream(A, 0, halfN + 1).sum();
				r2 += 2 * Arrays.stream(A, halfN + 1, N).sum();
				r2 += A[halfN];
				r2 += A[halfN - 1];

				result = Math.max(r1, r2);

			} else {
				result -= 2 * Arrays.stream(A, 0, halfN).sum();
				result += 2 * Arrays.stream(A, halfN, N).sum();
				result -= A[halfN];
				result += A[halfN - 1];
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 62628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, K;
  cin >> N >> K;
  if(N < K){
    cout << 1 << endl;
  }else{
    if(N%K==0) cout << 0 << endl;
    else cout << 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    if(N % 2 == 1){
        ll k = (N-1)/2;
        cout << 2*k*k << endl;
        rep(i, k){
            rep(j, k-i-1){
                cout << i+1 << " " << i+j+2 << endl;
                cout << i+1 << " " << 2*k-i-j-1 << endl;
                cout << 2*k-i << " " << i+j+2 << endl;
                cout << 2*k-i << " " << 2*k-i-j-1 << endl;
            }
            cout << i+1 << " " << 2*k+1 << endl;
            cout << 2*k-i << " " << 2*k+1 << endl;
        }
    }
    else{
        ll k = N / 2;
        cout << 2*k*(k-1) << endl;
        rep(i, k){
            rep(j, k-i-1){
                cout << i+1 << " " << i+j+2 << endl;
                cout << i+1 << " " << 2*k-i-j-1 << endl;
                cout << 2*k-i << " " << i+j+2 << endl;
                cout << 2*k-i << " " << 2*k-i-j-1 << endl;
            }
        }
    }
}

Measured memory_bytes: 3596
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n;
    cin >> n;
    ll ans = 0;
    FOR(i,1,n){
        if(((i % 3) != 0) && ((i % 5) != 0)){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int n;
	cin>>n;
	vector<int> d(n);
	rep(i,n){
		cin>>d[i];
	}
	sort(d.begin(),d.end(),greater<int>());
	int ans = 1;
	int currentD = d[0];
	for(int i = 1; i < n; i++){
		if(currentD > d[i]) ans++;
		currentD = d[i];
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;
double table[55];


int main(){

	scanf("%d",&N);

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

		scanf("%lf",&table[i]);
	}

	sort(table,table+N);

	double ans = (table[0]+table[1])/2;

	for(int i = 2; i < N; i++){

		ans = (ans+table[i])/2;
	}

	printf("%.10lf\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  if(n%10==0){
    int x=n/2;
    int ans=0;
    while(x>0){
      if(x%10)ans+=x%10;
      x/=10;
    }
    cout<<ans*2<<endl;
  }else{
    int ans=0;
    while(n>0){
      ans+=n%10;
      n/=10;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

int d, c;
void input() {
    cin >> d >> c;
}

void solve() {
    cout << d * c << endl;
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 1160
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=ja
//単一始点最短経路
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
//s start node
//return 各nodeへの最短の距離が入る,numeric_limits<T>::max()の場合、到達できない
template< typename T >
vector< T > dijkstra(const WeightedGraph< T > &g, int s, vector<int>& prev) {
	const auto INF = numeric_limits<T>::max();
	vector<T> dist(g.size(), INF);
	prev.assign(g.size(),-1);

	using Pi = pair<T, int>; //dist,node id
	priority_queue<Pi, vector<Pi>, greater<Pi>> que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while(!que.empty()) {
		T cost;
		int idx; //node id
		tie(cost, idx) = que.top();
		que.pop();
		if(dist[idx] < cost)
			continue;
		for(auto &e : g[idx].edges) {
			auto next_cost = cost + e.cost;
			if(dist[e.to] <= next_cost)
				continue;
			dist[e.to] = next_cost;
			prev[e.to] = idx;
			que.emplace(dist[e.to], e.to);
		}
	}
	return dist;
}
vector<int> get_path(int t, const vector<int>& prev){ //頂点tへの最短路
	vector<int> path;
	for(; t != -1;t=prev[t]){
		path.push_back(t);
	}
	reverse(path.begin(), path.end());
	return path;
}

int main() {
  ll V,E; cin>>V>>E;
  ll r; cin>>r;
  WeightedGraph<ll> graph(V);
  REP(i,E){
    ll s,t,d; cin>>s>>t>>d;
    graph.at(s).edges.emplace_back(t,d);
  }

  vector<int> prev;
  auto ans = dijkstra(graph, r, prev);
  FOR(i,0,ans.size()){
    ll v=ans.at(i);
    if (v==numeric_limits<ll>::max()){
      cout<<"INF"<<endl;
    }else cout<<v<<endl;
  }

  return 0;
}


Measured memory_bytes: 19732
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n,a,s[5];
double dp[303][303][303];
double go(int a,int b,int c)
{
	if(a+b+c==0)
		return 0;
	if(dp[a][b][c])
		return dp[a][b][c];
	double ret=1.0000000000;
	if(a)
		ret+=1.00*a*go(a-1,b,c)/(1.000*n);
	if(b)
		ret+=1.00*b*go(a+1,b-1,c)/(1.000*n);
	if(c)
		ret+=1.00*c*go(a,b+1,c-1)/(1.000*n);
	ret+=(ret*(1.0000000*(n-a-b-c))/(1.000000*(a+b+c)));
	dp[a][b][c]=ret;
	return ret;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a,s[a]++;
	cout<<fixed<<setprecision(10)<<go(s[1],s[2],s[3]);
	return 0;
}

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

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

inline void Main() {
  // code
  string s; int k;
  cin >> k >> s;
  if(s.length() <= k) {
    cout << s << endl;
  } else {
    rep(i, k) {
      cout << s[i];
    }
    cout << "..." << endl;
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3612
N = int(input())
Q = [0]
for i in map(int, input().split()):
	if i >= len(Q):
		if Q[0] == 0:
			print(0)
			exit()
		Q += ([0] * (i + 1 - len(Q)))
	Q[i] += 1
mod = 998244353

sum = 1
for i in range(len(Q)):
	if Q[i] == 0:
		sum = 0
		break
	if i == 0:
		if Q[i] != 1:
			sum = 0
			break
		else:
			continue
	sum *= (Q[i-1] ** Q[i])
	sum %= mod

print(sum)


Measured memory_bytes: 11124
#include <stdio.h>

int main(){
  int d[14]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  scanf("%d %d",&x,&y);
  if(d[x]==d[y]) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int64_t X,K,D;
    cin >> X >> K >> D;
    int64_t chk=abs(X/D);
    int64_t ans;
    if(abs(chk)>=K)
    {
        if(X>0)
        {
            ans=X-D*K;
        }
        if(X<0)
        {
            ans=X+D*K;
        }
        cout << abs(ans) << endl;
        return 0;
    }
    if((K-chk)%2==0)
    {
        if(X>0)
        ans=abs(X-D*chk);
        else
        ans=abs(X+D*chk);
    }
    else
    {
        if(X>0)
        ans=min(abs(X-D*chk+D),abs(X-D*chk-D));
        else
        ans=min(abs(X+D*chk+D),abs(X+D*chk-D)); 
    }
    cout << abs(ans) << endl;
    
}

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

int main()
{
    string S;
    cin >> S;
    if (S[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }
    else
        S[0] = 'a';
    if (count(S.begin() + 2, S.end() - 1, 'C') != 1)
    {
        cout << "WA" << endl;
        return 0;
    }
    else
    {
        S[S.find("C")] = 'c';
    }
    for (int i = 0; i < S.size(); i++)
    {
        if (!('a' <= S[i] && S[i] <= 'z'))
        {
            cout << "WA" << endl;
            return 0;
        }
    }
    cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val (N, K) = readLine()!!.split(" ").map(String::toInt)
    val h = (1..N).map{ readLine()!!.toInt() }.sorted()
    println( (0..N-K).map { h[it+K-1] - h[it] }.min()!! )
}



Measured memory_bytes: 47188
import Control.Monad
import Data.List

solve = foldl' f (0, 0)
  where
    f (n, c) [a, b] = if a < n then (n, c) else (b, succ c)

readN = map read . words <$> getLine

main = do
  [n, m] <- readN
  rs <- replicateM m readN
  print $ snd . solve . sortOn last $ rs


Measured memory_bytes: 94588
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a;
    rep(i, n){
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    int l=0, r=a[n-1];
    while(r-l>1){
        int x = (l + r) / 2;
        int tmpk = k, i;
        bool flag=true;
        for(i=n-1;i>=0;i--){
            tmpk -= (a[i] - 1) / x;
            if(tmpk<0){
                flag=false;
                break;
            }
        }
        if(flag){
            r = x;
        }else{
            l = x;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4316
import sys
N = int(input())
arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))

if N == 1:
    print(1)
    sys.exit()

d = {}

for i in range(N):
    for j in range(N):
        if i != j:
            x = arr[i][0] - arr[j][0]
            y = arr[i][1] - arr[j][1]
            if (x, y) in list(d.keys()):
                d[(x, y)] += 1
            else:
                d[(x, y)] = 1

print(N - max(list(d.values())))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,i,x,d,s=0,s1=0;
 	int ans=INT_MAX;
 	cin>>n;
 	int a[n],b[n],c[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 		for(i=0;i<n;i++)
 		{
 			s=s+a[i];
 			b[i]=s;
		 }
		 for(i=n-1;i>=0;i--)
		 {
		 	s1=s1+a[i];
		 	c[i]=s1;
		 }
		for(i=0;i<n-1;i++)
		{
			ans=min(ans,abs(b[i]-c[i+1]));
		}
		cout<<ans<<endl;
 	}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll n = 1;
    ll ans = N - 1;
    while (n * n <= N) {
        if (N % n == 0) {
            ans = std::min(ans, n - 1 + N / n - 1);
        }
        n++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] ^= a[i][k] & b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;

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

int main() {
  ll N, K;
  vector<ll> x;
  cin >> N >> K;
  REP(i, N) {
    ll po = 0;
    cin >> po;
    x.push_back(po);
  }
  ll m = llINF;
  REP(i, N - K + 1) {
    ll po = min(abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]),
                abs(x[i + K - 1] - x[i]) + abs(x[i]));
    if (po < m)
      m = po;
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';


int main() {
	double n, k;
	cin >> n>>k;
	vector<int> a(n);
	rep(i,n)scanf("%d", &a[i]); '\n';
	
	cout << 1+ceil((n-k)/(k-1));
	}

	

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int m;
  long long k;
  cin >> m >> k;
  vector<int> pm(n - 1);
  iota(pm.begin(), pm.end(), 0);
  for (int i = 0; i < m; i++) {
    int z;
    cin >> z;
    z--;
    swap(pm[z - 1], pm[z]);
  }
  vector<int> res(n - 1);
  iota(res.begin(), res.end(), 0);
  auto trans = [&](vector<int> f, vector<int> g) {
    vector<int> a(n - 1);
    for (int i = 0; i < n - 1; i++) {
      a[i] = f[g[i]];
    }
    return a;
  };
  while (k) {
    if (k & 1) {
      res = trans(res, pm);
    }
    pm = trans(pm, pm);
    k >>= 1;
  }
  long long cur = x[0];
  cout << cur << '\n';
  for (int i = 0; i < n - 1; i++) {
    int d = x[res[i] + 1] - x[res[i]];
    cur += d;
    cout << cur << '\n';
  }
  return 0;
}


Measured memory_bytes: 3172