akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
using namespace std;

const int N = 200500;
bool was[N];

vector<int> E[N];

void DFS(int x) {
    was[x] = true;
    for (int y : E[x]) {
        if (!was[y])
            DFS(y);
    }
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int l;
            scanf("%d", &l);
            --l;
            E[i].push_back(n + l);
            E[n + l].push_back(i);
        }
    }
    DFS(0);
    bool ok = true;
    for (int i = 0; i < n; i++)
        ok &= was[i];
    puts(ok ? "YES" : "NO");
}


Measured memory_bytes: 8704
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int now[3][3][2],nex[3][3][2];
main()
{
	string s;
	while(cin>>s,s!="#")
	{
		vector<int>a;
		for(int i=0;i<s.size();i++)a.push_back((s[i]-'1')%3);
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<2;k++)now[i][j][k]=1e9;
		now[a[0]][2][0]=now[0][a[0]][1]=0;
		for(int i=1;i<s.size();i++)
		{
			for(int j=0;j<3;j++)for(int k=0;k<3;k++)for(int l=0;l<2;l++)nex[j][k][l]=1e9;
			for(int j=0;j<3;j++)for(int k=0;k<3;k++)
			{
				if(now[j][k][0]<1e9)
				{
					if(a[i]<=k)nex[a[i]][k][0]=min(nex[a[i]][k][0],now[j][k][0]+1);
					if(j<=a[i])nex[j][a[i]][1]=min(nex[j][a[i]][1],now[j][k][0]);
				}
				if(now[j][k][1]<1e9)
				{
					if(a[i]<=k)nex[a[i]][k][0]=min(nex[a[i]][k][0],now[j][k][1]);
					if(j<=a[i])nex[j][a[i]][1]=min(nex[j][a[i]][1],now[j][k][1]+1);
				}
			}
			swap(now,nex);
		}
		int ans=1e9;
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<2;k++)ans=min(ans,now[i][j][k]);
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3844
import math

if __name__ == '__main__':
    N = int(input())
    root_N_int = math.floor(math.sqrt(N))
    for A in range(root_N_int, 0, -1):
        if N % A == 0:
            B = int(N / A)
            break
    digit = len(str(B))
    print(digit)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		// 配列diceとcopydiceに数値を格納
		int dice[] = new int[6];
		int copydice[] = new int[6];
		for (int i = 0; i < 6; i++) {
			dice[i] = scanner.nextInt();
			copydice[i] = dice[i];
		}
		int dice2[] = new int[6];
		// 配列dice2に数値を格納
		for (int i2 = 0; i2 < 6; i2++) {
			dice2[i2] = scanner.nextInt();
		}
		// 乱数でdiceを転がす
		//Random random = new Random();
		//int count = 0;
		//while (true) {
			//int command = (1 + random.nextInt(4));
		String order ="NNNNWNNNWNNNENNNENNNWNNN";
		for (int count = 0; count < order.length(); count++) {
			char command = order.charAt(count);
			if (command == 'N') {
				dice[0] = copydice[1];
				dice[1] = copydice[5];
				dice[4] = copydice[0];
				dice[5] = copydice[4];

				for (int surface = 0; surface < 6; surface++) {
					copydice[surface] = dice[surface];
				}
			} else if (command == 'S') {
				dice[0] = copydice[4];
				dice[1] = copydice[0];
				dice[4] = copydice[5];
				dice[5] = copydice[1];

				for (int surface = 0; surface < 6; surface++) {
					copydice[surface] = dice[surface];
				}
			} else if (command == 'W') {
				dice[0] = copydice[2];
				dice[2] = copydice[5];
				dice[3] = copydice[0];
				dice[5] = copydice[3];

				for (int surface = 0; surface < 6; surface++) {
					copydice[surface] = dice[surface];
				}
			} else if (command == 'E') {
				dice[0] = copydice[3];
				dice[2] = copydice[0];
				dice[3] = copydice[5];
				dice[5] = copydice[2];

				for (int surface = 0; surface < 6; surface++) {
					copydice[surface] = dice[surface];
				}
			}

			if (dice[0] == dice2[0] && dice[1] == dice2[1] && dice[2] == dice2[2]
					&& dice[3] == dice2[3] && dice[4] == dice2[4] && dice[5] == dice2[5]) {
				break;
			}
			//if (count == 1000) {
				//break;
			//}
			//count++;
		}
		if (dice[0] == dice2[0] && dice[1] == dice2[1] && dice[2] == dice2[2]
				&& dice[3] == dice2[3] && dice[4] == dice2[4] && dice[5] == dice2[5]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}



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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a;
    int t;
    for(int i=0;i<n;i++) {
        cin >> t;
        a.push_back(t);
    }
    sort(all(a));
    
    cout << a.back() - *a.begin() << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


