akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//
ll a[maxn];

//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	

	int xu, yu, n; cin >> xu >> yu >> n;

	int xl = 0, yl = 0;

	int x, y, a;
	rep(i, n)
	{
		cin >> x >> y >> a;
		if (a == 1) xl = max(xl, x);
		else if (a == 2) xu = min(xu, x);
		else if (a == 3)yl = max(yl, y);
		else if (a == 4)yu = min(yu, y);

		if ((xu - xl)*(yu - yl) <= 0)
		{
			Print(0);
			return 0;
		}

	}

	Print((xu - xl)*(yu - yl));

	//
	// your code finished

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>
#include <ctime>
#include <list>
#include <complex>
#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

const double EPS = 1e-9;

bool check(double x, double y, double vx, double vy){
	double yy = -1 / 2. / vx / vx*x*x + vy / vx*x;
	return y < yy + EPS;
}

int main(){
	int d, n, b;
	cin >> d >> n >> b;

	vector<int> p(n), h(n);
	rep(i, n) cin >> p[i] >> h[i];

	double ans = 1e100;
	FOR(i, 1, b + 2){
		double len = (double)d / i;

		double lb = 0, ub = sqrt(len / 2);
		rep(j, 10000){
			double mid = (lb + ub) / 2;
			bool ok = true;
			rep(k, n){
				double pp = p[k];
				while (pp > len - EPS) pp -= len;
				ok &= check(pp, h[k], mid, len / 2 / mid);
			}
			if (ok) lb = mid;
			else ub = mid;
		}
		if (lb < EPS) continue;
		double vx = lb, vy = len / 2 / vx;
		ans = min(ans, sqrt(vx*vx+vy*vy));
	}
	cout.setf(ios::fixed);
	cout.precision(10);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1268
def nurie(x, y, a):
    if a == 1:
        for i in range(x):
            for j in range(H):
                A[i][j] = 1
    if a == 2:
        for i in range(x, W):
            for j in range(H):
                A[i][j] = 1
    if a == 3:
        for i in range(W):
            for j in range(y):
                A[i][j] = 1
    if a == 4:
        for i in range(W):
            for j in range(y, H):
                A[i][j] = 1

def cal_area(A):
    count = 0
    for i in range(W):
        for j in range(H):
            if A[i][j] == 0:
                count += 1
    return count

W, H, N = map(int, input().split())
A = [[0]*H for i in range(W)]

for i in range(N):
    x, y, a = map(int, input().split())
    nurie(x, y, a)

print(cal_area(A))

Measured memory_bytes: 3064
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, p = LI()
    A = LI()

    even, odd = 0, 0
    for a in A:
        if a % 2:
            odd += 1
        else:
            even += 1

    if odd:
        return 2 ** (n - 1)
    else:
        return 2 ** n if p == 0 else 0


print(main())


Measured memory_bytes: 3064
#include <stdio.h>
#define LIM 25

int bmi(double kg,double m){
        double buf;
        buf = m * m;
        buf = kg / buf;
        if(buf < 25){
                return 0;
        }
        else{
                return 1;
        }
}

int main(){
        int n;
        double k,m;
        int c=0;
        while(scanf("%d,%lf,%lf",&n,&k,&m)!=EOF){
                if(1==bmi(k,m)){
                        printf("%d\n",n);
                        k = 0;
                }

                c++;
        }

        return 0;
}
//vim: set ft=C fenc=utf-8 ff=unix ts=4 sw=4: 

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, m, a[10], c[10];
P p[10];
void solve(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> c[i];
		a[i]--;
		p[i] = P(a[i],c[i]);
	}
	sort(p, p+m);
	
	vector<int> s(n, -1);
	for(int i = 0; i < m; i++){
		int x = p[i].first, y = p[i].second;
		if(i > 0 && x == p[i-1].first && y != p[i-1].second){
			cout << -1 << endl;
			return;
		}
		s[x] = y;
	}
	if(n > 1 && s[0] == 0){
		cout << -1 << endl;
		return;
	}
	for(int i = 0; i < n; i++){
		cout << max(s[i],(i==0&&n>1?1:0));
	}
	cout << endl;
}

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

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

vector<vector<int>> to;
vector<bool> seen, finished;

