akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let mut s:Vec<char> = read::<String>().chars().collect();
    s.sort();
    let s:String = s.into_iter().collect();

    println!("{}", if s == "abc" {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <cstdio>

int linearSearch(int *S, int key, int n){
	int i, count;
	count = 0;
	for(i=0;i<n;i++){
		if(S[i] == key){
			count ++;
			break;
		}
	}
	return count;
}


int main(void){
	int i,n,q, key, count;
	int *S;
	count = 0;
	scanf("%d", &n);
	S = new int[n];
	for (i=0; i<n; i++){
		scanf("%d", &S[i]);
	}
	
	scanf("%d", &q);
	for (i=0;i<q;i++){
		scanf("%d", &key);
		count += linearSearch(S, key, n);
	}

	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

string binary(int a, int b){
    string ans = "";
    FOR(i,0,b-1){
        if (a % 2 == 1) ans += '1';
        else ans += '0';
        a /= 2;
    }
    return ans;
}
int main()
{
    int h,w,k; cin >> h >> w >> k;
    string C[h];
    FOR(i,0,h-1) cin >> C[i];
    int H = (1 << h); int W = (1 << w);
    int cnt = 0;
    FOR(i,0,H-1){
        FOR(j,0,W-1){
            string sh = binary(i, h);
            string sw = binary(j, w);
            int c = 0;
            FOR(k,0,h-1){
                FOR(l,0,w-1){
                    if (sh[k] == '1' && sw[l] == '1' && C[k][l] == '#') c++;
                }
            }
            if (c==k) cnt++;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3624
#define DEBUG 0

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2/24/2019, 9:21:23 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
const ll infty = 10000000000000007;

int A, B, Q;
ll s[100010];
ll t[100010];
ll x[100010];

void flush(ll y)
{
  int lb = 0;
  int ub = A;
  while (ub - lb > 1)
  {
    int temp = (lb + ub) / 2;
    if (y > s[temp])
    {
      lb = temp;
    }
    else
    {
      ub = temp;
    }
  }
  int ind_a = lb;
  lb = 0;
  ub = B;
  while (ub - lb > 1)
  {
    int temp = (lb + ub) / 2;
    if (y > t[temp])
    {
      lb = temp;
    }
    else
    {
      ub = temp;
    }
  }
  int ind_b = lb;
  ll p0 = s[ind_a];
  ll p1 = s[ind_a + 1];
  ll q0 = t[ind_b];
  ll q1 = t[ind_b + 1];
#if DEBUG == 1
  cerr << y << " " << p0 << " " << p1 << " " << q0 << " " << q1 << endl;
#endif
  ll ans = min(y - min(p0, q0), max(p1, q1) - y);
  ans = min(ans, 2 * (p1 - y) + (y - q0));
  ans = min(ans, (p1 - y) + 2 * (y - q0));
  ans = min(ans, 2 * (q1 - y) + (y - p0));
  ans = min(ans, (q1 - y) + 2 * (y - p0));
  cout << ans << endl;
}

int main()
{
  cin >> A >> B >> Q;
  s[0] = -infty;
  for (auto i = 1; i <= A; i++)
  {
    cin >> s[i];
  }
  s[A + 1] = infty;
  A += 2;
  t[0] = -infty;
  for (auto i = 1; i <= B; i++)
  {
    cin >> t[i];
  }
  t[B + 1] = infty;
  B += 2;
  for (auto i = 0; i < Q; i++)
  {
    cin >> x[i];
  }
  for (auto i = 0; i < Q; i++)
  {
    flush(x[i]);
  }
}

Measured memory_bytes: 3712
#include<stdio.h>
#include<string.h>
void N(int dice[]);
void E(int dice[]);
void S(int dice[]);
void W(int dice[]);
int main(void){
	int dice1[6];
	char dir[101];
	int len,i;
	scanf("%d %d %d %d %d %d",&dice1[0],&dice1[1],&dice1[2],&dice1[3],&dice1[4],&dice1[5]);
	scanf("%s",&dir);
	len=strlen(dir);
	for(i=0;i<len;i++){
		switch(dir[i]) {
		case 'N':
			N(dice1);
			break;
		case 'E':
			E(dice1);
			break;
		case 'S':
			S(dice1);
			break;
		case 'W':
			W(dice1);
			break;
		}
	}
	printf("%d\n",dice1[0]);
	return 0;
}
void N(int dice[]){
	int tmp;
	tmp=dice[0];
	dice[0]=dice[1];
	dice[1]=dice[5];
	dice[5]=dice[4];
	dice[4]=tmp; 
}
void E(int dice[]){
	int tmp;
	tmp=dice[0];
	dice[0]=dice[3];
	dice[3]=dice[5];
	dice[5]=dice[2];
	dice[2]=tmp;
}
void S(int dice[]){
	int tmp;
	tmp=dice[0];
	dice[0]=dice[4];
	dice[4]=dice[5];
	dice[5]=dice[1];
	dice[1]=tmp;
}
void W(int dice[]){
	int tmp;
	tmp=dice[0];
	dice[0]=dice[2];
	dice[2]=dice[5];
	dice[5]=dice[3];
	dice[3]=tmp;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  string s;cin>>s;

  bool e=true;

  rep(i,0,s.size()){
    if((i+1)%2==1){
      if(s[i]=='R'||s[i]=='U'||s[i]=='D'){}
      else {e=false;break;}
    }else{
      if(s[i]=='L'||s[i]=='U'||s[i]=='D'){}
      else {e=false;break;}
    }
  }
  if(e)out("Yes");
  else out("No");

  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < 3; i++) set.add(sc.nextInt());
        System.out.println(set.size() == 2 ? "Yes" : "No" );
    }
}


Measured memory_bytes: 22736
#include <stdio.h>

int MAX(int a,int b){
    return a>b?a:b;
}
int main()
{   int h,w;
    scanf("%d%d",&h,&w);
    char s[h][w+1];
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    int width[h+1][w+1],height[h+1][w+1];
    for(int i=0;i<h;i++){
        //printf("\n");
        int j=0;
        while(j<w){
            while(s[i][j]=='#'&&j<w){
                width[i][j]=0;
                j++;
            }
            int left=j;
            while(s[i][j]=='.'&&j<w){
                j++;
            }
            //printf("exit w loop left=%d,j=%d ",left,j);
            for(int k=left;k<j;k++){
                width[i][k]=j-left;
            }
        }
        
    }
    for(int i=0;i<w;i++){
        int j=0;
        while(j<h){
            while(s[j][i]=='#'&&j<h){
                height[j][i]=0;
                j++;
            }
            int top=j;
            while(s[j][i]=='.'&&j<h){
                j++;
            }
            
            for(int k=top;k<j;k++){
                height[k][i]=j-top;
            }
        }
        
    }
    int ans=0;
    //printf("height\n");
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //printf("%d ",height[i][j]);
            ans=MAX(ans,width[i][j]+height[i][j]);
        }
        //printf("\n");
    }
    
    /*printf("width\n");
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("%d ",width[i][j]);
        }
        printf("\n");
    }*/
    printf("%d",ans-1);

    return 0;
}


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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  char c = S[K - 1];
  for (int i = 0; i < N; i++) {
    if (S[i] != c) S[i] = '*';
  }
  cout << S;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    long K = sc.nextLong();
    
    int[][] x = sc.nextIntTable(N, 2);
    Arrays.sort(x, (a, b) -> a[0] - b[0]);
    
    long total = 0;
    for (int[] v: x) {
      total += v[1];
      if (total >= K) {
        System.out.println(v[0]);
        break;
      }
    }
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 28740
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back
using namespace std;
typedef long long int ll;
int  main(){
	char a;
	cin>>a;
	cout<<(char)('a'+(a-'a'+1))<<endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF 1e9;
#define INFL 1e18;
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class DDisjointSetOfCommonDivisors {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll A, B;
        in >> A >> B;
        ll G = gcd(A, B);
        set<ll> ans;
        ans.insert(1);
        ll a = 2;
        while (G >= a * a) {
            if (G % a == 0) {
                G /= a;
                ans.insert(a);
            } else {
                a++;
            }
        }
        ans.insert(G);
        out << ans.size() << '\n';
	}
};


int main() {
	DDisjointSetOfCommonDivisors solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#if 0
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1142&lang=jp
#endif

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <unordered_set>

#define FOR(var, start, count) for(int var=start; var<count; var++)
#define REP(var, count) FOR(var,0,count)

using namespace std;

int main(void) {

	int M;
	cin >> M;
	REP(dataset, M) {
		string str;
		cin >> str;
		
		unordered_set<string> list;
		
		REP(i, str.size()) {
			string s[2][2];
			s[0][0] = str.substr(0, i);
			s[1][0] = str.substr(i);
			
			s[0][1] = s[0][0];
			reverse(s[0][0].begin(), s[0][0].end());
			s[1][1] = s[1][0];
			reverse(s[1][0].begin(), s[1][0].end());
			
			REP(x, 2) {
				REP(y, 2) {
					REP(z, 2) {
						string k = s[x][y] + s[(x+1)%2][z];
						list.insert(k);
					}
				}
			}
		}
		
		cout << list.size() << endl;
	
	}

}

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

int main() {
  int n, ab, l, r, m, s=0;
  cin >> n;
  vector<int> L(n);
  for(int i=0; i<n; i++) cin >> L[i];
  sort(L.begin(), L.end());
  for(int a=0; a<n; a++) for(int b=a+1; b<n; b++) {
    ab=L[a]+L[b], l=b, r=n;
    while(l+1<r) {
      m=(l+r)/2;
      if(ab>L[m]) l=m; else r=m;
    }
    s+=l-b;
  }
  cout << s << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   string s;
   int count = 0;
   cin >> s;
   bool flag = false;
   if(s[0]!='A') {
       cout << "WA" << endl;
       return 0;
   }
   for(int i = 1;i < s.length();i++) {
       if(s[i]>'z'||s[i]<'a') {
        //    cout << i << ":" << s[i] << endl;
           if(s[i]=='C'&&i!=1&&i!=s.length()-1) {
               count++;
               if(count>1) {
                   cout << "WA" << endl;
                   return 0;
               }
           } else {
               cout << "WA" << endl;
               return 0;
           }
       }
   }
   if(count==1) cout << "AC" << endl;
   else cout << "WA" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000;
char cn[CM + 10], * ci = cn + 10, * owa = cn + CM;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	char c = ci[8];
	ci[8] = 0;
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci[8] = c;
	ci += (64 - dig >> 3) + 1;

	if (ci - owa > 0) {
		memcpy(cn, owa, 10);
		ci -= CM;
		fread(cn + 10, 1, CM, stdin);
	}
	return tmp;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 + 10];
	char* K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[0] = C;
		K[1] = di;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = di;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue) {
		for (auto i = f.K[ue]; i < f.K[ue + 1]; i++)* di++ = *i;
		int sita = X - ue * 100000ll;
		rep(i, 5 - (f.K[sita + 1] - f.K[sita]))* di++ = '0';
		for (auto i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = *i;
	}
	else for (auto i = f.K[X]; i < f.K[X + 1]; i++)* di++ = *i;
	*di++ = '\n';
}

int B[200001];

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


	fread(ci, 1, CM, stdin);

	int N = getint();
	ll kotae = 1;
	int A[200000];
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int *a = A;
	
	int amari = N % 10800;
	int shou = N / 10800;
	rep(j, shou) {
		rep(k, 10800) putint(kotae - B[*a++]);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[*a++]);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,ans,j,k,q,c,x,y;
    cin>>a;
    j=0;
    fr(i,1000010){
        j=j*10;
        j+=7;
        j=j%a;
        if(j==0){
            cout<<i+1;
            exit(0);
        }
    }
    cout<<-1;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
long long a[100005],b[100005];
vector<long long>v[100];
int main()
{
    long long t,n,m,i,j,k,x=0,y=0,z;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        b[a[i]]=i;
    }
    for(i=1;i<=n;i++){
        cout<<b[i]<<" ";
    }
    cout<<endl;


}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll d11=b*c*(a%2==0?a/2:a/2+1),d12=b*c*(a/2);
    ll d21=a*b*(c%2==0?c/2:c/2+1),d22=a*b*(c/2);
    ll d31=a*c*(b%2==0?b/2:b/2+1),d32=a*c*(b/2);
    cout<<min(abs(d11-d12),min(abs(d21-d22),abs(d31-d32)))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <iomanip>

#define vec vector

using namespace std;

using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
using vvl = vector<vl>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;

int n;
vvi adj;
ll mod = 1e9 + 7;

pll doofus(int node, int parent)
{
    pll ways = {1, 1};
    if (adj[node].size() == 1)
        return {1, 1};
    for (int i = 0; i < adj[node].size(); i++)
    {
        if (adj[node][i] != parent)
        {
            pll w = doofus(adj[node][i], node);
            ways.first = (ways.first * ((w.first + w.second) % mod)) % mod;
            ways.second = (ways.second * w.first) % mod;
        }
    }
    return ways;
}

int main()
{
    cin >> n;
    adj = vvi(n + 1, vi());
    for (int i = 0; i < n - 1; i++)
    {
        int x, y; cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    adj[1].push_back(0);
    pll w = doofus(1, 0);
    cout << (w.first + w.second) % mod;
    return 0;
}

Measured memory_bytes: 11264
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	private static final long MOD = 1000000007;
	
	public Main() {
		FastScanner scanner = new FastScanner();
		int N = scanner.nextInt();
		
		long[][][] DP = new long[N+1][2][2];
		
		DP[0][0][0] = 1;
		DP[0][1][0] = 0;
		DP[0][0][1] = 0;
		DP[0][1][1] = 0;
		
		for (int i = 0; i < N; i++) {
			DP[i+1][1][1] = ((10L*DP[i][1][1]%MOD + DP[i][0][1])%MOD + DP[i][1][0])%MOD;
			DP[i+1][0][1] = (9L*DP[i][0][1]%MOD + DP[i][0][0])%MOD;
			DP[i+1][1][0] = (9L*DP[i][1][0]%MOD + DP[i][0][0])%MOD;
			DP[i+1][0][0] = 8L*DP[i][0][0]%MOD;
		}
		
		System.out.println(DP[N][1][1]);
	}
	
	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}
	
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 146048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      int[] seq = new int[n+1];
      seq[0] = 0;

      String line = in.readLine();
      char regex = ' ';
      boolean isContinue = true;
      for(int i=1, offset=0,next=0; isContinue; offset = ++next) {
        if((next = line.indexOf(regex,offset)) == -1) {
          next = line.length();
          isContinue = false;
        }
        seq[i++] = Integer.parseInt(line.substring(offset,next));
      }

      int sum=0;
      StringBuilder buf = new StringBuilder();
      for(int i=0; i<n; i++) {
        sum += Math.abs(seq[i+1] - seq[i]);
      }
      sum += Math.abs(seq[n]);

      int d=0;
      for(int i=1; i<n; i++) {
        d = 0;
        d -= Math.abs(seq[i] - seq[i-1]);
        d -= Math.abs(seq[i+1] - seq[i]);
        d += Math.abs(seq[i+1] - seq[i-1]);
        buf.append(sum + d).append('\n');
      }

      {
        d = 0;
        d -= Math.abs(seq[n] - seq[n-1]);
        d -= Math.abs(seq[0] - seq[n]);
        d += Math.abs(seq[0] - seq[n-1]);
        buf.append(sum + d).append('\n');
      }

      System.out.print(buf);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 43880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, ans = 0, sum = 0;
	char c;
	string s;
	cin >> n;
	rep(i, n) {
		cin >> c;
		sum += (c == 'I' ? 1 : -1);
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Xml.Schema;

class IDONTKNOWCSHARP
{
    public static void Main()
    {
        string[] values = GetLines();
        int value = 0;

        int A = int.Parse(values[0]);
        int B = int.Parse(values[1]);
        int C = int.Parse(values[2]);
        int K = int.Parse(values[3]);

        if (K - A > 0)
        {
            value += A;
            K -= A;

            if (K - B > 0)
            {
                K -= B;

                if (K - C > 0)
                {
                    //error
                }
                else
                {
                    value -= K;
                }
            }
            else
            {
            //    value += K;
            }
        }
        else
        {
            value += K;
        }

        Console.WriteLine(value);
    }

    static string[] GetLines()
    {
        return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
    }
}

Measured memory_bytes: 27548
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<iomanip>
#include<string>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define setp(n) fixed<<setprecision(n)
int main(){
    int n;
    string s, t;
    cin>>n>>s>>t;
    rep(i, n){
        cout<<s[i]<<t[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
h, w = map(int,input().split())
A = [input() for i in range(h)]

Q = []
V = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        if A[i][j] == "#":
            Q.append([i, j, 0])
            V[i][j] = 1
            D[i][j] = 0


st = 0
while st < len(Q):
    for i in [[-1,0], [1,0], [0,-1], [0,1]]:
        x = Q[st][0] + i[0]
        y = Q[st][1] + i[1]
        if 0 <= x < h and 0 <= y < w and V[x][y] == 0:
            V[x][y] = 1
            Q.append([x, y, Q[st][2]+1])
            D[x][y] = Q[st][2]+1
    st += 1

print(max([max(i) for i in D]))


Measured memory_bytes: 166792
#include <iostream>
#include <algorithm>
using namespace std;
long long l,r;

int main(){
	int min=2019;
	cin>>l>>r;
	if (r-l>=2019){
		cout<<"0"<<endl;
		return 0;
	}
	for (int i=l;i<r;i++){
		for (int j=i+1;j<=r;j++){
			if ((1ll*i*j)%2019<min){
				min=(1ll*i*j)%2019;
			}
		}
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 256
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;
int dp[160][80][10];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    using pii = pair<int, int>;
    const int INF = 1e9;
    int n, m;
    while(cin >> n >> m && n) {
        vector<vector<pii>> rocks(n);
        for(auto& r : rocks) {
            int k; cin >> k;
            r.resize(k);
            for(auto& p : r)
              cin >> p.first >> p.second;
        }
        fill_n((int*)dp, 160 * 80 * 10, INF);
        for(int i : in(2)) for(int k : in(rocks[i].size())) dp[i][i][k] = 0;
        for(int i : in(n - 1)) for(int j : in(m + 1)) for(int k : in(rocks[i].size())) {
            int cx, cd; tie(cx, cd) = rocks[i][k];
            if(dp[i][j][k] == INF) continue;
            for(int l : in(rocks[i + 1].size())) {
                int nx, nd; tie(nx, nd) = rocks[i + 1][l];
                int cost = (cd + nd) * abs(cx - nx);
                dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j][k] + cost);
            }
            if(i == n - 2 || j == m) continue;
            for(int l : in(rocks[i + 2].size())) {
                int nx, nd; tie(nx, nd) = rocks[i + 2][l];
                int cost = (cd + nd) * abs(cx - nx);
                dp[i + 2][j + 1][l] = min(dp[i + 2][j + 1][l], dp[i][j][k] + cost);
            }
        }
        int ans = INF;
        for(int i : in(max(0, n - 2), n))
          for(int j : in(m + 1)) {
              if(i == n - 2 && j == m) continue;
              for(int k : in(rocks[i].size())) 
                ans = min(ans, dp[i][j][k]);
          }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	deque<char> s;
	string tmp;
	cin >> tmp;
	for (auto &it : tmp) s.pb(it);
	int Q;
	sci(Q);
	int rev = 0;
	while (Q--) {
		int val;
		sci(val);
		if (val == 1) {
			rev ^= 1;
		} else {
			int F;
			char cc;
			cin >> F >> cc;
			--F;
			if (F ^ rev) {
				s.pb(cc);
			} else {
				s.pf(cc);
			}
		}
	}
	if (rev) {
		reverse(ALL(s)); 
	}
	for (auto &it : s) {
		printf("%c", it);
	}
	printf("\n");
	return 0;
}

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

int f[100005], h[100005];
int main() {
	int n, K;
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n; i++) {
		scanf("%d", &h[i]);
		f[i]=1000000000;
		f[1]=0;
		for (int k=1; k<=K; k++)
		if (i>k) f[i]=min(f[i], f[i-k]+abs(h[i]-h[i-k]));
	}	
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let (mut num_of_five, mut num_of_seven) = (0, 0);
    input!(v: [i32; 3]);
    for item in v.iter() {
        if *item == 5 {
            num_of_five += 1;
        } else if *item == 7 {
            num_of_seven += 1;
        }
    }
    if num_of_five == 2 && num_of_seven == 1 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4476
import heapq

def calc(front_sum, back_sum):
    heapq.heapify(a_front)
    heapq.heapify(a_back)
    front_sums = [front_sum]
    back_sums = [back_sum]
    for i in a_center:
        front_sum += i - heapq.heappushpop(a_front, i)
        front_sums += [front_sum]
    a_center.reverse()
    for i in a_center:
        back_sum += i + heapq.heappushpop(a_back, -i)
        back_sums += [back_sum]
    return max([front_sums[i] - back_sums[-i-1] for i in range(n+1)])



if __name__ == "__main__":
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 0
    a_front = []
    a_center = []
    a_back = []
    front_sum = 0
    back_sum = 0

    for i in a:
        k += 1
        if k <= n:
            a_front += [i]
            front_sum += i
        elif k <= 2 * n:
            a_center += [i]
        else:
            a_back += [-i]
            back_sum += i

    print(calc(front_sum, back_sum))



Measured memory_bytes: 38292
#include<iostream>

using namespace std;

int main()
{
  int n,c=0;
  cin>>n;
  while(n!=0)
  {
    int sum=n%10;
    if(sum==7){
     c=1;
      break;
    }
    n=n/10;
  }
  if(c==1)cout<<"Yes";
  else cout<<"No";
  
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N, M; cin >> N >> M;
    long long res = res = pow(2, M) * (M * 1900 + (N - M) * 100);
    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            int[] B = new int[M];
            int[] C = new int[M];
            for (int i = 0; i < M; i++) {
                B[i] = in.nextInt();
                C[i] = in.nextInt();
            }

            ArrayList<Pair<Integer, Integer>> pairs = new ArrayList<>();
            for (int i = 0; i < M; i++) {
                pairs.add(new Pair<Integer, Integer>(C[i], B[i]));
            }
            Collections.sort(pairs);

            int[] AA = new int[N];
            iLoop: for (int i = 0, j = 0; i < pairs.size(); i++) {
                Pair<Integer, Integer> pair = pairs.get(pairs.size() - 1 - i);
                int c = pair.first.intValue();
                int b = pair.second.intValue();
                for (int k = 0; k < b; k++) {
                    AA[j++] = c;
                    if (j >= N) {
                        break iLoop;
                    }
                }
            }

            Arrays.sort(A);
            Arrays.sort(AA);

            for (int i = 0, j = 0; i < N; i++) {
                if (A[N - 1 - j] > AA[i]) {
                    AA[i] = A[N - 1 - j];
                    j++;
                }
            }

            long sum = 0;
            for (int i = 0; i < N; i++) {
                sum += AA[i];
            }
            System.out.println(sum);
        }
    }
}

class Pair<T extends Comparable<T>, S> implements Comparable<Pair<T, S>> {
    public T first;
    public S second;

    public Pair(T t, S s) {
        this.first = t;
        this.second = s;
    }

    private int hash = 0;

    @Override
    public int hashCode() {
        if (hash == 0) {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((first == null) ? 0 : first.hashCode());
            result = prime * result + ((second == null) ? 0 : second.hashCode());
            hash = result;
        }
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pair<T, S> other = (Pair<T, S>) obj;
        if (first == null) {
            if (other.first != null)
                return false;
        } else if (!first.equals(other.first))
            return false;
        if (second == null) {
            if (other.second != null)
                return false;
        } else if (!second.equals(other.second))
            return false;
        return true;
    }

    @Override
    public int compareTo(Pair<T, S> o) {
        return first.compareTo(o.first);
    }
}


Measured memory_bytes: 92956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=3e3+10;
ll dp[N][N];
int a[N],n,s;
void add(ll &x,ll y)
{
    x=(x+y)%mod;
}
int main()
{
    cin>>n>>s;
    for(int i=1;i<=n;i++) 
		cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=s;++j) 
			dp[i][j]=dp[i-1][j]*2%mod;
        for(int j=s;j>=a[i];--j)
            add(dp[i][j],dp[i-1][j-a[i]]);
    }
    cout<<dp[n][s]<<endl;
}

Measured memory_bytes: 74140
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int N=200005;

double eps=1e-9;
set<string>ans;
int n;

void rec(string s,set<int>used,int len){
  if(len==n){
    ans.insert(s);
    return;
  }
  len++;
  for(auto i:used){
    string nw=s;
    nw+=(i+'a');
    rec(nw,used,len);
  }
  for(int i=0;i<26;i++){
    if(used.find(i)==used.end()){
      int flag=0;
      if(!used.empty()){
	if(*(--used.end())>i){
	  flag++;
	}
      }
      if(flag==0){
	string nw=s;
	set<int>tmp=used;
	tmp.insert(i);
	nw+=(i+'a');
	rec(nw,tmp,len);
      }
      break;
    }
  }
}

void solve(){
  cin>>n;
  set<int>st;
  string s;
  rec(s,st,0);
  for(auto i:ans){
    cout<<i<<'\n';
  }
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}


Measured memory_bytes: 12416
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

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

const ll INF = (ll)1e19;

bool check(char c1, char c2) {
  if (c1 == '?' || c2 == '?' || c1 == c2) return true;
  return false;
}

void Main() {
  string a, b, c;
  cin >> a >> b >> c;
  int A, B, C;
  A = a.size();
  B = b.size();
  C = c.size();
  vector<bool> ab(20000, false), ac(20000, false), bc(20000, false);
  rep(i, A) rep(j, B) if (!check(a[i], b[j])) ab[i - j + 10000] = true;
  rep(i, A) rep(j, C) if (!check(a[i], c[j])) ac[i - j + 10000] = true;
  rep(i, B) rep(j, C) if (!check(b[i], c[j])) bc[i - j + 10000] = true;
  int ans = A+B+C;
  REP(i, -B-C, A+C) REP(j, -B-C, A+B) {
    if (!ab[i + 10000] && !ac[j + 10000] && !bc[j - i + 10000]) {
      int l = min(0, min(i, j));
      int r = max(A, max(i+B, j+C));
      ans = min(ans, r - l);
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e9+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


int main() {
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll n, m;
	cin >> n >> m;
	vi v(111111);
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		v[a] += b;
	}
	REP(i, 111111) {
		sum += v[i];
		if (sum >= m) {
			cout << i << endl;
			break;
		}
	}
}

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

int main(){
    int N, tmp, ans=0;
    cin >> N;
    vector<int> a(9, 0);
    
    for(int i=0; i<N; i++){
	cin >> tmp;
	tmp /= 400;
	if(tmp>=8)
	    a[8]++;
	else
	    a[tmp]=1;
    }

    for(int i=0; i<8; i++){
	if(a[i]==1)
	    ans++;
    }
    
    cout << max(ans, 1) <<" " <<ans+a[8]<< endl;
}




Measured memory_bytes: 256
N, P = map(int, input().split(' '))
A = tuple(map(int, input().split(' ')))

dp = [[0, 0] for _ in range(N + 1)]
dp[0][0] = 1

for index, a in enumerate(A, start=1):
    if a % 2 == 0:
        dp[index][0] = dp[index - 1][0] * 2
        dp[index][1] = dp[index - 1][1] * 2
    else:
        dp[index][0] = dp[index - 1][1] + dp[index - 1][0]
        dp[index][1] = dp[index - 1][0] + dp[index - 1][1]

print(dp[N][P])


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


int main()
{
    int64_t x;
    cin>>x;
    int64_t num=0;
    int64_t n_100;
    int64_t k=100;
    while(k<x)
    {
        n_100=k/100;
        k+=n_100;
        num++;
    }
    cout<<num<<endl;
    return 0;
}




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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;
#define N 2005

typedef long long int ll;
typedef vector<pair<int, int>> vpi;
typedef unordered_map<int, unordered_map<int, int>> ump;

ll dp[N][N];

bool present(ll dp[][N], int l, int r) {
	return dp[l][r] != -1;
}

ll maxHappiness(vpi &v, int cur, int l, int r, ll dp[][N]) {

	if (l > r)
		return 0;

	if (present(dp, l, r))
		return dp[l][r];

	// deb(v[cur].first);
	// deb(v[cur].first * abs(v[cur].second-l));

	ll lmax = maxHappiness(v, cur+1, l+1, r, dp);
	ll rmax = maxHappiness(v, cur+1, l, r-1, dp);

	ll put_in_left = (ll)v[cur].first * abs(v[cur].second-l) + lmax;
	ll put_in_right = (ll)v[cur].first * abs(v[cur].second-r) + rmax;


	// deb();
	// cout << " " << put_in_left << " " << put_in_right << endl;

	dp[l][r] = max(dp[l][r], max(put_in_left, put_in_right));

	return dp[l][r];
}

bool comp(pair<int, int> a, pair<int, int> b) {
	return b.first < a.first;
}

int main() {

	int n;
	cin >> n;
	
	vpi v;
	v.resize(n+1);
	int ip;

	for (int i = 1; i <= n; i++) {
		cin >> ip;
		// v.push_back({ip, i});
		v[i] = {ip, i};
	}

	sort(v.begin()+1, v.end(), comp);

	// for (auto x: v)
	// 	cout << x.first << " " << x.second << ", ";
	// cout << endl;


	memset(dp, -1, sizeof(dp));

	cout << maxHappiness(v, 1, 1, n, dp);

	return 0;
}

Measured memory_bytes: 35132
/*  -*- coding: utf-8 -*-
 *
 * 2867.cc: Many Kinds of Apples
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int cs[MAX_N], as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", cs + i);

  int q;
  scanf("%d", &q);

  while (q--) {
    int t, x, d;
    scanf("%d%d%d", &t, &x, &d);
    x--;

    if (t == 1) {
      as[x] += d;
      if (as[x] > cs[x]) {
	printf("%d\n", x + 1);
	return 0;
      }
    }
    else {
      as[x] -= d;
      if (as[x] < 0) {
	printf("%d\n", x + 1);
	return 0;
      }
    }
  }

  puts("0");
  return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main() {
	ll i,j,k,l,m,n,t;
// 	ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
	cin>>m>>n;
	l=0;
	for(i=0;i<n;i++){
	    cin>>j;
	    l+=j;
	}
	
	if(l>m){
	    cout<<-1<<endl;
	} else{
	    cout<<m-l<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3600