akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n; cin >> n;
  
  vector<int> x(n);
  
  int sum = 0;
  for(int i=0; i<n; i++){
    cin >> x[i];
    sum += x[i];
  }
  
  int p = sum/n;
  
  int ans1 = 0; 
  for(int i=0; i<n; i++){
    ans1 += (x[i]-p)*(x[i]-p);
  }
  
  p++;
  
  int ans2 = 0; 
  for(int i=0; i<n; i++){
    ans2 += (x[i]-p)*(x[i]-p);
  }
  
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iC = int.Parse(sS[2]);
            int iX = int.Parse(sS[3]);
            int iY = int.Parse(sS[4]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstS = new List<int>();
            lstS.Add(iA * iX + iB * iY);                                                                // A B のみ
            lstS.Add(iC * (iX > iY ? iX * 2 : iY * 2));                                                 // C   のみ
            lstS.Add(iC * (iX > iY ? iY * 2 : iX * 2) + (iX > iY ? iA : iB ) * Math.Abs(iX - iY));      // A B の少ない方でC + 多い方で残り
            lstS.Sort();

            // 出力
            Console.WriteLine("{0}", lstS[0].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
     
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
     
#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>
     
int main(){
  string S;
  lli i=0;
  cin>>S;

  i=S.length()-1;

  while(i>=0){
    if(i>=6 and S.substr(i-6,7)=="dreamer"){
      i=i-7;
    }else if(i>= 5 and S.substr(i-5,6)=="eraser"){
      i=i-6;
    }else if(i>=4 and S.substr(i-4,5)=="dream"){
      i=i-5;
    }else if(i>=4 and S.substr(i-4,5)=="erase"){
      i=i-5;
    }else{
      cout<<"NO"<<endl;
      return 0;
    }
  }

  cout<<"YES"<<endl;
      
  return 0;
}


Measured memory_bytes: 512
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007;
const int MAX = 100005;

int n, m, grid[77][77];
string s[77];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=0; i<n; i++) cin>>s[i];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            grid[i+1][j+1] = s[i][j]=='#';
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(grid[i][j]){
                bool ok=false;
                if(grid[i-1][j]) ok=true;
                if(grid[i+1][j]) ok=true;
                if(grid[i][j-1]) ok=true;
                if(grid[i][j+1]) ok=true;
                if(!ok) cout<<"No"<<endl, exit(0);
            }
        }
    }
    cout<<"Yes"<<endl;
	return 0;
}


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

void solve(int D, int M, long long magic, vector<long long>& c, 
           vector<vector<long long>>& s,
           vector<long long> &ans, long long &satis){
  long long la,onelos=0;
  for(int j=0; j<M; j++){
    onelos += c[j];
  }
  long long num = 10;
  vector<long long> sat(num,0), los(num,0), nlos(num,0);
  vector<pair<long long, long long>> tmpsat(num*M);
  vector<vector<long long>> last(num,vector<long long>(M,-1)), nlast(num,vector<long long>(M,-1));
  vector<vector<long long>> t(num,vector<long long>(D)), nt(num,vector<long long>(D));
  for(int i=0; i<D; i++){
    for(int j=0; j<num; j++){
      for(int k=0; k<M; k++){
        la = (long long)i - last[j][k];
    	tmpsat[j*M+k].first = sat[j] + s[i][k] - los[j] - onelos + la*c[k];
        tmpsat[j*M+k].first -= (los[j] - la*c[k])*magic; //mahou
        tmpsat[j*M+k].second = j*M+k;
      }
    }
    sort(tmpsat.begin(), tmpsat.end(), greater());
    for(int j=0; j<num; j++){
      sat[j] = tmpsat[j].first;
      long long ty = tmpsat[j].second%M;
      long long prenum = tmpsat[j].second/M;
      sat[j] += (los[prenum] - ((long long)i - last[prenum][ty])*c[ty])*magic; //mahoumo
      nlast[j] = last[prenum];
      nlast[j][ty] = (long long)i;
      nlos[j] = los[prenum] + onelos - ((long long)i - last[prenum][ty])*c[ty];
      nt[j] = t[prenum];
      nt[j][i] = ty;
    }
    for(int j=0; j<num; j++){
      last[j] = nlast[j]; los[j] = nlos[j]; t[j] = nt[j];
    }
  }
  satis = sat[0];
  ans = t[0];
}
int main(){
  int D, M=26;
  cin >> D;
  vector<long long> c(M);
  for(int i=0; i<M; i++){
    cin >> c[i];
  }
  vector<vector<long long>> s(D,vector<long long>(M));
  for(int i=0; i<D; i++){
    for(int j=0; j<M; j++){
      cin >> s[i][j];
    }
  }
  vector<long long> ans(M),anss(M);
  long long satis=0,maxsatis = -1e10;
  for(long long magic=0; magic<26; magic++){
  	solve(D,M,magic,c,s,ans,satis);
    if(satis > maxsatis){
      maxsatis = satis;
      anss = ans;
    }
  }
  //cout << sat[0] << endl;
  for(int i=0; i<D; i++){
    cout << anss[i]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3800
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String args[]) {
		new Main().solve();
	}
	void solve() {
		Scanner scan = new Scanner(System.in);
		Stack<Integer> stack = new Stack<Integer>();
		String[] strArray = scan.nextLine().split(" ");
		for (int i = 0; i < strArray.length; i++) {
			String str = strArray[i];
			int x,y;
			switch(str.charAt(0)) {
			case '+':
				y = stack.pop();
				x = stack.pop();
				stack.add(x + y);
				break;
			case '-':
				y = stack.pop();
				x = stack.pop();
				stack.add(x - y);
				break;
			case '*':
				y = stack.pop();
				x = stack.pop();
				stack.add(x * y);
				break;
			default:
				stack.add(Integer.parseInt(str));
				break;
			}
		}
		System.out.println(stack.pop());
	}
}



