akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
import std.bigint;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto nk = readNums!long;
  auto a = readNums!int;

  auto visited = new int[](cast(int)nk[0]);

  int now = 1, count = 1;
  int loop_count;
  visited[0] = 1;
  while(true){
    count++;
    now = a[now-1];
    if(visited[now-1] > 0){
      loop_count = count - visited[now-1];
      break;
    } else {
      visited[now-1] = count;
    }
  }

  long move = (nk[1] - visited[now-1] + 1) % loop_count;
  if(nk[1] - visited[now-1] + 1 <= 0){
    move = nk[1];
    now = 1;
  }

  foreach(i; 0 .. move){
    now = a[now-1];
  }

  writeln(now);
}


Measured memory_bytes: 11944
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] table = new int[m][2];
		for(int i = 0; i < m; i++) {
			table[i][0] = sc.nextInt();
			table[i][1] = sc.nextInt();
		}
		List<int[]> list = Arrays.stream(table).sorted((a1, a2) -> a1[1] - a2[1]).collect(Collectors.toList());
		Set<Integer> c  =new HashSet<>();
		for(int[] array : list) {
			boolean b = false;
			for(int i : c)
				b |= array[0] <= i && i < array[1];
			if(b)
				continue;
			c.add(array[1]-1);
		}
		System.out.println(c.size());
	}
}

Measured memory_bytes: 95436
n,k=map(int,input().split())
x=sorted(list(map(int,input().split())))
print(min((min(abs(x[i])+abs(x[i+k-1]-x[i]),abs(x[i+k-1])+abs(x[i]-x[i+k-1]))) for i in range(n-k+1)))

Measured memory_bytes: 15020
# coding: utf-8
# Your code here!

N,K,S=map(int,input().split())
ans=[]
if S!=10**9:
    for i in range(K):
        ans.append(S)
    
    for i in range(N-K):
        ans.append(S+1)
else:
    for i in range(K):
        ans.append(S)
    
    for i in range(N-K):
        ans.append(S-1)

ans=[str(i) for i in ans]
ans=" ".join(ans)
print(ans)

Measured memory_bytes: 14232
# AOJ 0074 Videotape
# Python3 2018.6.14 bal4u

