akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


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



int main() {

	ll n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	ll ans = 0;


	for (int i = 0; i < n; i++)
	{
		auto up = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		auto dw = c.end() - upper_bound(c.begin(), c.end(), b[i]);

		//cout << up << " " << dw << endl;
		ans += up * dw;

	}
	cout << ans << endl;








	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void) {
 
  // 入力
  char a[4],b[4];
  scanf("%s",a);
  scanf("%s",b);
  int cnt=0;

  for(int i=0;i<3;i++){
    if(a[i]==b[i])cnt+=1;
  }
  
  printf("%d\n",cnt);
 
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x,min = 9999999999999,i;
    cin>>n;
    int f = 1;
    for(i=1; i*i<=n; i++)
    {
        if(n%i==0)
        {
            x = (((n/i)-1)+(i-1));
            if(x<min)
                min = x;
                else if(x == min)
                    break;
        }
    }
    cout<<min<<endl;
    return 0;
}


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

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <= k; j++){
			for(int l = 0; l <= k; l++){
				if(i + j + l <= k && a * (1 << i) < b * (1 << j) && b * (1 << j) < c * (1 << l)){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n);

    int l = -1, r = n - 1;
    while (r - l > 1) {
        int c = (l + r) / 2;
        bool ok = true;
        ll sum = a[c];
        for (int i = 0; i < n; i++) {
            if (i == c) continue;
            if (2 * sum >= a[i]) {
                sum += a[i];
            } else {
                ok = false;
                break;
            }
        }
        if (ok) r = c;
        else l = c;
    }

    cout << n - r << endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 998244353;

template <typename T>
T pow_mod(T n, T p, T m)  // (n^p) % m
{
    if(p == 0) return 1;
    if(p%2 == 1) return pow_mod<T>(n, p-1, m) * n % m;
    else{
        T tmp = pow_mod<T>(n, p/2, m) % m;
        return tmp * tmp % m;
    }
}

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

    vector<long long> comb(K+1, 0);
    comb[0] = 1;
    FOR(i, 1, K+1){
        comb[i] = ((N-i)*comb[i-1])%MOD * pow_mod<long long>(i, MOD-2, MOD);
        comb[i] %= MOD;
    }

    long long ans = 0, factor = pow_mod<long long>(M-1, N-1, MOD);
    REP(k, K+1){
        ans += ((M*factor)%MOD*comb[k]) % MOD;
        ans %= MOD;
        factor *= pow_mod<long long>(M-1, MOD-2, MOD);
        factor %= MOD;
    }
    if(M != 1) cout<<ans<<endl;
    else{
        if(N == 1 || K == N-1) cout<< 1 <<endl;
        else cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,Y,I=0,J=0,K=0;
  cin >> N >> Y;
  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= N;j++){
      if(i + j <= N && 9*i + 4*j + N == Y/1000){
        I = i;
        J = j;
        K = N - i - j;
      }
    }
  }
  if(I || J || K)cout << I << " " << J << " " << K << endl;
  else cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include<iomanip>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
bool sortbysecdesc(const pair<string,ll> &a,const pair<string,ll> &b)
{
       return a.second>b.second;
}
int main() {
	int n;cin>>n;
	vector<pair<double,double>>v;
	loop(n,i,0){
		double x,y;cin>>x>>y;
		v.pb(m_p(x,y));
	}
	sort(allv(v));
	int cnt=0;
	double res=0.0;
	do{
		cnt++;
		loop(n,i,1){
			res+=sqrt(pow(v[i].first-v[i-1].first,2)+pow(v[i].second-v[i-1].second,2));
		}
	}while(next_permutation(allv(v)));
	cout<<fixed<<setprecision(10)<<res/cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN   1000001 
  
// stores smallest prime factor for every number 
int spf[MAXN]; 
static void sieve() 
    { 
        spf[1] = 1; 
        for (int i=2; i<MAXN; i++) 
       
            // marking smallest prime factor for every 
            // number to be itself. 
            spf[i] = i; 
       
        // separately marking spf for every even 
        // number as 2 
        for (int i=4; i<MAXN; i+=2) 
            spf[i] = 2; 
       
        for (int i=3; i*i<MAXN; i++) 
        { 
            // checking if i is prime 
            if (spf[i] == i) 
            { 
                // marking SPF for all numbers divisible by i 
                for (int j=i*i; j<MAXN; j+=i) 
       
                    // marking spf[j] if it is not  
                    // previously marked 
                    if (spf[j]==j) 
                        spf[j] = i; 
            } 
        } 
    } 
     
bool check(int* a,int n){
    map<int,int> m;
    for(int i=0;i<n;i++){
        int x=a[i];
        while(x>1){
            int y=spf[x];
            if(m[y]>0){
                return false;
            }
            m[y]=1;
            while(x%y==0){
                x/=y;
            }
        }
    }
    return true;
}
int main() {
	int n;
	cin>>n;
	int a[n];
	
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	int gcd=a[0];
	for(int i=1;i<n;i++){
	    gcd=__gcd(gcd,a[i]);
	}
	if(gcd!=1){
	    cout<<"not coprime";
	}
	else{
	    sieve();
	    if(check(a,n)){
	        cout<<"pairwise coprime";
	    }
	    else
	    {
	        cout<<"setwise coprime";
	    }
	}
	return 0;
}


Measured memory_bytes: 11508
fun main() {
    val (a, b, c) = readIntList()
    println("$c $a $b")
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 36408
def main():
    a = int(input())
    zorome = 0
    yes = False

    for i in range(a):
        b = input()
        x, y = b.split(' ')
        if int(x) == int(y):
            zorome += 1
            if zorome == 3:
                yes = True
        else:
            zorome = 0
    if yes:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

#define ll long long
ll x,a,b;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>x>>a>>b;
	if(b - a <= 0)
		cout<<"delicious";
	else if(b - a <= x)
		cout<<"safe";
	else
		cout<<"dangerous";
	return 0;
}

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

int main(){
  
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct EdgeA
{
	int to;
	ll cost;
};

void calcAllShortest(vector<vector<EdgeA>>& G, vector<vector<ll>>& d)
{
	auto numV = (int)G.size();
	for (auto i = 0; i < numV; ++i)
	{
		d.push_back(vector<ll>(numV, LLONG_MAX));

		for (auto v : G[i])
		{
			d[i][v.to] = v.cost;
		}
		d[i][i] = 0;
	}

	for (auto k = 0; k < numV; ++k)
	{
		for (auto i = 0; i < numV; ++i)
		{
			for (auto j = 0; j < numV; ++j)
			{
				if (d[i][k] >= LLONG_MAX || d[k][j] >= LLONG_MAX)
				{
					continue;
				}
				auto kd = d[i][k] + d[k][j];
				if (d[i][j] > kd)
				{
					d[i][j] = kd;
				}
			}
		}
	}
}


int main()
{
	int N, M, R;
	cin >> N >> M >> R;
	vector<int> r(R);
	for (auto i = 0; i < R; ++i)
	{
		cin >> r[i];
		--r[i];
	}

	vector<vector<EdgeA>> G(N);
	for (auto i = 0; i < M; ++i)
	{
		int A, B;
		ll C;
		cin >> A >> B >> C;
		--A;
		--B;
		G[A].push_back({ B, C });
		G[B].push_back({ A, C });
	}

	vector<vector<ll>> d;
	calcAllShortest(G, d);

	vector<int> p;
	for (auto i = 0; i < R; ++i)
	{
		p.push_back(i);
	}

	auto ans = LLONG_MAX;
	do
	{
		auto sum = 0ll;
		for (auto i = 0; i < R - 1; ++i)
		{
			sum += d[r[p[i]]][r[p[i + 1]]];
		}
		ans = min(ans, sum);
	} while (next_permutation(p.begin(), p.end()) != false);
	cout << ans << endl;

	return 0;
}

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

int main()
{

   int n;
   cin >> n;
   char a[n] , b[n];
   char c[100];
   for(int i = 0 ; i < n ; i++)
    cin >> a[i];
    for(int i = 0 ; i < n ; i++)
    cin >> b[i];
   for(int i = 0 ; i < n   ; i++)
   {
       cout<<a[i]<<b[i];
   }

    return 0;

}


Measured memory_bytes: 256
import collections
n,m = map(int, input().split())
a = list(map(int, input().split()))
cumsum = [0]
for i in range(n):
  cumsum.append((cumsum[i]+a[i]) % m)
c = collections.Counter(cumsum)
values, counts = zip(*c.most_common())
ans = 0
for i in counts:
  if i >= 2:
    ans += (i*(i-1)) // 2
  else:
    break
print(ans)

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

const int N = 2e5 + 5;
vector< vector<int> > g (N);

vector<long long> diff (N);
vector<long long> ans (N);

void dfs (int node, int p) {
  ans[node] = diff[node] + (p != -1 ? ans[p] : 0);
  for (auto to : g[node]) {
    if (to != p) {
      dfs (to, node);
    }
  }
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int st, et;
    cin >> st >> et;
    st--; et--;
    g[st].emplace_back(et);
    g[et].emplace_back(st);
  }
  while (q--) {
    int s, add;
    cin >> s >> add;
    s--;
    diff[s] += add;
  }
  dfs (0, -1);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 25856
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;
const long long Maxn=1e5;
typedef long long ll;

int main(){
	int a,b,x;
	cin>>a>>b>>x;
	if(a+b>=x&&a<=x) printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[]args) {

		
		Scanner sc = new Scanner(System.in);
		 
		int cnt = sc.nextInt();
		
		int[] nums = new int[cnt];
		
		for (int i = 0 ; i < cnt; i++) {
			
			int num = sc.nextInt();
			
			nums[i] = num;  
			
		}
		// even judge method
		boolean repeatFlg = true;
		int result = 0;
		while (repeatFlg) {
			for (int i = 0 ; i < cnt; i++) {
				
				int num = nums[i];
				
				if (num % 2 == 0) {
					
					nums [i] = num / 2;
				} else {
					repeatFlg = false;
					nums [i] = -1;
					break;
				}
			}
			if (repeatFlg)
				result++;
		}
					
		System.out.println(result);
	}
	
//	public static int judgeAllEven(int result,int[]nums){
//		for (int num :nums) {
//			
//			if (num == -1) {
//				result--;
//				
//				break;
//			}
//		}
//
//		return result;
//	}

}
				
				
				
			

Measured memory_bytes: 21844
// A - Connection and Disconnection

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;

	ll K;
	cin >> K;

	string S3 = S + S + S;
	int k = 0;
	int cnt[3] = {0, 0, 0};
	for (int i=0; i<3; i++) {
		for (int j=0; j<S.size(); j++) {
			if (k == 0) {
				k++;
				continue;
			}

			if (S3[k] == S3[k-1]) {
				cnt[i]++;
				S3[k] = '#';
			}

			k++;
		}
	}

	ll ans;
	if (cnt[1] == cnt[2]) {
		// ABBBパターン
		ans = cnt[0] + cnt[1] * (K-1);
	} else {
		// ABABパターン
		if (K % 2 == 0) {
			ans = (cnt[0] + cnt[1]) * (K / 2);
		} else {
			ans = (cnt[0] + cnt[1]) * (K / 2) + cnt[0];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int main(void)
{
	int n;
	cin >> n;
	vec<pair<int, int>> a(n);
	rep(i, n) cin >> a[i].first;
	rep(i, n) a[i].second = i;
	sort(a.begin(), a.end());
	int count = 0;
	rep(i, n) if ((a[i].second - i) % 2) count++;
	count /= 2;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/ruby
#encoding: utf-8

#!/usr/bin/ruby
#encoding: utf-8
 
a,b,c,d = gets.split.map(&:to_i)
if b <= c or d <= a
  puts 0
  exit
end
s = [a,b,c,d].sort
puts s[2]-s[1]


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

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

    bool flag = false;
    for(int i=0; i<N; i++){
        string color;
        cin >> color;
        if(color == "Y"){
            flag = true;
            break;
        }
    }
    if(flag == true)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

ll mod_pow(ll x, ll n) {
	ll ret = 1;
	while (n > 0) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};
perm p(5000010);
void solve() {
	int n; cin >> n;
	int d = n / 2;
	vector<ll> ra(d + 2);
	rep(i, d+1){
      ll ad=p.comb(d,i)*mod_pow(2,d-i)%mod;
		ra[i + 1] = (ra[i] + ad)%mod;
	}
	ll ans = 0;
	rep(i, d + 1) {
		ll csum = p.comb(d, i)*(ra[d + 1] - ra[d - i+1]);
		csum = (csum%mod + mod) % mod;
      csum=csum*mod_pow(2,d-i)%mod;
        //cout<<csum<<endl;
		ans += csum;
	}
	ans = ans * 2 % mod;
	ll tans = mod_pow(3, n);
	ans = tans - ans;
	if (ans < 0)ans += mod;
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



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

vector<int> to[100005];
vector<int> dist;
int n;

void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u : to[v]) {
        if (u == p) continue;
        dfs(u,d+1,v);
    }
}

vector<int> calc(int x) {
    dist = vector<int>(n);
    dfs(x);
    return dist;
}

int main() {
    int u, v;
    cin >> n >> u >> v;
    u--; v--;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    } 

    vector<int> distU = calc(u);
    vector<int> distV = calc(v);

    int ans = 0;
    rep(i,n) {
        if (distU[i] < distV[i]) {
            ans = max(ans, distV[i]-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13712
ABCD = input()

for i in range(2 ** 3):
    op = format(i, '03b')
    op = op.replace('1', '+').replace('0', '-')
    formula = ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int n,h,w,i,j;
 
  while(1)
  {
      scanf("%d %d",&h,&w);
      if(h==0 && w==0 )
     {
         break;
     }
     for(i=0;i<h;i++)
     {
         for(j=0;j<w;j++)
         {
             printf("#");
         }
         printf("\n");
     }
      printf("\n");
 
  }
return 0;
 
}


Measured memory_bytes: 2072
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
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; }

long n,i,a,sum1,ans1,sum2,ans2;
bool sign1,sign2;

inline void solve(){
  IN(n);
  REP(i,n){
    IN(a);
    if(i==0){
      sum1=a;
      sum2=a;
      if(sum1<=0){
        ans1+=abs(sum1)+1;
        sum1=1;
      }
      if(sum2>=0){
        ans2+=sum2+1;
        sum2=-1;
      }
    }else{
      if(sign1){
        if(sum1+a<=0){
          ans1+=abs(sum1+a)+1;
          sum1=1;
        }else{
          sum1+=a;
        }
        sign1=false;
      }else{
        if(sum1+a>=0){
          ans1+=sum1+a+1;
          sum1=-1;
        }else{
          sum1+=a;
        }
        sign1=true;
      }
      if(sign2){
        if(sum2+a>=0){
          ans2+=sum2+a+1;
          sum2=-1;
        }else{
          sum2+=a;
        }
        sign2=false;
      }else{
        if(sum2+a<=0){
          ans2+=abs(sum2+a)+1;
          sum2=1;
        }else{
          sum2+=a;
        }
        sign2=true;
      }
    }
  }
  OUT(min(ans1,ans2));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++) H[i][0] = '\0';
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
}


Measured memory_bytes: 16972
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '?'){
      s.at(i) = 'D';
    }
  }
  cout << s << endl;
}
        
  

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  for (int i = 0; i < M; i++){
    cin >> h[i] >> w[i];
    h[i]--;
    w[i]--;
  }
  set<pair<int, int>> st;
  for (int i = 0; i < M; i++){
    st.insert(make_pair(h[i], w[i]));
  }
  vector<int> c1(H, 0);
  vector<int> c2(W, 0);
  for (int i = 0; i < M; i++){
    c1[h[i]]++;
    c2[w[i]]++;
  }
  vector<pair<int, int>> C1(H);
  for (int i = 0; i < H; i++){
    C1[i] = make_pair(c1[i], i);
  }
  sort(C1.rbegin(), C1.rend());
  vector<pair<int, int>> C2(W);
  for (int i = 0; i < W; i++){
    C2[i] = make_pair(c2[i], i);
  }
  sort(C2.rbegin(), C2.rend());
  int mx = C1[0].first + C2[0].first;
  bool ok = false;
  for (int i = 0; i < H; i++){
    if (C1[i].first == C1[0].first){
      for (int j = 0; j < W; j++){
        if (C2[j].first == C2[0].first){
          int y = C1[i].second;
          int x = C2[j].second;
          if (!st.count(make_pair(y, x))){
            ok = true;
            break;
          }
        } else {
          break;
        }
      }
      if (ok){
        break;
      }
    } else{
      break;
    }
  }
  if (ok){
    cout << mx << endl;
  } else {
    cout << mx - 1 << endl;
  }
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

deque<ll> make(vector<ll> &A) {
    deque<ll> ret;
    int N = A.size();
    int j = 0, k = N - 1;
    ret.push_back(A[j++]);
    while(1) {
        if (j > k) break;
        ret.push_back(A[k--]);
        if (j > k) break;
        ret.push_front(A[k--]);
        if (j > k) break;
        ret.push_back(A[j++]);
        if (j > k) break;
        ret.push_front(A[j++]);
    }
    return ret;
}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(all(A));
    deque<ll> ret1 = make(A);
    sort(A.rbegin(), A.rend());
    deque<ll> ret2 = make(A);

    ll ans = 0;
    for (int i = 0; i + 1 < ret1.size(); i++) {
        ans += abs(ret1[i] - ret1[i + 1]);
    }

    ll ans2 = 0;
    for (int i = 0; i + 1 < ret2.size(); i++) {
        ans2 += abs(ret2[i] - ret2[i + 1]);
    }
    cout << max({ans, ans2}) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

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

  long long sum = 0;
  for (int i = 0; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum << endl;

  return 0;
}


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

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {


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

            var inputs = new int[N];
            var maxMain = int.MinValue;
            var maxSub = int.MinValue;
            var x = 0;

            for(int i = 0; i < N; i++){
                x = int.Parse(Console.ReadLine());
                inputs[i] = x;
                if(x > maxMain){
                    maxSub = maxMain;
                    maxMain = x;
                    continue;
                }
                if(x > maxSub) maxSub = x;
            }

            for(int i = 0; i< N; i++){
                Console.WriteLine((inputs[i] != maxMain) ? maxMain : maxSub);

            }

            //Console.ReadKey();
           
        }


        public static long modder(){
            return (long)Math.Pow(10,9) + 7;
        }

        public static long GCD(long n, long m){
            
            if(m % n == 0) return n;
            else return GCD(m%n, n);

        }

        public static long LCD(long n, long m){

            return m * n / GCD(n,m);
        }
    }
}