Measured memory_bytes: 26280
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6 + 3)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
int exp(int a, int b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum)%MOD;
        sum = (sum * sum) % MOD;
        b >>= 1;
    }
    return res;
}

int main(){
    int line[3];
    REP(i, 3){
        cin >> line[i];
    }
    sort(line, line+3);
    cout << line[0] + line[1] << endl;
    return 0;
}


Measured memory_bytes: 764
import math
def l2(x,y,z):
    return math.sqrt(x*x+y*y+z*z)
while True:
    s = input()
    if s == '-1 -1 -1 -1':
        break
    a,b,c,d = map(float, s.split())
    a = (a / 360) * 2 * math.pi
    b = (b / 360) * 2 * math.pi
    c = (c / 360) * 2 * math.pi
    d = (d / 360) * 2 * math.pi
    x1 = math.cos(b)*math.cos(a)
    y1 = math.sin(b)*math.cos(a)
    z1 = math.sin(a)
    x2 = math.cos(d)*math.cos(c)
    y2 = math.sin(d)*math.cos(c)
    z2 = math.sin(c)
    theta = math.acos(x1*x2 + y1*y2 + z1*z2)
    print(round(6378.1*theta))

Measured memory_bytes: 7844
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int n;
int a[15];
int cnt=0;
void dfs(int step)
{
    if(step==n+1)
    {
        for(int i=1;i<=n;i++) putchar('a'+a[i]-1);
        putchar('\n');
        return;
    }
    for(int i=1;i<=cnt;i++) a[step]=i,dfs(step+1);
    cnt++,a[step]=cnt,dfs(step+1),cnt--;
}
int main()
{
    cin>>n;
    dfs(1);
	return 0;
}


Measured memory_bytes: 1536
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String ans = "AC";
        if(S.charAt(0)!='A') ans = "WA";
        int cntC = 0;
        for(int i=2;i<S.length()-1;i++){
            if(S.charAt(i)=='C') cntC ++;
        }
        if(cntC!=1) ans = "WA";
        int cnt = 0;
        for(int i=1;i<S.length();i++){
            char cur = S.charAt(i);
            if(cur<'a'||cur>'z') cnt++;
        }
        if(cnt!=1) ans = "WA";
        System.out.println(ans);
    }
}


Measured memory_bytes: 22868
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i
sum=A.inject(:+)
ans=INF
l=0
N.times do|i|
    ans=min(ans,(sum-l-l).abs)
    l+=A[i]
end
puts ans

