akhauriyash/Code-Regression huggingface dataset:
#include <cstdio> 
#include <iostream>
#include<algorithm>
#include <cstring>

using namespace std;

int main(){
	int coin;
	int happy = 0;
	scanf("%d",&coin);
	if(coin >= 500){
		happy += (coin / 500)*1000;
		coin %= 500;
	}
	if(coin >= 5){
		happy += (coin / 5)*5;
	}
	printf("%d",happy);
}

Measured memory_bytes: 3812
A,B=map(float,input().split())
import math
from decimal import *
b=str(B)
#print(b)
b0=int(b[0])
b2=int(b[2])
if len(b)==4:
    b3=int(b[3])
else:
    b3=0
#print(b0,b2,b3)
ans=Decimal(A)*b0+Decimal(A)*b2/10+Decimal(A)*b3/100
print(math.floor(ans))

Measured memory_bytes: 10028
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static long mod = 1000000007;
	
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	long[] A = new long[N];
	long sum = 0;
	for(int i = 0; i < N; i++){
		A[i] = s.nextLong();
		sum += A[i];
	}
	
	long result = 0;
	for(int i = 0; i < N; i++){
		sum -= A[i];
		result = (result + (sum%mod)*A[i])%mod;
	}

	System.out.println(result);

    
  }
}