while True:
	a = list(map(int, input().split()))
	if a[0] < 0: break
	t = 7200 - (3600*a[0] + 60*a[1] + a[2])
	print('{:02d}:{:02d}:{:02d}'.format(t//3600, (t%3600)//60, t%60))
	t *= 3
	print('{:02d}:{:02d}:{:02d}'.format(t//3600, (t%3600)//60, t%60))



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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; }

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int hw = max(h, w);
    
    int ans = (n + hw -1) / hw;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int n;
    cin>>n;
    vector<int> B(n-1);
    rep(i,n-1) cin>>B[i];
    int sum=B[0];//A[0]
    rep(i,n-2)
        sum+=min(B[i],B[i+1]);//A[i+1]
    sum+=B[n-2];//A[n-1]
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<int,P> PP;
typedef long long ll;
int n,m,ST;
int fie[11][11];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
vector<int> G[25][4];
int co;
int dp[25][(1<<18)];
void make_graf(){
  for(int x=0;x<m;x++){
    for(int y=0;y<n;y++){
      //      printf("fie[%d][%d]=%d\n",x,y,fie[x][y]);
      if(fie[x][y]<-1) continue;
      int no=fie[x][y];
      if(no<0) no=co;
      //          printf("%d\n",no);
      for(int i=0;i<4;i++){
	G[no][i].clear();
	for(int l=1;;l++){
	  int nx = x+dx[i]*l;
	  int ny = y+dy[i]*l;
	  if(nx<0 || ny<0) break;
	  if(nx>=m || ny>=n) break;
	  if(fie[nx][ny]>=-1)
	    G[no][i].push_back(fie[nx][ny]);
	}

	//	printf("size=%d\n",G[no][i].size());
      }
    }
  }
}
int solve(int no,int st){
  //  cout <<no << " " << bitset<24>(st) << endl;
  if(st<(1<<18)){
    if(dp[no][st]!=-1) return dp[no][st];
  }
  int x,y;
  if(st==ST){
    for(int i=0;i<4;i++){
      if(G[no][i].empty()) continue;
      for(int l=0;l<(int)G[no][i].size();l++){
	int num = G[no][i][l];
	if(num==-1) return 1;
      }
    }
    return 0;
  }
  int ret=0;
  for(int i=0;i<4;i++){
    //   cout << G[no][i].size() << endl;
    if(G[no][i].empty()) continue;
    for(int l=0;l<(int)G[no][i].size();l++){
      /*      int nx = x+dx[i]*l;
      int ny = y+dy[i]*l;
      if(nx<0 || ny<0) break;
      if(nx>=m || ny>=n) break;
      if(fie[nx][ny]==-2) continue;
      if(fie[nx][ny]==-1) continue;
      if(!(st & (1<<fie[nx][ny])) ){
	ret+=solve(nx,ny,no+1, (st | (1<<fie[nx][ny])) );
	break;
	}*/
      int num = G[no][i][l];

      //    cout << num << " " << (st|(1<<num)) << endl;
      if(num==-2) continue;
      if(num==-1) continue;
      if(!(st & (1 << num)) ){
	ret+= solve(num,(st | (1 << num)));
	break;
      }
    }
  }
  if(st<(1<<18))
    return dp[no][st]=ret;
  else
    return ret;
}

void print_fie(){
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      printf("%3d ",fie[j][i]);
    }
    puts("");
  }
}

int main(){
  while(1){
    scanf("%d %d",&m,&n);
    if(!n && !m) break;
    memset(dp,-1,sizeof(dp));
    int sx,sy;
    co=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	scanf("%d",&fie[j][i]);
	if(fie[j][i]==1){
	  fie[j][i]=co;
	  co++;
	} else if (fie[j][i]==2){
	  fie[j][i]=-1;
	  sx=j; sy=i;
	} else if (fie[j][i]==0){
	  fie[j][i]=-2;
	}
      }
    }
    ST=(1<<co)-1;
    make_graf();
    //  print_fie();
    printf("%d\n",solve(co,0));
  }
}

Measured memory_bytes: 26816
from math import gcd
n = int(input())
p = 10**9 + 7
iwashi = {}
bad = 0
ans = 1
for i in range(n):
    x, y = map(int, input().split())
    if(x == 0 and y == 0):
      bad += 1
      continue
    elif(x == 0):
        try:
        	iwashi[(0, 1)] += 1
        except KeyError:
            iwashi[(0, 1)] = 1
            continue
    elif(y == 0):
        try:
        	iwashi[(1, 0)] += 1
        except KeyError:
            iwashi[(1, 0)] = 1
        continue
    else:
        g = gcd(x, y)
        x, y = x // g, y // g
        if x < 0:
            x, y = -x, -y
        try:
        	iwashi[(x, y)] += 1
        except KeyError:
            iwashi[(x, y)] = 1
            
for x, y in iwashi:
    a = iwashi[(x, y)]
    if y > 0:
    	rx,ry = y, -x
    else:
      	rx,ry = -y, x
    try:
        b = iwashi[(rx,ry)]
        iwashi[(rx,ry)] = 0
    except KeyError:
      	b = 0
    ans *= pow(2, a, p) + pow(2, b, p) - 1
    ans %= p
    iwashi[(x, y)] = 0
print((ans + bad - 1) % p)