Measured memory_bytes: 30172
#include <iostream>
    #include <algorithm>

    using namespace std;
    int x[51], y[51];

    void BSort(int n)
    {
        int ok = 0;
        while (!ok) {
            ok = 1;
            for (int i = 1; i < n; ++i)
            if (x[i] > x[i + 1]) {
                swap(x[i], x[i + 1]);
                swap(y[i], y[i + 1]);
                ok = 0;
            }
        }
    }

    int min_3(int a, int b, int c, int d)
    {
        return min(min(min(a, b), c), d);
    }

    int max_3(int a, int b, int c, int d)
    {
        return max(max(max(a, b), c), d);
    }

    int ind_x(int border, int i, int j, int o, int l)
    {
        if (border == x[i])
            return i;
        if (border == x[j])
            return j;
        if (border == x[o])
            return o;
        if (border == x[l])
            return l;
        return 0;
    }

    int ind_y(int border, int i, int j, int o, int l)
    {
        if (border == y[i])
            return i;
        if (border == y[j])
            return j;
        if (border == y[o])
            return o;
        if (border == y[l])
            return l;
        return 0;
    }

    int main()
    {
        int n, k, first, cell_cnt[51][51] = {0};
        long long small_area, area;

        cin >> n >> k;
        for (int i = 1; i <= n; ++i)
            cin >> x[i] >> y[i];
        BSort(n);

        for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            for (int o = 1; o <= n; ++o)
                if (x[o] <= x[i] && y[o] <= y[j])
                    cell_cnt[i][j]++;
        }

        long long left_m, down_m, right_m, up_m;
        int left_i, down_i, right_i, up_i;
        first = 1;
        for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
        for (int o = 1; o <= n; ++o)
        for (int l = 1; l <= n; ++l) {
            left_m = min_3(x[i], x[j], x[o], x[l]);
            left_i = ind_x(left_m, i, j, o, l);

            down_m = min_3(y[i], y[j], y[o], y[l]);
            down_i = ind_y(down_m, i, j, o, l);

            right_m = max_3(x[i], x[j], x[o], x[l]);
            right_i = ind_x(right_m, i, j, o, l);

            up_m = max_3(y[i], y[j], y[o], y[l]);
            up_i = ind_y(up_m, i, j, o, l);

            if (cell_cnt[right_i][up_i] - cell_cnt[left_i - 1][up_i] - cell_cnt[right_i][down_i] + cell_cnt[left_i - 1][down_i] + 1 >= k) {
                area = (right_m - left_m) * (up_m - down_m);
                if (first) {
                    small_area = area;
                    first = 0;
                }
                else
                    small_area = min(small_area, area);
            }
        }
        cout << small_area;
        return 0;
    }


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
kisuu = 0
guusuu = 0
baisuu_4 = 0

for num in a:
  if num%2 == 1:
    kisuu += 1
  elif num%4 == 2:
    guusuu += 2
  else:
    baisuu_4 += 1

if guusuu ==0:
  if baisuu_4 >= kisuu - 1:
    print('Yes')
  else:
    print('No')
else:
  if baisuu_4 >= kisuu:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 14252
from collections import defaultdict

N = int(input())

power = defaultdict(int)
for k in range(2, N + 1):
    _k = k
    for p in range(2, k + 1):
        while _k % p == 0:
            power[p] += 1
            _k //= p
ans = 1
for n in power.values():
    ans *= n + 1
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>


using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int dp[1500][1500];

int main(){
    rep(i,1010){
        rep(j,1010){
            dp[i][j] = inf;
        }
    }
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h)cin >> s[i];
    queue<pair<int,int> > q;
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                q.push(MP(i,j));
                dp[i][j] = 0;
            }
        }
    }
    while(!q.empty()){
        auto x = q.front();
        q.pop();
        int a = x.first;
        int b = x.second;
        if(a>0){
            if(dp[a-1][b]==inf){
                dp[a-1][b] = dp[a][b] + 1;
                q.push(MP(a-1,b));
            }
        }
        if(a<h-1){
            if(dp[a+1][b]==inf){
                dp[a+1][b] = dp[a][b] + 1;
                q.push(MP(a+1,b));
            }
        }
        if(b>0){
            if(dp[a][b-1]==inf){
                dp[a][b-1] = dp[a][b] + 1;
                q.push(MP(a,b-1));
            }
        }
        if(b<w-1){
            if(dp[a][b+1]==inf){
                dp[a][b+1] = dp[a][b] + 1;
                q.push(MP(a,b+1));
            }
        }
    }
    int mx = 0;
    rep(i,h){
        rep(j,w){
            mx = max(mx,dp[i][j]);
        }
    }
    cout << mx << endl;
    return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

vector<int> ans;
void func(ll N){
    if(N==0)return;
    ll sum = 0;
    ll b = 1;
    int i = 0;
    if(N < 0){
        b = -2;
        i = 1;
    }
    for(;; i+=2){
        sum+=b;
        if(abs(sum) >= abs(N)){
            ans.push_back(i);
            break;
        }
        b*=4;
    }
    func(N-b);
    
}