bool dfs(int v) {
    if (seen[v]) {
        if (finished[v]) return false;
        else return true;
    }
    seen[v] = true;
    bool res = false;
    for (auto u : to[v]) res |= dfs(u);
    finished[v] = true;
    return res;
}

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

    int v, e;
    cin >> v >> e;
    to.resize(v);
    rep(i, e) {
        int s, t;
        cin >> s >> t;
        to[s].pb(t);
    }
    seen.resize(v);
    finished.resize(v);
    bool ans = false;
    rep(i, v) if (!seen[i]) ans |= dfs(i);
    cout << (ans ? 1 : 0) << endl;
}



Measured memory_bytes: 3232
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let x: usize = sc.read();
    let y: usize = sc.read();
    let z: usize = sc.read();
    println!("{} {} {}", z, x, y);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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



int main(void){
    int K;
    cin>>K;
    int num_a,num_b;
    if(K%2==0){
        num_a=K/2;
        num_b=K/2;
    }else{
        num_a=(K+1)/2;
        num_b=num_a-1;
    }
    cout<<num_a*num_b<<endl;
    return 0;
}



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

int main() {
    string o, e;
    cin >> o >> e;
    int os = o.size();
    int es = e.size();
    char pass[os+es];
    for (int i = 0; i < os; i++) {
        pass[2*i] = o[i];
    }
    for (int i = 0; i < es; i++) {
        pass[2*i+1] = e[i];
    }
    for (int i = 0; i < es+os; i++) {
        cout << pass[i];
    }
    cout << endl;
}

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

int main()
{
  int score = 0, n;
  for (int i = 0; i < 5; i++){
    cin >> n;
    if (n < 40){
      n = 40;
    }
    score += n;
  }
  cout << score / 5 << endl;
  return (0);
}

Measured memory_bytes: 1160
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    
    int N, K;
    cin >> N >> K;
    
    long long sum = 0;
    
    for (long long i = K; i <= N + 1; i++) {
        sum += i * (N - i + 1) + 1;
        sum = sum % 1000000007;
    }
    
    cout << sum;

    return 0;
}


Measured memory_bytes: 3636
n,q = map(int, input().split())
s = input()
l = [0] * q
r = [0] * q
for i in range(q):
    l[i],r[i] = map(int, input().split())
c = [0] * n
for i in range(1,n):
    if s[i-1:i+1] == "AC":
        c[i] = c[i-1] + 1
    else:
        c[i] = c[i-1]
for i in range(q):
    print(c[r[i]-1] - c[l[i]-1])

Measured memory_bytes: 14200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;



