akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	N := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	result := 0
	a := make([]int, N)
	bs := make([]int, N)
	for b := 0; b < 60; b++ {
		a[N-1] = (A[N-1] >> uint(b)) & 1
		bs[N-1] = a[N-1]
		for i := N - 2; i > -1; i-- {
			a[i] = (A[i] >> uint(b)) & 1
			bs[i] = bs[i+1] + a[i]
		}

		t := 0
		for i := 0; i < N-1; i++ {
			if a[i] == 0 {
				t += bs[i+1]
			} else {
				t += (N - (i + 1)) - bs[i+1]
			}
		}
		t %= 1000000007
		B := (1 << uint(b)) % 1000000007
		result += (t * B) % 1000000007
		result %= 1000000007
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 12800
#include <cstdio>
#include <cstring>

bool dp[1000001];
bool pm[1000001];

int main() {
	int n,x,v[30];
	pm[0]=pm[1]=true;
	for(int i=2;i<=1000000;i++) {
		if(!pm[i]) for(int j=2;i*j<=1000000;j++) pm[i*j]=true;
	}
	while(scanf("%d %d",&n,&x),n||x) {
		for(int i=0;i<n;i++) {
			scanf("%d",&v[i]);
		}
		memset(dp,0,sizeof(dp));
		dp[0]=true;
		for(int i=1;i<=x;i++) {
			for(int j=0;j<n;j++) {
				if(i-v[j]>=0&&dp[i-v[j]]) {
					dp[i]=true;break;
				}
			}
		}
		int ans=-1;
		for(int i=x;i>=2;i--) {
			if(dp[i]&&!pm[i]) {ans=i;break;}
		}
		if(ans!=-1) printf("%d\n",ans); else printf("NA\n");
	}
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n,c;
  cin>>n>>c;
  vector<vector<int>> cnt(3,vector<int>(c));
  vector<vector<int>> mat(c,vector<int>(c));
  rep(i,c) rep(j,c) cin>>mat[i][j];

  rep(i,n) rep(j,n) {
    int d;
    cin>>d;
    d--;
    cnt[(i+j)%3][d]++;
  }

  vector<vector<int>> val(3,vector<int>(c, 0));
  rep(k,3){
    rep(i,c){
      rep(j,c){
        val[k][j] += cnt[k][i] * mat[i][j];
      }
    }
  }

  int ans = INT_MAX;
  rep(i,c) rep(j,c) if(i!=j) rep(k,c) if(i!=k && j!=k){
    ans = min(ans, val[0][i] + val[1][j] + val[2][k]);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    long long  n=x/d;
    if(n>=k)
        printf("%lld\n",abs(x-k*d));
    else
    {
       long long  a,b;
        if((k-n)%2==0)
            a=abs(x-n*d);
        else
            a=abs(x-(n+1)*d);
        if((k-n-1)%2==0)
            b=abs(x-(n+1)*d);
        else
            b=abs(x-n*d);
        printf("%lld\n",min(a,b));

    }

    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   map<string,ll> ma;
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   for(ll i=0;i<n;i++)
   {
       map<string,ll> ma1;
       for(auto it = ma.begin();it!=ma.end();it++)
       {
           if(it->first.length() == 3)
                continue;
           string s1 = it->first;
           s1+=s[i];
           ma1[s1] = 1;
       }
       
       for(auto it = ma1.begin();it!=ma1.end();it++)
            ma[it->first] = 1;
       string temp;
       temp+=s[i];
       ma[temp] = 1;
   }
   
   ll ans = 0;
   for(auto it = ma.begin();it!=ma.end();it++)
        ans+=(it->first.length() == 3);
   
   cout<<ans;        
   
   return 0;
}  
   

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
def block(b):
    for i in range(8):
        for j in range(8):
            if b[i][j] == 1:
                if sum(b[i]) == 4:
                    return 'C'
                if sum([b[t][j] for t in range(8)]) == 4:
                    return 'B'
                if sum(b[i]) == 2:
                    if b[i + 1][j] == 0:
                        return 'E'
                    if b[i + 1][j + 1] == 0:
                        return 'G'
                    return 'A'
                if j > 0 and b[i + 1][j - 1] == 1:
                    return 'D'
                return 'F'

while True:
    try:
        b = 8 * [8 * [0]]
        for i in range(8):
            b[i] = list(map(int, input()))
        print(block(b))
        input()
    except:
        break

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

vector<ll> e;
vector<P> g[51];

bool dfs(ll t,ll p, ll l){
  if (t==l)return true;
  for(P v:g[t]){
    if (v.first==p)continue;


    if(dfs(v.first,t,l)){
      e.push_back(v.second);
    //  cout<<v.second<<"v"<<endl;
      return true;
    }
  }
  return false;
}

int main() {
  ll n;
  cin>>n;
  rep(i,n-1){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    g[a1].push_back(make_pair(b1,i));
    g[b1].push_back(make_pair(a1,i));
  }
  ll m;
  cin>>m;
  vector<ll> edge(m);
  rep(i,m){
    ll u1,v1;
    cin>>u1>>v1;
    u1--;v1--;
    e=vector<ll>();
    //cout<<i<<"dfs"<<endl;
    dfs(u1,-1,v1);
    for(ll j:e){
      edge[i]|=(1ll<<j);
    }
  }
  ll ans=0;
  rep(i,1ll<<m){
    ll now=0;
    rep(j,m){
      if ((i>>j)&1){
        now|=edge[j];
      }
    }
    ll c=__builtin_popcountll(now);
    ll c1=__builtin_popcountll(i);
    //cout<<i<<'i'<<c<<"c"<<endl;
    if (c1%2==0)ans+=(1ll<<(n-1-c));
    else ans-=(1ll<<(n-1-c));
  }
  cout<<ans;
}


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

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		ans += A[i] - 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define lop(i,s,t) for(int i=s;i<(t);++i)
using namespace std; 

const int N=200050,P=1e9+7; 

int n,m,limit,f[N],sum[N]; 
char s[N]; 

int main(int argc,char *argv[]){
//	freopen("d.in.cpp","r",stdin); 
    scanf("%d%d%s",&n,&m,s); 
    if(s[0]=='B')lop(i,0,m)s[i]=s[i]=='R'?'B':'R';
	//Pr("%d,%d,%s\n",n,m,s);  
    while(m&&s[m-1]=='R')--m;
    if(m==0){
    	f[0]=2,f[1]=1;
		rep(i,2,n)f[i]=(f[i-1]+f[i-2])%P;
		printf("%d\n",f[n]); 
		return 0; 	
    }
    if(n%2!=0){
        puts("0"); 
        return 0; 
    }
    limit=n-1; 
    for(int p=0,prv=0;p<m;++p){
        while(p<m&&s[p]=='R')++p;
		if(prv==0){
            if(p-prv%2==1)limit=p-prv;
            else limit=p-prv+1;
        }
        if((p-prv)%2==1)limit=min(limit,p-prv);
        //printf("%d\n",p-prv); 
        prv=p+1;
    }          
    //Pr("limit=%d\n",limit); 
	f[1]=sum[1]=0,f[2]=sum[2]=2;
	for(int i=4;i<=n;i+=2){
		sum[i-1]=(sum[i-2]+f[i-1])%P;
		if(i<=limit+1)(f[i]+=i)%=P;
		(f[i]+=(sum[i-1]-sum[max(1,i-limit-2)]+P)%P)%=P;
		sum[i]=(sum[i-1]+f[i])%P;
	}
	printf("%d\n",f[n]); 
    return 0; 
}    

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

void solve() {
	lli n, m, q, k;
	cin >> n >> k;
	vcL num( n, 0 );

	lli _min = INT_MAX, _max = 0;

	for (int i = 0; i < n; ++i) {
		cin >> num[i];
		
		if ( i >= k-1 ) {
			_min = min( _min, min( abs(num[i]), abs(num[ i-k+1 ]) ) + num[i]-num[ i-k+1 ] );
		}
	}
	
//	sort( num.begin(), num.end() );
	
	cout << _min << '\n';
}

int main() {
	precal();
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 1024
L,R = map(int, input().split())
if R - L >= 2018:
    print(0)
    exit()
else:
    ans = 2019**2
    for i in range(L, R):
        for j in range(i+1, R+1):
            #i %= 2019
            #j %= 2019
            k = (i*j) % 2019
            ans = min(ans, k)
    print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] s=new int[n];
		int[] t=new int[m];
		long[][] dp=new long[n+1][m+1];
		long[][] sum=new long[n+1][m+1];
		long mod=1000000007;
		for(int i=0; i<n; i++){
			s[i]=sc.nextInt();
		}
		for(int i=0; i<m; i++){
			t[i] =sc.nextInt();
		}
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				if(s[i-1]==t[j-1]){
					dp[i][j]=1+sum[i-1][j-1];
					dp[i][j]%=mod;
				}
				sum[i][j]=sum[i-1][j]-sum[i-1][j-1]+sum[i][j-1]+dp[i][j]+mod;
				sum[i][j]%=mod;
			}
		}
		System.out.println((sum[n][m]+1)%mod);
	}
}