int main()
{

    
    ll N;
    cin >> N;
    if(N == 0){
        cout << '0' << endl;
        return 0;
    }
    func(N);
    
    bool f0 = false;
    for(int i = 32; i >=0; i--){
         bool f = false;
        
        for(int j = 0; j < ans.size(); j++){
            if(ans[j]==i){
                cout << '1' ;
                f0 = true;
                //cout << "i" << i << endl;
                f = true;
                break;
            }
        }
        if(!f && f0){
            cout << '0' ;
        }
    }
    cout << endl;
    return 0;
//11000101011001101110100010101
//11000101011001101110100010101





}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdlib>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
const int N=1e6+11,mod=1e9+7;
int go[8][2]={{2,1},{4,3},{6,5},{3,3},{7,1},{2,1},{2,2},{4,4}};
int f[N][9];
char s[N];
int n;
inline void inc(int &x,int y){
	x+=y;
	if(x>=mod)
		x-=mod;
}
int main(){
	f[0][0]=1;
	gets(s+1);
	n=strlen(s+1);
	rep(i,1,n){
		rep(j,0,8){
			if(s[i]!='0')
				inc(f[i][go[j][1]],f[i-1][j]);
			if(s[i]!='1')
				inc(f[i][go[j][0]],f[i-1][j]);
		}
	}
	printf("%d\n",(f[n][1]+f[n][3])%mod);
	return 0;
}

Measured memory_bytes: 11776
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main(){
    ll n , m ;
    cin >> n >> m ;
    
    ll p[m] , q[m] ;
    for(int i = 0 ; i < m ; i++){
        cin >> p[i] >> q[i] ;
    }

    vector<ll> yd[n+1];
    for(int i = 0 ; i < m ; i++){
        yd[p[i]].push_back(q[i]);
    }
    for(int j = 0 ; j < n ; j++){
        sort(yd[j+1].begin(),yd[j+1].end());
    }
    for(int i = 0 ; i < m ; i++){
        printf ("%012lld\n",ll(p[i])*1000000+lower_bound(yd[p[i]].begin(),yd[p[i]].end(),q[i])-yd[p[i]].begin()+1); 
    }

    

    return 0 ;
}

Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    VPII nd(N);
    nd[0] = MP(210, 210);
    FOR(i, 1, N) {
        int n, d;
        cin >> n >> d;
        int x, y;
        tie(x, y) = nd[n];
        if (d == 0) {
            x--;
        } else if (d == 1) {
            y--;
        } else if (d == 2) {
            x++;
        } else {
            y++;
        }
        nd[i] = MP(x, y);
    }
    int xmax = 0, ymax = 0;
    int xmin = INF, ymin = INF;
    FORE(el, nd) {
        xmax = max(xmax, el.first);
        xmin = min(xmin, el.first);
        ymax = max(ymax, el.second);
        ymin = min(ymin, el.second);
    }
    cout << xmax - xmin + 1 << " " << ymax - ymin + 1 << endl;
    return;
}

int main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c;
    while (cin >> n) {
        if (n == 0) return 0;
        solve(n);
        //return 0;
    }
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    ll N; cin >> N;
    vector<ll> A(N+1);
    vector<ll> s(N+2);
    
    s[0] = 0;
    rep(i, N+1) {
        cin >> A[i];
        s[i+1] = s[i] + abs(A[i] - (i==0 ? 0 : A[i-1]));
    }
    A[N]=0;
// cout_h(A);
// cout_h(s);
    rep(i, N) {
        cout << 
            s.back() - (s[i+2] - s[i]) + abs(A[i+1] - (i==0 ? 0 : A[i-1]))
        << endl;
    }
    
    
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second
typedef long long ll;
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll n,w;	cin>>n>>w;
	ll wei[n+1],val[n+1];

	for(ll i=1;i<=n;i++){
		cin>>wei[i]>>val[i];
	}
	
	ll dp[n+1][w+1]; //max value when first i objs are considered and total weight <= j
	
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=w;j++){
			if(i==0||j==0)	dp[i][j]=0;
			else{
				if(j-wei[i]>=0){
					dp[i][j]=max(dp[i-1][j-wei[i]]+val[i], dp[i-1][j]);
				}
				else{
					dp[i][j]=dp[i-1][j];
				}
			}
		}
	}

	cout<<dp[n][w]<<'\n';
	
	return 0;
}


Measured memory_bytes: 79232
from collections import deque
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = 0

def bfs(y,x,m):
  g = [[None if S[i][j] == '.' else -1 for j in range(W)] for i in range(H)]
  g[y][x] = 0
  q = deque()
  q.append((y,x))
  while q:
    i,j = q.popleft()
    for di,dj in ((0,1),(1,0),(-1,0),(0,-1)):
      ni = i+di; nj = j+dj
      if 0 <= ni < H and 0 <= nj < W and g[ni][nj] is None:
        g[ni][nj] = g[i][j] + 1
        q.append((ni,nj))
  return max(max(r) for r in g)

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      deq = bfs(i,j,S)
      if ans < deq:
        ans = deq