void solve(){
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    if(s1.back()==s2.front()&&s2.back()==s3.front()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

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

  if(k==s){
    printf("Draw\n");
  }else if(k==1 or s==1){
    if(k<s)
      printf("Alice\n");
    else
      printf("Bob\n");
  }else{
    if(k>s)
      printf("Alice\n");
    else
      printf("Bob\n");
  }

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=1000000007;
constexpr ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll a,b,c;
cin>>a>>b>>c;
//2√ab<c-a-b
if(c-a-b<=0){
    cout<<"No"<<endl;
    return 0;
}
ll d=(c-a-b);
if(4*a*b<d*d){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val a = IntArray(n)
    val s = mutableListOf<String>()
    val p = IntArray(n)
    for (i in 0 until n) {
        a[i] = i
        val t = scanner.next()
        s.add(t)
        p[i] = scanner.nextInt()
    }
    for (i in 0 until n) {
        for (l in 0 until n - 1) {
            if (s[l] > s[l + 1]) {
                val ss = s[l]
                s[l] = s[l + 1]
                s[l + 1] = ss
                val b = a[l]
                a[l] = a[l + 1]
                a[l + 1] = b
                val q = p[l]
                p[l] = p[l + 1]
                p[l + 1] = q
            }
        }
    }
    for (i in 0 until n) {
        for (l in 0 until n - 1) {
            if (s[l] == s[l + 1]) {
                if (p[l] < p[l + 1]) {
                    val b = a[l]
                    a[l] = a[l + 1]
                    a[l + 1] = b
                    val q = p[l]
                    p[l] = p[l + 1]
                    p[l + 1] = q
                }
            }
        }
    }
    for (i in 0 until n) {
        println(a[i] + 1)
    }
}


Measured memory_bytes: 31388
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int N, M, now = 0, hole, maxi;
    long long result  = 1;
    bool canDo = true;
    vector<int> step;
    vector<long long> fib;

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

    //連続した階段の数を配列にぶち込む
    for(int i = 0; i < M; i++){
        scanf("%d", &hole);
        step.push_back(hole - now  - 1);
        now = hole + 1;
    }
    step.push_back(N - now);

    //stepをソート  O(N log N)
    sort(step.begin(), step.end());

    if(step.front() < 0){
        cout << 0 << endl;
        return 0;
    }

    maxi = step.back();

    //フィボナッチ数列の計算
    fib.push_back(1);
    fib.push_back(1);
    for(int i = 2; i <= maxi; i++)
        fib.push_back((fib[i - 1] + fib[i - 2]) % 1000000007);

    //結果の計算
    for(const auto &e: step)
        result = result * fib[e] % 1000000007;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(ll i=0;i<x;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(){
  string S;
  cin>>S;
  if(S=="ABC") cout<<"ARC";
  else cout<<"ABC";
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}

const char newl = '\n';

ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans*=a;a*=a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mod){ll ans=1;do{if(b&1)ans=ans*a%mod;a=a*a%mod;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll x; cin >> x;

    map<ll, ll> mp;
    map<ll, ll> pm;
    for (ll i = -1000; i < 1000; i++) {
        ll ii = i * i;
        ll iiiii = ii * ii * i;
        mp[i] = iiiii;
        pm[iiiii] = i;
    }

    ll A, B;
    for (auto & itr : mp) {
        if (itr.second + x == 0) {
            A = 0;
            B = itr.first;
            break;
        }
        if (pm[itr.second + x] != 0) {
            A = pm[itr.second + x];
            B = itr.first;
            break;
        }
    }
    cout << A << ' ' << B << newl;

    return 0;
}


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

long mod = 998244353;

long modpow(long a, long n){
  long r = 1;
  while(n){
    if(n & 1)  r = r * a % mod;
    a = a * a % mod;
    n = n >> 1;
  }
  return r;
}

int main(){
  int n, d;  cin >> n >> d;
  vector<long> table(n, 0);
  bool nothing = (d != 0), zero = false;
  for(int i=1; i<n; i++){
    cin >> d;
    table[d]++;
  }
  if(table[0])  nothing = true;
  long ans = 1;
  for(int i=1; i<n-1; i++){
    if(table[i]>0 && zero)  nothing = true;
    if(table[i] == 0)  zero = true;
    if(table[i] == 1)  continue;
    ans = (ans * modpow(table[i], table[i+1])) % mod;
  }

  if(nothing || (n==1 && table[0]==0))  ans = 0;
  cout << ans << endl;

  return 0;
}


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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<string> s(N);
    for(auto& i : s){
        cin >> i;
        sort(i.begin(), i.end());
    }
    sort(s.begin(), s.end());
    string prev;
    unsigned long cnt{0}, ans{0};
    for(const auto& i : s){
        if(prev == i){
            ++cnt;
        }else{
            cnt = 0;
            prev = i;
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
function Main(input) {
  var In = input.split('\n');
  var num = In[1].split(' ');
  var count = 0;
  
  while(true) {
    var a = true;
    var length = In[0];
    for(var i = 0; i < length; i++){
      if(num[i]%2 == 0){
        num[i] = num[i] / 2;
      } else if(num[i] % 2 != 0){
        a = false;
      }
    }
    
    if(a == false){
      break;
    }
    count += 1;
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 20:10:47 +0900
# LastModified: 2020-06-26 20:35:09 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    c = []
    for _ in range(3):
        c.append(list(map(int, input().split())))
    a_12 = c[0][0]-c[1][0]
    a_13 = c[0][0]-c[2][0]
    a_23 = c[1][0]-c[2][0]
    b_12 = c[0][0]-c[0][1]
    b_13 = c[0][0]-c[0][2]
    b_23 = c[0][1]-c[0][2]

    for i in range(1, 3):
        if b_12 != c[i][0]-c[i][1] or b_13 != c[i][0]-c[i][2] or b_23 != c[i][1]-c[i][2]:
            print("No")
            return
        if a_12 != c[0][i]-c[1][i] or a_13 != c[0][i]-c[2][i] or a_23 != c[1][i]-c[2][i]:
            print("No")
            return
    print("Yes")



        


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<(b);i++)
#define ROF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 70
#define M 51
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

int main()
{
    int a,b,c,d,e,f,g;
    while(cin>>a>>b>>c>>d>>e>>f>>g)
    {
        ll ans = 0;
        ans+=b;
        int odd = 0,even = 0,p = 1;
        if(a%2)odd++;
        else even++,p = a;
        if(d%2)odd++;
        else even++,p = d;
        if(e%2)odd++;
        else even++,p = e;
        if(odd>even&&p>0)
        {
            ans+=3;
            a--;
            d--;
            e--;
        }
        ans+=(a/2)*2;
        ans+=(d/2)*2;
        ans+=(e/2)*2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int A,B;
    cin>>A>>B;
    ll ans = -1;
    rep1(i,1000000){
        if(int(i * 0.08) == A && int(i * 0.1) == B){
            ans = i;
            break;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define rep(i,n) for(long long int i=0;i<n;i++)
#define rep1(i,n) for(long long int i=1;i<=n;i++)
#define repU(i,bottom,ceiling) for(long long int (i)=(bottom);(i)<=(ceiling);(i)++)
#define repD(i,ceiling,bottom) for(long long int (i)=(ceiling);(i)>=(bottom);(i)--)
#define pub push_back
#define pob pop_back
#define pf printf
#define sf scanf
#define ci(a) cin>>a
#define lco(a) cout<<a<<endl
#define co(a) cout<<a
#define vci(v) for(long long int i=0;i<v.size();i++) cin>>v[i]
#define vco(v) for(long long int i=0;i<v.size();i++){ cout<<v[i]<<' '; } cout<<endl
#define mp make_pair
#define fir first
#define sec second
#define clr(arr) memset((arr),0,sizeof(arr))
#define Re return 

typedef long long int ll;
typedef double db;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vb;
typedef vector<vector<double>> vvd;
typedef vector<long long int> vll;
typedef vector<vector<long long int>> vvll;
typedef pair<int,int> pii;

const string alphabet("abcdefghijklmnopqrstuvwxyz");
const vector<pair<int,int>> dir={{0,0},{1,0},{1,1},{0,1},{-1,1},{0,-1},{-1,-1},{0,-1},{1,-1}};
const long double Pi=3.141592653589793238462643383279502884197;
const long double Napier=2.71828182845904523536;
const int Inf=(int)2e9+1e8;
const int Mod=(int)1e9+7;

template<typename T,typename U>                                                   
inline pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir+r.fir,l.sec+r.sec};                                    
} 

template<typename T,typename U> 
inline pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir-r.fir,l.sec-r.sec};                                    
} 

template<typename T,typename U>                                                   
inline pair<T,U> operator*(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir*r.fir,l.sec*r.sec};                                    
}

template<typename T,typename U>                                                   
inline pair<T,U> operator/(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir/r.fir,l.sec/r.sec};                                    
}

template<typename T> inline void Swap(T *x,T *y){ T tem=*x; *x=*y; *y=tem; }

inline long long int rem(long long int n,long long int m){
	if(!m) return 0;
	return (n<0?(n%m)+m:(n%m));
}
             
/*The main code follows below*/

int main(){
	int k; ci(k);
	ll Max,Min;
	vll A; 
	rep(i,k){ ll a; ci(a); A.pub(a); }
	Max=Min=2;
	repD(i,k,1){
		//lco(A.back());
	
		ll RMax=Max%A.back();
		ll RMin=Min%A.back();
		//lco(RMax<<RMin);
		if(Max-RMax<Min){ lco(-1); return 0; }
		Max+=(A.back()-1-RMax);
		Min+=(!RMin?0:(A.back()-RMin));
		//lco(Min<<' '<<Max);
		A.pob();
	}
	lco(Min<<' '<<Max);
	return 0;
}

Measured memory_bytes: 1528
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int x,y,z;
  cin>>x>>y;
  if(x<y)swap(x,y);
  while(1){
    z=x%y;
    if(z==0)break;
    x=y,y=z;
  }cout<<y<<endl;
  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int N, A[200002];
vector<int> vt;
int main(){
    scanf("%d", &N);
    deque<int> dq;
    for(int i = 0; i < N; i++){
        scanf("%d", A + i);
        if(i & 1)dq.push_back(A[i]);
        else dq.push_front(A[i]);
    }
    if(N % 2 == 0)reverse(dq.begin(), dq.end());
    for(auto &i : dq)
        printf("%d ", i);
    return 0;
}


Measured memory_bytes: 3840
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll a[3];
    rep(i,3){
        cin >> a[i];
    }
    ll cnt1=0;
    ll cnt2=0;
    rep(i,3){
        if(a[i]==5){
            cnt1++;
        }
        if(a[i]==7){
            cnt2++;
        }
    }
    if(cnt1==2 && cnt2==1){
        cout << "YES" <<endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N;
  cin>>N;
  int M = 26;
  vector<int> MIN(M,INF);
  for (int i = 0; i < N; i++)
  {
    vector<int> input_c(M,0);
    string str;
    cin>>str;
    for (int i = 0; i < str.size(); i++)
    {
      input_c[(int)(str[i] - 'a')]++;
    }

    for (int i = 0; i < M; i++)
    {
      MIN[i] = min(MIN[i],input_c[i]);
    }
  }

  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < MIN[i]; j++)
    {
      cout<<char(i + 'a');
    }
    
  }
  cout<<endl;
  

  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; ++i) {
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j = i * i; j <= n; j += i) {
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while(x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for(int p : fl) {
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  Sieve s(1e6 + 1);
  map<ll, ll> mp;
  rep(i, n) {
    auto f = s.factor(a[i]);
    for(auto p : f) mp[p.first] = max(mp[p.first], ll(p.second));
  }
  mint l = 1;
  for(auto p : mp) l *= mint(p.first).pow(p.second);
  mint ans = 0;
  rep(i, n) ans += l / a[i];
  cout << ans << endl;
}

Measured memory_bytes: 5112
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
signed main() {
	int a, b;
	cin >> a >> b;
	if (a != 1 && b != 1) cout << 1 << endl;
	if (a != 2 && b !=2) cout << 2 << endl;
	if (a != 3 && b != 3) cout << 3 << endl;
}

Measured memory_bytes: 256
import numpy as np

mass = int(input())
buildings = np.array(list(int(i) for i in input().split()))
move_count = 0
max_move = 0

for i in range(mass-1):
  if buildings[i] >= buildings[i+1]:
    move_count += 1
  else:
    if move_count > max_move:
      max_move = move_count
    move_count = 0
  if move_count > max_move:
    max_move = move_count

print(max_move)

Measured memory_bytes: 23408
nn,m=map(int,input().split())

C=[[] for i in range(nn)]
C.insert(0,"niku")

for i in range(m):
    a,b=map(int,input().split())
    C[a].append(b)
    C[b].append(a)

ans=0    

def tansa(n,path,app):
    new_path=path[:]
    new_path.append(app)
    #print(str(n)+"+",new_path,path)
    if len(new_path)==nn:
        global ans
        ans+=1
        return 1

    for num in C[n]:
        if not num in new_path:
            tansa(num,new_path,num)

            
tansa(1,[],1)

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<memory>
using namespace std;


class ATGCHashSet {
public:
    static const int STR_LENGTH = 14;

    ATGCHashSet() {
        int i;
        for (i = 0; i < BUCKET_NUM; i++) {
            bucket[i][0] = '\0';
        }
    }

    int hashByIdx(char str[], int idx) {
        int key = getKey(str);
        return (h1(key) + idx * h2(key)) % BUCKET_NUM;
    }

    bool find(char str[]) {
        long long key, i, hash;
        for ( i = 0;; i++) {
            hash = hashByIdx(str, i);
            if (strcmp(bucket[hash], str) == 0) return true;
            else if (strlen(bucket[hash]) == 0) return false;
        }
        return false;
    }

    bool insert(char str[]) { 
        long long key, i, hash;
        for (i = 0;; i++) {
            hash = hashByIdx(str, i);
            if (strcmp(bucket[hash], str) == 0) return true;
            else if (strlen(bucket[hash]) == 0) {
                strcpy(bucket[hash], str);
                return false;
            }
        }
        return false;
    }

private:
    static const int BUCKET_NUM = 1046527;

    char bucket[BUCKET_NUM][STR_LENGTH];

    int getChar(char ch) {
        if (ch == 'A') return 1;
        else if (ch == 'C') return 2;
        else if (ch == 'G') return 3;
        else if (ch == 'T') return 4;
        else return 0;
    }

    long long getKey(char str[]) {
        long long sum = 0, p = 1, i;
        for (i = 0; i < strlen(str); i++) {
            sum += p * getChar(str[i]);
            p *= 5;
        }
        return sum;
    }

    int h1(int key) { return key % BUCKET_NUM; }
    int h2(int key) { return 1 + (key % (BUCKET_NUM - 1)); }
};

int main() {
    int i, n, h;
    char str[ATGCHashSet::STR_LENGTH], com[9];
    unique_ptr<ATGCHashSet> table(new ATGCHashSet());

    scanf("%d", &n);

    for (i = 0; i < n; i++ ) {
        scanf("%s %s", com, str);

        if (strcmp(com, "insert") == 0) {
            table->insert(str);
        } else if (strcmp(com, "find") == 0) {
            if (table->find(str)) printf("yes\n");
            else printf("no\n");
        } else {
            printf("some error occur");
            return 1;
        }
    }
    return 0;
}



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

int main(){

		int a, b;
		scanf("%d%d", &a, &b);
		int x[3];
		x[0] = a + b;
		x[1] = a - b;
		x[2] = a * b;
		int result = x[0];
		for(int i = 1; i < 3; i++){
			if(x[i] > result)
				result = x[i];
		}
		
		printf("%d\n", result);
}

Measured memory_bytes: 256
fn main() {
    let (n, k, v) = read();
    let ans = solve(v);
    write(ans);
}
 
fn read() -> (i32, i32, Vec<Vec<bool>>) {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let mut iter = l1.trim().split_whitespace();
    let n = iter.next().unwrap().parse::<i32>().unwrap();
    let k = iter.next().unwrap().parse::<i32>().unwrap();

    let mut v: Vec<Vec<bool>> = Vec::new();
    for i in 0..n {
        v.push(Vec::new());
        for j in 0..k {
            v[i as usize].push(false);
        }
    }

    for i in 0..k {
        let mut l1 = String::new();
        std::io::stdin().read_line(&mut l1).ok();
        let d = l1.trim().parse::<i32>().unwrap();

        let mut l2 = String::new();
        std::io::stdin().read_line(&mut l2).ok();
        let iter = l2.trim().split_whitespace();

        for j in iter {
            let j = j.trim().parse::<i32>().unwrap();
            v[j as usize - 1][i as usize] = true;
        }
    }

    (n, k, v)
}
 
fn write(x: i32) {
    println!("{}", x);
}
 
fn solve(v: Vec<Vec<bool>>) -> i32 {
    v.iter().filter(|&x| x.iter().all(|&x| !x)).count() as i32
}

Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N,K,R,S,P;
	cin>>N>>K>>R>>S>>P;
	string T;cin>>T;
	map<ll,ll>mp;
	rep(i,0,N){
		if(i>=K && T[i]==T[i-K]){
			T[i]='a';
			continue;
		}
		mp[T[i]]++;
	}
	ll ans;
	ans=mp['r']*P+mp['s']*R+mp['p']*S;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  int N;
  cin >> N;
  int vec[N][3];
  FOR(i,0,N) {
    cin >> vec[i][0] >> vec[i][1] >> vec[i][2];
  }
  FOR(i,0,N-1) {
    int now = i;
    int artime = 0;
    while (now < N-1) {
      if (artime <= vec[now][1]) artime = vec[now][1]; //始発より先に着くなら、始発で出発
      else {
        while (artime % vec[now][2] != 0) artime++; //始発よりあとに着くなら、それ以降でFで割れる時に出発
      }
      artime += vec[now][0]; //次駅までの所要時間を足す
      now++;
    }
    cout << artime << endl;
  }    
  cout << 0 << endl; //最後の駅は例外
  return 0;
}

Measured memory_bytes: 3604
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

for i in range(10000):
    s = str(i)
    if len(s) != n:
        continue
    ok = True
    for a, b in sc:
        if s[a - 1] != str(b):
            ok = False
            break
    if ok:
        print(i)
        exit()

print(-1)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,u,v;
    cin >> N >> u >> v;
    u--;v--;
    graph G = graph(N);
    for(int i = 0; i < N-1; i++){
        ll A,B;
        cin >> A >> B;
        A--;B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<ll> distA(N);
    vector<ll> distB(N);
    for (int j = 0; j < N; ++j) {
        distA[j] = -1;
        distB[j] = -1;
    }
    queue<ll> q = queue<ll>();
    q.push(u);
    distA[u] = 0;
    while(!q.empty()){
        ll current = q.front();q.pop();
        for (int i = 0; i < G[current].size(); ++i) {
            if(distA[G[current][i]] == -1){
                distA[G[current][i]] = distA[current]+1;
                q.push(G[current][i]);
            }
        }
    }
    q = queue<ll>();
    distB[v] = 0;
    q.push(v);
    while(!q.empty()){
        ll current = q.front();q.pop();
        for (int i = 0; i < G[current].size(); ++i) {
            if(distB[G[current][i]] == -1){
                distB[G[current][i]] = distB[current]+1;
                q.push(G[current][i]);
            }
        }
    }
    ll M = 0;
    for (int i = 0; i < N; ++i) {
        //cout << distA[i] << "," << distB[i] << endl;
    }
    for (int i = 0; i < N; ++i) {
        if(distA[i] <= distB[i] && G[i].size() == 1){
            ll step = distB[i];
            if((distB[i] - distA[i]) % 2 == 1){
                //step--;
            }
            M = max(M,step - 1);
        }
    }
    cout << M << endl;
}


Measured memory_bytes: 8064
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL P[20001];

LL A[20001],B[20001];

void solve(){
	for(int i=1;i<=N;i++){
		A[i] = (i-1)*20001 + 1;
	}
	for(LL i=N;i>=1;i--){
		B[P[i]] = (1000000000LL-(N-i+1LL)) - A[P[i]];
	}
}

int main(){
    cin >> N;
    for(int i=1;i<=N;i++) cin >> P[i];

    solve();

    for(int i=1;i<=N;i++) cout << A[i] << " ";
    cout << endl;
    for(int i=1;i<=N;i++) cout << B[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define lowbit(x) (x&(-x))
#define MP make_pair
#define fi first
#define se second
#define ls(x) (x << 1)
#define rs(x) ((x << 1) | 1)
#define rep(i,l,r) for (register int i = l ; i <= r ; i++)
#define down(i,r,l) for (register int i = r ; i >= l ; i--)
#define fore(i,x) for (int i = head[x] ; i ; i = e[i].next)
#define SZ(v) (int)v.size()

typedef long long ll;
typedef pair <int,int> pr;
const int maxn = 1e6 + 10;

int mx[maxn],a[maxn],l[maxn],r[maxn],mn[maxn];
int sum[maxn];
int n,k;

int query(int i){
	int res = 0;
	for (; i ; i -= lowbit(i)) res = max(res,mx[i]);
	return res;
}
void modify(int i,int d){
	for (;i <= n ; i+=lowbit(i)) mx[i] = max(mx[i],d);
}
int query_mn(int i){
	int res = n + 1;
	for (; i ; i -= lowbit(i)) res = min(res,mn[i]);
	return res;
}
void modify_mn(int i,int d){
	for (;i <= n ; i+=lowbit(i)) mn[i] = min(mn[i],d);
}
int main(){
	scanf("%d %d",&n,&k);
	for (int i = 1 ; i <= n ; i++) scanf("%d",&a[i]) , a[i]++;
	for (int i = 1 ; i <= n ; i++){
		int id = query(n - a[i] + 1);
		modify(n - a[i] + 1,i);
		//cout<<i<<" "<<id<<endl;
		if ( !id || i - id + 1 > k ) continue;
		sum[i]++;
		sum[id + k]--;
		l[i] = id;
	}
	rep(i,1,n) r[i] = mn[i] = n + 1;
	down(i,n,1){
		int id = query_mn(a[i]);
		modify_mn(a[i],i);
		//cout<<i<<" "<<id<<endl;
		if ( id > n || id - i + 1 > k ) continue;
		r[i] = id; 
	}
	int cur = 0;
	int ans = 1,flag = 0;
	for (int i = 1 ; i <= k ; i++) cur += sum[i];
	if ( !cur ) flag = 1;
	for (int i = 2 ; i <= n - k + 1 ; i++){
		cur += sum[i + k - 1];
		if ( r[i - 1] <= i + k - 1 || l[i + k - 1] );
		else continue;
		if ( cur > 0 ) ans++;
		else if ( !flag ) ans++ , flag = 1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 20224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	string t="CF";
	int ind=0;
	rep(i,s.size()){
		if(s[i]==t[ind]){
			ind++;
			if(ind==2){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_s = list(map(int,input().split()))
    dct = {}
    for i,value in enumerate(a_s):
        i = i+1
        dct[i] = value
    counter = 0
    for key in dct.keys():
        if dct[dct[key]] == key:
            counter += 1
    print(counter//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20704