akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
 
const ll mod = (ll)1e9+7;
const ll maxn = (ll)3e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;
 
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

ll dis[1000005];
ll p[1000005];
ll ty[1000005]; 
void solve(){
     
	ll n;
	cin >> n;
	
	priority_queue < pair < pair < ll , ll >  , pair< ll , ll >  > , vector < pair < pair < ll , ll >  , pair< ll , ll >  >  > , greater < pair < pair < ll , ll >  , pair< ll , ll >  > > > pp;
	mem(dis,-1);
	mem(ty, -1);
	pp.push({{ 1 , -1  } , {-1 , -1}});
	mem(p,-1);
	while(!pp.empty()){
		pair < pair < ll , ll >  , pair< ll , ll >  > s = pp.top();
		pp.pop();
		s.ff.ss *=-1;
		if(dis[s.ff.ss] != -1) continue;
		dis[s.ff.ss] = s.ff.ff;
		p[s.ff.ss] = s.ss.ff;
		ty[s.ff.ss] = s.ss.ss;
		ll p1 = (s.ff.ss*10)%n;
		if(dis[p1] == -1)pp.push( { {dis[s.ff.ss] , -p1}  , { s.ff.ss  , 0LL }  });
		p1 = (s.ff.ss+1)%n;
		if(dis[p1] == -1)pp.push({ {dis[s.ff.ss]+1 , -p1} , { s.ff.ss , 1LL } }) ;
	}
	vector < ll > v;
	ll node = 0;
	cout << dis[0] << '\n'; 
	return;
}
 
 
int main() {
 
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
 
    return 0;
}

Measured memory_bytes: 28688
#include <iostream>


using namespace std;
int main(){
   int a,b,c;
   cin>>a>>b>>c;
   if(a!=b&&a!=c&&b!=c){
       cout<<"No";
       
       
   }
   else{
       if(a==b&&b==c){
           cout<<"No";
       }
       else{
           cout<<"Yes";
           
       }
   }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 30;
const double EPS = 1E-9;

map<string, bool> mp;
int n;

vector<string> make_list(string s){
	vector<string> ls;
	int sz = s.size();
	int i = 0, j = 0;
	while( i < sz){
		j = i;
		while(j < sz && isalpha(s[j])) j++;
		ls.push_back(s.substr(i, j - i));
		i = ++j;
	}
	return ls;
}

int main(){
	while(cin >> n && n){
		vector<string> vs[100];
		string s;
		getline(cin, s);
		for(int i = 0; i < n; i++){
			getline(cin, s);
			vs[i] = make_list(s);
			mp[vs[i][0]] = true;
		}
		bool update = true;
		while(update){
			update = false;
			for(int j = 1; j < (int)vs[0].size(); j++){
				if(mp[vs[0][j]]){
					update = true;
					for(int k = 0; k < n; k++){
						if(vs[0][j] == vs[k][0]){
							for(int l = 1; l < (int)vs[k].size(); l++){
								bool f = true;
								for(int m = 1; m < (int)vs[0].size(); m++){
									if(vs[0][m] == vs[k][l]){
										f = false;
										break;
									}
								}
								if(f)vs[0].push_back(vs[k][l]);
							}
							break;
						}
					}
					vs[0].erase(vs[0].begin() + j);
					break;
				}
			}
		}
		int mem = vs[0].size() - 1;
		mp.clear();
		for(int i = 0; i < n; i++){
			vs[i].clear();
		}
		cout << mem << endl;
	}
	return 0;
}

Measured memory_bytes: 1012
// Frog 1.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
const int G = 1000 * 100 + 10;
int a[G];
long long dp[G];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[1] = abs(a[0] - a[1]);
	for (int i = 2; i < n; i++){
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]),dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}



Measured memory_bytes: 4708
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 105;

vector<double> X,Y,X1,Y1,X2,Y2;
bool flag[MAX_N*2][MAX_N*2];
int n;