Measured memory_bytes: 17108
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int Q;
	cin >> Q;
	while (Q--) {
		int H, W;
		cin >> H >> W;
		vector<string> S(H);
		for (int i = 0; i < H; ++i) {
			cin >> S[i];
		}
		vector<char> spec;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (S[i][j] != '.') {
					spec.push_back(S[i][j]);
				}
			}
		}
		sort(spec.begin(), spec.end());
		spec.erase(unique(spec.begin(), spec.end()), spec.end());
		int C = spec.size();
		vector<int> lx(C, H), ly(C, W), rx(C, -1), ry(C, -1);
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (S[i][j] != '.') {
					int val = lower_bound(spec.begin(), spec.end(), S[i][j]) - spec.begin();
					S[i][j] = char(val + '0');
					lx[val] = min(lx[val], i);
					ly[val] = min(ly[val], j);
					rx[val] = max(rx[val], i);
					ry[val] = max(ry[val], j);
				}
			}
		}
		vector<bool> used(C, false);
		bool able = true;
		for (int i = 0; i < C; ++i) {
			int ptr = -1;
			for (int j = 0; j < C; ++j) {
				if (used[j]) continue;
				bool flag = true;
				for (int k = lx[j]; k <= rx[j]; ++k) {
					for (int l = ly[j]; l <= ry[j]; ++l) {
						if (S[k][l] != '?' && S[k][l] != char(j + '0')) {
							flag = false;
						}
					}
				}
				if (flag) {
					ptr = j;
					break;
				}
			}
			if (ptr == -1) {
				able = false;
				break;
			}
			used[ptr] = true;
			for (int j = lx[ptr]; j <= rx[ptr]; ++j) {
				for (int k = ly[ptr]; k <= ry[ptr]; ++k) {
					S[j][k] = '?';
				}
			}
		}
		cout << (able ? "SAFE" : "SUSPICIOUS") << endl;
	}
	return 0;
}


