akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

ll legendre( ll n, ll p ) {
  ll ret = 0;

  while( n > 0 ) {
    ret += n/p;
    n /= p;
  }

  return ret;
}

ll ans;

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

  if( N&1 ) {
    N /= 2;

    ll two = legendre( 2*N+1, 2 )-N-legendre( N, 2 );
    ll five = legendre( 2*N+1, 5 )-legendre( N, 5 );

    chmax( two, 0ll );
    chmax( five, 0ll );

    ans = std::min( two, five );
  } else {
    N /= 2;
    ans = std::min( N+legendre( N, 2 ), legendre( N, 5 ) );
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,q,x,y,z;
    cin >> n >> q;
    dsu tree(n);
    while(q--)
    {
        cin >> x >> y >> z;
        if(x)cout << tree.same(y,z) << '\n';
        else tree.merge(y,z);
    }
    return 0;
}


Measured memory_bytes: 3904
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll a, b, k; cin >> a >> b >> k;
    rep(i, k){
        if(i%2==0){
            a = a/2;
            b += a;
        }else{
            b = b/2;
            a += b;
        }
    }
    cout << a << " " << b << ln;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int>x(N);
    vector<int>y(N);
    vector<int>h(N);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0) {
            cnt = i;
        }
    }
    int takasa = 0;
    for(int i = 0; i <= 100; i++) {
        for(int j = 0; j <= 100; j++) {
            bool ok = true;
            takasa = h[cnt]+abs(x[cnt]-i)+abs(y[cnt]-j);
            for(int k = 0; k < N; k++) {
                if(h[k] != max(takasa-abs(x[k]-i)-abs(y[k]-j),0)) {
                    ok = false;
                }
            }
            if(ok) {
                cout << i << " " << j << " " << takasa << endl;
                return 0;
            }
        }
    }       
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;

int n;
struct node{
  node* next;
  node* prev;
  long value;
};

void del(node* p){
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
  return;
}

int main(){
  scanf("%d",&n);
  node* first = (node*)malloc(sizeof(node));
  if(first==NULL) exit(-1);
  node* last = (node*)malloc(sizeof(node));
  if(first==NULL) exit(-1);
  first->prev = NULL;
  first->next = last;
  last->prev = first;
  last->next = NULL;
  for(int i=0;i<n;i++){
    char cmd[20];
    scanf("%s",cmd);
    if(strcmp(cmd,"insert")==0){
      long t;
      scanf("%ld",&t);
      node* p = (node*)malloc(sizeof(node));
      if(p==NULL) exit(-1);
      p->prev = first;
      p->next = first->next;
      p->value = t;
      first->next->prev = p;
      first->next = p;
    }
    else if(strcmp(cmd,"delete")==0){
      long t;
      scanf("%ld",&t);
      node* now = first->next;
      while(now->value!=t&&now!=last) now = now->next;
      if(now!=last) del(now);
    }
    else if(strcmp(cmd,"deleteFirst")==0){
      del(first->next);
    }
    else if(strcmp(cmd,"deleteLast")==0){
      del(last->prev);
    }
  }
  node* now = first;
  while(now->next!=last){
    printf("%ld",now->next->value);
    now = now->next;
    if(now->next!=last) printf(" ");
    else printf("\n");
  }
  return 0;
}

Measured memory_bytes: 32216
S=input()

if len(S)%2!=0:
    print('No')
    exit()
else:
    for i in range(len(S)):
        if i%2==0 and S[i]=='h':
            continue
        elif i%2!=0 and S[i]=='i':
            continue
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;


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

  int total = 0;
  for(int i = 0; i < M; ++i){
    int tmp;
    cin >> tmp;
    total += tmp;
  }

  cout << (N - total >= 0 ? N-total : -1 )<< endl;

  return 0;
}


Measured memory_bytes: 3620
import java.util.*;
public class Main {

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

	int[] moveX = {0,0,-1,1};
	int[] moveY = {-1,1,0,0};
	char[][] map;
	boolean[][] check;
	int ans = 0;
	int w, h;

	void calc () {
		// 同じScanner型の変数にnewで代入するのはどうもまずい
		Scanner sc = new Scanner(System.in);
		while (true) {
			h = sc.nextInt();
			w = sc.nextInt();
			if (w == 0) break;
			ans = 0;
			map = new char[h][w];
			check = new boolean[h][w];
			for (int i = 0; i < h; i++)
				map[i] = sc.next().toCharArray();

			bfs();

			System.out.println(ans);
		}
	}

	void bfs () {

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {

				if (check[i][j]) continue;
				check[i][j] = true;
				ans++;

				Queue<Integer> queueX = new LinkedList<Integer>();
				Queue<Integer> queueY = new LinkedList<Integer>();
				queueX.add(j);
				queueY.add(i);

				while (!queueX.isEmpty()) {
					int x = queueX.poll();
					int y = queueY.poll();
					for (int k = 0; k < moveX.length; k++) {
						int nextX = x + moveX[k];
						int nextY = y + moveY[k];

						if (0 <= nextX && nextX < w &&
							0 <= nextY && nextY < h &&
							!check[nextY][nextX] &&
							map[i][j] == map[nextY][nextX]) {

							check[nextY][nextX] = true;
							queueX.add(nextX);
							queueY.add(nextY);

						}

					}
				}
			}
		}

	}

}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var D = f[0];
            var ret = f[1];
            
            for (int i = 0; i < N; i++)
            {
                var tmp = int.Parse(Console.ReadLine());
                int val = tmp + 1;
                int choco = 1;
                while (val <= D)
                {
                    choco++;
                    val = (choco * tmp) + 1;
                }
                ret += choco;
            }
            Console.WriteLine(ret);
        }
    }
}

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

