akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
using namespace std;
int x[10][10],ans=0,vis[10];
int n,m;
void dfs(int v,int u){
	//printf("v:%d u%d\n",v,u);
	if(u==n) {ans++;return;}
	for(int i=1;i<=10;i++){
		if(!x[v][i])continue;
		if(vis[i])continue;
		vis[i]=1;
		dfs(i,u+1);
		vis[i]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int a,b,i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		x[a][b]=1;x[b][a]=1;
	}
	vis[1]=1;
	dfs(1,1);
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

int mod = 1e9+7;
int INF = 1e9+7;
// const long long INF = 1LL<<60;


int main(){
  int A, B;
  cin >> A >> B;

  cout << A*B << endl;


  return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	string S, T;
	cin >> S >> T;
	string ans = "YES";
	char d[] = {'L', 'U', 'R', 'D'};
	rep(k, 4) {
		int r = sr, c = sc;
		rep(i, N) {
			if (S[i] == d[k]) {
				r += di[k];
				c += dj[k];
				if (r < 1 || r > H || c < 1 || c > W)
					ans = "NO";
			}
			if (T[i] == d[(k + 2) % 4]) {
				if (0 < r - di[k] && r - di[k] <= H && 0 < c - dj[k] && c - dj[k] <= W) {
					r -= di[k];
					c -= dj[k];
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <string> 
using namespace std;
int a[5];
int main(){
	int i,j,k,n;
	string st;
	cin>>st;
	for(i=0;i<st.length();i++)a[i+1]=st[i]-48;
	if(a[1]+a[2]+a[3]+a[4]==7){
	    cout<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]+a[2]+a[3]-a[4]==7){
	    cout<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]+a[2]-a[3]+a[4]==7){
	    cout<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]+a[2]-a[3]-a[4]==7){
	    cout<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]-a[2]+a[3]+a[4]==7){
	    cout<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]-a[2]+a[3]-a[4]==7){
	    cout<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]-a[2]-a[3]+a[4]==7){
	    cout<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	    return 0;
	}
	if(a[1]-a[2]-a[3]-a[4]==7){
	    cout<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	    return 0;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;
constexpr int MAX = 1e5 + 2;

int main()
{
    int n, m;
    ll ans = 1LL;
    cin >> n >> m;
    vector<int> a(m);
    vector<ll> fib(MAX, 0LL);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
    }
    fib[1] = 1LL;
    for (int i = 2; i < MAX; i++)
    {
        fib[i] = fib[i - 1] + fib[i - 2];
        fib[i] %= mod;
    }
    a.emplace_back(n + 1);
    ans *= fib[a[0]];
    ans %= mod;
    for (int i = 1; i < m + 1; i++)
    {
        ans *= fib[a[i] - a[i - 1] - 1];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


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

int main (){
    string O,E;
    cin >> O ;
    cin >> E;
    for (int i=0; i<E.length();i++){
        cout << O[i] << E[i];

    }
    if (O.length() != E.length()){
        cout << O[O.length()-1];
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
int calc(int a) {
    if (a == 2 || a == 3) return 1;
    if (a == 1 || a % 2 == 0) return 0;
    for (int i = 3; i * i <= a; ++i) {
        if (a % i == 0) return 0;
    }
    return 1;
}
int main() {
    int n;
    while (cin >> n && n) {
        int cnt = 0;
        for (int i = n + 1; i <= 2 * n; ++i) {
            if (calc(i) == 1) cnt++;
        }
        cout << cnt << endl;
    }
    
    
    
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
int days,n;
cin>>days>>n;
ll cnt=0;
int num;
for(int i=0;i<n;i++)
{
	cin>>num;
	cnt=(ll)cnt+(ll)num;
}
if(cnt>(ll)days)
cout<<-1;
else
cout<<((ll)days-cnt);
}

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

int main() {
  int N;
  int A[100];
  cin>>N;
  for(int i =0;i<N;i++){
    cin>>A[i];
  }
  sort(A,A+N);
  reverse(A,A+N);
   int Alce =0;
  int Bob = 0;
  for(int i =0; i<N;i++){
    if(i%2==0){
      Alce+= A[i];
    }else{
      Bob+=A[i];
    }
  }
  cout<<Alce-Bob<<endl;
    
  
}

Measured memory_bytes: 384
let charl_of_string s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
  exp (String.length s - 1) []

let dp = Array.make 26 0

let calc c =
  let ind = (int_of_char c) - 97 in
  dp.(ind) <- dp.(ind) + 1

let flag = ref true
let cl =
  read_line ()
  |> charl_of_string
  |> List.map calc
  
let () =
  for i = 0 to 25 do
    if dp.(i) mod 2 = 1 then flag := false
  done;
  if !flag then print_endline "Yes"
  else print_endline "No"

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

int main()
{
	int n;
	scanf("%d", &n);
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				sum += __gcd(i, __gcd(j, k));
			}
		}
	}		
	printf("%lld\n", sum);
	return 0;
}

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

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a > b) swap(a,b);
	if(a == 1 && b == 2) printf("3");
	if(a == 1 && b == 3) printf("2");
	if(a == 2 && b == 3) printf("1");
	return 0;
}

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