Measured memory_bytes: 3024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1) {
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> p(n);
    vector<int> t(n+1,0);
    REP(i,n)cin>>p[i]>>t[i+1];
    vector<vector<int>> dp(n+1,vector<int>(4,INF));
    dp[0][0] = 0;
    int oldpos = 0;
    int flag = -1;
    for(int i = 1;i <= n;++i) {
      bool valid = false;
      for(int j = 1;j <= 3;++j) {
        if(abs(oldpos-p[i-1]) * j <= t[i] - t[i-1] && dp[i-1][j-1] < INF) {
          valid = true;
          dp[i][j] = abs(oldpos-p[i-1]) + dp[i-1][j-1];
        }
      }
      for(int j = 0;j <= 3;++j) {
        if(oldpos * (j+1) + p[i-1] <= t[i] - t[i-1] && dp[i-1][j] < INF) {
          valid = true;
          dp[i][1] = min(dp[i][1],oldpos + p[i-1] + dp[i-1][j]);
        }
      }
      if(!valid && flag == -1)
        flag = i;
      oldpos = p[i-1];
    }
    int mn = INF;
    for(int i = 1; i <= 3;++i) {
      if(dp[n][i] < INF)
      mn=min(mn,dp[n][i]);
    }
    if(flag != -1)
      cout << "NG " << flag << endl;
    else
      cout << "OK " << mn + p[n-1] << endl;
  }
  return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    if(A*C <= B) {
        cout << C;
    }
    else {
        cout << B/A;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long
typedef std::pair<int,int> pii;
inline bool up(int&x,const int y){return x<y?x=y,1:0;}
inline bool down(int&x,const int y){return x>y?x=y,1:0;}
#define N 300005
int n,k,a[N];
int dp[N];
struct segment{
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r
	int mx[N<<2];
	inline void pushup(int rt){
		mx[rt]=std::max(mx[ls],mx[rs]);
	}
	inline void build(int rt,int l,int r){
		mx[rt]=0;
		if(l==r) return;
		int mid=l+r>>1;
		build(lson),build(rson),pushup(rt);
	}
	inline void ins(int rt,int l,int r,int x,int v){
		if(l==r) return mx[rt]=v,void();
		int mid=l+r>>1;
		if(x<=mid) ins(lson,x,v); else ins(rson,x,v);
		pushup(rt);
	}
	inline int qry(int rt,int l,int r,int x,int y){
		if(x<=l&&r<=y) return mx[rt];
		int mid=l+r>>1,ret=0;
		if(x<=mid) up(ret,qry(lson,x,y));
		if(mid<y) up(ret,qry(rson,x,y));
//		std::cerr<<x<<' '<<y<<' '<<ret<<'\n';
		return ret;
	}
} T;
int m;
int main(){
	std::ios::sync_with_stdio(0);
	std::cin>>n>>k;
	rep(i,1,n) std::cin>>a[i],++a[i],up(m,a[i]);
	memset(dp,0,sizeof(dp));
	T.build(1,1,m);
	int ret=0;
	rep(i,1,n){
		int l=std::max(1,a[i]-k),r=std::min(m,a[i]+k);
		dp[i]=T.qry(1,1,m,l,r)+1;
		T.ins(1,1,m,a[i],dp[i]);
		up(ret,dp[i]);
	}
//	rep(i,1,n) std::cerr<<dp[i]<<" \n"[i==n];
	std::cout<<ret<<'\n';
	return 0;
}

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

int main() {


	int a, b;

	cin >> a >> b;

	/*
	n ��<1010�܂ɂ��Ă���͖̂��̏����Ƃ��Ă܂� A,B <= 100 �Ȃ̂ŁA
	�ō��ł� B �̏����10%���v�Z����� 1000 * 0.1(10%�̈Ӗ�) �ł��傤��100%�Ȃ̂�
	1000�ȏ�͒T�����Ȃ��Ă������A�]�T��������1010�ɂ��Ă���B
	*/
	for (int n = 0; n < 1010; n++) {
		/*
		8 /100 �y�сA10/100�͏���ł̌v�Z�B
		�P�O�O���̂W�A�P�O�O���̂P�O;
		���Ȃ݂ɂP�O�O���̂P�O�O�A�܂�P�͏����100���B
		*/
		if (a == n * 8 / 100 && b == n * 10 / 100) {
			cout << n << endl;
			/*
			�����𖞂����A�o�͂ł����ꍇ�� return0 ��Ԃ��Amain�֐��𔲂��Ă���B
			*/
			return 0;
		}
	}
	/*
	if���ŏ����𖞂����Ȃ������ꍇ�Aif�����́@return���͎��s���ꂸ�A
	����cout�܂Ői��ł���B
	*/
	cout << -1 << endl;
}

Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    
    if h == 0 and w == 0:
        break
    else:
        pass
    
    for i in range(h):
        for j in range(w):
            
            if i == 0 or i == h - 1:
                
                print("#", end="")
                
            else:
                
                if j == 0:
                    print("#", end="")
                elif j == w - 1:
                    print("#", end="")
                else:
                    print(".", end="")
            
        print()
    print()


Measured memory_bytes: 7000
from sys import stdin

class DisjointSet(object):
    def __init__(self, n):
        self.parent = [None] * (n+1)
        self.rank = [None] * (n+1)

    def make_set(self, x):
        if self.parent[x] == None:
            self.parent[x] = x
            self.rank[x] = 0

    def find_set(self, x):
        if x != self.parent[x]:
            self.parent[x] = self.find_set(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        self.link(self.find_set(x), self.find_set(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)

def read_and_print_ds(n, q):
    ds = DisjointSet(n)
    for _ in range(q):
        line = [ int(i) for i in stdin.readline().strip().split() ]
        s1 = line[1]
        s2 = line[2]
        if line[0] == 0:
            ds.make_set(s1)
            ds.make_set(s2)
            ds.unite(s1, s2)
        else:
            ds.make_set(s1)
            ds.make_set(s2)
            if ds.same(s1, s2):
                print("1")
            else:
                print("0")

n, q = [ int(i) for i in input().split() ]
read_and_print_ds(n, q)


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll x, y;
    cin >> x >> y;
    cout << x * y / __gcd(x, y) << '\n';
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    min = 10 ** 15
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0 and min > i + n // i - 2:
            min = i + n // i - 2
    print(min)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38768
#include <iostream>

using namespace std;

int cnt[32];

int main(void){
  int n,m,ans;
  
  cin >> n >> m;
  for (int i=0; i<n; i++){
    int k,a;
    cin >> k;
    for (int j=0; j<k; j++){
      cin >> a;
      cnt[a]++;
    }
  }
  ans = 0;
  for (int i=0; i<=m; i++){
    if (cnt[i]==n) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S= input()
N = len(S)
p1  = S[:(N - 1)//2]
p2  = S[(N + 3)//2 - 1:]
# print(p1)
# print(p1[::-1])
# print(p2)
# print(p2[::-1])
if S == S[::-1] and  p1 == p1[::-1] and p2 == p2[::-1]:
    print("Yes")
else:
    print("No")

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

string prans(int i,int j,int k,int l){
    string ret="";
    ret+= to_string(i);
    ret+=" ";
    ret+= to_string(j);
    ret+=" ";
    ret+= to_string(k);
    ret+=" ";
    ret+= to_string(l);
    return ret;
}

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int> > a(h+2,vector<int>(w+2,0));
    vector<string> ans;
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            cin>>a[i][j];
        }
    }
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            if(a[i][j]<1)continue;
            if(a[i][j]%2==0)continue;
            if(j!=w){ans.push_back(prans(i,j,i,j+1));--a[i][j];++a[i][j+1];}
            else if(i!=h){ans.push_back(prans(i,j,i+1,j));--a[i][j];++a[i+1][j];}
            }
    }
    cout<<ans.size()<<endl;
    for(const auto &i:ans){
        cout<<i<<endl;
    }
    return 0;
}

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


int main(){
  while(1){
    int n; cin >> n;
    if(n==0) break;
    vector<long long> page(n);
    for(int i=0; i<n; i++) cin >> page[i];
    sort(page.begin(),page.end());
    page.push_back((long long)1e+15);
    int start=0;
    for(int i=0; i<n; i++){
      if(page[i+1] == page[i]+1) continue;
      else{
	if(i - start != 0){
	  cout << page[start] << "-" << page[i];
	}
	else{
	  cout << page[start];
	}
	start = i+1;
      }
      if(i != n-1) cout << " ";
    }
    cout << "\n";

  }
}

Measured memory_bytes: 1224
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<pair<long long, long long>> a(n), b(m);
  for (int i=0; i<n; i++) cin >> a.at(i).first >> a.at(i).second;
  for (int i=0; i<m; i++) cin >> b.at(i).first >> b.at(i).second;
  for (int i=0; i<n; i++) {
    long long min = 10000000000, num = 0;
    for (int j=0; j<m; j++) {
      long long buf = abs(a.at(i).first - b.at(j).first) + abs(a.at(i).second - b.at(j).second);
      if (buf < min) {
        min = buf;
        num = j+1;
      }
    }
    cout << num << endl;
  }
  return 0;
}


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

enum eCOURSE{
	COURSE_U,
	COURSE_R,
	COURSE_D,
	COURSE_L,
};

struct tDataSet{
	int *pX, *pY, *field;
	eCOURSE* course;
};

const int SIZE_X = 7;
const int SIZE_Y = 11;

bool checkGoal( tDataSet& data ){
	if ( ( *data.pX == 0 && *data.pY == 1 && *data.course == COURSE_U && data.field[ 2*SIZE_X + 1 ] ) ||
		 ( *data.pX == 1 && *data.pY == 1 && *data.course == COURSE_L && data.field[ 1*SIZE_X + 1 ] && !data.field[ 2*SIZE_X + 1 ] ) ){
		return true;
	}
	return false;
}

int main(){
	string s;
	int field[ SIZE_Y * SIZE_X ];

	for ( int i = 0; i < SIZE_Y * SIZE_X; ++i ){
		field[ i ] = 0;
	}

	for ( int i = 1; i < SIZE_Y - 1; ++i ){
		cin >> s;
		for ( unsigned j = 0; j < s.size(); ++j ){
			field[ i*7 + (j+1) ] = static_cast< int >( s[ j ] - '0' );
		}
	}

	s = "";
	int pX = 1, pY = 0;
	eCOURSE course = COURSE_R;

	tDataSet data;
	data.pX = &pX;
	data.pY = &pY;
	data.course = &course;
	data.field = field;

	bool goal = false;

	while ( !goal ){
		int defU = ( 2 * pY ) * SIZE_X + ( pX + 1 );
		int defR = ( 2 * pY + 1 ) * SIZE_X + pX;
		int defD = ( 2 * pY ) * SIZE_X + pX;
		int defL = ( 2 * ( pY - 1 ) + 1 ) * SIZE_X + pX;

		switch ( course ){
			case COURSE_U : 
				if ( field[ defU ] ){
					s += 'U';
					goal = checkGoal( data );
					if ( field[ defL ] ){
						course = COURSE_L;
					}else{
						--pY;
					}
				}else{
					course = COURSE_R;
					++pX;
				}
				break;
			case COURSE_R :
				if ( field[ defR ] ){
					s += 'R';
					goal = checkGoal( data );
					if ( field[ defU ] ){
						course = COURSE_U;
					}else{
						++pX;
					}
				}else{
					course = COURSE_D;
					++pY;
				}
				break;
			case COURSE_D :
				if ( field[ defD ] ){
					s += 'D';
					goal = checkGoal( data );
					if ( field[ defR ] ){
						course = COURSE_R;
					}else{
						++pY;
					}
				}else{
					course = COURSE_L;
					--pX;
				}
				break;
			case COURSE_L :
				if ( field[ defL ] ){
					s += 'L';
					goal = checkGoal( data );
					if ( field[ defD ] ){
						course = COURSE_D;
					}else{
						--pX;
					}
				}else{
					course = COURSE_U;
					--pY;
				}
				break;
			
		}
	}

	cout << s << endl;

	return 0;
}

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

using namespace std;

#define llong long long
#define ii pair<int, int>
#define xx first
#define yy second
#define len(s) ((int)s.size())
#define rep(i,n) for (int i = -1; ++i < n; )
#define rep1(i,n) for (int i = 0; ++i <= n; )

bool ask(llong num) {
  cout << "? " << num << endl;
  char x; cin >> x;
  return x == 'Y';
}

void answer(llong num) {
  cout << "! " << num << endl;
  exit(0);
}

int digcnt(llong num) { return num == 0 ? 0 : digcnt(num / 10) + 1; } 

llong makenum(llong head, llong l, int fill = 9) {
  for (l -= digcnt(head); l > 0; --l) head = head * 10 + fill;
  return head;
}

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

  int ll = 12;
  llong num = 0;
  for (int i = 0; i < ll; ++i) {
    int l = i == 0, r = 9;
    while (l < r) {
      int mid = (r + l) / 2;
      if (ask(makenum(num * 10 + mid, ll))) r = mid;
      else l = mid + 1;
    }
    num = num * 10 + l;
  }
  
  num = makenum(num, ll, 0);
  if (num == (llong)1e11) {
    llong t = 2;
    while (!ask(t)) t *= 10;
    answer(t / 2);
  }
  while (!ask(num - 1)) num /= 10;
  answer(num);

  return 0;
}


