akhauriyash/Code-Regression huggingface dataset:
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

void solve(int test_case) {//209
	int n,m;
	cin>>n>>m;
	unordered_map<int, unordered_set<int>> ma;
	while(m--) {
		int a,b;
		cin>>a>>b;
		if(ma.count(a)==0)ma[a]=unordered_set<int>();
		if(ma.count(b)==0)ma[b]=unordered_set<int>();
		ma[a].insert(b);
		ma[b].insert(a);
	}
	bool contains= 0;
	for(auto i:ma[1]) {
		if(ma[i].count(n))contains=1;
	}
	if(contains)cout<<"POSSIBLE"; else cout<<"IMPOSSIBLE";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 41600
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int a[512][512],d[64][64];
ll w[3][64];
int n,c;
int main(){	FIN;
	cin>>n>>c;
	fore(i,0,c) fore(j,0,c)cin>>d[i][j];
	fore(i,0,n) fore(j,0,n) cin>>a[i][j],a[i][j]--;
	fore(r,0,3) fore(k,0,c) fore(i,0,n) fore(j,0,n)
		if((i+j)%3==r) w[r][k]+=d[a[i][j]][k];
	ll ans=1e17;
	fore(i,0,c) fore(j,0,c) fore(k,0,c) {
		if(i==j||i==k||j==k) continue;
		ans=min(ans,w[0][i]+w[1][j]+w[2][k]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

bool is_prime(int n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

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

  int a, d, n;
  while (true) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) break;
    int cnt = 0;
    lint p = a, ans = 0;
    while (true) {
      if (is_prime(p)) cnt++;
      if (cnt == n) {
        ans = p;
        break;
      }
      p += d;
    }
    cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<map>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int n;
int a[100005];
int main()
{
	read(n);
	for(int i=0;i<n;i++)
		read(a[i]);
	sort(a,a+n);
	int ans1=0;
	int i=n-2;
	for(i;i>=0;i--)
		if(a[i]==a[i+1])
		{
			ans1=a[i];
			break;
		}
	int ans2=0;
	for(i=i-2;i>=0;i--)
		if(a[i]==a[i+1])
		{
			ans2=a[i];
			break;
		}
	cout<<1ll*ans1*ans2<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
ll a[223456]/*,used[223456]*/;
std::map<ll,ll> mapp;
ll p[40];
int main()
{
    int n;
    cin >> n;
    mapp.clear();
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
        mapp[a[i]]++;
    }
    p[0]=1;
    for (int i=1;i<40;i++)
    {
        p[i]=p[i-1]<<1;
    }
    //memset(used,0,sizeof(used));
    sort(a,a+n,greater<ll>());
    int ans=0;
    for (int i=0;i<n;i++)
    {
        if(mapp[a[i]]<=0) continue;
        mapp[a[i]]--;
        for (int j=39;j>=0;j--)
        {
            ll t=p[j]-a[i];
            if (t<=0||t>=INT_MAX) continue;
            if (mapp[t]>0)
            {
                mapp[t]--;
                //used[i]=1;
                ans++;
                //cout <<i<<" "<< t << endl;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 52736
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int[][] matrix = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                matrix[i][j] = sc.nextInt();
            }
        }

        int[] a = new int[3];
        int[] b = new int[3];
        a[0] = 0;
        b[0] = matrix[0][0] - a[0];
        b[1] = matrix[0][1] - a[0];
        b[2] = matrix[0][2] - a[0];
        a[1] = matrix[1][0] - b[0];
        a[2] = matrix[2][0] - b[0];
        
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (matrix[i][j] != a[i] + b[j]) {
                    System.out.println("No");
                    return;
                }
            }
        }
        
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23892
// g++ -std=c++11 test.cpp && ./a.out
// g++ -std=c++11 bfs.cpp && cat bfs.txt | ./a.out

#include <algorithm>
#include <iostream>
#include <queue>
#include <functional>
#include <numeric>
#include <math.h>

using namespace std;

#define PRINT(A) {for (int i = 0; i < A.size(); i++) { cout << A[i] << " ";} cout << endl;}
#define SUM(A) accumulate(A.begin(), A.end(), 0)
#define MAX(A) *max_element(A.begin(), A.end())
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

bool solve(int K){
    if (K%7 == 0) {
        K = K/7;
    }
    int num = 0;
    REP(i, K) {
        num = (num * 10 + 1) % K;
        if (num == 0) {
            cout << i+1 << endl;
            return true;
        }
    }
    return false;
}

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

    if (!solve(K)) {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
n=int(input())
a=list(map(int, input().split()))
x=[0 for i in range(n)]
sum=0
for i in range(n):
    if i%2==0:
        sum=sum+a[i]
    else:
        sum=sum-a[i]

x[0]=sum//2

for i in range(1, n):
    x[i]=a[i-1]-x[i-1]

x=map(lambda t:t*2, x)
x=map(str, x)

ans=" ".join(x)

print(ans)


Measured memory_bytes: 85092
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


string s;
int main() {
	cin >> s;
	REP(i, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}	


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],cnt2=0,cnt0=0;
    map<ll,ll> mp;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    for(auto p:mp){
        if(p.second%2==0) cnt2++;
        cnt0++;
    }
    if(cnt2%2==0) cout<<cnt0<<endl;
    else cout<<cnt0-1<<endl;

    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> time(5, 0);
  for (auto i = 0; i < 5; i++)
    cin >> time[i];
  ll min_time = time[0];
  for (auto i = 1; i < 5; i++)
  {
    min_time = min(min_time, time[i]);
  }
  ll res = ((N + min_time - 1) / min_time) + 5 - 1;

  cout << res << endl;

  return 0;
}


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

int main() {
	int a,b,c,d,e,f;
	cin >> a >> b >> c;
	if((a <= b) && (a <= c)) {
		d = a;
		if(b <= c) {
			e = b;
			f = c;
		} else {
			e = c;
			f = b;
		}
	} else if((b <= a) && (b <= c)) {
		d = b;
		if(a <= c) {
			e = a;
			f = c;
		} else {
			e = c;
			f = a;
		}
	} else if((c <= a) && (c <= b)) {
		d = c;
		if(a < b) {
			e = a;
			f = b;
		} else {
			e = b;
			f = a;
		}
	}
	cout << d << " " << e << " " << f << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n, d, x;
  ll ans = 0;
  cin >> n >> d >> x;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int days = 1;
    while (days <= d) {
      ans++;
      days += a[i];
    }
  }
  cout << ans + x << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var sb = new StringBuilder();
        for (int i = 0; i < s.Length; i++)
        {
            switch (s[i])
            {
                case '0':
                    sb.Append('0'.ToString());
                    break;
                case '1':
                    sb.Append('1'.ToString());
                    break;
                case 'B':
                    if (sb.Length != 0)  sb.Length -= 1;
                    break;
            }
        }

        var ans = sb.ToString();
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(void) {
	int a,b,c,d;
	scanf("%d %d %d", &a,&b,&c);
	if(a>b)
	{
		d = a;
		a = b;
		b = d;
	}
	if(b>c)
	{
		d = b;
		b = c;
		c = d;
	}
	if(a>b)
	{
		d = a;
		a = b;
		b = d;
	}
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}


Measured memory_bytes: 2140
import java.util.Scanner;


public class Main {
	
	static Scanner sc = new Scanner(System.in);	
	static String s;
	static int a, b;
	static int i;
	
	public static void main(String[] args) {

		while(read()){
			solve();
		}
		
	}
	
	static boolean read() {
		
		s = sc.next();
		
		if(s.charAt(0)=='0') return false;
		
		return true;
	}
	
	static void solve() {

		a = 0;
		b = 0;
		
		for(int i=1; s.length() > i; i++){
			if(s.charAt(i) == 'A') a++;
			if(s.charAt(i) == 'B') b++;
			
			
 		}
		
		if(a > b){
			a++;
		}else{
			b++;
		}
		
		System.out.println(a+" "+b);
	}

}

Measured memory_bytes: 11000
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    A, B, C, K=MI() 

    if K<=A:
        print(K)
    elif K>A and K<= A+B:
        print(A)
    elif K >= A + B:
        print(A -(K-A-B))

    


if __name__ == "__main__":
	main()

Measured memory_bytes: 61812
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int mn=INF,mx=0;
    rep(i,n){
      int a,b,c,d,e;
      cin>>a>>b>>c>>d>>e;
      int sum=a+b+c+d+e;
      mn=min(mn,sum);
      mx=max(mx,sum);
    }
    cout<<mx<<" "<<mn<<endl;
  }

}

Measured memory_bytes: 3064
if __name__ == "__main__":
    n = int(input())
    k = int(input())
    x = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if x[i] < abs(k - x[i]):
            ans += x[i] * 2
        else:
            ans += abs(k - x[i]) * 2

    print(ans)



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

int h, w;
char input[2001][2003];
int rl[2001][2000];
struct Rect{
	int h, w;
	Rect() {}
	Rect(int x, int y)
		: h(x), w(y)
	{}
}s[1999];


int main()
{
	int front, rear, pos, w_now, ans(0), t;
	
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; ++i)
		scanf("%s", input[i] + 1);
	if (h == 1 || w == 1) {
		printf("%d\n", h * w);
		return 0;
	}
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j < w; ++j) {
			input[i][j] = input[i][j] != input[i][j + 1];
			input[i][j] ^= input[i - 1][j];
		}
	for (int i = h; i > 2; --i)
		for (int j = 1; j < w; ++j)
			input[i][j] ^= input[i - 2][j];
	for (int i = 2; i <= h; ++i) {
		front = rear = 1;
		while (rear < w) {
			while (rear < w && !input[i][rear])
				++rear;
			while (front < rear) {
				rl[i][front] = rear - front;
				++front;
			}
			++rear, ++front;
		}
	}
	for (int j = 1; j < w; ++j) {
		pos = 0;
		s[pos++] = Rect(rl[2][j], 1);
		for (int i = 3; i <= h; ++i) {
			if (rl[i][j] > s[pos - 1].h)
				s[pos++] = Rect(rl[i][j], 1);
			else {
				w_now = 0;
				while (pos && rl[i][j] <= s[pos - 1].h) {
					w_now += s[pos - 1].w;
					ans < (t = (s[pos - 1].h + 1) * (w_now + 1)) && (ans = t);
					--pos;
				}
				s[pos++] = Rect(rl[i][j], w_now + 1);
			}
		}
		w_now = 0;
		while (pos) {
			w_now += s[pos - 1].w;
			ans < (t = (s[pos - 1].h + 1) * (w_now + 1)) && (ans = t);
			--pos;
		}
	}
	ans < h && (ans = h);
	ans < w && (ans = w);
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXN=200000;
const int totalhuruf=26;
int n,berikut[(MAXN/totalhuruf)+5][totalhuruf],occ[totalhuruf],total;
bool dp[MAXN/totalhuruf+5][totalhuruf],memo[MAXN/totalhuruf+5][totalhuruf];
string input;
vector <int> batas;
void resetocc(){
	for(int i=0;i<totalhuruf;i++)
		occ[i]=1;
	total=totalhuruf;
}
void update(int huruf){
	if(occ[huruf]==1)
		total--;
	occ[huruf]--;
}
void update(char a){
	update((int) a-'a');
}
int pospertama(int awal,int target){
	while((input[awal]-'a')!=target)
		awal++;
	return awal;
}
bool bisagak(int pos,int huruf){			//0 based indeks
	if(pos==(int) batas.size()-1)
		return (occ[huruf]==1);
	if(memo[pos][huruf])
		return dp[pos][huruf];
	memo[pos][huruf]=true;
	bool &ret=dp[pos][huruf];
	ret=false;
	int awal=pospertama(batas[pos],huruf)+1;
	bool bisa[totalhuruf];
	for(int i=0;i<totalhuruf;i++)
		bisa[i]=true;
	while(awal<batas[pos+1])
	{
		bisa[input[awal]-'a']=false;
		awal++;
	}
	for(int i=0;i<totalhuruf;i++)
	{
		if(!bisa[i])
			continue;
		if(bisagak(pos+1,i))
		{
			ret=true;
			berikut[pos][huruf]=i;
			break;
		}
	}
	return ret;
}
void printans(int awal){
	int now=awal;
	for(int i=0;i<batas.size();i++)
	{
		printf("%c",(char) now+'a');
		now=berikut[i][now];
	}
	printf("\n");
}
int main()
{
	memset(memo,false,sizeof(memo));
	cin>>input;
	n=input.length();
	resetocc();
	batas.pb(0);
	for(int i=0;i<n;i++)
	{
		update(input[i]);
		if(total==0)
		{
			resetocc();
			batas.pb(i+1);
		}
	}
	for(int i=0;i<totalhuruf;i++)
	{
		if(bisagak(0,i))
		{
			printans(i);
			break;
		}
	}
}

Measured memory_bytes: 2564
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << x << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ cout << (x[i]) << " ";} cout << endl;