Measured memory_bytes: 132024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	P p[100010];
	rep(i, m) {
		int a, b; cin >> a >> b;
		p[i].first = b;
		p[i].second = a;
	}
	sort(p, p + m);
	int l = 0;
	int ans = 0;
	rep(i, m) {
		if (p[i].first != p[i + 1].first && !(p[i].first > l&&p[i].second <= l)) {
			ans++; l = p[i].first - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if (2 * c < a + b) {
        ans = min(x, y) * 2 * c;
        if (x > y) {
            if ((x - y) * a > 2 * (x - y) * c) ans += 2 * (x - y) * c;
            else ans += (x - y) * a;
        } else {
            if ((y - x) * b > 2 * (y - x) * c) ans += 2 * (y - x) * c;
            else ans += (y - x) * b;
        }
    } else {
        ans = x * a + y * b;
    } 
    cout << ans << "\n";
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	ll w, h, x, y; cin >> w >> h >> x >> y;
	double ans0 = double(w) * h / 2;
	int ans1;
	if (x * 2 == w && y * 2 == h) {
		ans1 = 1;
	}
	else {
		ans1 = 0;
	}
	cout << setprecision(12) << ans0 << " " << ans1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int con = 1;
		int ans = 0;

		for (int i = 0; i < N; i++) {
			if (sc.nextInt() == con) {
				con++;
			}else {
				ans++;
			}
		}
		if (con == 1) {
			System.out.println(-1);
		}else {
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 59832
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    char a;
    scanf("%c",&a);
    printf("%c\n",a+1);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int num = 0;

        while(true){

            String num1 = br.readLine();
            String[] num2 = num1.split(" ");
            int a = Integer.parseInt(num2[0]);
            int b = Integer.parseInt(num2[2]);
            String op = num2[1];

            if(op.equals("+")){
                num = a + b;
                System.out.println(num);
            }else if(op.equals("-")){
                num = a - b;
                System.out.println(num);
            }else if(op.equals("*")){
                num = a * b;
                System.out.println(num);
            }else if(op.equals("/")){
                num = a / b;
                System.out.println(num);
            }else if(op.equals("?")){
                break;
            }
        }
    }
}

Measured memory_bytes: 24332
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

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

    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> ans(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep(i,n) ans[i] = i+1;

    int a, b;
    int cnt = 0;
    do{
        cnt++;
        bool flag = true;
        bool flag2 = true;
        for(int i=0; i<n; i++){
            if(ans[i]!=p[i]) flag = false;
            if(ans[i]!=q[i]) flag2 = false;
        }
        if(flag) a = cnt;
        if(flag2) b = cnt;
    }while(next_permutation(ALL(ans)));

    cout << abs(a-b) << endl;
    return 0;
}

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



int main(){
    ll N , x;
    cin >> N >> x;
    ll sum = 0;
    ll ans = 0;
    vector<ll> a(N,0);
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] > x){
            ans += a[i] - x;
            a[i] = x;
        } 
    } 
    
    for(int i = 0; i < N - 1; i++){
        if(a[i] + a[i + 1] > x){
            ll tmp = a[i + 1];
            a[i + 1] = x - a[i];
            ans += tmp - a[i + 1];
        }
    }


    cout << ans << endl;

}