Measured memory_bytes: 61528
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 10100;
typedef long long ll;
const int mod = 998244353;
const int inv2 = mod + 1 >> 1;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int fac[maxn], ifac[maxn], inv[maxn];
inline ll c(int x,int y){ return (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod; }
int f[maxn][maxn], n;
std::string s0, s1;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	int c0 = 0, c1 = 0, n;
	cin >> s0 >> s1, n = s0.size();
	for(int i = 0;i < n;++i) {
		c0 += s0[i] == '1' && s1[i] == '1';
		c1 += s0[i] == '0' && s1[i] == '1';
	}
	for(int i = 0;i <= c1;++i) {
		f[0][i] = (ll) fac[i] * fac[i] % mod;
	}
	for(int i = 1;i <= c0;++i) {
		for(int j = 1;j <= c1;++j) {
			f[i][j] = ((ll) f[i - 1][j] * i * j + (ll) f[i][j - 1] * j * j) % mod;
		}
	}
	int ans = 0;
	for(int i = 0;i <= c0;++i) {
		ans = (ans + (ll) f[i][c1] * c(c0, i) % mod * c(c0 + c1, c0 - i) % mod * fac[c0 - i] % mod * fac[c0 - i]) % mod;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 393856
#import<iostream>
#import<map>
#import<queue>
#import<cstdlib>
#import<cstring>
using namespace std;struct B{int z[2];char s[14];bool operator<(const B&r)const{return strcmp(s,r.s)<0;}};main(){int a[13][5]={{2,-1},{2,5,-1},{0,1,3,6,-1},{2,7,-1},{5,-1},{1,4,6,9,-1},{2,5,7,10,-1},{3,6,8,11,-1},{7,-1},{5,10,-1},{6,9,11,12,-1},{7,10,-1},{10,-1}},X[]={2,1,2,3,0,1,2,3,4,1,2,3,2},Y[]={0,1,1,1,2,2,2,2,2,3,3,3,4},v,d,s,i,j,t,u;B g={0,0,"0123456789:;0"};for(;;){map<B,int>m;queue<B>q;B b={i=-1,-1};for(;++i<13;!v?b.z[*b.z>=0]=i:0){cin>>v;if(v<0)return 0;b.s[i]=48+v;}b.s[13]=0;m[b]=1;for(q.push(b);!q.empty();q.pop()){B&b=q.front();if(!strcmp(b.s,g.s))break;for(d=i=0;i<13;v?d+=abs(X[v]-X[i])+abs(Y[v]-Y[i]):0,i++)v=b.s[i]-48;s=m[b];if(s+d<22)for(j=0;j<2;j++)for(i=0;~a[u=b.z[j]][i];i++){B n=b;t=n.z[j]=a[u][i];if(t-n.z[1-j]){swap(n.s[u],n.s[t]);int&r=m[n];if(!r)r=s+1,q.push(n);}}}printf(m[g]?"%d\n":"NA\n",m[g]-1);}}

Measured memory_bytes: 1492
//CSP2020 J/S RP++
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n,len;
char c[10005];

int main(void){
	scanf("%d %s",&n,c+1);
	len=strlen(c+1);
	for(int i=1;i<=len;i++){
		int p=c[i]-'A'+n;
		p%=26;
		p+='A';
		printf("%c",p);
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;

int main(){
	long long a[1000000];
	cin>>a[0];
	for(int i=0;true;i++)
	{
		if(a[i]%2==0){
			a[i+1]=a[i]/2;
		}else{
			a[i+1]=a[i] * 3 +1;
		}
		for(int j=0;j<i+1;j++)
		{
			if(a[j]==a[i+1])
			{
				cout<<i+2;
				return 0;
			}
		}
	}


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void check(int *x, int *y){
	int temp;
	if(*x > *y){
		temp = *x;
		*x = *y;
		*y = temp;
	}
}

int main(){
	int x ,y;
	while(1){
		scanf("%d %d",&x ,&y);
		if(x == 0 && y == 0){
			return 0;
		}
		check(&x, &y);
		printf("%d %d\n",x ,y);
	}
	return 0;
}

Measured memory_bytes: 600
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
t, a = Is()
H = LI()
B = [abs(t - x*0.006 - a) for x in H]
m = -INF
print(B.index(min(B))+1)


Measured memory_bytes: 65388
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    str s;
    cin >> s;
    int n = sz(s), res = 0;
    for (int i = 0; i < n / 2; i++)
        res += (s[i] != s[n - 1 - i]);
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i,n) cin >> a[i].first;
    rep(i,n) a[i].second = i+1;
    sort(all(a));
    rep(i,n) cout << a[i].second << " ";
    cout << endl;
}

Measured memory_bytes: 1664
import networkx as nx
n, m, *AB = map(int, open(0).read().split())
G = nx.Graph()
G.add_nodes_from(range(1, n+1))
G.add_edges_from(zip(AB[::2], AB[1::2]))
print('Yes')
d = dict(nx.bfs_predecessors(G, 1))
for i in range(2, n+1):
    print(d[i])

Measured memory_bytes: 214420
#include<stdio.h>

int n;

void CountingSort(int *A,int *B,int k){
  int i,C[k+1];

  for(i=0;i<=k;i++) C[i]=0;
  for(i=0;i<n;i++)  C[A[i]]++;

  //for(i=0;i<=k;i++) printf("%d ",C[i]); printf("\n");

  for(i=1;i<=k;i++) C[i]=C[i]+C[i-1];

  //for(i=0;i<=k;i++) printf("%d ",C[i]); printf("\n");

  for(i=n-1;i>=0;i--){
    B[C[A[i]]-1]=A[i];
    C[A[i]]--;
    }
}

int main(){
  int i,k=0;
  scanf("%d",&n);
  int A[n],B[n];

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(k<A[i]) k=A[i];
  }
  
  CountingSort(A,B,k);

  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    printf("%d",B[i]);
  }

  printf("\n");
  
  return 0;
}





Measured memory_bytes: 17348
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

	vector<int> v(N);
	double ans = 0;
	rep(i,N){
		cin >> v[i];
	}

	sort(v.begin(), v.end());

	rep(i, N) {
		if (i == 0 || i == 1) ans += v[i];
		else ans += pow(2, i - 1) * v[i];
	}

	printf("%.11lf\n", ans/pow(2,N-1));

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    IO;
    int arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr, arr + 3);
    cout << arr[0] + arr[1];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	ll ans = n+1-2;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ll d1 = i;
			ll d2 = n/i;
			ans = min(ans,d1-1+d2-1);
		}	
	}
	cout<<ans<<endl;































	
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);