typedef long long ll;

using namespace std;

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

    int A,B;
    cin >> A >> B;

    vector< vector<char> > r(100, vector<char>(100, '.'));
    rep(i, 0, 50){
        rep(j,0,100){
            r[i][j] = '#';
        }
    }
    int count_a = A-1;
    int count_b = B-1;
    rep(i,0,50){
        rep(j,0,100){
            if (i%2==0 && count_a > 0 && j%2 == 0){
                r[i][j] = '.';
                count_a--;

            }  
        }
    }
    rep(i,50,100){
        rep(j,0,100){
            if (i%2==0 && count_b > 0 && j%2 == 0 && i != 50){
                r[i][j] = '#';
                count_b--;

            }
        }
   }
   print("100 100");
   rep(i,0,100){
       rep(j,0,100){
           cout << r[i][j];
       }
       print("");
   }
}


Measured memory_bytes: 256
main = interact $ unlines . map (show . red_black) . read' . lines
 where
  read' ("0 0":_) = []
  read' (wh:xs) = (w, filter is_nonred (zip [0.. ] (concat tss))) : read' xs'
   where
    [w,h] = map read (words wh)
    (tss,xs') = splitAt h xs
    is_nonred (_,c) = c /= '#'

red_black (w,ts) = length (filter is_scanned (until_fix scan ts))
 where
  is_scanned (_,c) = c == '@'
  scan ts' = map paint ts'
   where
    paint (i,c) = if c == '.' && is_adjacent i then (i,'@') else (i,c)
    is_adjacent i = any (\i' -> lookup i' ts' == Just '@') neighbors
     where
      neighbors = filter is_inborder [i-1,i+1,i-w,i+w]
      is_inborder i' = div i' w == div i w || abs (i'-i) == w

until_fix f x = if f x == x then x else until_fix f (f x)

Measured memory_bytes: 5400
#$N=<>;$-=$-=$-$i- --$N-($i+=/W/)for<>=~/./g;print$-$i
$N=<>;$-=$-=$-($N-=/E/),$N+=/W/,$i+=/W/ for<>=~/./g;print$-$i
#$N=-<>;$-=$-=++$N+$-$i-($i+=/W/)for<>=~/./g;print$-$i

Measured memory_bytes: 26956
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int k; cin >> k;
	vector<ll> a(k);
	for( auto &i : a ) cin >> i;
	reverse(a.begin(), a.end());
	ll l = 2, r = 3;
	for( auto m : a ){
		l = (l+m-1)/m*m;
		r = (r+m-1)/m*m;
	}
	if( l == r ){
		cout << -1 << endl;
	} else {
		cout << l << " " << r-1 << endl;
	}
	return 0;
}

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

#define N 100000

int main() {
	static char s[N + 1], t[(N + 1) / 2 + 1];
	int n, i, k;

	scanf("%s", s);
	n = strlen(s);
	k = 0;
	for (i = 0; i < n; i += 2)
		t[k++] = s[i];
	printf("%s\n", t);
	return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n,m;cin>>n>>m;
  ll mod = pow(10, 9) + 7;

  if(n>m)swap(n,m);
  if(n+2<=m){
    cout<<0<<endl;
    return 0;
  }

  ll res=1;
  for(int i=n;i>=1;i--){
    res = res * i % mod;
  }
  for(int i=m;i>=1;i--){
    res = res * i % mod;
  }

  if(n==m){
    res = res * 2 % mod;
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
char s[107];
ll k;
int ans;

int main() {
	scanf("%s %lld", s, &k);
	int l = strlen(s);
	bool flg = 0;
	int cnt = 0;
	for(int i = 0; i < l; i++) {
		if(s[i] == '1') cnt++;
		else {
			flg = 1;
			ans = s[i] - '0';
			break;
		}
	}
	if(!flg) puts("1");
	else {
		if(k > cnt) cout << ans << endl;
		else cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }




vcs splitAll(string s, string t) {
	vcs r;
	for (int p = 0; (p = s.find(t)) != s.npos;) {
		r.pb(s.substr(0, p));
		s = s.substr(p + t.size());
	}
	r.pb(s);
	return r;
}

int BETA;
int ALPH;

char func(char c) {
	int t = (ALPH*((int)(c-'a')) - BETA + 26)%26;
	char ret = 'a' + t;
	return ret;
}

ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a%b) : a; }

int main() {
	int n; cin >> n;
	cin.ignore(1);
	
	for_(i, 0, n) {
		string in;
		getline(cin, in);
		
		int m = (int)in.sz;
		BETA = 0;
		ALPH = 0;
		while (1) {
			if (BETA==26) {
				BETA = 0;
				while (gcd(++ALPH, 26)!=1) { }
			}
			
			string str = in;
			for_(j, 0, m) {
				if (str[j]==' ') continue;
				str[j] = func(str[j]);
			}		
			if (str.find("this")!=str.npos || str.find("that")!=str.npos) {
				in = str;
				break;
			}
			BETA++;
		}
		
		cout << in << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
import itertools
n,m,x=[int(x) for x in input().split()]
book=[]
for i in range(n):
  b=[int(x) for x in input().split()]
  book.append(b)

l=[]
a=itertools.product(range(2),repeat=n)
for i in a:
  l.append(i)

price=[]
for i in range(2**n):
  check_list=[0]*(m+1)
  for j in range(n):
    if l[i][j]==1:
      for k in range(m+1):
        check_list[k]+=book[j][k]
  check=[]
  for p in range(1,m+1):
    if check_list[p]<x:
      check.append(False)
  if check==[]:
    price.append(check_list[0])

if price==[]:
  print("-1")
else:
  print(min(price))

Measured memory_bytes: 9660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<long long, long long>
#define ff first
#define ss second

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M, K; cin >> N >> M >> K;
    ll a[N+1], b[M+1]; a[0] = b[0] = 0;
    for(int i = 1; i <= N; i++) cin >> a[i], a[i] += a[i-1];
    for(int i = 1; i <= M; i++) cin >> b[i], b[i] += b[i-1];
    int ans = 0;
    for(int i = N, j = 0; i >= 0; i--){
        while(a[i] > K) i--;
        while(j <= M && a[i] + b[j] <= K) ans = max(ans, i+j), j++;
    }
    cout << ans;
}

Measured memory_bytes: 6704
#include<bits/stdc++.h>
using namespace std;
struct node
{
    string s;
    int num;
};
queue <node> qu;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    while(n--)
    {
        node temp;
        cin>>temp.s>>temp.num;
        qu.push(temp);
    }
    long long times = 0;
    while(!qu.empty())
    {
        node temp = qu.front();
        qu.pop();
        if(temp.num > m)
        {
            times += m;
            temp.num -= m;
            qu.push(temp);
        }
        else
        {
            times += temp.num;
            cout<<temp.s<<" "<<times;
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 6364
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll getNUM(char ch){
	if(ch >= '0' && ch <= '9'){
		return ch-'0';
	}else if(ch >= 'A' && ch <= 'Z'){
		return 10+(ch-'A');
	}else{
		return 35+(ch-'a');
	}
}


ll calc(ll P,char buf[20]){

	ll ret = 0;

	for(int i = 0; buf[i] != '\0'; i++){
		ret += getNUM(buf[i]);
	}

	return ret;
}


int main(){

	int N;
	scanf("%d",&N);

	ll NIM = 0,P;
	char buf[20];

	for(int loop = 0; loop < N; loop++){
		scanf("%lld %s",&P,buf);
		NIM ^= calc(P,buf);
	}

	if(NIM == 0){
		printf("lose\n");
	}else{
		printf("win\n");
	}

	return 0;
}

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

int main ()
{
    long long x,a ,b , y, z ;
    scanf("%lld",&x);
    scanf("%lld",&a);
    scanf("%lld",&b);

    y= abs(x-a);
    z= abs(x-b);

    if ( y > z)
        printf("B\n");
    else
        printf("A\n");
    return 0;


}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

//x < yで管理
map<pairII, int> Color;

int GetColor(int x, int y) {
	if (x > y)
		swap(x, y);
	
	return Color[make_pair(x, y)];
}

int main() {
	int i, j, k;

	int N, M, K;

	vector<int> A[100001];
	pairII edge[100000];
	int parentColor[100001] = { 0 };
	cin >> N;
	rep(i, 0, N-1) {
		pairII a;
		cin >> a.first >> a.second;
		if (a.first > a.second)
			swap(a.first, a.second);
		edge[i] = a;
		Color[a] = -1;
		A[a.first].push_back(a.second);
		A[a.second].push_back(a.first);
	}

	queue<int> Q;
	Q.push(1);
	parentColor[1] = -1;
	while (!Q.empty()) {
		int x = Q.front();
		Q.pop();

		int color = 0;
		for (auto y : A[x]) {
			if (parentColor[y] != 0)continue;

			color++;
			if (color == parentColor[x])
				color++;
			parentColor[y] = color;
			
			int s = x, t = y;
			if (s > t)swap(s, t);
			Color[make_pair(s, t)] = color;

			Q.push(y);

		}




	}
	
	K = 0;
	rep(i, 1, N+1) {
		K = max(parentColor[i], K);
	}
	cout << K << endl;
	rep(i, 0, N - 1) {
		cout << Color[edge[i]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 13440
/*
    ->->->->-> Vora Mahammasasim <-<-<-<-<-
*/
#include<bits/stdc++.h>
#define Quick std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define MOD 1e7+7;
using namespace std;





signed main(){

    Quick;
    string s;
    cin>>s;
    if(s[s.size()-1]!= 's') cout<<s+'s';
    else cout<<s+"es";
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,m,q;
  cin >> n >> m >> q;
  vvint city(n+1,vint(n+1));
  rep(i,0,m){
    int l,r;
    cin >> l >> r;
    city[l][r]++;
  }
  rep(i,0,n){
    rep(j,0,n){
      city[i+1][j+1] += city[i][j+1] + city[i+1][j] - city[i][j];
    }
  }
  rep(i,0,q){
    int a,b;
    cin >> a >> b;
    cout << city[b][b] - city[a-1][b] - city[b][a-1] + city[a-1][a-1] << endl;
  }
}

Measured memory_bytes: 2944
def min(a,b); a < b ? a : b; end
N = gets.to_i
H = gets.split.map(&:to_i)
dp = Array.new(N, 0)
(1 ... N).each do |j|
  if j >= 2
    dp[j] = min(dp[j - 2] + (H[j - 2] - H[j]).abs, dp[j - 1] + (H[j - 1] - H[j]).abs) 
  else
    dp[j] = dp[j - 1] + (H[j - 1] - H[j]).abs
  end
end
puts dp[-1]

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int sqrt_n = 700;
int arr[500005], c[500005];
int ans[500005];
int curr = 0;
void add(int ind)
{
    if(arr[c[ind]] == 0)
    {
        curr++;
    }
    arr[c[ind]]++;
}

void rem(int ind)
{
    arr[c[ind]]--;
    if(arr[c[ind]] == 0)
    {
        curr--;
    }
}

bool comp(pair<pii, int> a, pair<pii, int> b)
{
    if(a.f.f/sqrt_n != b.f.f/sqrt_n)
    {
        return a.f < b.f;
    }
    return (a.f.f/sqrt_n & 1) ? (a.f.s < b.f.s) : (a.f.s > b.f.s);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, q;
    cin >> n >> q;
    for(int i=0; i<n; i++)
    {
        cin >> c[i];
        c[i]--;
    }
    vector<pair<pii, int>> queries;
    for(int i=0; i<q; i++)
    {
        int l, r;
        cin >> l >> r;
        l--; r--;
        queries.PB(make_pair(make_pair(l, r), i));
    }
    sort(queries.begin(), queries.end(), comp);
    int curr_left = 0, curr_right = -1;
    for(pair<pii, int> p : queries)
    {
        //cout << p.f.f << " " << p.f.s  << "\n";
        while(curr_left > p.f.f)
        {
            curr_left--;
            add(curr_left);
        }
        while(curr_right < p.f.s)
        {
            curr_right++;
            add(curr_right);
        }
        while(curr_left < p.f.f)
        {
            rem(curr_left);
            curr_left++;
        }
        while(curr_right > p.f.s)
        {
            rem(curr_right);
            curr_right--;

        }
        ans[p.s] = curr;
    }

    for(int i=0; i<q; i++)
    {
        cout << ans[i] << "\n";
    }
    return 0;
}


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

struct Ps{
  int r,c;
  Ps():r(0),c(0){}
  Ps(int r,int c):r(r),c(c){}
  Ps operator+(const Ps&p)const
  { return Ps(r+p.r,c+p.c);  }
  friend istream& operator>>(istream&is,Ps&p)
  {is >> p.r >> p.c; return is;  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w; cin >> h >> w;
  Ps s,g; cin >> s >> g;
  s = s+Ps(-1,-1);
  g = g+Ps(-1,-1);
  bitset<1000> mz[1000];
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      mz[i][j] = []{char c; cin >> c; return c=='.';}();
  optional<int> distance[1000][1000];
  deque<pair<Ps,int>> dq;
  dq.emplace_front(move(s),0);
  while(!dq.empty()){
    auto [ps,di] = dq.front();
    dq.pop_front();
    if(distance[ps.r][ps.c])continue;
    distance[ps.r][ps.c] = di;
    mz[ps.r][ps.c] = 0;
    if(ps.r==g.r && ps.c==g.c)break;
    for(int i = -2; i <= 2; ++i){
      for(int j = -2; j <= 2; ++j){
	Ps nps(ps.r+i,ps.c+j);
	if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
	if(!mz[nps.r][nps.c])continue;
	if(abs(i)+abs(j) > 1){
	  dq.emplace_back(move(nps),di+1);
	} else {
	  mz[nps.r][nps.c] = 0;
	  dq.emplace_front(move(nps),di);
	}
      }
    }
  }
  cout << (distance[g.r][g.c] ? distance[g.r][g.c].value() : -1) << endl;
}


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

#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cerr.tie(NULL);

#define watch(x) cerr << (#x) << " is: " << (x) << endl
#define vw(v)                        \
    cerr << endl                     \
         << endl                     \
         << (#v) << " is: " << endl; \
    for (int B : (v))                \
    {                                \
        cerr << B << " ";            \
    }                                \
    cerr << endl
#define check(x) cerr << "here " << (x) << "?" << endl

#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
ll const MAX = 2147483647, REALMAX = 9223372036854775806;
//const int N = 

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	ll x = 1000;
	int mn = 1e9;
	for(int i = 0; i < n; i++){
		int s; cin>>s;
		if(i == 0) mn = s;
		else{
			if(mn < s){
				ll stock = x / mn;
				x %= mn;
				x += stock * s;
				mn = s;
			}
		}
		//cout<<x<<"\n";
		mn = min(mn, s);
	}
	cout<<x;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define endl ("\n")
#define deb(x) cout << (#x) << " = " << (x) << endl;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail
    
    long long w, h, x, y;
    cin >> w >> h >> x >> y;
    double area = w*h/2.0;
    cout << area << " ";
    if(w%2 == 0 and w/2 == x and h%2 == 0 and h/2 == y)
    {
        cout << 1;
        return 0;
    }
    cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <array>

using namespace std;

void re(int& x);

void re(char* c);
template<class T, class... Ts> void re(T& t, Ts&... ts);

void pr(int x);

void pr(const char *x);

void ps();
template<class T, class... Ts> void ps(const T& t, const Ts&... ts);

#ifdef FFDBG

#else
#define dbg(x...) dsfdsfsdfasd
#endif

#define rep(i, a, b) for(int i = a; i < (b); ++i)

int n;
char s[2100];
int tam[2100];
int grav[2100];
vector<int> g[2100];

void sdfs(int v, int p) {
    tam[v] = (s[v] == '1');
    grav[v] = tam[v];

    for (int x : g[v]) if (x != p) {
        sdfs(x,v);
        tam[v] += tam[x];
        grav[v] += grav[x] + tam[x];
    }
}

bool dfs(int v, int p, int grav_left) {
    //dbg(v,p,grav_left);
    int big_grav = -1;
    int big_v = -1;
    int tot_grav = 0;

    for (int x : g[v]) if (x != p) {
        if (grav[x] > big_grav) {
            big_grav = grav[x];
            big_v = x;
        }    
        tot_grav += grav[x];
    }

    if (p == -1) grav_left = tot_grav;
    int rem_grav = min((tot_grav-big_grav)*2, tot_grav);
    grav_left -= rem_grav;

    if (grav_left <= 0) return true; 
    return big_v != -1 && dfs(big_v, v, grav_left);
}

void solve()
{
    re(n,s);
    rep(i,0,n-1) {
        int u,v; re(u,v); u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int ans = 1000000000;
    rep(i,0,n) {
        //if (i != 1) continue;
        sdfs(i,-1);
        if ((grav[i] - tam[i]) % 2 == 0 && dfs(i,-1,-1)) ans = min(ans, grav[i] - tam[i]);
    }

    ps(ans == 1000000000 ? -1 : ans/2);
}

int main() {

    solve();
}

void re(int& x) { scanf("%d", &x); }

void re(char* c) { scanf("%s", c); }
template<class T, class... Ts> void re(T& t, Ts&... ts) { 
    re(t); re(ts...); 
}

void pr(int x) { printf("%d", x); }

void pr(const char *x) { printf("%s", x); }

void ps() { pr("\n"); }
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) { 
    pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); 
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n, m;
  cin >> n >> m;
  vector<int> dp(32768,-1);
  int bc[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int bits=0;
  REP(i, m) {
    int x;
    cin >> x;
    bits = (bits | (1 << x));
  }
  dp[0] = 0;
  REP(i, 10) {
    if(bits & (1 << i))
      REP(j, 16384) {
        if(dp[j] != -1) dp[j+bc[i]] = max(dp[j+bc[i]], dp[j] + 1);
      }
  }
  for(int i = 9; i >= 1 ; --i) {
    if(bits & (1 << i))
      for(;;) {
        if(n >= bc[i] && dp[n] == dp[n - bc[i]] + 1) {
          cout << i;
          n-=bc[i];
        } else break;
      }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    ll n;
    std::cin >> n;
    std::cout << n*(n-1)/2 << std::endl;
}

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

const int MAXN = 1e5 + 5;
int a[MAXN][3], dp[MAXN][3];
int n;

void input();
void solve();

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	input();
	solve();
	return 0;
}

void input() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i][0] >> a[i][1] >> a[i][2];
}

void solve() {
	for (int i = 0; i < 3; i++)
		dp[0][i] = a[0][i];
	for (int i = 1; i < n; i++)
		for (int j = 0; j < 3; j++)
			dp[i][j] = a[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]);
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}


Measured memory_bytes: 2560
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, D = invr()
X = []

for i in range(N):
    X.append(inlist())
c = 0
for i in range(N):
    for j in range(i+1, N):
        dis = 0
        y = X[i]
        z = X[j]
        for d in range(D):
            dis += (y[d] - z[d])**2
        dis = math.sqrt(dis)
        if dis == math.floor(dis):
            c += 1
print(c)


Measured memory_bytes: 3064
import * as fs from 'fs'
import {debug} from '../../../util'

const input = fs.readFileSync('/dev/stdin', 'utf8').split(' ')
const output = (x: any) => console.log(x)
// debug(input)
const [S, W] = input.map(n => parseInt(n, 10))
// debug(S)
// debug(W)

W >= S ? output('unsafe') : output('safe')

Measured memory_bytes: 29604
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

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

	string s,t;
	cin >> s >> t;

	if(n > m){
		swap(n,m);
		swap(s,t);
	}

	
	const ll g = __gcd(n,m);
	const ll l = n / g * m;
	ll ans = l;

	
	rep(i,n){
		const ll li = (l / n) * i;
		if(li % (l/m)) continue;
		const ll j = li / (l / m);
		//cout << i << " " << j << endl;
		if(s[i] != t[j]) ans = -1;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000

void init();
void push(int); //スタックの先頭（頂点）に要素 x を追加します
int pop(); //スタックの先頭（頂点）から要素を取り出します
int isEmpty(); //スタックが空かどうかを調べます
int isFull(); //スタックが満杯かどうかを調べます

int top, S[MAX];

/*initialize 関数は top を 0 とすることでスタックを空にします。
このとき配列（メモリ）の中に要素は残ったままですが、
以降の push 操作によって上書きされます。isEmpty 関数は top が 0 かどうかを
調べスタックが空かどうかを判定します。*/
void init(){
  top = 0;
}

/*push 関数では top を1 つ増やし、その場所に x を追加します。
ただし、スタックが満杯の場合はなんらかのエラー処理を行います。*/
void push(x){
  if(isFull() == 1){
    fprintf(stderr,"erorr!\n");
    exit(8);
  }
  else {
    S[++top] = x;
  }
}

/*pop 関数では、top が指す要素、つまりスタックの頂点の要素を返しつつ、
top の値を１つ減らすことで、頂点の要素を削除します。
ただし、スタックが空の場合はなんらかのエラー処理を行います。*/
int pop(){
  if(isEmpty() == 0){
    fprintf(stderr,"error!\n");
    exit(8);
  }
  top--;
  return S[top+1];
}

int isEmpty(){
  if(top == 0) return 0;
  else return 1;
}

/*isFull 関数はスタックが満杯かどうかを判定します。
例えば、配列が 0 オリジンで容量が MAX で定義されている場合は、
top が MAX-1 以上のときにスタックが満杯の状態になります。*/
int isFull(){
  if(top >= MAX-1) return 1;
  else return 0;
}


int main(){
  int x, y;
  top = 0;
  char s[100];

  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      x = pop();
      y = pop();
      push(x + y);
    }
    else if(s[0] == '-'){
      y = pop();
      x = pop();
      push(x - y);
    }
    else if(s[0] == '*'){
      x = pop();
      y = pop();
      push(x * y);
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
string s;
	



int main()
{
 ll n,k,x;
 cin>>n>>k;
 if(n%k!=0)
x=(n+k)/k;
else
x=n/k;
 cout<<min(n,abs(n-k*x));


}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int cnt = 0,ans=0;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			cnt++;
		}
		else {
			ans = max(cnt, ans);
			cnt = 0;
		}
	}
	ans = max(cnt, ans);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256