akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0; i<n; i++)
#define forp(i,a,b) for(int i=a;i<b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100001;
int spf[MAXN];
int gcd(int x, int y){ return y?gcd(y,x%y):x; }

void precal(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t=1;
    // cin>>t;
    while(t--){
        cin>>n;
        arrin(a,n);
        int ans=0;
        rep(i,n){
            if(i%2==0 && a[i]&1) ans++;
        }
        cout<<ans<<nl;
    }
    return 0;
}

Measured memory_bytes: 3180
//                        Bismillahir Rahmanir Rahim
//ALGO:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000000000
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;
int l1, l2, dp[3010][3010];
string x, y;
int lcs(int i, int j){
    if(i==l1||j==l2) return 0;
    if(~dp[i][j]) return dp[i][j];
    if(x[i]==y[j]) return dp[i][j]=1+lcs(i+1, j+1);
    return dp[i][j]=max(lcs(i+1, j), lcs(i, j+1));
}
void print(int i, int j){
    if(i==l1||j==l2) return;
    if(x[i]==y[j]){
        cout<<x[i];
        print(i+1, j+1);
        return;
    }
    if(dp[i+1][j]>dp[i][j+1]) print(i+1, j);
    else print(i, j+1);
}
int main()
{
    cin>>x>>y;
    l1=x.size(), l2=y.size();
    FILL(dp, -1);
    lcs(0, 0);
    print(0, 0);
}

Measured memory_bytes: 35968
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
#define Mxn 3001

ll n;
ll arr[Mxn];


bool taro(ll rem)
{
	if(n%2 == 0 && rem%2 == 0)
		return true;
		
	if(n%2 != 0 && rem%2 != 0)
		return true;
		
	return false;
}

ll solve(ll start,ll end)
{

	ll rem = end - start + 1;
	
	if(start == end)
	{
		if(taro(rem))
			return arr[start];
		else
			return -arr[start];
	}
		
	
	if(taro(rem))
	{
		return max(arr[start] + solve(start+1,end),arr[end] + solve(start,end-1));
	}
	else
	{
		return min(solve(start+1,end) - arr[start],solve(start,end-1) - arr[end]);
	}
	
	
}

ll dpsolve()
{
	ll dp[n][n];
	
	for(ll k=1;k<=n;k++)
	{
		for(ll i=0;i<=n-k;i++)
		{
			ll j = i + k - 1;
			ll rem = j - i + 1;
			if(i == j)
			{
				if(taro(rem))
					dp[i][j] = arr[i];
				else
					dp[i][j] = -arr[i];
			}
			else
			{
				if(taro(rem))
					dp[i][j] = max(arr[i] + dp[i+1][j],arr[j] + dp[i][j-1]);
				else
					dp[i][j] = min(dp[i+1][j] - arr[i],dp[i][j-1] - arr[j]);
			}
		}
	}
	return dp[0][n-1];
}
					




int main()
{
    fastio;
    cin>>n;
    loop(n)
		cin>>arr[i];
	
	ll ans = dpsolve();
	cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n; cin >> n;
	
	int arr[n];
	int sum = 0;
	
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
	}
	
	int m; cin >> m;
	
	int idx,val;
	while(m--) {
		cin >> idx >> val;
		cout << sum + val - arr[idx-1] << '\n';
	}
		
	return 0;
}

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

using namespace std;