Measured memory_bytes: 4032
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(input())
  p = tuple(map(int, input().split()))
  q = tuple(map(int, input().split()))
  l = [i for i in range(1,n+1)]
  for i, junretsu in enumerate(permutations(l, n)):
    if junretsu==p:
      a = i
    if junretsu==q:
      b=i
  print(abs(b-a))
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5244
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;

int main() {
	int a, b;
	cin >> a >> b;
	vint n(a * b, 0);
	rop(i, a * b)cin >> n[i];
	rop(i, a) {
		int sum = 0;
		rop(j, b) {
			cout << n[b * (i - 1) + j]<<" ";
			sum += n[b * (i - 1) + j];
		}
		cout << sum << endl;
	}
	int sumsum = 0;
	rop(i, b) {
		int sum = 0;
		rop(j, a) {
			sum += n[b * (j - 1) + i];
		}
		cout << sum << " " ;
		sumsum += sum;
	}
	cout << sumsum << endl;
	return 0;
}

// abc : 141 , aoj : ITP1_6_D


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

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,A,B) for(int i=A;i<=B;i++)
#define mod 998244353
#define MOD (1000*1000*1000+7)
#define v1d vector<int>
#define v2d vector<vector<int>>
#define vip vector<pair<int,int> >
#define v1s vector<string>
#define pa pair<int,int>
#define print(v) for(auto i:v)cout<<i<<" ";cout<<"\n";
#define endl '\n'
#define input(b,n) for(int i=1;i<=n;i++)cin>>b[i];
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v) v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s= bitset<64>(a).to_string();

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define fbo find_by_order // iterator to the kth element
#define ook order_of_key  //number of items that are strictly smaller than our item k
#define T pair<int, int>
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>