int main(){
    int c[10], p[10];
    int d, g;
    cin >> d >> g;
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }
    int ans = 0;
    for(int tmp = 0; tmp < (1<<d); tmp++){
        //cout << tmp << endl;
        int sum = 0, num = 0, max = 0;
        bitset<10> s(tmp);
        for(int i = 0; i < d; i++){
            if(s.test(i)){
                sum += 100*(i+1)*p[i] + c[i];
                num += p[i];
            }else max = i;
        }
        if(sum < g){
            for(int i = 0; i < p[max]; i++){
                sum += 100*(max + 1);
                num++;
                if(sum >= g) break;
            }
            if(sum < g) continue;
        }
        if(ans == 0){
            ans = num;
        }
        else{
            ans = min(ans, num);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

   class Main{
      public static void main(String args[]){
      Scanner scan = new Scanner(System.in);

      int a1 = scan.nextInt();
      int b1 = scan.nextInt();
      int c1 = scan.nextInt();
      int c2 = scan.nextInt();
      int b2 = scan.nextInt();
      int a2 = scan.nextInt();

      int q = scan.nextInt();

      for(int i=0;i<q;i++){

         int x = scan.nextInt();
         int y = scan.nextInt();

         if(x==a1){
            if(y==b1){
               System.out.println(c1);
            }else if(y==b2){
               System.out.println(c2);
            }else if(y==c1){
               System.out.println(b2);
            }else{
               System.out.println(b1);
            }

         }else if(x==a2){
            if(y==b1){
               System.out.println(c2);
            }else if(y==b2){
               System.out.println(c1);
            }else if(y==c1){
               System.out.println(b1);
            }else{
               System.out.println(b2);
            }

         }else if(x==b1){
            if(y==a1){
               System.out.println(c2);
            }else if(y==a2){
               System.out.println(c1);
            }else if(y==c1){
               System.out.println(a1);
            }else{
               System.out.println(a2);
            }

         }else if(x==b2){
            if(y==a1){
               System.out.println(c1);
            }else if(y==a2){
               System.out.println(c2);
            }else if(y==c1){
               System.out.println(a2);
            }else{
               System.out.println(a1);
            }

         }else if(x==c1){
            if(y==a1){
               System.out.println(b1);
            }else if(y==a2){
               System.out.println(b2);
            }else if(y==b1){
               System.out.println(a2);
            }else{
               System.out.println(a1);
            }

         }else{
            if(y==a1){
               System.out.println(b2);
            }else if(y==a2){
               System.out.println(b1);
            }else if(y==b1){
               System.out.println(a1);
            }else{
               System.out.println(a2);
            }

         }
      }

      }
   }
            


Measured memory_bytes: 26240
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
a.sort(reverse=True)
dp = [0] * (N + 1)
dp[0] = 1
if len(a) > 0:
    A = a.pop()
else:
    A = -1

if A == 1:
    dp[1] = 0
    if len(a) > 0:
        A = a.pop()
    if A == 2:
        dp[2] = 0
    else:
        dp[2] = 1
else:
    dp[1] = 1
for i in range(2, N + 1):
    if i == A:
        if len(a) > 0:
            A = a.pop()
        continue
    if dp[i - 1] != 0 and dp[i - 2] != 0:
        dp[i] = (dp[i - 1] + dp[i - 2])  % 1000000007
    elif dp[i - 1] != 0:
        dp[i] = dp[i - 1]  % 1000000007
    elif dp[i - 2] != 0:
        dp[i] = dp[i - 2]  % 1000000007
    else:
        dp[i] = 0
print(dp[-1])

Measured memory_bytes: 7848
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,ans=0;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    for (ll i=0;i<n-1;i++){
        ll count=1;
        while(a[i]==a[i+1]){
            count++;
            i++;
        }
        if(i==n-2 and a[i]!=a[i+1]){
            ans++;
        }
        ans+=count%2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = gets.to_i
sum = 0
w = gets.split.map do |i|
  sum += i.to_i
  i.to_i
end
comp = 0
min = Float::INFINITY
w.each do |i|
  comp += i
  min = [min,(comp - (sum - comp).abs).abs].min
end
puts min


Measured memory_bytes: 14324
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

template<class T> inline T cabs(const T &x) { return x > 0 ? x : (-x); }
template<class T> inline T gcd(const T &x, const T &y) { return (y == 0) ? x : gcd(y, x % y); }
template<class T> inline T _sgn(const T &x) { return (x > 0) - (x < 0); }

#define dbg(x) cout << #x << " = " << (x) << endl
#define dbg2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define dbg3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
#define dbg4(x,y,z,w) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #w << " = " << w << endl

#define out(x) cout << (x) << endl
#define out2(x,y) cout << (x) << " " << (y) << endl
#define out3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define out4(x,y,z,w) cout << (x) << " " << (y) << " " << (z) << " " << (w) << endl

const int maxN = 256;

int W, H, N;
int X[maxN], Y[maxN];
int x[maxN], y[maxN], a[maxN];

int main()
{
    cin >> W >> H >> N;
    for(int i = 0; i < N; i ++)
        cin >> x[i] >> y[i] >> a[i];
    memset(X, 0, sizeof(X));
    memset(Y, 0, sizeof(Y));
    for(int i = 0; i < N; i ++) {
        if( a[i] == 1 ) {
            for(int j = 0; j <= 2 * x[i]; j ++)
                X[j] = 1;
        }
        if( a[i] == 2 ) {
            for(int j = 2 * x[i] + 1; j <= 2 * W + 1; j ++)
                X[j] = 1;
        }
        if( a[i] == 3 ) {
            for(int j = 0; j <= 2 * y[i]; j ++)
                Y[j] = 1;
        }
        if( a[i] == 4 ) {
            for(int j = 2 * y[i] + 1; j <= 2 * H + 1; j ++)
                Y[j] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < W; i ++) {
        for(int j = 0; j < H; j ++) {
            if( !X[2 * i + 1] && !X[2 * (i + 1)] ) {
                if( !Y[2 * j + 1] && !Y[2 * j + 1] ) {
                    ans ++;
                }
            }
        }
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200000],tmp[200000];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		tmp[i]=a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
		printf("%d\n",tmp[i]<=a[n/2-1]?a[n/2]:a[n/2-1]);
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t Dfs(int64_t level, int64_t k,vector<int64_t> A, vector<int64_t> P){
    if(level==0){
        if(k==0) return 0;
        else return 1;
    }

    if(k<2) return 0;
    else if(k<A.at(level-1)+2) return Dfs(level-1,k-1,A,P);
    else if(k<A.at(level-1)+3) return P.at(level-1)+1;
    else if(k<2*A.at(level-1)+3) return P.at(level-1)+1+Dfs(level-1,k-2-A.at(level-1),A,P);
    else return 2*P.at(level-1)+1;
}

int main(){
    int64_t N,X; cin>>N>>X;

    vector<int64_t> A(N+1,1),P(N+1,1);
    rep(n,0,N){
        A.at(n+1)=2*A.at(n)+3;
        P.at(n+1)=2*P.at(n)+1;
    }

    cout<<Dfs(N,X,A,P)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

int main() {
    ll sum=0;
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        sum ^= a[i];
    }
    rep(i,n){
        a[i] ^= sum; 
        cout << a[i] << " ";
    }
}

Measured memory_bytes: 4780
import itertools

while True:
    n = int(input())
    k = int(input())
    if n==0: break
    deck = []
    for _ in range(n):
        deck.append(input())
    ans = set()
    for it in itertools.permutations(deck,k):
        ans.add("".join(it))
    print(len(ans))

Measured memory_bytes: 7760
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;//10^18
const ll mod = 1000000007;
//printf("%.10f\n", n);
ll ok[123456];
signed main() {
	ll n = 0, k = 0, cnt = 1, sum = 1, ans = 0;
	cin >> n; vector<ll> t(n), u(n); map<ll, map<ll, ll>> m;
	for (int h = 0; h < n; h++) { cin >> t[h] >> u[h]; }
	for (int h = 0; h < n; h++) {
		for (int i = h + 1; i < n; i++) {
			ll a = t[h] - t[i], b = u[h] - u[i];
			m[a][b]++; m[0 - a][0 - b]++;
			ans = max(ans, max(m[a][b], m[0 - a][0 - b]));
		}
	}
	cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int n;cin >> n;
   cout<<n*800-(n/15)*200<<endl;
   return 0;
}

Measured memory_bytes: 256
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

H,N = LI()
A = []
B = []
for i in range(N):
    a,b = LI()
    A.append(a)
    B.append(b)

dp = [inf]*(H+1)
ans = inf

dp[H] = 0

for i in range(N):
    for h in range(H+1)[::-1]:
        dp[h] = min(dp[h],dp[min(H,h+A[i])]+B[i])
print(dp[0])

Measured memory_bytes: 72152
import math
def g(n):
  x = [int(raw_input()) for _ in [0]*n]
  x += [360-sum(x)]
  return sum(map(lambda x: math.sin(x*math.pi/180), x))
  
while 1:
  n = input()
  if n==0: break
  s1 = g(n-1)
  s2 = g(input()-1)
  if abs(s1-s2)<1e-6: print 0
  elif s1>s2: print 1
  elif s1<s2: print 2

Measured memory_bytes: 4424
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    A = input().split()
    print("YES" if A[0][-1] == A[1][0] and A[1][-1] == A[2][0] else "NO")


if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	string S;
	cin >> N >> S;

	rep(i, 0, SZ(S))
	{
		S[i] = 'A' + (S[i] - 'A' + N) % 26;
	}

	cout << S << endl;

	return 0;
}

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

#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define endl "\n" 
#define all(c) c.begin(),c.end()
#define present(c,element) (c.find(element)!=c.end())
#define cpresent(c,element) (find(c,element)!=c.end())
typedef vector<int> vi;
typedef vector<ll> vll;
ll mod=1e9+7;

ll p5(ll a)
{
	ll aa=a*a;
	return (aa*aa*a);
}


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

int test=1;
//cin>>test;
while(test--)
{
	ll x;
	cin>>x;
	for(int a=-118;a<120;a++)
	{
		for(int b=-118;b<120;b++)
		{
			if(p5(a)-p5(b)==x)
			{
				cout<<a<<" "<<b<<endl;
				return 0;
			}
		}
	}
	

}
return 0;
}









Measured memory_bytes: 3600
data = input().split()

N = int(data[0])
H = int(data[1])
W = int(data[2])

A = []
B = []
count = 0

for i in range(N):
    a_b_data = input().split()
    A.append(int(a_b_data[0]))
    B.append(int(a_b_data[1]))
    
for j in range(N):
    if H <= A[j] and W <= B[j]:
        count = count + 1
        
print(count)

Measured memory_bytes: 3064
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let (a,b) = {
        let line = get_input();
        let mut split = line.split_whitespace();
        let a:i64 = split.next().unwrap().parse().unwrap();
        let b:i64 = split.next().unwrap().parse().unwrap();
        (a,b)
    };

    let ans = a + b;

    if ans % 2 == 0 {
        println!("{}", ans / 2);
    } else {
        println!("IMPOSSIBLE");
    }
}

Measured memory_bytes: 4352
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

vector<int> read_array()
{
    int n;
    scanf("%d\n", &n);

    vector<int> ary(n);
    REP(i, n) {
        scanf("%d", &ary[i]);
    }

    return ary;
}

void print_array(const vector<int>& ary)
{
    REP(i, ary.size()) {
        printf("%d%c", ary[i], i == ary.size()-1 ? '\n' : ' ');
    }
}

// 1 <= i <= n-1
void inssort_step(vector<int>& ary, int i)
{
    int value = ary[i];

    int j;
    for(j = i-1; j >= 0; --j) {
        if(ary[j] <= value) break;
        ary[j+1] = ary[j];
    }
    ary[j+1] = value;
}

int main()
{
    vector<int> ary = read_array();

    print_array(ary);
    FOR(i, 1, ary.size()) {
        inssort_step(ary, i);
        print_array(ary);
    }

    return 0;
}

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

l = [0] * 9

for i in range(n):
    s = min(a[i] // 400, 8)
    l[s] += 1

m = 0
for i in range(len(l) - 1):
    if l[i] != 0:
        m += 1

print(max(m, 1), l[-1] + m)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a+b==c||a+c==b||b+c==a){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
    return 0;
  }
  
    

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();
		int X=sc.nextInt();

		int omanjyu=X;

		int[] nichi=new int[N];
		for(int i=0; i<N; i++) {
			nichi[i]=sc.nextInt();
		}

		for(int i=0; i<N; i++) {
			for(int j=1; j<=D; j++) {
				if((j-1)%nichi[i]==0) {
					omanjyu++;
				}
			}
		}
		System.out.println(omanjyu);
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int a[100000];

int main() {
    int n, ans = 0, l, r, i;
    vector <pair<int, int>> v;
    vector <int> w, z;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
       scanf("%d %d", &l, &r);
       
       v.push_back(make_pair(l, r));
       w.push_back(l);
       z.push_back(r);
    }
    
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());
    sort(z.begin(), z.end());
    
    l = 1, r = 1e9;
    for (i = n - 1; i >= 0; i--) {
        l = max(l, v[i].first);
        r = min(r, v[i].second);
        
        a[i] = max(r - l + 1, 0);
    }
    
    l = 1, r = 1e9;
    for (i = 0; i < n - 1; i++) {
        l = max(l, v[i].first);
        r = min(r, v[i].second);
        
        ans = max(ans, max(r - l + 1, 0) + a[i + 1]);
    }
    
    for (i = 0; i < n; i++) {
        if (w[n - 1] == v[i].first) {
            l = w[n - 2];
        } else {
            l = w[n - 1];
        }
        
        if (z[0] == v[i].second) {
            r = z[1];
        } else {
            r = z[0];
        }
        
        ans = max(ans, max(r - l + 1, 0) + v[i].second - v[i].first + 1);
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 2552
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<ll> a(n), s(n + 1);
	rep(i, n)
	{
		cin >> a[i];
		--a[i];
		s[i + 1] = s[i] + a[i];
	}
	rep(i, n + 1)s[i] %= k;
	ll res = 0;
	map<ll, ll> mp;
	rep(i, min(k, n + 1))
	{
		++mp[s[i]];
	}
	for (int i = 0; i < n; ++i)
	{
		ll p = mp[s[i]];
		--mp[s[i]];
		res += mp[s[i]];
		if (i + k <= n)++mp[s[i + k]];
	}
	cout << res << endl;
}

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

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

Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
for i in range(M):
  A.append(int(input()))

X = [0] * (N + 1)
for i in A:
  X[i] = -1

for i in range(N + 1):
  if i == 0:
    X[i] = 1
  elif i == 1:
    if X[i] == -1:
      X[i] = 0
    else:
      X[i] = 1
  else:
    if X[i] == -1:
      X[i] = 0
    else:
      X[i] = (X[i - 1] + X[i - 2]) % 1000000007

print(X[N])


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

int main() {
  int n,x,min;
  cin>>n>>x;
  vector<int> m(n);
  for(int i=0;i<n;i++){ 
    cin>>m.at(i);
    x-=m.at(i);
  }
  sort(m.begin(),m.end());
  min=m.at(0);
  x/=min;
  x+=n;
  cout<<x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"

/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize target ("popcnt")*/
/*#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
*/

using namespace std;
const int N = 777;
int n, m, k, t;
char a[N][N];
int dp[N][N];
vector <pair <int, int> > v = {{1, 0}, {0, 1}};
int inf = 1e9;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }

    if (a[1][1] == '#'){
        dp[1][1] = 1;
    }
    else {
        dp[1][1] = 0;
    }

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (i == 1 && j == 1){
                continue;
            }
            dp[i][j] = inf;
            if (a[i][j] == '.'){
                if (i > 1){
                    dp[i][j] = dp[i - 1][j];
                }
                if (j > 1){
                    dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                }
            }
            else {
                if (i > 1){
                    if (a[i - 1][j] == '#'){
                        dp[i][j] = dp[i - 1][j];
                    }
                    else {
                        dp[i][j] = dp[i - 1][j] + 1;
                    }
                }
                if (j > 1){
                    if (a[i][j - 1] == '#'){
                        dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                    }
                    else {
                        dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
                    }
                }
            }
        }
    }

    cout << dp[n][m] << endl;


    return 0;
}


