akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL n, a[100000], s[60];

LL f() {
	int c = 0;
	dec(j, 60) {
		int p = -1;
		incID(i, c, n) {
			if(bit(a[i], j) == 1) { p = i; break; }
		}
		if(p == -1) { continue; }
		inc(i, n) {
			if(i == p) { continue; }
			if(bit(a[i], j)) { a[i] ^= a[p]; }
		}
		swap(a[c++], a[p]);
	}
	LL x = 0;
	inc(i, n) { x ^= a[i]; }
	return x;
}

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i,  n) {
	inc(j, 60) {
		s[j] ^= bit(a[i], j);
	}
	}
	inc(i,  n) {
	inc(j, 60) {
		if(s[j] == 1 & bit(a[i], j) == 1) { a[i] ^= (1LL << j); }
	}
	}
	
	LL ans = 0;
	inc(j, 60) { if(s[j] == 1) { ans += (1LL << j); }; }
	ans += f() * 2;
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

int main(){

     long long n,b=0,c=0;

     cin>>n;

     long long a[n];

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

     for(int i=0;i<n-1;i++){

      if(a[i]>a[i+1] || a[i]==a[i+1]){ 

       b++;

     c=max(b,c);

    // cout<<c<<" ";

}

   else b=0;

}

      cout<<c<<endl;

     

     

}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int n, k;
void solve(){
	cin>>n>>k;
	int heights[n];
	for(int i = 0; i < n; i++) cin>>heights[i];
	int dp[n];
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		dp[i] = INT_MAX;
		for(int j = 1; j <= k; j++){
			if(i - j >= 0){
				dp[i] = min(dp[i], dp[i - j] + abs(heights[i] - heights[i - j]));
//				cout<<dp[i]<<" ";
			}
			else break;
		}
//		cout<<dp[i]<<" ";
	}
//	cout<<endl;
	cout<<dp[n - 1];
}
int main(){
	io;
	solve();
	return 0;
}


Measured memory_bytes: 4420
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


long long int min(long long int a,long long int b){

    if(a>=b){return b;}
    return a;
}

int main(void){
int n;
long long int sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
    if(i%15!=0&&i%3!=0&&i%5!=0){sum=sum+i;}
    else{continue;}
}
printf("%lld",sum);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    string s,t;cin>>s>>t;
    ll g = __gcd(n,m);
    for(ll i=0;i<g;i++)if(s[i*(n/g)]!=t[i*(m/g)])return cout<<"-1" , 0;
    cout<<(n*m)/g;
}

Measured memory_bytes: 640
from sys import stdin
input=[]
for i in range(3):
  input.append(stdin.readline().rstrip().split())

#print(input)
N=int(input[0][0])
V=[]
for i in input[1]:
    V.append(int(i))
C=[]
for i in input[2]:
    C.append(int(i))

#print(N,V,C)
diff=[]
for i in range(len(V)):
    diff.append(V[i]-C[i])

output=0
for i in diff:
    if i>0:
        output+=i

print(output)


Measured memory_bytes: 3064
package main

