akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  //vector<ll>to[1000005];
  // ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,c=0,d=-1,e=-1;cin>>a;
  char b;
  string x,y,z;
  rep(i,a){
    cin>>b;
    x.push_back(b);
    z.push_back(i+'1');
  }
  //cout<<z[0];
    rep(i,a){
    cin>>b;
    y.push_back(b);
  }
  do{
    if(x==z)d=c;
    if(z==y)e=c;
    c++;
    if(d!=-1&&e!=-1)break;
  }while(next_permutation(z.begin(),z.end()));
  cout<<abs(d-e);
}



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

using ll = long long;


template<typename T> // T: type of cost
struct LCA {
  int n, root, l;
  vector<vector<int>> to;  // グラフ
  vector<vector<T>> co;    // コスト
  vector<int> dep;         // 根からの深さ
  vector<T> costs;         // コスト（距離）
  vector<vector<int>> par;  // ダブリング配列
  LCA(int n):n(n),to(n),co(n),dep(n),costs(n) {
    l = 0;
    while ((1<<l) < n) ++l;
    par = vector<vector<int>>(n+1,vector<int>(l,n));
  }

  // a - b の間にコスト c の辺を張る
  void add_edge(int a, int b, T c=0) {
    to[a].push_back(b); co[a].push_back(c);
    to[b].push_back(a); co[b].push_back(c);
  }
  void dfs(int v, int d=0, T c=0, int p=-1) {
    if (p != -1) par[v][0] = p;
    dep[v] = d;
    costs[v] = c;
    for (int i = 0; i < to[v].size(); ++i) {
      int u = to[v][i];
      if (u == p) continue;
      dfs(u, d+1, c+co[v][i], v);
    }
  }

  // 初期化 _root: 根の頂点番号
  void init(int _root=0) {
    root = _root;
    dfs(root);
    // ダブリングのテーブルを構築する
    for (int i = 0; i < l-1; ++i) {
      for (int v = 0; v < n; ++v) {
        par[v][i+1] = par[par[v][i]][i];
      }
    }
  }
  // LCA
  int lca(int a, int b) {
    if (dep[a] > dep[b]) swap(a,b);  // 深いほうが b になるようにしておく
    int gap = dep[b]-dep[a];         // gap ぶん b から登る
    for (int i = l-1; i >= 0; --i) {
      int len = 1<<i;
      if (gap >= len) {
        gap -= len;
        b = par[b][i];
      }
    }
    if (a == b) return a;
    for (int i = l-1; i >= 0; --i) {
      int na = par[a][i];
      int nb = par[b][i];
      if (na != nb) a = na, b = nb;
    }
    return par[a][0];
  }
  // 2点間の距離を求める（辺の重みを1とした場合のコストと等しい）
  int length(int a, int b) {
    int c = lca(a,b);
    return dep[a]+dep[b]-dep[c]*2;
  }
  // 2点間のコストを求める
  T dist(int a, int b) {
    int c = lca(a,b);
    return costs[a]+costs[b]-costs[c]*2;
  }
};


void aoj_grl_5_c() {
  int n; cin >> n;
  int root = 0;
  LCA<int> lca(n);

  rep(i, n) {
    int k; cin >> k;
    rep(j, k) {
      int c; cin >> c;
      lca.add_edge(i, c);
    }
  }
  lca.init(root);

  int q; cin >> q;
  rep(i, q) {
    int u, v; cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
}

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

  aoj_grl_5_c();

  return 0;
}



Measured memory_bytes: 27952
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int P[10010];
void init(int N) {
        for (int i=0;i<N;i++) {
            P[i] =i;
        }
    }
int root(int a){
    if(P[a]==a) return a;
    return (P[a] = root(P[a]));
}
void unite(int x,int y){
               P[root(x)] =root(y);
           }
bool is_same_set(int a,int b){
               return root(a)==root(b);
}
int main(){  
    int N,q;
    cin >>N >>q;
   init(N);
   int com,x,y;
   for(int j=0;j<q;j++){
       cin >>com>>x>>y;
       if(com==0){
               unite(x,y);
           }
      
       if(com==1){
          cout << is_same_set(x,y) <<endl;
       }
    }
}