int main(){

	int A, B, C;
	int five=0, seven=0;

	cin>>A>>B>>C;

	if(A==5)five++;
	else if(A==7)seven++;

	if(B==5)five++;
	else if(B==7)seven++;

	if(C==5)five++;
	else if(C==7)seven++;

	if(five==2 && seven==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    bool flag = true;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        if(a&1)flag = !flag;
    }

    cout << (flag ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

// repetition
// ----------------------------------------------------------------------------
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGNUM(x) printf("%d\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORNUM(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPNUM(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    int i, j;
    int num;
    int side_num;
    int a, b;

    scanf("%d", &num);

    int list[num];

    scanf("%d", &side_num);

    for (i = 0,j = 1; i < num; ++i, ++j){
        list[i] = j;
    }

    for (i = 0;i < side_num; ++i){
        scanf("%d, %d", &a, &b);

        list[a - 1] ^= list[b - 1];
        list[b - 1] ^= list[a - 1];
        list[a - 1] ^= list[b - 1];
    }

    for (i = 0;i < num; ++i){
        printf("%d\n", list[i]);
    }

    return 0;
}

Measured memory_bytes: 0
from collections import deque

X,Y,A,B,C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
apples = []
for i in range(A):
    apples.append([p[i],0])
for i in range(B):
    apples.append([q[i],1])
for i in range(C):
    apples.append([r[i],2])
apples.sort()
apples = deque(apples)

apples_number = 0
L = X+Y
ans = 0
while apples_number < L:
    apple = apples.pop()
    if apple[1] == 0 and X > 0:
        ans += apple[0]
        X -= 1
        apples_number += 1
    if apple[1] == 1 and Y > 0:
        ans += apple[0]
        Y -= 1
        apples_number += 1
    if apple[1] == 2:
        ans += apple[0]
        apples_number += 1

print(ans)

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

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


Measured memory_bytes: 256
// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define all( x ) x.begin() , x.end()
#define pb push_back
#define mp make_pair

const int maxn = 1e5 + 10 ;
const int mod = 998244353 ;
const int INF = 1e18 ;

int n , ans = 0 ;
vector< int > vv , vv2 ;

signed main()
{
 ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

 cin >> n ;
 int nn = n ;
 for(int i = 2 ; i <= sqrt( n ) ; i ++){

   if( nn%i != 0 )
    continue;

   int x = 0 ;
   while( nn%i == 0 ){
    x ++ ;
    nn /= i ;
   }

   vv.pb( x ) ;
 }

 if( nn > 1 )
  vv.pb( 1 ) ;

 for(int i = 1 ;i <= sqrt( n ) ; i ++){
  vv2.pb( (i*(i+1))/2 );
 }

 for( auto x : vv ){
   int ind = upper_bound( all( vv2 ) , x ) - vv2.begin() ;
   ans += ind ;
 }

 cout << ans ;

    return 0;
}


Measured memory_bytes: 11600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc144/tasks/abc144_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 はい
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B; cin >> A >> B;
    if(A >= 10) return -1;
    if(B >= 10) return -1;
    res = A*B;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())

dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)

Q = int(input())
for _ in [0]*Q:
    t, *q = input().split()
    if t == '1':
        i, c = q
        i = int(i)-1

        s = S[i]
        if s == c:
            continue
        S[i] = c
        dic[s].pop(bisect_left(dic[s], i))
        insort_left(dic[c], i)

    else:
        l, r = map(int, q)
        l -= 1
        r -= 1
        cnt = 0
        for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
        print(cnt)


Measured memory_bytes: 128064
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

vector<long long int> x;
vector<long long int> y;
vector<long long int> z;

int numofbits(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

long long int func(int N, int M,int fx, int fy, int fz){
	long long int ans=0;
	vector<long long int> tx(N),ty(N),tz(N);
	vector<long long int> list(N);
	for(int i=0;i<N;i++){
		tx[i]=fx*x[i];
		ty[i]=fy*y[i];
		tz[i]=fz*z[i];
		list[i]=tx[i]+ty[i]+tz[i];
	}
	
	sort(list.begin(),list.end());
	for(int i=0;i<M;i++){
		ans+=list[N-i-1];
	}
	return ans;
}

int main(){
	int N,M;
	cin>>N>>M;
	long long int ans=0;
	x.resize(N);
	y.resize(N);
	z.resize(N);
	for(int i=0; i<N;i++){
		cin>>x[i]>>y[i]>>z[i];
	}
	
	ans=max(ans,func(N,M,1,1,1));
	ans=max(ans,func(N,M,-1,1,1));
	ans=max(ans,func(N,M,1,-1,1));
	ans=max(ans,func(N,M,-1,-1,1));
	ans=max(ans,func(N,M,1,1,-1));
	ans=max(ans,func(N,M,-1,1,-1));
	ans=max(ans,func(N,M,1,-1,-1));
	ans=max(ans,func(N,M,-1,-1,-1));	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define debug(var) cout << #var << ": " << var << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = 1e6 + 5;

array<int, N> gpd;
void Eratosthenes_sieve(int n) {
    for (int i = 2; i < n; i++)
        if (!gpd[i])
            for (int j = i; j < n; j += i)
                gpd[j] = i;
}

int flag_pairwise;
unordered_set<int> used_prime;
void prime_factorize(ll x) {
    while (x > 1) {
        int p = gpd[x];
        int cnt = 0;
        while (x % p == 0)
            x /= p, cnt++;
        // store or process with p, cnt...
        if (used_prime.find(p) != used_prime.end())
            flag_pairwise = 0;
        used_prime.insert(p);
    }
}

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

    Eratosthenes_sieve(N);

    int n;
    cin >> n;

    int gcd_sum;
    flag_pairwise = 1;
    set<int> used_prime;
    for (int i = 0; i < n; i++) {
        int e;
        cin >> e;
        prime_factorize(e);
        gcd_sum = i == 0 ? e : __gcd(gcd_sum, e);
    }
    cout << (flag_pairwise ? "pairwise coprime"
                           : gcd_sum == 1 ? "setwise coprime" : "not coprime");
}

Measured memory_bytes: 10572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,n,i,j,k=0;
  cin>>a>>b>>c>>n;
  ll x[n],y[n],z[n];
  for(i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i],k+=(x[i]==0)+(x[i]==a-1)+(y[i]==0)+(y[i]==b-1)+(z[i]==0)+(z[i]==c-1);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      k+=((abs(x[i]-x[j])+abs(y[i]-y[j])+abs(z[i]-z[j]))==1);
  cout << 2*(a*b+b*c+c*a)+6*n-k*2 << endl;
  return 0;
}

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