void solve(){
    int n,m;cin>>n>>m;
    if(m == 1){
        if(n == 1){
            cout<<0;return ;
        }
        else{
            n = n*(n-1)/2;
            cout<<n;return ;
        }
    }
    if(n == 1){
        if(m == 1){
            cout<<0;return ;
        }
        else{
            m *= (m-1);
            m /= 2;
            cout<<m;return ;
        }
    }
    m = m*(m-1)/2;
    n = n*(n-1)/2;
    n += m;
    cout<<n;
}

int32_t  main(){ 
    IOS;
    int t=1;//cin>>t;
    while(t--){
        solve();
    }








}















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

using namespace std;

struct point {
  int b, l, u;
  long long s;
  
  bool operator < (const point &other) const {
    return s > other.s;
  }
};

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<point> a(n);
  long long need = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].b >> a[i].l >> a[i].u;
    need += (long long) a[i].b * a[i].l;
    a[i].s = (long long) a[i].l * a[i].b + (long long) a[i].u * (m - a[i].b);
  }
  sort(a.begin(), a.end());
  auto check = [&](long long t) {
    int full = t / m, small = t % m;
    long long sum = 0;
    for (int i = 0; i <= full; ++i) {
      sum += a[i].s;
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
      long long single = a[i].b <= small ? (long long) a[i].u * small - (long long) (a[i].u - a[i].l) * a[i].b : (long long) a[i].l * small;
      if (i <= full) {
        ans = max(ans, sum - a[i].s + single);
      } else {
        ans = max(ans, sum - a[full].s + single);
      }
    }
    return ans >= need;
  };
  long long l = 0, r = (long long) n * m;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << r << "\n";
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void)
{
	unsigned char str[1000];
	int i;
	int a[101], b[101];
	int t;
	
	while (1){
		scanf("%d", &t);
		
		if (!t){
			break;
		}
		
		scanf("%s", str);
		
		for (i = 0; i < t; i++){
			scanf("%d%d", &a[i], &b[i]);
		}
		for (i = t - 1; i >= 0; i--){
			str[a[i] - 1] ^= str[b[i] - 1];
			str[b[i] - 1] ^= str[a[i] - 1];
			str[a[i] - 1] ^= str[b[i] - 1];
			
			str[a[i] - 1] += (b[i] - a[i]);
			str[b[i] - 1] += (b[i] - a[i]);
			
			while (str[a[i] - 1] > 'z'){
				str[a[i] - 1] -= 26;
			}
			while (str[b[i] - 1] > 'z'){
				str[b[i] - 1] -= 26;
			}
		}
		printf("%s\n", (char *)str);
		fflush(stdin);
	}
	
	return (0);
}

Measured memory_bytes: 0
#import numpy as np

#def area--------------------------#
#ryouno syokiti
class ryou:
	def flinit(self):
		room=list()
		for i in range(10):
			room+=[0]
		return room

#def kaijo([a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9,a_10]):


#def kaijo(x):
#	y=[]
#	for i in x:
#		y=y+ " "+x[i]
#	return y		
def kaijo(x):
	print "",
	for i in range(len(x)-1):
		print str(x[i]),
	print str(x[len(x)-1])


#----------------------------------#

floor_11=ryou().flinit()
floor_12=ryou().flinit()
floor_13=ryou().flinit()
floor_21=ryou().flinit()
floor_22=ryou().flinit()
floor_23=ryou().flinit()
floor_31=ryou().flinit()
floor_32=ryou().flinit()
floor_33=ryou().flinit()
floor_41=ryou().flinit()
floor_42=ryou().flinit()
floor_43=ryou().flinit()