int main() {
	
	ll n;
	cin >> n;
	ll ans=0;
	for (ll i = 1;i <= n;i++) {
		if (i % 3 != 0 && i % 5 != 0)ans = ans + i;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;

  int result = -1;
  for(int i=0; i<=10000; i++){
    int price8 = i * 0.08;
    int price10 = i * 0.10;
    if(price8 == A && price10 == B){
      result = i;
      break;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long ans;
    ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
}


Measured memory_bytes: 3156
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N1, N2, N3, N4] = [(input_raw[0]), (input_raw[1]), (input_raw[2]) ,(input_raw[3])]
    S = "1974"
    if (N1 in S) and (N2 in S ) and (N3 in S) and (N4 in S) and N1 != N2 and N1 != N3 and N1 != N4 and N2 != N3 and N2 != N4 and N3 != N4:
        print "YES"
    else:
        print "NO"


if __name__ == '__main__':
    main()

Measured memory_bytes: 2932
N = int(input())
a_list = list(map(int, input().split()))
n_dict = {i:0 for i in range(1, N+1)}

for i in range(N, 0, -1):
    j = i
    a = a_list[j-1]
    temp_a = 0
    while j <= N:
        temp_a += n_dict[j]
        j += i
    if temp_a % 2 == a:
        pass
    else:
        n_dict[i] = 1

ans_num = list(n_dict.values())
ans_num = ans_num.count(1)
print(ans_num)

ans_str = ""
for i in range(1, N+1):
    if n_dict[i] == 1:
        if ans_str == "":
            ans_str = str(i)
        else:
            ans_str += " "+str(i)
if ans_str == "":
    pass
else:
    print(ans_str)

Measured memory_bytes: 31564
using System;

namespace AOJ.ALDS
{
    public class FibonacciNumber
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            long n1 = 1;
            long n2 = 1;
            
            if (n == 0) { Console.WriteLine(n1); }
            else if (n == 1) { Console.WriteLine(n2); }
            else
            {
                for (int i = 2; i <= n; i++)
                {
                    long n3 = n1 + n2;
                    n1 = n2;
                    n2 = n3;
                }
                Console.WriteLine(n2);
            }
        }
    }
}

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

using namespace std;

using ll = long long;

constexpr int kMaxN = 1e5 + 7;

vector<int> edges[kMaxN];

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

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    edges[u - 1].emplace_back(v - 1);
  }

  vector<int> cache(n);

  function<int(int)> dfs = [&] (int u) {
    if (cache[u]) {
      return cache[u];
    }
    int cur = 0;
    for (int v: edges[u]) {
      cur = max(cur, dfs(v));
    }
    return cache[u] = cur + 1;
  };

  int best = 1;
  for (int i = 0; i < n; ++i) {
    best = max(best, dfs(i));
  }

  cout << best - 1 << '\n';

  return 0;
}