public class Hello
{
    public static void Main()
    {
        hoge();
    }

    public static void hoge()
    {
        var line = System.Console.ReadLine().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var k = int.Parse(line[2]);

        UnionFind uf = new UnionFind(n);

        int[] fnum = new int[n];

        for (int input_i = 0; input_i < m; input_i++)
        {
            line = System.Console.ReadLine().Split(' ');
            var one = int.Parse(line[0]) - 1;
            var two = int.Parse(line[1]) - 1;
            fnum[one] += 1;
            fnum[two] += 1;
            uf.Union(one, two);
        }

        List<int> ans = Enumerable.Range(0, n).Select(x => uf.Size(x) - 1 - fnum[x]).ToList();

        for (
            int input_i = 0; input_i < k; input_i++)
        {
            line = System.Console.ReadLine().Split(' ');
            var one = int.Parse(line[0]) - 1;
            var two = int.Parse(line[1]) - 1;
            if(uf.Same(one, two))
            {
                ans[one] -= 1;
                ans[two] -= 1;
            }
        }

        System.Console.WriteLine(string.Join(" ", ans));

    }

    class UnionFind
    {
        // 親要素のインデックスを保持する
        // 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
        public int[] Parents { get; set; }
        public UnionFind(int n)
        {
            this.Parents = new int[n];
            for (int i = 0; i < n; i++)
            {
                // 初期状態ではそれぞれが別のグループ(ルートは自分自身)
                // ルートなのでマイナスで要素数(1個)を保持する
                this.Parents[i] = -1;
            }
        }

        // 要素xのルート要素はどれか
        public int Find(int x)
        {
            // 親がマイナスの場合は自分自身がルート
            if (this.Parents[x] < 0) return x;
            // ルートが見つかるまで再帰的に探す
            // 見つかったルートにつなぎかえる
            this.Parents[x] = Find(this.Parents[x]);
            return this.Parents[x];
        }

        // 要素xの属するグループの要素数を取得する
        public int Size(int x)
        {
            // ルート要素を取得して、サイズを取得して返す
            return -this.Parents[this.Find(x)];
        }

        // 要素x, yが同じグループかどうか判定する
        public bool Same(int x, int y)
        {
            return this.Find(x) == this.Find(y);
        }

        // 要素x, yが属するグループを同じグループにまとめる
        public bool Union(int x, int y)
        {
            // x, y のルート
            x = this.Find(x);
            y = this.Find(y);
            // すでに同じグループの場合処理しない
            if (x == y) return false;

            // 要素数が少ないグループを多いほうに書き換えたい
            if (this.Size(x) < this.Size(y))
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            // まとめる先のグループの要素数を更新
            this.Parents[x] += this.Parents[y];
            // まとめられるグループのルートの親を書き換え
            this.Parents[y] = x;
            return true;
        }
    }
}


Measured memory_bytes: 21436
#include<stdio.h>
#define N 2000000
#define M 8
int tum[N];
int size;

void sum(int tum[], int i) {
    int a = 2 * i + 1;
    int b = 2 * i + 2;
    int xu;

    if (a <= size && tum[a] > tum[i]) {
        xu = a;
    } else {
        xu = i;
    }
    if (b <= size && tum[b] > tum[xu]) {
        xu = b;
    }

    if (xu != i) {
        int tmp = tum[i];
        tum[i] = tum[xu];
        tum[xu] = tmp;
        sum(tum, xu);
    }
}

void fan(int k){
    int bro = size;
    int gra = (bro - 1) / 2;

    tum[size] = k;

    while(1){
        if(tum[gra] > tum[bro] || bro == 0)
            break;
        int tmp = tum[bro];
        tum[bro] = tum[gra];
        tum[gra] = tmp;

        bro = gra;
        gra = (bro - 1) / 2;
    }

    size++;
}

int zin(){
    int ret = tum[0];
    tum[0] = tum[size-1];
    size--;
    sum(tum, 0);
    return ret;
}

int main(){
    char gum[M];
    int k;

    while(1) {
        scanf("%s",gum);
        if(gum[0] == 'i'){
            scanf("%d", &k);
            fan(k);
        }else if(gum[1] == 'x'){
            printf("%d\n",zin());
        }else{
            return 0;
        }
    }
}