import (
	"fmt"
	"strconv"
)

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var s string
	var n int
	ans := 754
	fmt.Scan(&s)
	for i := 0; i < len(s)-2; i++ {
		n, _ = strconv.Atoi(s[i : i+3])
		if abs(753-n) < ans {
			ans = abs(753 - n)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, a, res = 0;
    cin>>n;
    int cnt[66][2] = {};
    while(n--){
        cin>>a;
        rep(i, 63) {
            cnt[i][a >> i & 1]++;
        }
    }
    rep(i, 63) {
        res += (int)pow(2, i) % MOD * cnt[i][0] % MOD * cnt[i][1] % MOD;
        res %= MOD;
    }
    cout<<res<<endl;
}


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

int main(){
    int A,B,C,D;
    int count1,count2;
    cin >> A >> B >> C >> D;

    while(A>0&&C>0){
        C-=B;
        if(C<=0){
            count1++;
        }

        A-=D;
        if(A<=0){
            count2++;
        }
    }

    if(count1==1){
        cout << "Yes" << endl;
    }

    else if(count2==1){
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
   s=list(input())
   from collections import Counter
   c=Counter(s)# ()にカウンターの対象のリストの変数名
   x=c['a']
   y=c['b']
   z=c['c']
   if (x-1)*2<=y+z and (y-1)*2<=x+z and (z-1)*2<=x+y:
       print('YES')
   else:
       print('NO')

resolve()

Measured memory_bytes: 49512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int x;
	cin >> x;
    if (x>=30) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
	return 0;
}


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

using namespace std;

void __start__() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef MY
    freopen("/home/ainur/CLionProjects/wow/input.txt", "r", stdin);
    freopen("/home/ainur/CLionProjects/wow/output.txt", "w", stdout);
#else
    //freopen("search.in", "r", stdin);
   // freopen("search.out", "w", stdout);
#endif
}

#define sz(x) (int)x.size()
#define yes cout<<"Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ft first
#define sd second
#define read(a) for(auto &qwqw:a)cin >> qwqw;
#define print(a) for(auto qwqw:a)cout<<qwqw<<' ';
#define print_plus(a) for(auto qwqw:a)cout<<qwqw+1<<' ';
//#define FOR(i, b, n) for(int i=b;i<n;i++) #define FOR(i, n) FOR(i, 0, n) #define FOR(n) FOR(i, 0, n)
mt19937_64 rnd(time(0));
#define int long long
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vb = vector<bool>;
using pii = pair<int, int>;
using vd = vector<long double>;


int log2(int q) {
    int c = 0;
    while (q) {
        q >>= 1;
        c++;
    }
    return c;
}

void test_case() {
    int x, n, ans = -132132123313232132;
    cin >> x >> n;
    set<int> s;
    for (int i = 0, q; i < n; ++i) {
        cin >> q;
        s.insert(q);
    }
    for (int j = -200; j <= 200; ++j) {
        if(s.count(j)==0 && abs(ans-x) > abs(j-x))
            ans = j;
    }


    cout << ans;

}

signed main() {
    __start__();
    int Q = 1;
    //cin >> Q;
    while (Q--) {
        test_case();
    }
}





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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int cnt[100001] = {};
	int N;
	cin >> N;
	rep(i, N) {
		int a;
		cin >> a;
		cnt[a]++;
		if(a>0)cnt[a - 1]++;
		if(a<100000)cnt[a + 1]++;
	}
	int maxn = 0;
	rep(i, 100001) {
		maxn = max(maxn, cnt[i]);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int b[105];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n - 1) cin >> b[i];

  int ans = 0;
  ans += b[0];
  FOR(i, 1, n - 1) {
    ans += min(b[i], b[i - 1]);
  }
  ans += b[n - 2];

  cout << ans << endl;
}


Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;
 
void task(){
 	string a,b; cin >> a >> b;
 	int mx = 0,mx2 =0;
 	for(int i = 0; i<a.size();i++){
 		mx = max(mx,a[i]-'a');
 	}
 	for(int i = 0; i<b.size();i++){
 		mx2 = max(mx2,b[i]-'a');
 	}
 	sort(all(a));
 	sort(all(b));
 	reverse(all(b));

 	if(a<b) cout << "Yes" << endl;
 	else cout <<"No" << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }
        
return 0;
}




Measured memory_bytes: 3676
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

while 1:
    S = str_input()

    if (S == "-"):
        break

    n = input()
    for i in xrange(n):
        x = input()
        S = S[x:] + S[:x]

    print S

Measured memory_bytes: 6472
a, b, c, d = map(int, input())


def calc(a, b, c, d):
    ops = ['+', '-']
    for i in ops:
        for j in ops:
            for k in ops:
                ans = a
                ans += b if i == '+' else -b
                ans += c if j == '+' else -c
                ans += d if k == '+' else -d
                if ans == 7:
                    return i, j, k


i, j, k = calc(a, b, c, d)
print('{}{}{}{}{}{}{}=7'.format(a, i, b, j, c, k, d))


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

const int INF = 1001001001;

int n, m, x;
int c[12], a[12][12];
int ans = INF;

void dfs(int dps, int buy, int cost, vector<int> d){
  	if(buy){
    	rep(i, m){
        	d[i] += a[dps][i];
        }
      	cost += c[dps];
    }
  
  	if(dps == n-1){
    	bool ok = true;
      	rep(i, m) if(d[i] < x) ok = false;

      	if(ok) ans = min(ans, cost);
      	return;
    }
  
  	dps++;
  	
	dfs(dps, 1, cost, d);
    dfs(dps, 0, cost, d);
}