fldic={"11":floor_11,
       "12":floor_12,
       "13":floor_13,
       "21":floor_21,
       "22":floor_22,
       "23":floor_23,
       "31":floor_31,
       "32":floor_32,
       "33":floor_33,
       "41":floor_41,
       "42":floor_42,
       "43":floor_43
       }

#----------------------------------#


#1kaime yomikomi
n=int(raw_input())

#nkaime syusyori

for l in range(n):
	list_mojiretsu=raw_input().split(" ")
	henka=map(int,list_mojiretsu)
	fldic[str(henka[0])+str(henka[1])][henka[2]-1]+=henka[3]
	


kaijo(floor_11)
kaijo(floor_12)
kaijo(floor_13)
print "####################"
kaijo(floor_21)
kaijo(floor_22)
kaijo(floor_23)
print "####################"
kaijo(floor_31)
kaijo(floor_32)
kaijo(floor_33)
print "####################"
kaijo(floor_41)
kaijo(floor_42)
kaijo(floor_43)

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

int main(void)
{
    int n,ans=0,ok,before;
    char s[51];

    scanf("%d",&n);
    scanf("%s",s);

    ok=0;
    for (int i = 0; i < n; i++)
    {
        if(s[i]=='A')
        {
            ok=1;
            before=i;
        }
        if(s[i]=='B'&&ok==1&&before==i-1)
        {
            ok=2;
            before=i;
        }
        if(s[i]=='C'&&ok==2&&before==i-1)
        {
            ok=0;
            ans++;
        }
    }

    printf("%d",ans);

    return 0;
}

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

int main() {
 int n;
 cin >> n;
 vector<int> arr(n);
 rep (i, n) {
   cin >> arr[i];
 }
 int res = 0;
 int x = 0;
 rep(i, n) {
   ++res;
   x = arr[x] - 1;
   if (x == 1) {
     break;
   }
 }
 if (res == n) {
   cout << -1 << endl;
 } else {
   cout << res << endl;
 }
}


Measured memory_bytes: 640
def solve():
    s = input()
    n=len(s)
    cnt = 0
    ans = 0
    j = 0
    for i in range(n-1):
        if j>=n-1:
            break
        if s[j]=='A':
            cnt+=1
        elif s[j]=='B' and s[j+1]=='C':
            ans+=cnt
            j+=1
        else:
            cnt = 0
        j+=1
    return ans
print(solve())

Measured memory_bytes: 41056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  bitset<6> B; cin>>B;
  cout<<B.count()<<endl;
  }


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!.split(" ")[0].map { it.toChar() }
    if (s[0] == s[1]){
        if (s[0] == s[2]){
            println("No")
        } else {
            println("Yes")
        }
    } else {
        println("Yes")
    }
}