Measured memory_bytes: 46316
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + int(b / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

void yesno(bool f) { cout << (f ? "Yes" : "No") << endl; }

//


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

	if ( n == 1 )
	{
		cout << "Hello World" << endl;
	}
	else
	{
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;



int main(){
 int a; cin>>a;
 string s; cin>>s;
 if(a>=3200)cout<<s<<endl;
 else cout<<"red"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long ans = 0;
        long sum = x;
        for (int i = 1; sum <= y; i++) {
            sum *= 2;
            ans++;
        }
        System.out.println(ans);
    }
}

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

int main(){

  int h, w;

  while(1) {

    cin >> h >> w;

    if(h == 0 && w == 0) break;

    for(int i=1; i<=w; i++) cout << "#";
    cout << "\n";
    
    for(int i=1; i<=h-2; i++) {
      cout << "#";
      for(int i=1; i<=w-2; i++) cout << ".";
      cout << "#";
      cout << "\n";  
    }
    
    for(int i=1; i<=w; i++) cout << "#";
    cout << "\n" << "\n";;
  }
    
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N, A, B;

	cin >> N >> A >> B;

	bool ans = abs(A - B) % 2;

	cout << (ans ?"Borys" : "Alice") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=1e5+50;
int n;
ll st,x[N],p[N],ans;

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
//	freopen("dat.in","r",stdin);
//	freopen("my.out","w",stdout);
#endif
	scanf("%d%lld",&n,&st);
	rep(i,1,n)scanf("%lld%lld",x+i,p+i);
	int l=1,r=n;	
	while(l<=r&&!(st<x[l]||st>x[r])){	
		if(p[l]>=p[r]){
			ans+=x[r]-x[l];
			while(l<=r&&p[l]>=p[r])p[l]+=p[r--];
		}else{
			ans+=x[r]-x[l];
			while(l<=r&&p[r]>p[l])p[r]+=p[l++];
		}
	}
	if(st<x[l]){
		ans+=x[r]-st;
	}
	if(st>x[r]){
		ans+=st-x[l];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
// -*- coding: utf-8 -*-
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskC solver = new TaskC();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskC {    
    String s;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      s = in.next();
      int ans = Integer.MAX_VALUE, cnt = 0, n = s.length();
      char color = s.charAt(0);
      for (int i = 1; i < n; ++i)
        if (s.charAt(i) != color) {
          color = s.charAt(i);
          ++cnt;
        }
      ans = cnt;
      cnt = 0;
      color = s.charAt(n - 1);
      for (int i = n - 2; i >= 0; --i)
        if (s.charAt(i) != color) {
          color = s.charAt(i);
          ++cnt;
        }
      ans = Math.min(ans, cnt);
      out.println(ans);
    }
    
  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

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

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


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

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

    int c = 1;
    for (int i = 1; i < s.length(); i++) {
        if(s[i - 1] != s[i]) c++;
    }
    cout << c << endl;
    return 0;
}

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

int main()
{
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = 0;
    if(N > A+B){
        ans += (N/(A+B))*A;
        if(N%(A+B) <= A) ans += N%(A+B);
        else ans += A;
    }else{
        ans += A;
    }
    if(N < A) ans = N;
    cout << ans << endl;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#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=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  map<int, int> mp;
  vector<int> a(3), b(3);
  rep(i, 3)cin >> a[i] >> b[i];
  rep(i, 3){
    mp[a[i]]++;
    mp[b[i]]++;
  }
  int one = 0, two = 0;
  FOR(i ,1, 5){
    if(mp[i] == 1)one++;
    else if(mp[i] == 2)two++;
  }
  if(one == 2 && two == 2)cout << "YES" << endl;
  else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
N=sys.stdin.readline().strip()
A=map(int, sys.stdin.readline().split())
a_max=None
ans=0
for i,a in enumerate(A):
    if i==0:
        a_max=a
    else:
        if a<a_max:
            ans+=(a_max-a)
        elif a_max<a:
            a_max=a
print ans


Measured memory_bytes: 93868
// 2017.7.27

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int b, f, r, v;;
	int house[5][4][11];
	int i, n;

	for (b = 1; b <= 4; b++) {
		for (f = 1; f <= 3; f++) {
			for (r = 1; r <= 10; r++) house[b][f][r] = 0;
		}
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d%d", &b, &f, &r, &v);
		house[b][f][r] += v;
	}

	for (b = 1; b <= 4; b++) {
		for (f = 1; f <= 3; f++) {
			for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
			putchar('\n');
		}
		if (b < 4) puts("####################");
	}
	return 0;
}


Measured memory_bytes: 2112
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        double r,area,length;
    	//?¨??????\??????????????????????????§????????????
		Scanner scanner = new Scanner(System.in);

		r = scanner.nextDouble();

    	area = r*r*Math.PI;
    	length = 2*r*Math.PI;
    	//println?????¨??¨??????1.0E9??¨????????????AOJ??????????????¨
    	//??????????????????????????§printf????????¨???
    	System.out.printf("%f %f",area,length);
    	scanner.close();
    }
}

