akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=2e5;
const int INF=1e9;
int main(){
	int M,D;cin>>M>>D;int count=0;
	rep(i,1,M+1)rep(j,1,D+1){
		int a=j/10;
		int b=j%10;
        if(a<2||b<2) continue;
		if(a*b==i) count++;
	}cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = 1000000007;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n, k;
  cin >> n >> k;
  V a(n);
  VIN(n,a);
  vector<P> an(n);
  REP(i,n){
    an.at(i).first = 0;
    an.at(i).second = 0;
  }
  REP(i,n){
    REP(j,n){
      if (i < j && a.at(i) > a.at(j)){
        an.at(i).second++;
      }
      if (i > j && a.at(i) > a.at(j)){
        an.at(i).first++;
      }
    }
  }
  I t=0;
  REP(i,n){
    I tmp = 0;
    I tmp2 = 0;
    tmp = (k + 1)*k/2LL % MOD;
    tmp = tmp * an.at(i).second % MOD;
    tmp2 = (k - 1)*k/2LL % MOD;
    tmp2 = tmp2 * an.at(i).first % MOD;
    t += tmp + tmp2;
    t %= MOD;
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {

    int N;
    int K;
    int cnt = 0;
    int h;

    cin >> N >> K;

    for (int i = 0; i < N; i++)
    {
        cin >> h;
        if (h >= K)
        {
            cnt++;
        }

    }
    cout << cnt << endl;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

int f(int x,int y,int z){
	return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	int N;
	cin >> N;
	int ans[10009]={0};

	for(int x=1;x<=110;x++){
		for(int y=1;y<=110;y++){
			for(int z=1;z<=110;z++){
				if(f(x,y,z)<=10000) ans[f(x,y,z)]++;
			}
		}
	}

	for(int i=1;i<=N;i++){
		cout << ans[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string.h>
using namespace std;

int main(){

	int r, c,x, **a;
	cin >> r >> c; 
	

	//??????????????????
	a = new int*[r + 1];
	for (int i = 0; i < r + 1; i++){
		a[i] = new int[c + 1];
	}

	for (int i = 0; i < r + 1; i++){
		for (int j = 0; j < c + 1; j++){
			a[i][j] = 0;
		}
	}

	for (int i = 0; i < r + 1; i++){
		for (int j = 0; j < c + 1; j++){
			if (i < r&&j < c){
				cin >> x;
				a[i][j] = x;
				a[i][c] += x;
				a[r][j] += x;			
			}
			if (j == c&&i!=r){
				a[r][j] += a[i][j];
			}


		}
	}

	

    //???????????±??????
	for (int i = 0; i < r + 1; i++){
		for (int j = 0; j < c + 1; j++){
			cout << a[i][j];
			if (j != c){
				cout << " ";
			}
		}cout << endl;
	}



	//delete
	for (int i = 0; i < r + 1; i++){
		delete[] a[i];
	}
	delete[] a;

	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>

int main(void){
    char s[103];
    scanf("%s",&s);
    int flag=0;
    for (int i = 0; s[i]!='\0'; i++)
    {  
        if(s[i]=='\0'){
            break;
        }
        if((i+1)%2){
            if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
                flag=1;
            }else {
                flag=0;
                break;
            }
        }else{
            if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
                flag=1;
            }else{
                flag=0;
                break;
            }
        }
    }
    if (flag==1)
    {
        printf("Yes\n");
    }else
    {
         printf("No\n");
    }
    
    
    
    return 0;
}

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

class MainClass
{
    static void Main()
    {
        var DG = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int D = DG[0], G = DG[1];
        int[] p = new int[D];
        int[] c = new int[D];
        for(int i = 0; i < D; i++)
        {
            var r = Console.ReadLine().Split();
            p[i] = int.Parse(r[0]);
            c[i] = int.Parse(r[1]);
        }

        int mincount = int.MaxValue;
        for(int bit = 0; bit < (1 << D); bit++)
        {
            int sum = 0;
            int count = 0;
            
            for(int i = 0; i < D; i++)
            {
                if ((bit & (1 << i)) != 0)
                {
                    sum += (i + 1) * p[i]*100 + c[i];
                    count += p[i];
                }
                
            }
            if (sum < G)
            {
                for(int i = D - 1; i >= 0; i--)
                {
                    if ((bit & (1 << i)) == 0)
                    {
                        int con = 0;
                        while (sum < G)
                        {
                            con++;
                            count++;
                            sum += (i + 1) * 100;
                            if (con > p[i]) { count = int.MaxValue;break; }
                        }
                        break;
                    }
                }
            }
            mincount = Math.Min(mincount, count);
        }
        Console.WriteLine(mincount);
    }
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

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

	int a, b, c, d; cin >> a >> b >> c >> d;

	vector<int>alice(101);
	vector<int>bob(101);

	for (int i = a; i < b; i++) {
		alice[i] = 1;
	}
	for (int i = c; i < d; i++) {
		bob[i] = 1;
	}
	
	int cnt = 0;

	rep(i, 101) {
		if (alice[i] == 1 && bob[i] == 1)cnt++;
	}
	cout << cnt << "\n";
}	




Measured memory_bytes: 256
object Main {

  import Math.pow

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val M = sc.nextInt
    val k = new Array[Int](M)
    val s = new Array[Long](M)
    for (i <- 0 until M) {
      k(i) = sc.nextInt
      var tmp = 0L
      for (j <- 0 until k(i)) {
        tmp += pow(2.0, sc.nextInt - 1).toLong
      }
      s(i) = tmp
    }

    val p = Array.fill(M)(sc.nextInt)
    var result = 0L

    def countOn(b: Int): Unit = {
      for (i <- 0 until M) {
        val on = b & s(i)
        if (on.toBinaryString.count(_.==('1')) % 2 != p(i)) {
          return
        }
      }
      result += 1
    }

    for (b <- 0 until pow(2.0, N).toInt) {
      countOn(b)
    }
    println(result)
  }
}

Measured memory_bytes: 27812
n = int(input())

dp = [[[[0]*4 for k in range(4)] for j in range(4)] for i in range(n+1)]

dp[0][3][3][3] = 1
mod = 1000000007

for lens in range(n):
    for c1 in range(4):
        for c2 in range(4):
            for c3 in range(4):
                #print(lens,c1,c2,c3,dp[lens][c1][c2][c3])
                if dp[lens][c1][c2][c3] == 0:
                    continue
                for a in range(4):
                    if a == 2 and c1 == 1 and c2 == 0:
                        continue
                    if a == 2 and c1 == 0 and c2 == 1:
                        continue
                    if a == 1 and c1 == 2 and c2 == 0:
                        continue
                    if a == 2 and c1 == 1 and c3 == 0:
                        continue
                    if a == 2 and c2 == 1 and c3 == 0:
                        continue
                    dp[lens+1][a][c1][c2] += dp[lens][c1][c2][c3]
                    dp[lens+1][a][c1][c2] %= mod

ans = 0
for c1 in range(4):
    for c2 in range(4):
        for c3 in range(4):
            ans += dp[n][c1][c2][c3]
            ans %= mod

print(ans)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, x;
    cin >> n >> x;

    ll ans = 1;

    ll l;
    ll d = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> l;

        d += l;

        if (d <= x)
        {
            ans++;
        }
        else
        {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    rep(i, n-1) {
        if (s[i]==s[i+1]) continue;
        int x = max(i+1, n-i-1);
        chmin(ans, x);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3756
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

N, K = map(int, input().split())
*A, = map(int, input().split())

a_gcd = A[0]
a_max = A[0]
for i in range(1,N,1):
    a_gcd = gcd(a_gcd,A[i])
    if (a_max < A[i]):
        a_max = A[i]

if ((a_max < K) or (0 < (K % a_gcd))):
    print("IMPOSSIBLE")
    exit()

print("POSSIBLE")


Measured memory_bytes: 14252
import operator
import functools


def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    # use list.sort() or sorted(list)
    v.sort(reverse=True)
    # use slice to sum first A elements
    # use '{:f}'.format to format float
    print('{:.6f}'.format((sum(v[:A]) / A)))

    va = v[A - 1]
    # use list.count instead of (sum(list(map(lambda x: 1 if ... else 0, v))))
    pool = v.count(va)
    # ...and for comprehension and boolean sum
    head = sum(x > va for x in v)
    # 5 4 3 3 3 2 1, A = 3, B = 5, pool = 3, pick = 1
    # 5 4 3 3 3 2 1, A = 4, B = 5, pool = 3, pick = 2
    # 3 3 3 3 3 2 1, A = 3, B = 6, pool = 5, pick = 3, 4, 5
    # 3 3 3 3 3 2 1, A = 3, B = 4, pool = 5, pick = 3, 4
    if head == 0:
        # for comprehension again, instead of a for loop that modifies variable
        ans = sum([_nCr(pool, pick) for pick in range(A, min(B, pool) + 1)])
    else:
        pick = A - head
        ans = _nCr(pool, pick)
    print(ans)


def _nCr(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    # reduce and xrange are for python2
    numer = functools.reduce(operator.mul, range(n, n-r, -1))
    denom = functools.reduce(operator.mul, range(1, r+1))
    return numer//denom


if __name__ == '__main__':
    main()


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

typedef long long ll;

int main(void)
{
    ll x;
    cin>>x;
    ll num = 100;
    ll counter = 0;
    while(num < x)
    {
        num = num * 1.01;
        counter++;
    }
    cout<<counter<<"\n";

    return 0;
}


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

int main() {
    ll h, w; cin >> h >> w;

    if (h == 1 || w == 1)
        cout << 1 << endl;
    else
        cout << (h * w + 1) / 2 << endl;

    return 0;
}

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

int main(){
	char ch;

	while(1){
		scanf("%c",&ch);
		if(isalpha(ch)){
			if(islower(ch))printf("%c",toupper(ch));
			else printf("%c",tolower(ch));		
		}	else printf("%c",ch);

	if(ch == '\n')break;
	}
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    
    
    cin>>n;
    vector<vector<int>> tree(n+1);
    
    for(int i=1; i<n; i++){
        int x,y;
        cin>>x>>y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    
    vector<int> bdist(n+1,-1), wdist(n+1,-1);
    queue<int> q;
    q.push(1);
    bdist[1]=0;
    while(!q.empty()){
        int cur=q.front();
        q.pop();
        for(int i:tree[cur]){
            if(bdist[i]==-1){
                bdist[i]=bdist[cur]+1;
                q.push(i);
            }
        }
    }
    q.push(n);
    wdist[n]=0;
    while(!q.empty()){
        int cur=q.front();
        q.pop();
        for(int i:tree[cur]){
            if(wdist[i]==-1){
                wdist[i]=wdist[cur]+1;
                q.push(i);
            }
        }
    }
    int bct=0, wct=0;
    for(int i=1; i<=n; i++){
        if(bdist[i]<=wdist[i]) bct++;
        else wct++;
    }
    cout<<(bct>wct?"Fennec":"Snuke");
    
    
    
    return 0;
}

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

int main(){
  map< char , int > count;
  string str;
  while( cin>>str ){
    for(int i=0;i<(int)str.size();i++){
      if( isupper(str[i]) ){
        str[i]=tolower(str[i]);
      }
    }
    for(int i=0;i<(int)str.size();i++){
      count[ str[i] ]++;
    }
  }
  for(char ch='a';ch<='z';ch++){
    cout<<ch<<" : "<<count[ch]<<endl;
  }
  return 0;
}


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

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

    int ans = 0;
    for (int i=1; i<=N; i++) {
        int m = 0;
        int i_temp = i;
        for (int j=0; j<5; j++) {
            m += i_temp%10;
            i_temp /= 10;
            if (i_temp == 0) break;
        }

        if (A <= m && m <= B) {
            ans += i;
        }
    }
    cout << ans << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();
        var t = Console.ReadLine().ToCharArray();
        int min = t.Length;
        for (int i = 0; i < s.Length - t.Length + 1; i++)
        {
            int diff = 0;
            for (int j = 0; j < t.Length; j++)
            {
                if (s[i + j] != t[j]) diff++;
            }
            min = Math.Min(min, diff);
        }
        Console.WriteLine(min);
    }
}


Measured memory_bytes: 25848
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b; cin >> a >> b;
	cout << a * b << endl;

	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int  main (){
  int a,n[5];
  int b=0;
  cin>>a;
  for(int i=0;i<3;i++){
    n[i]=a%10;
    a=a/10;
  }
  for(int i=0;i<3;i++){
    if(n[i]==1){
      b++;
    }
  }
  cout<<b<<"\n";
  return(0);
}


Measured memory_bytes: 256
import sys
N, Y = map(int, input().split())

for x in range(N+1)[::-1]:
  if x <= N:
    for y in range(N+1)[::-1]:
      if x+y <= N:
        z = N-(x+y)
        if 10000*x + 5000*y + 1000*z == Y:
          print(x,y,z)
          sys.exit()

print(-1,-1,-1)

Measured memory_bytes: 3188
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <iostream>

#pragma warning(disable:4996)

using namespace std;


int pickColor(int rating)
{
	if (rating < 3200)
		return rating / 400;
	else
		return -1;
}

int main()
{
	int N, rating;
	int color[8];
	while (cin >> N)
	{
		memset(color, 0, sizeof(color));

		int any = 0;
		for (int i = 0; i < N; ++i)
		{
			cin >> rating;
			int idx = pickColor(rating);
			if (idx != -1)
				++color[idx];
			else
				++any;
		}
		int kind = 0;
		for (int c = 0; c < 8; ++c)
		{
			kind += (color[c] > 0) ? 1 : 0;
		}
		int res_min = (kind == 0) ? 1 : kind;
		int res_max = kind + any;
		cout << res_min << " " << res_max << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
class unionFind():
	def __init__(self,n):
		self.tree=[-1]*n
	def find(self,x):
		if self.tree[x]<0:
			return x
		else:
			return self.find(self.tree[x])
	def union(self,x,y):
		xr=self.find(x)
		yr=self.find(y)
		if xr!=yr:
			if self.tree[xr]<self.tree[yr]:
				self.tree[yr]=xr
			elif self.tree[xr]>self.tree[yr]:
				self.tree[xr]=yr
			else:
				self.tree[xr]-=1
				self.tree[yr]=xr
			return True
		
		return False
def main():
	ans=0
	n,m=map(int,input().split())
	a=unionFind(n)
	li=[x-1 for x in list(map(int,input().split()))]
	for _ in range(m):
		x,y=map(int,input().split())
		a.union(x-1,y-1)
	for x in range(n):
		ans += a.find(x)==a.find(li[x])
	return ans
print(main())


Measured memory_bytes: 14644
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;

constexpr int maxn = 2000010;
char s[maxn];

set <int> S;
int nextt[maxn][30];
int now[30];
int now_tot[maxn];

void doit(){
    scanf("%s",s);
    int len=strlen(s);
    int tot=0;
    for (int i=len;i>=1;i--)
    {
        S.insert( s[i-1]-'a' );
        now_tot[i]=tot;
        if (S.size()==26)
        {
            tot++;
            S.clear();
        }
    }
    if (tot==0)
        {
        for (int i=0;i<26;i++)
            if (S.count (i )==0)
                {
                    printf("%c",i+'a');
                    return ;
                }
        }
    memset(now,0,sizeof(now));
    for (int i=len;i>=1;i--)
    {
        for (int j=0;j<26;j++)
            nextt[i][j]=now[j];
        now[ s[i-1]-'a' ]=i;
    }
    int tmp=0;
    for (int i=0;i<26;i++)
        if (S.count (i )==0)
        {
            tmp=now[i];
            break;
        }
    printf("%c",s[tmp-1]);
    for (int i=1;i<tot;i++)
        {
            for (int j=0;j<26;j++)
                if (now_tot [ nextt[ tmp ][ j ] ]==now_tot [ tmp ] -1 )
                    {
                        tmp=nextt[ tmp ][ j ];
                        printf("%c",s[tmp-1]);
                        break;
                    }
        }
    for (int i=0;i<26;i++)
        if (nextt[ tmp ][ i ]==0)
            {
                printf("%c",i+'a');
                break;
            }
}


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


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

int main() {
	string a, b, c; cin >> a >> b >> c;

	char turn = 'a';
	int ai = 0, bi = 0, ci = 0;
	for (int i = 0; i < a.size() + b.size() + c.size(); i++) {
		if (turn == 'a') {
			if (ai == a.size()) {
				cout << 'A' << endl;
				return  0;
			}
			turn = a[ai];
			ai++;
		}
		else if (turn == 'b') {
			if (bi == b.size()) {
				cout << 'B' << endl;
				return 0;
			}
			turn = b[bi];
			bi++;
		}
		else {
			if (ci == c.size()) {
				cout << 'C' << endl;
				return 0;
			}
			turn = c[ci];
			ci++;
		}
	}
	return 0;
}

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

int n;
int p[1000], x[1000];
vector<int> children[1000];

pair<int, int> solve(int v){
    int dp[5001];
    int64_t sum = 0;
    for(int i=1;i<=5000;++i) dp[i] = -1;
    dp[0] = 0;
    for(size_t i=0;i<children[v].size();++i){
        int u = children[v][i];
        auto ch = solve(u);
        sum += ch.first + ch.second;
        vector<int> idx;
        for(int j=0;j<=5000;++j) if(dp[j] == i) idx.push_back(j);
        for(int j: idx){
            if(j+ch.first  <= 5000) dp[j+ch.first ] = i+1;
            if(j+ch.second <= 5000) dp[j+ch.second] = i+1;
        }
    }
    for(int i=x[v];i>=0;--i){
        if(dp[i] == children[v].size()){
            int ret = sum - i;
            return {ret, x[v]};
        }
    }
    cout << "IMPOSSIBLE\n";
    exit(0);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);

    cin >> n;
    for(int i=1;i<n;++i){
        cin >> p[i];
        --p[i];
        children[p[i]].push_back(i);
    }
    for(int i=0;i<n;++i) cin >> x[i];
    solve(0);
    cout << "POSSIBLE\n";

    return 0;
}

Measured memory_bytes: 8704
# B - Bingo
A = [0]*101
for i in range(3):
    tmp = list(map(int,input().split()))
    for j in range(3):
        A[tmp[j]] = 3*i+j+1
N = int(input())
S = set()
for _ in range(N):
    b = int(input())
    S.add(A[b])

def bingo(l):
    ans = False
    for x,y,z in l:
        if x in S and y in S and z in S:
            ans = True
            break
    return ans

if bingo([(1,2,3),(4,5,6),(7,8,9),(1,4,7),(2,5,8),(3,6,9),(1,5,9),(3,5,7)]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62056
/************************************/
/* NoobM							*/
/* File Name : cha.cpp				*/
/* Date : 13.07.2020 02:20:47 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	
	int num = 1;
	int s = n;
	if(k == 1) cout << 0 << endl;
	else if(n >= k) cout << 1 << endl;
	else {
	for(int i = 2; ;i++) {
		s--;
		if(s + n >= k) {
			
			cout << i << endl;
			break;
		}
		s += n;
	}
}
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> p(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf(n);
    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        x--; y--;
        uf.merge(x, y);
    }
    ll ans = 0;
    rep(i, n) {
        if (uf.is_same(i, p[i])) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int a, b;
    cin >> a >> b;
    rep(i, 1, 2000){
        if(floor(i * 0.08) == a && floor(i * 0.1) == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f;
    int A,B,C;
    while(cin>>a>>b>>c>>d>>e>>f){
        A=a*3600+b*60+c;
        B=d*3600+e*60+f;
        C=B-A;
        
        cout <<C/3600<<" "<<(C%3600)/60<<" "<<(C%3600)%60<<endl;
    }
}




Measured memory_bytes: 3108
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var before="";
var s=[];
for(var i=0;i<n;i++){
   var arr=Arr[i].split(" ");
   var a=arr[0];
   var b=arr[1]-0;
   if(i==0 && a==")")return console.log("NO");
   if(before==a){
      s[s.length-1]+=b;
   }
   else {
      if(a==")"){
         var z=s[s.length-1];
         if(z>b){s[s.length-1]-=b;}
         if(z<b){s.pop();s.pop();s.push(a);s.push(b-z);}
         if(z==b){s.pop();s.pop();}
      }else{
         s.push(a);s.push(b);before=a;
      }
   }
}
if(s.length==0){console.log("YES");}
else {console.log("NO");}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    set<ll> st;
    rep(i, 3) {
        ll num; cin >> num;
        st.insert(
            num
        );
    }
    if (st.size() == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

N = int(input())						# 5

from collections import defaultdict
D = defaultdict(int)

for i in range(N):
	s = input()
	l = sorted(s)
	s = "".join(l)
	D[s]+=1

p("D ",D)


ans=0
for k in D:
	i = D[k]
	ans += i*(i-1)//2

print(ans)


Measured memory_bytes: 22408
#include <bits/stdc++.h>
using namespace std;
int main() { 
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double c,c2,x,r1,r2,pi;
  pi=3.141592653589793238;
  r1=2*pi*(h*60+m)/720;
  r2=2*pi*m/60;
  if(r2<r1){
    x=r1-r2;
    }
  else{
    x=r2-r1;
    }
  c2=a*a+b*b-2*a*b*cos(x);
  c=sqrtl(c2);
  printf("%.12lf\n",c);
  cout<<endl;
  return 0;
  }
  
  



Measured memory_bytes: 4132
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k, x, y;
int a[N], d[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++){
		for (int j = i + 1; j <= n; j++){
			int mn = j - i;
			mn = min(mn, abs(i - x) + abs(j - y) + 1);
			mn = min(mn, abs(i - y) + abs(j - x) + 1);
			d[mn]++;
		}
	}
	for (int i = 1; i <= n - 1; i++){
		cout << d[i] << endl;
	}
	return 0;
}












Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N;
	cin >> N;
	int ans = 0;
	int MIN = 1000;
	vector<int> S(N);
	for (int i = 0; i < N; ++i) {
		cin >> S[i];
		ans += S[i];
		if (S[i] % 10 != 0) {
			MIN = min(MIN, S[i]);
		}
	}
	sort(S.begin(), S.end());

	if (ans % 10 != 0) {
		
	}
	else {
		if (MIN != 1000){
			ans -= MIN;
		}
		else {
			ans =0;
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

constexpr lli plusScore = (lli)1e6;

constexpr size_t asize = 26;
int main() {
	size_t D;
	cin >> D;
	vector<lli> C(asize);
	for (lli& i : C)cin >> i;
	vector<vector<lli>> S(D, vector<lli>(asize));
	for (auto& arr : S) {
		for (lli& i : arr) {
			cin >> i;
		}
	}

	vector<lli> T(D);
	for (lli& i : T)cin >> i;

	vector<int> lastOpen(asize, -1);


	auto calcScore = [&](const vector<lli>& t) {
		vector<lli> last_open(asize, -1);
		lli score = 0;
		for (int i = 0; i < D; i++) {
			score += S[i][t[i] - 1];
			last_open[t[i] - 1] = i;
			for (int j = 0; j < asize; j++) {
				score -= C[j] * (i - last_open[j]);
			}
			cout << score << endl;
		}
		return score + plusScore;
	};
	calcScore(T);
	//cout <<  << endl;
	return 0;
}



Measured memory_bytes: 3720
import java.io.IOException;
import java.util.Scanner;
 
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String string = scanner.next();
		int max = 0;
		int count = 0;
		for(int i = 0; i<n;i++){
			char c = string.charAt(i);
			if(c == 'I'){
				count++;
				max = Math.max(count, max);
			}else if (c == 'D') {
				count--;
				max = Math.max(count, max);
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 20564
import java.io.*;
 
class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] nums = br.readLine().split(" ");
        int num;
        int max, min;
        long sum;
        max = min = Integer.parseInt(nums[0]);
        sum = (long) max;
        for (int i = 1; i < n; i++) {
            num = Integer.parseInt(nums[i]);
            if (max < num) max = num;
            else if (min > num) min = num;
            sum += num;
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

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

int main()
{
    int H,N;
    int A=0;

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

    // printf("H=%d N=%d", H,N);

    for (int i=0; i < N; i++)
    {
        int a;
        scanf("%d", &a);
        // printf("a[i]=%d", i,a);
        A += a;
    }

    // printf("A=%d", A);


    if ( (H - A) <= 0 )
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<char>s(n);
	rep(i, 0, n)cin >> s[i];

	int ans = 0;
	bool flag100, flag10;
	rep(i, 0, 1000) {
		flag100 = 0; flag10 = 0;
		rep(j, 0, n) {
			int x = s[j] - '0';
			if (!flag100)
				if (x == (i - i % 100) / 100) {
					flag100 = true;
					continue;
				}
			if (flag100 == true && flag10 == false)
				if (x == (i % 100 - i % 10) / 10) {
					flag10 = true;
					continue;
				}
			if (flag100 == true && flag10 == true)
				if (x == i % 10) {
					ans++;
					break;
				}
		}
	}
	cout << ans << endl;
}




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

int main()
{
	long long int n;cin>>n;
	long long int arr[n][3];
	for(long long int i=0;i<n;i++)
	{
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	long long int a[n+1][2];
	a[0][0]=0;a[0][1]=0;
	for(int i=1;i<n;i++)	
	{	
		arr[i][0]=max(arr[i][0]+arr[i-1][1],arr[i][0]+arr[i-1][2]);
		arr[i][1]=max(arr[i][1]+arr[i-1][0],arr[i][1]+arr[i-1][2]);
		arr[i][2]=max(arr[i][2]+arr[i-1][1],arr[i][2]+arr[i-1][0]);
	}
	cout<<max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]));
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
public class Main{
	static Scanner sc = new Scanner(System.in);
	static double x[] = new double[3];
	static double y[] = new double[3];
	static double px, py;
	
	public static void main(String[] args) {
		
		while(sc.hasNext()){
			scan();
			double a = (x[2] - x[1]) * (py - y[1]) - (y[2] - y[1]) * (px - x[1]);
			double b = (x[0] - x[2]) * (py - y[2]) - (y[0] - y[2]) * (px - x[2]);
			double c = (x[1] - x[0]) * (py - y[0]) - (y[1] - y[0]) * (px - x[0]);
			
			if((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}

	static void scan(){
		
		for(int i = 0; i < 3; i++){
			x[i] = sc.nextDouble();
			y[i] = sc.nextDouble();
		}
		px = sc.nextDouble();
		py = sc.nextDouble();
	}
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end



int main(){
   int n,x,y; cin>>n>>x>>y; x--; y--;
   vector<int> res(n,0);
   rep(i,0,n)rep(j,i+1,n){
      int add=abs(i-j);
      chmin(add,abs(i-x)+abs(y-j)+1);
      chmin(add,abs(j-x)+abs(i-j)+1);
      res[add]++;
   }
   rep(i,1,n)cout<<res[i]<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;

int main() {
	ll N;
	ll ans = 0;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];
	ll max = A[0];
	for (ll i = 1; i < N; i++) {
		if (A[i] < max) {
			ans += max-A[i];
		}
		else max = A[i];
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define ge getchar()
#define Re read()

inline int read() {
	int x = 0, ch;
	while(!isdigit(ch = ge)) ;
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	return x;
}

int n;
int a[100100][5];
int v[2];

struct BIT {
	int T[100100];

	inline void Add(int p) { while(p <= n) ++T[p], p += p & -p; }
	inline int Query(int p) { int x = 0; while(p) x += T[p], p ^= p & -p; return x; }
}t[2];

int main() { n = Re;
	for(int j = 1; j <= 3; j++)
		for(int i = 1; i <= n; i++)
			a[i][j] = Re;
	for(int i = 1; i <= n; i++) {
		int x = a[i][1];
		v[i & 1] ^= (a[i][1] % 3) ^ 1;
		if((i & 1) != (x & 1)) { puts("No"); return 0; }
		if(x % 3 == 1 && a[i][2] == x + 1 && a[i][3] == x + 2) continue;
		else if(x % 3 == 0 && a[i][2] == x - 1 && a[i][3] == x - 2) continue;
		else { puts("No"); return 0; }
	}
	for(int i = 1; i <= n; i++) {
		int p = (a[i][1] - 1) / 3 + 1; t[i & 1].Add(n - p + 1);
		//	cout << i << ' ' << p << endl;
		if(i - 2 * t[i & 1].Query(n - p) < p) {
			v[(i & 1) ^ 1] ^= ((p - i + 2 * t[i & 1].Query(n - p)) >> 1) & 1;
		}
	}// cout << v[0] << ' ' << v[1] << endl;
	puts(!v[0] && !v[1] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 2944
N,X,Y = map(int, input().split())

from collections import defaultdict,deque
cnt = defaultdict(int)

INF = 10 ** 18

def bfs(n):
    que = deque([n])
    dist = [INF] * (N + 2)
    dist[n] = 0
    dist[0] = -INF
    dist[N + 1] = -INF
    
    while que:
        v = que.popleft()
        d = dist[v]

        # VIP
        if v == X:
            if dist[Y] > d + 1:
                dist[Y] = d + 1
                que.appendleft(Y)
        elif v == Y:
            if dist[X] > d + 1:
                dist[X] = d + 1
                que.appendleft(X)

        # --
        if dist[v - 1] > d + 1:
            dist[v - 1] = d + 1
            que.append(v - 1)
        
        # ++
        if dist[v + 1] > d + 1:
            dist[v + 1] = d + 1
            que.append(v + 1)
    
    for i in range(n+1, N+1):
        cnt[dist[i]] += 1


for i in range(1,N+1):
    bfs(i)
for k in range(1,N):
    print(cnt[k])

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

int seach(char in){
	int r;
	if(in=='a')r=1;
	else if(in=='z')r=1;
	else if(in=='q')r=1;
	else if(in=='x')r=1;
	else if(in=='s')r=1;
	else if(in=='w')r=1;
	else if(in=='c')r=1;
	else if(in=='d')r=1;
	else if(in=='e')r=1;
	else if(in=='v')r=1;
	else if(in=='f')r=1;
	else if(in=='r')r=1;
	else if(in=='b')r=1;
	else if(in=='g')r=1;
	else if(in=='t')r=1;
	
	
	else if(in=='y')r=0;
	else if(in=='h')r=0;
	else if(in=='n')r=0;
	else if(in=='m')r=0;
	else if(in=='j')r=0;
	else if(in=='u')r=0;
	else if(in=='i')r=0;
	else if(in=='k')r=0;
	else if(in=='l')r=0;
	else if(in=='o')r=0;
	else if(in=='p')r=0;
	
	return r;
}
int main(){
	string in;
	int i,r,l,total;
	while(cin>> in,in!="#"){
	l=seach(in[0]);
	total=0;
	for(int i=1;i<in.size();i++){
		r=seach(in[i]);
		if(l!=r)total++;
		l=r;
	}
	cout<<total<<endl;
	}
}

Measured memory_bytes: 1184
#include <iostream>
#include <queue>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 1e9;
const ll kLInf = 1e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
   int N;
   cin >> N;
   int **a = new int*[3];
   REP(i, 3) {
      a[i] = new int[N+5];
   }
   REP(j, N) {
      REP(i, 3) cin >> a[i][j];
   }
   ll **dp = new ll*[N+5];
   REP(i, N+5) dp[i] = new ll[3];
   REP(i, 3) dp[0][i] = a[i][0];
   REP(i, N-1) {
      dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[0][i+1];
      dp[i+1][1] = max(dp[i][0], dp[i][2]) + a[1][i+1];
      dp[i+1][2] = max(dp[i][0], dp[i][1]) + a[2][i+1];
      eprintf("%d: %lld, %lld, %lld\n", i, dp[i+1][0], dp[i+1][1], dp[i+1][2]);
   }
   cout << max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << endl;
   return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int dp[108000];
Int N, W, w, v;

int main(){
  cin >> N >> W;
  fill(dp, dp + 108000, INF);
  dp[0] = 0;
  for(Int i = 0;i < N;i++){
    cin >> w >> v;
    for(Int j = 108000;j - v >= 0;j--){
      dp[j] = min(dp[j], dp[j-v] + w);
    }
  }
  Int ans;
  for(Int i = 0;i < 108000;i++)if(dp[i] <= W)ans = i;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

bool check(int mid){
    ll x = 0;
    for(int i = 0 ; i <= mid ; i++){
        x += a[i];
    }
    for(int i = mid + 1 ; i < n ; i++){
        if(a[i] <= 2 * x) x += a[i];
        else return 0;
    }
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    sort(a.begin(), a.end());
    int l = 0, r = n - 1;
    while(l <= r){
        int mid = (l + r) / 2;
        if(check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    cout << n - l << endl;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n;
    while (cin >> n, n) {
        set<char> charset;
        bool top[26] = {};
        int vars[26] = {};
        REP(i, n) {
            string line;
            cin >> line;
            REP(j, line.length()) {
                charset.insert(line[j]);
            }
            if (line.length() > 1) top[line[0]-'A'] = true;
            int k = 1;
            int sign = i == n-1 ? -1 : 1;
            for (int j = line.length()-1; j >= 0; j--) {
                vars[line[j]-'A'] += k * sign;
                k *= 10;
            }
        }

//        for (auto x : vars) {
//            LOG("%c %d\n", x.first, x.second);
//        }

        int N = charset.size();
        vector<char> chars;
        for (char c : charset) chars.push_back(c);

        int res = 0;
        REP(i, 1<<10) {
            if (__builtin_popcount(i) == N) {
                int nums[10];
                int idx = 0;
                REP(j, 10) {
                    if (i & (1 << j)) {
                        nums[idx++] = j;
                    }
                }

//                LOG("---------> ");
//                REP(j, N) {
//                    LOG("%d ", nums[j]);
//                }
//                LOG("\n");

                do {
                    int ans = 0;

                    REP(j, N) {
                        if (nums[j] == 0 && top[chars[j]-'A']) goto NEXT;
                    }

                    REP(j, N) {
                        ans += vars[chars[j]-'A'] * nums[j];
                    }
                    if (ans == 0) res++;

//                    REP(j, N) {
//                        LOG("%d ", nums[j]);
//                    }
//                    LOG("\n");

NEXT: {}
                } while (next_permutation(nums, nums+N));
            }
        }

        cout << res << endl;
    }
}

Measured memory_bytes: 1228
S = input()

if S == 'SUN' :
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else :
    print(1)

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}

using namespace std;

int main() 
{	
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll i = 1;
	while (a > 0 && c > 0)
	{
		if(i & 1) c -= b;
		else a -= d;
		i++;
	}
	if(a <= 0) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3652
// :pray: :arrayman:
// :pray: :summit:
// :pray: :pusheen:
// :pray: :prodakcin:
// :pray: :spacewalker:
// :pray: :duk:
// :pray: :gustav:
// :pray: :tmw:
// :pray: :eed:
// :pray: :chicubed:
// :pray: :arceus:
// :pray: :gamegame:
// :pray: :sinx:
// :pray: :eyg:
// :pray: :evan:
// :pray: :cj:
// :pray: :steph:
// :pray: :fatant:
// :pray: :mathbot:
// :pray: :dolphin:
// :pray: :stef:
// :pray: :geothermal:
// :pray: :mikey:
// :pray: :horse:
// :pray: :snek:
// :pray: :wayne:
// :pray: :wu:
// :pray: :vmaddur:
// :pray: :dorijanko:
// :pray: :gaming:
// :pray: :kassuno:
// :pray: :hyacinth:
// :pray: :chilli:
// :pray: :dhruv:
// :pray: :philip:
// :pray: :paiman:
// :pray: :camel:
// :pray: :tree:
// :pray: :tux:
// :pray: :jony:
// :pray: :kage:
// :pray: :ghost:
// :pray: :aha:
// :pray: :coolguy:
// :pray: :imax:
// :pray: :howlet:
// :pray: :darren:
// :pray: :arie: 
// :pray: :blastman: 
// :pray: :zephyr: 
// :pray: :bigc:

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>

#define ll long long
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 100000

using namespace std;

int n;
int h[MAXN + 1];
int dp[MAXN + 1];

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

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

    for (int i = 1; i < n; i++) {
        if (i - 1 >= 0) {
            dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        }

        if (i - 2 >= 0) {
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }

    cout << dp[n - 1] << '\n';

    return 0;
}


Measured memory_bytes: 1024
N, M=map(int,input().split())

A=[]
B=[]
C=[]
D=[]


for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    
for _ in range(M):
    c,d=map(int,input().split())
    C.append(c)
    D.append(d)
     
for i in range(N):
        L=[]
        for j in range(M):
            K=abs(A[i]-C[j])+abs(B[i]-D[j])  
            L.append(K)  
        next
        P=L.index(min(L))
        print(P+1)

Measured memory_bytes: 3064