Measured memory_bytes: 3276
#include <iostream>
#include <string>
using namespace std;
int main() {
  int price = 700;
  string S;
  cin >> S;
  for (int i = 0; i < 3; i++) {
    S[i] == 'o' ? price += 100 : price;
  }
  cout << price << endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int h,w;

int main(){
  while(true){
    cin>>h>>w;
    if(h==0||w==0) break;

    for(int i=0;i<h;++i){
      if(i%2==0){
        for(int j=0;j<w;++j){
          if(j%2==0){
            cout<<"#";
          }else{
            cout<<".";
          }
        }
        cout<<endl;
      }else{
        for(int j=0;j<w;++j){
          if(j%2==0){
            cout<<".";
          }else{
            cout<<"#";
          }
        }
        cout<<endl;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1152
M, D = map(int, input().split())

cnt = 0
for m in range(1, M+1):
    for d in range(20, D+1):
        d1 = d % 10
        d10 = d // 10
        if (d1 < 2):
            continue
        if (d1 * d10 == m):
#            print(str(m)+'/'+str(d))
            cnt = cnt + 1

print(cnt)

Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int N;
    cin >> N;
    VEC(int) A(N);
    READVEC(A);

    VEC(int) Xor(N + 1, 0);
    VEC(lint) Sum(N + 1, 0LL);
    FOR(i, 0, N) {
        Xor[i + 1] = Xor[i] ^ A[i];
        Sum[i + 1] = Sum[i] + A[i];
    }

    auto good = [&](int l, int r) {
        //l, r are 0-indexed.
        lint sum = Sum[r + 1] - Sum[l];
        int xr = Xor[r + 1] ^ Xor[l];
        return xr == sum;
    };

    lint ret = 0;
    FOR(i, 0, N) {
        int lo = i, hi = N - 1;
        while (hi - lo > 1) {
            int md = (lo + hi) / 2;
            if (good(i, md))
                lo = md;
            else
                hi = md - 1;
        }

        if (!good(i, hi))
            hi = lo;

        ret += hi + 1 - i;
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 3456
import Control.Applicative

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [n, k]
  | odd k = c0
  | otherwise = c0 + c1
  where
    c0 = (n `div` k) ^ 3
    c1 = ((n - (k `div` 2)) `div` k + 1) ^ 3


Measured memory_bytes: 508
n = int(input())
ans = [[['a']]] + [[] for _ in range(9)]
alp = ['a','b','c','d','e','f','g','h','i','j']
for i in range(n-1):
    for j in ans[i]:
        x = len(set(j))
        for k in range(x+1):
            ans[i+1].append(j+[alp[k]])
for i in ans[n-1]:
    print("".join(i))

Measured memory_bytes: 27460
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int A, B;
      cin >> A >> B;
      cout << max(0,A-2*B) << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
  int res=0;
    vector<int> l(n);
  rep(i,0,n)cin>>l[i];
  sort(l.begin(),l.end());
  rep(i,0,n)rep(j,i+1,n){
    int c=l[i]+l[j];
    int k=lower_bound(l.begin(),l.end(),c)-l.begin();
    res+=max(k-(j+1),0);
  }
  cout<<res;
}

Measured memory_bytes: 384
#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--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;

    rep(j, k){
        char c = 'x';
        for(int i = j; i < n; i += k){
            if (i == j){
                if (t[i] == 'r') c = 'p', ans += p;
                else if (t[i] == 'p') c = 's', ans += s;
                else if (t[i] == 's') c = 'r', ans += r;
            }
            else{
                if (t[i] == 'r' && c == 'p') { //勝ちの手が出せない時
                    if (i+k < n && t[i+k] == 'r') c = 's';
                    else if (i+k < n && t[i+k] == 'p') c = 'r';
                    else if (i+k < n && t[i+k] == 's') c = 's';
                }
                else if (t[i] == 'r') c = 'p', ans += p;
                
                if (t[i] == 'p' && c == 's') { //勝ちの手が出せない時
                    if (i+k < n && t[i+k] == 'r') c = 'r';
                    else if (i+k < n && t[i+k] == 'p') c = 'r';
                    else if (i+k < n && t[i+k] == 's') c = 'p';
                }
                else if (t[i] == 'p') c = 's', ans += s;
                
                if (t[i] == 's' && c == 'r') { //勝ちの手が出せない時
                    if (i+k < n && t[i+k] == 'r') c = 's';
                    else if (i+k < n && t[i+k] == 'p') c = 'p';
                    else if (i+k < n && t[i+k] == 's') c = 'p';
                }
                else if (t[i] == 's') c = 'r', ans += r;
            }
        }
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3772
use std::io::*;
use std::str::FromStr;

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

fn div(mut num: i64) -> i64 {
    let mut cnt = 0;
    while num % 2 == 0 {
        cnt += 1;
        num /= 2;
    }
    return cnt;
}

fn main() {
    let N: i64 = read();
    let mut minN = 999999999;

    for i in 0..N {
        let d = div(read());
        minN = if d < minN { d } else { minN };
    }

    println!("{}", minN);
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int MAXN = 2*1e5+10;
ll n, pos;
ll c[MAXN];
vector<ll> colors[MAXN];
ll dp[MAXN];
ll colordp[MAXN];

void solve() {
  dp[0] = 1;
  for (int i=0;i<pos;i++) {
    dp[i+1] = dp[i];
    if (colordp[c[i]] == 0) {
      colordp[c[i]] = dp[i];
    } else {
      dp[i+1] = (dp[i+1] + colordp[c[i]]) % MOD;
      colordp[c[i]] = (colordp[c[i]] + dp[i]) % MOD;
    }
  }
  cout << dp[pos] << endl;
}

int main() {
  cin >> n;
  int prev = -1;
  int tmp;
  for (int i=0;i<n;i++) {
    cin >> tmp;
    if (prev != tmp) {
      c[pos++] = tmp;
      prev = tmp;
    }
  }
  solve();
}


Measured memory_bytes: 9600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] L = new int[N];
		int sum=0;
		
		for(int i=0;i<N;i++) {
			L[i]=sc.nextInt();
		}
		
		Arrays.sort(L);
		
		for(int i=0;i<N-1;i++) {
			sum+=L[i];
		}
		
		if(L[N-1]<sum) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
		sc.close();
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int x;
    cin>>x;
    if(x==1){
        cout<<1<<endl;return 0;
    }
    int expo[x+1]={};
    for(int i=2;i<=x;i++)
    {
        for(int j=i*i;j<=x;j=j*i)
        expo[j]=1;
    }
    int ans=x;
    while(expo[ans]==0)
    ans--;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int d; cin >> d;
    vector<int> clis(26);
    vector<vector<int>> slis(d, vector<int>(26));
    vector<int> anslis(d);
    REP(i, 0, 26){cin >> clis[i];}
    REP(i, 0, d){
        int idx = 0, max = -1;
        REP(l, 0, 26){
            cin >> slis[i][l];
            if(chmax(max, slis[i][l])){
                idx = l;
            }
        }
        anslis[i] = idx;
    }
    vector<int> last(26, 0);
    int anspre = 0;
    REP(i, 0, d){
        last[anslis[i]] = i+1;
        anspre += slis[i][anslis[i]];
        int minus = 0;
        REP(l, 0, 26){
            minus += clis[l] * ((i+1) - last[l]);
        }
        anspre -= minus;
        //cout << anspre << endl;
    }
    REP(i, 0, 1e3){
        int from = rand() % 26;
        int to = rand() % 26;
        if(from == to){continue;}
        int old = anslis[from];
        anslis[from] = to;
        int anspre1 = 0;
        //スコア計算
        REP(l, 0, d){
            last[anslis[l]] = l+1;
            anspre1 += slis[l][anslis[l]];
            int minus = 0;
            REP(j, 0, 26){
                minus += clis[j] * ((l+1) - last[j]);
            }
            anspre1 -= minus;
        }
        //cout << anspre1 << endl;
        if(anspre > anspre1){
            anslis[from] = old;
        }else{
            anspre = anspre1;
        }
    }
    REP(i, 0, d){
        cout << (anslis[i] + 1) % d << endl;
    }
    //cout << anspre << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N;
  cin >> N;
  if(N == 1) {
    cout << 0 << endl;;
    return 0;
  }
  cout << N * (N - 1) / 2 << endl;
}


Measured memory_bytes: 256
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 998244353;
ll arr[200010];
ll find(ll u)
{
	while (arr[u] > 0)
	{
		u = arr[u];
	}
	return u;
}
void solve()
{
	IN(n)IN(q);
	memset(arr, -1, sizeof(arr));
	while (q--)
	{
		IN(t)IN(u)IN(v);
		if (t == 0)
		{
			if (find(u) != find(v))
			{
				arr[find(u)] = find(v);
			}
		}
		else
		{
			if (find(u) != find(v))
			{
				cout << 0 << endl;
			}
			else
			{
				cout << 1 << endl;
			}
		}
	}
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

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

using namespace std;

int a[105][105];
int f[105][105];
int n,m;

int main()
{
    //freopen("file.inp","r",stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
    {
        char c;
        cin >> c;
        a[i][j] = (c == '#');
    }
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
    {
        f[i][j] = 1e9;
        if (i + j == 2)
        {
            f[i][j] = a[i][j];
        }
        if (i > 1) f[i][j] = min(f[i][j], f[i - 1][j] + (a[i][j] == 1 && a[i - 1][j] == 0));
        if (j > 1) f[i][j] = min(f[i][j], f[i][j - 1] + (a[i][j] == 1 && a[i][j - 1] == 0));
    }
    cout << f[n][m];
    return 0;
}


Measured memory_bytes: 384
def main():
    n, m = list(map(int, input().split()))
    dcon = [set() for _ in range(n)]
    for _ in range(m):
        s, c = tuple(map(int, input().split()))
        dcon[s-1].add(c)

    if any(len(d) > 1 for d in dcon):
        print(-1)
        return
    
    digits = [0] if n == 1 else [1] + [0] * (n-1)
    for i in range(n):
        if dcon[i]:
            digits[i] = dcon[i].pop()

    if digits[0] == 0 and n != 1:
        print(-1)

    else:
        print(''.join(map(str, digits)))

main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, y;
	cin >> n >> y;

	int i, j, k, sum;
	for (i = 0; i <= y / 10000; i++) {
		for (j = 0; j <= y / 5000; j++) {
			k = (y - i * 10000 - j * 5000) / 1000;
			sum = i + j + k;
			if (sum == n && k >= 0) break;
		}
		if (sum == n && k >= 0) break;
	}

	if (sum == n && k >= 0) cout << i << " " << j << " " << k << endl;
	else cout << -1 << " " << -1 << " " << -1 << endl;

 	return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()


int main() {

    int A, B, C;
    cin >> A >> B >> C;

    for(int mul = 1; mul < B; mul ++){
        if(A * mul % B == C){
            cout << "YES" << endl;
            return 0;
        }
    }    
    cout << "NO" << endl;
    
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
B = np.fromstring(input(), dtype=np.int64, sep=' ')
A = np.zeros(N, dtype=np.int64)
A[:-1] = B
A[-1] = 100000
for i in range(1, N):
    A[i] = min(A[i], B[i - 1])
print(A.sum())


Measured memory_bytes: 21148
#include<iostream>
#include<cstdio>
using namespace std;
void output(int n){
    int m=3600;
    bool f=false;
    for(int i=0;i<3;i++){
        if(f)cout<<":";
        printf("%.2d",n/m);
        n%=m;
        m/=60;
        f=true;
    }
}
int main(){
    int t,m,s;
    while(cin>>t>>m>>s,t!=-1){
        int sum=2*3600-t*3600-m*60-s,sum3;
        sum3=sum*3;
        output(sum);
        cout<<endl;
        output(sum3);
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1196
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if s.is_empty() {
        None
    } else {
        s.parse::<T>().ok()
    }
}

fn main(){
    while let Some(n) = read() {
        let s1: Vec<_> = read::<String>().unwrap().chars().collect();
        let s2: Vec<_> = read::<String>().unwrap().chars().collect();

        const MOD: u64 = 1000000007;
        let mut ans = 1;
        let mut i = 0;
        while i < n {
            if s1[i] == s2[i] {
                let m = if i == 0 {
                    3
                } else if s1[i-1] == s2[i-1] {
                    2
                } else {
                    1
                };
                ans *= m;
                i += 1;
            } else {
                let m = if i == 0 {
                    6
                } else if s1[i-1] == s2[i-1] {
                    2
                } else {
                    3
                };
                ans *= m;
                i += 2;
            }
            ans %= MOD;
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#!/usr/bin/env python3

import itertools

while True:
    count = 0
    n, x = map(int, input().split())
    # print(n, x)
    if n == 0 and x == 0:
        break
    l = range(1, n+1)
    combs = itertools.combinations(l, 3)
    count = 0
    for c in combs:
        if sum(c) == x:
            count += 1
    print(count)




Measured memory_bytes: 5632
n = int(input())
a = list(map(int,input().split()))
maxketa = max([len(bin(a[i])) for i in range(n)])-2
mod = 10**9+7
ans = 0
for i in range(maxketa):
	ones = 0
	for j in range(n):
		if (a[j] >> i) & 1:
			ones += 1
	ans = (ans + (n-ones)*ones*(2**i)) % mod
 
print(ans)

Measured memory_bytes: 122808
#include<bits/stdc++.h>
using namespace std;
int main(){
  double L,R;
  int numL[4]={0},numR[4]={0};
  int cnt=0;
  while(cin>> L>> R){
    cnt++;
    if(L<0.2) numL[3]++;
    else if(L<0.6) numL[2]++;
    else if(L<1.1) numL[1]++;
    else numL[0]++;

    if(R<0.2) numR[3]++;
    else if(R<0.6) numR[2]++;
    else if(R<1.1) numR[1]++;
    else numR[0]++;
  }

  for(int i=0;i<4;i++){
    cout<< numL[i]<< " "<< numR[i]<< endl;
  }
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    n+=2;
    int a[n],dp[n];
    memset(a,0,sizeof(a));
    r(i,n-2)cin>>a[i+1];
    r(i,n){
        r(j,n)if(j){
            r(k,n)dp[k]=1e9;
            dp[0]=0;
            r(k,n){
                if(dp[k]!=1e9)for(int l=1;l<=j;l++){
                    if(k+l<n&&a[k+l]==0)dp[k+l]=min(dp[k+l],dp[k]+1);
                }
            }
            if(dp[n-1]!=1e9){
                cout<<j<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3076
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <iostream>
#include <vector>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
typedef long long ll;
mint pw1[200010],pw2[200010];
struct S{mint a; int len;};
struct F{ll x;};
S op(S l,S r){return S{(l.a *pw1[r.len]+ r.a),l.len + r.len};}
S e(){return S{0,0};}
S mapping(F l,S r){
    if(l.x==-1) return r;
    return S{l.x*pw2[r.len - 1],r.len};
}
F composition(F l,F r){
    if(l.x==-1) return r;
    return l;
}
F id(){return F{-1};};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,n,q; cin >> n >> q;
    pw1[0] = 1; pw2[0] = 1;
    for(i=1;i<=n;i++) pw1[i] = pw1[i - 1]*10,pw2[i] = pw2[i - 1]*10 + 1;
    vector<S> v(n,{1,1});
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(v);
    for(i=0;i<q;i++){
        int l,r,d; cin >> l >> r >> d; l--;
        seg.apply(l,r,F{d});
        cout << seg.prod(0,n).a.val() << "\n";
    }
}

Measured memory_bytes: 12440
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

bool memo[80][80][160*80+1] = {};

void dfs(int i, int j, int c, VVI &a, VVI &b, int &h, int &w) {
    if (i >= h || j >= w) return;
    if (memo[i][j][c+(a[i][j]-b[i][j])] == false) {
        dfs(i+1,j,c+(a[i][j]-b[i][j]),a,b,h,w);
        dfs(i,j+1,c+(a[i][j]-b[i][j]),a,b,h,w);
        memo[i][j][c+(a[i][j]-b[i][j])] = true;
    }
    if (memo[i][j][c-(a[i][j]-b[i][j])] == false) {
        dfs(i+1,j,c-(a[i][j]-b[i][j]),a,b,h,w);
        dfs(i,j+1,c-(a[i][j]-b[i][j]),a,b,h,w);
        memo[i][j][c-(a[i][j]-b[i][j])] = true;
    }
}

void solve() {
    int h,w;
    cin >> h >> w;
    VVI a(h,VI(w)), b(h,VI(w));
    REP(i,0,h) REP(j,0,w) cin >> a[i][j];
    REP(i,0,h) REP(j,0,w) cin >> b[i][j];
    dfs(0,0,0,a,b,h,w);
    int ans = (h+w) * 80;
    REP(i,0,(h+w) * 80+1) if (memo[h-1][w-1][i]) ans = min(ans,i);
    REP(i,0,(h+w) * 80+1) if (memo[h-1][w-1][-i]) ans = min(ans,i);
    cout << ans << endl;
}

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

Measured memory_bytes: 79872
#include<bits/stdc++.h>
using namespace std;
int n,k;
int dizi[100007];
long long int dp[100007];
int main()
{
	
	cin >> n >> k;
	for(int i=1;i<100007;i++)
		dp[i]=INT_MAX;
	for(int i=0;i<n;i++)
		cin >> dizi[i];
	for(int i=0;i<n;i++)
	{
		for(int ka=i+1;ka<=min(i+k,n);ka++)
		{
			dp[ka]=min(dp[ka],dp[i]+abs(dizi[i]-dizi[ka]));
		}
	}
	cout << dp[n-1];
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> p(12);
  vector<long long> po(12);
  long long a = 1;
  long long sum = 0;
  int indexnum = 0;
  n--;
  for (int i = 0; i < 12; i++) {
    p[i] = sum + a - 1;
    po[i] = a;
    sum += a;
    a *= 26;
    if (p[i] > n) {
      indexnum = i;
      break;
    }
    // cout << i << ' ' << p[i] << endl;
  }
  int index = indexnum;
  long long num = n - p[index-1];
  vector<int> ans_num(index);
  for (int i = indexnum-1; i >= 0; i--) {
    ans_num[i] = num/po[i];
    num = num % po[i];
  }
  for (int i = indexnum-1; i >= 0; i--) {
    cout << char('a' + ans_num[i]);
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3652
#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 size_t gcdZu(size_t m, size_t n) {
    size_t temp;

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

    return n;
}

static size_t A[100000];
static size_t gcdSum[2][100000];

int main(void) {
    size_t N;

    scanf("%zu\n", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%zu", &(A[i]));
        if (i < N - 1) {
            scanf(" ");
        }
    }

    size_t head = A[0];
    size_t tail = A[N - 1];

    gcdSum[0][0] = head;
    gcdSum[1][N - 1] = tail;

    for (size_t i = 1; i < N; i++) {
        head = gcdZu(head, A[i]);
        tail = gcdZu(tail, A[N - i - 1]);

        gcdSum[0][i] = head;
        gcdSum[1][N - i - 1] = tail;
    }

    size_t max = 0;

    for (size_t i = 0; i < N; i++) {
        size_t commonDivisor;

        if (i == 0) {
            commonDivisor = gcdSum[1][1];
        }
        else if (i == N - 1) {
            commonDivisor = gcdSum[0][N - 2];
        }
        else {
            commonDivisor = gcdZu(gcdSum[0][i - 1], gcdSum[1][i + 1]);
        }

        if (max < commonDivisor) {
            max = commonDivisor;
        }
    }

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

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define maxn 310000
using namespace std;
typedef pair<int,int>par;
int mx[maxn<<2],atg[maxn<<2];
int lx[maxn],ly[maxn],n,w,h;
int ax[maxn],ay[maxn],tpx,tpy,ans;
vector<int>G[maxn];
par s1[maxn],s2[maxn];
int tp1,tp2;
void mdy(int o,int l,int r,int ql,int qr,int tg){
	if(ql>qr)return ;
	if(ql<=l&&r<=qr){atg[o]+=tg,mx[o]+=tg;return ;}
	int mid=l+r>>1;
	if(ql<=mid)mdy(o<<1,l,mid,ql,qr,tg);
	if(qr>mid)mdy(o<<1|1,mid+1,r,ql,qr,tg);
	mx[o]=max(mx[o<<1],mx[o<<1|1])+atg[o];
}
void build(int o,int l,int r){
	mx[o]=-lx[l],atg[o]=0;
	if(l==r)return ;
	int mid=l+r>>1;
	build(o<<1,l,mid);
	build(o<<1|1,mid+1,r);
}
void solve(){
	for(int i=1;i<=tpx;++i)G[i].clear();
	for(int i=1;i<=n;++i)G[ax[i]].push_back(ly[ay[i]]);
	build(1,1,tpx),tp1=tp2=0;
	for(int i=1;i<tpx;++i){
		for(auto p:G[i])
			if(p<=h/2){
				int lst=i-1;
				while(tp1&&s1[tp1].first<=p){
					int pre=tp1>1?s1[tp1-1].second:1;
					mdy(1,1,tpx,pre,lst,s1[tp1].first-p);
					lst=pre-1,tp1--;
				}
				s1[++tp1]=par(p,i);
			} else {
				int lst=i-1;
				while(tp2&&s2[tp2].first>=p){
					int pre=tp2>1?s2[tp2-1].second:1;
					mdy(1,1,tpx,pre,lst,p-s2[tp2].first);
					lst=pre-1,tp2--;
				}
				s2[++tp2]=par(p,i);
			}
		s1[++tp1]=par(0,i);
		s2[++tp2]=par(h,i);
		mdy(1,1,tpx,i,i,h);
		ans=max(mx[1]+lx[i+1],ans);
	}
}
int main(){
	scanf("%d%d%d",&w,&h,&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&ax[i],&ay[i]),
		lx[++tpx]=ax[i],ly[++tpy]=ay[i];
	lx[++tpx]=0,lx[++tpx]=w;
	lx[++tpy]=0,ly[++tpy]=h;
	sort(lx+1,lx+tpx+1),tpx=unique(lx+1,lx+tpx+1)-lx-1;
	sort(ly+1,ly+tpy+1),tpy=unique(ly+1,ly+tpy+1)-ly-1;
	for(int i=1;i<=n;++i)
		ax[i]=lower_bound(lx+1,lx+tpx+1,ax[i])-lx,
		ay[i]=lower_bound(ly+1,ly+tpy+1,ay[i])-ly;
	solve();
	for(int i=1;i<=n;++i)swap(ax[i],ay[i]);
	swap(lx,ly),swap(tpx,tpy),swap(w,h),solve();
	printf("%d",ans*2);
//	fprintf(stderr,"[used time:%.7lf s]\n",clock()/(double)CLOCKS_PER_SEC);
}

Measured memory_bytes: 35200
#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin >> n, n)
    {
        int w[n] = {0};
        for (int i = 0; i < n; i++)
        {
            string s;
            cin >> s;
            w[i] = s.size();
        }
        bool clear = false;
        int ans = 0;
        for (int i = 0; i < n && !clear; i++)
        {
            int phrase = 0;
            int tmp = 0;
            for (int j = i; j < n; j++)
            {
                tmp += w[j];
                if (phrase == 0 || phrase == 2)
                {
                    if (tmp == 5)
                    {
                        phrase++;
                        tmp = 0;
                    }
                    else if (tmp > 5)
                    {
                        break;
                    }
                }
                else
                {
                    if (tmp == 7)
                    {
                        if (phrase == 4)
                        {
                            clear = true;
                            ans = i + 1;
                            break;
                        }
                        else
                        {
                            phrase++;
                            tmp = 0;
                        }
                    }
                    else if (tmp > 7)
                    {
                        break;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3148
#include <iostream>
#include <cmath>
#include <iomanip>

const double PI = 3.1415926535897932384626;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);

  double A, B, H, M;  std::cin >> A >> B >> H >> M;
  double ma = M*6;
  double ha = H*30 + ma/12;

  double xa = A*std::cos(ma*PI / 180.0);
  double ya = A*std::sin(ma*PI / 180.0);
  double xb = B*std::cos(ha*PI / 180.0);
  double yb = B*std::sin(ha*PI / 180.0);

  double dx = xa - xb;
  double dy = ya - yb;
  std::cout << std::setprecision(10) << std::fixed << std::sqrt(dx*dx + dy*dy) << "\n";

  return 0;
}


Measured memory_bytes: 4124
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;

    for(int i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }

    L[n1] = R[n2] = SENTINEL;
    
    int i = 0, j = 0;

    for(int k = left; k < right; k++){
        cnt++;
        if(L[i] <= R[j]){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main(){
    int A[MAX], n, i;
    cnt = 0;

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

    mergeSort(A, n, 0, n);

    for(i = 0; i < n; i++){
        if(i != 0){
            cout << " ";
        }
        cout << A[i];
    }

    cout << endl;
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 7016
import bisect
n = int(input())
l = list(map(int, input().split()))
count = 0
l = sorted(l)

for i in range(n-2):
  for j in range(i+1, n-1):
    k = bisect.bisect_left(l, l[i]+l[j])
    count += k -j - 1
print(count)

Measured memory_bytes: 3188
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let pi: Vec<usize> = (0..n).map(|_| read()).collect();

    let mut _min = pi[0];
    let mut cnt = 1;

    for i in 1..n {
        if pi[i] <= _min {
            cnt += 1;
            _min = pi[i];
        }
    }

    println!("{}", cnt);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PRINT(x,y) cout<<"Case #"<<(int)x<<": "<<(int)(y)<<endl;
		ll exp(ll x, ll y) {
			if(y==0) return 1;
			if(y==1) return x;
			if(y%2==0) return exp(x,y/2)*exp(x,y/2);
			else return x*exp(x,y/2)*exp(x,y/2);
		}
		ll gcd(ll a , ll b) {
			if(b==0) return a;
			return gcd(b , a%b);
		}
		ll lcm(ll a , ll b) {
			return (a*b)/gcd(a,b);
		}
		#define vec(n) vector<int> v((int)(n),0);
		#define vecl(n) vector<ll> v((ll)(n),0);
		#define sq(a) ((int)(a))*((int)(a));
		#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
		int l;
		ll fact(ll x) {
			if(x==1) return 1;
			else return x*fact(x-1);
		}
		bool isPrime(int x) {
			int ans  = 0;
			for(int i=2;i<=sqrt(x);++i) {
				if(x%i==0) {
					ans = 1; i=x;
				}  
			}
			if(ans==0) return true;
			else return false;
		}
		ll isPerfect(ll x) {
			double y = sqrt(x);
			return (floor(y)==ceil(y));
		} 

		int z = 0;
		void ask(int x, int y) {
			cout<<"? "<<x<<" "<<y<<endl;
			}

		void solve() {
			int n; cin>>n;
			vector<ll> v(n);
			for(int i=0;i<n;++i) cin>>v[i];
			ll suff[n+1] = {0};
		reverse(v.begin() , v.end());
			for(int i=n-1;i>=0;i--) {
				suff[i] = max(suff[i+1] , v[i]);
			}
			ll sum = 0;
			for(int i=0;i<n;++i) {
				if(v[i]<suff[i+1]) sum+=abs(v[i]-suff[i+1]);
			}
			cout<<sum;

		}			



		int main() {
			io
			
			 solve();
		}
		    
		

Measured memory_bytes: 6348
#include<stdio.h>
int main () {
    int w,h;
    int i,j,k;
    for (i=0;i<1000;i++) {
        scanf("%d %d",&w,&h);
        if (w==0 && h==0)
            break;
        for (j=0;j<w;j++) {
            for (k=0;k<h;k++) {
                if(k==0 || k==h-1 || j==0 || j==w-1) {
                    printf("#");
                } else 
                    printf (".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
} 


Measured memory_bytes: 2064
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
vector<Pll>v;
map<Pll, Pll>ma;
set<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	for (int j = 0; j < 30; j++)
		rep(i, n) {
		if (b[i] - a[i] > 0) {
			cnt = (b[i] - a[i]) / (b[(i - 1 + n) % n] + b[(i + 1) % n]);
		}
		else cnt = 0;
		b[i] -= (b[(i - 1 + n) % n] + b[(i + 1) % n])*cnt;
		ans += cnt;

	}
	rep(i, n) {
		if (a[i] != b[i])f = 1;
	}
	if (f)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

const ll mod = 1000000007;
const ll contest = 26;

int main(){
    ll d, csum = 0; cin >> d;
    vector<ll> c(contest);
    vector<vector<ll>> s(d, vector<ll>(contest));
    rep(i, contest){
        cin >> c[i];
        csum += c[i];
    }
    rep(i, d) rep(j, contest) cin >> s[i][j];
    vector<ll> last(contest, 0);
    vector<ll> result(d, 0);
    ll sum = 0;
    rep(i, d){
        ll maxx = 0, tt = 1, score = 0;
        rep(t, contest){
            score = sum + s[i][t];
            rep(j, contest){
                if(t == j) continue;
                score -= c[j]*((i+1)-last[j]);
            }
            if(score > maxx){
                tt = t;
                maxx = score;
            }
        }
        last[tt] = i+1;
        result[i] = tt;
        sum += maxx % mod;
        //cout << tt+1 << endl;
    }

    fill(last.begin(), last.end(), 0);
    sum = 0;
    rep(i, d){
        sum += s[i][result[i]];
        last[result[i]] = i+1;
        rep(j, contest){
            if(result[i] == j) continue;
            sum -= c[j]*((i+1)-last[j]);
        }
    }
    
    rep(a, d){
        rep(b, 10){
            random_device rd;
            mt19937 mt(rd());
            ll tt = a, cc = mt()%contest;
            double p = mt()%1000000/999999.0;
            ll bak = result[tt];
            result[tt] = cc;

            fill(last.begin(), last.end(), 0);
            ll old = sum;
            sum = 0;
            rep(i, d){
                sum += s[i][result[i]];
                last[result[i]] = i+1;
                rep(j, contest){
                    if(result[i] == j) continue;
                    sum -= c[j]*((i+1)-last[j]);
                }
            }
            if(sum < old && p > 0.01){
                result[tt] = bak;
                sum = old;
            }
        }
    }
    for(auto i : result){
        cout << i+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3728
//https://atcoder.jp/contests/abc161/tasks/abc161_a
//A - ABC Swap
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 main() {
  ll X,Y,Z; cin>>X>>Y>>Z;
  swap(X,Y);
  swap(X,Z);
  cout<<X<<" "<<Y<<" "<<Z<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int X;

	cin >> X;

	int a1 = X / 500;
	int a2 = (X % 500) / 5;

	cout << a1 * 1000 + a2 * 5 << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools


N, M = map(int, input().split())
graph = [[False]*N for _ in range(N)]

for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    graph[a][b] = True
    graph[b][a] = True

ans = 0
for x in itertools.permutations(range(1, N)):
    # このxの順番で訪問できるか確かめる
    flag = True
    now = 0
    for e in x:
        if not graph[now][e]:
            flag = False
        now = e
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include <bits/stdtr1c++.h>
// typedef __int128 int128;
// typedef __float128 float128;

using namespace std;
using namespace rel_ops;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
#define pb push_back

int main(){

  // freopen("A.in", "r", stdin);

  ll N, A, B;
  cin >> N >> A >> B;

  if(N * A  < B){
    cout << N * A;
  }
  else cout << B;
}


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

typedef vector<vector<int> > VII;
typedef pair<int, int> PII;

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

void bfs (int i, int j, VII &table) {
    queue<PII> que;
    que.push(make_pair(i, j));
    table[i][j] = 0;
    while (1) {
        if (que.empty() == 1) {
            break; 
        }
        int now_y = que.front().first;
        int now_x = que.front().second;
        que.pop();

        for (int k = 0; k < 8; k++) {
            if (table[now_y + dy[k]][now_x + dx[k]] == 1) {
                que.push(make_pair(now_y + dy[k], now_x + dx[k]));
                    table[now_y + dy[k]][now_x + dx[k]] = 0;
            }
        }
    }
    return;
}

int main(void) {
    int w;
    int h;
    while (cin >> w >> h) {
        if (w == 0 && h == 0) {
            break;
        }
        VII table(h + 2, vector<int>(w + 2, 0));
        for (int i = 1; i < h + 1; i++) {
            for (int j = 1; j < w + 1; j++) {
                cin >> table[i][j];
            }
        }
        int number = 0;
        for (int i = 1; i < h + 1; i++) {
            for (int j = 1; j < w + 1; j++) {
                if (table[i][j] == 1) {
                    bfs(i, j, table);
                    number++;
                }
            }
        }
        cout << number << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int cnt=0;
	int m=max(max(a,b),c);
	while(m-a>1){cnt++;a+=2;}
	while(m-b>1){cnt++;b+=2;}
	while(m-c>1){cnt++;c+=2;}
	if(a==b&&b==c){
	}else if(b==c){
		if(a>b)cnt++;
		else cnt+=2;
	}else if(a==b){
		if(c>a)cnt++;
		else cnt+=2;
	}else{
		if(b>a)cnt++;
		else cnt+=2;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll ans=0;
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		ll now=i;
		ll cnt=0;
		while(now!=0){
			cnt++;
			now/=10;
		}
		if(cnt%2){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256