akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class SCC {
public:
    explicit SCC(const vector<vector<int>>& g) : idx(g.size(), -1) {
        const int N = g.size();
        vector<int> order, visit(N, 0);
        for(int i=0;i<N;i++){
            if(!visit[i]) dfs(i, g, order, visit);
        }
        reverse(order.begin(), order.end());
        vector<vector<int>> h(g.size());
        for(int i=0;i<g.size();i++){
            for(auto& t : g[i]) h[t].push_back(i);
        }
        int s = 0;
        for(auto& t : order){
            if(idx[t] != -1) continue;
            compS.push_back(vector<int>());
            dfs2(t, h, s);
            ++s;
        }
        compG.assign(s, vector<int>());
        for(int i=0;i<N;i++){
            for(auto& t : g[i]){
                if(idx[i] != idx[t]) compG[idx[i]].push_back(idx[t]);
            }
        }
    }
    const auto& getGraph() const { return compG; }
    int getCompNum() const { return compG.size(); }
    int getId(int v) const { return idx[v]; }
    const auto& getConnectSet(int id) const { return compS[id]; }
private:
    void dfs(int pos, const vector<vector<int>>& g, vector<int>& order, vector<int>& visit){
        visit[pos] = 1;
        for(auto& t : g[pos]){
            if(visit[t]) continue;
            dfs(t, g, order, visit);
        }
        order.push_back(pos);
    }
    void dfs2(int pos, const vector<vector<int>>& g, int id){
        idx[pos] = id;
        compS[id].push_back(pos);
        for(auto& t : g[pos]){
            if(idx[t] != -1) continue;
            dfs2(t, g, id);
        }
    }
private:
    vector<vector<int>> compG;
    vector<int> idx;
    vector<vector<int>> compS;
};

int main(){
    int V, E; cin >> V >> E;
    vector<vector<int>> g(V);
    for(int i=0;i<E;i++){
        int u, v; cin >> u >> v;
        g[u].push_back(v);
    }
    SCC scc(g);
    int Q; cin >> Q;
    for(int i=0;i<Q;i++){
        int u, v; cin >> u >> v;
        cout << (scc.getId(u) == scc.getId(v) ? 1 : 0) << endl;
    }
}


Measured memory_bytes: 4400
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

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

    LL result = 0;

    for(int i = 0; i < n; i++){
        LL j = a[i]/2;
        result += j;
        a[i] -= j*2;
        if(i < n-1 && a[i] != 0 && a[i+1] != 0){
            a[i]--;
            a[i+1]--;
            result++;
        }
    }

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