print(ans)

Measured memory_bytes: 3316
# _S = input()
# T = input()

# _S = list("?tc????")
# T = list("coder")


# _S = list("??p??d??")
# T = list("abc")

_S = list(input())
T = list(input())

def calculate(_S,T):
    _sl = len(_S)
    tl = len(T)

    result = []
    for startIndex in range(0,_sl - tl + 1):

        isOk = True
        for j in range(tl):
            _SValue = _S[startIndex+j]
            if (_SValue != "?") and (_SValue != T[j]):
                isOk = False
                break


        if isOk:
            copyS = _S.copy()
            copyS[startIndex:startIndex + tl] = T
            res = "".join(copyS).replace("?","a")
            result.append(res)


    if len(result) == 0:
        print("UNRESTORABLE")
    else:
        result = sorted(result)
        print(result[0])

calculate(_S,T)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<128>>;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << (x) << '\n'
typedef long long lint;
const int INF = 2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const lint LINF = 1e18;
typedef vector<int> vint;
typedef pair<int, int> pint;
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
void print() { cout << endl; }
template <class T, class... A> void print(const T &first, const A &... rest) {
    cout << first;
    print(rest...);
}
template <class... A> void print(const A &... rest) { print(rest...); }
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(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    string s, t;
    cin >> s >> t;
    int slen = s.size();
    int tlen = t.size();
    s = "a" + s;
    t = "b" + t;
    debug(s);
    debug(t);

    int dp[slen + 10][tlen + 10];
    rep(i, slen + 10) {
        rep(j, tlen + 10) { dp[i][j] = 0; }
    }
    rep(i, 1, slen + 10) {
        rep(j, 1, tlen + 10) {
            if(s[i] == t[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    int len = dp[slen][tlen];
    int i = slen, j = tlen;
    vector<char> ans(len + 1);
    while(len > 0) {
        if(s[i] == t[j]) {
            ans[len] = s[i];
            i--;
            j--;
            len--;
        } else if(dp[i][j] == dp[i - 1][j]) {
            i--;
        } else {
            j--;
        }
    }
    rep(i, 1, ans.size()) { cout << ans[i]; }
    cout << "\n";
}

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

int main(){
  int a,b,c,x; cin>>a >>b >>c >>x;
  int ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(x==500*i+100*j+50*k)ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

struct UnionFind {
  private:
  vector<int> child,tree;
  vector<vector<int>> list;

public:
  UnionFind(int v) {
    tree.resize(v);
    list.resize(v);
    REP(i,v) tree[i] = i, list[i].push_back(i);
  }

  int root(int i){
    if(i == tree[i]){
      REP(j,child.size()) tree[child[j]] = i;
      child.clear(); 
      return i;
    }
    else{
      child.push_back(i);
      return i = root(tree[i]);
    }
  }

  int size(int i){
    return list[root(i)].size();
  }

  vector<int> nodes(int no){
    return list[root(no)];
  }

  bool unit(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return false;
    if(list[x].size() < list[y].size()) swap(x,y);
    for(int no:list[y]) list[x].emplace_back(no);
    tree[y] = x;
    return true;
  }

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

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    pvec x(n),y(n);
    rep(i,n){
        cin>>x[i].fs>>y[i].fs;
        x[i].sc=i; y[i].sc=i;
    }
    sort(all(x)); sort(all(y));
    vector<T> z;
    rep(i,n-1){
        int dist=abs(x[i].fs-x[i+1].fs);
        z.eb(dist,x[i].sc,x[i+1].sc);
    }
    rep(i,n-1){
        int dist=abs(y[i].fs-y[i+1].fs);
        z.eb(dist,y[i].sc,y[i+1].sc);
    }
    sort(all(z));
    UnionFind uf(n);
    int cnt=0;
    int ans=0;
    for(auto &pass:z){
        int dist,a,b;
        tie(dist,a,b)=pass;
        if(uf.isUnit(a,b)) continue;
        ans+=dist;
        uf.unit(a,b);
        cnt++;
        if(cnt==n-1) break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 23532
#include <stdio.h>

int main(void){
    int a,b,n,x,i;
    
    for(;;){
        i=0;
        scanf("%d%d",&n,&x);
        if(n+x == 0) break;
        
        for(a=1;a<=n;a++)
            for(b=a+1;b<=n;b++)
                if(b < x-a-b && x-a-b <= n)
                    i++;
        
        printf("%d\n", i);
    }
    
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%1000 == 0){
    cout << 0 << endl;
    return 0;
  }
  cout << 1000 - (n%1000) << endl;
  return 0;
}


Measured memory_bytes: 3632
<?php
fscanf(STDIN, '%d %d', $a, $b);
echo lcm($a, $b);

function gcd ($m, $n) {
    while ($m % $n !== 0) {
        $temp = $n;
        $n = $m % $n;
        $m = $temp;
    }
    return $n;
}
    
function lcm ($m, $n) {
    return $m * $n / gcd($m, $n);
}

Measured memory_bytes: 4728
#include<stdio.h>
int main(void){
    int a,b,add,sub,mul,max=-10000000;
    scanf("%d %d",&a,&b);
    add=a+b;
    if(add>max)max=add;
    sub=a-b;
    if(sub>max)max=sub;
    mul=a*b;
    if(mul>max)max=mul;

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

    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, b, c, d, r = 999999999;
int main() {
	cin >> n >> a >> b >> c >> d; a--, b--, c--, d--;
	for(int i = 1; i <= n; i++) r = min(r, abs(a / i - b / i) + abs(a % i - b % i) + abs(c / i - d / i) + abs(c % i - d % i));
	cout << r << endl;
}

Measured memory_bytes: 3104
#D
#入力
S=input()
Q=int(input())
#Query=[]
#for i in range(Q):
#    Query.append(list(input().split()))
    
    
#処理
t=0
b=""
a=""
for j in range(Q):
    i=list(input().split())
    if i[0]=="1":
        t+=1
    elif i[0]=="2":
        if t%2==0:
            if i[1]=="1":
                b=i[2]+b
            elif i[1]=="2":
                a=a+i[2]
        elif t%2==1:
            if i[1]=="1":
                a=a+i[2]
            elif i[1]=="2":
                b=i[2]+b
if t%2==0:
    print(b+S+a)
    
else:
    print(a[::-1]+S[::-1]+b[::-1])

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n, m; std::cin >> n >> m;
  string ans(n, '0');
  if (n > 1) ans[0] = '1';
  map<int, int> cnt;
  bool ok = true;
  rep(i, m) {
    int s, c; std::cin >> s >> c;
    ans[s-1] = '0' + c;
    if (cnt.count(s) != 0 && cnt[s] != c)
      ok = false;
    cnt[s] = c;
  }
  if (n > 1 && cnt.count(1) != 0 && cnt[1] == 0) ok = false;
  std::cout << (ok ? ans : "-1") << "\n";
}


Measured memory_bytes: 256
# 木の高さをソート, それぞれの差をリストに格納する, 小さい方から数えてK番目の値が可能な最小値

N, K = map(int, input().split())

h = sorted([int(input()) for _ in range(N)])

# print('h =', h)
dif_h = []

K = K -1

for i in range(K, N):
    dif_h.append(h[i]-h[i-K])

ascending_dif_h = dif_h.sort()
# print('as_dif_h =', dif_h)

print(dif_h[0])


Measured memory_bytes: 11324
#include <bits/stdc++.h>
using namespace std ;
int a,b,c,arr[10];
int main(){
	
	cin>>a>>b>>c;
	
	arr[a]++;
	arr[b]++;
	arr[c]++;
	
	if(arr[a]==2 or arr[b]==2 or arr[c]==2){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    string s;
    cin>>s;
    string t = s;
    reverse(s.begin(), s.end());
    int cnt(0);
    for(int i = 0; i < s.size()/2; i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	ll X;
	cin >> X;
	ll s = 0;
	int i = 1;
	while (s < X) {
		s += i;
		i++;
	}
	cout << i - 1 << endl;
}


Measured memory_bytes: 256
s = gets.chomp.split('')
x, y = gets.split.map(&:to_i)

while s[0] == 'F'
    x -= 1
    s.shift
end

moves_x = []
moves_y = []
move_x = true
while s.length > 0 do
    if s[0] == 'T'
        move_x = !move_x
        s.shift
    else
        m = 0
        while s[0] == 'F' do
            s.shift
            m += 1
        end
        if move_x
            moves_x.push(m)
        else
            moves_y.push(m)
        end
    end
end

def check(moves, target)
    len = moves.length
    if len == 0
        return target == 0
    end
    dp = Array.new(len){Hash.new()}
    dp[0][moves[0]] = true
    dp[0][-moves[0]] = true
    (1...len).each do |i|
        dp[i - 1].each do |key, _|
            dp[i][key+moves[i]] = true
            dp[i][key-moves[i]] = true
        end
    end
    return dp[len - 1][target]
end

if check(moves_x, x) && check(moves_y, y)
    puts 'Yes'
else
    puts 'No'
end

Measured memory_bytes: 232572
#include<stdio.h>

int main(){
  int A[3];
  scanf("%d" "%d" "%d",&A[0],&A[1],&A[2]);
  int max=A[0];int min=A[0];
  for(int i=1;i<3;i++){
    if(max<A[i]){max=A[i];}
    if(min>A[i]){min=A[i];}
  }
  printf("%d",max-min);
}


Measured memory_bytes: 128
import math
N, A, B = map(int, input().split())
H =[int(input()) for _ in range(N)]
H.sort(reverse = True)
s = 0
l = H[0]//B + 1
while l - s > 1:
    cnt = 0
    mid =(s+l) // 2
    x = mid*B
    for h in H:
        if h > x:
            cnt += math.ceil((h-x)/(A-B))
        else:
            break
    if cnt > mid:
        s = mid
    else:
        l = mid
print(l)

Measured memory_bytes: 7512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long x = sc.nextLong();

		long ans = x / 11 * 2;
		long amari = x % 11;
		if(amari > 6) {
			ans += 2;
		} else if(amari >= 1) {
			ans++;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 35600
a = gets.to_i
i = 3
while i <= a do
  if (i%3 == 0)
    print " #{i}"
  else
  j = i
    while j != 0
      if (j%10 == 3)
        print " #{i}"
        break
      else 
        j /=10  
      end
     
    end

  end
  i=i+1

end
puts ""
  


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

int main(){
    int n, m;
    double sum;
    cin >> n;
    int x[n], y[n];
    for (int i=0; i<n; i++) cin >> x[i];
    for (int i=0; i<n; i++) cin >> y[i];
    // p = 1
    sum = 0;
    for (int i=0; i<n; i++) sum += abs(x[i]-y[i]);
    cout << fixed << setprecision(6) << sum << endl;
    // p = 2
    sum = 0;
    for (int i=0; i<n; i++) sum += pow(x[i]-y[i], 2);
    cout << fixed << setprecision(6) << sqrt(sum) << endl;
    // p = 3
    sum = 0;
    for (int i=0; i<n; i++) sum += pow(abs(x[i]-y[i]), 3);
    cout << fixed << setprecision(6) << pow(sum, 1.0/3.0) << endl;
    // p = inf
    m = abs(x[0]-y[0]);
    for (int i=1; i<n; i++) m = max(m, abs(x[i]-y[i]));
    cout << fixed << setprecision(6) << (double)m << endl;
    return 0;
}


Measured memory_bytes: 3464
n, k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    p[i] = (p[i] * -~p[i]) / 2 / p[i]
ans = v = sum(p[:k])
for i in range(n - k):
    v = v - p[i] + p[k + i]
    ans = max(ans, v)
print(ans)


Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string str;
    cin >> str;
    int q;
    cin >> q;
    rep(i,q){
        string c;
        cin >> c;
        if(c == "print"){
            int a,b;
            cin >> a >> b;
            cout << str.substr(a,b-a+1) << endl;

        }else if (c == "reverse")
        {
            int a,b;
            cin >> a >> b;
            reverse(str.begin()+a,str.begin()+b+1);

        }else if(c == "replace"){
            int a,b;
            string s;
            cin >> a >> b >> s;
            str.replace(a,b-a+1,s);

        }
        //cerr << "DEBUG:" << str << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3204
// Problem : B - Homework
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define pii pair<int,int>
#define S second
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
#define mod 1000000007
#define YES "YES"
#define NO "NO"
const long long INF = 1000000000000000000LL;
//const int WASTE=∞;
ll power(ll a,ll b){
	ll i=1;
	while(b){
		if(b%2)
			i=(i*a)%mod;
		b/=2;
		a=(a*a)%mod;
	}
	return i;
}
ll mulmod(ll a, ll b) { 
    ll res = 0;
    a = a % mod; 
    while (b > 0) {
        if (b % 2 == 1) 
            res = (res + a) % mod; 
        a = (a * 2) % mod; 
        b /= 2; 
    }
    return res % mod; 
} 
const int N=1e5+5;
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  	// cout<<fixed;
  	// cout.precision(10);
   	
   	int n,m;
   	cin>>n>>m;
   	int a=0;
   	while(m--){
   		int i;
   		cin>>i;
   		a+=i;
   	}
   	if(a>n) cout<<-1;
   	else cout<<n-a;
   	
   	
   	
   	
   	
   	
   	
   	
   	
  	return 0;
}



Measured memory_bytes: 3644
#include <stdio.h>

typedef struct
{
  char ch;
  char num;
}P;

void Bubble(P C[],int n)
{
  P t;
  int i,j;

  for(i = 0;i < n;i++)
  {
    for(j = n - 1;j >= i + 1;j--)
    {
      if(C[j].num < C[j - 1].num)
      {
        t = C[j];
        C[j] = C[j - 1];
        C[j - 1] = t;
      }
    }
  }
}

void Select(P C[],int n)
{
  P t;
  int i,j,min;

  for(i = 0;i < n;i++)
  {
    min = i;
    for(j = i;j < n;j++)
    {
      if(C[j].num < C[min].num) min = j;
    }
    t = C[i];
    C[i] = C[min];
    C[min] = t;
  }
}

void Print(P C[],int n)
{
  int i;

  for(i = 0;i < n;i++)
  {
    if(i) printf(" ");
    printf("%c",C[i].ch);
    printf("%c",C[i].num);
  }
  printf("\n");
}

int Judg(P C1[],P C2[],int n)
{
  int i;

  for(i = 0;i < n;i++)
  {
    if(C1[i].ch != C2[i].ch) return 0;
  }
  return 1;
}

int main()
{
  P C1[100],C2[100];
  int i,n;

  scanf("%d",&n);
  for(i = 0;i < n;i++)
  {
    scanf(" %c%c",&C1[i].ch,&C1[i].num);
    C2[i] = C1[i];
  }

  Bubble(C1,n);
  Print(C1,n);
  printf("Stable\n");

  Select(C2,n);
  Print(C2,n);
  if(Judg(C1,C2,n)) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}



Measured memory_bytes: 2052
import math
def main():
    a,b,h,m = map(int, input().split())
 
    ar = h * 360 / 12 + m * 30 / 60
    br = m * 360 / 60
    kakudo = x if (x := abs(ar-br)) < 180 else 360-x
    ans = a**2+b**2-2*a*b*math.cos(math.radians(kakudo))
    print(ans**0.5)
if __name__ == "__main__":
    main()

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

public class Main{
    public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int a[] = new int[N];
			for(int j=0; j<N; j++){
				a[j] = sc.nextInt();
			}
			Arrays.sort(a);
			
			int desOrder[] = new int[N];
			for(int j=0; j<N; j++){
				desOrder[N-j-1] = a[j];
			}
			int AliceScore = 0;
			int BobScore = 0;
			for(int j=0; j<N; j++){
				if(j%2==0){
					AliceScore = AliceScore+desOrder[j];
				}else{
					BobScore = BobScore+desOrder[j];
				}
			}
			System.out.println(AliceScore-BobScore);
		}
}


Measured memory_bytes: 22736
#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 N, K;
vector<int> G[100005];
ll ret;

#define MOD 1000000007
#define MX 200005

ll fact[MX];
ll invfact[MX];

ll mod_pow(ll x, ll n){
  if(n==0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if(n & 1) res = res * x % MOD;
  return res;
}
ll mod_comb(ll n, ll k){
  if(n<0 || k<0 || n<k) return 0;
  return (((fact[n] * invfact[k]) % MOD) * invfact[n-k]) % MOD;
}
ll mod_perm(ll n, ll k){
  if(n<0 || k<0 || n<k) return 0;
  return (fact[n] * invfact[n-k]) % MOD;
}
ll mod_fact(ll n){
  if(n<0) return 0;
  return fact[n];
}
void mod_init(){
  fact[0] = fact[1] = 1;
  for(ll i=2; i<MX; i++) fact[i] = (fact[i-1] * i) % MOD;
  invfact[0] = invfact[1] = 1;
  for(ll i=2; i<MX; i++) invfact[i] = mod_pow(fact[i], MOD-2);
}

void dfs(int v, int p){
  ll M = 1;
  if(p!=-1) M++;
  ret *= mod_perm(K-M, G[v].size() - ((p==-1)?0:1));
  ret %= MOD;
  rep(i,G[v].size()){
    if(G[v][i] == p) continue;
    dfs(G[v][i], v);
  }
}

int main(){
  mod_init();
  cin >> N >> K;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  ret = 1;
  dfs(0, -1);
  ret *= K;
  ret %= MOD;
  
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    int n,m;
    cin>>n;
    int Gcd=0;
    for(int i=0; i<n; i++){
        cin>>m;
        Gcd=gcd(Gcd,m);
    }
    cout<<Gcd<<endl;
    return 0;
}


Measured memory_bytes: 256