akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string S;cin >> S;
    string ans = "AC";
    if(S[0] != 'A') ans = "WA";
    int c=0;
    for(int i=1;i<S.size();i++){
        if(!islower(S[i]) && S[i] != 'C') ans="WA";
        if(2 <= i && i <= S.size()-2 && S[i] == 'C') c++;
    }
    if(c!=1) ans="WA";
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int N,X,i,L[100],bound_c = 0,result=1;

    scanf("%d %d",&N,&X);
    for(i = 0;i < N;i++){
        scanf("%d",&L[i]);
    }

    for(i = 0;i < N;i++){
        bound_c += L[i];
        if(bound_c <= X){
            result++;
        }else{
            break;
        }
    }

    printf("%d",result);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

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

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]

macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                let _ = stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap};
 
type Graph = Vec<Vec<usize>>;
const M: usize = 1e9 as usize + 9;

fn main() {
    input!{
        x:usize,
        a:usize,
    }
    if x >= a {
        println!("10");
    } else {
        println!("0");
    }
}


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

int D[4][2] = {{0,-1},{1,0},{0,1},{-1,0}};

int main() {
  int H, W;
  cin >> H >> W;

  char A[60][60];
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < W; ++j) {
      A[i][j] = s[j];
    }
  }

  bool ok = true;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (A[i][j] == '.') continue;

      ok = false;
      for (int k = 0; k < 4; ++k) {
        int targetX = j + D[k][0];
        int targetY = i + D[k][1];
        if (targetX < 0 || W <= targetX || targetY < 0 || H <= targetY) {
          continue;
        }
        if (A[targetY][targetX] == '#') {
          ok = true;
          break;
        }
      }
     if (!ok) {
       goto LOOP_END;
     }
    }
  }