int main()
{
	double p,q,r;
	int id=1;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		X.clear(),Y.clear(),X1.clear(),Y1.clear(),X2.clear(),Y2.clear();
		rep(i,n*2){
			rep(j,n*2){
				flag[i][j] = false;
			}
		}
		rep(i,n){
			scanf("%lf%lf%lf",&p,&q,&r);
			X.push_back(p+r),X.push_back(p-r);
			Y.push_back(q+r),Y.push_back(q-r);
			X1.push_back(p-r),X2.push_back(p+r);
			Y1.push_back(q-r),Y2.push_back(q+r);
		}
		sort(X.begin(),X.end());
		sort(Y.begin(),Y.end());
		X.erase(unique(X.begin(),X.end()),X.end());
		Y.erase(unique(Y.begin(),Y.end()),Y.end());
		rep(i,n){
			X1[i] = lower_bound(X.begin(),X.end(),X1[i]) - X.begin();
			Y1[i] = lower_bound(Y.begin(),Y.end(),Y1[i]) - Y.begin();
			X2[i] = lower_bound(X.begin(),X.end(),X2[i]) - X.begin();
			Y2[i] = lower_bound(Y.begin(),Y.end(),Y2[i]) - Y.begin();
		}
		rep(i,n){
			for(int j=Y1[i];j<Y2[i];j++){
				for(int k=X1[i];k<X2[i];k++){
					flag[j][k] = true;
				}
			}
		}
		double ans = 0;
		rep(i,Y.size()-1){
			rep(j,X.size()-1){
				if(flag[i][j]){
					ans += (X[j+1]-X[j])*(Y[i+1]-Y[i]);
				}
			}
		}
		printf("%d %.2f\n",id,ans);
		id++;
	}
	return 0;
}

Measured memory_bytes: 3320
import numpy as np
n, m = map(int, input().split())

img = np.array([list(input()) for i in range(n)])
w = img.shape[-1]
template = np.array([list(input()) for i in range(m)])
tw = template.shape[-1]

for y in range(n - m + 1):
    for x in range(w - tw + 1):
        if np.all(img[y:y + m, x:x + tw] == template):
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 21660
let pr x = print_endline @@ string_of_int x

let fold f init s =
  let rec iter i res =
    if i < 0 then res else iter (i - 1) (f res s.[i]) in
  iter (String.length s - 1) init

let solve seq =
  let len = String.length seq in
  let (_,_,res) = fold
                    (fun (cnt,pre,mv) x ->
                      if x != pre then
                        (cnt+1,x,min mv (max cnt (len - cnt)))
                      else (cnt+1,x,mv))
                    (0,seq.[0],len) seq in res

let () = input_line stdin
         |> solve
         |> pr

Measured memory_bytes: 4864
import java.util.Scanner;
public class Main {
	int d,k;
	public void solve() {
	Scanner sc = new Scanner(System.in);
	String a = sc.next();

	if( Character.isUpperCase( a.charAt( 0 ) ) ) {
	    System.out.println("A");
	}else {
	    System.out.println("a");
	}
	}
	public static void main(String[] args) {
		new Main().solve();
	
	}
}


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

int main() {
  int N;
  cin >> N;
  bool c = true;
  map<int, int> v;
  REP(i, N) {
    int n;
    cin >> n;
    if(v.count(n)) {
      cout << "NO" << endl;
      c = false;
      break;
    } else {
      v[n] = 1;
    }
  }
  if(c) cout << "YES" << endl;
}

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

int s[1000], d[1000], y[1000], a, b;
P p[100000];
int main() {
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n)scanf("%d", &s[i]);
		rep(i, m)scanf("%d%d", &a, &b), p[i] = { b,a };
		sort(p, p + m); iota(d, d + n, 0);
		rep(i, m) {
			swap(d[p[i].second - 1], d[p[i].second]);
			p[i] = { d[p[i].second - 1],d[p[i].second] };
			if (p[i].first > p[i].second)swap(p[i].first, p[i].second);
		}
		rep(i, n)y[d[i]] = s[i];
		int M = accumulate(y, y + k, 0); int S = M;
		rep(i, m) {
			if (p[i].first < k&&p[i].second >= k)
				M = min(M, S + y[p[i].second] - y[p[i].first]);
		}
		printf("%d\n", M);
	}
}

Measured memory_bytes: 3992
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n;
	scanf("%d", &n);
	int a;
	vector<int> count(100000);
	rep(i, n){
	  scanf("%d", &a);
	  ++count[a];
	  if(a > 0)++count[a - 1];
	  if(a < 100000 - 1)++count[a + 1];
	}
	int maxa = *std::max_element(all(count));
	printf("%d\n", maxa);
	
	Please AC;
}


Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