Measured memory_bytes: 37880
I, O, T, J, L, S, Z = map(int, input().split())
k0 = 0
k0 += (I//2)*2
k0 += (J//2)*2
k0 += (L//2)*2

k1 = 0
if I >= 1 and J >= 1 and L >= 1:
    k1 = 0
    k1 += 3
    I -= 1
    J -= 1
    L -= 1
    k1 += (I//2)*2
    k1 += (J//2)*2
    k1 += (L//2)*2

k = max(k0, k1)
k += O
print(k)

Measured memory_bytes: 38256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N, K;
int v[53];

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

  cin >> N >> K;
  rep(i, N) cin >> v[i];

  int max_value = 0;
  rep(cnt, min(N, K)+1){
    int ta = K-cnt; //throw awayの回数
    rep(a,cnt+1){
      priority_queue<int, vector<int>, greater<int> > pque;
      int b = cnt - a;
      int value = 0;
      rep(i, a){
        pque.push(v[i]);
        value+=v[i];
      }
      rep(i, b){
        pque.push(v[N-i-1]);
        value+=v[N-i-1];
      }
      rep(i, ta){
        if (pque.empty()) break;
        int top = pque.top();
        if(top>0) break;
        value-=top;
        pque.pop();
      }
      max_value=max(max_value, value);
    }
  }
  
  cout << max_value << endl;
  return 0;
}


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

#pragma GCC diagnostic warning "-Wconversion"

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;

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

        int m2 = 0;
        int m4 = 0;
        int m = 0;

        int n;
        cin >> n;

        fora(i, n)
        {
                int x;
                cin >> x;
                if (x % 4 == 0)
                        ++m4;
                else if (x % 2 == 0)
                        ++m2;
                else ++m;
        }

        if (m2 >= 1 && (m4 + m) >= 1)
                ++m;

        if (m == 0 || (m4 > 0 && m4 >= m - 1))
                cout << "Yes\n";
        else cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, H, W;
    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W + 1) << endl;
}



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

int main(void){
    int a, b, c, d;
    int ans = 0;
    cin >> a >> b >> c >> d;
    
    if(a < c){
        if(b < c)       ;
        else{
            ans = min(b - c, d - c);
        }
    }
    else{
        if(a > d)       ;
        else{
            ans = min(b - a, d - a);
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

int main()
{
    int $=1;
    //cin>>$;
    while($--)
    {
        ll n;
        cin>>n;
        ll x,y;
        vector<pair<int,int>>v;
        while(n--)
        {
            cin>>x>>y;
            v.emplace_back(make_pair(x,y));
        }
        sort(v.begin(),v.end());
        for(auto x : v) cout<<x.first<<" "<<x.second<<endl;
    }
}


/*
8888888888888888888888888888
    Md. Masud Mazumder
    University of Chittagong
    Department of CSE
8888888888888888888888888888
*/



Measured memory_bytes: 3792
s = gets.rstrip

def iskaibun(s)
  if s == s.reverse
    return true
  else
    return false
  end
end

len = s.size - 1

if iskaibun(s) \
    and iskaibun(s[0..(len-1).div(2)]) \
    and iskaibun(s[(len+3).div(2)..len])
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define max1 3005
#define siz 100000
#define mod 1000000007
#define inf 1e18+5
#define ll long long int
#define debug(x) cout<<#x<<" "<<x<<endl
#define jam(x) cout<<"Case #"<<x<<": "
typedef pair<ll,ll> pr;
vector<vector<double> > dp(max1,vector<double>(max1,-1) );
vector<double> a(max1);
ll n;
double fun(ll idx,ll s)
{
  if(idx>=n)
  {
    if(s>(n-s))
    {
      return 1.0;
    }
    else
    {
      return 0;
    }
  }
  if(dp[idx][s]!=-1)
  {
    return dp[idx][s];
  }
  return dp[idx][s]=((fun(idx+1,s+1)*a[idx])+(fun(idx+1,s)*(1.0-a[idx])));
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
  cin>>n;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  cout<<fixed<<setprecision(10);
  cout<<fun(0,0)<<endl;
}


Measured memory_bytes: 71168
#include <stdio.h>
int main(void){
  int A,B;
  scanf("%d %d",&A,&B);
  if(A==B)
    printf("Draw");
    else if(A==1)
      printf("Alice");
    else if(B==1)
      printf("Bob");
    else if(A>B)
      printf("Alice");
    else
      printf("Bob");
  }

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
		
		
       for(char c : s) {
           // System.out.print((char)((c-'A'+n)%26 + 'A'));
          System.out.print((char)((c-'A'+n)%26 + 'A'));

        }


      
	}
}

Measured memory_bytes: 26580
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])

if a+b+c+d == 7:
    print('{0}+{1}+{2}+{3}=7'.format(a, b, c, d))
elif a-b+c+d == 7:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))
elif a+b-c+d == 7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif a+b+c-d == 7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif a-b-c+d == 7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
elif a-b+c-d == 7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
elif a+b-c-d == 7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif a-b-c-d == 7:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))

Measured memory_bytes: 3064
// D - Face Produces Unhappiness
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,K; cin>>N>>K;
	string S; cin>>S;
	int happy = 0;
	for(int i=0; i<N-1; ++i) if(S[i]==S[i+1]) ++happy;
	happy = min(happy+K*2, N-1);
	cout<< happy <<endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int n,a[3],m;
    cin>>n;
    for(int i = 0; i<3;i++,n /= 10){
        if(n%10 == 1)a[2-i] = 9;
        else if(n%10 == 9)a[2-i] = 1;
    }
    m = a[0]*100 + a[1]*10 + a[2];
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

Pii devide(vector<int> &B, vector<int> &W, int K){
    int N = B.size();
    vector< vector<bool> > dp(N + 1, vector<bool>(K + 1, false));
    dp[0][0] = true;
    REP(i, N){
        REP(k, K + 1){
            if(dp[i][k]){
                if(k + B[i] <= K) dp[i + 1][k + B[i]] = true;
                if(k + W[i] <= K) dp[i + 1][k + W[i]] = true;
            }
        }
    }
    int x1 = -1, x2 = 0;
    IREP(i, K + 1){
        if(dp[N][i]){
            x1 = i;
            break;
        }
    }
    REP(i, N) x2 += B[i] + W[i];

    return Pii(x1, x2 - x1);
}