using Graph = vector<vector<int>>;
Graph G;
Vll c;
Vll ans;
void dfs(int v, int p=-1) {
  ans[v] = c[v];
  if (p != -1) ans[v] += ans[p];
  for (auto nv : G[v]) {
    if (nv == p) continue;
    dfs(nv, v);
  }
}


int main() {
  int n, q; cin >> n >> q;
  G = Graph(n);
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  c = Vll(n);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    c[p] += x;
  } 

  ans = Vll(n);
  dfs(0, -1);

  rep(i, n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    
    string t;
    cin >> t;
    string ans = "No";
    if(t.find(s) == 0){
        if(t.size() == s.size() +1){
            ans = "Yes";
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int a, aa;
    cin >> a;
    aa =a;
    int b = 3;
    int i;
    for (i=1; i<b; i++){
            a = a * aa;
    }

    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())

divisor = []
for i in range(1 , math.floor(N**(1/2))+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

if int(len(divisor)) == 1:
    print(N-1)
else:
    print(math.floor(min(distance))-2)

Measured memory_bytes: 3188
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	int l = 0;
	int r = 1;
	int res = 0;
	while (l < N) {
		while (r < N && a[l] == a[r]) r++;
		if (r - l < a[l]) res += r - l;
		else res += r - l - a[l];
		l = r;
		r++;
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

using namespace std;

char cell[16][16];
char co[] = {'o','x'};
int dx[] = {1, 1,  1,  0, -1, -1, -1, 0};
int dy[] = {1, 0, -1, -1, -1 , 0,  1, 1};


int check(int x, int y){
	if(x<0||y<0||8<=y||8<=x)return 0;
	return 1;
}

int cp(int index, int turn){
	if(turn == 0){
		return index < 8;
	}else{
		return index >= 0;
	}
}

int func(int turn){
	int get[8][8]={0};
	
	rep(i,8) rep(j,8)get[i][j]=-1;
	
	int di, f;
	if(turn==0){
		di = 1;
		f = 0;
	}
	else{
		di = -1;
		f = 7;
	}
	for(int i = f; cp(i,turn); i+=di)for(int j = f; cp(j,turn); j+=di){
		int t = 0;
		if(cell[i][j]=='.'){
			rep(k,8){
				int c = 0;
				int x = j+dx[k];
				int y = i+dy[k];
				while(check(x,y)){
					if(cell[y][x]==co[turn]){
						t+=c;
						break;
					}else if(cell[y][x] == co[1-turn]){
						c++;
					}else if(cell[y][x] =='.'){
						break;
					}
					y+=dy[k];
					x+=dx[k];
				}
			}
		}
		if(t==0)t=-1;
		get[i][j] = t;
	}
	
	//rep(i,8){rep(j,8){printf("%3d", get[i][j]);}puts("");}
	
	int mg = 0;
	rep(i,8)rep(j,8)mg = get[i][j]>mg?get[i][j]:mg;
	for(int i = f; cp(i,turn); i+=di)for(int j = f; cp(j,turn); j+=di){
		if(get[i][j] == mg){
			cell[i][j] = co[turn];
			rep(k,8){
				queue< pair<int,int> > c;
				int x = j+dx[k];
				int y = i+dy[k];
				while(check(x,y)){
					if(cell[y][x]==co[1-turn]){
						c.push(make_pair(x,y));
					}else if(cell[y][x] == co[turn]){
						while(!c.empty()){
							int xx=c.front().first;
							int yy=c.front().second;
							c.pop();
							cell[yy][xx]=co[turn];
						}
						break;
					}else if(cell[y][x] == '.'){
						break;
					}
					y+=dy[k];
					x+=dx[k];
				}
			}
	//		rep(k,8)puts(cell[k]);
	//		puts("");
			return 1;
		}
	}
	return 0;
}

int main(void){
	
	rep(i,8) scanf("%s", cell[i]);
	
	int t = 0;
	int turn = 0;
	
	while(t!=2){
		if(!func(turn)){
			t++;
		}else{
			t = 0;
		}
//		printf("%d\n", t);
		turn = 1 - turn;
	}	
	
	rep(i,8)puts(cell[i]);
	
	return 0;
}

Measured memory_bytes: 1152
n = int(input())
data = []
for i in range(n):
    a, b = map(int, input().split())
    data.append([a, b, a+b])
a_ans = 0
b_ans = 0
data.sort(key=lambda x: x[2] ,reverse=True)
for i in range(n):
    if i % 2 == 0:
        a_ans += data[i][0]
    else:
        b_ans += data[i][1]
print(a_ans - b_ans)


Measured memory_bytes: 24460
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define ctoi(c) c - '0'
#define tos(s) to_string(s)

typedef long long ll;


int main() {
    int n;
    cin >> n;
    int ans = 0;
    int a = 0;
    for (int i=1; i <= n; i++) {
        cin >> a;
        if (i % 2 == 1) {
            if (a % 2 == 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

/*
ACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACAC                                                                              
                                   ******,  .,, .,, ,,,    ****.**              
                                   ** . .,,,,,,,,,,,,,,,,,,,,,. .,*             
                                   **,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.            
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                    ****      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,      
              ***************,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,    
         ********************,,,,,,,,,,,,,,@@@,,,,,,,,,,,/@@@,,,,,,,,,,,,,,,    
        ******************,,,,,,,,,,,,,,,,,,(,,.         ,,,,,,,,,,,,,,,,,,,    
       ********************,,,,,,,,,,,*,,,,,.     %&&&     .,,,,*,,,,,,,,,,,,.  
       ***,,,,,,,,,,,,,,*,,,,,,,,,,,,,,,,,,,,               ,,,,,,,,,,,,,,,,,   
       ,,,,,,,,,,,,,,,,,,,**,,,,,,,,,,.......      ##(     ........,,,,,,,,,,.  
     .,,,,,,,,,,,,,,,,,,**,,,,,,,,,,..............    ..............,,,,,,,,    
    .,,,,,,,,,,,,,,,,,,,**,,,,,,,,,.................................,,,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,***,,,,,,,....................................,,,,,,,,,  
   ,,,,,,,,,,,,,,,,,,,,**,,,,,,,,.....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,**,,,,,,,,....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,,,     
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,.,,,,,     
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,        
     ,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................................,,,        
      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,          
       ..,,,,,,,,,,,,,,,,,,,,,,,,,,.................................,           
       .........**.....       ,,,,,..............................               
        .......*......                  ****,**,       ,..****                  
        .......*,....                   .......        ......                   
          .......*....                   .....          .....                   
                                         ......          .....                  
*/

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll s,w;
    cin>>s>>w;
    if(s>w)
        cout<<"safe"<<endl;
    else
        cout<<"unsafe"<<endl;
    return 0;
}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{     
    const int BTCtoJPY = 380000;
    public void Slove()
    {
        int n = int.Parse(Console.ReadLine());
        double sum =
            Enumerable.Range(0, n)
            .Select(x => Console.ReadLine().Split())
            .Select(x => double.Parse(x[0]) * (x[1] == "JPY" ? 1 : BTCtoJPY))
            .Sum();
        System.Console.WriteLine(sum);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int main(){
	std::string s;
	int n;
	std::cin >> n >> s;
	int c = 0;
	for(int i=0; i<n; i++){
		if(s[i]=='R') c++;
		else		  c--;
	}
	if(c>=1) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    string s;
    cin >> s;

    int n = s.size();
    int c = n;
    rep(i, n - 1) {
        if (s[i] != s[i+1]) {
            c = min(c, max(i + 1, n - i - 1));
        }

    }

    cout << c << endl;
}

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


Measured memory_bytes: 512
N = int(input())

score = 0
scoremax=0
for i in range(1, N+1):
    if i * (i + 1) >= 2*N:
        scoremax = i
        break
for i in range(scoremax, 0, -1):
    if score + i <= N:
        score += i
        print(i)
    if score == N:
        exit()


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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)

// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < n; ++i){
// 		res += max(0ll, a[i]-x/f[i]);
//     }
//     return res <= k;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }



int main(){
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  if(K % 2 == 1 && (B - A) <= 10e18) print(B - A);
  else if(K % 2 == 0 && (A - B) <= 10e18) print(A - B);
  else print("Unfair");
}

Measured memory_bytes: 256
N,M = map(int,input().split())
S = []
for m in range(M):
	nums = list(map(int,input().split()))
	S.append(nums[1:])
#print(S)
p = list(map(int,input().split()))
#print(p)

ans = 0
for bits in range(1<<N):
	for m in range(M):
		on = 0
		for s in S[m]:
			on += (bits>>(s-1))&1
		if (on&1) != p[m]:
			break  
	else:
		ans += 1

print(ans)


Measured memory_bytes: 3064
#include <cstdio>
int main(){
    int n, m;
    static int dict[256];

    char k,v,x;
    while(scanf("%d\n", &n)){
        if(!n) return 0;
        for(int i = 0; i < 256; i++) dict[i] = i;
        for(int i=0; i<n; i++){
            scanf("%c %c\n", &k, &v);
            dict[(int)k] = (int)v;
        }
        scanf("%d\n", &m);
        for(int i=0; i< m; i++){
            scanf("%c\n", &x);
            printf("%c", dict[(int)x]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 1000
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int main() {
	int a,b;
	cin >>a>>b;
	if(a+b>=10){
		cout << "error"<<endl;
	}else{
		cout << a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

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;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B;
    scan(A, B);
    long m = (A + B).max(A - B).max(A * B);
    writeln(m);
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ff first 
#define ss second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 998244853
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 

const ll INF=1e18; 
const int SIZE = 100005;
const int SSIZE = 1000005;

int main(){
    ll n;
    cin>>n;
    ll b[n+1];
    inp1(b,n-1)
    ll sum = b[1];
    rep(i,1,n-2){
        if(b[i+1]>=b[i]) sum += b[i];
        else sum += b[i+1];
    }
    sum += b[n-1];
    cout<<sum<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <typename Cost = int> class Edge{
public:
  int from,to;
  Cost cost;
  Edge() {}
  Edge(int to, Cost cost): to(to), cost(cost){}
  Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){}

  Edge rev() const {return Edge(to,from,cost);}
  
  friend ostream& operator<<(ostream &os, const Edge &e){
    os << "(FROM: " << e.from << "," << "TO: " << e.to << "," << "COST: " << e.cost << ")";
    return os;
  }
};

template <typename T> using Graph = vector<vector<Edge<T>>>;
template <typename T> using Tree = vector<vector<Edge<T>>>;

template <typename C, typename T> void add_edge(C &g, int from, int to, T w){
  g[from].push_back(Edge<T>(from, to, w));  
}

template <typename C, typename T> void add_undirected(C &g, int a, int b, T w){
  g[a].push_back(Edge<T>(a, b, w));
  g[b].push_back(Edge<T>(b, a, w));
}

LLI dp[300000];
LLI counter[300000];

void dfs(int cur, int par, const Tree<int> &tree){
  if(par>=0) dp[cur] += dp[par];
  dp[cur] += counter[cur];

  for(auto &e : tree[cur]){
    if(e.to == par) continue;
    dfs(e.to, cur, tree);
  }
  
  return;
}


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

  int N,Q;
  while(cin >> N >> Q){
    Tree<int> tree(N);
    REP(i,N-1){
      int a,b; cin >> a >> b;
      --a, --b;
      add_undirected(tree,a,b,1);
    }

    fill_array(counter, 0);
    fill_array(dp, 0);

    
    REP(i,Q){
      int p,x; cin >> p >> x;
      --p;
      counter[p] += x;
    }
    
    dfs(0,-1,tree);

    REP(i,N){
      if(i) cout << " ";
      cout << dp[i];
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	if(x<0)putchar('-'),x=-x;
	int y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
int n,a[200005];
set<pair<int,ll> > s;
int main(){
	n=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	s.insert({0,0});
	for(int i=0;i<n;i++){
		auto it=s.lower_bound({a[i],0});
		it--;
		ll x=read(),y=x+it->second;
		it++;
		while(it!=s.end() and it->second<=y)
			s.erase(it++);
		s.insert({a[i],y});
	}
	print((*(--s.end())).second);
    return 0;
}

Measured memory_bytes: 13568
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX 10

int n, k, ice[MAX];

int main() {
	while (1) {
		scanf("%d", &n);
		if (n == 0)
			return 0;

		for(int i = 0; i < MAX; i++)
			ice[i] = 0;

		while(n-- > 0) {
			scanf("%d", &k);
			ice[k]++;
		}

		for(int i = 0; i < MAX; i++) {
			if(ice[i] > 0)
				while(ice[i]-- > 0)
					printf("*");
			else
				printf("-");
			puts("");
		}
	}
}

Measured memory_bytes: 0
import fractions
def LCM(a,b):
    return int(a*b/fractions.gcd(a,b))
A,B,C,D = map(int,input().split())#A以上B以下
L = LCM(C,D)
Cbaisu = (B//C) - ((A-1)//C)
Dbaisu = (B//D) - ((A-1)//D)
Lbaisu = (B//L) - ((A-1)//L)
print(B-A+1 - Cbaisu - Dbaisu + Lbaisu)

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



int64_t myupperbinarysearch(vector<int64_t> &vec, int64_t b){
  

  
  int64_t left=0;
  int64_t right=int64_t(vec.size());

  while (left<right){
    int64_t mid=(left+right)/2;
    if ((vec.at(mid)>b and mid==0)or(vec.at(mid)>b and vec.at(mid-1)<=b)){
      return mid;
    }
    
    else if (vec.at(mid)>b){
      right=mid;
    }
    
    else if (vec.at(mid)<=b){
      left=mid+1;
    }
  }
  
  return int64_t(vec.size());
}

int64_t mylowerbinarysearch(vector<int64_t> &vec, int64_t b){
  
  int64_t left=0;
  int64_t right=int64_t(vec.size());
  
  while (left<right){
    int64_t mid=(left+right)/2;
    if ((vec.at(mid)>=b and mid==0)or(vec.at(mid)>=b and vec.at(mid-1)<b)){
      return mid;
    }
    
    else if (vec.at(mid)>=b){
      right=mid;
    }
    
    else if (vec.at(mid)<b){
      left=mid+1;
    }
  }
  
  return int64_t(vec.size());
}




int main(){
  
  
  int64_t n;
  cin>>n;
  
  vector<int64_t> asize(n),bsize(n),csize(n);
  
  for (int64_t i=0;i<n;i++){
    cin>>asize.at(i);
  }
  for (int64_t i=0;i<n;i++){
    cin>>bsize.at(i);
  }  
  for (int64_t i=0;i<n;i++){
    cin>>csize.at(i);
  }
  
  sort(asize.begin(),asize.end());
  sort(bsize.begin(),bsize.end());
  sort(csize.begin(),csize.end());
  
  int64_t answer=0;
  
  for (int64_t b:bsize){
    answer+=mylowerbinarysearch(asize,b)*(n-myupperbinarysearch(csize,b));
  }
  
    
  cout<<answer<<endl;
  
               
    
    
  
  
  
  
  
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int,int>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define inf 1e9
void solve(){
	int n;
	cin>>n;
	int a[n];
	int mini=inf,maxi=-inf;
	rep(i,0,n){
		cin>>a[i];
		mini=min(mini,a[i]);
		maxi=max(maxi,a[i]);
	}
	ll ans=inf;
	rep(i,mini,maxi+1){
		ll loc=0;
		rep(j,0,n){
			loc+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,loc);
	}
	cout<<ans<<endl;

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <functional>
#include <climits>
#include <queue>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n';)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;if((c=gcu())=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i, n) for(int i = n;i;i--)

struct edge {int t, c, r;};

int main() {
	int V {in}, E {in}, s {}, t {V - 1};
	vector<vector<edge>> G(V);
	times (i, E) {
		int f {in}, t{in}, c {in};
		G[f].push_back({t, c, (int) G[t].size()});
		G[t].push_back({f, 0, (int) G[f].size() - 1});
	}
	int f {};
	for (;;) {
		vector<int> l(V, -1);
		l[s] = 0;
		queue<int> q;
		q.push({0});
		while (!q.empty()) {
			auto n = q.front();
			q.pop();
			for (edge e: G[n])
				if (e.c > 0 && l[e.t] < 0) {
					l[e.t] = l[n] + 1;
					q.push(e.t);
				}
		}
		if (l[t] < 0) {
			outl(f);
			return 0;
		}
		vector<int> I(V);
		function<int(int, int)> dfs = [&](int v, int f){
			if (v == t)
				return f;
			for (int &i = I[v]; i < (int) G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.c > 0 && l[v] < l[e.t]) {
					int d {dfs(e.t, min(f, e.c))};
					if (d > 0) {
						e.c -= d;
						G[e.t][e.r].c += d;
						return d;
					}
				}
			}
			return 0;
		};
		for (int u; (u = dfs(s, INT_MAX)) > 0; f += u)
			;
	}
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int r, D, x;
signed main() {
    cin >> r >> D >> x;
    rep(i, 10) {
        x = r * x - D;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#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()
{
    ll n; cin >> n;
    vll a(n); rep(i, n) cin >> a[i];
    ll x1 = 0;
    rep(i, n) {
        x1 += (i % 2 == 0 ? 1 : -1) * a[i];
    }
    cout << x1 << " ";
    rep(i, n - 1) {
        x1 = 2 * a[i] - x1;
        cout << x1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>
int main (){
int max=0,sum=0,k,a[21],i,j;
scanf ("%d",&k);
  for (i=0;i<k;i++){
  scanf ("%d",&a[i]);
  if(max<a[i]){
    max=a[i];
  }
    if (max-1<a[i]){
    sum++;
    }
  }
  
printf ("%d\n",sum);
return 0;
}

Measured memory_bytes: 128
h,w = map(int, input().split())

s = [list(map(str,input().split())) for i in range(h)]

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

answer = ""
for i in range(h):
  for j in range(w):
    if s[i][j] == "snuke":
      answer = alphabet[j] + str(i+1)

print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	int a[5],i;
	rep(i,5)
	{
		cin >> a[i];
	}
	rep(i,5)
	{
		if(a[i]==0)
		{
			cout << i+1;
		}
	}
	return 0;
}


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

  int N, M;
  cin >> N >> M;
   
  vector< int > ans(N);
  
  for(int i=0; i < M*2; i++){
  int a;
    cin >>a;
 a--;
    
    ans.at(a)  +=1;
      }
  for (int i=0; i < N; i++) {
 
    cout << ans.at(i) << endl;
  }
  
}

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

typedef long long ll;

using namespace std;

int main(){
ll N,M; cin >> N >> M;
  vector<pair<ll,ll>> vec(N+M); for(ll i = 0; i < N; i++){ cin >> vec[i].first;
                                                        vec[i].second = 1;}
  for(ll i = 0; i < M; i++){ cin >> vec[i + N].second >> vec[i + N].first;}
  //vecの第一成分が値、第二成分が個数を表す
  
  sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end());
  
  ll i = 0;  ll count = 0; ll sum = 0;
  
  while( count <  N)
  { sum += vec[i].first * vec[i].second; 
    count += vec[i].second; i++;}
  
  sum -= vec[i-1].first * ( count - N ); cout << sum << endl; return 0;}
 
  

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

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

int N;
P p[400000];

bool check(long long int k){
	
	//cout << k << endl;
	
	priority_queue<long long int> que;
	
	long long int ss = 0;
	
	for(int i = 0; i < k; i++){
		que.push(p[i].second);
		ss += p[i].second;
	}
	
	if(ss <= k * p[k - 1].first){
		return true;
	}
	
	for(int i = k; i < N; i++){
		ss += p[i].second;
		que.push(p[i].second);
		ss -= que.top();
		que.pop();
		
		//cout << ss << " " << p[i].first << endl;
		
		if(ss <= k * p[i].first){
			return true;
		}
		
	}
	
	return false;
}

long long int bin_search(long long int lef, long long int rig){
	long long int middle = (lef + rig) / 2;
	//cout << middle << " ";
	if(rig - lef <= 1){
		if(check(rig)){
			return rig;
		}else{
			return lef;
		}
	}
	if(check(middle)){
		lef = middle;
	}else{
		rig = middle;
	}
	return bin_search(lef, rig);
}

int main(){
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> p[i].second >> p[i].first;
	}
	
	p[N].first = 0;
	p[N].second = 1000;
	
	N++;
	
	sort(p, p + N, greater<P>());
	
	cout << bin_search(0, N) << endl;
	
	return 0;
}



Measured memory_bytes: 15344
import sys
input = sys.stdin.readline

N = int(input())
R = []

for i in range(N):
	x,l = map(int, input().split())
	R.append([max(x-l,0),x+l])
R.sort(key = lambda r : r[1])

ans = N
lr = -1
for i in range(N):
	if(lr > R[i][0]):
		ans -=1
		continue
	else:
		lr = R[i][1]
print(ans)

Measured memory_bytes: 21284
X,Y = map(int,input().split())
M = 10**9+7
if X%3 == Y%3 == 1 or X%3 == Y%3 == 2:
    Answer = 0
else:
    dif = abs(X-Y)
    W =  (min(X,Y) - dif)//3
    X1 = W + dif
    Y1 = W
    Answer = 1
    N = X1+Y1
    for i in range(1,X1+1):
        Answer = (Answer*(N)*pow(i,-1,M))%M
        N -= 1
    for j in range(1,Y1+1):
        Answer = (Answer*(N)*pow(j,-1,M))%M
        N -= 1
print(Answer)

Measured memory_bytes: 8932
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;




int main()
{
    int h, w, k;

    cin >> h >> w >> k;
    int D = 0;
    vector<vector<char>>t(h, vector<char>(w));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            cin >> t[i][j]; if (t[i][j] == '#')D++;
        }
    ll ans = 0;

    for (int i = 0; i < (1 << h); i++) {
        vector<int>a;
        for (int ak = 0; ak < h; ak++)if (i & (1 << ak))a.push_back(ak);
        for (int j = 0; j < (1 << w); j++) {
            vector<int> b;
            for (int ak = 0; ak < w; ak++)if (j & (1 << ak))b.push_back(ak);
            int r = 0;
            vector<vector<char>>p;
            p = t;
            for (int ia = 0; ia < a.size(); ia++) {
                
                for (int ja = 0; ja < w; ja++) {
                    if (p[a[ia]][ja] == '#') {
                        r++; p[a[ia]][ja] = '.';
                    }
                }
            }
            
            for (int ja = 0; ja < b.size(); ja++) {
                for (int ia = 0; ia < h; ia++) {
                    if (p[ia][b[ja]] == '#') {
                        r++; p[ia][b[ja]] = '.';
                    }
                }
            }
            
            if (D-r == k)ans++;
//cout << a.size() << " " << b.size()<<" "<<r<< endl;




        }
    }
    cout << ans << endl;



    return 0;

}

Measured memory_bytes: 3628
#include <stdio.h>
#define Q 200
#define N 20
int i,n,A[N],M[Q],f,q;

main(){
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&M[i]);
  }
  for(i = 0; i < q; i++){
    f = 0;
    element(0, M[i]);
    if(f == 1){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}
  
void element(int i, int q){
  if(q == 0){
    f = 1;
  }else if(i != n){
    element(i + 1, q - A[i]);
    element(i + 1, q);
  }
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define int long long
#define ll long long
#define moder 1000000007
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
signed main(){
	int x;
	cin>>x;
	if(x==3||x==5||x==7)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>

int main()
{
  long long a,b,x,p,q,ans;
  scanf("%lld%lld%lld",&a,&b,&x);
  p=(a+x-1)/x;
  q=b/x;
  ans=q-p+1;
  if(ans<0) ans=0;
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long X, long long Y) {
    vector<ll> res(100001);
    rep(i, N) {
        rep(j, N) {
            if (i >= j) continue;
            ll c = min(j - i, abs(i - X) + abs(j - Y) + 1);
            c = min(c, abs(i - Y) + abs(j - X) + 1);
            res[c]++;
        }
    }
    repn(i, N - 1) cout << res[i] << endl;
}

int main() {
    long long N;
    long long Y;
    long long X;
    scanf("%lld", &N);
    scanf("%lld", &X);
    scanf("%lld", &Y);
    X--;
    Y--;
    solve(N, X, Y);
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    int n;
    ll k;
    cin >> n >> k;

    struct Node {
        int to     = 0;
        bool visit = false;
        int visIdx = 0;
    };

    vector<Node> graph(n, {0, false, 0});
    rep(i, 0, n) {
        int _to;
        cin >> _to;
        graph[i].to = --_to;
    }

    int from       = 0;
    int to         = 0;
    bool hasCircle = false;
    // rep(i, 0, k) {
    for (ll i = 0; i < k; i++) {
        // printf("%lld: %d -> ", i, from);
        //閉路未検出
        if (hasCircle) {
        }
        // 検出済
        else {
            // 訪問済: つまり閉路検出
            if (graph[from].visit) {
                hasCircle = true;
                ll len    = i - graph[from].visIdx;
                ll rest   = (k - i) % len;
                ll num    = (k - i) / len;
                // printf("  is Circle\n %lld = %lld + %lld * %lld + %lld\n", k, i, len, num, rest);
                i += len * num;
                if (rest == 0) continue;
            }
            // 未訪問
            else {
                graph[from].visit  = true;
                graph[from].visIdx = i;
            }
        }
        from = graph[from].to;
        // printf("%d\n", from);
    }

    cout << ++from << endl;
    return 0;
}


Measured memory_bytes: 5620
#include <iostream>
#include <string.h>
#define MAX_N 100
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  int F[MAX_N][10];
  rep(i, N) {
    rep(j, 10) { cin >> F[i][j]; }
  }
  int P[MAX_N][11];
  rep(i, N) {
    rep(j, 11) { cin >> P[i][j]; }
  }

  int64_t Ans = INT64_MIN;
  for (int plan = 1; plan < 1024; plan++) {
    int C[MAX_N];
    memset(C, 0, sizeof(int) * N);
    rep(j, 10) {
      int open = plan & (1 << j);
      rep(k, N) {
        if (open && F[k][j])
          C[k]++;
      }
    }
    int64_t CC = 0;
    rep(k, N) { CC += P[k][C[k]]; }
    Ans = max(Ans, CC);
  }
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,i,sum,hit;
	
	while(scanf("%d",  &n), n != 0){
		
		sum = 0;
		
		n /= 4;
		
		for(i = 0; i < n; i++){
			scanf("%d", &hit);
			sum += hit;
		}
		
		printf("%d\n", sum);
	}
	
	return(0);
}

Measured memory_bytes: 600
#include<cstdio>
#include <cstdlib>
#include <string>
using namespace std;
int main() {
char a[100];
string str[3];
for(int i = 0; i < 3; i++) {
scanf("%s", a);
str[i] = a;
if(str[i].size() == 0) {printf("NO\n"); return 0;}
}
bool res = str[0][str[0].size() -1 ] == str[1][0];
res = res && str[1][str[1].size() -1 ] == str[2][0];
printf("%s\n", res? "YES": "NO");
return 0;
}

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

public class P
{
    public int p { get; set; }
    public int h { get; set; }
}

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim()) + 1;
        var s = Console.ReadLine().Trim() + " 0";
        string[] line = s.Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ans = getAns(a, n);
        Console.WriteLine(ans);
    }
    static long getAns(int[] a, int n)
    {
        var ans = 0L; var lastp = 0;
        var st = new Stack<P>();
        for (int i = 0; i < n; i++)
        {
            if (st.Count() == 0) st.Push(new P { p = i, h = a[i] });
            else
            {
                var w = st.Peek();
                if (a[i] > w.h) st.Push(new P { p = i, h = a[i] });
                else if (a[i] < w.h)
                {
                    while (true)
                    {
                        ans = Max(ans, (long)(i - w.p) * w.h);
                        lastp = w.p;
                        st.Pop();
                        if (st.Count() == 0) break;
                        w = st.Peek();
                        if (a[i] <= w.h) continue;
                        else break;
                    }
                    st.Push(new P { p = lastp, h = a[i] });
                }
            }
        }
        return ans;
    }
}



Measured memory_bytes: 35460
#include<bits/stdc++.h>
using namespace std;
#define f1(a,b,c) for(int c=a;c<=b;c++)
#define f2(a,b,c) for(int c=a;c>=b;c--)
#define f3(a,b,c) for(int c=a;c;c=b)
#define so1(a,n) sort(a+1,a+n+1,mycmp);
#define so2(a,n) sort(a+1,a+n+1);
#define ll long long
#define itn int
#define ubt int 
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
const int twx=2e3+100;
const int MOD=1e9+7;
const int inf=0x3f3f3f3f;
ll read()
{
    ll sum=0;
    ll flag=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            flag=-1;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        sum=((sum*10)+c-'0');
        c=getchar();
    }
    return sum*flag;
}
int n,m,k;
int asd[twx<<1][twx][2];
int ans;
int sum[twx];
ll add(ll x,ll y)
{
    return x+y>=MOD?x+y-MOD:x+y;
}
ll sub(ll x,ll y)
{
    return x-y<0?x-y+MOD:x-y;
}
ll mul(ll x,ll y)
{
    return 1LL*x*y%MOD;
}
void init()
{
	n=read();
    m=read();
    k=read();
}
void work()
{
    asd[0][0][0]=1;
    f1(1,n+m,i)
    {
        sum[0]=add(asd[i-1][0][0],asd[i-1][0][1]);
        f1(1,n,j)
        {
            sum[j]=add(sum[j-1],add(asd[i-1][j][0],asd[i-1][j][1]));
        }
        f1(0,n,j)
        {
            asd[i][j][0]=add(asd[i-1][j][0],asd[i-1][j][1]);
            if(j)
            {
                asd[i][j][1]=sub(sum[j-1],(j-k>=0?sum[j-k]:0));
            }
        }
        f1(0,n,j)
        {
            if(j%(k-1)==n%(k-1)&&(i*(k-1)-j+1)%(k-1)==m%(k-1)&&i*(k-1)-j+1<=m)
            {
                ans=add(ans,asd[i][j][1]);
            }
        }
    }
}
void print()
{
	printf("%d\n",ans);
}
int main()
{
    init();
    work();
    print();
    return 0;
}

Measured memory_bytes: 67968