akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  
  int sum;
  string S,T;
  cin >> S >> T;
  
  sum=0;
  
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i))
      sum=sum+1;
  }

    cout << sum << endl;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
#define MAX 10005
using namespace std;
typedef long long ll;
int main()
{
    int n,a[MAX]= {0};
    cin>>n;
    for(int i=1; i<=100; i++)
    {
        for(int j=1; j<=100; j++)
        {
            for(int k=1; k<=100; k++)
            {
                int tool=i*i+j*j+k*k+i*j+i*k+k*j;
                if(tool<=10000)
                    a[tool]++;
            }
        }
    }
    for(int i=1; i<=n; i++)
        cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 3592
<?php
fscanf(STDIN, "%d %d %d", $n, $a, $b);
  $train = $n * $a;
  $taxi = $b;
  $array = array($train, $taxi);
  $answer = $array[0];
  for($i = 0; $i < count($array); $i++){
    if($answer > $array[$i]){
       $answer = $array[$i];
    }
  }
   echo $answer;
?>

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

N, M, Q = [int(x) for x in input().split()]
L = [0] * M
R = [0] * M
p = [0] * Q
q = [0] * Q
for i in range(M):
    L[i], R[i] = [int(x) for x in input().split()]
for j in range(Q):
    p[j], q[j] = [int(x) for x in input().split()]

train = [[0 for i in range(N + 1)] for _ in range(N + 1)]
seg = [[0 for i in range(N + 1)] for _ in range(N + 2)]

for i in range(M): # すべての列車について
    train[L[i]][R[i]] += 1

for col in range(1, N + 1):
    for row in range(col, 0, -1):
        seg[row][col] = train[row][col] + seg[row][col - 1] + seg[row + 1][col] - seg[row + 1][col - 1]

for j in range(Q):
    print(seg[p[j]][q[j]])


Measured memory_bytes: 25872
import math

def isprime(x):
    M=math.sqrt(x)
    if x==2:
        return True

    if x<2 or x%2==0:
        return False

    i=3
    while i<=M:
        if x%i==0:
            return False

        i=i+2

    return True

c=0
n=int(input())
for i in range(n):

    x=int(input())

    if isprime(x):
        c=c+1

print(c)
    


Measured memory_bytes: 5672
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111


	void solve(){

		ini(n);
		ini(n1);
		int pre[n+1];
		int tmppre[n+1];
		ZERO(pre);
		ZERO(tmppre);
		FOR(i,0,n){
			ini(x);
			pre[i+1] = pre[i]+x;
			tmppre[i+1] = tmppre[i]+max(0LL,x);
		}
		int rick = 0;
		FOR(i,0,n-n1+1){
			int LL = tmppre[i];
			int mid = max(0LL,pre[i+n1]-pre[i]);
			int RR = tmppre[n]-tmppre[i+n1];
			rick = max(rick,LL+mid+RR);
		}
		out(rick);















	}






























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 1920
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = list(input())
    l = []
    f = False
    for i in range(n)[::-1]:
        for j in l:
            a[i] = min(a[i], a[i] ^ j)
        if a[i]:
            if s[i] == "0":
                l.append(a[i])
            else:
                print(1)
                f = True
                break
    if f:
        continue
    print(0)

Measured memory_bytes: 8976
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define endl '\n'
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <=n; i++)
#define rep2(i, n) for (i = 0; i < n-1; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend() //Sort in reverse,Vector.
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.

int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif

   int x;

   cin>>x;

   if(x>=30)
   	cout<<"Yes";

   else
   	cout<<"No";

  
   
}  
   




Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set> 
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h> 
#include <cstdio>
using namespace std;
int main()
{
int a;
cin>>a;
int b;
cin>>b;
int cnt=a*b;
if(cnt%2==0)
cout<<"Even";
else cout<<"Odd";
system ("pause");
return 0;
}

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