Measured memory_bytes: 640
def rotate(N, S):
	words = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	m = len(words)
	ans = ""
	for s in S:
		idx = words.find(s)
		ans += words[(idx + N) % m]
	return ans


if __name__ == "__main__":
	N = int(input())
	S = input()
	print(rotate(N, S))

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

using namespace std;
using ll = long long;

const ll mx = 1LL << 62;
ll dp[20002][256];

int main() {
    while (1) {
        int n, m;
        cin >> n >> m;

        if (n == 0 && m == 0) break;

        vector<int> c;
        vector<int> x;

        for (int i = 0; i < m; ++i) {
            int ci;
            cin >> ci;
            c.push_back(ci);
        }

        for (int i = 0; i < n; ++i) {
            int xi;
            cin >> xi;
            x.push_back(xi);
        }

        int y = 128;

        for (int i = 0; i <= n + 1; ++i) {
            for (int j = 0; j < 256; ++j) {
                dp[i][j] = -1;
            }
        }
        dp[0][128] = 0;
        
        for (int i = 0; i < n; ++i) {
            int next = x[i];
            for (int j = 0; j < m; ++j) {
                int cj = c[j];
                for (int k = 0; k < 256; ++k) {
                    if (dp[i][k] == -1) continue;
                    int high = max(min(255, k + cj), 0);
                    int cost = (high - next) * (high - next);
                    dp[i + 1][high] = min((dp[i+ 1][high] == -1 ? mx : dp[i+ 1][high]), dp[i][k] + cost);
                }
            }
            // for (int k = 128; k < 256; ++k) {
            //     cout << dp[i + 1][k] << " ";
            // }
            //cout << endl;
        }

        ll mincost = mx;
        for (int i = 0; i < 256; ++i) {
            if (dp[n][i] < mincost && dp[n][i] != -1) mincost = dp[n][i];
        }
        cout << mincost << endl;

    }
}