Measured memory_bytes: 1024
let ans, a_s = ref 0, Array.init (read_int ()) @@ fun _ -> Scanf.scanf " %d" (+) 0
let f (p, c) a = a, if a <> p then (ans := !ans + if p > c then c else c - p; 1) else c + 1
let _ = Array.(sort (-) a_s; f (fold_left f (a_s.(0), 0) a_s) 0) |> ignore; Printf.printf "%d\n" !ans

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
void solve(){

	int n = 5 ;
  
  int ans = 0 ;
  for(int i = 1 ; i <= n; i++){
    int x ; cin >> x;
    if(x == 0){
      ans = i;
    }
  }
  cout << ans << endl ;
}
int main(){

	solve();
	return 0 ;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
*/

int main(){
cout<<fixed<<setprecision(10);


  int H,W;cin>>H>>W;
char vec[55][55];
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}
  int counter=0;
  bool paint=true;
  for(int i=1;i<H;i++){
for(int j=1;j<W;j++){
  if(vec[i][j]=='#'&&vec[i+1][j]!='#'&& vec[i-1][j]!='#'&& vec[i][j+1]!='#'&& vec[i][j-1]!='#'){
    // paint=false;break;
     counter++;
   }
  
}
 //   if(paint==false)break;
  }
  
  if(counter==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w, k) = (v[0], v[1], v[2]);
    let mut items = HashMap::new();
    for i in 0..k {
        let v = read_vec::<i64>();
        let (r, c, k) = (v[0] as usize - 1, v[1] as usize - 1, v[2]);
        items.insert((r, c), k);
    }
    let mut dp = vec![0; w];
    for y in 0..h {
        let mut next = vec![0; w];
        let mut from_left = vec![0; 4];
        for x in 0..w {
            from_left[0] = max(from_left[0], dp[x]);
            if items.contains_key(&(y, x)) {
                from_left[3] = max(from_left[2] + items[&(y, x)], from_left[3]);
                from_left[2] = max(from_left[1] + items[&(y, x)], from_left[2]);
                from_left[1] = max(from_left[0] + items[&(y, x)], from_left[1]);
            }
            next[x] = *from_left.iter().max().unwrap();
        }
        dp = next;
    }
    println!("{}", dp[w - 1]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 11788
import collections
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

K = int(input())


def ans():
    visited = [False] * K

    s = (1, 1)

    q = collections.deque()
    q.append(s)

    while True:
        c = q.popleft()
        visited[c[0]] = True

        if c[0] == 0:
            return c[1]

        if not visited[(c[0] * 10) % K] and not visited[(c[0] * 10) % K]:
            q.appendleft(((c[0] * 10) % K, c[1]))

        if not visited[(c[0] + 1) % K] and not visited[(c[0] + 1) % K]:
            q.append(((c[0] + 1) % K, c[1] + 1))


print(ans())



Measured memory_bytes: 16912
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
int main() {
	string s; cin >> s; bool f = false;
	while (s.length()>=3) {
		if (s == "ABC") {
			f = true; break;
		}
		int len = s.length();
		string memo;
		bool a[3]; fill(a, a + 3, false);
		rep(i, len) {
			if (i + 2 < len&&s.substr(i, 3) == "ABC") {
				i += 2;
			}
			else {
				a[s[i] - 'A'] = true;
			}
		}
		char chk;
		if (!a[0] && a[1] && a[2])chk = 'A';
		else if (a[0] && !a[1] && a[2])chk = 'B';
		else if (a[0] && a[1] && !a[2])chk = 'C';
		else {
			break;
		}
		rep(i, len) {
			if (i + 2 < len&&s.substr(i,3)=="ABC") {
				i += 2; memo += chk;
			}
			else {
				memo += s[i];
			}
		}
		s = memo;
	}
	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;
    cin >> n;
    vector<ll> l(n);
    for (ll i = 0; i < n; i++) cin >> l[i];
    ll ans = 0;
    sort(l.begin(), l.end());
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n;j++){
            for (ll k = j + 1; k < n;k++){
                if (l[i] != l[j] and l[i] != l[k] and l[j] != l[k] and l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
d1, d2 = list(map(int, input().split())), list(map(int, input().split()))

if tuple(sorted(d1)) != tuple(sorted(d2)):
    print('No')
    exit()

d1dict = {v: k for k, v in enumerate(d1)}
dms = ((1, 2, 4, 3), (0, 3, 5, 2), (0, 1, 5, 4), (0, 4, 5, 1), (0, 2, 5, 3), (1, 3, 4, 2))

d20 = d1dict[d2[0]]
dm = dms[d20]
try:
    dmi = dm.index(d1dict[d2[1]])
    print('Yes' if d2[2] == d1[dm[(dmi + 1) % 4]]
                   and d2[3] == d1[dm[(dmi + 3) % 4]]
                   and d2[4] == d1[dm[(dmi + 2) % 4]]
                   and d2[5] == d1[5 - d20] else 'No')
except:
    print('No')
    exit()

Measured memory_bytes: 7808
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-6
using namespace std;
typedef long long ll;
const int mods = 998244353;
const int maxn = 2e5+10;

ll n;

inline long long read() {
    long long tmp=0, fh=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
    while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
    return tmp*fh;
}
ll dep,a,b,thr;

ll qpow(ll n,ll b){
	if(b<0) return 0;
	ll res =1;
	while(b){
		if(b&1) res=res*n;
		n=n*n;
		b>>=1;
	}
	return res;
} 

int main() {
	cin>>n;
	thr = floor(log10(n));
	if(thr==0){
		cout<<n<<endl;
		return 0;
	}
	ll ans = 0;
	ll x = n/qpow(10,thr);
	ll y = n%10;
	ll k = n-x*qpow(10,thr);
	k/=10;
	F(i,1,n){
		dep = floor(log10(i));
		a=i/(qpow(10,dep));
		b=i%10;
		if(b==0) continue;
		if(a==b) ans++;
		ans+=(qpow(10,thr-1)-1)/9;
		if(b<x){
			ans+=qpow(10,thr-1);
		}
		else if(b>x){
			continue;
		}
		else{
			ans+=k;
			if(a<=y) ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Text;

namespace ALDS1_2_C {
    struct Card {
        public char suit;
        public int num;

        public Card(char suit,int num) {
            this.suit = suit;
            this.num = num;
        }

        public override string ToString() {
            return string.Format("{0}{1}", suit, num);
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            Card[] A = Console.ReadLine().Split(' ')
                .Select(c => new Card(c[0], int.Parse(c[1].ToString())))
                .ToArray();
            Card[] B = (Card[])A.Clone();
            Card[] stable = A.OrderBy(c => c.num).ToArray();

            // BubbleSort
            for (int i = 0; i < n; i++) {
                for (int j = n - 1; j > i; j--) {
                    if (A[j].num < A[j - 1].num) {
                        Card temp = A[j];
                        A[j] = A[j - 1];
                        A[j - 1] = temp;
                    }
                }
            }

            // SelectionSort
            for(int i = 0; i < n; i++) {
                int minj = i;
                for(int j = i; j < n; j++) {
                    if (B[j].num < B[minj].num)
                        minj = j;
                }

                if (minj != i) {
                    Card temp = B[i];
                    B[i] = B[minj];
                    B[minj] = temp;
                }
            }

            // result
            Print(A);
            Console.WriteLine(A.SequenceEqual(stable) ? "Stable" : "Not stable");
            Print(B);
            Console.WriteLine(B.SequenceEqual(stable) ? "Stable" : "Not stable");
        }

        static void Print(Card[] arr) {
            StringBuilder sb = new StringBuilder();
            sb.Append(arr[0].ToString());
            for (int i = 1; i < arr.Length; i++) {
                sb.AppendFormat(" {0}", arr[i].ToString());
            }
            Console.WriteLine(sb.ToString());
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  char a;
  int b;
  
  vector<vector<int> > data(4, vector<int>(13,0));
  for (int i = 0; i < n ; i++) {
    cin >> a >> b;
    if (a == 'S'){
      a = 0;
    }
    else if (a == 'H'){
      a = 1;
    }
    else if (a == 'C'){
      a = 2;
    }
    else if (a == 'D'){
      a = 3;
    }
    data.at(a).at(b-1) = 1;
  }
  
  for (int i = 0; i < 4 ; i++) {
    for (int j = 0; j < 13 ; j++) {
      if (data.at(i).at(j) == 0){
        if (i == 0){
          cout << 'S' << ' ';
        }
        else if (i == 1){
          cout << 'H' << ' ';
        }
        else if (i == 2){
          cout << 'C' << ' ';
        }
        else if (i == 3){
          cout << 'D' << ' ';
        }
        cout << j + 1 << endl;
      }
    }
  }
}




Measured memory_bytes: 3136
#include <stdio.h>

int main() {
	
	char s[11];
	scanf("%s", s);
	
	char result[11];
	int index = 0;
	
	for( int i = 0; i < 11; i++){
		if(s[i] == '0'){
			result[index] = '0';
			index++;
		}
		else if(s[i] == '1'){
			result[index] = '1';
			index++;
		}
		else if(s[i] == 'B'){
			if(index > 0){
				index--;
				result [index] = '\0';
			}
		}
	}
	
	result[index] = '\0';
	
	printf("%s", result);
	
	return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi d(n);
	rep(i, n) cin >> d[i];
	
	ll ans = 0;
	rep(i, n) rep(j, i) ans += (ll)d[i] * d[j];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define f first
#define s second
#define R PP(1,0,0)
#define C PP(0,1,0)
#define S PP(0,0,1)
using namespace std;
typedef pair <int,int> P;
typedef pair <int,P> iP;
int p,q;
string str[2][11];
map<iP,int> M;
iP PP(int a,int b,int c){return iP(a,P(b,c));}

int gcd(int a,int b,int c,int d){
  a=abs(a),b=abs(b),c=abs(c),d=abs(d);
  a= a&&b? __gcd(a,b):max(a,b);
  c= c&&d? __gcd(c,d):max(c,d);
  a= a&&c? __gcd(a,c):max(a,c);
  return max(1,a);
}

void solve(){
  if(M.size()==2&&M.count(PP(1,1,1))) M[R]=M[C]=M[S]=M[PP(1,1,1)]/3;

  map<iP,int> ::iterator i,j;
  for(int k=0;k<3;k++){
    for(i=M.begin();i!=M.end();i++)
      for(j=M.begin();j!=M.end();j++){
	int a=i->f.f, b=i->f.s.f, c=i->f.s.s,d=i->s;
	int x=j->f.f, y=j->f.s.f, z=j->f.s.s,w=j->s;
	int T[3][2]={{a,x},{b,y},{c,z}};
	int D,ax,by,cz,dw,l=T[k][0],r=T[k][1];
	D=gcd(l,r,0,0);
	ax=(a*(r/D)-x*(l/D));
	by=(b*(r/D)-y*(l/D));
	cz=(c*(r/D)-z*(l/D));
	dw=(d*(r/D)-w*(l/D));
	D=gcd(ax,by,cz,dw);
	ax/=D,by/=D,cz/=D,dw/=D;
	if(M.count(PP(ax,by,cz))||ax<0||by<0||cz<0||dw<0) continue;
	i=M.begin();
	M[PP(ax,by,cz)]=dw;
      }
  }
}

void in(){
  M.clear();
  int cnt[3]={},d;
  for(int i=0;i<p;i++)
    for(int j=0,f=1,dot=0;j<str[0][i].size();j++){
      char ch=str[0][i][j];
      if(ch=='.')dot++;
      else if(f)f=0,d=gcd(cnt[0],cnt[1],cnt[2],dot),M[PP(cnt[0]/d,cnt[1]/d,cnt[2]/d)]=dot/d;
      if(ch=='('||ch=='['||ch=='{')cnt[ch/50]++;
      if(ch==')'||ch==']'||ch=='}')cnt[ch/50]--;
    }
}


int cal(int a,int b,int c){
  int d=gcd(a,b,c,0),D;
  a/=d,b/=d,c/=d;
  if(M.count(PP(a,b,c))) return M[PP(a,b,c)]*d;
  int fa=M.count(R),fb=M.count(C),fc=M.count(S);
  int abc=fa+fb+fc;
  if(abc/3) return (M[R]*a+M[C]*b+M[S]*c)*d;
  if(abc/2&&(!a!=!fa||!b!=!fb||!c!=!fc)) return -1;
  if(abc/2) return (M[R]*a+M[C]*b+M[S]*c)*d;
  /*
  D=gcd(b,c,0,0);
  if(fa&&M.count(PP(0,b/D,c/D)))return (M[R]*a+M[PP(0,b/D,c/D)]*D)*d;
  D=gcd(a,c,0,0);
  if(fb&&M.count(PP(a/D,0,c/D)))return (M[C]*b+M[PP(a/D,0,c/D)]*D)*d;
  D=gcd(a,b,0,0);
  if(fc&&M.count(PP(a/D,b/D,0)))return (M[S]*c+M[PP(a/D,0,c/D)]*D)*d;
  */
  return -1;
}

void out(){
  int cnt[3]={},e[3]={M.count(R),M.count(C),M.count(S)};
  e[0]= e[0]? M[R]:-1;
  e[1]= e[1]? M[C]:-1;
  e[2]= e[2]? M[S]:-1;
  
  for(int i=0;i<q;i++){
    M.erase(R),M.erase(C),M.erase(S);
    if(e[0]!=-1)M[R]=e[0];
    if(e[1]!=-1)M[C]=e[1];
    if(e[2]!=-1)M[S]=e[2];
    cout <<cal(cnt[0],cnt[1],cnt[2]);
    if(i!=q-1)cout <<" ";
    for(int j=0;j<str[1][i].size();j++){
      char ch=str[1][i][j];
      if(ch=='('||ch=='['||ch=='{')cnt[ch/50]++;
      if(ch==')'||ch==']'||ch=='}')cnt[ch/50]--;
    }
  }
  cout <<endl;
}

int main(){
  while(1){
    cin>>p>>q;
    if(!p&&!q) break;
    for(int i=0;i<p;i++)cin>>str[0][i];
    for(int i=0;i<q;i++)cin>>str[1][i];
    in();
    solve();
    out();
  }
  return 0;
}

Measured memory_bytes: 1232
import re
S=str(input())
k=int(input())

if set(S)=={'1'}:
  print(1)
  
else:
  x=re.search(r'[2-9]',S).start()
      
  if S[0]=='1':
    if k<=x:
      print(S[0])
    else:
      print(S[x])     
  else:
    print(S[0])


Measured memory_bytes: 3188
#define mod 1000000007

long long modmult (long long n, long long m){
	if(!m) return 1;
	if(m&1) return modmult(n, m-1)*n%mod;
	return modmult(n*n%mod, m>>1);
}

long long modinv(long long n) { return modmult(n, mod-2); }

unsigned long long count;

unsigned long long c(a,b){
	unsigned long long res = 1;
	int i;
	
	if(a<b*2)return c(a,a-b);
	for(i=a;i>b;i--)res=res*i%mod;
	for(i=2;i<=a-b;i++)res=res*modinv(i)%mod;

	return res;
}

main(){
	long long int x, y, x2s;
	scanf("%lld %lld", &x, &y);
	
	for(x2s=0;x2s<=x/2;x2s++){
		if(x2s + (x - x2s*2)*2 != y) continue;
//		printf("y: %lld * 2 + %lld\n", x-x2s*2, x2s);
		count+=c(x-x2s,x2s)%mod;
		count%=mod;
//		printf("-- %lld c %lld patterns available\n", x-x2s, x2s);
	}
	
	printf("%lld\n", count);
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int ans=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3920
let rec f = function x::y::ys -> x + f ys | _ -> 0
let _ = Scanf.scanf "%d" @@ fun n ->
  Array.(init (2*n) (fun _ -> Scanf.scanf " %d" ((+) 0)) |> to_list)
  |> List.sort (-) |> f |> Printf.printf "%d\n"

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(B + C < A) cout << 0 << endl;
    else cout << B + C - A << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int n;
vector<long > a;
vector<long> b;
vector<long> c;
vector<vector<long> > happiness ;
long mx(long x,long y){
	return (x>y) ? x:y ;
}

long solve(int i,int last){
	if(i==0) return happiness [i][last];
	else if(happiness[i][last]!=-1) return happiness [i][last];
	else{
		if(last==0){
			happiness[i][0]=max(b[i]+solve(i-1,1),c[i]+solve(i-1,2));
		}
		else if(last==1){
			happiness[i][1]=max(a[i]+solve(i-1,0),c[i]+solve(i-1,2));
		}
		else if(last==2){
			happiness[i][2]=max(b[i]+solve(i-1,1),a[i]+solve(i-1,0));
		}

		return happiness[i][last];
	}



}


	
int main(){
	cin>>n;
	a.assign(n,0);
	b.assign(n,0);
	c.assign(n,0);
	for(int i=0;i<n;i++){
		cin>>a[i];
		cin>>b[i];
		cin>>c[i];
	}
	happiness.assign(n,vector<long>(3,-1));
	happiness[0][0]=max(b[0], c[0]);
	happiness[0][1]=max(c[0], a[0]);
	happiness[0][2]=max(a[0], b[0]);

	cout<<max(solve(n-1,0),max(solve(n-1,1),solve(n-1,2)));

	return 0;
}






Measured memory_bytes: 14336
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int K;
int S[500][500];
int sz[500];
int main(){
  int i;
  int m = 1;
  rd(N);
  while(K*(K-1)/2 < N){
    K++;
  }
  if(K*(K-1)/2 != N){
    wt_L("No");
    wt_L('\n');
    return 0;
  }
  for(i=(0);i<(K);i++){
    int j;
    for(j=(i+1);j<(K);j++){
      S[i][sz[i]++] = m;
      S[j][sz[j]++] = m++;
    }
  }
  wt_L("Yes");
  wt_L('\n');
  wt_L(K);
  wt_L('\n');
  for(i=(0);i<(K);i++){
    wt_L(sz[i]);
    wt_L(' ');
    {
      int WYIGIcGE;
      if(sz[i]==0){
        putchar_unlocked('\n');
      }
      else{
        for(WYIGIcGE=(0);WYIGIcGE<(sz[i]-1);WYIGIcGE++){
          wt_L(S[i][WYIGIcGE]);
          wt_L(' ');
        }
        wt_L(S[i][WYIGIcGE]);
        wt_L('\n');
      }
    }
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N;
// int K, S[500][500], sz[500];
// {
//   int m = 1;
//   rd(N);
//   while(K*(K-1)/2 < N) K++;
//   if(K*(K-1)/2 != N) wt("No"), return 0;
//   rep(i,K) rep(j,i+1,K){
//     S[i][sz[i]++] = m;
//     S[j][sz[j]++] = m++;
//   }
//   wt("Yes");
//   wt(K);
//   rep(i,K) wt(sz[i], S[i](sz[i]));
// }


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

// a quote from http://www.igaris.com/math/c.pdf

#define MOD (1000000000+7)

long long C[1001][1001];

long long power( long long x, int n )
{
	if( n == 0 ) {
		return 1;
	}
	if( n % 2 ) {
		return x * power( x, n - 1 ) % MOD;
	}
	else {
		return power( x * x % MOD, n / 2 );
	}
}

long long ifac( long long x )
{
	long long f = 1;
	while( x > 1 ) {
		f *= power( x, MOD - 2 );
		f %= MOD;
		x--;
	}
	return f;
}

long long count( int n, int k )
{
	if( n == 1 || k == 1 ) {
		return 1;
	}
	if( n < 0 || k < 1 ) {
		return 0;
	}
	if( C[n][k] != 0 ) {
		return C[n][k];
	}
	long long res = ( count( n - k, k ) + count( n, k - 1 ) ) % MOD;
	C[n][k] = res;
	return res;
}

int main()
{
	int n, k;
	cin >> n >> k;

/*
	// Pascal's triangle for combination
	C[0][0] = 1;
	for( int i = 1; i < 1001; i++ ) {
		for( int j = 0; j <= i; j++ ) {
			if( j == 0 || j == i ) {
				C[i][j] = C[i - 1][0];
			}
			else {
				C[i][j] = ( C[i - 1][j - 1] + C[i - 1][j] ) % MOD;
			}
		}
	}
*/
	long long ans = count( n, k );

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 10004
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vector<queue<ll>> v(n);
    rep(i,n){
        rep(j,n-1){
            ll x;cin >> x;x--;
            v[i].push(x);
        }
    }
    ll day=0,end=0;
    set<ll> prematch;
    rep(i,n)prematch.ins(i);
    while(true){
        ll preend=end;
        set<ll> match;
        vector<bool> check(n,false);
        for(auto i:prematch){
            if(v[i].empty())continue;
            if(check[i])continue;
            ll x=v[i].front();
            if(v[x].empty())continue;
            if(check[x])continue;
            if(v[x].front()==i){
                v[i].pop();v[x].pop();
                check[i]=true;check[x]=true;
                end+=2;
                match.ins(i);match.ins(x);
            } 
        }
        day++;
        if(preend==end){
            cout << -1 <<endl;
            return 0;
        }
        if(end==n*(n-1))break;
        prematch=match;
    }
    cout << day <<endl;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

int main() {
  ll A,B,Q;
  cin >> A >> B >> Q;
  vector<ll> s(A), t(B);
  map<ll,ll> st;
  REP(i,A) cin >> s[i];
  REP(i,B) cin >> t[i];
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  // Aiから見て、一番近い B を探す
  REP(i,A) {
    auto it = lower_bound( t.begin(), t.end(), s[i] );
    ll hi, lo, tgt;
    if ( it == t.end() ) hi = INF;
    else hi = *it - s[i];
    if ( it == t.begin() ) lo = INF;
    else lo = s[i] - *(--it);
    tgt = min(hi,lo);
//    cout << "A " << s[i] << " " << tgt << " " << hi << " " << lo << endl;
    st.emplace( s[i], tgt );
  }
  // Biから見て、一番近い A を探す
  REP(i,B) {
    auto it = lower_bound( s.begin(), s.end(), t[i] );
    ll hi, lo, tgt;
    if ( it == s.end() ) hi = INF;
    else hi = *it - t[i];
    if ( it == s.begin() ) lo = INF;
    else lo = t[i] - *(--it);
    tgt = min(hi,lo);
//    cout << "B " << t[i] << " " << tgt << endl;
    st.emplace( t[i], tgt );
  }
//  for( auto x: st )
//    cout << x.first << " " << x.second <<endl;

  // Ai,Bi 合わせた数列の一番近い個所を探す
  REP(i,Q) {
    ll x;
    cin >> x;
    auto it = st.lower_bound( x );
    ll hi, lo, tgt;
    if ( it == st.end() ) hi = INF;
    else hi = it->first - x + it->second;
    if ( it == st.begin() ) lo = INF;
    else { --it; lo = x - it->first + it->second; }
    tgt = min(hi,lo);
    
    cout << tgt << endl;
  }
  return 0;
}


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}

int aa,bb,a,b,c,x,y,g,ma;

int main()
{
	a=read(); b=read(); c=read(); x=read();  y=read();
	
//	if(a>c/2)a=c/2;
//	if(b>c/2)b=c/2;
//double
	
//	if(x>y)swap(a,b),swap(x,y);
	
	ma=a*x+b*y;
//	ma=min(ma,a*) //O1   //(double ) //youwu //
    
    g=max(x*2,y*2);
    for(int i=2; i<=g; i+=2){
    	aa=max(0,x-i/2);
    	bb=max(0,y-i/2);
    	ma=min(ma,i*c+aa*a+bb*b);
	}
    
    cout<<ma;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int K, X;
    cin >> K >> X;
    if(500 * K >= X)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
x = int(S[:2])
y = int(S[2:])

if 1<=x<=12:
    if 1<=y<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=y<=12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 2940
/*
Author: Snickeen 
Email : ff@snickeen.com
If you find any bug, please tell me.
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL INF = 1e18+7;
const LL MOD = 1e9+7;
const LL MAXN = 1e6+7;

/////**********************************************/////



signed main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	LL i,j,k,n,m,ans=0;
	cin>>n>>m;
	for(i=n;i<=m;i++){
		k=i;j=0;
		while(k){
			j=j*10+k%10;
			k/=10;
		}
		ans+=i==j;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <complex>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// 外積　cross(a,b) = |a||b|sinθ
D cross(P a, P b) {
  return (conj(a)*b).Y;
}

// 点の進行方向
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}


/* 多角形 */

// 頂点の順序（sortやmax_elementに必要）
namespace std {
  bool operator<(const P a, const P b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

// 凸包
VP convexHull(VP ps) {  // 元の点集合がソートされていいならVP&に
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;  // 余計な点も含むなら == -1 とする
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

// 凸判定。縮退を認めないならccwの判定部分を != 1 とする
bool isCcwConvex(const VP& ps) {
  int n = ps.size();
  rep (i, n) if (ccw(ps[i], ps[(i+1) % n], ps[(i+2) % n]) == -1) return false;
  return true;
}

// 凸多角形の内部判定　O(n)
// 点が領域内部なら1、境界上なら2、外部なら0を返す
int inConvex(P p, const VP& ps) {
  int n = ps.size();
  int dir = ccw(ps[0], ps[1], p);
  rep (i, n) {
    int ccwc = ccw(ps[i], ps[(i + 1) % n], p);
    if (!ccwc) return 2;  // 線分上に存在
    if (ccwc != dir) return 0;
  }
  return 1;
}

int main() {
  while (true) {
    VP ps(4);
    rep (i,4) {
      D x,y;
      if (! (cin >> x >> y) ) return 0;
      ps[i] = P(x,y);
    }
    VP conv = convexHull(ps);
    bool pFound = false;
    rep (i,conv.size()) if ( EQ(norm(conv[i]-ps[3]), 0) ) pFound = true;
    cout << (pFound ? "NO" : "YES") << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <algorithm>
#include <vector>

#define N 10
#define INF (1 << 30)

using std::cin;
using std::cout;
using std::endl;

using std::vector;
using std::min;

void dump(const vector<int>& v){
    for(int i : v){
        cout << i << " ";
    }
    cout << endl;
}

vector<int> dijkstra(const int c[N][N]) {
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        d[i] = INF;
    }
    d[1] = 0;

    vector<int> q;
    for(int i = 0; i < N; i++){
        q.push_back(i);
    }

    while (q.size() != 0) {
        int v = q[0];
        for(int u : q){
            if(d[u] < d[v]){
                v = u;
            }
        }
        q.erase(remove(q.begin(), q.end(), v), q.end());

        for(int u = 0; u < N; u++){
            d[u] = min(d[u], d[v] + c[u][v]);
        }
    }

    return d;
}

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

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

    vector<int> cost = dijkstra(c);

    int sum = 0;
    for (int q = 0; q < h * w; q++) {
        int x;
        cin >> x;
        if(x == -1){
            continue;
        }
        sum += cost[x];
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
    int a,b,i;
    char serve[101];
    while (scanf(" %s",serve)!=EOF&&(serve[0]-'0')!=0) {
        a=0,b=0;
        for (i=0; i<strlen(serve); i++) {
            if (i==0) {
                continue;
            } else {
                if (serve[i]=='A') {
                    a++;
                } else {
                    b++;
                }
            }
        }
        if (a>b) {
            a++;
        } else {
            b++;
        }
        printf("%d %d\n",a,b);
    }
    return 0;
}

Measured memory_bytes: 536
#include <cstdio>
using namespace std;

int main()
{
	double a,s;
	while(scanf("%lf",&a)!=EOF)
	{
		s=a;
		for(int i=2; i<=10; i++)
		{
			a=(i%2 ? a/3.0 : a*2.0);
			s+=a;
		}
		printf("%.8lf\n",s);
	}
}

Measured memory_bytes: 0
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PAIR pair<int, int>
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
//constexpr int MOD = 10e9+7;
constexpr int INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 

  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//
int x[100010];
signed main()
{
  ios();
  int N,K;
  cin >> N >> K;
  REP(i,N) cin >> x[i];
  int ans = INF;
  REP(i,N - K +1)
  { 
    int l = i;
    int r = K-1+i;
    chmin(ans,min(abs(x[r]-x[l]) + abs(x[l]),abs(x[r]-x[l]) + abs(x[r])));
  }
  cout << ans << endl;
}

//N縺薙・荳ｭ縺九ｉ騾｣邯壹☆繧橘蛟九ｒ驕ｸ縺ｶ縺ｨ縺阪・驕ｸ縺ｳ譁ｹ縺ｯ髯舌ｌ繧峨ｌ繧九・ S T L

//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ REP(i,N) ruiseki[i+1] += ruiseki[i];
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,ma,mb;
	cin >> n >> ma >> mb;

	int a[n],b[n],c[n];
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	int num=401;
	int dp[n][num][num];
	for(int i=0;i<n;i++){
		for(int j=0;j<num;j++){
			for(int k=0;k<num;k++){
				dp[i][j][k] = INF;
			}
		}
		dp[i][a[i]][b[i]] = c[i];
	}
	dp[0][0][0] = 0;
	for(int k=1;k<n;k++){
		for(int i=0;i<num;i++){
			for(int j=0;j<num;j++){
				dp[k][i][j] = min(dp[k][i][j],dp[k-1][i][j]);
				if(i-a[k]>=1 && j-b[k]>=1 && dp[k-1][i-a[k]][j-b[k]]!=INF){
					dp[k][i][j] = min(dp[k][i][j],dp[k-1][i-a[k]][j-b[k]]+c[k]);
				}
			}
		}
	}
	int x,y,ans=INF;
	for(int i=1;;i++){
		y=ma*i; x=mb*i;
		if(y>=num || x>=num){
			break;
		}
		if(dp[n-1][y][x]!=INF){
			ans = min(ans,dp[n-1][y][x]);
		}
	}
	if(ans==INF) cout << "-1\n";
	else		cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 25344
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int n, k, a[100005], dp[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2; i<n; i++)
    {
        int Min=INT_MAX;
        for(int j=1; j<=k; j++)
            if(i-j>=0)
                Min=min(Min, dp[i-j]+abs(a[i]-a[i-j]));
        dp[i]=Min;
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

#define MAXN 100
int N;
int A[MAXN+5];

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%d",&A[i]);
    int Ans=0;
    for(int i=2;i<=N;i++)
        if(A[i]==A[i-1]){
            Ans++;
            A[i]=0;
        }
    printf("%d",Ans);
}


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

using namespace std;

using ll = long long;

int calc(int num, int K) {
    if (num == 1) return 0;
    if (num <= K) return 1;
    num -= K;
    int res = 1;
    res += (num + (K - 2)) / (K - 1);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vector<int> a(n);
    int idx = -1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) idx = i;
    }

    cout << 1 + (max(n - K, 0) + (K - 2)) / (K - 1) << endl;
    return 0;
}

Measured memory_bytes: 640
lists = []
for i in range(5):
	lists.append(input())

f_list = []
for i in lists:
	f_list.append(i[-1])

mins = 10
if not "0" in f_list:
    mins = int(min(f_list))
elif len(set(f_list)) == 1:
    pass
else:
    mins = int(sorted(set(f_list))[1])
sums = 0
for i in lists:
	sums += int((int(i)+9)/10)*10


print(sums-10+mins)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b, c;

signed main() {
	cin >> a >> b >> c;
	cout << (a==b && b==c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#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 ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

typedef struct S{
	long now;
	int x;
	int y;
}s;

int main(){
	int h,w;
	cin >> h >> w;
	
	bool f[h][w]={};
	int cnt = 0;
	rep(i,0,h){
		rep(j,0,w){
			char c;
			cin >> c;
			if(c == '.')
				f[i][j]++;
			else
				cnt++;
		}
	}
	
	s status = {0,0,0};
	stack
 st;
	st.push(status);
	
	vector<vector<long>> dp( h, vector<long>( w , 0x7FFFFFFFFFFFFFFF ) );
	

	while(!st.empty()){
		status = st.top();
		int x = status.x;
		int y = status.y;
		long now = status.now;
		st.pop();
		
		if(dp[y][x] < now)
			continue;
		
		dp[y][x] = now;
		if( y != 0 && f[y-1][x] ){
			if(dp[y-1][x] > now+1 ){
				status.x = x;
				status.y = y-1;
				status.now = now+1;
				st.push(status);
			}
		}
		

		if( y != h-1 && f[y+1][x] ){
			if(dp[y+1][x] > now+1 ){
				status.x = x;
				status.y = y+1;
				status.now = now+1;
				st.push(status);
			}
		}
		
		if( x != 0 && f[y][x-1] ){
			if(dp[y][x-1] > now+1 ){
				status.x = x-1;
				status.y = y;
				status.now = now+1;
				st.push(status);
			}
		}
		
		if( x != w-1 && f[y][x+1] ){
			if(dp[y][x+1] > now+1 ){
				status.x = x+1;
				status.y = y;
				status.now = now+1;
				st.push(status);
			}
		}
	}
	
	long saisyo = dp[h-1][w-1];

	if(saisyo == 0x7FFFFFFFFFFFFFFF)
		P(-1);
	else{
		long ans = (h)*(w)-cnt-saisyo-1;
		P(ans);
	}
	ret 0;
}

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

#define endl '\n'

typedef long long ll;

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

	ll n, x; cin >> n >> x;

	cout << 3 * (n - __gcd(n, x)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const int MAX_C = 2010;
long long Com[MAX_C][MAX_C] = {0};

int main(){
  int N, M; cin >> N >> M;
  vector<int> to[N];
  rep(i, M){
    int u, v; cin >> u >> v;
    u--; v--; to[u].push_back(v); 
  }
  int S, T; cin >> S >> T; S--; T--;
  queue<pair<int, int>>q;
  q.push({S, 0});
  int dist[N][3]; 
  rep(i, N){
    rep(j, 3){
      dist[i][j]=inf;
    }
  }
  dist[S][0] = 0;
  while(!q.empty()){
    int a = q.front().first, b = q.front().second; q.pop();
    for(int x: to[a]){
      if(dist[x][(b+1)%3]==inf){
        dist[x][(b+1)%3] = dist[a][b] + 1;
        q.push({x, (b+1)%3});
      }
    }
  }
  if(dist[T][0]==inf) cout << -1 << endl;
  else  cout << dist[T][0]/3 << endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> P1;

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

set<P1> memo;

main(){
  
  int a, b, c, n;
  
  cin>>a>>b>>c>>n;
  
  for(int i=0;i<n;i++){
    
    int x, y, z;
    
    cin>>x>>y>>z;

    memo.insert(P1(P(x,y),z));
  }
  
  int ans=a*b*2+b*c*2+c*a*2;
  
  set<P1>::iterator ite=memo.begin();
  
  while(ite!=memo.end()){

    int x=(*ite).first.first;
    int y=(*ite).first.second;
    int z=(*ite).second;
    
    ans+=6;
    
    for(int i=0;i<6;i++){

      int nx=x+dx[i];
      int ny=y+dy[i];
      int nz=z+dz[i];

      if(nx<0||a<=nx||ny<0||b<=ny||nz<0||c<=nz) ans-=2;
      else if(memo.count(P1(P(nx,ny),nz))) ans-=1;
      
    }
    
    ite++;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 3148