Measured memory_bytes: 5632
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	char S[1002];
	scanf("%s", S);

	int f[4] = { 0,0,0,0 };
	for (int i = 0; i < strlen(S); i++) {
		if (S[i] == 'E') {
			f[0]++;
		}
		if (S[i] == 'W') {
			f[1]++;
		}
		if (S[i] == 'S') {
			f[2]++;
		}
		if (S[i] == 'N') {
			f[3]++;
		}
	}
	bool ok1 = true, ok2 = true;
	if (f[0] > 0) {
		if (f[1] <= 0) {
			ok1 = false;
		}
	}
	if (f[1] > 0) {
		if (f[0] <= 0) {
			ok1 = false;
		}
	}
	if (f[2] > 0) {
		if (f[3] <= 0) {
			ok2 = false;
		}
	}
	if (f[3] > 0) {
		if (f[2] <= 0) {
			ok2 = false;
		}
	}
	if (ok1 == true && ok2 == true) {
		puts("Yes");
	}
	else {
		puts("No");
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
# -- coding: utf-8 --
a, b = map(int, input().split(' '))
count = 0
for first in range(10):
    for second in range(10):
        for third in range(10):
            loop_num = first * 10001 + second * 1010 + third * 100
            if a <= loop_num <= b:
                count += 1
print(count)

Measured memory_bytes: 3316
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
#print(lis)
price=0
i=0
while m>0:
    price+=lis[i][0]*min(m,lis[i][1])
    m-=min(m,lis[i][1])
    #print(price)
    i+=1
print(price)
    
    

    
            
        
        
    
    
    
    

    
    


    
    

        
        
    


    

Measured memory_bytes: 88512
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

struct Task{
  string name;
  int time;
};
int main(){

  long ii,jj,kk;
  vector<Task> t;
  int n,q,totalTime;
  cin >> n >> q;
  t.resize(n);
  queue<Task> que,que2;
  
  for(ii=0;ii<n;ii++){
    cin >> t[ii].name >> t[ii].time;
    que.push(t[ii]);

    //cout << "ii:" << ii << endl;
    
  }
  
  totalTime = 0;
  Task tmp;
  while(!que.empty()){
    tmp = que.front();
    que.pop();

    //cout << tmp.name << " " << tmp.time << endl;
    
    if((tmp.time -q) > 0){
      totalTime += q;
      tmp.time -=q;
      que.push(tmp);
    }
    else{
      totalTime += tmp.time;
      tmp.time = totalTime;
      que2.push(tmp);
    }
    //cout << "totalTime:" << totalTime << endl;
  }
  while(!que2.empty()){
    tmp = que2.front();
    que2.pop();
    cout << tmp.name << " " << tmp.time << endl;
  }
  return 0;
}



Measured memory_bytes: 6884
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int V,E;
vi g[100010];
ll size;
map<int,int> M;
int dp[100010];

int color[100010];

pi dfs(int v,int c){
	pi res;
	if(c==1)res.fir=1;
	else res.sec=1;
	color[v]=c;
	rep(i,sz(g[v])){
		if(color[g[v][i]]==c)return mp(-1,-1);
		if(!color[g[v][i]]){
			pi res2=dfs(g[v][i],-c);
			if(res2.fir==-1)return mp(-1,-1);
			res.fir+=res2.fir;
			res.sec+=res2.sec;
		}
	}
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>V>>E;
	rep(i,E){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	
	rep(i,V)if(!color[i]){
		pi res=dfs(i,1);
		if(res.fir==-1){
			cout<<"-1"<<endl;
			return 0;
		}
		if(res.fir>res.sec)swap(res.fir,res.sec);
		size+=res.fir;
		M[res.sec-res.fir]++;
	}
	int m=V/2-size;
	fill(dp,dp+m+1,-1);
	dp[0]=0;
	foreach(it,M){
		rep(i,m+1){
			if(dp[i]>=0){
				dp[i]=it->sec;
			}else if(i < it->fir || dp[i - it->fir] <= 0){
				dp[i]=-1;
			}else{
				dp[i]=dp[i - it->fir]-1;
			}
		}
	}
	for(int i=m;i>=0;i--)if(dp[i]>=0){
		size+=i;
		cout<<size*(V-size)-E<<endl;
		return 0;
	}
}

Measured memory_bytes: 7872
#include <iostream> 
#include <cmath>
#include <cstring> 
#include <cstdio> 
#include <algorithm>
using namespace std;
int x,a,b;
int main(){
	cin>>x>>a>>b;
	if(x>a&&a>b){
		cout<<"A"<<endl;
	} 
	else if(x>b&&b>a){
		cout<<"B"<<endl;
	}
	else if(a>b&&b>x){
		cout<<"B"<<endl;
	}
	else if(b>a&&a>x){
		cout<<"A"<<endl;
	}
	else if(a>x&&x>b){
		int c=a-x,d=x-b;
		if(c>d){
			cout<<"B"<<endl;
		}
		else{
			cout<<"A"<<endl;
		}
	}
	else if(b>x&&x>a){
		int e=b-x,f=x-a;
		if(e>f){
			cout<<"A"<<endl;
		}
		else{
			cout<<"B"<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main() {
  int n,a,ans=0;
  cin >> n;
  map<int,int> mp;
  for(int i=0; i<n; i++) {
    cin >> a;
    mp[a]++;
  }
  for(auto au:mp) {
    if(au.first<au.second) {
      ans+=au.second-au.first;
    }
    else if(au.first>au.second) {
      ans+=au.second;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4736
import math
while 1:
        n=input()
        if n==0:
                break
        s=map(int,raw_input().split())
        m=0.0
        for i in range(n):
                m+=s[i]
        m=m/n
        a=0.0
        for i in range(n):
                a+=(s[i]-m)**2
        a=(a/n)**0.5
        print a

Measured memory_bytes: 4480
package main

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

func main() {
	N := nextInt()
	power := 1
	max := int(math.Pow10(9)) + 7
	for i := 1; i <= N; i++ {
		power = power * i % max
	}

	fmt.Println(power)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

	return i
}

// ---------- Input.

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e5+5;
map<int,int>mp[N];
set<int>e[N];
queue<pair<int,int> >que;
int fa[N],n;
int getfather(int &p){
	return p=fa[p]==p?p:getfather(fa[p]);
}
int main(){
	scanf("%d",&n);
	rep(i,1,2*(n-1)){
		int u,v;
		scanf("%d%d",&u,&v);
		mp[u][v]++;mp[v][u]++;
		e[u].insert(v);e[v].insert(u);
		if(mp[u][v]==2) que.push(make_pair(u,v));
	}
	rep(i,1,n) fa[i]=i;
	while(!que.empty()){
		int u=que.front().first,v=que.front().second;
		getfather(u);getfather(v);
		que.pop(); e[u].erase(v); e[v].erase(u);
		mp[u][v]--;mp[v][u]--;
		if(e[u].size()<e[v].size()) swap(u,v);
		for(set<int>::iterator it=e[v].begin();it!=e[v].end();it++){
			int t=*it;
			e[t].erase(v);e[t].insert(u);e[u].insert(t);
			mp[v][t]=mp[t][v]=0;
			mp[u][t]++;mp[t][u]++;
			if(mp[u][t]==2) que.push(make_pair(u,t));
		}
		fa[v]=u;e[v].clear();
	}
	int res=0;
	rep(i,1,n) res+=fa[i]==i;
	puts(res==1?"YES":"NO");
	return 0;
}


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

int main()
{
    long long a[10], i,j,temp;
    for(i=0;i<10;i++){
        scanf("%lld",&a[i]);
    }
    for(i=0; i<10; i++){
        for(j=0; j<10-(i+1); j++){
                if(a[j] < a[j+1]){
                    temp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                }
        }
    }
    for(i = 0; i < 3; i++)
        printf("%d\n",a[i]);

        return 0;

}

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

class Solve {
private:

public:
	bool is_last_query{};
	Solve()
	{
		int N, M;
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0)
		{
			is_last_query = true;
			return;
		}

		std::vector<std::pair<int, int>> min_points(N), max_points(N);
		for (int i{}; i < N; i++)
			min_points[i].second = max_points[i].second = i;
		for (int i{}; i < M; i++)
		{
			int S, k;
			scanf("%d%d", &S, &k);
			if (k == 1)
			{
				int c;
				scanf("%d", &c);
				c--;
				min_points[c].first += S;
				max_points[c].first += S;
			}
			else
			{
				for (int j{}; j < k; j++)
				{
					int c;
					scanf("%d", &c);
					c--;
					max_points[c].first += S;
				}
			}
		}
		std::sort(min_points.begin(), min_points.end());
		std::sort(max_points.begin(), max_points.end());
		int max{};
		if (min_points.front().second != max_points.back().second)
			max = max_points.back().first - min_points.front().first;
		else
			max = std::max(max_points[N - 2].first - min_points[0].first, max_points[N - 1].first - min_points[1].first);
		
		printf("%d\n", max + 1);
		return;
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3364
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct _node_table {
    int* next_node;
    int* cost;
    int size;
    int capacity;
} node_table[100005];

int dp[100005];

void init_node(int i) {
    node_table[i].capacity = 10;
    node_table[i].next_node = (int*)malloc(node_table[i].capacity*sizeof(int));
    node_table[i].cost = (int*)malloc(node_table[i].capacity*sizeof(int));
    node_table[i].size = 0;
}

void free_node(int i) {
    free(node_table[i].next_node);
    free(node_table[i].cost);
}

void grow_node(int s) {
    if(node_table[s].capacity < node_table[s].size+2) {
        int size, i;
        int* next_node = node_table[s].next_node;
        int* cost = node_table[s].cost;
        node_table[s].capacity *= 1.5;
        node_table[s].next_node = (int*)malloc(node_table[s].capacity*sizeof(int));
        node_table[s].cost = (int*)malloc(node_table[s].capacity*sizeof(int));
        for(i=0,size=node_table[s].size;i<size;i++) {
            node_table[s].next_node[i] = next_node[i];
            node_table[s].cost[i] = cost[i];
        }
        free(next_node);
        free(cost);
    }
}

void add_next_node(int s, int t, int d) {
    int size = node_table[s].size;
    node_table[s].next_node[size] = t;
    node_table[s].cost[size] = d;
    node_table[s].size++;

    grow_node(s);
}

void solve(int r, int V) {
    int i, size, from, to, cost;
    int queue[SHRT_MAX];
    int wp, rp;

	dp[0] = 0;
    for(i=1;i<V;i++) dp[i] = INT_MAX;

    wp = rp = 0;
    queue[wp++%SHRT_MAX] = r;

    while(wp>rp) {
        from = queue[rp++%SHRT_MAX];

        for(i=0,size=node_table[from].size;i<size;i++) {
            to = node_table[from].next_node[i];
            cost = node_table[from].cost[i];

            if(cost+dp[from] < dp[to]) {
                queue[wp++%SHRT_MAX] = to;
                dp[to] = cost+dp[from];
            }
        }
    }
}

int main(void) {
	int i, n;
    for(i=0;i<100005;i++) init_node(i);

	scanf("%d\n", &n);
    for(i=0;i<n;i++) {
        int j, u, k, v, c;
        scanf("%d %d", &u, &k);
        for(j=0;j<k;j++) {
	        scanf("%d %d", &v, &c);
	        add_next_node(u, v, c);
        }
    }

    solve(0, n);

    for(i=0;i<n;i++) {
        free_node(i);
        if(dp[i] == INT_MAX) {
            printf("INF\n");
        } else {
            printf("%d %d\n", i, dp[i]);
        }
    }

    return 0;
}

Measured memory_bytes: 16468
#include <stdio.h>
int main(void){
	int k,s,x,y,z,ans=0;
	scanf("%d %d",&k,&s);
	for(x=0;x<=k;x++){
		for(y=0;y<=k;y++){
			int tmp=s-x-y;
			if(0<=tmp&&tmp<=k){
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
ABCXY = input().split()
A,B,C,X,Y = int(ABCXY[0]),int(ABCXY[1]),int(ABCXY[2]),int(ABCXY[3]),int(ABCXY[4])
resultA = []
resultB = []
Min = float("inf")
if(X >= Y):
    taisyou = X*2
else:
    taisyou  = Y*2
    
for i in reversed(range(0, taisyou+1, 2)):
    #Xの枚数はX - i/2
    #Yの枚数はY- i/2
    if(X - i/2 <= 0):
        Xcount = 0
    else:
        Xcount = X-i/2
    if(Y - i/2 < 0):
        Ycount = 0
    else:
        Ycount = Y-i/2
    Min =  min(Min, i * C + Xcount* A + Ycount * B)
print(int(Min))

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
import numpy as np
import itertools


def solve(N: int, L: "List[int]"):
    ans = 0
    if len(L)>2:
        for c in itertools.combinations(L,3):
            if len(set(c))==3:
                if (c[0]+c[1]>c[2]) and (c[1]+c[2]>c[0]) and (c[2]+c[0]>c[1]):
                    ans += 1
    else:
        ans = 0
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27156
import java.util.*;
public class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  if (n % 2 == 0) {
   if (n == 0) {
    System.out.println(2);
   } else {
    System.out.println(n);
   }
  } else {
   System.out.println(2*n);
  }
 }
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

class UnionFind {
public:
    // 親の番号を格納する。親だった場合-size
    vector<int> parents;

    UnionFind(int n) {
        parents = vector<int>(n, -1);
    }

    // aがどのグループに属しているか
    int root(int a) {
        if (parents[a] < 0) {
            return a;
        }
        return parents[a] = root(parents[a]);
    }

    int size(int a) {
        return -parents[root(a)];
    }

    // aとbをくっつける
    bool connect(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) {
            return false;
        }
        // 大きいほうにA
        if (size(ra) < size(rb)) {
            swap(ra, rb);
        }
        parents[ra] += parents[rb];
        parents[rb] = ra;
        return true;
    }

    bool is_union(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        return ra == rb;
    }
};


int main() {
    int n, m, k;
    cin >> n >> m >> k;

    UnionFind uf(n);

    vector<vector<int>> friends(n);
    vector<vector<int>> blocks(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.connect(a, b);
        friends[a].push_back(b);
        friends[b].push_back(a);
    }
    rep(i, k) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        blocks[a].push_back(b);
        blocks[b].push_back(a);
    }

    rep(i, n) {

        int suggestions = uf.size(i);
        suggestions--;

        for (int f : friends[i]) {
            if (uf.is_union(i, f)) suggestions--;
        }
        for (int f : blocks[i]) {
            if (uf.is_union(i, f)) suggestions--;
        }

        cout << suggestions << ' ';

    }


}


Measured memory_bytes: 12152
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
int main()
{
	cin >>n;
	cout <<(1000-(n%1000))%1000;
	return 0;
} 

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    int a,b;
    cin >> a >> b;
    if(a==b) cout << " Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;

vector<bool> perm[131075];
int N, A, B;
int len;
vector<bool> getbin(int x){
    vector<bool> buff;
    while(x!=0){
        buff.push_back(x%2);
        x /= 2;
    }
    for (int i=0;i<N-buff.size();i++){
        buff.push_back(0);
    }
    return buff;
}
int getval(vector<bool> buff){
    int t = 1, ret = 0;
    for (int i=0;i<buff.size();i++){
        ret += (int)buff[i] * t;
        t = t << 1;
    }
    return ret;
}

int find(int i, int j, int start){
    for (int k=start;k<N;k++){
        if (perm[i][k]!=perm[j][k]) return k;
    }
    return -1;
}

void fill(int i, int j, int start){
    if (start==N-1) return;
    if (i==j) return;
    if (i>j) return;
    if (start<0 || start>=N){
        cout << -1 << endl;
        exit(0);        
    }
    if (i<0 || i>=len) {
        cout << -1 << endl;
        exit(0);
    }
    if (j<0 || j>=len) {
        cout << -1 << endl;
        exit(0);
    }
    int pos = find(i, j, start);
    if (pos<0 || pos >= N){
        cout << -1 << endl;
        exit(0);
    }

    // cout << "pos: " << pos << endl;
    //swap pos row and start row
    bool temp = perm[i][start];
    perm[i][start] =  perm[i][pos];
    perm[i][pos] = temp;
    temp = perm[j][start];
    perm[j][start] =  perm[j][pos];
    perm[j][pos] = temp;
    // Now first row is different
    int mid = (i+j)/2;
    // cout << "mid: " << mid << endl;
    for(int k=i;k<=mid;k++){
        perm[k][start] = perm[i][start];
    }
    for(int k=j;k>mid;k--){
        perm[k][start] = perm[j][start];   
    }
    // Copy the rest and alter the next leading bit 
    if (start+1<N && mid+1<j){
        for (int k=start+1;k<N;k++){
            perm[mid][k] = perm[i][k];
            perm[mid+1][k] = perm[i][k];
        }
        perm[mid][start+1] = !perm[mid][start+1];
        perm[mid+1][start+1] = !perm[mid+1][start+1];        
    }
    fill(i, mid, start+1);
    fill(mid+1, j, start+1);
    // cout << "CHECK1" << endl;
    // Swap back
    for (int k=i;k<=j;k++){
        temp = perm[k][start];
        perm[k][start] =  perm[k][pos];
        perm[k][pos] = temp;
    }
}

int main(void){
    cin >> N;
    len = (int) pow(2, N);
    for (int i=0;i<len;i++){
        perm[i] = vector<bool>(N);
        for(int j=0;j<N;j++){
            perm[i][j] = 0;
        }
    }
    cin >> A >> B;
    perm[0] = getbin(A), perm[len-1] = getbin(B);  
    int cnt = 0;
    for (int i=0;i<N;i++){
        cnt += (perm[0][i]!=perm[len-1][i]);
    }
    if (cnt%2==0) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    if (N==1){
        cout << A << " " << B << endl;
        return 0;
    }
    // cout << -1 << endl;
    // exit(0);
    fill(0, len-1, 0);
    for (int i=0;i<len;i++){
        cout << getval(perm[i]) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 10240
import numpy as np

N,K = map(int,input().split())
P = np.array(list(map(int,input().split())))

s = (K+ np.sum(P[:K]))/2
ans = s
for i in range(1,N-K+1):
    s = s - P[i-1]/2 + P[i+K-1]/2
    if s > ans:
        ans = s
print(ans)


Measured memory_bytes: 35432
using System;

namespace C_sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var tenant = new int[4, 3, 10];

            var n = int.Parse(Console.ReadLine());

            for (var i = 0; i < n; i++)
            {
                var line = Console.ReadLine().Split();
                var b = int.Parse(line[0]) - 1;
                var f = int.Parse(line[1]) - 1;
                var r = int.Parse(line[2]) - 1;
                var v = int.Parse(line[3]);

                tenant[b, f, r] += v;
            }

            for (var i = 0; i < 4; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    for (var k = 0; k < 10; k++)
                    {
                        Console.Write($" {tenant[i, j, k]}");
                    }
                    Console.WriteLine();
                }
                if (i != 3)
                {
                    Console.WriteLine("####################");
                }
            }
        }
    }
}



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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  char S[N][N];
  for(int i=0;i<N;i++){
    cin >> S[i];
  }
  // (A, B) <=> (A + 1, B + 1)
  int cnt = 0;
  for(int b=0;b<N;b++){
    bool pos = true;
    for(int i=0;i<N;i++){
      if(pos == false) break;
      for(int j=i+1;j<N;j++){
        if(S[i][(j + b) %N] != S[j][(i + b) %N]){
          pos = false;
          break;
        }
      }
    }
    if(pos == true) cnt++;
  }
  cout << cnt*N << endl;
}

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

int md;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int mul(int a, int b)
{
	return (long long)a * b % md;
}

const int N = 5000;
int n, dp[N][N];

int main() 
{
	scanf("%d%d", &n, &md);
	dp[0][0] = 1;
	for (int i = 1; i < n; ++i) {
		int dif = std::min(i, n - i + 1);
		for (int j = 0; j < n; ++j) dp[i][j] = add(dp[i - 1][j], j >= dif ? dp[i][j - dif] : 0);
	}
	int r = 0;
	for (int i = 0; i < n; ++i) r = add(r, mul(n - i, dp[n - 1][i]));
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 99292
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<functional>
#include<set>
#include<complex>
#include<limits>
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

int main()
{
	std::cout << std::setprecision(std::numeric_limits<long double>::digits10 + 1);
	typedef std::complex<double> point;
	double sx, sy, gx, gy;
	std::cin >> sx >> sy >> gx >> gy;
	point start(sx, sy), goal(gx, gy);
	int N;
	std::cin >> N;
	std::vector<std::pair<point, double>> barrier;
	for (int i{};i < N;++i)
	{
		double x, y, r;
		std::cin >> x >> y >> r;
		barrier.emplace_back(point(x, y), r);
	}
	p_queue<std::pair<double, int>> queue;
	int k{};
	for (auto const& b : barrier)
	{
		queue.emplace(std::max(std::sqrt(std::norm(b.first - start)) - b.second, 0.), k++);
	}
	queue.emplace(std::sqrt(std::norm(goal - start)), k);
	std::vector<double> data(N, std::numeric_limits<double>::max());
	while (queue.size())
	{
		auto top = queue.top();
		queue.pop();
		if (top.second == N)
		{
			std::cout << top.first << std::endl;
			return 0;
		}
		if (top.first < data[top.second])
		{
			data[top.second] = top.first;
			auto const& f = barrier[top.second];
			for (int i{};i < N;++i)
			{
				if (i == top.second)
					continue;
				auto const& b = barrier[i];
				queue.emplace(std::max(std::sqrt(std::norm(b.first - f.first)) - b.second - f.second, 0.) + data[top.second], i);
			}
			queue.emplace(std::max(std::sqrt(std::norm(f.first - goal)) - f.second, 0.) + data[top.second], N);
		}
	}
}

Measured memory_bytes: 16764
#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x) \
  cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  cout << (!x) << endl;
}


Measured memory_bytes: 3576
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const* argv[])
{
    int64_t A, B;
    int64_t ans = 0;

    scanf("%" PRId64 "%" PRId64, &A, &B);

    if ((A % 2) && (B % 2)) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 128
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
sample_input = list(range(3))
sample_input[0] = '''5
5 3 2 4 1'''
sample_input[1] = '''6
5 2 4 6 1 3'''
sample_input[2] = '''1
100'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main part
def swap_list_item(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp

num_of_data = int(input())
list_of_data = list(map(int, input().split()))

swap_count = 0
flag = True
while flag:
    flag = False
    n = num_of_data - 1
    while n >= 1:
        if list_of_data[n] < list_of_data[n-1]:
            swap_list_item(list_of_data, n, n-1)
            flag = True
            swap_count += 1
        n -= 1

result = ''
for number in list_of_data:
    result += str(number) + ' '
print(result.strip())
print(swap_count)

Measured memory_bytes: 7740
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
Acum = [0]+list(accumulate(map(int, input().split())))
Bcum = [0]+list(accumulate(map(int, input().split())))

ans = 0
for a in range(n+1):
    if k < Acum[a]:
        break
    b = bisect.bisect_right(Bcum, k-Acum[a])-1
    if ans < a+b:
        ans = a+b
print(ans)

Measured memory_bytes: 48552