int main(int argc, char const *argv[])
{
	string a[10]={""," .,!?","cabcabcabcab","fdefdefdefde","ighighighigh"
					,"ljkljkljkljk","omnomnomnomn","spqrspqrspqr","vtuvtuvtuvtu","zwxyzwxyzwxy"};
	int n;
	cin>>n;
	while(n)
	{
		string s;
		cin>>s;
		for (int i = 0; i < s.size(); ++i)
		{
			char c=s.at(i);
			if(c=='0') continue;
			else
			{
				int b=0;
				while(s.at(i)==c) ++i,++b;
				if(c=='1') cout<<a[1].at(b%5);
				else cout<<a[c-'0'].at(b%12);
			}
		}
		cout<<endl;
		--n;
	}
	return 0;
}


Measured memory_bytes: 3064
import heapq
from collections import defaultdict
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

n, m, s = map(int, input().split())

connect = defaultdict(list)
for i in range(m):
    u, v, a, b = map(int, input().split())
    connect[u].append((v, a, b))
    connect[v].append((u, a, b))

c, d = [-1], [-1]
for i in range(n):
    c_, d_ = map(int, input().split())
    c.append(c_)
    d.append(d_)

ans = [-1] * (n+1)
dp = [{} for _ in range(n+1)]
coin_max = [-1] * (n+1)

h = [(0, s, 1)]
heapq.heapify(h)

while heapq:
    t, coin, city = heapq.heappop(h)

    if ans[city] == -1:
        ans[city] = t
        if all([v >= 0 for v in ans[2:]]):
            break

    if coin not in dp[city]:
        dp[city][coin] = t
    else:
        continue

    if coin_max[city] >= coin:
        continue
    else:
        coin_max[city] = coin

    for neighbor, a, b in connect[city]:
        if coin - a >= 0 and neighbor != city:
            if coin-a not in dp[neighbor]:
                heapq.heappush(h, (t+b, coin-a, neighbor))

    if coin+c[city] not in dp[city]:
        heapq.heappush(h, (t+d[city], coin+c[city], city))

print('\n'.join(map(str, ans[2:])))

Measured memory_bytes: 95872
import java.io.*;
import java.util.*;

class Main{
	
	public static void mode_v(ArrayList<Integer> list){
		int max =  0;
		ArrayList <Integer> inp = new ArrayList<Integer>();
		
		int[] num = new int[100];
		
		for(int i=0;i<num.length;i++){
			num[i] = 0;
			
		}
		
		for(int i=0;i<list.size();i++){
			int x = list.get(i);
			num[x-1]++;
		}
		for(int i=0;i<num.length;i++){
			if(max < num[i])
			max = num[i];
		}
		for(int i=0;i<num.length;i++){
			if(num[i] == max){
				System.out.println(i+1);
			}
		}
		
	}

	public static void main(String args[]) throws IOException{
		String str;
		ArrayList <Integer> inp = new ArrayList<Integer>();

		Scanner scan = new Scanner(System.in);
		
		while(scan.hasNext()){
			
			str = scan.next();
			int x = Integer.valueOf(str).intValue();
			inp.add(x);
		}
		mode_v(inp);
	}
}

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

const int MAXN = 1000 * 1000 + 10;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;

long long dp[3005][3005];
bool sch[3005][3005];

int h, w;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout << fixed << setprecision(10);

    cin >> h >> w;

    long long ans = 0, mod = 1000 * 1000 * 1000 + 7;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char r;
            cin >> r;
            if(r == '.') sch[i][j] = true;
        }
    }

    for(int i = 0; i < h; i++){
        if(!sch[i][0]) break;
        dp[i][0] = 1;
    }
    for(int i = 0; i < w; i++) {
        if(!sch[0][i]) break;
        dp[0][i] = 1;
    }

    for(int i = 1; i < w + h; i++){
        for(int j = 1; j < min(h, i); j++){
            int k = i - j;
            if(k > w) continue;

            if(sch[j - 1][k]) dp[j][k] += dp[j - 1][k];
            if(sch[j][k - 1]) dp[j][k] += dp[j][k - 1];

            dp[j][k] %= mod;
            //cerr << "j: " << j << " k: " << k << ' ' << dp[j][k] << endl;
        }
    }

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}



Measured memory_bytes: 18236
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll cnt[66][2];