Measured memory_bytes: 28044
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;

void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

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

const int MAX = 210;

int N, M, R;
ll dist[MAX][MAX];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> R;
    vector<int> vr;
    rep(i,R) {  int r; cin >> r; --r; vr.push_back(r); }
    for (int i = 0; i < 210; ++i) {
        for (int j = 0; j < 210; ++j) dist[i][j] = LLINF;
        dist[i][i] = 0;
    }

    for (int i = 0; i < M; ++i) {
        int a, b, c; cin >> a >> b >> c; --a, --b;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    rep(k,N)rep(i,N)rep(j,N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    ll ans = LLINF;
    sort(all(vr));
    do{
      ll tmp = 0;
      for (int i = 1; i < vr.size(); ++i) tmp += dist[vr[i]][vr[i-1]];
      chmin(ans,tmp);
    } while (next_permutation(vr.begin(), vr.end()));

    cout << ans << endl;
}


Measured memory_bytes: 640
#include<functional>
#include<iostream>
#include<map>
#include<utility>

typedef std::pair<int, int> P;
std::multimap<P, char, std::greater<P>> m;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		m.clear();

		for( int i = 0; i != n; ++i )
		{
			char t;
			std::cin >> t;
			int win = 0, lose = 0;
			for( int j = 0; j != n - 1; ++j )
			{
				int r;
				std::cin >> r;
				if( r != 2 )
					++( r ? lose : win );
			}

			m.insert( std::make_pair( P( win, -lose ), t ) );
		}

		for( auto it = m.begin(); it != m.end(); ++it )
			std::cout << it->second << std::endl;
	}

	return 0;
}

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

ll N;
vector<ll> X;