int main(void){
    string O,E,ans;
    cin>>O>>E;
    int Ocnt=0,Ecnt=0;

    for(int i=1;i<=O.size()+E.size();i++){
        if(i%2==1){
            ans.push_back(O[Ocnt]);
            Ocnt++;
        }else{
            ans.push_back(E[Ecnt]);
            Ecnt++;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N, K, Q = LI()
    a_list = []
    for i in range(Q):
        a_list.append(II())

    score_list = [K-Q for i in range(N)]

    for i in range(Q):
        a = a_list[i]
        aidx = a - 1
        score_list[aidx] += 1

    for score in score_list:
        if score <= 0:
            print('No')
        else:
            print('Yes')
solve()

Measured memory_bytes: 11784
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
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;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,K;
    cin >> N >> K;
    if(N==K)pr(0);
    else if(N<K)pr(min(N,K-N));
    else{
        pr(min(N%K, abs((N%K)-K)));
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public int getIndex( double eye ) {
		if ( eye < 0.2 ) return 3;
		else if ( eye < 0.6 ) return 2;
		else if ( eye < 1.1 ) return 1;
		else return 0;
	}
	
	public static void main ( String args[] ) {
		int[] left = new int[4] , right = new int[4];
		Main m = new Main();
		Scanner sc = new Scanner(System.in);
		while ( sc.hasNext() ) {
			double l = sc.nextDouble();
			double r = sc.nextDouble();
			left[m.getIndex(l)]++;
			right[m.getIndex(r)]++;
		}
		for ( int i = 0; i < 4; i++ )
			System.out.println(left[i]+" "+right[i]);
	}
}

Measured memory_bytes: 12000
# AOJ 1065 The House of Huge Family
# Python3 2018.7.10 bal4u

# UNION-FIND library
class UnionSet:
	def __init__(self, nmax):
		self.size = [1]*nmax
		self.id = [i for i in range(nmax+1)]
	def root(self, i):
		while i != self.id[i]:
			self.id[i] = self.id[self.id[i]]
			i = self.id[i]
		return i
	def connected(self, p, q): return self.root(p) == self.root(q)
	def unite(self, p, q):
		i, j = self.root(p), self.root(q)
		if i == j: return
		if self.size[i] < self.size[j]:
			self.id[i] = j
			self.size[j] += self.size[i]
		else:
			self.id[j] = i
			self.size[i] += self.size[j]
# UNION-FIND library

while True:
	n, m = map(int, input().split())
	if n == 0: break
	u = UnionSet(n)
	ans, tbl = 0, []
	for i in range(m):
		x, y, c = map(int, input().split())
		if c < 0: ans += c
		else: tbl.append((c, x, y))
	tbl.sort(reverse=True)
	for c, x, y in tbl:
		if not u.connected(x, y):
			if n > 2:
				n -= 1
				u.unite(x, y)
			else: ans += c
	print(ans)



Measured memory_bytes: 5628
import string

S = input()
T = input()

count1 = [0] * 26
count2 = [0] * 26


for j in range(26):
    count1[j] = S.count(string.ascii_lowercase[j])
    count2[j] = T.count(string.ascii_lowercase[j])

hantei = 1

for i in range(0,len(S)+1):
    count_tmp1 = 0
    count_tmp2 = 0
    for j in range(26):
        if i == count1[j] :
            count_tmp1 += 1
    for j in range(26):
        if i == count2[j] :
            count_tmp2 += 1
    if count_tmp1 != count_tmp2:
        hantei = 0
        break

if hantei == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int H,W;
  	cin >> H >> W ;
  	
  	int grid[H+2][W+2];
  	for(int i = 0;i < H+2;i++){
    	for(int j = 0;j < W+2;j++){
        grid[i][j] = 0;
        }
    }
    
	string line;
  	for (int i = 0; i < H; i++){
  		cin >> line;
  		for(int j = 0; j < W;j++){
        	if(line.at(j)=='#'){
            	grid[i+1][j+1] = 1;
            }
        }
    }
  	
  	string ans_line;
  	int count;
  	for (int i = 0; i < H;i++){
      	ans_line = "";
    	for (int j = 0; j < W; j++){
        	if (grid[i+1][j+1]==1){
            	ans_line += '#';
            }else{
              	count =grid[i][j] + grid[i][j+1] + grid[i][j+2] 
                  		+ grid[i+1][j] + grid[i+1][j+2] 
                  		+ grid[i+2][j] + grid[i+2][j+1] + grid[i+2][j+2];
            	ans_line += to_string(count);
            }
        }
      	cout << ans_line << endl;
    }
  	
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[3006];
  int ans = 0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ans += a[i] - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int N, l[1000], r[1000], an = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &l[i], &r[i]);
		an += r[i] - l[i] + 1;
	}
	printf("%d", an);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
string a,b,c;
int main() {
    cin>>a>>b>>c;
    cout<<a[0];
    cout<<b[1];
    cout<<c[2]<<endl;
    return 0;
}

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


int main() {
  int a, b;
 cin >> a >> b;
  string s1, s2;
 for(int i = 1; i <= b; ++i) s1 += a + '0';
 for(int i = 1; i <= a; ++i) s2 += b + '0';
  if(s1 < s2) cout << s1;
  else cout << s2;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef long long ll;

int m;

mat mul(mat &A,mat &B){
	mat C(A[0].size(),vec(B.size()));
	for(int i=0;i<B.size();i++){
		for(int j=0;j<A[0].size();j++){
			for(int k=0;k<B[0].size();k++){
				C[j][i]=(C[j][i]+A[k][i]*B[j][k])%m;
			}
		}
	}
	return C;
}

mat pow(mat A,int n){
	mat B(A.size(),vec(A.size()));
	for(int i=0;i<A.size();i++){
		B[i][i]=1;
	}
	while(n>0){
		if(n & 1)B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

int n,a,b,c,t;
int s[501];
int res[501];


int main(void){
	while(1){
		scanf("%d %d %d %d %d %d",&n,&m,&a,&b,&c,&t);
		if(n+m+a+b+c+t==0)break;
		mat A(n, vec(n));
		for(int i=0;i<n;i++){
			for(int j=-1;j<=1;j++){
				if(j+i>=0 && j+i<n){
					if(j==-1)A[j+i][i]=a;
					if(j==0)A[j+i][i]=b;
					if(j==1)A[j+i][i]=c;
				}
			}
		}
		A=pow(A,t);
		for(int i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		memset(res,0,sizeof(res));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				res[i]=(res[i]+s[j]*A[j][i])%m;
			}
		}
		for(int i=0;i<n;i++){
			printf("%d%c",res[i],i==n-1?'\n':' ');
		}
	}
}

Measured memory_bytes: 1116
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf8");

var lines = [];
var reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on("line", line => {
  lines.push(line);
});

reader.on("close", () => {
  let input = lines.shift().split(/\s/);
  let n = parseInt(input[0]),
    k = parseInt(input[1]);
  let h = lines.sort((a, b) => b - a);

  let min = Infinity;
  for (let i = k - 1; i < n; i++) {
    if (h[i - k + 1] - h[i] < min) min = h[i - k + 1] - h[i];
  }

  console.log(min);
});


Measured memory_bytes: 27148
#include<bits/stdc++.h>
using namespace std;
#define int long long 
main()
{
    string s;
    cin>>s;
    int n=s.size(),ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='-') ans--;
        else ans++;
    }
    cout<<ans<<endl;
}


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

int main() {
    int n, r;
    while (cin >> n >> r, n) {
        vector<int> cards(n);
        for (int i = 0; i < n; i++) cards[i] = n - i;
        while (r--) {
            int p, c; cin >> p >> c; p--;
            vector<int> blue(cards.begin(), cards.begin() + p);
            vector<int> yellow(cards.begin() + p, cards.begin() + p + c);
            while (p--) cards[p + c] = blue.back(), blue.pop_back();
            while (c--) cards[c] = yellow.back(), yellow.pop_back();
		}
        cout << cards.front() << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N;
	string A, B, C;
	cin >> N >> A >> B >> C;
	int cnt = 0;
	rep(i, N) {
		if (A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) {
			cnt += 2;
		}
		else if (A[i] == B[i] && B[i] == C[i]) {
			cnt += 0;
		}
		else {
			cnt += 1;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = []

for i in range(n):
    x = int(input())
    lst.append(x)

a = max(lst)
b = []
for i in range(n):
    if (lst[i] == a):
        b.append(i)

if (len(b) > 1):
    for i in range(n):
        print(a)

else:
    lst[b[0]] = 0
    c = max(lst)
    for i in range(n):
        if (i == b[0]):
            print(c)
        else:
            print(a)


Measured memory_bytes: 24784
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int a[1100];
pair<int,int> F(int left,int right){
    int p=-1,q=mod;
    for(int i=left;i<right;i++){
        p=max(p,a[i]);
        q=min(q,a[i]);
    }
    return make_pair(p,q);
}
int main(){
    int n,m;
    cin>>n>>m;
    lol(i,n)cin>>a[i];
    if(n==m){
        pair<int,int> tmp=F(0,n);
        cout<<tmp.first-tmp.second<<endl;
        return 0;
    }
    int left=0,right=m;
    int ans=0;
    while(true){
        int p,q;
        if(left<right){
            pair<int,int> tmp=F(left,right);
            p=tmp.first,q=tmp.second;
        }
        else{
            pair<int,int> tmp=F(0,right);
            p=tmp.first,q=tmp.second;
            tmp=F(left,n);
            p=max(p,tmp.first);
            q=min(q,tmp.second);
        }
        ans+=p-q;
        left=right%n;
        right=(right+m)%n;
        if(right<=0)right+=n;
        if(left==0)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3068
#pragma GCC optimize (Ofast)
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0); 
	long long a,b,c,k;

	{
		cin>>a>>b>>c>>k;
		if(k<a)
			cout<<k;
		else if(k<a+b)
			cout<<a;
		else
			cout<<a-(k-a-b);
		cout<<endl;
	}
	return 0;
}




Measured memory_bytes: 3612
intToBin :: Int -> [Int]
intToBin 0 = []
intToBin 1 = [1]
intToBin n = (mod n 2) : intToBin (div n 2)

weights :: Int -> [Int]
weights w = (filter (/= 0) . zipWith (*) ws . intToBin) w
    where ws = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]

main :: IO ()
main = interact $ unlines . map unwords . map (map show) . map weights . map read . lines

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  while (true) {
    int n, r;
    cin >> n >> r;
    if (n == 0) return 0;
    vi a(n);
    int i = 0;
    int now = r;
    while (true) {
      if (now > 0) {
        now--;
        a[i]++;
        if (a[i] == r) {
          cout << i << endl;
          break;
        }
      }
      else {
        now += a[i];
        a[i] = 0;
      }
      i++;
      i %= n;
    }
  }
}



Measured memory_bytes: 3076
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          
          Console.WriteLine(a[1] * (a[2]/a[0]));
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
char s[100010];
int main()
{
	scanf("%s",s);
	int l=strlen(s);
	for(int i=0;i<=l/2;i++)
	{
		if(s[i]=='b'&&s[l-i-1]!='d'||s[i]=='d'&&s[l-i-1]!='b'||s[i]=='p'&&s[l-i-1]!='q'||s[i]=='q'&&s[l-i-1]!='p')
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = 1;
  rep(i,N) ans=(ans)/gcd(ans,a[i])*a[i];
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rl rd<LL>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
typedef long long LL;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int A, B, C;
LL K;

int main() {

	A = ri(), B = ri(), C = ri(), K = rl();
	int res = A - B;
	if (K & 1) res = - res;
	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 256
import sys

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))


n = ri()
li = rl()
ans = 0
for i in li:
    t = 0
    while i & 1 == 0:
        i //= 2
        t += 1
    ans += t
print(ans)



Measured memory_bytes: 10144
using System;
using System.Linq;

namespace ITP1_2_A
{
    class Program
    {
        public static void Main()
        {
            int[] val = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            if (val[0] <val[1] && val[1] < val[2])
               Console.WriteLine("Yes");
            else
               Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 18432
#include<stdio.h>
int main(){
    long int n,m,a[10000],i=0,b,c,d;
    scanf("%ld",&n);
    m=n;
    while (n!=0){
        scanf("%ld",&a[i]);
        n--;
        i++;
    }
    b=c=a[0];
    for(int i=0;i<m;i++){
        d+=a[i];
    }
    for(i=1;i<m;i++){
        if(b<a[i]){
            b=a[i];
        }else if(c>a[i]){
            c=a[i];
        }
    }
    printf("%ld %ld %ld\n",c,b,d);
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  string s;
  cin >> s;

  int n = s.length();
  V<int> curr(2020), prev(2020);

  ll ans = 0;
  rep(i, n) {
    fill(curr.begin(), curr.end(), 0);
    int p = s[i] - '0';
    if (p != 0) curr[p] += 1;

    rep(j, 2020) {
      if (prev[j] > 0) {
        int p = (j * 10 + s[i] - '0') % 2019;
        curr[p] += prev[j];
      }
    }
    ans += curr[0];
    prev = curr;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int n, l;
	scanf("%d %d", &n, &l);
	int i = 1;
	int sum = 0;
	while (i <= n)
	{
		sum += i;
		i++;
	}
	if ( l >= 0)
	{
		printf("%d\n", n*l - n + sum - l);
	}
	else if (-1*l >= n)
	{
		printf("%d\n", n*l - n + sum - (l+n-1));
	}
	else
	{
		printf("%d\n", n*l - n + sum );
	}
	return (0);
}



Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

int ispraime(int x){
    int true=1;
    int false=0;
    double y;
    int i=3;
    if(x==2) return true;
    if(x<2||x%2==0) return false;
    y=sqrt(x);
    if(x>=2&&x%2!=0){
        while(i<=y){
        if(x%i==0) return false;
        else i=i+2;
    }
    return true;
}
}

int main(){
    int x,n,i,j,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&x);
      if(ispraime(x)==1) count++;
}
printf("%d\n",count);
return 0;
}


Measured memory_bytes: 2084
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;


int A[2020][2020];
void solve() {
	int K = 38, N = 1407;
	//K = 6, N = 31;
	vector<vector<int>>ans;
	REP(i, K - 1) {
		REP(j, K) {
			A[i][j] = (K - 1)*j + i + 1;
		}
	}
	REP(j, K) {
		vector<int>tmp = {N};
		REP(i, K)tmp.push_back(A[i][j]);
		ans.push_back(tmp);
	}

	REP(d, K - 1) {
		
		REP(s, K - 1) {
			vector<int>tmp = { A[d][K - 1] };
			int i = s;
			REP(j, K - 1) {
				tmp.push_back(A[i][j]);
				i = (i + d) % (K - 1);
			}
			ans.push_back(tmp);
		}

	}
	cout << N << " " << K << endl;
	REP(i, N) {
		REP(j, K) {
			cout << ans[i][j] << " \n"[j == K - 1];
		}
	}
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3836
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int A, B, P, Q, R; cin >> A >> B;
    cin >> P >> Q >> R;
    double rx = P * B;
    double ry = Q * (B - A);
    cout << fixed << setprecision(12) << (rx - ry) / (Q + R) + B << endl;
    return 0;
}



Measured memory_bytes: 3292
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n;
ll ans;
int main(){
	scanf("%lld",&n);
	ll t=sqrt(n)+100;
	rep(k,1,t){
		if(n%k==0&&(n/k-1)>k)ans+=n/k-1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
struct node {
	pii lp;
	pii rp;
	node( pii l, pii r ) {
		lp = l;
		rp = r;
	}
};

bool visit[55][55][55][55] = {};

int main() {
	int w, h;
	while( cin >> w >> h, w||h ) {
		w+=1;
		h+=1;
		string fl[h+1], fr[h+1];
		rep(y,h+1) {
			fl[y] = '#';
			fr[y] = '#';
		}
		rep(x,w) {
			fl[0] += '#';
			fl[h] += '#';
			fr[0] += '#';
			fr[h] += '#';
		}
		int lx, ly, rx, ry;
		for(int y=1; y<h; y++) {
			string in;
			cin >> in;
			fl[y] += in + '#';
			cin >> in;
			fr[y] += in + '#';
			reverse( fr[y].begin(), fr[y].end() );
			for(int x=1; x<=w; x++) {
				if( fl[y][x] == 'L' ) {
					fl[y][x] = '.';
					lx = x; ly = y;
				}
				if( fr[y][x] == 'R' ) {
					fr[y][x] = '.';
					rx = x; ry = y;
				}
			}
		}
/*
		cout << endl;
		rep(y,h+1) {
			cout << fl[y] << endl;
		}
		cout << endl;
		rep(y,h+1) {
			cout << fr[y] << endl;
		}
*/
		bool ok = false;
		queue<node> que;
		que.push(node(pii(lx, ly), pii(rx, ry)));
		memset( visit, 0, sizeof(visit) );
		while( !que.empty() ) {
			node nd = que.front();
			que.pop();
			if( visit[nd.lp.first][nd.lp.second][nd.rp.first][nd.rp.second] ) continue;
			visit[nd.lp.first][nd.lp.second][nd.rp.first][nd.rp.second] = true;
//			cout << nd.lp.first << " " << nd.lp.second << " " << nd.rp.first << " " << nd.rp.second << endl;
			if( fl[nd.lp.second][nd.lp.first]=='%' && fr[nd.rp.second][nd.rp.first]=='%' ) {
				ok = true;
				break;
			}
			if( fl[nd.lp.second][nd.lp.first]=='%' || fr[nd.rp.second][nd.rp.first]=='%' )
				continue;
			int dx[4] = {-1, 0, 1, 0};
			int dy[4] = {0, -1, 0, 1};
			rep(i, 4) {
				int nlx = nd.lp.first  + dx[i];
				int nly = nd.lp.second + dy[i];
				int nrx = nd.rp.first  + dx[i];
				int nry = nd.rp.second + dy[i];
				if( !visit[nlx][nly][nrx][nry] ) {
					int wall = 0;
					if( fl[nly][nlx] == '#' ) {
						nly-=dy[i];  nlx-=dx[i];
						wall++;
					}
					if( fr[nry][nrx] == '#' ) {
						nry-=dy[i];  nrx-=dx[i];
						wall++;
					}
					if( wall < 2 ) {
						que.push( node(pii(nlx, nly), pii(nrx, nry)) );
					}
				}
			}
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 12676
#include<iostream>
#include<bitset>
int main(){
  int a,b,c,d,e,f,p=2,q=-1;
  std::bitset<3123> sugar,water;
  sugar[0]=water[0]=1;
  std::cin>>a>>b>>c>>d>>e>>f;
  for(int i=0;i<100;++i)water[i*a]=1;
  for(int i=0;i<100;++i)water|=water<<b;
  for(int i=0;i<100;++i)sugar[i*c]=1;
  for(int i=0;i<100;++i)sugar|=sugar<<d;
  for(int i=0;i<f/100;++i)if(water[i])for(int j=0;j<f;++j)if(sugar[j]){
    
    if(i*100+j<=f){
      
      if(i*e>=j){
        //std::cout<<i<<' '<<j<<std::endl;
        if(i+j!=0){
          if((double)j/(i+j)>(double)q/(p+q)){
            p=i;
            q=j;
          }
        }
      }
    }
  }
  std::cout<<p*100+q<<' '<<q<<std::endl;
}


Measured memory_bytes: 256
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from itertools import count

for line in stdin:
    if not line.strip():
        break
    H = 4.9 * (float(line) / 9.8) ** 2
    for N in count(1):
        if H <= 5 * N - 5:
            print(N)
            break

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

int l[1010];
int N,A,B,C;
int INF = 99999999;

int dfs(int d,int a, int b, int c) {
    if(d == N)  {
        if(min(a,min(b,c)) == 0) return INF;
        return abs(A-a) + abs(B-b) + abs(C-c) - 30;
    }
    int res1 = dfs(d+1,a,b,c);
    int res2 = dfs(d+1,a+l[d],b,c) + 10;
    int res3 = dfs(d+1,a,b+l[d],c) + 10;
    int res4 = dfs(d+1,a,b,c+l[d]) + 10;
    return min(res1,min(res2,min(res3,res4)));
}

int main () {
    cin >> N >> A >> B >> C;
    for(int i=0; i<N; i++) cin >> l[i];
    cout << dfs(0,0,0,0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	string s;
	cin >> s;
	int N = s.size();
	int k = 0;
	rep(i, (N - 1) / 2) {
		if (s.at(i) == s.at(N - 1 - i) && s.at(i) == s.at((N - 3) / 2 - i) && s.at((N + 1) / 2 + i) == s.at((N - 3) / 2 - i)) {

		}
		else {
			k = 1;
		}
	}
	if (k == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    char c;
    cin >> c;
    if(c >= 'A' and c <= 'Z')
    	cout << 'A' << endl;
    else
    	cout << 'a' << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  rep(i, m) cin >> x[i];

  sort(x.begin(), x.end());
  vector<ll> diff(m);
  rep(i, m-1) {
    diff[i] = x[i+1]-x[i];
  }
  sort(diff.begin(), diff.end());
//  rep(i, m) {
//    cerr << diff[i] << endl;
//  }
//  cerr << endl;
  ll ans = 0;
  rep(i, m-n+1) {
    ans += diff[i];
  }
  cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];

    int ans = 1e8;
    for(int i=-100; i<=100; i++){
        int tmp = 0;
        for(int j=0; j<n; j++) tmp += pow(i - v[j], 2);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def aizu004():
    xs = map(int,raw_input().split())
    W = xs[0]
    H = xs[1]
    x = xs[2]
    y = xs[3]
    r = xs[4]
    if (r <= x <= W-r) and (r <= y <= H-r):
        print "Yes"
    else:
        print "No"
aizu004()

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    
    ll ans;
    if ((B - A) % 2 == 0)
    {
        ans = (B - A) / 2;
    }
    else
    {
        ans = min(A - 1, N - B) + 1 + (B - A - 1) / 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)

using namespace std;

typedef long long LL;
const int mod = 1e9 + 7;
const int N = 2000020;

LL p[N], invp[N];
LL qpow(LL a, LL b)
{
	LL ret = 1, base = a;
	while (b) {
		if (b & 1) ret = ret * base % mod;
		base = base * base % mod, b >>= 1;
	}
	return ret;
}

LL C(int a, int b){ return p[a] * invp[b] % mod * invp[a - b] % mod;}
LL G(int a, int b){ return (C(a + b + 2, b + 1) - 1 + mod) % mod;}
LL F(int a, int b, int c, int d){ return (G(c, d) - G(a - 1, d) - G(c, b - 1) + G(a - 1, b - 1) + mod + mod) % mod;}
LL F1(int x1, int y1, int x2, int y2, int x3, int y3){ return F(x2 - x1, y2 - y1, x3 - x1, y3 - y1);}
LL F2(int x1, int y1, int x2, int y2, int x3, int y3){ return F(x1 - x3, y1 - y3, x1 - x2, y1 - y2);}

int main()
{
	
	p[0] = 1;
	Rep(i, 2000010) p[i] = p[i - 1] * i % mod;
	invp[2000010] = qpow(p[2000010], mod - 2);
	for (int i = 2000009; i >= 0; i --) invp[i] = invp[i + 1] * (i + 1) % mod;
	
	int x1, x2, x3, x4, x5, x6;
	int y1, y2, y3, y4, y5, y6;
	
	scanf("%d%d%d%d%d%d", &x1, &x2, &x3, &x4, &x5, &x6);
	scanf("%d%d%d%d%d%d", &y1, &y2, &y3, &y4, &y5, &y6);
	
	LL ans = 0;
	
	for (LL i = x3; i <= x4; i ++) {
		ans -= F2(i, y3 - 1, x1, y1, x2, y2) * F1(i, y3, x5, y5, x6, y6) % mod * (i + y3) % mod;
		ans += F1(i, y4 + 1, x5, y5, x6, y6) * F2(i, y4, x1, y1, x2, y2) % mod * (i + y4 + 1) % mod;
		ans = (ans % mod + mod) % mod;
	}
	for (LL i = y3; i <= y4; i ++) {
		ans -= F2(x3 - 1, i, x1, y1, x2, y2) * F1(x3, i, x5, y5, x6, y6) % mod * (i + x3) % mod;
		ans += F1(x4 + 1, i, x5, y5, x6, y6) * F2(x4, i, x1, y1, x2, y2) % mod * (i + x4 + 1) % mod;
		ans = (ans % mod + mod) % mod;
	}
	printf("%lld\n", ans);
	
	return 0;
}
/*
7752 8955 42058 60436 84566 97345
274 18805 54433 64765 70933 98819
*/

Measured memory_bytes: 31488
#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef unsigned long long wolf;
long long mod=1000000007;
char in[1100000];
int lc[210000];
int rc[210000];
int L[210000];
int R[210000];
wolf rj[610000];
int v[210000];
void dfs(int a){
	v[a]=1;
	if(lc[a]!=-1){
		dfs(lc[a]);
		v[a]+=v[lc[a]];
	}
	if(rc[a]!=-1){
		dfs(rc[a]);
		v[a]+=v[rc[a]];
	}
}
map<wolf,int> dp;
wolf sum[610000];
wolf hash[210000];
int sz;
int chk(int a,int b){
	queue<pair<int,int> >Q;
	Q.push(make_pair(a,b));
	while(Q.size()){
		int at=Q.front().first;
		int cur=Q.front().second;
		Q.pop();
		if(v[cur]==1){
			if(~lc[at]){
				Q.push(make_pair(lc[at],lc[b]));
				Q.push(make_pair(rc[at],rc[b]));
			}
		}else{
			if(v[at]==1)return 0;
			Q.push(make_pair(lc[at],lc[cur]));
			Q.push(make_pair(rc[at],rc[cur]));
		}
	}
	return 1;
}
int calc(int a){
	if(v[a]==3&&~lc[a]&&~rc[a])return 0;
	if(dp.count(hash[a]))return dp[hash[a]];
	
	set<wolf>S;
	int ret=999999999;
	for(int i=a+1;i<sz&&R[i]<R[a];i++){
		if(v[i]==1)continue;
		if(v[a]%(v[i]-1)!=1)continue;
		if(S.count(hash[i]))continue;
		if(!chk(a,i))continue;
		S.insert(hash[i]);
		ret=min(ret,v[a]/(v[i]-1)-1+calc(i));
	}
	return dp[hash[a]]=ret;
}
int main(){
	scanf("%s",in);
	rj[0]=1;
	for(int i=0;i<210000;i++)rc[i]=lc[i]=-1;
	for(int i=1;i<610000;i++)rj[i]=rj[i-1]*mod;
	for(int i=0;in[i];i++){
		sum[i+1]=sum[i]+rj[i]*in[i];
	}
	sz=0;
	stack<int>S;
	S.push(-1);
	for(int i=0;in[i];i++){
		if(in[i]=='('){
			L[sz]=i;
			if(S.top()!=-1){
				if(lc[S.top()]==-1)lc[S.top()]=sz;
				else rc[S.top()]=sz;
			}
			S.push(sz);
			sz++;
		}else{
			R[S.top()]=i;
			S.pop();
		}
	}
	dfs(0);
	for(int i=0;i<sz;i++){
		hash[i]=(sum[R[i]+1]-sum[L[i]])*rj[609999-L[i]];
	}
	printf("%d\n",calc(0));
}

Measured memory_bytes: 18324
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<int>a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    int maxn=0;
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        if(a[i] >= maxn) {
            maxn=a[i];
        }
        else{
            cnt+=maxn-a[i];
        } 
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;


int main(){
 int n;
  cin>>n;
  if(n%3==0){
    if(n==111) cout<<3<<endl;
    else cout<<0<<endl;}
  else if(n%3==1) cout<<1<<endl;
  else cout<<2<<endl;
 
}
 

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    long N;
    cin >> N;
    N--;
    string a_to_z = "abcdefghijklmnopqrstuvwxyz";
    string name = "";
    long max = 0;
    long x = 1;
    long M = N;
    do
    {
        name = a_to_z.substr(N % 26, 1) + name;
        N = (N - 26) / 26;
        x *= 26;
        max += x;
    } while (M >= max);
    cout << name;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    string ans = "DENIED";
    rep(i, n){
        cin >> a.at(i);
    }
    int count = 0;
    int ans_count = 0;
    rep(i, n){
        if(a.at(i) % 2 == 0) count++;
        if((a.at(i) % 2 == 0) && (a.at(i) % 3 == 0 || a.at(i) % 5 == 0)){
            ans_count++;
        }
    }
    if(count == ans_count){
            ans = "APPROVED";
        }
    cout << ans << endl;
}


Measured memory_bytes: 256