template<class T>
vector<T> topo_sort(vector<vector<T>> &graph){
    ll n = graph.size();
    vector<ll> in(n);
    rep(i,n)for(auto &to : graph[i])in[to]++;
    deque<ll> deq;
    rep(i,n)if(in[i] == 0)deq.emplace_back(i);
    vector<T> ret;
    while(!deq.empty()){
        ll t = deq.front();deq.pop_front();
        ret.emplace_back(t);
        for(auto &to : graph[t]){
            in[to]--;
            if(in[to] == 0)deq.emplace_back(to);
        }
    }

    return ret;
};

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    vector<vector<ll>> graph(n);
    rep(i,m) {
        ll a,b;cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        // graph[b].emplace_back(a);
    }
    auto topo = topo_sort(graph);
    ll ans = 0;
    vector<ll> dp(n);
    rep(i,n){
        ll pos = topo[i];
        for(auto &to : graph[pos]){
            chmax(dp[to], dp[pos] + 1);
        }
    }

    rep(i,n)chmax(ans, dp[i]);

    cout << ans << endl;
}

Measured memory_bytes: 10744
#include <stdio.h>

int main(void){
  int n,a[4][3][10],b,f,r,v,i;
  scanf("%d",&n);
  for(b = 0; b < 4; b++){
    for(f = 0; f < 3; f++){
      for(r = 0; r < 10; r++){
        a[b][f][r] = 0;
      }
    }
  }
  for(i = 0; i < n; i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    a[b - 1][f - 1][r - 1] += v;
  }
  for(b = 0; b < 4; b++){
    for(f = 0; f < 3; f++){
      for(r = 0; r < 10; r++){
        printf(" %d",a[b][f][r]);
      }
      printf("\n");
    }
    if(b != 3){
      printf("####################\n");
    }
  }
  return 0;
}


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

using namespace std;

int main(){
	int N;
	cin >> N;
	vector<double> probabilities (N, 0);

	for(int i = 0; i < N; i++){
		cin >> probabilities[i];
	}

	vector<vector<double>> DP (N + 1, vector<double> (N + 1, 0));
	DP[0] = {1, 0, 0, 0};

	for(int i = 1; i <= N; i++){
		DP[i][0] = DP[i - 1][0] * (1 - probabilities[i - 1]);

		for(int j = 1; j <= N; j++){
			DP[i][j] = (double) (DP[i - 1][j - 1] * probabilities[i - 1]) + (double)  (DP[i - 1][j] * (1 - probabilities[i - 1]));
		}
	}

	double answer = 0;

	for(int i = (N + 1) / 2; i <= N; i++){
		answer += DP[N][i];
	}

	cout << setprecision(10) << answer << endl;

	return 0;
}


Measured memory_bytes: 70784
#include<stdio.h>
int main(void)
{
	int X,Y,Z,box;
	scanf("%d %d %d",&X,&Y,&Z);
	box=X;
	X=Y;
	Y=box;
	box=X;
	X=Z;
	Z=box;
	printf("%d %d %d\n",X,Y,Z);
	return 0;
}

Measured memory_bytes: 1700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

import static java.lang.Integer.parseInt;

/**
 * Surrounding Area
 */
public class Main {

	static final int BLACK = 1;
	static final int WHITE = 2;
	static final int[][] HV = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int w, h;
			w = parseInt(line.substring(0, line.indexOf(' ')));
			h = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((w | h) == 0) break;

			char[][] map = new char[h + 2][w + 2];
			int[][] check = new int[h + 2][w + 2];

			for (int i = 1; i <= h; i++) {
				line = br.readLine();
				for (int j = 1; j <= w; j++) {
					map[i][j] = line.charAt(j - 1);
					if (map[i][j] == 'B' || map[i][j] == 'W') {
						check[i][j] = BLACK | WHITE;
					}
				}
			}

			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if (map[i][j] == 'B' || map[i][j] == 'W') {
						int marker = 0;
						if (map[i][j] == 'B') {
							marker = BLACK;
						} else {
							marker = WHITE;
						}
						Deque<int[]> queue = new ArrayDeque<>();
						queue.offer(new int[]{i, j});
						while (!queue.isEmpty()) {
							int[] p = queue.poll();
							for (int k = 0; k < HV.length; k++) {
								int ny = p[0] + HV[k][0];
								int nx = p[1] + HV[k][1];
								if (1 <= ny && ny <= h
										&& 1 <= nx && nx <= w
										&& map[ny][nx] == '.'
										&& (check[ny][nx] & marker) == 0) {
									queue.offer(new int[]{ny, nx});
									check[ny][nx] |= marker;
								}
							}
						}
					}
				}
			}

			int black = 0;
			int white = 0;
			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if (check[i][j] == BLACK) {
						black++;
					} else if (check[i][j] == WHITE) {
						white++;
					}
				}
			}
			System.out.println(black + " " + white);

		} //end while
	} //end main
}

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

int main(){
	int n,x,t;
	scanf("%d%d%d",&n,&x,&t);
	int div=n/x,mod=n%x;
	if(mod)printf("%d",(div+1)*t);
	else printf("%d",div*t);
}