signed main(){

    int N;
    cin >> N;
    vector< vector<int> > ko(N, vector<int>(0)), depth(N, vector<int>(0));
    int P, maxdepth = 1;
    FOR(i, 1, N){
        cin >> P;
        P--;
        ko[P].push_back(i);
    }
    depth[0].push_back(0);
    REP(i, N){
        if(depth[i].size() == 0) break;
        maxdepth++;
        REP(j, depth[i].size()){
            REP(k, ko[depth[i][j]].size()){
                depth[i + 1].push_back(ko[depth[i][j]][k]);
            }
        }
    }
    
    vector<int> X(N);
    readvec(X);

    vector<int> B(N), W(N, 0);
    REP(i, N) B[i] = X[i];

    IREP(i, maxdepth - 1){
        REP(j, depth[i].size()){
            int l = depth[i][j];
            if(ko[l].size() == 0) continue;
            int n = ko[l].size();
            vector<int> b(n), w(n);
            REP(k, n){
                b[k] = B[ko[l][k]], w[k] = W[ko[l][k]];
            }
            Pii res = devide(b, w, X[l]);
            if(res.first == -1){
                cout << "IMPOSSIBLE";
                return 0;
            }else{
                B[l] = X[l]; W[l] = res.second;
            }
        }
    }
    cout << "POSSIBLE";
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

vector<int>vec[100005];
map<pair<int,int>, int >m;

bool visited[100005], color[100005];

void dfs(int node, int col, int prev)
{
	int len = vec[node].size();
	
	if(!visited[node])
	{
		if(m[{node, prev}] % 2 == 0)
		{
			color[node] = color[prev];
		}
		else
		{
			if(color[prev] == 0) color[node] = 1;
			else color[node] = 0;
		}
		
		visited[node] = 1;
		
	}
	
	for(int i = 0; i < len; i++)
	{
		int ans = vec[node][i];
		
		if(!visited[ans])
		{
			dfs(ans, color[node], node);
		}
	}
}

int main()
{
     int n, u, v, w;
     
     cin >> n ;
     
     for(int i  = 1; i <= n-1; i++)
     {
		 cin >> u >> v >> w;
		 
		 vec[u].push_back(v);
		 vec[v].push_back(u);
		 
		 m.insert(make_pair(make_pair(u,v), w));
		 m.insert(make_pair(make_pair(v,u), w));
	 }
	 
	 color[1] = 0;
	  
	 visited[1] = 1; 
	    
	 dfs(1,0,1);
     
     for(int i = 1; i <= n; i++)
     {
		 cout << color[i] << endl;
	 }
     
	 return 0;
}


Measured memory_bytes: 21376
#include <stdio.h>
int main(void){
	int n, m;
	scanf("%d %d", &n, &m);
	int k[n];
	int a[n][m];
	for(int i=0;i<n;i++){
		scanf("%d", &k[i]);
		for(int j=0;j<k[i];j++)	scanf("%d", &a[i][j]);
	}
	
	int flag=1;
	int count=0;
	
	for(int i=1;i<m+1;i++){	//種類るーぷ
		for(int j=0;j<n;j++){	//人るーぷ
			for(int p=0;p<k[j];p++){ //あれるーぷ
				if(a[j][p]==i)	goto basyo;
			}
			flag=0;
			break;
			basyo:continue;
        }
		if(flag==1)	count++;
		flag=1;
	}
	printf("%d", count);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define D(x) cout<<"D:"<<#x<<'='<<x<<endl;
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	for(int i = 0; (unsigned)i < v.size(); i++) os<<v[i]<<' ';
	return os;
}
int w[200005];
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = next<int>(); 
	for(int i = 0; i < n; i++) cin>>w[i];
	sort(w, w+n);
	for(int i = 1; i < n; i++)
		if (w[i] == w[i-1])
		{
			cout<<"NO"<<endl;
			return 0;
		}
	cout<<"YES"<<endl;
	return ~~(0-0);
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
int h,w,k;
int fie[802][802];
int sx,sy;
int dist[802][802];

int solve(){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			dist[i][j]=INF;
		}
	}
	dist[sy][sx]=0;
	queue<P> que;
	que.push(P(sy,sx));
	while(que.size()){
		P q=que.front();
		que.pop();
		if(q.first==0 || q.first==h-1 || q.second==0 || q.second==w-1)return (dist[q.first][q.second]-1)/k;
		for(int i=0;i<4;i++){
			int nx=q.second+dx[i],ny=q.first+dy[i];
			if(dist[q.first][q.second]<k && fie[ny][nx]==0 && dist[q.first][q.second]+1<dist[ny][nx]){
				dist[ny][nx]=dist[q.first][q.second]+1;
				que.push(P(ny,nx));
			}
			if(dist[q.first][q.second]>=k && dist[q.first][q.second]+1<dist[ny][nx]){
				dist[ny][nx]=dist[q.first][q.second]+1;
				que.push(P(ny,nx));
			}
		}
		if(dist[q.first][q.second]<k){
			dist[q.first][q.second]++;
			que.push(P(q.first,q.second));
		}
	}
	return -1;
}