Measured memory_bytes: 596
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    int n, m;
    cin >> n >> m;
    auto a = vector<int>(n);
    for (auto& ai : a) {
        cin >> ai;
        ai /= 2;
    }

    const auto exp2 = [](auto x) {
        auto cnt = 0;
        while ((x & 1) == 0) {
            x >>= 1;
            ++cnt;
        }
        return cnt;
    };
    auto mn = large{exp2(a[0])};
    auto mx = large{exp2(a[0])};
    for (auto ai : a) {
        auto e2 = large{exp2(ai)};
        mn = min(mn, e2);
        mx = max(mx, e2);
    }
    if (mn != mx) {
        cout << 0 << endl;
        return 0;
    }

    mn = 1LL << mn;
    for (auto& ai : a) {
        ai /= mn;
    }
    auto l = 1LL;
    for (auto ai : a) {
        l = lcm(l, large(ai));
        if (l > m) {
            cout << 0 << endl;
            return 0;
        }
    }

    auto x = l * mn;
    auto x1 = m / x;
    auto x2 = m / (2 * x);

    cout << (x1 - x2) << endl;
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long int;

const ll INF = 1LL << 60;
ll N;
string s;

void chmin(ll &A, ll B) {
  A = min(A, B);
}

ll dp[1010][1010][12][2];
int main() {
  cin >> N >> s;
  reverse(s.begin(), s.end());
  int L = s.length();

  fill(dp[0][0][0], dp[L+1][0][0], INF);
  dp[0][0][0][0] = 0;

  string pat = "0123456789+";
  
  ll pow_tab[12] = {};
  pow_tab[0] = 1;
  for(int i=1; i<12; i++) {
    pow_tab[i] = pow_tab[i-1] * 10;
  }

  for(int i=0; i<L; i++) {
    for(int j=0; j<=i; j++) {
      for(int k=0; k<=10; k++) {
	for(int f=0; f<2; f++) {
	  if(dp[i][j][k][f] == INF) continue;
	  for(auto c : pat) {
	    int cost = (c != s[i]);
	    if(c == '+') {
	      bool ng = false;
	      // previous char
	      ng |= (k == 0);

	      // leading zero
	      ng |= (f == 1 and k >= 2);

	      if(ng == false) {
		int nk = 0, nf = 0;
		chmin(dp[i+1][j+cost][nk][nf], dp[i][j][k][f]);
	      }
	    }
	    else { // digit
	      ll add = pow_tab[k] * (c - '0');
	      chmin(dp[i+1][j+cost][k+1][c == '0'], dp[i][j][k][f] + add);
	    }
	  }
	}
      }
    }
  }

  /*
  for(int i=0; i<=L; i++) {
    for(int j=0; j<=i; j++) {
      for(int k=0; k<=10; k++) {
	for(int f=0; f<2; f++) {
	  if(dp[i][j][k][f] == INF) continue;
	  fprintf(stderr, "dp[%d][%d][%d][%d] = %lld\n", i, j, k, f, dp[i][j][k][f]);
	}
      }
    }
  }
  */

  const int NONE = L + 10;
  int ans = NONE;
  for(int j=0; j<=L; j++) {
    for(int k=0; k<=10; k++) {
      for(int f=0; f<2; f++) {
	bool ng = false;
	// previous char
	ng |= (k == 0);
	
	// leading zero
	ng |= (f == 1 and k >= 2);
	
	if(ng == false and dp[L][j][k][f] <= N) {
	  ans = min(ans, j);
	}
      }
    }
  }
  cout << (ans == NONE ? -1 : ans) << endl;
  return 0;
}



Measured memory_bytes: 192776
N = int(input())
list=[[int(j) for j in input().split()] for i in range(N)]
#print(list[0][0]) # 配列の要素の抜出し

ans = 'Yes'
for n in range(N):
    dist = int(list[n][0])
    x = int(list[n][1])
    y = int(list[n][2])
    if dist < x + y:
        ans = 'No'
        break
    if dist % 2 != (x + y) % 2: #偶数奇数が一致していなければ
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 60248
package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}



Measured memory_bytes: 19024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    set<int>s;
    int a;
    rep(i,3){
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#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 LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n = 3;
    vi a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    cout << a[2] * 10 + a[1] + a[0] << endl;

}


Measured memory_bytes: 256