int main(){
    cin >>N;
    X.resize(N);
    for (int i = 0; i < N; i++) cin >> X[i];
    ll out = 99999999;
    for (int i = 1; i <= 100; i++){
      ll tmp = 0;
      for (int j = 0; j < N; j++) {
        tmp += (X[j] - i)*(X[j]-i);
      }
      out = min(tmp, out);
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


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

  int ans = 0;
  rep(i, s.size()) ans += (s[i] != t[i]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3812
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    if(n%2 == 0){
        int m = n*(n-1)/2 - n/2;
        cout << m << endl;
        for(int i = 1;i <= n-1;i++){
            for(int j = i+1;j <= n;j++){
                if(i+j != n+1)cout << i << " " << j << endl;
            }
        }
    }else{
        int m = n*(n-1)/2 - n/2;
        cout << m << endl;
        for(int i = 1;i <= n-2;i++){
            for(int j = i+1;j <= n-1;j++){
                if(i+j != n)cout << i << " " << j << endl;
            }
        }
        for(int i = 1;i <= n-1;i++)cout << i << " " << n << endl;
    }
    


    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://agc032.contest.atcoder.jp/tasks/agc032_a

Measured memory_bytes: 256
void main() {
	auto N = ri;
	long k;
	auto P = readAs!(int[]);
	auto Q = readAs!(int[]);
	auto arr = P.dup.sort().array;

	long a, b;
	do {
		if(arr == P) a = k;
		if(arr == Q) b = k;
		k++;
		//debug arr.writeln;
	} while(nextPermutation(arr));
	writeln(abs(a - b));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint A(N+1), B(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
	}
	sort(begin(A)+1, end(A));
	sort(begin(B)+1, end(B));
	if (N&1) {
		cout << B[(N+1)/2] - A[(N+1)/2] + 1 << endl;
	} else {
		cout << B[N/2+1]+B[N/2] - A[N/2+1]-A[N/2] + 1 << endl;
	}
}

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


Measured memory_bytes: 4772
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import bisect
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    n, k = getlist()
    nums = getlist()
    acc = {0: [0]}
    tmp = 0
    for i, num in enumerate(nums):
        tmp += num
        tmp %= k
        tgt = ((tmp - i -1  + k) % k)
        if tgt not in acc:
            acc[tgt] = [i+1]
        else:
            acc[tgt].append(i+1)
        # acc.append(tmp-i-1)

    # cnt = Counter(acc)
    ans = 0
    for v in acc.values():
        for j, cur in enumerate(v):
            ins = bisect.bisect_left(v, cur+k)
            # print(ins, j)
            ans += ins - j - 1
        # ans += ((v-1) * v) // 2
    # print(acc)
    print(ans)

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 120904
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1001000;
char s[N];
int a[N], b[N], is[10], n, K;
bool FLAG, Zeroflag;
void find(int cur) {
	if(cur == 0) {
		for(int j = 1; j < 10; j ++ ) if(!is[j]) {
			b[cur] = j; FLAG = 1; break;
		}
		Zeroflag = 1;
		return;
	}
	bool have = 0;
	for(int j = a[cur]+1; j < 10; j ++ ) if(!is[j]) {
		b[cur] = j, have = 1, FLAG = 1; break;
	}
	if(have) return ;
	for(int j = 0; j < 10; j ++ ) if(!is[j]) {
		b[cur] = j; break;
	}
	find(cur-1);
}
int main() {
	scanf("%s%d", s+1, &K);
	n = strlen(s+1);
	for(int i = 1; i <= n; i ++ ) a[i] = s[i] - 48;
	for(int i = 1; i <= K; i ++ ) {
		int x; scanf("%d", &x);
		is[x] = 1;
	}
	for(int i = 1; i <= n; i ++ ) {
		if(!is[a[i]]&&!FLAG) {
			b[i] = a[i];
			continue;
		}
		bool have = 0;
		if(FLAG) {
			for(int j = 0; j < 10; j ++ ) if(!is[j]) {
				b[i] = j; have = 1; break;
			}
		}
		else {
			for(int j = a[i]+1; j < 10; j ++ ) if(!is[j]) {
				FLAG = 1; b[i] = j; have = 1; break;
			}
		}
		if(!have) {
			for(int j = 0; j < 10; j ++ ) if(!is[j]) {
				b[i] = j; break;
			}
			find(i-1);
		}
	}
	if(Zeroflag) printf("%d", b[0]);
	for(int i = 1; i <= n; i ++ ) printf("%d", b[i]);
	putchar('\n');
}

Measured memory_bytes: 4352
#include<string.h>
#include <stdio.h>
#include <ctype.h>

int main(void){
    char ch;
    
    while(1){
        scanf("%c",&ch);
        
        if(ch == '\n')break;
        if(islower(ch)) ch = toupper(ch);
        else if(isupper(ch)) ch = tolower(ch);
        printf("%c",ch);
    }
    printf("\n");
}

Measured memory_bytes: 1740
#include<iostream>

using namespace std;

int main()
{
  char c;

  int st[26] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  
  while( cin >> c )
    {
      if ( c >= 'a' && c <= 'z' )
        {
          st[c - 'a']++;
        }
      else if ( c >= 'A' && c <= 'Z' )
        {
          st[c - 'A']++;
        }
    }

  for ( char i = 'a'; i <= 'z'; i++)
    {
      cout << i << " : " << st[i - 'a'] << endl;
    }
  
  return 0;
}

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

void out(long long int n)
{
    cout << n << endl;
}

int main()
{
    long long int x,t;
    cin>>x>>t;
    if(t>=x) { out(0); }
    else if(t<x) { out(x-t); }
    else {}
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    G = [[] for _ in range(N)]
    for i, (ai, bi) in enumerate(zip(a, b)):
        ai -= 1
        bi -= 1
        G[ai].append((i, bi))
        G[bi].append((i, ai))

    ans = 0
    for k in range(M):
        q = deque()
        visited = {0}
        q.append(0)
        while q:
            s = q.popleft()
            for i, t in G[s]:
                if i == k:
                    continue
                if t in visited:
                    continue
                visited.add(t)
                q.append(t)

        if len(visited) < N:
            ans += 1

    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Sliceconvtoi() []int {
	strs := strings.Split(sc.Text(), " ")

	var ints []int
	var x int

	for _, s := range strs {
		x, _ = strconv.Atoi(s)
		ints = append(ints, x)
	}

	return ints
}

func main() {
	for sc.Scan() {
		i := Sliceconvtoi()
		fmt.Println(int(math.Log10(float64(i[0]+i[1]))) + 1)
	}

}



Measured memory_bytes: 1104
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
a = lmp()
num = 0
for i in range(n):
    num ^= a[i]
for i in range(n):
    print(num ^ a[i])





Measured memory_bytes: 105608
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    while (true) {
        ll w = in(), h = in();
        if (w == 0 && h == 0)break;
        auto mp = VVI(ll, h + 2, w + 2, 0);
        REP(i, h) {
            REP(j, w) {
                mp[i + 1][j + 1] = in();
            }
        }
        ll ans = 0;
        REP(i, h) {
            REP(j, w) {
                if (mp[i + 1][j + 1] == 1) {
                    stack<pair<ll, ll>>st; st.emplace(i + 1, j + 1);
                    while (!st.empty()) {
                        auto cood = st.top(); st.pop();
                        mp[cood.first][cood.second] = 2;
                        for (ll dy = -1; dy <= 1; ++dy) {
                            for (ll dx = -1; dx <= 1; ++dx) {
                                ll y = cood.first + dy, x = cood.second + dx;
                                if (mp[y][x] == 1) {
                                    st.emplace(y, x);
                                }
                            }
                        }
                    }
                    ++ans;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3148
#include<stdio.h>
#include<string.h>
char t[16];
int main(){
	scanf("%s",t);
	int p=strlen(t);
	int ret=0;
	for(int i=0;i<p/2;i++){
		if(t[i]=='i'&&t[p-i-1]=='i');
		else if(t[i]=='w'&&t[p-i-1]=='w');
		else if(t[i]=='('&&t[p-i-1]==')');
		else if(t[i]==')'&&t[p-i-1]=='(');
		else ret++;
	}
	if(p%2&&t[p/2]!='i'&&t[p/2]!='w')ret++;
	printf("%d\n",ret);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


int arr[maxii];
int arr2[maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;
int x[]={1,-1,0,0};
int y[]={0,0,-1,1};
int x2[]={1,-1,0,0,1,-1,1,-1};
int y2[]={0,0,-1,1,1,-1,-1,1};
int bx[]={0,0,1,-1,-1,1,1,-1};
int by[]={1,-1,0,0,-1,-1,1,1};
int kx[] = {1,1,2,2,-1,-1,-2,-2};
int ky[] = {2,-2,1,-1,2,-2,1,-1};

bool isvisited(int x,int y)
{
    if(x<1 || y<1 || x>n ||y>m)
    {
        return false;
    }
    else if(check2[x][y]==true)
    {
        return false;
    }
    else true;
}
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    int n,m;
    sc(n)
    sc(m)
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        arr[a]++;
        arr[b]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<arr[i]<<endl;
    }
}






Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a , b;

 cin >> a >> b;
 if ((a * b) % 2 == 0){
  cout << "Even" << endl;  
 }
 else if((a * b) % 2 == 1){
  cout << "Odd" << endl;
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<int,int> M;
int main(){
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x;scanf("%d",&x);M[x]++;
	}
	for(auto it=M.begin();it!=M.end();){
		if(it->second<2)it=M.erase(it);
		else it++;
	}
	if(M.size()==0 || M.size()==1&& M.begin()->second<4)return puts("0"),0;
	auto it=M.end();it--;
	long long x=it->first;it--;
	x*=it->first;
	for(auto &y:M)if(y.second>=4)x=max(x,1LL*y.first*y.first);
	printf("%lld\n",x);
}

Measured memory_bytes: 4992
N = int(input())
S = input()
ans = 0

for i in range(0, 1000):
    i = str(i).zfill(3)
    idx = 0
    for j in range(3):
        if i[j] in S[idx:]:
            idx += S[idx:].index(i[j])+1
            continue
        else:
            break
    else:
        ans += 1

    


print(ans)

Measured memory_bytes: 42332
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define PR       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int s, w;
    cin >> s >> w;
    cout << (w >= s ? "unsafe" : "safe");
    return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,l,r) for(int i=(r-1);i>=(l);i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define range(i) i.begin(),i.end()
#define sum(i) accumulate(range(i),0)
#define Yes(i) out(i?"Yes":"No")
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(10);};}aaaaaaa;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){
    cin>>head;
    in(move(tail)...);
}
template <class T>
inline void out(T t) {
    cout<<t<<'\n';
}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){
    cout<<head<<' ';
    out(move(tail)...);
}

int main(){
    INT(a,b);
    out((a-1)*(b-1));
}









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

int main(){
	int n, x, i, j, k, ans = 0;

	while(cin >> n >> x && (n > 0 || x > 0)){
		ans = 0;
		for (i = 1; i <= n - 2; i++){
			for (j = i + 1; j <= n - 1; j++){
				for (k = j + 1; k <= n; k++){
					if (i + j + k == x) ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}



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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const ll MOD = 998244353;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 1634569;

const int N = 3e2 + 20;
ll dp[2][N * N], f[2][N * N], n, a[N], S, ans;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	ans = 1;
	for (int i = 1; i <= n; i++)
		ans = 3LL * ans % MOD;
	for (int i = 1; i <= n; i++)
		cin >> a[i], S += a[i];
	f[0][0] = dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= S; j++) {
			dp[i % 2][j] = (2LL * dp[1 - i % 2][j] + (j >= a[i] ? dp[1 - i % 2][j - a[i]] : 0)) % MOD;
			f[i % 2][j] = (f[1 - i % 2][j] + (j >= a[i] ? f[1 - i % 2][j - a[i]] : 0)) % MOD;
		}
//	cout << ans << endl;
	for (int i = (S % 2 ? S / 2 + 1 : S / 2); i <= S; i++)
		ans = (ans - 3LL * dp[n % 2][i] + 3LL * MOD) % MOD;
	if (S % 2 == 0)
		ans = (ans + 3LL * f[n % 2][S / 2]) % MOD;
	cout << ans << endl;
}



Measured memory_bytes: 3200
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		BeTogether together = new BeTogether();
		together.run();
	}
}

class BeTogether {
	
	int N;
	int[] nums;
	
	BeTogether() {
		Scanner cin = new Scanner(System.in);
		this.N = cin.nextInt();
		this.nums = new int[N];
		for (int i = 0; i < N; i++) {
			nums[i] = cin.nextInt();
		}
	}
	
	void run() {
		int avarage = calculateAvarage();
		int min = 0;
		for (int i = 0; i < N; i++) {
			min += (nums[i] - avarage) * (nums[i] - avarage);
		}
		System.out.println(min);
	}
	
	int calculateAvarage() {
		double sum = 0.0;
		for (int i = 0; i < N; i++) {
			sum += nums[i];
		}
		return (int)Math.round(sum / nums.length);
	}
}


Measured memory_bytes: 9612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int x;
    cin >> x;
    int ans = 0;
    for(int b = 1; b <= 100; b++){
        for(int p = 2; p <= 10; p++){
            int y = 1;
            rep(i,p) y *= b;
            if (y <= x) ans = max(ans, y);
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int i,dis,N,M;
  cin >> N >> M;
  bool flag = true;
  if(N%2 == 1){
    dis = N-1;
    for(i=0; i<M; i++){
      cout << i+1 << " " << i+dis+1 << endl;   
      dis -=2;
    }
  }
   else{
     dis = N-1;
    for(i=0; i<M; i++){
      cout << i+1 << " " << i+dis+1 << endl;   
      dis -=2;
      if(dis <= (N/2) && flag){dis--; flag = false;}
    }
   }
  return 0;
}

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

int main() {
    long n, sum = 0, temp = 0, ans = LONG_MAX;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    rep(i, n - 1) {
        temp += a.at(i);
        ans = min(ans, abs(sum - 2 * temp));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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;}

int main()
{   
    string s,t; cin >> s >> t;
    bool is_res = true;
    for(int i=0;i<s.size();i++){
        if(s[i] != t[2-i])is_res = false;
    }
    cout << (is_res?"YES":"NO") << endl;
}

Measured memory_bytes: 256
import itertools as it
import numpy as np
import math

N = int(input())
A =[]

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

A = np.array(A)

L = list(it.permutations(range(0,N)))

distance = 0

for i in range (0, len(L)):
    for j in range (1, N):
        distance+=math.sqrt((A[L[i][j]][1]-A[L[i][j-1]][1])**2+(A[L[i][j]][0]-A[L[i][j-1]][0])**2)

print(distance/math.factorial(N))

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

int main(void)
{
    int N, i, ans=0;
    string A, B, C;

    cin >> N >> A >> B >> C;
    
    for(i=0; i<N; i++){
        if(A[i]!=B[i] && B[i]!=C[i] && C[i]!=A[i]){
            ans += 2;
        }
        else if(A[i]==B[i] && B[i]!=C[i]){
            ans += 1;
        }
        else if(A[i]==C[i] && B[i]!=C[i]){
            ans += 1;
        }
        else if(B[i]==C[i] && A[i]!=C[i]){
            ans += 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main()
{
  int n;
  int arr1[100];
  int arr2[100];
  double temp1, temp2, temp3, temp4 = 0;
  scanf("%d", &n);

  for(int i = 0; i < n; i++)
    {
      scanf("%d", &arr1[i]);
    }
  for(int i = 0; i < n; i++)
    {
      scanf("%d", &arr2[i]);
    }
  for(int i = 0; i< n; i++)
    {
      temp1 += abs(arr1[i] - arr2[i]);

      temp2 += abs(pow(arr1[i] - arr2[i], 2));

      temp3 += abs(pow(arr1[i] - arr2[i], 3));
      if(temp4 < abs(arr1[i] - arr2[i]))
	{
	  temp4 = abs(arr1[i] - arr2[i]);
	}
    }

  printf("%f\n%f\n%f\n%f\n", temp1, pow(temp2, 1.0/2), pow(temp3, 1.0/3), temp4);
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    int x, t;
    cin >> x >> t;
    ((x > t) ? (cout << x - t << endl) : (cout << 0 << endl));
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> A;
    A.emplace_back(1);
    for(int i = 6; i <= n; i *= 6){
        A.emplace_back(i);
    }
    for(int i = 9; i <= n; i *= 9){
        A.emplace_back(i);
    }

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

    vector<int> dp(n + 1, 1e9);
    dp[0] = 0;
    for(int i = 0; i < A.size(); i++){
        for(int j = A[i]; j <= n; j++){
            dp[j] = min(dp[j], dp[j - A[i]] + 1);
        }
    }
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>

int main() {
  char buf[4];
  scanf("%s", buf);
  std::string s = buf;
  scanf("%s", buf);
  std::string t = buf;

  int res = 0;
  for (size_t i = 0; i < 3; ++i)
    if (s[i] == t[i]) ++res;

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


Measured memory_bytes: 256