int main(void){
	int n,i,j;
	ll a,ans = 0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		for(j=0; j<60; ++j){
			++cnt[j][(a>>j)&1];
		}
	}
	for(j=0; j<60; ++j){
		add_mod(ans,(1ll<<j)%MOD*cnt[j][0]%MOD*cnt[j][1]%MOD);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#

def happiness(s):
    h = 0
    c = s[0]
    for i in range(1,len(s)):
        if s[i] == c:
            h = h + 1
        else:
            c = s[i]
    return h

def schrun(s,l):
    c = s[l]
    i = l+1
    while (i<len(s)) and (s[i] == c) :
        i = i+1
    return i
        
#
n, k = map(int, input().split())
s = input()
#
h = happiness(s)
i = 0
l = 0
while( (i<k) and (l<n) and (h<n-1)):
    l = schrun(s,l)
    r = schrun(s,l)-1
    if r == n-1:
        h = h + 1
    else:
        h = h + 2
    i = i + 1
    l = r + 1

print(h)


Measured memory_bytes: 3316
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Pair[] ar = new Pair[n];
            for (int i = 0; i < n; i++) {
                int units = in.nextInt();
                int deadLine = in.nextInt();
                ar[i] = new Pair(units, deadLine);
            }
            Arrays.sort(ar, Comparator.comparingInt(o -> o.deadline));
            int time = 0;
            int work = 0;
            while (work < n) {
                time += ar[work].takesUnit;
                if (time > ar[work].deadline) {
                    out.println("No");
                    return;
                } else
                    work++;
            }
            out.println("Yes");
        }

        private class Pair {
            private int takesUnit;
            private int deadline;

            public Pair(int takesUnit, int deadline) {
                this.takesUnit = takesUnit;
                this.deadline = deadline;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 52940
def solve(J):
    t = 0
    J.sort(key=lambda x: x[0])
    J.sort(key=lambda x: x[1])
    for i in range(len(J)):
        t += J[i][0]
        if t > J[i][1]:
            return False
    return True


N = int(input())
Job = [list(map(int, input().split())) for _ in range(N)]
print("Yes") if solve(Job) else print("No")


Measured memory_bytes: 53664
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long ul;
// #define int long long

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// func declaration
template <class T> void print2DVec(vector< vector<T> >&);
template <class T> void calcVec(vector<T>&, int, char);
int char_to_int(const char);

// const
const int INF = 10000000;

/*MEMO
・辞書順
abc < abcd, atcoder < atlas
・イテレータ
std::vector<int>::iterator とタイプするのは面倒なので、
 通常は型推論の auto を使用する。
 auto iter = max_element(ALL(vec));
・2次元配列
vector<vector<int>> vec = {{1, 2, 3}, {4, 5, 6}}
・20×10の配列
vector<vector<int>> vec(20, vector<int>(10, 0));
・(n, m)の多次元配列
vector< vector<int> > vec(n, vector<int>(m, 0))  // 0で初期化
*/

void all2div(vector<int>& vec) {
    size_t vec_len = vec.size();
    REP(i, vec_len) {
        vec.at(i) /= 2;
    }
}

int main() {
    cin.tie();
    ios::sync_with_stdio(false);
    
    // input
    string s;
    cin >> s;
    size_t len_s = s.length();
    for (int i = 0; i < len_s; i += 2) {
        cout << s.at(i);
    }
    cout << "\n";
    
    return 0;
}


// function
template <class T> void print2DVec(vector< vector<T> >& vec) {
    REP(i, vec.size()) {
        REP(j, vec.front().size()) {
            cout << vec.at(i).at(j);
        }
        cout << endl;
    }
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    switch (ch) {
        case '+':
            REP(i, vec.size()) vec.at(i) += num; break;
        case '-':
            REP(i, vec.size()) vec.at(i) -= num; break;
        case '*':
            REP(i, vec.size()) vec.at(i) *= num; break;
        case '/':
            REP(i, vec.size()) vec.at(i) /= num; break;
        case '%':
            REP(i, vec.size()) vec.at(i) %= num; break;
        default:
            cout << "Incorrect Operator" << endl;
    }
}

int char_to_int(const char c) {
    if('0' <= c && c <= '9') return (c - '0');
    return -1;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 100000

typedef long long LL;
typedef long double LD;

int main(){
  string s,t;
  cin >> s >> t;
  int n=s.length(),m=t.length();
  vector<pair<int,int>> spos(n+2),tpos(m+2);
  spos[n]=spos[n+1]={n,n},tpos[m]=tpos[m+1]={m,m};
  for(int i=n-1;i>=0;i--){
    if(s[i]=='0'){
      spos[i]={i,spos[i+1].second};
    }else{
      spos[i]={spos[i+1].first,i};
    }
  }
  for(int i=m-1;i>=0;i--){
    if(t[i]=='0'){
      tpos[i]={i,tpos[i+1].second};
    }else{
      tpos[i]={tpos[i+1].first,i};
    }
  }
  vector<vector<pair<pair<int,int>,pair<int,int>>>> dp(n+2,vector<pair<pair<int,int>,pair<int,int>>>(m+2,{{INF,0},{-1,-1}}));
  dp[n+1][m+1]={{0,0},{n+1,m+1}};
  for(int i=n+1;i>=0;i--){
    for(int j=m+1;j>=0;j--){
      if(i==n+1&&j==m+1) continue;
      if(dp[spos[i].first+1][tpos[j].first+1].first.first<=dp[spos[i].second+1][tpos[j].second+1].first.first){
        dp[i][j]={{dp[spos[i].first+1][tpos[j].first+1].first.first+1,0},{spos[i].first+1,tpos[j].first+1}};
      }else{
        dp[i][j]={{dp[spos[i].second+1][tpos[j].second+1].first.first+1,1},{spos[i].second+1,tpos[j].second+1}};
      }
    }
  }
  string ans="";
  pair<int,int> now={0,0};
  while(now.first!=n+1||now.second!=m+1){
    ans+=(dp[now.first][now.second].first.second+'0');
    now=dp[now.first][now.second].second;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 253476
#include <algorithm>
#include <iostream>
#include<queue>
#include<cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef pair<int, int> pii;
int G[1005][1005];
int cost[1005][1005];
int n,m;
int stx, sty, edx, edy;
int op[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};

void show(void){
    for (int i = 1; i <= n;i++){
        for (int j = 1; j <= m;j++){
            if(cost[i][j]==inf)
                cout << "- ";
            else
                cout << cost[i][j] << " ";
        }
        cout << endl;
    }
}

bool adj(int x1,int y1,int x2,int y2){
    return ((abs(x1 - x2) == 1 && y1 == y2) || (x1 == x2 && abs(y1 - y2) == 1));
} 

int main(){
    memset(cost, 0x3f, sizeof(cost));
    memset(G, -1, sizeof(G));
    cin >> n >> m >> stx >> sty >> edx >> edy;
    for (int i = 1; i <= n;i++){
        for (int j = 1; j <= m;j++){
            char c;
            cin >> c;
            if(c=='.')
                G[i][j] = 0;
        }
    }

    deque<pair<int, pii>> dq;

    dq.push_front({0, {stx, sty}});
    cost[stx][sty] = 0;

    while(!dq.empty()){
        int cur = dq.front().first;
        pii t = dq.front().second;
        dq.pop_front();

        for (int i = 0; i < 4;i++){
            int tx = t.first + op[i][0];
            int ty = t.second + op[i][1];
            if(!G[tx][ty] && cur<cost[tx][ty]){
                dq.push_front({cur, {tx, ty}});
                cost[tx][ty] = cur;
            }
        }

        int r1 = max(t.first - 2, 1);
        int r2 = min(t.first + 2, n);
        int c1 = max(t.second - 2, 1);
        int c2 = min(t.second + 2, m);

        for (int i = r1; i <= r2;i++){
            for (int j = c1; j <= c2;j++){
                if(!G[i][j] && cur+1 < cost[i][j]){
                    dq.push_back({cur + 1, {i, j}});
                    cost[i][j] = cur + 1;
                }
            }
        }         
    }

    //show();
        
    if(cost[edx][edy]!=inf)
        cout << cost[edx][edy] << endl;
    else
        cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 11584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> a;
	a.push_back(0);
	for(int i = 0;i<n;i++)
	{
		int c;
		cin>>c;
		a.push_back(c);
	}
	a.push_back(0);
	int s = 0;
	for(int i = 0;i<=n;i++)
	{
		s+=abs(a[i]-a[i+1]);
	}
	//cout<<s<<endl;
	for(int i = 1;i<=n;i++)
	{
		int m = s;
		m-=(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]));
		m+=abs(a[i+1]-a[i-1]);
		cout<<m<<endl;
	}
}

Measured memory_bytes: 3924
#include <stdio.h>
char S[100000];
void solve(long N,char S[])
{
    char m='0';
    long q=0;
    for(long i=0;i<N;i++)
        if(m!=S[i])
    {
        q++;
        m=S[i];
    }
    printf("%ld",q);
}
int main()
{
    long N;
    scanf("%ld",&N);
    getchar();
    for(long i=0;i<N;i++)
        scanf("%c",&S[i]);
    solve(N,S);
    return 0;
}

Measured memory_bytes: 256
#a
"""
import math
a, b = map(str, input().split())
j = int(a + b)
if math.sqrt(j).is_integer():
    print("Yes")
else:
    print("No")
"""

#b
"""
ans = ["Positive","Negative"]
a, b = map(int, input().split())
if 0 < a:
    print("Positive")
elif b >= 0:
    print("Zero")
else:
    print(ans[(b-a)%2-1])
"""

#C
"""
import itertools
n = int(input())
MARCH = ["M", "A", "R", "C", "H"]
march = [0 for _ in range(5)]
for i in range(n):
    s = input()
    if s[0] in MARCH:
        march[MARCH.index(s[0])] += 1
num = list(range(5))
a = list(itertools.combinations(num, 3))
ans = 0
for i in a:
    bf = 1
    for k in i:
        bf *= march[k]
    ans += bf
print(ans)
"""

#D
"""
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]
q = int(input())
p = [int(input()) for _ in range(q)]
ans = [[0 for i in range(n)] for _ in range(n)]
tate = [[[]]]
for i in range(n):
    for j in range(n):

for _ in p:
    print(ans[p])

"""
#E
"""
s = input()
bf = s[0]
ans = 0
for i in range(1,len(s)):
    if bf != s[i]:
        ans += 1
        bf = s[i]
print(ans)
"""

#F
"""
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
ans = ta[0]
for i in ta:
    if ans[0] <= i[0] and ans[1] <= i[1]:
        ans = i
    else:
        a = ((ans[0] - 1) // i[0]) + 1
        b = ((ans[1] - 1) // i[1]) + 1
        ab = max(a,b)
        ans = [i[0] * ab, i[1] * ab]
print(ans[0]+ans[1])
"""

#G
s = input()
ans = 0
for i in range(1,len(s)):
    if i % 2 == 1:
        if s[i] != "p":
            ans += 1
    else:
        if s[i] != "g":
            ans -= 1
print(ans)

Measured memory_bytes: 39536
def isValidNumOfBill(x, y, z, N):
    return x + y + z == N

def isValidSumOfMoney(x, y, z, Y):
    return 10000 * x + 5000 * y + 1000 * z == Y

def outputResult(x, y, z):
    print('{x:d} {y:d} {z:d}'.format(x=x, y=y, z=z))

def outputFailure():
    print('-1 -1 -1')

def searchA(N, Y):
    # define range
    xlim = range(0, Y // 10000 + 1)
    ylim = range(0, Y // 5000 + 1)
    zlim = range(0, Y // 1000 + 1)

    for x in xlim:
        for y in ylim:
            for z in zlim:
                # print(x, y, z)
                if not isValidNumOfBill(x, y, z, N):
                    continue
                if isValidSumOfMoney(x, y, z, Y):
                    return (x, y, z)

def searchB(N, Y):
    # 最初に金額を合わせる
    calcX = lambda Y: Y // 10000
    calcY = lambda x, Y: (Y - 10000 * x) // 5000
    calcZ = lambda x, y, Y: (Y - 10000 * x - 5000 * y) // 1000
    x = calcX(Y)
    y = calcY(x, Y)
    z = calcZ(x, y, Y)

    while x >= 0:
        while y >= 0:
            # print(x, y, z)
            if sum((x, y, z)) == N:
                return (x, y, z)
            y -= 1
            z = calcZ(x, y, Y)
        x -= 1
        y = calcY(x, Y)
        z = calcZ(x, y, Y)

def main():
    # read 'N Y'
    args = input().split(" ")
    N = int(args[0])
    Y = int(args[1]) 

    # search for 10000x + 5000y + 1000z = Y
    # result = searchA(N, Y)
    result = searchB(N, Y)
    if result is not None:
        x, y, z = result
        outputResult(x, y, z)
    else:
        outputFailure()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main (String[] args)
    {
        int i, I = 1;
        String s;
        Scanner sc = new Scanner(System.in);

        s = sc.nextLine();
        I = Integer.parseInt(s);
        int[] a = new int[I];

        for (i = 0; i < I; i++)
        {
            s = sc.next();
            a[i] = Integer.parseInt(s);
        }
        sc.close();

        for (i = I - 1; i > 0; i--)
        {
            System.out.print(a[i]+" ");
        }
        System.out.println(a[0]);
    }
}


Measured memory_bytes: 26204
// 2012/05/19 Tazoe

#include <iostream>
using namespace std;

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

		if(N==0)
			break;

		int S[200][2];
		S[0][0] = 0;
		S[0][1] = 0;

		int x_max = 0;
		int x_min = 0;
		int y_max = 0;
		int y_min = 0;

		for(int i=1; i<N; i++){
			int n, d;
			cin >> n >> d;

			switch(d){
				case 0:
					S[i][0] = S[n][0]-1;
					S[i][1] = S[n][1];
					break;
				case 1:
					S[i][0] = S[n][0];
					S[i][1] = S[n][1]+1;
					break;
				case 2:
					S[i][0] = S[n][0]+1;
					S[i][1] = S[n][1];
					break;
				case 3:
					S[i][0] = S[n][0];
					S[i][1] = S[n][1]-1;
					break;
			}

			if(S[i][0]>x_max){
				x_max = S[i][0];
			}
			else if(S[i][0]<x_min){
				x_min = S[i][0];
			}
			else if(S[i][1]>y_max){
				y_max = S[i][1];
			}
			else if(S[i][1]<y_min){
				y_min = S[i][1];
			}
		}

//		for(int i=0; i<N; i++)
//			cout << S[i][0] << ' ' << S[i][1] << endl;

		cout << x_max-x_min+1 << ' ' << y_max-y_min+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	
	int N;
	int[] A;
	Map<Integer, Integer> nums ;
	int[][] memo;
	
	public void run() throws Exception{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		N = Integer.parseInt(reader.readLine());
		
		StringTokenizer tok = new StringTokenizer(reader.readLine());
		nums = new HashMap<>(N * 2);
		
		memo = new int[N][N];
		for(int i = 0; i < N; i++) {
			for(int j= 0; j< N; j++) {
				memo[i][j] = -1;
			}
		}
		
		A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(tok.nextToken());
		}
		
		Arrays.sort(A);
		
		for(int i = 0; i < N; i++) {
			nums.put(A[i], i);
		}
		int answer = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				answer = Math.max(answer, dfs(i, j) + 2);
			}
		}
		System.out.println(answer);
	}
	
	public int dfs(int i, int j) {
		if(memo[i][j] != -1) return memo[i][j];
		
		int diff = A[j] - A[i];
		Integer ni = nums.get(A[j] + diff);
		if(ni == null) {
			return memo[i][j] = 0;
		}else {
			return memo[i][j] = dfs(j, ni) + 1;
		}
	}
	
	
	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}



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

int main()
{
    int x, y;
    cin >> x >> y;
    /***
    a=y/2-x
    b=2x-y/2
    4a+2b=y
    a+b=x
    ***/
    int a, b;
    a = y / 2 - x;
    b = 2 * x - y / 2;
    if (a < 0 || b < 0 || y % 2 == 1)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  char s[110000];
  int  ss[110000];
  int res=0;
  cin >> s;
  int N = strlen(s);

  rep(i,N) ss[i] = s[i]-'0';

  int prev = ss[0];
  FOR(i,1,N-1){
    if(prev==ss[i]) {
      prev = 1-ss[i];
      res++;
    }
    else prev = ss[i];
  }

  prev = 1-ss[0];
  int cnt=1;
  FOR(i,1,N-1){
    if(prev==ss[i]) {
      prev = 1-ss[i];
      cnt++;
    }
    else prev = ss[i];
  }
  res = min(res,cnt);
  cout << res << endl;

}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define pll pair<ll, ll>
#define rep(x, l, r) for (x = l; x < r; x++)

const ll mod=1000000007;
const char nl='\n';

void solve()
{
	ll i, j, k, l, m, n, u, v,x,y,z,a,b,c,r,g,q;
    cin>>n;
    vector<ll> arr(n),dp(n,100000000000000);
    for(i=0;i<n;i++){
        cin>>arr[i];
    }
    dp[0]=0,dp[1]=abs(arr[0]-arr[1]);

    for(i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>

int main(void){
  int N,d;
  int ans = 0;
  int flag[100];
  scanf("%d",&N);
  
  for(int i= 0;i < 100;i++){
    flag[i] = 0;
  }

  for(int i = 0;i < N;i++){
    scanf("%d",&d);
    flag[d-1] = 1;
  }

  for(int i = 0;i < 100;i++){
    if(flag[i]) ans++;
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std ;
#define rep(i,a) for(i=0; i<a; i++)

typedef long long ll;

int main(int argc, char const *argv[]) {
    int i,N;
    cin >> N;
    int A[N];
    rep(i,N){
        cin >> A[i];
    }

    double sum=0.0;

    rep(i,N){
        sum += 1.0/A[i];
    }
    cout << 1.0/sum;
    return 0;
}


Measured memory_bytes: 256
require 'pp'
N, C = gets.chomp.split(" ").map(&:to_i)
x = []
v = []

N.times do |i|
  x[i], v[i] = gets.chomp.split(" ").map(&:to_i)
end

x_r = x.reverse
x_r.each_with_index do |e, i|
  x_r[i] = C - e
end
v_r = v.reverse

def costs(x, v)
  costs = []
  N.times do |i|
    d = i == 0 ? x[i] : x[i] - x[i-1]
    costs[i] = v[i] - d
  end
  costs
end

c = costs(x, v)
c_r = costs(x_r, v_r)


def max_e(x, v, c)
  answer = [0]
  e_max = 0
  e = 0
  c.each_with_index do |c, i|
    e += c
    e_max = [e_max, e].max
    answer << e_max
  end

  answer
end


e_f = max_e(x, v, c)
e_r = max_e(x_r, v_r, c_r)


def solve(x, c, e_f, e_r)
  e_max = 0

  e = 0
  c.each_with_index do |c, i|
    e += c

    e_max = e if e_max < e

    e_rev = e - x[i] + e_r[N - (i+1)]
    e_max = e_rev if e_max < e_rev
  end

  e_max
end


max_e_f = solve(x, c, e_f, e_r)
max_e_r = solve(x_r, c_r, e_r, e_f)

puts [max_e_f, max_e_r].max


Measured memory_bytes: 8948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define RA(x) begin(x), end(x)
#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;

int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    int n,m;
    ll ans = 1;
    cin>>n>>m;
    if(abs(n-m)>1){
      cout<<0<<endl;
      return 0;
    }
    else{
      rep(i,2,n+1){
        ans*=(i);
        ans%=(mod);
      }
      rep(i,2,m+1){
        ans*=(i);
        ans%=(mod);
      }
      if(n==m){
        ans*=(2);
        ans%=(mod);
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def parity
  c = M.count{|m| (m[0] + m[1]).odd? }
  if c == M.size
    1
  elsif c == 0
    0
  else
    raise
  end
end

def distance(a,b)
  (a[0] - b[0]).abs + (a[1] - b[1]).abs
end

def move(from, dir, d)
  case dir
  when :U
    [from[0], from[1] + d]
  when :D
    [from[0], from[1] - d]
  when :L
    [from[0] - d, from[1]]
  when :R
    [from[0] + d, from[1]]
  else
    nil
  end
end

def create_arm(parity)
  c = M.map{|m| m[0].abs + m[1].abs }.max.bit_length
  arm = c.times.map{|i| 1 << i }.reverse
  arm << 1 if parity.zero?
  arm
end

def orientate_arm(arm, m)
  result = Array.new(arm.size)
  x = arm.each_with_index.inject([0,0]) do |from, (d, i)|
    dir, to = [:U, :D, :L, :R]
      .map{|o| [o, move(from, o, d)] }
      .min_by{|(o, x)| distance(x, m) }
    result[i] = dir
    to
  end
  raise unless 2.times.all?{|i| x[i] == m[i] }
  result.join
end

N = gets.to_i
M = N.times.map{ gets.split.map(&:to_i) }

begin
  A = create_arm(parity)
  ans = M.map{|m| orientate_arm(A, m) }
  puts A.size
  puts A.join(' ')
  puts ans
rescue
  puts -1
end



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

using namespace std;

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if ((s[0] == s[1]) && (s[1] != s[2]) && (s[2] == s[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}    


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

//------------------------------------------------------------------------------------------------
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<ll, pl> pll;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
//-------------------------------------------------------------------------------------------------
#define PI acos(-1)
#define inf 1000000001
#define ninf -inf
#define pb push_back
#define mp make_pair
#define mod 1000000007
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int gcd(int a,int b){if(a==0)return b;else return gcd(b%a,a);}
int be(int a,int b){int ans=1;while(b){if(b&1){b--;ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;}return ans;}
void fi(int &num){bool neg=false;num=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')break;ch=getchar();}if(ch=='-'){neg=true;ch=getchar();}while(ch>='0'&&ch<='9'){num=num*10+ch-'0';ch=getchar();}if(neg)num=-num;}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int grundy[100001];
int n,k;
vector<int> vt;
int mex(int j)
{set<int> st;
for(int i=0;i<vt.size();i++)
{
    if((j-vt[i])<0)break;
    st.insert(grundy[j-vt[i]]);
}

for(int i=0;i<=101;i++)
    if(st.find(i)==st.end())return i;
}
signed main()
{
    grundy[0]=0;
    scanf("%d%d",&n,&k);
    while(n--)
    {int temp;
        scanf("%d",&temp);
        vt.pb(temp);
    }
    sort(vt.begin(),vt.end());
    for(int i=1;i<=100000;i++)
    {
        grundy[i]=mex(i);
      //  printf("%d \n",grundy[i]);
    }

    if(grundy[k])
    printf("First\n");
    else printf("Second\n");
    return 0;}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

using P = pair<ll, ll>;

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

int dfs(vector<string> const& v, vector<vector<bool>>& visited, int y, int x) {
    visited[y][x] = true;
    int res = 1;
    for(int i=0; i<4; ++i) {
        int ny = y + dy[i], nx = x + dx[i];
        if(ny < 0 || v.size() <= ny || nx < 0 || v[0].size() <= nx || v[ny][nx] == '#' || visited[ny][nx]) {
            continue;
        }
        res += dfs(v, visited, ny, nx);
    }
    return res;
}


int main() {
    int w, h;
    while(cin >> w >> h, w) {
        vector<string> v(h);
        for(int i=0; i<h; ++i) {
            cin >> v[i];
        }
        int sy, sx;
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                if(v[i][j] == '@') {
                    sy = i;
                    sx = j;
                }
            }
        }
        vector<vector<bool>> visited(h, vector<bool>(w));
        cout << dfs(v, visited, sy, sx) << endl;
    }
}


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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 1e5 + 10;
struct E
{
    int v, next;
} edge[N << 1];
int head[N], e;
void addedge(int u, int v)
{
    edge[e].v = v;
    edge[e].next = head[u];
    head[u] = e++;
}

int n;
int mod;

LL dp1[N], dpf[N], dp2[N];

LL dfs1(int u, int f)
{
    LL ret = 1;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == f) continue;
        LL val = dfs1(v, u);
        ret = ret * (1 + val) % mod;
    }
    return dp1[u] = ret;
}

LL pre[N], suf[N], val[N];
int idx[N];

void dfs2(int u, int f)
{
    int cnt = 0;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == f) continue;
        ++cnt;
        idx[cnt] = v;
        val[cnt] = dp1[v];
    }

    // if (cnt == 0) return;

    // assert(cnt >= 0);
    // assert(cnt <= n - 1);

    pre[0] = 1;
    for (int i = 1; i <= cnt; i++) pre[i] = pre[i - 1] * (1 + val[i]) % mod;
    suf[cnt + 1] = 1;
    for (int i = cnt; i >= 1; i--) suf[i] = suf[i + 1] * (1 + val[i]) % mod;

    for (int i = 1; i <= cnt; i++)
    {
        int p = idx[i];
        // assert(p >= 1);
        // assert(p <= n);

        LL v1 = pre[i - 1];
        LL v2 = suf[i + 1];
        LL v = v1 * v2 % mod;  // 同级

        dpf[p] = (dpf[u] * v + 1) % mod;
        dp2[p] = dpf[p] * dp1[p] % mod;
    }

    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == f) continue;
        dfs2(v, u);
    }
}

int main()
{
#ifdef LOCAL
    freopen("in2", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (~scanf("%d%d", &n, &mod))
    {
        clr(head, -1), e = 0;
        int u, v;
        for (int i = 1; i < n; i++)
        {
            scanf("%d%d", &u, &v);
            addedge(u, v);
            addedge(v, u);
        }

        int root = rand() % n + 1;
        dfs1(root, -1);
        dp2[root] = dp1[root];
        dpf[root] = 1;

        dfs2(root, -1);

        for (int i = 1; i <= n; i++) printf("%lld\n", dp2[i]);
    }

    return 0;
}


Measured memory_bytes: 14676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1000000007;
const int MaxN = 5010;

int n, tot, Size[MaxN], head[MaxN], ver[MaxN * 2], Next[MaxN * 2];
ll g[MaxN], tmp[MaxN], dp[MaxN][MaxN];

void add(int u, int v) {
	ver[++tot] = v;
	Next[tot] = head[u];
	head[u] = tot;
}

void dfs(int u, int fa) {
	Size[u] = 1;
	dp[u][1] = 1;
	for (int i = head[u]; i; i = Next[i]) {
		int v = ver[i];
		if (v == fa) continue;
		dfs(v, u);
		for (int j = 1; j <= Size[u] + Size[v]; j++) tmp[j] = 0;
		for (int j = 1; j <= Size[u]; j++)
			for (int k = 0; k <= Size[v]; k++) {
				tmp[j + k] += dp[u][j] * dp[v][k] % Mod;
				if (tmp[j + k] >= Mod) tmp[j + k] -= Mod;
			}
		for (int j = 1; j <= Size[u] + Size[v]; j++)
			dp[u][j] = tmp[j];
		Size[u] += Size[v];
	}
	for (int i = 2; i <= Size[u]; i += 2) {
		dp[u][0] -= dp[u][i] * g[i] % Mod;
		if (dp[u][0] < 0) dp[u][0] += Mod; 
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	g[2] = 1; 
	for (int i = 4; i <= n; i += 2)
		g[i] = g[i - 2] * (i - 1) % Mod;
	dfs(1, 0);
	printf("%lld\n", Mod - dp[1][0]);
	return 0;
}

Measured memory_bytes: 92632
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;


ll solve(ll h, ll w){
    ll mini=LINF;
    rep(i,1,w){
        ll s1=h*i;
        ll s2=0; ll s3=0;
        if((w-i)%2==0 or h%2==0){
            s2=(w-i)*h/2;
            mini=min(mini,abs(s2-s1));
        }else{
            ll s2a=(w-i)/2*h;
            ll s3a=(w-i)*h -s2a;
            ll s2b=h/2 * (w-i);
            ll s3b=(w-i)*h -s2b;
            mini=min(mini,max({s1,s2a,s3a})-min({s1,s2a,s3a}));
            mini=min(mini,max({s1,s2b,s3b})-min({s1,s2b,s3b}));
        }
    }
    return mini;
}

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

    cout<<min(solve(h,w),solve(w,h))<<endl;
}

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

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

	unsigned int BIT_FLAG_a = (1 << a);
	unsigned int BIT_FLAG_b = (1 << b);
	unsigned int BIT_FLAG_c = (1 << c);

	unsigned int bit = BIT_FLAG_a;
	int ans = 1;

	if (!(bit & BIT_FLAG_b)) {
		bit |= BIT_FLAG_b;
		++ans;
	}

	if (!(bit & BIT_FLAG_c)) {
		bit |= BIT_FLAG_c;
		++ans;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 500005
#define ll long long
#define mod 1000000007
using namespace std;

typedef pair<int, char> P;

ll a, b, c, d;

ll gcd(ll x, ll y)
{
    return (y == 0) ? x : gcd(y, x % y);
}

int main()
{
    cin >> a >> b >> c >> d;
    ll ans = b - a + 1;
    ans -= ((b / c) - (a - 1) / c);
    ans -= ((b / d) - (a - 1) / d);
    ll g = c / gcd(c, d) * d;
    ans += ((b / g) - (a - 1) / g);
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    int N;
    std::cin >> N;
    
    std::cout << N * N * N << std::endl;  

    return 0;
}


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

using namespace std;

typedef long long ll;
int main()
{
	ll n; cin >> n;
	string s = "",k = "abcdefghijklmnopqrstuvwxyz";
	while(n){
		n--;
		int pos = n%26;
		n /= 26;
		s += k[pos];
	}
	reverse(s.begin(), s.end());
	cout << s;
}


Measured memory_bytes: 3620
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: q,i,j,l,r
    integer(int32):: cnt_like2017(0:100000)
    integer(int32), allocatable:: ans(:)
    logical:: is_prime(100000), is_like2017(100000)
    is_prime(:) = .true.
    is_prime(1) = .false.

    do i=2,size(is_prime)
        if (is_prime(i)) then
            j=2
            do while(i*j <= size(is_prime))
                is_prime(i*j) = .false.
                j=j+1
            end do
        end if
    end do
    
    do i=1,100000,2
        is_like2017(i) = is_prime(i) .and. is_prime((i+1)/2)
    end do

    cnt_like2017(:) = 0
    do i=1,100000
        cnt_like2017(i) = cnt_like2017(i-1)
        if (is_like2017(i)) cnt_like2017(i)=cnt_like2017(i)+1
    end do


    read*, q
    allocate(ans(q), source=0)
    do i=1,q
        read*, l,r
        ans(i) = cnt_like2017(r) - cnt_like2017(l-1)
    end do

    print'(i0)', ans(:)
end program main

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}

signed main(){
  int n; cin>>n;
	int a=0,b=0;
	rep(i,n){
		int c; cin>>c;
		if(c%4==0) a++;
		else if(c%2==0) b++;
	}
	cerr << a SP b << endl;
	int cnt;
	if(a) cnt = 2*a+max(1,b);
	else cnt = b;
	if(cnt>=n) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256