LOOP_END:
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[100005];
	int b;
	scanf("%s%d",s,&b);
	int len=strlen(s);
	for(int i=0;i<len;i+=b){
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector <pair<int,int>>w(n);
  for (int i=0; i<n; i++){
    int a,b;
    cin >> a >> b;
    w[i] = make_pair(b,a);
  }
  sort(w.begin(),w.end());
  long long int nt = 0;
  for(int i=0; i<n; i++){
    nt += w[i].second;
    if (nt > w[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1792
import sys
import os

def file_input():
    f = open('ABC085/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()

    N,Y=map(int, input().split())

    # # x=0        # ten=0
    # y=0        # five=0
    # z=0        # one=0
    tmp=Y//1000-N
    # print(tmp)

    for x in range(N+1):
        if (tmp-9*x)%4==0:
            y=(tmp-9*x)//4
            if y>=0:
                z=N-(x+y)
                if z>=0:
                    print(str(x)+" "+str(y)+" "+str(z))
                    break
    else:
        print("-1 -1 -1")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int N;
	cin >> N;

	vector<int> V(N, 0);
	vector<int> C(N, 0);
	vector<int> diff(N, 0);

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

	for (int i = 0; i < N; i++) {
		cin >> C[i];
		diff[i] = V[i] - C[i];
	}

	int min = *min_element(diff.begin(), diff.end());
	int max = *max_element(diff.begin(), diff.end());

	int ans = 0;
	if (min * max < 0) {
		sort(diff.begin(), diff.end(), greater<int>());
		int ind = 0;
		while (diff[ind] > 0) {
			ans += diff[ind];
			ind += 1;
		}
	}
	else {
		if (max <= 0) {
			ans = 0;
		}
		else {
			ans = accumulate(diff.begin(), diff.end(), 0);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    X = int(input())
    
    money = 100
    res = 0
    while money < X:
        money = int(money * 1.01)
        res += 1
    
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 72980
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}
//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"



string to_string_keta(const long long int l, const int keta) {
	ostringstream oss;

	oss << std::setw(keta) << std::setfill('0') << l;

	return oss.str();
}
int main() {
	while (1) {
		string st; cin >> st;
		if (st[0] == '-')break;
		string up = st.substr(0, st.find('.'));
		string down = st.substr(st.find('.') + 1);
		if (st.find('.') == string::npos) {
			up = st;
			down = "0";
		}
		if (down != "0") {
			while (!down.empty() && down.back() == '0') down.pop_back();
		}
		if (stoi(up)< 0)break;
		else {
			int ap = stoi(up);
			if (ap >= powint(2, 8)) {
				cout << "NA" << endl;
				continue;
			}
			else {
				string ans;
				for (int i = 7; i >= 0; --i) {
					if (ap >= powint(2, i)) {
						ans.push_back('1');
						ap -= powint(2, i);
					}
					else {
						ans.push_back('0');
					}
				}
				ans.push_back('.');
				bool ok = false;
				for (int i = 0; i <= 15; ++i) {
					int ast = 625 * i;
					string aast = to_string_keta(ast, 4);
					while (!aast.empty()&&aast.back() == '0') aast.pop_back();
					if (aast.empty())aast = "0";
					if (aast == down) {
						ok = true;
						int num = i;
						for (int j = 3; j >=0; --j) {
							if (num >= powint(2, j)) {
								ans.push_back('1');
								num -= powint(2, j);
							}
							else {
								ans.push_back('0');
							}
						}
					}
				}
				if (!ok) {
					cout << "NA" << endl;
					continue;
				}
				else {
					cout << ans << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

int main()
{
  fastio;
  
  int x;
  cin>>x;
  int i=0;
  int deg=0;
  while(deg%360!=0||deg==0)
  {
    deg+=x;
    i++;
  }
  cout<<i<<endl;
}


Measured memory_bytes: 3608
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		String result = "No";
		if(s.charAt(0) == '7' || s.charAt(1) == '7' || s.charAt(2) == '7') result = "Yes";
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 27008
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll n, m;
ll dp[33005][22];
ll msum[33005], adj[22][22];
int main(){
	fastio;
    cin >> n >> m;
    ll smw = 0;
    for (ll i = 0; i < 33005; i++) for (ll j = 0; j < 22; j++) dp[i][j] = -1;
    for (ll i = 0; i < m; i++){
    	ll u, v, w; cin >> u >> v >> w; u--; v--;
    	adj[u][v] = adj[v][u] = w; smw += w;
    	for (ll mask = 0; mask < (1LL << n); mask++){
    		if (((mask >> u) & 1) && ((mask >> v) & 1)) msum[mask] += w;
		}
	}
	dp[1][0] = 0;
	for (ll mask = 1; mask < (1LL << n); mask++){
		for (ll i = 0; i < n; i++){
			if (dp[mask][i] != -1){
				for (ll j = 0; j < n; j++){
					if ((!(mask >> j & 1)) && (adj[i][j])) dp[mask | (1LL << j)][j] = max(dp[mask | (1LL << j)][j], dp[mask][i] + adj[i][j]);
				}
				ll rmask = ((1LL << n) - 1) ^ mask;
				for (ll submask = rmask; submask; submask = (submask - 1) & rmask){
					dp[mask | submask][i] = max(dp[mask | submask][i], dp[mask][i] + msum[submask | (1LL << i)]);
				}
			}
		}
	}
	cout << smw - dp[(1LL << n) - 1][n - 1] << endl;
}

Measured memory_bytes: 9588
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
	return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
	return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static char S[200001];
static size_t whiteSum[200000];
static size_t blackSum[200000];

int main(void) {
	size_t N;

	scanf("%zu\n%s", &N, S);

	bool blackFound = false;

	for (size_t i = 0; i < N; i++) {
        if (i == 0) {
            whiteSum[0] = (S[i] == '.' ? 1 : 0);
            blackSum[0] = (S[i] == '#' ? 1 : 0);
        }
        else {
            whiteSum[i] = whiteSum[i - 1] + (S[i] == '.' ? 1 : 0);
            blackSum[i] = blackSum[i - 1] + (S[i] == '#' ? 1 : 0);
        }
	}

    size_t transCountMin = (size_t)10000000;

    for (size_t i = 0; i <= N; i++) {
        size_t transCount = 0;
        if (i < N) {
            transCount += whiteSum[N - 1] - whiteSum[i];
        }
        if (0 < i) {
            transCount += blackSum[i - 1];
        }

        if (transCount < transCountMin) {
            transCountMin = transCount;
        }
    }

	printf("%zu\n", transCountMin);

	return 0;
}


Measured memory_bytes: 3456
def is_no2(X):
    if X[1] == min(X) or X[1] == max(X):
        return 0
    else:
        return 1

N = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(N-2):
    X = [P[i], P[i+1], P[i+2]]
    ans += is_no2(X)

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        for(int i = 1; i <= H; i ++){
            for(int j = 1; j <= W; j++){
                if( i == 1 || i == H || j == 1 || j == W){
                    printf("#");
                }
                else{
                    printf(".");
                }
                
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

int main(){
    int N, buf;
    cin >> N;
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> A;
    for(int i = 1; i <= N; ++i){
        cin >> buf;
        A.push(make_pair(buf, i));
    }
    while(!A.empty()){
        cout << A.top().second << ' ';
        A.pop();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4328
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int h0;
    cin >> h0;
    int ans = h0;
    for(int i=1; i<N;i++) {
        int h1;
        cin >> h1;
        if(h1 > h0) {
            ans += h1 - h0;
        }
        h0 = h1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , k , a[104] , dp[N][2];
int calc(int val , bool p ){
    //cout<<val<<" "<<p<<endl;
    if(val == 0)
        return !p;
    int &ret = dp[val][p];
    if(ret != -1)return ret;
    if(p == 0)
        ret = 1;
    else ret = 0;
    for(int i = 0 ; i < n ; i++){
        if(val - a[i] < 0)continue;
        if(p == 0)
        ret = min(ret , calc(val - a[i] , !p));
        else ret = max(ret , calc(val - a[i] , !p));
    }
    return ret;
}
int main(){
    cin >> n >> k;
    for(int i = 0; i < n ; i++){
        cin >> a[i];
    }
    memset(dp , -1 , sizeof dp);
    if(calc(k , 0) == 1)
        cout<<"Second";
    else cout<<"First";
    return 0;
}

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

int main(){
  vector<char> a(3),b(3);
  for(int i=0;i<3;i++){
    cin >> a.at(i);
    cin >> b.at(i);
  }
  if(a.at(0)==b.at(2)&&a.at(1)==b.at(1)&&a.at(2)==b.at(0)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <atcoder/all>
using namespace std; using namespace atcoder; using ll = long long;
ll n;
map<ll,ll> mp;
vector<ll> v;
ll dfs(ll id, ll x) {
  if (v.size() == id) {
    //cout << n << " " << x << " " << n/x<<endl;
    pair<ll,ll> p=crt(vector<ll>{0,n/x-1}, vector<ll>{x,n/x});
    if (p.first == 0) return (ll)1e18;
    else return p.first;
  } else {
    ll an = 1e18;
    int till = mp[v[id]];
    for(int i=0;i<=till;i++) {
      an = min(an, dfs(id+1, x));
      x *= v[id];
    }
    return an;
  }
  return (ll)1e18;
}
int main() {
  //n=1;
  //for(ll i=2;i<=16;i++) n*=i;
  //cout<<n<<endl;
  cin>>n; n*=2;
  ll m=n;
  for(ll i=2;i*i<=m;i++) {
	while(m%i==0) mp[i]++, m/=i;
  }
  if (m>1) mp[m]++;
  for(pair<ll,ll> p : mp) {
    v.push_back(p.first);
  }
  cout<<dfs(0,1)<<endl;
}

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

//
// Watch
//

int main () {
    int S;
    int h, m, s;

    cin >> S;

    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;

}

Measured memory_bytes: 3100
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

int t = 7368792;

main {
  while (true) {
    int m = in();
    int n = in();
    if (m == 0 && n == 0) break;
    vector<bool> v(t);
    int i = m;
    rep(_, n) {
      while (v[i]) i++;
      for (int k = i; k < t; k += i) v[k] = true;
    }
    while (v[i]) i++;
    cout << i << endl;
  }
}



Measured memory_bytes: 3996
import Data.List (sortBy)

main = do
  line1 <- getLine
  line2 <- getLine
  let
    [_,k] = map read $ words line1 :: [Int]
    dat = map read $ words line2 :: [Int]
    ans = sum $ take k $ sortBy (\x y -> y `compare` x) dat
  putStrLn $ show ans


Measured memory_bytes: 636
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	int N;
	cin >> N;
	vector<int> C(N);
	vector<int> S(N);
	vector<int> F(N);
	REP(i, N-1){
		cin >> C[i] >> S[i] >> F[i];
	}
	REP(i, N-1){
		ll time = 0;
		for(int k=i; k<N-1; k++){
			if(time<=S[k]){
				time = S[k]+C[k];
			}else if(time%F[k]==0){
				time += C[k];
			}else{
				time = ((int)(time/F[k])+1)*F[k]+C[k];
			}
		}
		cout << time << endl;
	}
	cout << 0 << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int a, b;
  cin >> a >> b;

  int c = b - a;
  cout << (1 + c) * c / 2 - b << endl;

  return 0;
}


Measured memory_bytes: 256
# 初期入力
A,B = (int(x) for x in input().split())

#
import math
tapp_num = math.ceil( (B-1)//(A-1) )
#print(tapp_num)


sasikomiguti_misiyou=0
if B==1:
    print(0)
elif B<=A:
    print(1)
else:        
    sasikomiguti_misiyou =(tapp_num -1)*(A) +A
    if B <= sasikomiguti_misiyou-1:
        print(tapp_num)
    else:
        print(tapp_num +1)

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
    int a, b, c, k;
    scanf("%d %d %d\n%d", &a, &b, &c, &k);
    int d = max(a, max(b, c));
    int r = a + b + c - d;
    printf("%d\n", (int)(d * pow(2, k) + r));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
const long long LLINF = 1LL << 62;
const int INF = 1LL << 30;
using namespace std;

int main(void) {
	int N, K;
	cin >> N >> K;

	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - (K - 1) - 1 << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 100001

int N, M;

bool check(int N){
    bool f = false;
    if(N % 10 == 7) return true;
    N /= 10;
    if(N % 10 == 7) return true;
    N /= 10;
    if(N % 10 == 7) return true;
    return false;
}


int main(){
    cin >> N;
    if(check(N)) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
typedef pair<int,int> P;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
string s[22];
int cnt;
void dfs(int x, int y){
	cnt++;
	s[x][y]='#';
	for(int i=0;i<4;i++){
		if(s[ x+dx[i] ][ y+dy[i] ]!='#') dfs(x+dx[i],y+dy[i]);
	}
}
int main(){
	while(true){
		int w,h,sx,sy;
		cnt=0;
		cin >> w >> h;
		if(!w) break;
		for(int i=1;i<=h;i++){
			cin >> s[i];
			s[i]="#"+s[i]+"#";
		}
		s[0]="";
		s[h+1]="";
		s[0].append(w+2,'#');
		s[h+1].append(w+2,'#');
		for(int i=1;i<h+1;i++){
			for(int j=1;j<w+1;j++){
				if(s[i][j]=='@'){sx=i;sy=j;}
			}
		}
		dfs(sx,sy);
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
# include <iostream>
# include <string>
# include <vector>


using namespace std;


int main() {
    string s;
    cin >> s;

    int n = s.size();
    vector<int> a(n+1, 0);

    for (int i=0; i<n; i++) {
        if (s[i] == '<') a[i+1] = a[i] + 1;
    }

    for (int i=n-1; 0<=i; i--) {
        if (s[i] == '>' and a[i] <= a[i+1]) a[i] = a[i+1] + 1;
    }

    long long ans = 0;
    for (int ai: a) {
        ans += ai;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
/*long int frog1(long int dp[],int h[],long int i)
{
  
  if(i==1)
    dp[i]=abs(h[i+1]-h[i]);
  else
    
  
    return dp[i-1];
}*/
int main()
{
  fio;
  long int n;
  cin>>n;
  int h[n+1];
  long int dp[n];
  dp[0]=0;
   for(int i=1;i<n;++i)
    dp[i]=NIL;
  for(int i=1;i<=n;++i)
  cin>>h[i];

  //long int k=frog1(dp,h,n);
  dp[1]=abs(h[2]-h[1]);
  for(int i=2;i<n;++i)
    dp[i]=min(abs(h[i+1]-h[i])+dp[i-1],abs(h[i+1]-h[i-1])+dp[i-2]);
  // for(int i=0;i<n;++i)
  cout<<dp[n-1]<<'\n';
  return 0;
}

Measured memory_bytes: 1408
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder
import kotlin.math.max

object BMain{
    fun solve(){
        val n = nextInt()
        val k = nextLong()
        val a = LongArray(n){ nextLong() }

        var ansr = 0L
        var ansl = 2000000000L

        while(ansl - ansr > 1L){
            val ansm = (ansl + ansr) / 2
            var mcount = 0L
            a.forEach {
                mcount += if(it % ansm == 0L){
                    it / ansm
                } else{
                    it / ansm + 1
                }
            }

            if(mcount <= k + n){
                ansl = ansm
            }else{
                ansr = ansm
            }
        }

        println(ansl)
    }





    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun nextDouble() = next().toDouble()
}

fun main(){
    BMain.solve()
}



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

  int n,a,b[10];

  while(1){

    cin >>n;

    if(n == 0)break;

    for(int i=0 ; i < 10 ; i++){
      b[i]=0;
    }
    
    for(int i=0 ; i < n ; i++){
      cin >>a;
      b[a]++;
    }
    
    for(int i=0 ; i < 10 ; i++){
      if(b[i] == 0){
	cout <<"-";
      }
      for(int j=0 ; j < b[i] ; j++){
	cout <<"*";
      }
      cout <<endl;
    }
  }
  
  return 0 ;
}

Measured memory_bytes: 1152
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int x;
    cin >> x;
    repl(i,x,200000){
        repl(j,2,sqrt(x)+2){
            if(i%j==0 && j!=i) goto nxt;
        }
        cout << i << endl;
        return 0;
        nxt:;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	int s=0;
	cin>>a>>b>>c;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	if((b-a)%2==0)s+=(b-a)/2;
	else s+=(b-a+4)/2;
	s+=c-b;
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
def main():
  M, D = map(int, input().split())
  seki = 0
  for month in range(1, M+1):
    for day in range(1, D+1):
      dten = day // 10
      done = day % 10
      seki += 1 if done * dten == month and dten >= 2 and done >= 2 else 0
  print(seki)


if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

bool cmp(const pair<int,int> &a, const pair<int,int> &b) {
    return (double)a.second / a.first > (double)b.second / b.first;
}

int main() {
    ios::sync_with_stdio(0);

    int N, W;
    cin >> N >> W;

    double ans = 0;
    int rem = W;
    vector<pair<int,int> > posv, negv;
    for(int i = 0; i < N; ++i) {
        int w, vv;
        cin >> w >> vv;
        if(w <= 0 && vv >= 0) {
            ans += vv;
            rem -= w;
        }
        else if(w >= 0 && vv <= 0) {
            // through
        }
        else {
            if(w > 0) posv.push_back(make_pair(w, vv));
            else negv.push_back(make_pair(-w, -vv));
        }
    }
    sort(posv.begin(), posv.end(), cmp);
    sort(negv.begin(), negv.end(), cmp);
    reverse(negv.begin(), negv.end());

    double pr, nr;
    vector<pair<int,int> >::iterator pi, ni;
    pi = posv.begin();
    ni = negv.begin();
    pr = 0;
    if(ni != negv.end()) nr = ni->first;

    while(pi != posv.end()) {
        if(rem < pi->first) {
            ans += (double)pi->second * rem / pi->first;
            pr = pi->first - rem;
            rem = 0;
            break;
        }
        else {
            ans += pi->second;
            rem -= pi->first;
            ++pi;
        }
    }

    while(pi != posv.end() && ni != negv.end()) {
        bool pr_is_min = pr < nr;
        double amt_w = pr_is_min ? pr : nr;

        double diff = amt_w/pi->first*pi->second - amt_w/ni->first*ni->second;
        if(diff < 0) break;
        ans += diff;
        if(pr_is_min) {
            ++pi;
            pr = pi->first;
            nr -= amt_w;
        }
        else {
            ++ni;
            nr = ni->first;
            pr -= amt_w;
        }
    }

    cout.precision(4);
    cout.setf(ios::fixed);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 0
n,m = map(int,input().split())
a = list(map(int,input().split()))

sum_a = sum(a)
jouken = sum_a / (m * 4)
#print(jouken)
c = 0
for i in range(n):
    if a[i] >= jouken:
        c += 1
if c >= m:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 38392
from collections import defaultdict
N, M = map(int, input().split())
A = [[] for i in range(N)]
for i in range(N):
    A[i] = list(map(lambda x: int(x) - 1, input().split()))


def calc(k):
    D = [0] * N
    S = [True] * M
    K = M
    while K > 0:
        d = defaultdict(int)
        for i in range(N):
            while D[i] < M and not S[A[i][D[i]]]:
                D[i] += 1
            d[A[i][D[i]]] += 1
        for p, v in d.items():
            if v > k:
                S[p] = False
                K -= 1
                break
        else:
            return True
    return False


l, r = 0, N
while r - l > 1:
    mid = (l + r) // 2
    if calc(mid):
        r = mid
    else:
        l = mid

print(r)



Measured memory_bytes: 49756
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int S[100000];

int main(void) {

    int n;
    cin >> n;

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

    int q, total = 0;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        int left = 0, right = n - 1, mid = 0;
        while (left <= right) {
            mid = (left + right) / 2;
            if (t == S[mid]) {
                ++total;
                break;
            }
            if (t > S[mid]) {
                left = mid + 1;
            }
            else {
                right = mid - 1;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, x;
    cin >> N >> x;
    vector<int> A(N);
    rep(0, i, N)
    {
        cin >> A.at(i);
    }
    sort(all(A));

    int sum = 0, ans = 0;
    rep(0, i, N)
    {
        sum += A.at(i);
        if (sum > x)
        {
            break;
        }
        ans++;
    }
    if (ans == N && sum != x)
    {
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

int main(void)
{
    int N;
    cin >> N;
    while(N) {
        if (N%10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        N /= 10;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        
        int w = s.nextInt();
        int h = s.nextInt();
        int x = s.nextInt();
        int y = s.nextInt();
        int r = s.nextInt();
        
        //
        String result = "";
        if ( 0 <= x-r && x+r <= w && 0 <= y-r && y+r <= h ) {
            result = "Yes";
        } else {
            result = "No";
        }
        System.out.println(result);
        
    }
}


Measured memory_bytes: 26352
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
    int n , k ;
    cin >> n >> k ;
    int dp[k + 2] = {0} , arr[n] ;
    for(int i = 0 ; i < n ; i++) cin >> arr[i];
    sort(arr , arr + n) ;
    for(int i = 0 ; i <= k ; i++){
        if(k < arr[0]) {
            dp[i] = 0 ;
            continue ;
        }
        for(int j = 0 ; j < n ; j++){
            if(i >= arr[j]){
                if(dp[i - arr[j]] == 0) {
                    dp[i] = 1 ;
                    break ;
                }
            }
        }
    }
    if(dp[k]) cout << "First" ;
    else cout << "Second" ;
}

Measured memory_bytes: 640
import math

N,A,B=map(int, input().split())
v=list(map(int, input().split()))

v.sort()
v.reverse()
w=0
for i in range (0,A):
  w+=v[i]
ave=w/A
print(ave)

mini=v[A]
C=v[0:A].count(mini)#最低個数
D=v[0:A].count(mini)+B-A#要素が増えても平均が落ちない場合の最大個数
if v[0]!=v[A]:#要素が増えたら平均が落ちる場合
  D=A
  for k in range (0,A):
    if v[k]>v[A]:
      D-=1#最大個数はB-(v[A]より大きいものの個数)
p=v.count(mini)#最小の人たちの個数
D=min(D,p)

q=0
for k in range (C,D+1):
  q+=math.factorial(p)/(math.factorial(p-k)*math.factorial(k))
print(int(q))


Measured memory_bytes: 3064
import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            for c in links[v]:
                for u in links[v][c]:
                    if (u, c) not in visited:
                        q.append((d + 1, u, c))
        else:
            for u in links[v][e]:
                if (u, e) not in visited:
                    q.appendleft((d, u, e))
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))


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

#include <iostream>
#include <fstream>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

int MAX_TRIE = (int) 1.5e6;

class Task {
 public:
  void solveOne(istream &in, ostream &out) {
    int n;
    in >> n;

    vector<vector<int>> child(MAX_TRIE, vector<int>(26, -1));
    vector<vector<int>> numReducibleTo(MAX_TRIE, vector<int>(26, 0));
    vector<int> totalChildren(MAX_TRIE);
    vector<int> count(MAX_TRIE);
    int root = 0;
    int nextAvailable = 1;

    for (int i = 0; i < n; ++i) {
      string s;
      in >> s;
      int at = root;
      for (int j = int(s.size()) - 1; j >= 0; --j) {
        int cur = s[j] - 'a';
        if (child[at][cur] < 0) {
          child[at][cur] = nextAvailable++;
        }
        at = child[at][cur];
      }
      ++count[at];
    }

    int64 res = 0;

    for (int at = nextAvailable - 1; at >= 0; --at) {
      for (int c = 0; c < 26; ++c) {
        int dest = child[at][c];
        if (dest < 0) continue;
        totalChildren[at] += count[dest] + totalChildren[dest];
        for (int i = 0; i < 26; ++i) {
          if (i == c) {
            numReducibleTo[at][i] += count[dest] + totalChildren[dest];
          } else {
            numReducibleTo[at][i] += numReducibleTo[dest][i];
          }
        }
      }
      for (int c = 0; c < 26; ++c) {
        int dest = child[at][c];
        if (dest < 0) continue;
        if (count[dest] == 0) continue;
        res += count[dest] * (int64) numReducibleTo[at][c];
        res -= count[dest] * (count[dest] + 1) / 2;
      }
    }

    out << res << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Task solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 415032
# import math
# import statistics
# import itertools
# a=int(input())
# b=input()
# c=[]
# for i in a:
#     c.append(int(i))
A,B,C= map(int,input().split())
# f = list(map(int,input().split()))
# g = [int(input()) for _ in range(N)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

nowA=A
nowB=B
nowC=C
count=0
if A%2==1 or B%2==1 or C%2==1:
    print(0)
elif A==B==C :
    print(-1)
else:
    while True:
        nowA=B//2+C//2
        nowB=A//2+C//2
        nowC=A//2+B//2
        A=nowA
        B=nowB
        C=nowC
        count+=1
        if nowA%2==1 or nowB%2==1 or nowC%2==1:
            print(count)
            exit()


Measured memory_bytes: 9152
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2052
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12596
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,i,f[1000005],sum[1000005],ans;
int main(){
	f[0]=1;
	sum[0]=1;
   	f[1]=1;
   	sum[1]=2;
   	n=read();
   	for(i=2;i<=n;i++){
   		f[i]=(sum[i-1]-f[i-2]+mo)%mo;
   		sum[i]=(sum[i-1]+f[i])%mo;
   	}
   	for(i=0;i<=n;i++){
		if(i<=n-2)
			ans=(ans+f[i]*(n-1)%mo*(n-1))%mo;
		if(i==n)
			ans=(ans+f[i])%mo;
		else
			ans=(ans+f[i]*min(i+1,n-1))%mo;
	}
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  int A[Q];
  for (int i = 0; i < Q; i++) {
    cin >> A[i];
    A[i]--;
  }
  int p[N]{};
  for (int i = 0; i < Q; i++) {
    p[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    if (K - Q + p[i] <= 0) cout << "No\n";
    else cout << "Yes\n";
 
  }
  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FORr(i, j, 0)
#define INF (1<<30)
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

int sx, sy, tx, ty;

int main() {
        scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
        rep(i, abs(ty - sy)) printf("U");
        rep(i, abs(tx - sx)) printf("R");
        rep(i, abs(ty - sy)) printf("D");
        rep(i, abs(tx - sx)) printf("L");
        printf("L");
        rep(i, abs(ty - sy) + 1) printf("U");
        rep(i, abs(tx - sx) + 1) printf("R");
        printf("D");
        printf("R");
        rep(i, abs(ty - sy) + 1) printf("D");
        rep(i, abs(tx - sx) + 1) printf("L");
        printf("U\n");
        return 0;
}

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

int x, y;

int dfs(int lx, int ly, int ux, int uy, int n) {
    if(lx <= x && x <= ux && ly <= y && y <= uy) return n % 3 + 1;
    int dx = ux - lx + 1, dy = uy - ly + 1;
    if(n % 4 == 0) return dfs(lx, ly, ux + dy, uy, n + 1);
    if(n % 4 == 1) return dfs(lx, ly, ux, uy + dx, n + 1);
    if(n % 4 == 2) return dfs(lx - dy, ly, ux, uy, n + 1);
    if(n % 4 == 3) return dfs(lx, ly - dx, ux, uy, n + 1);
    return -999;
}

int main() {
    cin >> x >> y;
    cout << dfs(0, 0, 0, 0, 0) << '\n';
    return 0;
}



Measured memory_bytes: 3100
n,m=gets.split.map(&:to_i)

a = []
n.times do
  a << gets.strip
end

b = []
m.times do
  b << gets.strip
end

def match?(x,y)
  x.each_with_index {|row, i| return false unless row == y[i]}
  true
end

(0..(n-m)).each do |i|
  (0..(n-m)).each do |j|
    _a = a[i...(i+m)].map {|row| row[j...(j+m)]}
    if match?(_a, b)
      puts 'Yes'
      exit 0
    end
  end
end

puts 'No'

Measured memory_bytes: 1916
N = int(input())
 
c = []
for i in range(10):
    c.append([0] * 10)
 
for i in range(N):
    s = str(i+1)
    i1 = int(s[0])
    i2 = int(s[-1])
    c[i1][i2] += 1
    
total = 0
for i in range(10):
    for j in range(10):
        total += c[i][j] * c[j][i]
        
print(total)

Measured memory_bytes: 3064