Measured memory_bytes: 3780
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 100010
int a[N];
int gcd(int x,int y)
{
    return x%y==0?y:gcd(y,x%y);
}
int main()
{
    int i,j,k,n,m,ans;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        a[i]=abs(a[i]-m);
    }
    ans=a[0];
    for(i=1;i<n;i++)
        ans=gcd(ans,a[i]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const N = Number.parseInt(lines[0]);
  var array = new Array(N);
  for (var n = 0; n < N; n++) {
    array[n] = Number.parseInt(lines[1].split(' ')[n]);
  }
  
  bubbleSort(array, N);
});

function bubbleSort(A, N) {
  var cnt = 0;
  var flag = true;
  while (flag) {
    flag = false;
    for (var j = N - 1; j >= 0; j--) {
      if (A[j] < A[j - 1]) {
        var tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
        flag = true;
        cnt++;
      }
    }
  }
  
  // 結果出力
  console.log(A.join(' '));
  console.log(cnt);
}


Measured memory_bytes: 17472
#include <iostream>

using namespace std;

int main()
{
string x;

int n,AC=0,TLE=0,WA=0,RE=0;

cin>>n;
for(int i=0;i<n;i++){
cin>>x;
    if(x=="AC"){AC++;}
    else if(x=="TLE"){TLE++;}
    else if(x=="WA"){WA++;}
else if(x=="RE"){RE++;}
}


cout<<"AC x "<<AC<<endl;
cout<<"WA x "<<WA<<endl;
cout<<"TLE x "<<TLE<<endl;
cout<<"RE x "<<RE<<endl;




    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll x;
    cin >> x;
    if(x % 11 == 0){
        cout << 2*x/11 << endl;
    }else{
        ll ans = x/11;
        ll rem = x - ans*11;
        ans *= 2;
        if(rem <= 6) ans++;
        else ans += 2;
        cout << ans << endl;
    }
    return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// 解説PDFより：問題の条件から方程式を作り、最初の山の降雨量からまず求めていく方法

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vll ans(n);
    rep(i, n) ans[0] += a[i];
    for (int i=1; i<n; i+=2) ans[0] -= (ll)2*a[i];
    rep(i, n-1) ans[i+1] = 2*a[i] - ans[i];
    rep(i, n) printf("%lld%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 4612
//Author: nimishkhurana
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(i=a;i<b;i++)
#define rrep(i,b,a) for(i=b;i>=a;i--)
#define ld long double
#define ll long long
#define umapi unordered_map<int,int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int> 
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define pb push_back
#define mk make_pair
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define INF 1000000000
template <typename T>
ostream& operator << (ostream& stream, const pair<T,T> &p) {
    return stream<<"("<<p.first<<","<<p.second<<") ";
}


int main(){
    fastIO
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n, k;
    cin>>n>>k;
    int i, j;
    int h[n];
    rep(i, 0, n) cin>>h[i];

    deque<int> dp;
    dp.push_back(0);
    for(int i = 1; i < n; i++){
        int cur = INF, j = i-1;
        for(auto it = dp.rbegin(); it != dp.rend(); it++){
            cur = min(cur, *it + abs(h[i] - h[j--]));
        }

        if(dp.size()==k)
            dp.pop_front();
        dp.push_back(cur);
    }
    cout<<dp.back();
   
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    string ans = "Yes";
    if(s[2] != s[3])ans = "No";
    if(s[4] != s[5])ans = "No";

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

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 i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(a);
		
		long ans = 1;
		int[] num = new int[n/2];
		int half = 0;
		if(n%2 == 0){
			for(int i=0; i<n; i++){
				if(a[i]%2 == 0){
					System.out.println(0);
					return;
				}
				num[a[i] / 2]++;
			}
		}else{
			for(int i=0; i<n; i++){
				if(a[i]%2 == 1){
					System.out.println(0);
					return;
				}
				if(a[i] == 0){
					half++;
				}else{
					num[a[i] / 2 - 1]++;
				}
			}
			if(half != 1){
				System.out.println(0);
				return;
			}
		}
		for(int i=0; i<n/2; i++){
			if(num[i/2] != 2){
				System.out.println(0);
				return;
			}
			ans *= 2;
			if(ans >= 1000000007){
				ans %= 1000000007;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 32376
n,m=map(int,input().split())
comb = []
for _ in range(m):
    comb.append(list(map(int,input().split()))[1:])
point = list(map(int,input().split()))
ans = 0
for i in range(2**n): #スイッチのon/offの組み合わせは2**n通りある
    on = [0]*m
    for j in range(n): #それぞれ何個めがonになっているか調べる
        if (i>>j)&1: #j個目がonになっているとき
            for k in range(m): #それぞれの電球に対して
                if j+1 in comb[k]: #もしj個目のon/offが電球kに関係するなら
                    on[k] += 1 #電球kに関してonポイントを与える
                    on[k] %= 2 #onポイントは偶奇のみ議論する
    if point==on: #もしこの組み合わせのon/offパターンが所与の条件に一致するなら
        ans += 1 #全ての電灯が一致する組み合わせが一つ見つかったことになる
print(ans)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int A,B,N; cin>>A>>B>>N;
  int ans;
  	if(B-1<N) ans = (A*(B-1))/B;
  else ans = A*N/B;
    Out(ans);
}

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

int main(void){
    ll ans=0;
    ll r,g,b,n;cin>>r>>g>>b>>n;
    for(int i=0;i<=n/r;i++){
        for(int j=0;j<=(n-r*i)/g;j++){
            if((n-r*i-g*j)%b==0)ans++;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    sort(arr.begin(), arr.end());
    int ans = arr.back() - arr[0];
    for(int i = 0; i + (k-1) < n; i++) {
        ans = min(ans, arr[i+k-1]-arr[i]);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const INF: i32 = 1000000000;

fn main() {
    input! {
        n: usize,
        m: usize,
        x: i32,
        ca:[(i32,[i32;m]);n],
    }

    let mut ans: i32 = INF;

    for bit in 0..(1 << n) {
        let mut price = 0;
        let mut smart = vec![0i32; m];
        for i in 0..n {
            if (bit >> i) & 1 == 1 {
                // 合計金額を加算
                price += ca[i].0;

                // アルゴリズムの数だけ回す
                for j in 0..m {
                    // 教科書の理解度を加算する
                    smart[j] += ca[i].1[j]
                }
            }
        }

        // 全ての理解度がxを超えてるか判断
        if smart.iter().fold(true, |isok, &s| isok && s >= x) {
            // ansとpriceを比較して小さい方をansに代入
            ans = std::cmp::min(price, ans);
        }
    }

    if ans >= INF {
        println!("-1")
    } else {
        println!("{}", ans)
    }
}


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

int main() {
  int h,w,k;cin>>h>>w>>k;
  vector<vector<char>> c(h,vector<char>(w));
  rep(i,h)rep(j,w)cin>>c[i][j];
  int ans=0;
  rep(bit1,1<<h)rep(bit2,1<<w){
    vector<int> H(h),W(w);
    rep(i,h)rep(j,w){
      if(bit1&(1<<i)){
        if(c[i][j]=='#')H[i]=1;
      }
      if(bit2&(1<<j)){
        if(c[i][j]=='#')W[j]=1;
      }
    }
    int cnt=0;
    rep(i,h){
      if(H[i]==1)continue;
      rep(j,w){
        if(W[j]==0){
          if(c[i][j]=='#')cnt++;
        }
      }
    }
    if(cnt==k)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
import * as fs from "fs";

const lines = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n")

const [all, choise] = lines[0].split(' ').map(Number)

const arr = lines[1].split(' ').map(Number)

const expectation = arr.map(n1 => (n1 + 1) / 2)

const res = expectation.reduce((r1, n1, i1) => {
  if (i1 <= choise - 1) return {max: r1.cur + n1, cur: r1.cur + n1}
  const cur = r1.cur + n1 - expectation[i1 - choise]
  return {max: Math.max(cur, r1.max), cur}
}, {max: 0, cur: 0})

console.log(res.max)

Measured memory_bytes: 35544
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    bl = [int(i) for i in input().split()]
    cl = [int(i) for i in input().split()]

    ans, last = 0, -1
    for i in range(n):
        if i == 0:
            ans += bl[al[i] - 1]
            last = al[i]
            continue
        ans += bl[al[i] - 1]
        if last == al[i] - 1:
            ans += cl[last - 1]
        last = al[i]
    print(ans)


if __name__=="__main__":
    solve()


Measured memory_bytes: 3064
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def judge(height, indexes):
    if height == 1:
        return 'C'
    if height == 4:
        return 'B'
    idx0, idx1 = indexes
    if height == 2:
        return 'EAG'[1+idx0-idx1]
    if height == 3:
        return 'FD'[idx0-idx1]

while True:
    it = (stdin.readline() for _ in xrange(8))
    L = [line for line in it if line.count('1')]
    indexes = (L[i].index('1') for i in xrange(2))
    print(judge(len(L), indexes))
    if not stdin.readline():
        break

Measured memory_bytes: 4264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())

//変数
ll N, T, A;
vector<double> vec;
//解法
void solve() {

	rep(i, N) {
		vec[i] = T - (vec[i] * 0.006);
	}

	int nearid = 0;
	rep(i, N) {
		if (abs(A - vec[i]) < abs(A - vec[nearid])) {
			nearid = i;
		}
	}
	
	cout << nearid+1;

	return;
}

int main() {
	//入力
	cin >> N >>T>> A;
	vec.resize(N);
	rep(i, N) cin >> vec[i];
	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    for(int i = 0;i < n;i++) {
        cin >> s.at(i);
    }
    sort(s.begin(),s.end());
    for(int i = 0;i < n;i++) {
        cout << s.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    int ok = 0, pe = 0;
    vector<int> penalty(n, 0);
    REP(i, m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC"){
            if(penalty[p] == -1)
                continue;
            ok++;
            pe += penalty[p];
            penalty[p] = -1;
        }
        else{
            if(penalty[p] == -1)
                continue;
            penalty[p]++;
        }
    }
    cout << ok << " " << pe << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;

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

  cout << fixed << setprecision(15);

  int n, a, b;
  cin >> n >> a >> b;
  vector < ll > v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end(), greater < ll > ());
  ld sum = 0.0;
  for(int i = 0; i < a; i++){
    sum += (ld)v[i];
  }
  ld mean = sum / (ld)a;
  cout << mean << '\n';

  ll lst = v[a - 1], cnt = 0;
  for(int i = a; i < n; i++){
    if(v[i] == lst) cnt++;
  }

  int c = 0;
  for(int i = a - 1; i >= 0; i--){
    if(v[i] == lst) c++;
  }

  ll dp[55][55];

  dp[1][0] = dp[1][1] = 1;
  for(int i = 2; i < 51; i++){
    for(int j = 0; j <= i; j++){
      dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
    }
  }

  ll ans;
  if(c == a){
    for(int i = a; i <= b && i <= cnt + c; i++){
      ans += dp[cnt + c][i];
    }
  }else{
    ans = dp[cnt + c][c];
  }

  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int i, j, x[100000], y[100000];

  i = 0;
  do {
    scanf("%d %d", &x[i], &y[i]);
    i++;
  } while (!(x[i - 1] == 0 && y[i - 1] == 0));

  for (j = 0; j < i- 1; j++) {
    if (x[j] < y[j]) {
      printf("%d %d\n", x[j], y[j]);
    } else {
      printf("%d %d\n", y[j], x[j]);
    }
  }

  return 0;
}

Measured memory_bytes: 1052
import java.util.*;
import java.io.*;

public class Main {
	static BufferedReader br;
	static StringTokenizer tokenizer;
	static int[] xOff = {0, 0, 1, -1};
	static int[] yOff = {1, -1, 0, 0};
	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new InputStreamReader(System.in));
		int n = nextInt();
		int m = nextInt();
		boolean[][] black = new boolean[n][m];
		Queue<Integer> rQ = new ArrayDeque<Integer>();
		Queue<Integer> cQ = new ArrayDeque<Integer>();
		int curr = 0, next = 0, ans = 0;
		for(int i = 0; i < n; i++) {
			String t = next();
			for(int k = 0; k < m; k++) {
				black[i][k] = t.charAt(k) == '#';
				if(black[i][k]) {
					curr++;
					rQ.add(i);
					cQ.add(k);
				}
			}
		}
		while(!rQ.isEmpty()) {
			if(curr == 0) {
				curr = next;
				next = 0;
				ans++;
			}
			curr--;
			int r = rQ.poll();
			int c = cQ.poll();
			for(int i = 0; i < 4; i++) {
				if(r + xOff[i] >= 0 && r + xOff[i] < n && c + yOff[i] >= 0 && c + yOff[i] < m && !black[r + xOff[i]][c + yOff[i]]) {
					next++;
					black[r + xOff[i]][c + yOff[i]] = true;
					rQ.add(r + xOff[i]);
					cQ.add(c + yOff[i]);
				}
			}
		}
		System.out.println(ans);

	}

	public static String next() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null)
				throw new IOException();
			tokenizer = new StringTokenizer(line);
		}
		return tokenizer.nextToken();
	}

	public static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 68160
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
ll dp[3005][3005]={0};
ll arr[3005];
ll solve(ll start,ll end)
{
	if(start>end)
		return 0;
	else if(start==end){
		dp[start][end]=arr[start];
		return arr[start];
	}
	else if(dp[start][end])
		return dp[start][end];
	
	return dp[start][end]=max(arr[start]-solve(start+1,end),arr[end]-solve(start,end-1));
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("test.txt","r",stdin);
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	cout<<solve(0,n-1)<<endl;
	


}

Measured memory_bytes: 70272
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]

c = H[0]
for i in range(1,N):
    if abs(T - H[i] * 0.006 - A) < abs(T - c * 0.006 - A):
        c = H[i]
print(H.index(c)+1)

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

int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<int>v;
		rep(i, n)v.push_back(i + 1);
		int cnt = 0;
		while (1) {
			if (v.size() == 1)break;
			v.erase(v.begin() + (cnt + m - 1) % v.size());
			cnt = (cnt + m - 1) % (v.size() + 1);
		}
		cout << v[0] << endl;
	}
}

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

int main(){
  string s;
  cin>>s;
  bool right=false,left=false,kaibun=false;
  string kaileft,kairight;
  REP(i,(s.size()-1)/2){
    kaileft+=s[i];
  }
  for (int i =(s.size())/2+1; i < s.size(); i++)
  {
    /* code */
    kairight+=s[i];
  }
  if (kaileft==kairight)
  {
    /* code */
    kaibun=true;
  }
  string leftleft,leftright,rightright,rightleft;
  leftleft=kaileft;
  rightright=kairight;
  reverse(kaileft.begin(),kaileft.end());
  reverse(kairight.begin(),kairight.end());

  if (kaileft==leftleft)
  {
    /* code */
    left=true;
  }

  if (kairight==rightright)
  {
    /* code */
    right=true;
  }

  if (right&&left&&kaibun)
  {
    /* code */
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  }

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int cnt[10][10];
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= n; i++) {
		std::string tmp = std::to_string(i);
		cnt[tmp[0] - '0'][tmp.back() - '0']++;
	}
	int64_t res = 0;
	for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) res += (int64_t) cnt[i][j] * cnt[j][i];
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n, k; cin >> n >> k; int a[n], sum[n];
	fill(sum, sum + n, 0);
	int kind = 0;
	Rep(i, n){
		cin >> a[i];
		if(sum[a[i] - 1] == 0) kind += 1;
		sum[a[i] - 1] += 1;
	}
	Rep(i, n) if(sum[i] == 0) sum[i] = inf;
	sort(sum, sum + n);
	int ans = 0;
	if(kind > k){
		Rep(i, kind - k){
			ans += sum[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int count = 0;
		int [] namber = new int[200];
		int [][] array = new int [n+1][4];
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= 3; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		for(int j = 1; j <= 3; j++){
			for(int i = 1; i <= count; i++){
				namber[i] = 0;
			}
			count = 1;
			for(int k = 1; k < n; k++) {
				for(int i = k + 1; i <= n; i++) {
					if(array[k][j] == array[i][j]) {
						namber[count] = array[k][j];
						count++;
					}
				}
			}
			for(int k = 1; k < namber.length;k++){
				for(int i = 1; i <= n; i++) {
					if(namber[k] == array[i][j]){
						array[i][j] = 0;
					}
				}
			}
		}
		for(int i = 1; i <= n; i++) {
			int answer = 0;
			for(int j = 1; j <= 3; j++) {
				answer += array[i][j];
			}
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 21352
import math
H,W = list(map(int,input().split()))
data = [list(input()) for l in range(H)]
check = [[0 for s in range(W)] for k in range(H)]
sum = 0

def search(i,j,H,W,data,check):
    stack = [[i,j]]
    check[i][j] = 1 
    tempSum = 0
    numW = 0
    numB = 0
    while True:
        if len(stack) != 0:
            s = stack[-1]
            hNow,wNow = s[0],s[1]
            WB = data[hNow][wNow]
            if WB == '.':
                numW += 1
            else:
                numB += 1
        else:
            return (numW*numB),check


        stack.pop()

        if hNow < H-1:
            if (data[hNow+1][wNow] != WB) and (check[hNow+1][wNow] == 0):
                stack.append([hNow+1,wNow])
                check[hNow+1][wNow] = 1
        if wNow < W-1:
            if (data[hNow][wNow+1] != WB) and (check[hNow][wNow+1] == 0):
                stack.append([hNow,wNow+1])
                check[hNow][wNow+1] = 1

        if hNow > 0:
            if (data[hNow-1][wNow] != WB) and (check[hNow-1][wNow] == 0):
                stack.append([hNow-1,wNow])
                check[hNow-1][wNow] = 1

        if wNow > 0:
            if (data[hNow][wNow-1] != WB) and (check[hNow][wNow-1] == 0):
                stack.append([hNow,wNow-1])
                check[hNow][wNow-1] = 1
        
for i in range(H):
    for j in range(W):
        if (check[i][j] == 0):
            temp,check = search(i,j,H,W,data,check)
            sum += temp

print(sum)

Measured memory_bytes: 15772
//=================================
// Created on: 2018/07/04 14:52:47
//=================================
#include <bits/stdc++.h>
using namespace std;
int Not(const int i) { return 2 - i; }
int Plus(const int i, const int j) { return max(i, j); }
int Prod(const int i, const int j) { return min(i, j); }
int v[3] = {0, 0, 0};
string S;
int pos;
int number()
{
    if (isdigit(S[pos])) {
        return pos++, S[pos - 1] - '0';
    } else {
        return pos++, v[S[pos - 1] - 'P'];
    }
}
int formula()
{
    if (isalpha(S[pos]) or isdigit(S[pos])) { return number(); }
    if (S[pos] == '-') {
        pos++;
        const int sub = formula();
        return Not(sub);
    } else {
        pos++;
        const int a = formula();
        const char op = S[pos];
        pos++;
        const int b = formula();
        pos++;
        return (op == '*' ? Prod(a, b) : Plus(a, b));
    }
}

int main()
{
    for (;;) {
        cin >> S;
        if (S == ".") { break; }
        int ans = 0;
        for (v[0] = 0; v[0] < 3; v[0]++) {
            for (v[1] = 0; v[1] < 3; v[1]++) {
                for (v[2] = 0; v[2] < 3; v[2]++) {
                    pos = 0;
                    const int c = formula();
                    if (c == 2) { ans++; }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
num = int(input())

def num2alpha(num):
    if num <= 26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

print(num2alpha(num).lower())

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

int main()
{
	long long x;
	cin >> x;

	for (long long a = -1000; a <= 1000; ++a) {
		for (long long b = -1000; b <= 1000; ++b) {
			if (x == a * a*a*a*a - b * b*b*b*b) {
				cout << a << " " << b << endl;

				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3592
import sys
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
lst1 = [list(map(int,readline().split())) for i in range(m)]

lstm = [-1]*n

for i,j in lst1:
    i-=1
    if lstm[i] == -1:
        lstm[i]=j
    elif lstm[i]==j:
        continue
    else:
        print(-1)
        exit()

if n == 2 and lstm[0] == 0:
    print(-1)
    exit()
if n == 3 and lstm[0] == 0:
    print(-1)
    exit()

for i in range(n):
    if lstm[i] == -1:
        lstm[i] = 0
if n == 2 and lstm[0] == 0:
    lstm[0] = 1
if n == 3 and lstm[0] == 0:
    lstm[0] = 1
print("".join(map(str,lstm)))

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

const int maxn = 100+5;
int n, m, t[maxn], p[maxn], x[maxn];

int main(){
	scanf("%d", &n);
	int suma_tiempos = 0;
	
	for(int i = 1; i<=n; i++) {
		scanf("%d", &t[i]);
		suma_tiempos += t[i]; //Obtengo la suma total de los tiempos
	}
	
	scanf("%d", &m);
	for(int i = 1; i<=m; i++) {
		int pi, xi;
		scanf("%d %d", &pi, &xi);
		
		int suma_nueva = suma_tiempos;
		
		//Quito el tiempo original para resolver el problema P_i
		suma_nueva -= t[pi];
		
		//Añado el nuevo tiempo para resolver el problema P_i
		suma_nueva += xi;
		
		printf("%d\n", suma_nueva);
	}
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
//------------
void func() {
    int N;
    cin  >> N;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
       int a;
       cin >> a;

       int count = 0;
       while (a % 2 == 0) {
           count += 1;
           a = a >> 1;
       }
       ans += count;
    }
    cout << ans << endl;
}

int main() {
    func();
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n,a,b,c,d;
char S[1001000];
int main(){
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	scanf("%s",S+1);
	for(int i=a;i<c;i++)
		if(S[i]=='#'&&S[i+1]=='#')return puts("No"),0;
	for(int i=b;i<d;i++)
		if(S[i]=='#'&&S[i+1]=='#')return puts("No"),0;
	if(c>d){
		bool bo=false;
		for(int i=b;i<=d;i++)
			if(S[i]=='.'&&S[i+1]=='.'&&S[i-1]=='.')bo=true;
		if(!bo)return puts("No"),0;
	}
	puts("Yes");
}

Measured memory_bytes: 384