int main(void){
	scanf("%d%d%d",&h,&w,&k);
	for(int i=0;i<h;i++){
		string str;
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='#'){
				fie[i][j]=1;
			}
			if(str[j]=='S'){
				sx=j;
				sy=i;
			}
		}
	}
	printf("%d\n",solve()+1);
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  
  int ans=0;
  
  int x=0;
  
  
  for(int i=0;i<N-1;i++){
    if(H[i]>=H[i+1]){
      x++;
      ans=max(ans,x);
    }
    else{
      x=0;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3784
#include<stdio.h>
int main(void){
    int a[10]={0},i,j;
    char c;
    while(scanf(" %c",&c)!=EOF){
        a[0]=c-'0';
        for(i=1;i<10;i++){
            scanf(" %c",&c);
            a[i]=c-'0';
        }
        for(i=0;i<9;i++){
            for(j=0;j<9-i;j++){
                a[j]=(a[j]+a[j+1])%10;
            }
        }
        printf("%d\n",a[0]);
    }
    return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline
ll getint()
{
	re ll num;
	re char c;
	re bool f=0;
	while(!isdigit(c=gc()))f^=c=='-';
	num=c^48;
	while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
	return f?-num:num;
}

inline
void outint(ll a)
{
	static char ch[23];
	if(a==0)pc('0');
	while(a)ch[++ch[0]]=a-a/10*10,a/10;
	while(ch[0])pc(ch[ch[0]--]^48);
}

int n;
cs int N=100005;
int cnt[2][N];
int maxn[2],num[2],submaxn[2],subnum[2];
signed main()
{
	n=getint();
	for(int re i=2; i<=n+1; ++i)
		{
			int a=getint();
			++cnt[i&1][a];
			if(maxn[i&1]<cnt[i&1][a])
				{
					if(num[i&1]==a)
						{
							maxn[i&1]=cnt[i&1][a];
						}
					else
						{
							subnum[i&1]=num[i&1];
							submaxn[i&1]=maxn[i&1];
							maxn[i&1]=cnt[i&1][a];
							num[i&1]=a;
						}
				}
			else if((cnt[i&1][a]==maxn[i&1]&&num[i&1]!=a)||cnt[i&1][a]>submaxn[i&1])
				{
					submaxn[i&1]=cnt[i&1][a];
					subnum[i&1]=a;
				}
		}
	int ans;
	if(num[0]!=num[1])ans=n-maxn[0]-maxn[1];
	else ans=n-max(maxn[0]+submaxn[1],maxn[1]+submaxn[0]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
vala1 = 0
maxCnta = 0
maxCnta1 = 0
for i in a:
    cnta[i] += 1

for i in a:
    if maxCnta < cnta[i]:
        vala = i
        maxCnta = cnta[i]
for i in a:
    if maxCnta1 < cnta[i] and vala != i:
        maxCnta1 = cnta[i]
        vala1 = i
#---------------------------
valb = 0
valb1 = 0
maxCntb = 0
maxCntb1 = 0
for i in b:
    cntb[i] += 1

for i in b:
    if maxCntb < cntb[i]:
        valb = i
        maxCntb = cntb[i]

for i in b:
    if maxCntb1 < cntb[i] and valb != i:
        maxCntb1 = cntb[i]
        valb1 = i

if valb != vala:
    res = 0
    for i in a:
        if i != vala:
            res += 1
    for i in b:
        if i != valb:
            res += 1
    print(res)
else:
    resa = 0
    resb = 0
    resa1 = 0
    resb1 = 0
    for i in a:
        if i != vala:
            resa += 1
        if i != vala1:
            resa1 += 1
    for i in b:
        if i != valb:
            resb += 1
        if i != valb1:
            resb1 += 1
    print(min(resa + resb1, resa1 + resb))

#print(a, b, vala, valb)

Measured memory_bytes: 14012