Measured memory_bytes: 8832
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = new long[][](2);
    A[0] = aryread();
    A[1] = aryread();
    long ans = long.min;
    foreach (i; 0 .. N)
    {
        ans = ans.max(A[0][0 .. i + 1].sum() + A[1][i .. $].sum());
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <vector>
#define rep(i,n) for(int i=0; i< int(n); i++)
using namespace std;

int findSumOfDigits(int n){
	int sum = 0;
	while(n>0){
		sum += n%10;
		n /= 10;
	}
	return sum;
}


int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int total = 0;
	for(int i = 1; i<=n; i++){
		int sum = findSumOfDigits(i);
		if(sum >= a && sum <= b) total += i;
	}
	cout << total << endl;


} 



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int m, h;
    cin >> m;
    for (int i = 1; i < N; i++) {
        cin >> h;
        m = max(m, h);
        if (m-1 > h) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void e(int a, int b, int& x, int& y) {
  x = 1;
  y = 0;
  if (b != 0) {
    e(b, a % b, y, x);
    y -= (a / b) * x;
  }
}
int main() {
  int a, b, x, y;
  cin >> a >> b;
  e(a, b, x, y);
  cout << x << ' ' << y << endl;
}

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

int main() {
  int N;
  cin >> N;
  int a[N], b[N];
  for(int i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }
  int flag=0;
  for(int i=0; i<N-2; i++){
    if (a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2]){
      flag = 1;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3596
nim, mike = map(int, input().split())

g = [["#"]*100 for _ in range(50)] + [["."]*100 for _ in range(50)]

for i in range(nim-1):
    x, y = (i%50)*2, (i//50)*2
    g[y][x] = "."
for i in range(mike-1):
    x, y = (i%50)*2, 51+(i//50)*2
    g[y][x] = "#"

print(100, 100)
for g_i in g:
    print("".join(g_i))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
ll issign(ll x) {
	if (x == 0)return 0;
	else if (x > 0)return 1;
	return -1;
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 1e18 ;
	for (int possible = -1; possible <= 1; possible += 2) {
		ll sum = 0;
		ll cost = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
			ll have;
			if (i & 1)
				have = -possible;
			else
				have = possible;
			if (issign(sum) != have) {
				cost += abs(sum - have);
				sum = have;
			}
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s;
int k;
int dp[303][303][303];

int solve(int fron,int bck,int changes)
{
	if(fron>=bck)
	{
		if(changes<=k)
		{
			return 0;
		}
		else
		{
			return (int)(s.length()+2);
		}
	}
	if(dp[fron][bck][changes]!=-1)
	{
		return dp[fron][bck][changes];
	}
	int ans=(int)(s.length()+2);
	if(s[fron]==s[bck])
	{
		ans=solve(fron+1,bck-1,changes);
	}
	else
	{
		ans=min(ans,solve(fron+1,bck,changes)+1);
		ans=min(ans,solve(fron,bck-1,changes)+1);
		ans=min(ans,solve(fron+1,bck-1,changes+1));
	}
	dp[fron][bck][changes]=ans;
	return ans;
}

int main()
{
	cin>>s;
	scanf("%d",&k);
	memset(dp,-1,sizeof dp);
	int x=solve(0,s.length()-1,0);
	printf("%d\n",(int)s.length()-x);
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;



int main() {

    string S; cin >> S;
    int flag = 1;

    int n = S.length()/2;
    REP(i, n){
        // cout << S[i] << " " << S[S.length() - 1 - i] << endl;
        if(S[i] != S[S.length() - 1 - i]){
            // cout << S[i] << " " << S[S.length() - 1 - i] << endl;
            flag = 0;
            cout << "No" << endl;
            return 0;
        }
    }
    S = S.substr(0,S.length()/2);
    n = S.length()/2;
    REP(i, n){
        // cout << S[i] << " " << S[S.length() - 1 - i] << endl;
        if(S[i] != S[S.length() - 1 - i]){
            // cout << S[i] << " " << S[S.length() - 1 - i] << endl;
            flag = 0;
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD=1e9+7;
const int INF=1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m=MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------//
void solve(){
   
   int n;
   int a=0,b=0,c=0;
   cin>>n;
   vector<int> v(n);
   for(int i=0;i<n;i++){
	    cin>>v[i]; 
	  }
   for(int i=0;i<n;i++){
	   if(v[i]%4==0)a++;
	   else if(v[i]%2==0)b++;
	   else c++;
	  }
   if(c<=a)cout<<"Yes";
   else if(a+1<c)cout<<"No";
   else if(b>0)cout<<"No";
   else cout<<"Yes";
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, A[50][5];
int bit = 0;
int flag(int i) {
    if (bit & (1ll << i))
        return 1;
    else
        return 0;
}

void solve() {
    //vector<P> v(N);
    vector<int> v(N);
    int ans = INF;
    for (bit = 0; bit < (1ll << N); bit++) {
        /*
        FOR(i, 0, N) {
            v[i] = P(A[i][flag(i)], flag(i));
        }
        sort(all(v), [](P a, P b) {
            if (a.first < b.first) {
                return true;
            } else if (a.first == b.first && a.second < b.second) {
                return true;
            } else
                return false;
        });
        */
        FOR(i, 0, N)
        v[i] = A[i][flag(i)];
        sort(all(v));
        int tmp = 0;
        bool used[20];
        FOR(i, 0, 20)
        used[i] = false;
        bool ok = true;
        vector<int> b(N);
        FOR(i, 0, N) {
            int a = A[i][flag(i)];
            bool okk = false;
            FOR(x, 0, N) {
                if (used[x] == false && v[x] == a && abs(x - i) % 2 == flag(i)) {
                    //tmp += abs(x - i);
                    b[i] = x;
                    used[x] = true;
                    okk = true;
                    break;
                }
            }
            if (!okk) {
                ok = false;
                break;
            }
        }
        if (ok) {
            FOR(x, 0, N) {
                FOR(y, 0, N) {
                    if (x == y)
                        continue;
                    if (x < y && b[x] > b[y])
                        tmp++;
                    else if (x > y && b[x] < b[y])
                        tmp++;
                }
            }
            chmin(ans, tmp);
        }
    }
    if (ans != INF)
        cout << ans / 2 << endl;
    else {
        cout << -1 << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N)
    cin >> A[i][0];
    FOR(N)
    cin >> A[i][1];
    solve();
    return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n,m;
	cin>>n>>m;
	vector<lli> z(m);
	map<lli,vector<lli>> d;
	REP(i,0,m){
		lli x,y;
		cin>>x>>y>>z[i];
		d[x].push_back(y);
		d[y].push_back(x);
	}

	lli flag[100010];
	REP(i,0,100010)flag[i]=0;
	lli cnt=0;

	for(lli i=1;i<=n;i++){
		if(flag[i]!=0)continue;
		cnt++;
		queue<lli> q;
		q.push(i);
		flag[i]=cnt;
		while(q.size()){
			lli top = q.front();
			q.pop();
			for(auto e:d[top]){
				if(flag[e]==0){
					flag[e]=cnt;
					q.push(e);
				}
			}
		}
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pb push_back
#define x first
#define y second

int main()
{
	IOS
  ll n;
	cin>>n;
	ll h[n+1],c[n+1],i,j;
	for(i=1;i<=n;i++)
		cin>>h[i];
	c[1]=0;
	c[2]=abs(h[2]-h[1]);
	for(j=3;j<=n;j++)
		c[j]=min(c[j-1]+abs(h[j]-h[j-1]),c[j-2]+abs(h[j]-h[j-2]));
	cout<<c[n];
	return 0;
}

Measured memory_bytes: 1792
sl = list(input())

al = "AKIHABARA"

for s in sl:
    try:
        idx = al.index(s)
    except:
        print("NO")
        import sys
        sys.exit()
    al = al[idx+1:]
bl = "KIHBR"
for s in bl:
    try:
        idx = sl.index(s)
    except:
        print("NO")
        import sys
        sys.exit()
    sl = sl[idx+1:]
print("YES")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	const int MAX=100001;
	int N;
	cin>>N;
	ll A[MAX]={};
	ll S[MAX]={};
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A,A+N);
	for(int i=0;i<N;i++){
		S[i]=A[i];
	}
	for(int i=1;i<N;i++){
		S[i]+=S[i-1];
	}
	for(int i=N-1;i>0;i--){
		if(2*S[i-1]<A[i]){
			cout<<N-i<<endl;
			return 0;
		}
	}
	cout<<N<<endl;
	return 0;
}

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

using namespace std;

const int MAX = 1001;
const int INF = (1<<20);
typedef pair<int,int> P;
typedef pair<int,P> PP;

int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
char grid[MAX][MAX];
int cost[MAX][MAX];
int H,W,N;
vector<PP> V;

void init(){
  for(int i = 0; i <= H; i++)
    for(int j = 0; j <= W; j++)
      cost[i][j] = INF;

}

void input(){
  for(int i = 1; i <= H; i++)
    for(int j = 1; j <= W; j++){
      cin >> grid[i][j];
      PP pp;

      if(grid[i][j] == 'S' || '0' <= grid[i][j] && grid[i][j] <= '9'){
	if(grid[i][j] == 'S') pp.first = 0;
	else pp.first = grid[i][j] - '0';
	
	pp.second = P(i,j);
	V.push_back(pp);
      }
    }
}


bool isIn(P p){
  return 0 < p.first && p.first<= H && 0 < p.second && p.second <= W;
}
void solve(P p){

  int n = cost[p.first][p.second];

  for(int i = 0; i < 4; i++){
    P next = p;
    next.first += dy[i];
    next.second += dx[i];
    if(grid[next.first][next.second] != 'X' && cost[next.first][next.second] > n+1 && isIn(next)){
	cost[next.first][next.second] = n+1;
	solve(next);
    }
  }
}

P find(int n){
  for(int i = 0; i < V.size(); i++)
    if(V[i].first == n) return V[i].second;

}

int main(){

  cin >> H >> W >> N;

  input();
  sort(V.begin(),V.end());
  
  int ans = 0;
 
  for(int i = 1; i <= N; i++){
    init();
    P f = find(i-1), t = find(i);
    cost[f.first][f.second] = 0;
    solve(f);
    ans += cost[t.first][t.second];
    
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12784
import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9+7;
    static HashMap<Integer, Integer> memo;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        char[] x = s.toCharArray();
        int popcount = 0;
        for(int i=0; i<n; i++){
            if(x[i]=='1'){
                popcount++;
            }
        }
        
        //0 -> popcount-1
        //2 -> popcount+1
        int[] remx = new int[3];
        int[][] rem2beki = new int[3][n+1];
        for(int i=0; i<3; i+=2){
            int mod = popcount-1+i;
            if(mod<=0){
                continue;
            }
            rem2beki[i][0] = 1;
            for(int j=0; j<n; j++){
                rem2beki[i][j+1] = rem2beki[i][j]*2%mod;
                remx[i] = remx[i]*2 + ((x[j]=='1')?1:0);
                remx[i] %= mod;
            }
        }
        
        for(int i=0; i<n; i++){
            if(popcount==1 && x[i]=='1'){
                System.out.println(0);
                continue;
            }
            
            int j = (x[i]=='0') ? 2 : 0;
            int res = remx[j];
            if(x[i]=='0'){
                //mod popcount+1
                res += rem2beki[j][n-1-i];
                res %= popcount+1;
            }else{
                //mod popcount-1
                res -= rem2beki[j][n-1-i] - (popcount-1);
                res %= popcount-1;
            }
            
            System.out.println(calc(res)+1);
        }
    }
    
    public static int calc(int n){
        if(n==0){
            return 0;
        }
        
        int popcount = Integer.bitCount(n);
        int res = n%popcount;
        
        return calc(res)+1;
    }
}


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

int main() {
    ios::sync_with_stdio(false);
    int N, M, A, B, C;
    
    cin >> N >> M;
    
    vector<int> arr;
    vector<pair<int,int>> op;
    for(int i = 0; i < N; i++) {
        cin >> A;
        arr.push_back(A);
    }
    
    for(int i = 0; i < M; i++) {
        cin >> B >> C;
        op.push_back({C,B});
    }
    
    sort(arr.begin(), arr.end());
    sort(op.begin(), op.end());
    
    int remain = N;
    long long ans = 0;
    while(remain-- > 0) {
        if(op.empty() || (arr.size() && arr.back() >= op.back().first)) {
            ans += arr.back();
            arr.pop_back();
        } else {
            ans += op.back().first;
            op.back().second--;
            if(op.back().second == 0) op.pop_back();
        }
    }
    cout << ans;
}


Measured memory_bytes: 1784
#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>;

int main(){
  string s;
  cin>>s;
  if(s=="ABC") cout<<"ARC"<<endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sll set<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
using namespace std;

int main(){
	IOS;
	int q=1,c=1;
	//cin>>q;
	while(q--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;

		int t=ceil(a/(float)d),ak=ceil(c/(float)b);		

		if(t>=ak)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;

	}
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
    // Your code here!
   int point[2][2];//white space
   int W,H,N;
   int x[100],y[100],a[100];
   int ans;
   
   scanf("%d%d%d",&W,&H,&N);
   //(0,0)
   point[0][0]=0;
   point[0][1]=0;
   //(W,H)
   point[1][0]=W;
   point[1][1]=H;
   
   for(int i=0;i<N;i++){
       scanf("%d%d%d",&x[i],&y[i],&a[i]);
   }
   
   for(int i=0;i<N;i++){
       if(a[i]==1 && point[0][0] < x[i]){
           point[0][0] = x[i];
       }
       else if(a[i]==2 && point[1][0] > x[i]){
           point[1][0] = x[i];
       }
       else if(a[i]==3 && point[0][1] < y[i]){
           point[0][1]  = y[i];
       }
       else if(a[i]==4 &&  point[1][1] > y[i]){
            point[1][1] = y[i];
       }
       
   }
   ans = (point[1][0]-point[0][0])*(point[1][1]-point[0][1]); //-1*-1=1;
   if(point[1][0] < point[0][0] || point[1][1] < point[0][1]){
       ans = 0;
   }
   printf("%d\n",ans);
}


Measured memory_bytes: 256
TL = input()
TL = list(TL)
cnt1 = 0
cnt2 = 0
fg = True

for lop in range(0,len(TL)):
    if fg == True:
        if TL[lop] == "0":
            cnt1 += 1
    else:
        if TL[lop] == "1":
            cnt1 += 1
    fg = fg ^ 1

fg = True
for lop in range(0,len(TL)):
    if fg == True:
        if TL[lop] == "1":
            cnt2 += 1
    else:
        if TL[lop] == "0":
            cnt2 += 1
    fg = fg ^ 1
 
print( min(cnt1,cnt2) )

Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC161
{
    class MainClass
    {

        static int[] s,m;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            m = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int m4 = 4*s[1];
            int sum = m.ToList().Sum();
            var ml = m.ToList();
            ml.Sort();
            ml.Reverse();
            double div = (double)sum / (double)m4;
            // WriteLine(sum);
            // WriteLine(m4);
            // WriteLine(div);
            for(int i = 0;i<s[1];i++){
                // WriteLine(ml[i]);
                if(ml[i]<div){
                    WriteLine("No");
                    return;
                }

            }
            WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#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;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int x,n;
    cin >> x >> n;
    int num[n];
    rep(i,n){
        cin >> num[i];
    }
    bool check = true;
    ll answer = 1e9;
    for(int i = 0;check;i++){
        bool ok1 = true;
        rep(j,n){
            if(num[j] == x+i){
                ok1 = false;
            }
        }
        if(ok1){answer = x+i;}
        bool ok2 = true;
        rep(j,n){
            if(num[j] == x-i){
                ok2 = false;
            }
        }
        if(ok2){answer = x-i;}
        if(answer != 1e9) break;
    }
    cout << answer << endl;
}

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

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


Measured memory_bytes: 3120
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        while (n-- > 0) {
            int num = sc.nextInt();
            
            if (num % 2 == 0) {
                if (num % 5 == 0 || num % 3 == 0) {
                    
                } else {
                    System.out.println("DENIED");
                    return;
                }
            }
        }
        
        System.out.println("APPROVED");
    }
}


Measured memory_bytes: 21844
loop do
  n = gets.to_i
  break if n == 0
  arr = gets.split(' ').map(&:to_i)

  dp = Array.new(n) { Array.new(21, 0) }

# ??????????????°???
  dp[0][arr[0]] = 1

  1.upto(n-2) do |i|
    0.upto(20) do |j|
      next if dp[i-1][j] == 0

      plus = j + arr[i]
      minus = j - arr[i]

      dp[i][plus] += dp[i-1][j] if plus <= 20
      dp[i][minus] += dp[i-1][j] if minus >= 0
    end
  end

  puts dp[n-2][arr[n-1]]
end

Measured memory_bytes: 8632
n=int(input())
alph=["A","C","G","T"]
a=[alph[i]+alph[j]+alph[k] for i in range(4) for j in range(4) for k in range(4)]
#print(len(a))
d1={l:0 for l in a}
for i in d1:
    if i!="AGC" and i!="ACG" and i!="GAC":
        d1[i]=1
d2={l:0 for l in a}
for i in range(n-3):
    for j in d1:
        next=[j+alph[k] for k in range(4)]
        for k in range(4):
            l=next[k]
            if l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC":
                #print(l)
                pass
            elif l[0]=="A" and l[3]=="C" and (l[1]=="G" or l[2]=="G"):
                #rint(l)
                pass
            else:
                d2[l[1:]]+=d1[j]
    for j in d1:
        d1[j]=d2[j]
        d2[j]=0
print(sum(d1.values())%(1000000007))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline bool cmp(string a,string b){
	return a<b;
}
int main()
{
	std::ios::sync_with_stdio(false);
	string b[111];
	int n,l;
	cin>>n>>l;
	for(int i=1;i<=n;i++)
	cin>>b[i];
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++)
	cout<<b[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3676
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<cstdio>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

#define MAX 210
int n;
ll A[MAX];
string s;

class XorBasis {
private:
  const static int len = 61;
  long long M[len];
public:
  XorBasis() { init(); }
  
  void init() { rep(i,len) M[i] = 0; }

  void add(long long x) {
    rep(i,len) {
      if( (x>>i) & 1LL ) {
	if( !( (M[i]>>i) & 1LL ) ) {
	  M[i] = M[i] ^ x;
	  return;
	}
	x = x ^ M[i];
      }
    }
  }

  bool query(long long x) {
    rep(i,len) {
      if( (x>>i) & 1LL ) {
	x = x ^ M[i];
      }
    }
    return x == 0LL;
  }
  
};

void solve() {
  XorBasis basis;
  basis.init();
  for(int i=n-1;i>=0;--i) {
    if( s[i] == '0' ) {
      basis.add(A[i]);
    } else {
      if( !basis.query(A[i]) ) {
	puts("1");
	return;
      }
    }
  }
  puts("0");
}

int main() {
  int T;
  cin >> T;
  while( T-- ) {
    cin >> n;
    rep(i,n) cin >> A[i];
    cin >> s;
    solve();
  }
  return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)


struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  int root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(ll x) {
    return -data[root(x)];
  }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<P> in(m);
    FOR(i,0,m){
      ll a,b;
      cin>>a>>b;
      in[i] = P(a,b);
    }
    UnionFind uni(n+1);
    reverse(in.begin(), in.end());
    ll res = n*(n-1)/2;
    deque<ll> ans;
    FOR(i,0,m){
      ll x = in[i].first;
      ll y = in[i].second;
      ans.push_back(res);
      if(!uni.findSet(x,y)){
        ll a=uni.size(x);
        ll b=uni.size(y);
        res -= (a+b)*(a+b-1)/2 - a*(a-1)/2 - b*(b-1)/2;
      }
      uni.unionSet(x,y);

    }

    FOR(i,0,m){
      cout<<ans.back()<<endl;
      ans.pop_back();
    }
}


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

long long int N, a[11], t = 1, r = 1, M = 1, A;

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld", a + i);
        M *= 3;
    }
    M /= 3;
    for(int i = 0; i < N; ++i){
        A += (1 + (a[i] & 1)) * M;
        M *= (2 - (a[i] & 1));
        M /= 3;
    }
    cout << A << endl;
    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
MAX = max(A, B) + 1
MOD = 1000000007
nCk = [0] * MAX
nCk[0] = 0
nCk[1] = N
inv = [0] * MAX
inv[1] = 1


for i in range(2, MAX):
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    nCk[i] = (nCk[i - 1] * (N - i + 1) * inv[i]) % MOD

count = (pow(2, N, MOD) - 1 - nCk[A] - nCk[B]) % MOD
print(int(count))


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

int main(){
    int N;
    cin >>N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    long long sum=0;
    if(N==1||N==2){
        cout << 0 << endl;
    }
    else{
        for(int i=0;i<N-2;i++){
            for(int j=1;j<N-1;j++){
                for(int k=2;k<N;k++){
                    if(L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]){ //全部違うとき
                        if(
                            L[i]+L[j]>L[k]&&L[j]+L[k]>L[i]&&L[k]+L[i]>L[j]&&i<j&&j<k
                        ){
                            sum+=1;
                        }
                    }
                }
            }
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str = scan.nextLine();
    String[] strs = str.split(" ");
    long x = Long.parseLong(strs[0]); // 今いる
    long k = Long.parseLong(strs[1]); // 回数
    long d = Long.parseLong(strs[2]); // 変動量

    if (x < 0) x = -x;

    long tmp = Math.floorDiv(x, d);
    if (k < tmp) {
      System.out.println(x - k * d);
      return;
    }
    long a = x - tmp * d;
    k -= tmp;
    System.out.println(Math.abs(a - d * (k % 2)));
  }
}

Measured memory_bytes: 35624
#include <iostream>
#include <limits.h>
using namespace std;
int mod(int n)
{
	if(n>=0) return n;
	return -1*n;
}
int mini(int a, int b)
{
    if(a<b) return a;
    return b;
}
int cost3(int n, int h[], int k)
{
	int a[n],i;
	for(i=0;i<n;i++)
		a[i] = INT_MAX;
	if(n==1)
		return 0;
	if(n==2)
		return mod(h[0]-h[1]);
	a[n-1]=0;
	a[n-2]=mod(h[n-1]-h[n-2]);
	for(i=n-3;i>=0;i--)
		for(int j = i+1;j<min(n,i+k+1);j++)
			a[i] = mini(a[i],mod(h[i]-h[j])+a[j]);
	return a[0];
}
 
int main()
{
	int n,k;
	cin >> n >> k;
	int i,h[n];
	for(i=0;i<n;i++)
		cin >> h[i];
	cout << cost3(n,h,k);
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <ctime>

using namespace std;

typedef int INT;
#define int long long

INT main()
{

	int a, b;
	cin >> a >> b;
	int c = 1, d = 3, i = 3;
	int p = 0;
	while (true)
	{
		if (c > a && d > b && c - a == d - b)
		{
			p = c - a;
			break;
		}
		c = d;
		d += i;
		i++;
	}

	cout << p;

	//system("pause");
	return 0;
}




Measured memory_bytes: 256