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

int N, K;
vector<pair<ll,ll>> P;

ll calc(ll minX, ll maxX, ll minY, ll maxY){
    int cnt = 0;
    for(int i=0; i<N; i++){
        ll x = P[i].first, y = P[i].second;
        if(minX <= x && x <= maxX && minY <= y && y <= maxY) cnt++;
    }

    if(cnt<K) return 4e18;
    else{
        return (maxX-minX)*(maxY-minY);
    }
}

int main(){
    cin >> N >> K;
    P = vector<pair<ll,ll>>(N);

    for(int i=0; i<N; i++)
        cin >> P[i].first >> P[i].second;
    
    ll ans = 4e18;
    for(int a=0; a<N; a++)for(int b=0; b<N; b++)for(int c=0; c<N; c++)for(int d=0; d<N; d++){
        if(a==b && b==c && c==d) continue;
        
        int p[4] = {a,b,c,d};
        ll minX = 1e9, maxX = -1e9, minY = 1e9, maxY = -1e9;
        for(int i=0; i<4; i++){
            minX = min(minX, P[p[i]].first);
            maxX = max(maxX, P[p[i]].first);
            minY = min(minY, P[p[i]].second);
            maxY = max(minY, P[p[i]].second);
        }

        ans = min(ans, calc(minX,maxX,minY,maxY));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# 負整数が偶数個の場合は全て正整数に置き換えられ、奇数個の場合は少なくとも一つは負整数が残る
input()
num_list = list(map(int, input().split()))
minus_num = 0
sum = 0
for i in range(len(num_list)):
    if(num_list[i] < 0):
        minus_num += 1
        num_list[i] *= -1
    sum += num_list[i]
if(minus_num % 2 == 0):
    print(sum)
else:
    print(sum - min(num_list) * 2)

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

const long long MAX_N = 1e5 + 5, MAX_M = 40;
long long n, x, ans, p;
long long a[MAX_N];
long long l[MAX_N];
long long cnt[MAX_M];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (long long i = 0; i < n; i++)
		cin >> a[i];
		
	for (long long i = 0; i < n; i++)
		x ^= a[i];
		
	for (long long i = 0; i < n; i++) {
		l[i] = __builtin_ctz(a[i]);
		cnt[l[i]]++;
	}
		
	
	for (long long i = 32; ~i; i--)
		if (((x >> i) & 1) ^ p) {
			if (!cnt[i]) {
				cout << "-1\n";
				return 0;
			}
			
			p = !p;
			cnt[i]--;
			ans++;
		}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int a,b;cin>>a>>b;
  if(a<=b)cout<<a<<endl;
  else cout<<a-1<<endl;
}	





Measured memory_bytes: 256
using System;

namespace ConsoleApp11
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = a - 1;
            int d = c * ((a - 1) + 1) / 2;
            int e = b - 1;
            int f = e * ((b - 1) + 1) / 2;
            Console.WriteLine(d+f);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
  	int  x, y;
  	cin >> x >> y;
  	y /=2;
  	cout << x + y;
    return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
const ll MOD = 998244353;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll dp[200005];

int main(){
    int n,k;
    cin >> n>> k;
    vector<int> L(k),R(k);
    rep(i,k){
        cin >> L[i]>> R[i];
    }
    dp[0]=0;
    dp[1]=1;
    for(int i=2;i<=n;i++){
        if(i==2){
            dp[i]=0;
        }else{
            dp[i]=dp[i-1];
        }
        
        rep(j,k){
            if(i-L[j]>=1){
                dp[i]+=dp[i-L[j]];
            }
            dp[i]%=MOD;
            if(i-R[j]-1>=1){
                dp[i]-=dp[i-R[j]-1];
            }
            dp[i]=(dp[i]+MOD)%MOD;
        }
        dp[i]%=MOD;
        //cerr<<dp[i]<<' ';
    }
    dp[n]%=MOD;
    //cerr<<endl;
    ll ans=dp[n]%MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5184
n,m=map(int,input().split())
s=input()[::-1]
ans=[]
now=0
while n>m-1:
  x=s[now+1:now+m+1][::-1]
  memo=x.find('0')
  if memo<0:
    print(-1)
    quit()
  n-=(m-memo)
  now+=(m-memo)
  ans.append(str(m-memo))
if n>0:
  ans.append(str(n))
print(' '.join(ans[::-1]))
  

Measured memory_bytes: 48476
n = int(input())

acount = 0
bcount = 0
abcount = 0
ans = 0

for _ in range(n):
    s = input()
    if s[0] == 'B':
        bcount += 1
    if s[-1] == 'A':
        acount += 1
    if s[0] == 'B' and s[-1] == 'A':
        abcount += 1
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'B':
            ans += 1

if abcount == 0 or max(abcount,acount,bcount) != abcount:
    print(ans + min(acount,bcount))
else:
    print(ans + min(acount,bcount) - 1)


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

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 312345;
const double pi = 3.14159265359;
const double eps = 0.00000001;


int32_t main() {

    $
    //freopen("input.txt", "r+", stdin);
    //freopen("output.txt", "w+", stdout);
    
    int n;

    map<string, vector<ii>> g;

    cin >> n;

    string s;
    int x;

    forn (0, n) {
        cin >> s >> x;
        g[s].push_back({x, i + 1});
    }

    for (auto& it : g) {
        sort(all(it.S), greater<ii>());
        for (auto i : it.S) {
            cout << i.S << '\n';
        }
    }




    
}

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


int main() {
  int N,L;
  cin >> N >> L;
  vector<string> str(N);
  for(int i=0; i<N; i++) {
    cin >> str.at(i);
  }
  sort(str.begin(),str.end());
  for(int i=0; i<N; i++){
    cout << str.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
from sys import stdin
def main():
    readline=stdin.readline
    N,Y=map(int,readline().split())

    flag=False
    for i in range(N+1):
        for j in range(N+1):
            m=10000*i+5000*j
            if m>Y:
                break
            else:
                k=(Y-m)//1000
                m+=1000*k
                if i+j+k==N:
                    print(i,j,k)
                    flag=True
                    break
        if flag:
            break
    if flag==False:
        print(-1,-1,-1)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();
        final int x = scanner.nextInt();

        final long[][] table = new long[n][m];
        final int[] prices = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = scanner.nextInt();
            for (int j = 0; j < m; j++) {
                table[i][j] = scanner.nextInt();
            }
        }

        final long[] sum = new long[m];
        final int answer = permutation(0, prices, 0, sum, x, table);
        System.out.println(answer < Integer.MAX_VALUE ? answer : -1);
    }

    private static int permutation(final int current, final int[] prices, final int price, final long[] sum, final int x, final long[][] table) {
        if (current == table.length) {
            return Integer.MAX_VALUE;
        }

        for (int i = 0; i < sum.length; i++) {
            sum[i] += table[current][i];
        }

        final boolean allOver = Arrays.stream(sum)
                .allMatch(l -> l >= x);
        int min = allOver ? price + prices[current] : Integer.MAX_VALUE;

        min = Math.min(min, permutation(current + 1, prices, price + prices[current], sum, x, table));

        for (int i = 0; i < sum.length; i++) {
            sum[i] -= table[current][i];
        }

        return Math.min(min, permutation(current + 1, prices, price, sum, x, table));
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 38136
/*https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int n, l, m;
	long long min_cost = 1e9 + 1, cost = 0;
	cin >> n >> l >> m;
	int a[n], b[l], c[m], x[m], y[m];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int j = 0; j < l; j++)
		cin >> b[j];
	for (int i = 0; i < m; i++)
		cin >> x[i] >> y[i] >> c[i];
	for (int i = 0; i < m; i++)
	{
		cost = a[x[i] - 1] + b[y[i] - 1] - c[i];
		// cout << cost << endl;
		min_cost = min(min_cost, cost);
	}
	n = min(n, l);
	int minR = 1e5 + 1, minM = 1e5 + 1;
	for (int i = 0; i < n; i++)
		minR = min(a[i], minR);
	for (int i = 0; i < l; i++)
		minM = min(b[i], minM);
	cost = minM + minR;
	min_cost = min(min_cost, cost);
	cout << min_cost;
}

Measured memory_bytes: 5532
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
 
const int N = 10000, OO = 1e9 + 7, T = 410, M = 998244353, P = 6151, SQ = 800, lg = 32;
typedef pair <int, int> pii;
string s[N];
int is[N][100], sum[N];

int32_t main() {
	use_fast;
	int n, m, k;
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++) 
		cin >> s[i];
	for(int i = 0; i < m; i++) {
		for(int j = 0; j < n; j++) {
			is[i][j] = (s[j][i] == '1');
			if(j)
				is[i][j] += is[i][j - 1];
		}
	}
	int ans = n * m;
	for(int msk = 0; msk < (1 << (n - 1)); msk++) {
		for(int i = 0; i <= n; i++)
			sum[i] = 0;	
		int cnt = __builtin_popcount(msk);
		vector <int> v;
		for(int i = 0; i < n; i++)	
			if(msk & (1 << i))
				v.pb(i);
		v.pb(n - 1);
		for(int i = 0; i < m; i++) {
			int pre = -1;
			bool b = false;
			for(auto u : v) {
				sum[u] += is[i][u];
				if(pre != -1) 
					sum[u] -= is[i][pre];
				if(sum[u] > k)	
					b = true;
				pre = u;
			}
			if(!b)
				continue;
			cnt++;
			b = false;
			pre = -1;
			for(auto u : v) {
				sum[u] = is[i][u];
				if(pre != -1) 
					sum[u] -= is[i][pre];
				if(sum[u] > k)	
					b = true;
				pre = u;
			}		
			if(b) {
				cnt = n * m + 1;
				break;
			}	
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0; 
} 
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>


int main() {

    int n{0};
    std::cin >> n;

    int arr[n];
    for(int index = 0; index< n; ++index)
    {
        int val;
        std::cin >> val;
        arr[index] = val;
    }

    int dp[n];
    dp[0] = 0;
    dp[1] = std::min(std::abs(arr[0] - arr[1]),std::abs(arr[0] - arr[2]));

    for(int index = 2; index < n; ++index)
    {
        dp[index] = std::min(dp[index-1] + std::abs(arr[index] -arr[index-1]), dp[index-2] + std::abs(arr[index] -arr[index-2]));
    }
    std::cout << dp[n-1];

    return 0;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)


func next() int {
  sc.Scan()
  text, err := strconv.Atoi(sc.Text())
  if err != nil {
    panic(err)
  }
  return text
}

func main() {
  sc.Split(bufio.ScanWords)
  h := next()
  a := next()
  
  count := h / a
  if h % a != 0 {
    count++
  }
  fmt.Println(count)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}

int main()
{
  //fopen();
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  cin>>n;
  cout<<a[n-1];

  
  
}
    




Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int sum = 0;
		int maxSub = 0;
		for (int i = 0; i < 5; i++) {
			int time = sc.nextInt();
			int sub = 10 - time % 10;
			if (sub == 10) {
				sub = 0;
			}
			sum += time + sub;
			if (sub > maxSub) {
				maxSub = sub;
			}
		}
		System.out.println(sum - maxSub);

		sc.close();
	}
}


Measured memory_bytes: 24020
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int cnt=0;
    if(s[0]==s[s.size()-1]){
        cnt++;
    }
    if(s.size()%2==1){
        cnt++;
    }
    if(cnt%2==0){
        cout << "Second" << endl;
    }
    else{
        cout << "First" << endl;
    }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    int32 mn = INF;
    int32 ans = 0;
    REP(i,n){
        int32 a;
        cin >> a;
        if(mn >= a)ans++;
        mn = min(mn, a);
    }
    ANS(ans);
    return 0;
}

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

int main(){
  int r,g,b,n,ans;
  ans=0;
  cin>>r>>g>>b>>n;

  for(int i=0;i<n/r+1;i++){
    for(int j=0;j<(n-r*i)/g+1;j++){
        if((n-r*i-g*j)%b==0){
          ans+=1;
        }
    }
  }
  cout<<ans<<endl;
}


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

int main(){
    int A[3][3];
    bool Bingo = false;
    bool field[3][3];
    REP(i,3){
        REP(j,3) cin >> A[i][j];
    }
    int N;
    cin >> N;
    int b[N];
    REP(i,N) cin >> b[i];
    REP(i,3){
        REP(j,3){
            field[i][j] = false;
            REP(k,N){
                if(b[k] == A[i][j]) field[i][j] = true;
            }
        }
    }

    if(field[0][0]&&field[0][1]&&field[0][2]) Bingo = true;
    if(field[1][0]&&field[1][1]&&field[1][2]) Bingo = true;
    if(field[2][0]&&field[2][1]&&field[2][2]) Bingo = true;
    if(field[0][0]&&field[1][0]&&field[2][0]) Bingo = true;
    if(field[0][1]&&field[1][1]&&field[2][1]) Bingo = true;
    if(field[0][2]&&field[1][2]&&field[2][2]) Bingo = true;
    if(field[0][0]&&field[1][1]&&field[2][2]) Bingo = true;
    if(field[0][2]&&field[1][1]&&field[2][0]) Bingo = true;
    if(Bingo) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
<?php
fscanf(STDIN, "%d %d %d", $n, $a, $b);
$dis = $b - $a;
if ($dis % 2) {
  $dis_1_a = $a - 1 + 1;
  $dis_b = $b - 1;
  $dis_n_b = $n - $b + 1;
  $dis_n_a = $n - $a;
  echo min($dis_1_a + ($dis-1)/2, $dis_n_b + ($dis-1)/2, $dis_b, $dis_n_a);
} else {
  echo $dis / 2;
}

Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
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 (b < a) { a = b; return true; } return false; }


signed main() {
	string A; cin >> A;
	int n = A.size();

	int cnt[26] = {};
	for (auto c : A)cnt[c - 'a']++;
	int ans = n * (n - 1) / 2 + 1;
	rep(i, 0, 26)
		if (cnt[i] >= 2)
			ans -= cnt[i] * (cnt[i] - 1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
n,k = [int(j) for j in input().split(" ")]

a = []
for _ in range(k):
    _ = int(input())
    a.append([int(j) for j in input().split(" ")])

a_set = set(sum(a, []))
n_set = {j+1 for j in range(n)}
print(len(n_set - a_set))

Measured memory_bytes: 9248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    while(k--) {
        vector<int> old(n, 0);
        swap(old, a);
        rep(i, n) {
            a[max(0, i-old[i])]++;
            if(i+old[i]+1 < n) a[i+old[i]+1]--;
        }
        bool ok = true;
        rep(i, n-1) {
            a[i+1] = a[i] + a[i+1];
        }
        rep(i, n) {
            if(a[i] != n) ok = false;
        }
        if(ok) break;
    }
    rep(i, n) {
        cout << a[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5172
#include<stdio.h>
#include<string.h>

int main(void){
  int n,i;
  char s1[10], s2[10];
  int a = 0;
  int b = 0;
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
  
  scanf("%s %s", s1, s2);
  
  if ( strcmp(s1, s2) == 0 ){ 
  a += 1;
  b += 1;
  }
  
  else if ( strcmp(s1, s2) > 0 ) 
  a += 3;
  
  else if ( strcmp(s1, s2) < 0 )
  b += 3;
  
  }
  
  printf("%d %d\n",a,b);
  
  return 0;
}


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

using namespace std;

int
main()
{
  string n;
  cin >> n;
  int c = 1;
  char p = n[0];
  for (int i = 1; i < 4; ++i) {
    if (p == n[i]) {
      c++;
    }
    else {
      c = 1;
    }
    if (c == 3) {
      break;
    }
    p = n[i];
  }
  if (c < 3) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include <cmath>  
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    double r;
    cin >> r;
//??¢?????¨?????¨?????????????????????????????§????????£????????????????????????????????????????????????????°???°?????°??¨??????0.00001 ??\???????????????????????§?????????????????¨????????????
    printf("%.5f %.5f", r* r * M_PI, (r*2)*M_PI);
    
}

Measured memory_bytes: 3208
#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = (1 << 19) + 10;

const int maxn = 2e5 + 100;

const int mod = 924844033;

const int proot = 5;

struct edge {
	int to, next;
	
	edge(){}
	edge(int to, int next): to(to), next(next) {}
}e[maxn << 1];

int n, m;
int head[maxn], coef[maxn], siz[maxn];
int fac[N], ifac[N], a[N], b[N];

int Exp(int x, int n) {
	int y = 1;
	while(n) {
		if(n & 1) {
			y = 1ll * y * x % mod;
		}
		x = 1ll * x * x % mod;
		n >>= 1;
	}
	return y;
}

void pre() {
	fac[0] = 1;
	for (int i = 1; i < N; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
	}
	ifac[N - 1] = Exp(fac[N - 1], mod - 2);
	for (int i = N - 1; i >= 1; --i) {
		ifac[i - 1] = 1ll * ifac[i] * i % mod;
	}
	return;
}

void dfs(int u = 1, int par = 0) {
	siz[u] = 1;
	for (int i = head[u]; ~i; i = e[i].next) {
		if(e[i].to != par) {
			dfs(e[i].to, u);
			--coef[siz[e[i].to]];
			siz[u] += siz[e[i].to];
		}
	}
	--coef[n - siz[u]];
	++coef[n];
	return;
}

void add_edge(int u, int v) {
	e[m] = edge(v, head[u]);
	head[u] = m++;
	return;
}

void add_biedge(int u, int v) {
	return add_edge(u, v), add_edge(v, u);
}

void dft(int *a, bool rev = 0) {
	for (int i = 0, j = 0; i < m; ++i) {
		if(i < j) {
			std::swap(a[i], a[j]);
		}
		for (int k = (m >> 1); (j ^= k) < k; k >>= 1);
	}
	for (int hl = 1, l = 2; hl < m; hl = l, l <<= 1) {
		int wn = Exp(proot, (mod - 1) / l);
		if(rev) {
			wn = Exp(wn, mod - 2);
		}
		for (int i = 0; i < m; i += l) {
			int w = 1;
			for (int j = i, k = (i | hl); j < (i | hl); ++j, ++k) {
				int x = a[j], y = 1ll * a[k] * w % mod;
				a[j] = (x + y) % mod;
				a[k] = (x - y) % mod;
				w = 1ll * w * wn % mod;
			}
		}
	}
	if(rev) {
		int inv = Exp(m, mod - 2);
		for (int i = 0; i < m; ++i) {
			a[i] = 1ll * a[i] * inv % mod;
		}
	}
	return;
}

int main() {
	pre();
	scanf("%d", &n);
	memset(head + 1, -1, sizeof(head[0]) * n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		add_biedge(u, v);
	}
	dfs();
	m = 1;
	while(m <= (n << 1)) {
		m <<= 1;
	}
	for (int i = 1; i <= n; ++i) {
		a[i] = 1ll * coef[i] * fac[i] % mod;
		b[i] = ifac[n - i];
	}
	dft(a);
	dft(b);
	for (int i = 0; i < m; ++i) {
		a[i] = 1ll * a[i] * b[i] % mod;
	}
	dft(a, 1);
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", (1ll * a[i + n] * ifac[i] % mod + mod) % mod);
	}
	return 0;
}

Measured memory_bytes: 23680
H, W = map(int,input().split())
s = [input() for i in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        # (0,0)
        if i == 0 and j == 0:
            if s[i][j] == "#":
                dp[i][j] = 1
        # 1行目
        elif i == 0:
            if s[i][j-1] == "#":
                dp[i][j] = dp[i][j-1]
            else:
                if s[i][j] == "#":
                    dp[i][j] = dp[i][j-1] + 1
                else:
                    dp[i][j] = dp[i][j-1]
        # 1列目
        elif j == 0:
            if s[i-1][j] == "#":
                dp[i][j] = dp[i-1][j]
            else:
                if s[i][j] == "#":
                    dp[i][j] = dp[i-1][j] + 1
                else:
                    dp[i][j] = dp[i-1][j]
        else:
            # 上か左どちらの値が小さいか
            # 左側の方が小さい
            if dp[i-1][j] > dp[i][j-1]:
                if s[i][j-1] == "#":
                    dp[i][j] = dp[i][j-1]
                else:
                    if s[i][j] == "#":
                        dp[i][j] = dp[i][j-1] + 1
                    else:
                        dp[i][j] = dp[i][j-1]
            # 上側の方が小さい
            elif dp[i-1][j] < dp[i][j-1]:
                if s[i-1][j] == "#":
                    dp[i][j] = dp[i-1][j]
                else:
                    if s[i][j] == "#":
                        dp[i][j] = dp[i-1][j] + 1
                    else:
                        dp[i][j] = dp[i-1][j]
            # 等しい
            else:
                if s[i-1][j] == "#" or s[i][j-1] == "#":
                    dp[i][j] = dp[i-1][j]
                else:
                    if s[i][j] == "#":
                        dp[i][j] = dp[i-1][j] + 1
                    else:
                        dp[i][j] = dp[i-1][j]

print(dp[H-1][W-1])

Measured memory_bytes: 3192
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN = 100000;
const int MAXM = 200000;
const int MOD = 1000000007;

int n, m, s, t;
int ghead[MAXN], gnxt[2 * MAXM], gto[2 * MAXM], glen[MAXM];

ll ds[MAXN], dt[MAXN]; int wayss[MAXN], wayst[MAXN];
priority_queue<pair<ll, int> > pq;

void dcalc(ll *d,int *ways, int s) {
	REP(i, n) d[i] = LLONG_MAX, ways[i] = 0; pq = priority_queue<pair<ll, int> >();
	d[s] = 0, ways[s] = 1, pq.push(MP(-d[s], s));
	while (!pq.empty()) {
		ll cd = -pq.top().first; int at = pq.top().second; pq.pop();
		if (cd > d[at]) continue;
		for (int x = ghead[at]; x != -1; x = gnxt[x]) {
			int to = gto[x]; ll nd = cd + glen[x >> 1];
			if (nd < d[to]) d[to] = nd, ways[to] = ways[at], pq.push(MP(-d[to], to));
			else if (nd == d[to]) ways[to] = (ways[to] + ways[at]) % MOD;
		}
	}
	REP(i, n) assert(d[i] != LLONG_MAX);
}

void run() {
	scanf("%d%d%d%d", &n, &m, &s, &t); --s, --t;
	REP(i, n) ghead[i] = -1;
	REP(i, m) {
		int a, b; scanf("%d%d%d", &a, &b, &glen[i]); --a, --b;
		gnxt[2 * i + 0] = ghead[a], ghead[a] = 2 * i + 0, gto[2 * i + 0] = b;
		gnxt[2 * i + 1] = ghead[b], ghead[b] = 2 * i + 1, gto[2 * i + 1] = a;
	}

	dcalc(ds, wayss, s), dcalc(dt, wayst, t);
	//REP(i, n) printf("%d: ds=%lld wayss=%d dt=%lld wayst=%d\n", i + 1, ds[i], wayss[i], dt[i], wayst[i]);
	ll dtot = ds[t]; int waystot = wayss[t];
	int ret = 0;
	REP(i, n) {
		if (ds[i] + dt[i] != dtot || ds[i] != dt[i]) continue;
		//printf("at node %d: %lld\n", i + 1, (dtot + MOD - (ll)wayss[i] * wayst[i] % MOD) % MOD);
		int cnt1 = (ll)wayss[i] * wayst[i] % MOD;
		int cnt2 = (waystot + MOD - cnt1) % MOD;
		ret = (ret + (ll)cnt1*cnt2) % MOD;
	}
	REP(x, 2*m) {
		int a = gto[x ^ 1], b = gto[x];
		if (ds[a] + glen[x >> 1] + dt[b] != dtot || 2 * ds[a] >= dtot || 2 * dt[b] >= dtot) continue;
		//printf("at edge %d->%d: %lld\n", a + 1, b + 1, (dtot + MOD - (ll)wayss[a] * wayst[b] % MOD) % MOD);
		int cnt1 = (ll)wayss[a] * wayst[b] % MOD;
		int cnt2 = (waystot + MOD - cnt1) % MOD;
		ret = (ret + (ll)cnt1*cnt2) % MOD;
	}
	printf("%d\n", ret);
}

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


Measured memory_bytes: 10452
n,m=map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in range(m):
  b,c=map(int,input().split())
  l.append([c,b])
for i in range(n):
  l.append([a[i],1])
l.sort(reverse=True)
ans,cnt=0,0
for i in range(n):
  if cnt+l[i][1]>=n:
    ans+=(n-cnt)*l[i][0]
    break
  else:
    ans+=l[i][0]*l[i][1]
    cnt+=l[i][1]
print(ans)

Measured memory_bytes: 34608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n,m;cin >> n >> m;
    vector<int> a(n,-1);
    vector<int> s(m),c(m);
    for(int i=0;i<m;i++){
        cin >> s[i] >> c[i];
        s[i]--;
    }
    bool ans=true;
    for(int i=0;i<m;i++){
        if(a[s[i]]==-1) a[s[i]]=c[i];
        else{
            if(a[s[i]]!=c[i]) ans=false;
        }
    }
    if(a[0]==0&&a.size()>1) ans=false;
    if(!ans){
        cout << -1 << endl;
        return 0;
    }
    if(a[0]==-1&&a.size()>1) a[0]=1;
    for(int i=0;i<n;i++){
        if(a[i]==-1) a[i]=0;
    }
    for(int i=0;i<n;i++) cout << a[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int N = 2003, K = 10004;
int n, k;
string s[N];
bitset<K> dq[N];

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> s[i];

    dq[n] = 1;
    for (int i = n - 1; i >= 0; --i)
        dq[i] = dq[i + 1] | (dq[i + 1] << (int)s[i].size());

    vector<pii> a;
    for (int i = 0; i < n; ++i)
        if (dq[i + 1][k - (int)s[i].size()])
            a.emplace_back(i, 0);
    for (int p = 0; p < k; ++p)
    {
        if (a.size() > k) a.resize(k);
        char min_ch = 'z';
        for (auto &el : a)
        {
            int i = el.fi;
            int j = el.se;
            chkmin(min_ch, s[i][j]);
        }
        cout << min_ch;
        vector<pii> b;
        int min_pos = n;
        for (auto &el : a)
        {
            int i = el.fi;
            int j = el.se;
            if (s[i][j] == min_ch)
            {
                if (j + 1 == s[i].size())
                    chkmin(min_pos, i + 1);
                else
                    b.emplace_back(i, j + 1);
            }
        }
        for (int i = min_pos; i < n; ++i)
        {
            int rest = k - p - 1 - (int)s[i].size();
            if (rest >= 0 && dq[i + 1][rest])
                b.emplace_back(i, 0);
        }
        swap(a, b);
    }
    
    return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define lint long long int
using namespace std;

int main() {
	lint n=0;
	lint ans=0;
	cin>>n;
	vector<lint> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	if(n%2==1)
	{
		cout<<"0"<<endl;
	}
	sort(v.begin(),v.end());
	ans=v[n/2]-v[n/2-1];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
n = int(input())


from itertools import product
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

def dfs(ans, i):
    if len(ans) == n:
        print("".join(ans))
        return
    for j in range(i+1):
        dfs(ans+ascii_lowercase[j], max(j+1, i))

dfs("", 0)

Measured memory_bytes: 57564
N = int(input())
ret = 0
# L,Rを総当たりしたときの頂点数の総和
for i in range(N):
    ret += (i+1) * (N-i)
for _ in range(N-1):
    # 辺が1つ有効になるごに、連結成分が1つ減る
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if x > y:
        x, y = y, x
    ret -= (x+1) * (N-y)

print(ret)

Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

vector<int> g[100010];
int used[100010];

bool dfs(int now,int col){
    used[now]=col;
    for(auto nex:g[now]){
        if(used[nex]==0){
            if(dfs(nex,-col)==false) return false;
        }else if(used[nex]==used[now]) return false;
    }
    return true;
}

class DisjointSet{
public:
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    sz.resize(size,0);
    for(int i=0;i<size;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
 
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      sz[x]+=sz[y];
    }else{
      p[x]=y;
      sz[y]+=sz[x];
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }
 
  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
 
  int findSize(int x){
    return sz[findSet(x)];
  }
};

int main(){
  ll N,M;
  cin>>N>>M;

  DisjointSet us(N+1);
  rep(i,M){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(b);
      g[b].push_back(a);
      if(us.same(a,b));
      else us.unite(a,b);
  }

  ll ais=0;
  for(int i=0;i<N;i++) if(g[i].size()==0) ais++;

  ll com=0;
  ll ans=0;
  ll two=0;
  for(int i=0;i<N;i++){
      if(g[i].size()==0) continue;
      if(us.findSet(i)==i){
          com++;
          if(dfs(i,1)){
              ans+=2;
              two++;
          }else ans++;
      }
  }

  ans+=2*(two*(two-1));
  ans+=2*two*(com-two);
  ans+=(com-two)*(com-two-1);
  ans+=(N*N-(N-ais)*(N-ais));
  cout<<ans<<endl;



  return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << (1000 - N % 1000) % 1000 << endl;

    return 0;
}


Measured memory_bytes: 3648
def mDistance(a, b):
    axisDist = [abs(x0 - x1) for x0, x1 in zip(a, b)]
    return(sum(axisDist))


N, M = map(int, input().split())
An, Am = ([], [])

while len(An) < N:
    An.append(tuple(map(int, input().split())))

while len(Am) < M:
    Am.append(tuple(map(int, input().split())))

for a in An:
    B = map(lambda b: mDistance(a, b), Am)
    I, _ = min(enumerate(list(B)), key=lambda b: b[1])
    print(I + 1)


Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int K, S;
    int ans = 0;
    scanf("%d%d",&K,&S);
    for(int i=0;i<=K&&i<=S;i++){
        for(int j=0;j<=K&&j+i<=S;j++){
            if(S-i-j<=K)
                ans++;

        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
# ABC126D - Even Relation
def dfs(r: int) -> None:
    stack = [r]
    while stack:
        v = stack.pop()
        for u, w in T[v]:
            if D[u] == -1:
                D[u] = (D[v] + w) % 2
                stack.append(u)


def main():
    # same parity of distance from root <-> same group
    global T, D
    N, *A = map(int, open(0).read().split())
    T = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 3, 3):
        v, u, w = A[i : i + 3]
        T[v].append((u, w))
        T[u].append((v, w))
    D = [-1] * (N + 1)  # D[i] := parity of distance from vertex 1 (root)
    D[1] = 0
    dfs(1)
    print(*D[1:], sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 42732
import copy
import fractions
a, b = map(int, input().split())

temp = fractions.gcd(a, b)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

d = make_divisors(temp)
d.sort()

for ele in d:
    if ele==1:
        continue
    d = [e for e in d if e%ele!=0 or ele==e] 

print(len(d))

Measured memory_bytes: 5272
#include<iostream>
#include<cstring>
using namespace std;
int n,s;
long long int dp[1<<11][10][250];

long long int check(int bit,int now,int sum)
{
  //cout<<bit<<" "<<now<<" "<<sum<<endl;
  if(s==sum && n==now)
    {
      //   cout<<bit<<" "<<now<<" "<<sum<<endl;      
      return 1;
    }
  if(n<now)
    return 0;
  if(s<=sum)
    {
      if ((bit&1)==0)
	return check(bit|1,now+1,sum);
      else
	return 0; 
    }
  if(dp[bit][now][sum]!=-1)
    return dp[bit][now][sum];
  long long int ans=0;
  for(int i=0;i<10;i++)
    {
      if((bit & (1<<i))==0)
	ans+=check(bit|(1<<i),now+1,sum+(i*(now+1)));      
    }
  dp[bit][now][sum]=ans;
  return ans; 
}

int main()
{
  
  //  cout<<(1<<1 | 1<<2)<<endl;
  for(;cin>>n>>s;)
    {
      memset(dp,-1,sizeof(dp));
      cout<<check(0,0,0)<<endl;
    }
}

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

#define fmm(x) cerr << "[!] " << #x << " e " << x << "\n";
using ll = long long;

using namespace std;

const int MAX = 100005;

int main(){
  // ENGAGE MODUL RACHETĂ ᕦ(ò_ó)ᕤ
  ios::sync_with_stdio(false);
  cin.tie(0);

  #ifdef ACAS_LA_SEFU
//  freopen("valoare.in", "r", stdin);
  #endif

  ll n, k; cin >> n >> k;
  n = n%k;
  ll minn = n;
  while(1){
    if (abs(n-k)!=minn){
      minn = min(abs(n-k), minn);
      n = abs(n-k);
    } else break;
  }
  cout << minn;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(void)
{
    int A, B, C;
    cin >> A;
    if (A == 1)
    {
        cout << "Hello World";
    }
    else
    {
        cin >> B >> C;
        cout << B + C;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect, bisect_left
import heapq

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    A.sort()
    S = [0] * (N + 1)
    for i, a in enumerate(A): S[i + 1] = a + S[i]
 
    l, h = 1, A[N-1] * 2 + 1
    while h - l > 1: #最小値がｍ以上の要素をM個用意できるか
        m = (h + l) // 2
        count = 0
        for i, a in enumerate(A): count += N - bisect_left(A, m - a)
        if count >= M: 
            l = m
        else: h = m

    total = 0
    count = 0
    Q = []
    heapq.heapify(Q)
    min_out = 10000000
    for i, a in enumerate(A):
        j = bisect_left(A, l - a)  
        total += a * (N - j) + (S[N] - S[j])
        count += N - j
        if 0 <= j < N: min_out = min(min_out, a + A[j])

    if count > M:
        total -= min_out * (count - M)

    print(total)

    return 0

if __name__ == "__main__":
    solve()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int n;
    cin>>n;
    int mi=1000,ma=0;
    REP(i,n){
        int a;
        cin>>a;
        chmin(mi,a);
        chmax(ma,a);
    }
    cout<<ma-mi<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define datamax 100001
typedef struct{
  char name[11];
  int time;
}PROCESS;
PROCESS queue[datamax];
void inqueue(PROCESS);
PROCESS dequeue(void);
int min(int,int);
int head,tail;
int main(){
  int n,q,ans=0,i;
  PROCESS temp;
  int calc;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",queue[i].name,&queue[i].time);
  }
  head = 0; tail=n;
  while(head != tail){
    temp = dequeue();
    calc = min(temp.time,q);
    ans += calc;
    temp.time = temp.time - calc;
    if(temp.time > 0)inqueue(temp);
    else{
      printf("%s %d\n",temp.name,ans);
    }
  }

  return 0;
}
  
int min(int a,int b){
  if(a < b)return a;
  else return b;
}

void inqueue(PROCESS x){
  queue[tail] = x;
  tail = (tail + 1) % datamax;
}

PROCESS dequeue(){
  PROCESS temp;
  temp = queue[head];
  head = (head +1) % datamax;
  return temp;
}



Measured memory_bytes: 3324
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
using namespace std;
typedef long long ll;


int main()
{
	ll n, sum = 0;
	cin >> n;
	vector<ll>a,b(n-1);
	rep(i, n - 1)cin >> b[i];
	a.push_back(b[0]);
		for (ll i = 1; i <= n - 2; i++) {
			a.push_back(min(b[i - 1], b[i]));
		}
	cout << accumulate(a.begin(),a.end(),0) + b[n - 2] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <bitset>
#define ll long long
#define rep(x,n) for(ll (x)=0;(x)<n;(x)++)
#define rep1(x,n) for(ll (x)=1;(x)<=n;(x)++)
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
using namespace std;

const int N=200005;
int pa1[N],pa2[N],ans[N];
map<pair<int,int>,int>cnt;

int fpa1(int x)
{
    return pa1[x]==x?x:pa1[x]=fpa1(pa1[x]);
}

int fpa2(int x)
{
    return pa2[x]==x?x:pa2[x]=fpa2(pa2[x]);
}

int main()
{
    #ifdef LOCAL
        //freopen("C_data.txt","r",stdin);
    #endif // LOCAL
    int n,k,l,a,b;
    scanf("%d%d%d",&n,&k,&l);
    rep1(i,n) pa1[i]=pa2[i]=i;
    while(k--)
    {
        scanf("%d%d",&a,&b);
        pa1[fpa1(a)]=fpa1(b);
    }
    while(l--)
    {
        scanf("%d%d",&a,&b);
        pa2[fpa2(a)]=fpa2(b);
    }
    rep1(i,n) cnt[make_pair(fpa1(i),fpa2(i))]++;
    rep1(i,n) ans[i]=cnt[make_pair(fpa1(i),fpa2(i))];
    rep1(i,n) printf("%d ",ans[i]);
    printf("\n");
}


Measured memory_bytes: 14336