Measured memory_bytes: 43132
N = int(input())
W = list(map(int , input().split()))

total_weight = sum(W)
half_weight = total_weight / 2 

weight = 0

for i in range(N):
    weight += W[i]
    if weight >= half_weight:
        before = weight - W[i]
        after = weight
        break
        
B = abs(total_weight - 2*before)
A = abs(total_weight - 2*after)

if B > A:
    print(A)
else:
    print(B)

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <deque>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n , x;
    cin >> n;
    deque < ll > b;
    for( int i = 0 ; i < n ; i++ ){
      cin >> x;
      if( i % 2 == 1 ) b.push_front( x );
      else b.push_back( x );
    }
    if( n % 2 == 1 ) reverse( b.begin() , b.end() );
    for( int i = 0 ; i < n ; i++ )cout << b[i] << " ";
}


Measured memory_bytes: 3840
// Problem : A - αlphabet
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 *   ﷽
 * In the name of Allah,the Most Gracious,the Most Merciful
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <climits>

using namespace std;

int main()
{
	char c;
	cin>>c;
	if(c >= 'A' && c <= 'Z') cout << "A";
	else cout << "a";
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 1; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int main(void) {
	ll num, i, j, k, ans = 0, a;
	cin >> num;
	num++;
	rep(i, num) {
		rep(j, num) {
			a = gcd(i, j);
			rep(k, num) {
				ans += gcd(a, k);
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s,t;

int main(){
	cin >> s;
	ans = 0;
	rep(i,s.size()/2){
		if(s[i] != s[s.size()-1-i]) ans++;
	}
	cout << ans << "\n";
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  char p = '\0';
  int ret = 0;
  for (char c : s) {
    if (p != c)
      ++ret;
    p = c;
  }
  cout << ret << "\n";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 200010;
int mat[N];
namespace mf {
  const int M = 400010;
  const int INF = 0x3f3f3f3f;
  struct edge {
    int la,b,cap;
  } con[M << 1];
  int tot = 1, fir[N];
  void add(int from,int to,int capc) {
    con[++tot] = (edge) {fir[from], to, capc};
    fir[from] = tot;
    con[++tot] = (edge) {fir[to], from, 0};
    fir[to] = tot;
  }
  int dis[N], st, en, cur[N], n;
  int dfs(int pos,int imp) {
    if (pos == en || !imp) return imp;
    int ret = 0, tmp;
    for (int& i = cur[pos]; i; i = con[i].la) {
      if (dis[con[i].b] == dis[pos] + 1) {
	tmp = dfs(con[i].b, min(imp, con[i].cap));
	con[i].cap -= tmp;
	con[i^1].cap += tmp;
	imp -= tmp;
	ret += tmp;
	if (!imp) break;
      }
    }
    return ret;
  }
  bool bfs() {
    queue<int> q;
    rep (i, 1, n) dis[i] = INF;
    dis[st] = 0;
    q.push(st);
    for (int pos; !q.empty(); q.pop()) {
      pos = q.front();
      for (int i = fir[pos]; i; i = con[i].la) {
	if (con[i].cap && dis[con[i].b] == INF) {
	  dis[con[i].b] = dis[pos] + 1;
	  q.push(con[i].b);
	}
      }
    }
    if (dis[en] == INF) return false;
    rep (i, 1, n) cur[i] = fir[i];
    return true;
  }
  int calc() {
    int ret = 0;
    while (bfs())
      ret += dfs(st, INF);
    rep (pos, (n/2)+1, n-2) {
      for (int i = fir[pos]; i; i = con[i].la) {
	if (con[i].b <= (n/2) && con[i].cap > 0)
	  mat[pos - (n/2)] = con[i].b;
      }
    }
    return ret;
  }
  
}
int n, vis[N];
vector<int> vec[N], rec[N];
pii ans[N];
void dfs(int pos) {
  vis[pos] = 1;
  rep (i, 0, (int)rec[pos].size()-1) {
    if (vis[mat[rec[pos][i]]]) continue;
    ans[rec[pos][i]] = pii(pos, mat[rec[pos][i]]);
    dfs(mat[rec[pos][i]]);
  }
}
int main() {
  read(n);
  rep (i, 1, n-1) {
    int tmp, x;
    read(tmp);
    rep (j, 1, tmp) {
      read(x);
      vec[i].push_back(x);
      rec[x].push_back(i);
      if (x != 1) mf::add(x, i + n, 1);
    }
  }
  mf::n = 2 * n - 1;
  mf::st = ++ mf::n;
  mf::en = ++ mf::n;
  rep (i, 1, n) mf::add(mf::st, i, 1);
  rep (i, n+1, 2*n-1) mf::add(i, mf::en, 1);
  int res = mf::calc();
  if (res < n-1) {
    puts("-1");
    return 0;
  }
  dfs(1);
  int tmp = 1;
  rep (i, 1, n) if (!vis[i]) tmp = 0;
  if (tmp == 0) puts("-1");
  else {
    rep (i, 1, n-1) {
      printf("%d %d\n", ans[i].fir, ans[i].sec);
    }
  }
  return 0;
}


Measured memory_bytes: 33732
#include <bits/stdc++.h>
using namespace std;
int main(){
    using ll = long long;
    int n; cin >>n;
    vector<ll> a(n+1);
    vector<ll> b(n);

    for(int i=0; i<n+1; i++){
        cin >> a.at(i);
    }
    for(int i=0; i<n; i++){
        cin >> b.at(i);
    }

    ll sum = 0;

    for(int i=0; i<n; i++){
        if(b.at(i) >= a.at(i)){
            sum += a.at(i);
            b.at(i) -= a.at(i);
            sum += min(a.at(i+1), b.at(i));
            a.at(i+1) = max(ll(0),a.at(i+1)-b.at(i));
        }else{
            sum += b.at(i);
        }
    }

    cout << sum << endl;


}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define MOD 1000000007
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
ll ncr(ll n, ll r,ll m)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans *= modi(n - i + 1, m);
		ans %= m;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}


bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}

void dfs(ll a, vector<ll>adj[100099], bool visited[100001], ll dp[])
{
	visited[a] = true;
	if (adj[a].size() == 0) {
		dp[a] = 0;
	}
	
	for (auto u : adj[a])
	{
		if (!visited[u])
		{
			visited[u] = true;
			dfs(u, adj, visited, dp);
			dp[a] =max(dp[a], dp[u] + 1);
		}
		else {
			dp[a] = max(dp[a], dp[u] + 1);
		}
	}
	
}

ll calhash(string& s) {
	ll i, hash = 0, p = 1, pow = 3;
	for (i = 0; s[i] != '\0'; i++) {
		hash = (hash + p * (s[i] - 'a' + 1)) % MOD;
		p *= pow;
	}
	return hash;
}
ll digit(ll n)
{
	ll count = 0;
	while (n != 0) {
		n = n / 10;
		++count;
	}
	return count;
}
ll* kmp(string& s) {
	ll j, i, prefix[1000];
	prefix[0] = 0;
	for (i = 1; s[i] != '\0'; i++) {

			j = prefix[i - 1];
			while (j > 0 && s[j] != s[i]) {
				j = prefix[j - 1];
			}
			if (s[i] == s[j]) {
				prefix[i] = j + 1;
			}
	}
	return prefix;
}

void bfs(ll start, ll arr[], vector<ll> adj[], ll c) {
	queue<pair<ll,ll>> q;
	pair<ll, ll> temp;
	temp = { start, c };
	q.push(temp);
	while (!q.empty()) {
		temp = q.front();
		q.pop();
		for (auto u : adj[temp.first]) {
			    arr[u] = arr[u] - temp.second;
				q.push({ u , -temp.second});
			}
			
		
	}
}
int main() {
	fast;
	ll n, m, i, a, b, dp[100001] = { 0 };
	
	vector<ll> adj[100001];
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		adj[a].pb(b);
	}
	for (i = 1; i <= n; i++) {
		dp[i] = 0;
	}
	bool visited[100001] = { false };
	for (i = 1; i <= n; i++) {
		if (!visited[i]) {
			dfs(i, adj, visited, dp);
		}
	}
	ll ans = 0;
	for (i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
		//cout << dp[i]<<" ";
	}
	cout << ans;
	return 0;
}

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

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

struct mobile {
  int lm,rm,lc,rc,ll,rl;
  mobile(int lc,int rc,int ll,int rl)
  : lc(lc), rc(rc), ll(ll), rl(rl) {
    lm = rm = -1;
  }
};

int gcd(int a,int b) {
  return b != 0 ? gcd(b, a%b) : a;
}

int lcm(int a,int b) {
  return a/gcd(a,b)*b;
}

int dfs(int pos,vector<mobile> &vm) {
  mobile now = vm[pos];
  now.lm = (now.lc == -1) ? 1 : dfs(now.lc,vm);
  now.rm = (now.rc == -1) ? 1 : dfs(now.rc,vm);
  int g = lcm(now.ll*now.lm, now.rl*now.rm);
  now.rm = g / now.rl;
  now.lm = g / now.ll;
  return now.rm+now.lm;
}

int main() {
  int n,i,p,q,r,b,root;
  while(cin>>n, n) {
    vector<mobile> vm;
    vector<bool> isroot(n+1,true);
    root = -1;
    rep(i,n) {
      cin>>p>>q>>r>>b;
      r--,b--;
      if(r >= 0) isroot[r] = false;
      if(b >= 0) isroot[b] = false;
      vm.push_back(mobile(r,b,p,q));
    }

    rep(i,n) if(isroot[i] == true) cout<<dfs(i,vm)<<endl;
  }
}

Measured memory_bytes: 0
<?php

[$n, $k] = explode(' ', trim(fgets(STDIN)));
$towns = explode(' ', trim(fgets(STDIN)));
$teleportHistory = [];
$visitedTurns = [];
$ptr = 1;   // <注意> 1から始まる
$i = 0;

while($i < $k)
{
  if(isset($visitedTurns[$ptr - 1])) break;
  $visitedTurns[$ptr - 1] = $i;
  $teleportHistory[] = $ptr;
  $ptr = $towns[$ptr - 1];
  $i++;
}

if(isset($visitedTurns[$ptr - 1])) {
  $turnsLastIndex = $k - $visitedTurns[$ptr - 1];
  $historyLastIndex = $i - $visitedTurns[$ptr - 1];
  echo $teleportHistory[$visitedTurns[$ptr - 1] + $turnsLastIndex % $historyLastIndex] . "\n";
} else {
  echo $ptr . "\n";
}

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

int main(){
  int N;
  cin>>N;
  int s=0;
  int a=N%10;
  int b=N;
  while(1){
    s+=a;
    b=(b-a)/10;
    a=b%10;
    if(b-a==0){
      s+=a;
      break;
    }
  }
  if(N%s==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main() {
	int n;	
	while(cin >> n) {
		if(n == 0) break;
		vector<string> threads(n);
		rep(i, n) cin >> threads[i];

		// "+" ????????????????\?????????????
		rep(i, n) {
			REP(j, 1, threads[i].size()) {
				if(threads[i][j - 1] == '.' && threads[i][j] != '.') {
					threads[i][j - 1] = '+';
					break;
				} 
				else if(threads[i][j - 1] == '.' && threads[i][j] == '.') {
					threads[i][j - 1] = ' ';
				}
			}
		}
	
		// "|" ????????????????\?????????????
		vector<bool> idx(n, false);
		rep(i, n) {	
			rep(j, threads[i].size()) {
				if(j >= n) break;
				
				if(threads[i][j] == '+' && !idx[j]) { 
					idx[j] = true;  
				}
				else if(threads[i][j] == '+' && idx[j]) { 
					for(int k = i-1; k >= 0; --k) {
						if(threads[k][j] != ' ') break;	
						threads[k][j] = '|';
					}
				}	
			}
		}

		rep(i, n) cout << threads[i] << endl;	
		
	}
	return 0;
}

Measured memory_bytes: 1852
#include<stdio.h>
int main(void)
{
	int M1, D1, M2, D2;
	scanf("%d", &M1);
	scanf("%d", &D1);
	scanf("%d", &M2);
	scanf("%d", &D2);
	if (M1 + 1 == M2 || (M1 == 12 && M2 == 1))
		printf("1");
	else
		printf("0");
	return 0;
}

Measured memory_bytes: 128