int main(){
	cin >> n >> m >> x;
  	rep(i, n){
    	cin >> c[i];
      	rep(j, m) cin >> a[i][j];
    }
  
  	vector<int> d(12, 0);
   	dfs(0, 1, 0, d);
    dfs(0, 0, 0, d);

  	if(ans == INF) ans = -1;
  	cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
bool c(int x,int y){
    return y<x;
}
int main() {
    int n;cin>>n;
    vector<int > p;
    for (int i = 0; i < n; ++i){
        int a;cin>>a;
        p.push_back(a);
    }
    int q;cin>>q;
    while(q--){
        //vector<int > v(p);
        int b,e,k;
        cin>>b>>e>>k;
        int ans=count(&p[b],&p[e],k);
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main()

{

    int n;

    cin >> n;

    int dp[n][3],a[n],b[n],c[n];

    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];

    dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];

    for (int i = 1; i < n; ++i)

    {

        dp[i][0] = a[i]+max(dp[i-1][1], dp[i-1][2]);

        dp[i][1] = b[i]+max(dp[i-1][0], dp[i-1][2]);

        dp[i][2] = c[i]+max(dp[i-1][0], dp[i-1][1]);

    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << '\n';

}

Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>a(3*N);
    for(int i = 0; i < 3*N; i++) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int ans = 0;
    for(int i = 3*N-2; i >= N; i-=2) {
        ans+=a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5616
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  long long int i,j;
  long long int n,ans=1e9+1,sum;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i)
    cin>>a.at(i);
  sort(a.begin(),a.end());
  for(i=0;i<101;++i){
    sum=0;
    for(j=0;j<n;++j){
      sum+=pow(a.at(j)-i,2);
      //cout<<sum<<' ';
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int i, j;
	string s,t;
	char cha;
	cin >> s;
	cin >> t;
	for (i = 0;i < s.size();i++) {
		for (j = 0;j < i;j++) {
			if (s[i] < s[j]) {
				cha = s[i];
				s[i] = s[j];
				s[j] = cha;
			}
		}
	}
	for (i = 0;i < t.size();i++) {
		for (j = 0;j < i;j++) {
			if (t[i] > t[j]) {
				cha = t[i];
				t[i] = t[j];
				t[j] = cha;
			}
		}
	}
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

int main()
{
    string s;
    cin >> s;
    for(int i = 1; i < 4; ++i)
    {
        if(s[i-1] == s[i])
        {
            cout << "Bad\n";
            return 0;
        }
    }
    cout << "Good\n";
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;
string a,b,sum;
void check(int z,int x);
int A,B;
int main(void){

    int n;
    cin>>n;
    while(n--){
        a="",b="",sum="";

        cin>>a>>b;
        //cout<<"a="<<a<<"b="<<b<<"sum="<<sum<<endl;
        if(a.length()>80||b.length()>80){
            sum="overflow";
            goto end;
        }
        A=a.length(),B=b.length();
        //cout<<A<<B<<endl;
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        if(A<B)swap(A,B),swap(a,b);
        for(int i=0;i<=A-B;i++){
            b+="0";
        }
        check(0,0);
        //cout<<sum<<endl;
        if(sum.length()>80){
            sum="overflow";
            goto end;
        }
        reverse(sum.begin(),sum.end());
        end:;
        cout<<sum<<endl;
    }
    return 0;
}

void check(int z,int x){
    int i;


    if(a[z]==0)a[z]='0';
    if(b[z]==0)b[z]='0';
    //cout<<a[z]<<"."<<b[z]<<"."<<sum<<endl;
    //cout<<"--"<<z<<endl;
    if(z==81||(z>A&&z>B&&x==1)||(z>=A&&z>=B&&x==0)){
            x=0;
            return;
    }
    i=(int)a[z]-'0' + (int)b[z]-'0' + x,x=0;
    //cout<<"*"<<i<<endl;
    //cout<<"-"<<z<<endl;
    if(i>=10)x=1,i-=10;
    sum+=i+'0';
    //cout<<"+"<<sum<<endl;

    check(z+1,x);

}

Measured memory_bytes: 1204
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
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;

/*
int diff_height[13]   = {0,0,0,0,0,0,0,0,1,1,1,1,1};
int diff_row[13] = {-1,-1,-1,0,0,1,1,1,-1,-1,0,1,1};
int diff_col[13] = {-1,0,1,-1,1,-1,0,1,-1,1,0,-1,1};
*/



int diff_height[13] = {0,0,1,0,1,1,1,0,-1,1,-1,1,1};
int diff_row[13] = {0,1,0,1,0,1,1,-1,1,0,1,-1,1};
int diff_col[13] = {1,0,0,1,1,0,1,1,0,-1,1,1,-1};


int N,M,Q;

bool rangeCheck(int height,int row,int col){
	if(height >= 0 && height <= N-1 && row >= 0 && row <= N-1 && col >= 0 && col <= N-1)return true;
	else{
		return false;
	}
}


void func(){

	char board[N][N][N];

	for(int h = 0; h < N; h++){
		for(int row = 0; row < N; row++){
			for(int col = 0; col < N; col++){
				board[h][row][col] = '*';
			}
		}
	}

	int pile_num[N][N];
	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			pile_num[row][col] = 0;
		}
	}

	char which = '*';
	int ans;

	int input_col,input_row,tmp_height,tmp_row,tmp_col,num;
	bool clearFLG = false;

	char base_color;

	for(int loop = 1; loop <= Q; loop++){
		scanf("%d %d",&input_col,&input_row);
		input_row--;
		input_col--;

		if(pile_num[input_row][input_col] == N)clearFLG = true;

		if(clearFLG)continue;

		if(loop%2 == 1){
			board[pile_num[input_row][input_col]++][input_row][input_col] = 'b';
		}else{
			board[pile_num[input_row][input_col]++][input_row][input_col] = 'w';
		}

		for(int height = 0; height < N; height++){
			for(int row = 0; row < N; row++){
				for(int col = 0; col < N; col++){
					if((loop%2 == 1 && board[height][row][col] != 'b') || (loop%2 == 0 && board[height][row][col] != 'w'))continue;

					base_color = (loop%2 == 1) ? 'b':'w';

					for(int i = 0; i < 13; i++){

						tmp_height = height;
						tmp_row = row;
						tmp_col = col;

						num = 0;

						do{
							num++;

							tmp_height += diff_height[i];
							tmp_row += diff_row[i];
							tmp_col += diff_col[i];

						}while(rangeCheck(tmp_height,tmp_row,tmp_col) == true && board[tmp_height][tmp_row][tmp_col] == base_color);

						if(num >= M){
							clearFLG = true;
							break;
						}
					}
					if(clearFLG)break;
				}
				if(clearFLG)break;
			}
			if(clearFLG)break;
		}

		if(clearFLG){

			if(loop%2 == 1){
				which = 'b';
			}else{
				which = 'w';
			}
			ans = loop;
		}
	}

	switch(which){
	case '*':
		printf("Draw\n");
		break;
	case 'b':
		printf("Black %d\n",ans);
		break;
	case 'w':
		printf("White %d\n",ans);
		break;
	}
}


int main(){

	while(true){
		scanf("%d %d %d",&N,&M,&Q);
		if(N == 0 && M == 0 && Q == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100010;
ll n,s,x[N],p[N],cntl,cntr,ans;
int main(){
	scanf("%lld%lld",&n,&s);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&p[i]),x[i]<s?cntl++:cntr++;
	int l=1,r=n;
	bool dir=p[l]>=p[r];
	while(cntl&&cntr){
		if(p[l]>=p[r]) ans+=dir?x[r]-x[l]:0,p[l]+=p[r],r--,cntr--,dir=0;
		else ans+=dir?0:x[r]-x[l],p[r]+=p[l],l++,cntl--,dir=1;
	}
	cntl?ans+=s-x[l]:ans+=x[r]-s;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
# Date [ 2020-09-19 21:46:14 ]
# Problem [ e.py ]
# Author Koki_tkg

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n, x, m = read_ints()
    query = []
    s = set([])
    while x not in s:
        s.add(x)
        query.append(x)
        x = x * x % m
    
    frm = query.index(x)
    length = len(query) - frm
    total = sum(query[frm:])
    
    ans = sum(query[:frm]) + total * ((n - frm) // length) + sum(query[frm:frm + (n - frm) % length])
    print(ans)

if __name__ == '__main__':
    Main()

Measured memory_bytes: 13132
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>
#include <set>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> mp(h);
    string str;
    vector<int> vh,vw;
    set<int> sh,sw;

    rep(i,h){
        bool flag = false;
        cin >> str;
        rep(j,str.length()){
            if(str[j] == '#'){
                flag = true;
                break;
            }
        }
        if(!flag)sh.insert(i);

        mp[i] = str;
    }

    rep(i,w){
        bool flag = false;
        rep(j,h){
            if(mp[j][i] == '#'){
                flag = true;
                break;
            } 
        }
        if(!flag) sw.insert(i);
    }

    rep(i,h){
        //if(sh.count(i) > 0 ) break;
        rep(j,w){
            if(sw.count(j) == 0 && sh.count(i) == 0 ){
                cout << mp[i][j];
            }
        }
        if(sh.count(i) == 0){
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int limit = 50;
bool visit[limit];
bool graph[limit][limit];

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

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
void dfs(int v, int n) {
	//対象の頂点について訪問済みとする
	visit[v] = true;
	for (int v2 = 0; v2 < n; ++v2) {
		//経路が存在しない場合は無視する
		if (graph[v][v2] == false) continue;
		//訪問済みの頂点は無視する
		if (visit[v2] == true) continue;
		dfs(v2, n);
	}
}

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(limit), b(limit);
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]][b[i]] = true;
		graph[b[i]][a[i]] = true;
	}
	int ans = 0;
	for (int i = 0; i < m; ++i) {
		//各辺を除外して橋となる辺であるか調査する
		graph[a[i]][b[i]] = false;
		graph[b[i]][a[i]] = false;
		for (int j = 0; j < n; ++j) visit[j] = false;
		//除外した状態でdfsで探索
		dfs(0, n);
		bool bridge = false;
		//全ての頂点を訪問できなかった場合、除外した辺は橋である
		//辺を除外することで未連結となっているか調査している
		for (int j = 0; j < n; ++j) {
			if (visit[j] == false) {
				bridge = true;
			}
		}
		if (bridge) ans++;
		graph[a[i]][b[i]] = true;
		graph[b[i]][a[i]] = true;
	}
	cout << ans << endl;
    return;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;

int main(){
  int n,m,t,ans;
  
  string a,b; 

  cin>>n>>m>>t;
  if(n%m==0) ans=t*(n/m);
  else ans=t*(n/m+1);
  

  cout<<ans;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

using namespace std;
int main(){
    int n;std::cin >> n;
    std::cout << 3*n*n << std::endl;
    
}

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

int f(int x){
  if(x%4==0)return x;
  if(x%4==1)return 1;
  if(x%4==2)return x+1;
  if(x%4==3)return 0;
}

signed main(){
  int a,b;
  cin>>a>>b;
  cout<<(f(b)^f(a-1))<<endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int a[111],b[111],c[111],d[111];

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>a[i]>>b[i];
    rep(i,M)cin>>c[i]>>d[i];

    rep(i,N){
        int mi=INT_MAX,t=-1;
        rep(j,M){
            int tmp=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(mi>tmp){
                mi=tmp;
                t=j;
            }
        }
        cout<<t+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a


N, X = map(int, input().split())
x = list(map(lambda x: abs(int(x) - X), input().split()))

ans = x[0]
for i in range(N):
    if x[i]%ans == 0:
        continue
    ans = gcd(ans, x[i])

print(ans)

Measured memory_bytes: 14220
fun main() {
    val (n, d) = nextLongList()
    val d2 = d * d
    var count = 0
    repeat(n.toInt()) {
        val (x, y) = nextLongList()
        if (x * x + y * y <= d2) {
            count++
        }
    }
    println(count)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 63760
from sys import stdin
from itertools import combinations_with_replacement


def get_result(data):
    N, M, Q = data[0]
    cond = data[1:]
    seq = [i+1 for i in range(M)]
    all_seq = combinations_with_replacement(seq, N)
    scores = []
    for seq in all_seq:
        score = 0
        for c in cond:
            if (seq[c[1]-1] - seq[c[0]-1]) == c[2]:
                score += c[3]
        scores.append(score)
    return max(scores)


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 12656
import math
A,B,H,M = map(int,input().split())

#短針は1分間に0.5度動くことに注意
dig = abs((H*30 + M*0.5)-M*6)
if dig > 180:
    dig = 360 - dig

ans = math.sqrt((A**2+B**2)-(2*A*B*math.cos(math.radians(dig))))
print(ans)

Measured memory_bytes: 9320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n)cin >> v[i];

    int ans = 0;
    rep(l, min(n, k) + 1){
        rep(m, l + 1){
            vector<int> j;
            rep(x, m)j.push_back(v[x]);
            rep(x, l - m)j.push_back(v[n-1-x]);
            sort(j.begin(), j.end(), greater<int>());
            int s = j.size();
            rep(x, min(k - l, s)){
                if(j[j.size()-1] < 0)j.pop_back();
                else break;
            }
            int sum = 0;
            rep(x, j.size())sum += j[x];
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

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

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

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    string S;
    cin >> S;
    LL res = 0;
    int cnt = 0;
    for (int i = 0; i < SZ(S); i++) {
        if (S[i] == 'A') cnt++;
        if (S[i] == 'C') cnt = 0;
        if (S[i] == 'B') {
            if (i + 1 < SZ(S) and S[i+1] == 'C') {
                i++;
                res += cnt;
            }
            else cnt = 0;
        }
    }
    cout << res << "\n";
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int a[3],k;
    for (int i = 0;i < 3;++i) cin >> a[i];
    cin >> k;
    while (k && a[0] >= a[1]) {
        k--;
        a[1] *= 2;
    }
    while (k && a[1] >= a[2]) {
        k--;
        a[2] *= 2;
    }
    cout << (a[0] < a[1] && a[1] < a[2] ? "Yes" : "No") << newl;
}

Measured memory_bytes: 3680
ar = []
while True:
  try:
    a, b, c, d, e, f = map(float, raw_input().split())
    x = (c * e - b * f) / (a * e - d * b)
    y = (c * d - f * a) / (b * d - e * a)
    ar.append([x, y])
  except:
    break

for i in ar:
  print("{:.3f} {:.3f}".format(i[0] + 0, i[1] + 0))

Measured memory_bytes: 6376
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)	
#define REP(i,b) FOR(i,0,b)
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
using pi=pair<int,int>;

void chmin(int&a,int b){
	a=a<b?a:b;
}
void chmax(int&a,int b){
	a=a>b?a:b;
}

const int mod=1000000007;
void add(int&a,int b){
	assert(a<mod);
	assert(b<mod);
	a+=b;
	if(a>=mod)a-=mod;
}
void sub(int&a,int b){
	assert(a<mod);
	assert(b<mod);
	a-=b;
	if(a<0)a+=mod;
}
int mul(int a,int b){
	assert(a<mod);
	assert(b<mod);
	return a*b%mod;
}
int modPow(int x,int n){
	int res=1;
	while(n){
		if(n&1)res=mul(res,x);
		x=mul(x,x);
		n>>=1;
	}
	return res;
}
int modInv(int x){
	return modPow(x,mod-2);
}
const int Size=2017000;
int fact[Size],factInv[Size];
void PreCalc(){
	fact[0]=1;
	FOR(i,1,Size)
		fact[i]=mul(fact[i-1],i);
	factInv[Size-1]=modInv(fact[Size-1]);
	for(int i=Size-2;i>=0;i--)
		factInv[i]=mul(factInv[i+1],i+1);
}
int Bin(int a,int b){
	assert(0<=a);
	assert(0<=b);
	return mul(mul(fact[a+b],factInv[a]),factInv[b]);
}

int Wafrelka(int sx,int sy,int tx,int ty,int x1,int y1,int x2,int y2){
	int res=0;
	FOR(i,x1,x2+1){
		add(res,mul(mul(Bin(i-sx,y2-sy),Bin(tx-i,ty-(y2+1))),y2-sy+1+i-sx));
		sub(res,mul(mul(Bin(i-sx,(y1-1)-sy),Bin(tx-i,ty-y1)),(y1-1)-sy+1+i-sx));
	}
	FOR(i,y1,y2+1){
		add(res,mul(mul(Bin(x2-sx,i-sy),Bin(tx-(x2+1),ty-i)),x2-sx+1+i-sy));
		sub(res,mul(mul(Bin((x1-1)-sx,i-sy),Bin(tx-x1,ty-i)),(x1-1)-sx+1+i-sy));
	}
	return res;
}

signed main(){
	PreCalc();
	int x[6],y[6];
	REP(i,6)x[i]=read();
	REP(i,6)y[i]=read();
	int ans=0;
	REP(a,2)REP(b,2)REP(c,2)REP(d,2){
		int w=Wafrelka(x[a]-1+a,y[b]-1+b,x[4+c]+c,y[4+d]+d,x[2],y[2],x[3],y[3]);
		if(a^b^c^d)
			sub(ans,w);
		else
			add(ans,w);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 31744
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string S;
    cin >> S;
    int l = S.length();


    int bs1=0;
    int bs2=0;

    for(int i=0;i<l;i++){
        if (i%2==0){
            if (S[i] == '1'){
                bs1++;
            }
            else{
                bs2++;
            }
        }
        else{
            if (S[i] == '1'){
                bs2++;
            }
            else{
                bs1++;
            }      
        }
    }

    cout << min(bs1,bs2) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

void chmin(int &a, int b) { if (a > b) a = b; }


int N, A, B, C;
vector<int> L;


int rec(int i, int a, int b, int c) {
    if (i == N) {
        if (!a || !b || !c) return INF;
        return abs(a - A) + abs(b - B) + abs(c - C); 
    }

    int res0 = rec(i + 1, a       , b       , c       );
    int res1 = rec(i + 1, a + L[i], b       , c       ) + (a ? 10 : 0);
    int res2 = rec(i + 1, a       , b + L[i], c       ) + (b ? 10 : 0);
    int res3 = rec(i + 1, a       , b       , c + L[i]) + (c ? 10 : 0);
    
    return min({res0, res1, res2, res3});
}


int main(){
    cin >> N >> A >> B >> C;
    L.resize(N);

    rep(i, N) cin >> L.at(i);

    cout << rec(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
l = int(input())

if l <= 60:
    n = 2
    print(n, l)
    for i in range(l):
        print(1, n, i)
    exit()

p = []
temp = l
while temp > 0:
    p.append(temp % 2)
    temp //= 2

ans = []
res = []
n = len(p)
temp = 1
for i in range(n - 1):
    ans.append([i + 1, i + 2, 0])
    ans.append([i + 1, i + 2, temp])
    temp *= 2

m = l - temp + 1
s = n
fuga = temp
while m > 0 and s > 0:
    #print(s, temp, m)
    if m > temp:
        m -= temp
        ans.append([s, n, fuga])
        fuga += temp
        #print(m)
    temp //= 2
    s -= 1

print(n, len(ans))
t = 1
for x in ans:
    print(x[0], x[1], x[2])

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

Graph G;
vector<int> d; // d[i]根から頂点iまでの距離
void Dfs(int v, int parent)
{ 
    for (auto e : G[v])
    {
        if (e.first == parent) continue; // 逆流を防ぐ(探索の肝！)
        d[e.first] = d[v] + e.second;
        Dfs(e.first, v);
    }
}

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

    int u, v, w;
 
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N - 1; ++i)
    {
        cin >> u >> v >> w;
        --u; --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    d.assign(N, 0);
    Dfs(0, -1);

    for (auto ans : d) cout <<(ans & 1)<< endl;

    return 0;
};


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

int N;

int main()
{
	int dmin = 100;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		int A;
		scanf("%d", &A);
		int d = 0;
		while (A % 2 == 0) {
			A /= 2;
			++d;
		}
		dmin = min(dmin, d);
	}
	printf("%d\n", dmin);
	return 0;
}


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

const static ll MOD = (1e+9);

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}
ll get_s(ll a,ll b,ll c, ll d,ll e, ll g){
    ll x1 = c-a,x2 = e-a,y1 = d-b,y2 = g-b;
    return(abs(x1*y2-x2*y1));
}

int main(){
    ll S;cin>>S;
    ll y = (S%MOD == 0 ? S/MOD:S/MOD+1);
    ll x = abs(y*MOD-S);
    cout<<0<<' '<<0<<' '<<MOD<<' '<<1<<' '<<x<<' '<<y<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int maxLen(string str);

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int maxLength = 0;
    for (int i = 0; i < N; i++)
    {
        maxLength = max(maxLength, maxLen(S.substr(i)));
    }

    cout << maxLength;
    return 0;
}

int maxLen(string str)
{
    int size = str.size();
    vector<int> zMaxLength(size, 0);
    zMaxLength[0] = size;
    int i = 1, j = 0;
    while (i < size)
    {
        while (i + j < size && str[j] == str[i + j])
        {
            ++j;
        }
        zMaxLength[i] = j;
        if (j == 0)
        {
            ++i;
            continue;
        }
        int k = 1;
        while (i + k < size && k + zMaxLength[k] < j)
        {
            zMaxLength[i + k] = zMaxLength[k];
            ++k;
        }
        i += k;
        j -= k;
    }
    int maxLen = 0;
    for (int i = 1; i < size; i++)
    {
        maxLen = max(maxLen, min(zMaxLength[i], i));
    }
    return maxLen;
}

Measured memory_bytes: 256
use proconio::{marker::*, *};
use std::cmp::Ordering;
use std::collections::BinaryHeap;

#[derive(Copy, Clone, Eq, PartialEq)]
struct State {
    cost: usize,
    position: (usize, usize),
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        other
            .cost
            .cmp(&self.cost)
            .then_with(|| self.position.cmp(&other.position))
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other: &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

fn inside(y: i32, x: i32, h: usize, w: usize) -> bool {
    0 <= y && y < h as i32 && 0 <= x && x < w as i32
}

fn main() {
    input! {
        h: usize,
        w: usize,
        c: (Usize1, Usize1),
        d: (Usize1, Usize1),
        s: [Chars; h],
    }

    let mut heap = BinaryHeap::new();
    let mut costs = vec![vec![1_000_000_000usize; w]; h];

    costs[c.0][c.1] = 0;
    heap.push(State {
        cost: 0,
        position: c.clone(),
    });

    let dd = vec![1, 0, -1, 0, 1];
    while let Some(State { cost, position }) = heap.pop() {
        let (y, x) = position;
        if cost > costs[y][x] {
            continue;
        }
        for i in 0..4 {
            let (ny, nx) = (y as i32 + dd[i], x as i32 + dd[i+1]);
            if !inside(ny, nx, h, w) {
                continue
            }

            let (ny, nx) = (ny as usize, nx as usize);

            if s[ny][nx] == '#' || cost >= costs[ny][nx] {
                continue;
            }

            costs[ny][nx] = cost;
            heap.push(State {
                cost,
                position: (ny, nx),
            });
        }

        for yy in -2..=2 {
            for xx in -2..=2 {
                let (ny, nx) = (y as i32 + yy, x as i32 + xx);
                if !inside(ny, nx, h, w) {
                    continue
                }

                let (ny, nx) = (ny as usize, nx as usize);

                if s[ny][nx] == '#' || cost + 1 >= costs[ny][nx] {
                    continue;
                }

                costs[ny][nx] = cost + 1;
                heap.push(State {
                    cost: cost + 1,
                    position: (ny, nx),
                });
            }
        }
    }

    println!("{}", if costs[d.0][d.1] != 1_000_000_000 { costs[d.0][d.1] as i32 } else { -1 });
}


Measured memory_bytes: 15056
S = input()
ans = 0
acgt = ['A', 'C', 'G', 'T']
for i in range(len(S)):
    for j in range(i+1, len(S)+1):
        s = S[i:j]
        tmp = 0
        for ss in s:
            if ss not in acgt: break
            tmp += 1
        ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define int long long
#define pb push_back
#define getMat(v, n, m, val) vector<vector<int>> v(n,vector<int>(m, val))
#define lb lower_bound
#define up upper_bound
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define size(v) (int)v.size()
using namespace std;
//const int mod = 1e9+7;

int power(int a, int b, int mod){
    if(b == 0) return 1;
    int res = power(a, b/2, mod);
    res = res*res%mod;

    if(b&1) res = res*a%mod;
    return res;
}

int32_t main(){
    fastio;
    int n, x, m; cin >> n >> x >> m;

    unordered_map<int,int> mp;
    vector<int> v;
    int val = x,idx=0;
    while(true){
        if(mp.count(val)>0){
            idx = mp[val];
            break;
        }
        mp[val] = idx++;
        v.pb(val);
        val = power(val,2,m);
    }

    vector<int> pre(size(v), 0);
    pre[0] = v[0];
    for(int i=1; i<size(pre); i++){
        pre[i] = pre[i-1]+v[i];
    }

    int ans = 0;
    if(n <= size(v)){
        ans += pre[n-1];
    }else{
        int last = (idx-1)>=0?pre[idx-1]:0;
        // for(int x: pre) cout << x << " ";
        // cout << endl;
        ans += last;
        int rep = ((n-idx)/(size(v)-idx));
        ans += rep*(pre[size(v)-1]-last);

        int f = ((n-idx)%(size(v)-idx))-1;
        if(f >= 0) ans += pre[idx+f]-last;
    }
    cout << ans << endl;
    return 0;
}

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

#define INF (1 << 29)

int main(){
  int n;
  vector<int> a;
  int temp;
  scanf("%d",&n);
  for(int i = 0;i < n;++i){
    scanf("%d",&temp);
    a.push_back(temp);
  }
  sort(a.begin(), a.end());
  double ans = 0;
  for(int i = 0;i <= n - 4;++i){
    ans = max(ans, (double)((double)(a[n - 1] + a[n - 2]) / (double)(a[i + 1] - a[i])));
  }
  ans = max(ans, (double)((double)(a[n - 3] + a[n - 4]) / (double)(a[n - 1] - a[n - 2])));
  ans = max(ans, (double)((double)(a[n - 1] + a[n - 4]) / (double)(a[n - 2] - a[n - 3])));
  printf("%.6lf\n",ans);
  return 0;
}


Measured memory_bytes: 3308