akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A_TableTennisTraining solver = new A_TableTennisTraining();
        solver.solve(1, in, out);
        out.close();
    }

    static class A_TableTennisTraining {
        final long infinity = Long.MAX_VALUE / 2;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.nextLong();
            long a = in.nextLong() - 1;
            long b = in.nextLong() - 1;
            long ans = infinity;
            ans = Math.min(ans, f(a, b, false, false));
            ans = Math.min(ans, a + f(0, b - a, true, false));
            ans = Math.min(ans, (n - 1 - b) + f(a + (n - 1 - b), n - 1, false, true));
            out.println(ans);
        }

        private long f(long a, long b, boolean aCanWait, boolean bCanWait) {
            if (a % 2 == b % 2) {
                return (b - a) / 2;
            }
            if (aCanWait || bCanWait) {
                return 1 + (b - a - 1) / 2;
            }
            return infinity;
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



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

priority_queue<int> q;

int n,m,ans;

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		q.push(x);
	}
	for(int i=1;i<=m;i++)
	{
		ans+=q.top();
		q.pop();
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 26.05.2018 15:04:10       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = (int) 2e9;
  for (int bound : a) {
    vector<int> c;
    multiset<int> s;
    for (int i = 0; i <= n; i++) {
      if (i == n || a[i] < bound) {
        sort(c.begin(), c.end());
        for (int j = 0; j <= (int) c.size() - k; j++) {
          s.insert(c[j]);
        }
        c.clear();
      } else {
        c.push_back(a[i]);
      }
    }
    if ((int) s.size() < q) {
      continue;
    }
    auto it = s.begin();
    for (int i = 0; i < q - 1; i++) {
      it++;
    }
    ans = min(ans, *it - bound);
  }
  cout << ans << '\n';
  return 0;
}


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

int main() {
int A,B,count=0;
cin>>A>>B;
for(int i=A;i<=B;i++){
string s=to_string(i);
string s1=s;
reverse(s.begin(),s.end());
if(s==s1){
count++;
}
}
cout<<count<<endl;
}

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

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  s1[0]=s1[0]-'a'+'A';
  s2[0]=s2[0]-'a'+'A';
  s3[0]=s3[0]-'a'+'A';
  cout << s1[0] << s2[0] << s3[0] << endl;
  return 0;
}

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

const int mod=(int)1e9+7;
int t[22][22];
int dp[(1<<21)+2];
int add(int a, int b) { return (a+b>=mod) ? a+b-mod : a+b; }

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&t[i][j]);
	dp[0]=1;
	for(int i=1;i<(1<<n);i++)
	{
		int ile=0;
		for(int j=i;j;j>>=1)
			ile+=(j&1);
		for(int j=0;j<n;j++)
			if(t[ile][j+1] && (i&(1<<j)))
				dp[i]=add(dp[i],dp[i^(1<<j)]);
	}
	printf("%d",dp[(1<<n)-1]);
}

Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;
  if(r <= x && x <= w-r && r <= y && y <= h - r){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n;cin>>n;
    cout<<pow(n,3)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
long long int a[200000+50];
int main()
{
	long long int n;
	while(~scanf("%lld",&n))
	{
		long long int i,sum=0,k;
		for(i=0;i<n;i++)
		{
			scanf("%lld",&a[i]);
			sum+=a[i];
		}
		k=fabs(sum-2*a[0]);
		for(i=0;i<n-1;i++)
		{
			sum-=2*a[i];
			if(k>fabs(sum))
				k=fabs(sum);
		}
		if(k<0)
				k*=-1;
		printf("%lld\n",k);
		
	}
}

Measured memory_bytes: 1664
require 'set'
A, B = gets.split.map(&:to_i)

divisors = Set.new
(1..(Math.sqrt(A).to_i)).each do |n|
  next unless A % n == 0
  divisors.add(n) if B % n == 0
  m = A / n
  divisors.add(m) if B % m == 0
end
(1..(Math.sqrt(B).to_i)).each do |n|
  next unless B % n == 0
  divisors.add(n) if A % n == 0
  m = B / n
  divisors.add(m) if A % m == 0
end
sorted = divisors.to_a.sort
ans = 1 # 1
primes = []
sorted.each do |n|
  next if n == 1
  if primes.all? { |pr| n % pr != 0 }
    ans += 1
    primes.push(n)
  end
end
puts ans


Measured memory_bytes: 2552
#include <bits/stdc++.h>
//#include <algorithm>
//#include <stdio.h>
//#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

bool IsPrime(int num) {
	if(num<2) return false;
	else if(num==2) return true;
	else if(num%2==0) return false;

	double sqrtNum=sqrt(num);
	for(int i=3;i<=sqrtNum;i+=2) {
		if(num%i==0) return false;
	}
	return true;
}

int q;
int cnt[100001];

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

	cin>>q;
	for(int i=3;i<=100000;i+=2) {
		if(IsPrime(i)&&IsPrime((i+1)/2)) {
			cnt[i]++;
		}
	}
	FOR(i,1,100001) cnt[i]+=cnt[i-1];

	REP(i,q) {
		int l,r;cin>>l>>r;
		cout<<cnt[r]-cnt[l-1]<<endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

bool cmp (const pl& l, const pl& r) {
    return l.first+l.second < r.first+r.second;
}

int N;
pl p[5000];
ll dp[5001];

int main() {
    cin >> N;
    rep(i,N) cin >> p[i].first >> p[i].second;
    sort(p,p+N,cmp);
    rep(i,N+1) dp[i] = linf;
    dp[0] = 0;
    rep(i,N) {
        for (int j = N; j >= 1; j--) {
            if (dp[j-1] <= p[i].first) dp[j] = min(dp[j], dp[j-1]+p[i].second);
        }
    }
    int ans = 0;
    rep(i,N+1) {
        if (dp[i] == linf) break;
        ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main() {
	int n, x, t;
	scanf("%d", &n);
	scanf("%d", &x);
	scanf("%d", &t);

	printf("%d\n", (n % x == 0) ? t * (n / x) : t * ((n / x) + 1));
	return 0;
}



Measured memory_bytes: 1732
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

#define MAX_SIZE 1000
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

char M[MAX_SIZE][MAX_SIZE];
int H, W;

void bfs(int &sy, int &sx, int &ans, const char g) {
  int D[MAX_SIZE][MAX_SIZE];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      D[i][j] = -1;
    }
  }

  queue<P> que;
  que.push(P(sy, sx));
  D[sy][sx] = 0;
  while (que.size()) {
    P p = que.front(); que.pop();
    if (M[p.first][p.second] == g) {
      sy = p.first;
      sx = p.second;
      ans += D[p.first][p.second];
      break;
    }

    for (int i = 0; i < 4; ++i) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (0 <= ny && ny < H &&
          0 <= nx && nx < W &&
          M[ny][nx] != 'X' &&
          D[ny][nx] == -1) {
        que.push(P(ny, nx));
        D[ny][nx] = D[p.first][p.second] + 1;
      }
    }
  }
}

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

  int sy, sx;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> M[i][j];
      if (M[i][j] == 'S') {
        sy = i;
        sx = j;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bfs(sy, sx, ans, i + 1 + '0');
  }

  cout << ans << endl;

  return 0;
}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

void insertionSort(vector<int> &A, int &N){
    for(int k=0; k<N; k++){
        cout << A[k];
        if(k != N-1) cout << " ";
    }
    cout << endl;
    for(int i=1; i<N; i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int k=0; k<N; k++){
            cout << A[k];
            if(k != N-1) cout << " ";
        }
        cout << endl;
    }
}

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        int Ai; cin >> Ai;
        A[i] = Ai;
    }
    insertionSort(A, N);
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N,M;
  cin>>N>>M;
  int ans=1;
  if(N-M==0){
    for(int i=0;i<N;i++){
      ans*=i+1;
      ans%=1000000007;
    }
    ans*=ans;
    ans%=1000000007;
    ans*=2;
    ans%=1000000007;
    cout<<ans;
  }
  if(N-M==1){
    for(int i=0;i<M;i++){
      ans*=i+1;
      ans%=1000000007;
    }
    ans*=ans;
    ans%=1000000007;
    ans*=N;
    ans%=1000000007;
    cout<<ans;
  }
  if(M-N==1){
    for(int i=0;i<N;i++){
      ans*=i+1;
      ans%=1000000007;
    }
    ans*=ans;
    ans%=1000000007;
    ans*=M;
    ans%=1000000007;
    cout<<ans;
  }
  if(N-M>1||M-N>1)cout<<0;
  cout<<endl;
}


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

#define ll long long

using namespace std;

int main(){
	ll a[30]={0},i;
	char c;
	
	while((c=getchar())!= EOF){
		if(c>='A' && c<='Z') c+='a'-'A';
		if(c>='a' && c<='z') a[c-'a']++;
	}
	for(i=0;i<='z'-'a';i++){
		c=i+'a';
		cout<<c<<" : "<<a[i]<<"\n";
	}
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <limits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;
int n;
long long cnt;

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

    // sol 1 - O(nlogn)
/*    vector<long long> factors(n, 0);
    for (int i = 1; i <= n; ++i) {
        for (int j = i; j <= n; j += i) {
            factors[j]++;
        }
        cnt += factors[i];
    }
    cnt -= factors[n];*/
    for (int a = 1; a <= n-1; ++a) {
        cnt += (n-1) / a;
    }
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 3832
#include<iostream>
using namespace std;
int main()
{
	int l,r,min1=1<<30;
	cin>>l>>r;
	if(r-l>=2018)
	{
		cout<<0;
		return 0;
	}
	for(int i=l;i<=r-1;i++)
		for(int j=i+1;j<=r;j++)
		{
			int a=i%2019,b=j%2019;
			min1=min(min1,a*b%2019);
		}
	cout<<min1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X, Y;
string S, T;

signed main(){
  cin >> X >> Y;
  int ans = 0;
  while(X<=Y){
    ans++;
    X *= 2;
  }
  
  COUT(ans);
  return 0;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rush() int T;scanf("%d",&T);int kase=1;while(T--)
#define all(x) (x).begin(),(x).End()
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define pb(x) push_back(x)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
using std::bitset;
typedef long long ll;
const ll maxn=1e6+5;
const ll mod=998244353;
const ll INF=0x3f3f3f3f3f3f3f3f;
const long double PI=acos(-1.0);
const long double eps=1e-5;
inline ll read(){ll ans=0,flag=1;char c;c=getchar();while(c<'0' || c>'9'){if(c=='-')flag=-1;c=getchar();}while(c>='0' && c<='9'){ans=ans*10+(ll)(c-'0');c=getchar();}return ans*flag;}
ll quickpow(ll x,ll y,ll mod){ll ans=1;while(y){if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}

vector<int>a;

int main()
{
    int n;
    cin>>n;
    a.clear();
    int x;
    cin>>x;
    a.pb(x);
    int ans=1;
    for(int i=0;i<n-1;i++)
    {
        cin>>x;
        int t=a[a.size()-1];
        if(x<t)
        {
            ans++;
            a.pb(x);
        }
    }
    cout<<ans;
    return 0;
}


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

long p = 1000000007;
vector<long> f(100001, -1);

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a;
        cin >> a;
        f[a] = 0;
    }
    rep(i, n+1) {
        if (i == 0) continue;
        if (i == 1 && f[i] == -1) {
            f[1] = 1;
            continue;
        }
        if (i == 2 && f[i] == -1) {
            f[2] = f[1] + 1;
            continue;
        }
        if (f[i] == -1) f[i] = (f[i-1] + f[i-2]) % p;
    }
    cout << f[n]<< endl;
}

Measured memory_bytes: 3884
def calc(ans_list, num):
    ans_2 = []
    for a in ans_list:
        for i in num_list:
            if i not in a:
                t = a + i
                ans_2.append(t)
    if (num < n):
        return calc(ans_2, num + 1)
    return ans_2


n = int(input())
num_list = [str(i) for i in range(1, n + 1)]
p = int("".join(input().split(" ")))
q = int("".join(input().split(" ")))
ans_list = calc(num_list, 2)
ans_list = [int(i) for i in ans_list]
p_num = len([a for a in ans_list if a > p])
q_num = len([a for a in ans_list if a > q])
print(abs(p_num - q_num))

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

typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e6 + 100, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if(a < 0)
		a += MOD;
	else if(a >= MOD)
		a -= MOD;
	return a;
}

int mul(int a, int b) {
	return 1LL * a * b % MOD;
}

int power(int a, int b) {
	int res = 1;
	while(b) {
		if(b & 1)
			res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int n, ans, a[N], px[N], dpA[N], dpB[N], dp[N], ps[N], last[N], help[N];
vector<int> vec[N];

int main() { // 1 basE
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	vec[0].push_back(0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		px[i] = px[i - 1] ^ a[i];
		vec[px[i]].push_back(i);
	}
	
	int round = 0;
	if(px[n] == 0) {
		ans = power(2, vec[0].size() - 2);
		fill(dp, dp + N, 1);
		copy(dp, dp + N, ps);
		for (int i = 1; i <= n; i++)
			if(px[i] == 0) {
				round++;
				unordered_map<int, int> add;
				for (int j = i - 1; px[j]; j--)
					add[px[j]]++;
				for (auto p: add) {
					int x = p.first;
					ps[x] = sum(ps[x], mul(round - 1 - last[x], dp[x] - 1));
					last[x] = round - 1;
				}
				for (auto p: add)
					dp[p.first] = sum(dp[p.first], mul(p.second, ps[p.first]));
			}
		
		for (int i = 0; i < N; i++)
			ans = sum(ans, dp[i] - 1);
		cout << ans;
	}
	
	else {
		int A = 0, B = 0;
		dpB[0] = 1;
		B = 1;
		for (int i = 1; i <= n; i++)
			if(px[i] == 0) {
				dpB[i] = A;
				B = sum(B, dpB[i]);
			}
			else if(px[i] == px[n]) {
				dpA[i] = B;
				A = sum(A, dpA[i]);
			}
		cout << dpA[n];
	}
	return 0;
}

Measured memory_bytes: 89716
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
/*考察
偶数回Tした後の移動はx軸方向の移動
奇数回Tした後の移動はy軸方向の移動である
最も簡単な考えだと
(偶数回Tした後の移動の和)=x
(奇数回Tした後の移動の和)=y
だとただ近づいていくだけでゴールにたどり着ける

 */
int main(){
    string s;
    cin>>s;
    int x,y;
    cin>>x>>y;
    vector<int> ver,hor;
    int c=0,f=1;
    bool beg=(s[0]=='T');
    for(int i=0;i<s.size()+1;i++){
        if(i<s.size()&&s[i]=='F'){
            c++;
        }    
        else{
            if(c==0){f=f*(-1);c=0;}
            else if(f>0){
                hor.push_back(c);f=f*(-1);c=0;
            } 
            else{
                ver.push_back(c);f=f*(-1);c=0;
            }
        }
    }
    //+5000
    bool dpx[hor.size()+1][10000*2+2]={};
    dpx[0][10000]=true;
    rep(i,hor.size()){
        for(int j=0;j<10000*2+2;j++){
            if(dpx[i][j]){dpx[i+1][j+hor[i]]=true;if(i!=0||beg)dpx[i+1][j-hor[i]]=true;}
        }
    }
    bool dpy[ver.size()+1][10000*2+2]={};
    dpy[0][10000]=true;
    rep(i,ver.size()){
        for(int j=0;j<10000*2+2;j++){
            if(dpy[i][j]){dpy[i+1][j+ver[i]]=true;dpy[i+1][j-ver[i]]=true;}
        }
    }
    if(dpx[hor.size()][10000+x]&&dpy[ver.size()][10000+y]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 78464
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
dist = abs(A-B)
delta = V-W
res = 'YES'
if W>V:
    res = 'NO'
else:
    if delta*T >= dist:
        res = 'YES'
    else:
        res = 'NO'
print(res)





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

using namespace std;

int main() {
  int n; cin >> n;
  vector<long long> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  long long maxscore = 0;
  for (int c = 1; c <= n-1; ++c) {
    // k=0 =>  0 -> n-1
    // k=1 =>  0 -> n-1-c  -> c -> n-1
    // k=2 =>  0 -> n-1-2c -> c -> n-1-c -> 2c -> n-1
    long long score = 0;
    for (int k = 1; c*k < n-1; ++k) {
      //    n-1-c*k == c*s
      // or n-1-c*s == c*k
      int l = n-1-c*k, r = c*k;
      if (l % c == 0 && l/c <= k) break;
      if ((n-1-r) % c == 0 && (n-1-r)/c <= k) break;
      if (l <= c) break;
      score += s[l] + s[r];
      maxscore = max(maxscore, score);
    }
  }
  cout << maxscore << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)

template<class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}



//a1,a2,a3,a4
//[a2^a3^a4],[a1^a3^a4],[a1^a2^a4],[a1^a2^a3]
void _main() {
        int n; cin >> n;
        vector<int> vec(n); cin >> vec;
        int xr = 0;
        for (int i = 0; i < n; i++) xr ^= vec[i];
        for (int i = 0; i < n; i++) cout << (xr ^ vec[i]) << ' ';
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 4776
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	string s;
	cin >> s;
	string t;
	cin >> t;
	ll count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == t[i]) {
			count++;
		}
	}
	if (count == s.size()) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3596
while 1:
	n=int(raw_input())
	if n==0:break
	m=int(raw_input())
	a=raw_input()
	P="I"+"OI"*n
	l=1+2*n
	c=0
	for i in range(m-l+1):
		if a[i:i+l]==P:c+=1
	print c

Measured memory_bytes: 36600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n=5;
    vector<int>a(n);
    REP(i,n)IN(a[i]);
    int tmp=0;
    int sum=0;
    REP(i,n){
        tmp=max(tmp,10*((a[i]+9)/10)-a[i]);
        sum+=((a[i]+9)/10)*10;
    }
    sum-=tmp;
    OUT(sum);
    return 0;
}

Measured memory_bytes: 256
/*ABC081A - Placing Marbles*/
#include <iostream>
#include <string>
using namespace std;

int main() 
{
  string s;
  int count=0;

  cin >> s;

  for(int i=0; i<3; i++)
    if( s[i] == '1' ) count++;

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
def inpl(): return list(map(int, input().split()))

N, M = inpl()
G = {i:[] for i in range(N)}
rG = {i: [] for i in range(N)}
X = [0]*(N)
searched = [0]*(N)

for _ in range(N-1+M):
    a, b = inpl()
    G[a-1].append(b-1)
    rG[b-1].append(a-1)
    X[b-1] += 1

q = X.index(0)
T = [0]*N
Q = deque([q])
t = 0
while Q:
    p = Q.popleft()
    T[p] = t
    t += 1
    for q in G[p]:          
        X[q] -= 1
        if X[q] == 0:
            Q.append(q)

for i in range(N):
    c, ans = -1, 0
    for p in rG[i]:
        if c < T[p]:
            c, ans = T[p], p+1
    print(ans)

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

int gcd(int &a, int &b){
  if( a < b ) gcd(b,a);
  ll r;
  while( a % b != 0 ){
    r = a % b;
    a = b;
    b = r;
  }

  return b;
}

int main(){
  int a,b;
  cin >> a >> b;

  cout << gcd(a,b) << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	int a, b;

	std::cin >> a >> b;

	std::cout << std::ceil(((double)a + (double)b) / 2.0) << std::endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;

void solve(){
	int n;
	ll d;
	cin>>n>>d;
	two_sat ts(n);
	vector<ll>x(n),y(n);
	rep(i,n){
		cin>>x[i]>>y[i];
	}
	//x:0,y:1
	rep(i,n){
		REP(j,i+1,n){
			if(abs(x[i]-x[j])<d){
				ts.add_clause(i,1,j,1);
			}
			if(abs(x[i]-y[j])<d){
				ts.add_clause(i,1,j,0);
			}
			if(abs(y[i]-x[j])<d){
				ts.add_clause(i,0,j,1);
			}
			if(abs(y[i]-y[j])<d){
				ts.add_clause(i,0,j,0);
			}
		}
	}
	if(ts.satisfiable()){
		cout<<"Yes\n";
		auto v=ts.answer();
		rep(i,v.size()){
			if(v[i]==0){
				cout<<x[i]<<"\n";
			}
			else{
				cout<<y[i]<<"\n";
			}
		}
	}
	else{
		cout<<"No\n";
	}
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxS =1e5+7;


int main()
{
   ll n;
  cin >> n;
  ll sum=0;
  for(int i=1;i<=n;i++)
  {
    if(i%3!=0&&i%5!=0)
      sum+=i;
  }
  cout << sum << "\n";
  
  
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    string s;
    while(cin>>s){
    	int n1=0,n2=0,len=s.length();
    	for(int i=0;i<len;i++){
    		if(s[i]=='0') n1++;
    	}
    	n2=len-n1;
    	cout<<min(n1,n2)*2<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    int count=0;
    int a,b;
    bool can=false;
    for(int i=0; i<N; i++){
        cin >> p.at(i);
    }

    for(int i=1; i<N+1; i++){
        if( p.at(i-1)!=i and count==0 ){  //昇順ではない時
            a=i;           //来るべき値をaに保持
            b=p.at(i-1);   //実際に入っていた値をbに保持
            count ++;
            continue;
        }
        if( p.at(i-1)!=i and count==1 ){ //二回目の昇順ではない時
            if(i==b and p.at(i-1)==a ){
                can = true;
                count ++;
                continue;
            }else{
                can = false;
                break;
            }
        }
        if( p.at(i-1)!=i and count==2 ){
            can = false;
            break;
        }
    }
    if(can or count==0){
        cout << "YES";
    }else{
        cout << "NO";
    }
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,c,d,x,y,z;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        x=a-c;y=a-b;z=b-c;
        if(x<0) x=-x;
        if(y<0) y=-y;
        if(z<0) z=-z;
        if(x<=d || (y<=d && z<=d))printf("Yes\n");
        else printf("No\n");
        return 0;
}


Measured memory_bytes: 1648
from collections import deque


def main():
    input()  # n
    friendliness = deque(sorted(int(x) for x in input().split()))
    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    while friendliness:
        ans += edges.popleft()
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == '__main__':
    main()


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

using ll=long long; 

struct P{
	int d;
	int v;
	bool operator<(const P& opp)const{
		return v<opp.v;
	}
};

void solve(){
	int x;
	cin>>x;
	int sum=0;
	int cnt=1;
	while(sum<x){
		sum+=cnt;
		cnt++;
	}
	int dif=sum-x;
	cout<<cnt-1<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A,B,D;
void input(){
    fast_io();
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ll a,b; cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
        D.push_back((b-a%b)%b);
    }
    
}

int solve(){
    for (int i = N-2; i >= 0; i--)
    {
        if(D[i]>=D[i+1]) continue;
        ll p = (D[i+1]-D[i]+B[i]-1)/B[i];
        D[i] += p*B[i];
        while(D[i]<D[i+1]) D[i] += B[i];
    }
    DBG(D)
    cout << D[0] << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 2912
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	

	int N;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		if (int(((double)i)*1.08) == N) {
			cout << i;
			return 0;
		}
	}

	cout << ":(";


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string s;
    ll ans=0;
    map<char,int> c;
    cin >> s;
    rep(i,4){
        c[s[i]]++;
        if(c[s[i]]==2) ans++;
    }
    cout << (ans==2?"Yes\n":"No\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

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

int n;
int board[8][8];
bool used[8][8];

bool ok(int y, int x) {
  return 0 <= y && y < n && 0 <= x && x < n;
}

bool solve(int y, int x, int r) {
  if (r < 0) return false;
  if (used[y][x]) return false;
  used[y][x] = true;
  if (r == 0) {
    rep (i, n) rep (j, n) if (!used[i][j] && board[i][j] < 0) {
      bool res = solve(i, j, -board[i][j]);
      used[y][x] = false;
      return res;
    }
    return true;
  }
  rep (k, 4) {
    int ny = y + dy[k];
    int nx = x + dx[k];
    if (!ok(ny, nx)) continue;
    if (board[ny][nx] < 0) continue;
    if (solve(ny, nx, r - board[ny][nx])) return true;
  }
  used[y][x] = false;
  return false;
}

int main() {
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) rep (j, n) cin >> board[i][j];
    rep (i, n) rep (j, n) used[i][j] = false;
    int sum = 0;
    rep (i, n) rep (j, n) sum += board[i][j];
    if (sum != 0) {
      cout << "NO" << endl;
      continue;
    }
    rep (i, n) rep (j, n) if (board[i][j] < 0) {
      if (solve(i, j, -board[i][j])) cout << "YES" << endl;
      else cout << "NO" << endl;
      i = j = n;
    }
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<vector<ll> > dp(n + 1, vector<ll>(2));
  dp[0][0] = 0;
  dp[0][1] = -INF;

  rep(i,n) scanf("%lld", &a[i]);

  int cursor;
  for (int i = 1; i <= n; ++i) {
    cursor = i - 1;
    dp[i][0] = max(dp[cursor][0] + a[cursor], dp[cursor][1] - a[cursor]);
    dp[i][1] = max(dp[cursor][0] - a[cursor], dp[cursor][1] + a[cursor]);
  }

  printf("%lld\n", dp[n][0]);
}


Measured memory_bytes: 6528
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<String> list = new ArrayList<String>();
		for (int i = 0 ; i < N;i++) {
			list.add(scan.next());
		}
		int c1 = 0;
		int c2 = 0;
		int c3 = 0;
		int c4 = 0;
		for (int i=0;i<list.size();i++) {
			if(list.get(i).equals("AC")) {
				c1++;
			}else if(list.get(i).equals("WA")) {
				c2++;
			}else if(list.get(i).equals("TLE")) {
				c3++;
			}else if(list.get(i).equals("RE")) {
				c4++;
			}
		}
		System.out.println("AC x "+c1);
		System.out.println("WA x "+c2);
		System.out.println("TLE x "+c3);
		System.out.println("RE x "+c4);
	}

}


Measured memory_bytes: 54824
import sys
import math

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b=map(str,input().split())

a=int(a)
b=int(float(b)*1000)

print((a*b)//1000)


Measured memory_bytes: 9180
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N = int(input())
    a = list(map(int, input().split()))

    a_pos = []
    n_breaks = 0
    i = 1
    for ai in a:
        if i - ai < 0:
            n_breaks += 1
        else:
            a_pos.append(ai)
            i += 1

    # a[i] - i >= 0 for all i

    # a_ret = []
    if len(a_pos) == 0 or a_pos[0] != 1:
        print(-1)
    else:
        i = 1
        for ai in a_pos:
            if i - ai != 0:
                n_breaks += 1
            else:
                # a_ret.append(ai)
                i += 1
        print(n_breaks)


if __name__ == '__main__':
    main()


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

int main() {
    int n;
    cin >> n;
    int a[n], min = 100000001;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (min >= a[i]) min = a[i];
    }

    for (int i = 1; i <= min; ++i) {
        bool able = true;
        for (int j = 0; j < n; ++j) {
            if (a[j] % i) able = false;
        }
        if (able) cout << i << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3112
#include<cmath>
#include<cstdio>

int N;

int main(){
    scanf("%d",&N);
    int A=0,B=0;
    for(int i=1;i<=N;i++){
        int x;
        scanf("%d",&x);
        A+=x,B+=x*x;
    }
    int k=floor(A*1.0/N+0.5);
    printf("%d",N*k*k-2*A*k+B);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int m;
  while(cin>>m,m){
    using P = pair<int, int>;
    using E = pair<P, P>;
    vector<P> ps(m);
    for(int i=0;i<m;i++){
      cin>>ps[i].first>>ps[i].second;
      ps[i].first+=2020;
      ps[i].second+=2020;
    }
    
    vector<E> es;
    for(int i=0;i<m;i++){
      int j=(i+1)%m;
      es.emplace_back(ps[i],ps[j]);
    }
    
    for(int i=0;i<m;i++){
      if(es[i].first.second>es[i].second.second)
        swap(es[i].first,es[i].second);      
    }
    
    int ans=0;
    auto calc=
      [&](int y,P a,P b){        
        int dy=b.second-a.second;
        if(a.first<=b.first){
          int dx=b.first-a.first;
          P res(a.first+dx*(y-a.second)/dy,
                a.first+dx*(y-a.second)/dy);
          if(dx*(y-a.second)%dy) res.second++;
          return res;
        }else{
          int dx=a.first-b.first;
          P res(a.first-dx*(y-a.second)/dy,
                a.first-dx*(y-a.second)/dy);
          if(dx*(y-a.second)%dy) res.first--;
          return res;
        }
      };
    
    for(int y=0;y<5000;y++){
      vector<P> ss;
      for(int i=0;i<m;i++){
        auto a=es[i].first;
        auto b=es[i].second;
        assert(a.second<=b.second);
        
        if(a.second>y) continue;
        if(b.second<y+1) continue;

        auto c=calc(y,a,b);
        auto d=calc(y+1,a,b);
        ss.emplace_back(min(c.first,d.first),max(c.second,d.second));
      }
      
      sort(ss.begin(),ss.end());
      assert(ss.size()%2==0);
      int prv=0;
      for(int i=0;i<(int)ss.size();i+=2){
        ans+=ss[i+1].second-max(ss[i].first,prv);
        prv=ss[i+1].second;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3004
import numpy as np
N=int(input())
dist=[[0.0 for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j,x in enumerate(map(int,input().split())):
        dist[i][j]=float(x)
dist = np.array(dist)
for i in range(N):
    dist[i,i] = float('inf')
ans=0
for i in range(N):
    for j in range(i+1,N):
        min_=min(dist[i]+dist[j])
        if min_<dist[i,j]:
            ans=-1
            break
        elif min_>dist[i,j]:
            ans+=dist[i,j]
    if ans <0:
        break
print(int(ans))

Measured memory_bytes: 24436
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? ">" : "<"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	char x,y;
	int ans=0;
	cin >>x>>y;
	if (x == y) {
		cout << "=" << endl;
		return 0;
	} else {
		cout << solve(x > y) << endl;
	}
}

Measured memory_bytes: 3608
times = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
a_sum = a.inject{|sum, num| sum + num}
b_sum = b.inject{|sum, num| sum + num}
count = b_sum - a_sum
a.length.times do |i|
  count -= (b[i] - a[i] + 1) / 2 if b[i] > a[i] 
end
message = count >= 0 ? "Yes" : "No"
puts message


Measured memory_bytes: 3196
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

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

Measured memory_bytes: 256
n = int(input())
list = []
for i in range(n):
    a,b=input().split()
    list.append((a, int(b)))
    
s = input()
    
t = 0
for i in range(n):
  if list[i][0] == s:
    for j in range(i+1,n):
      t = t + list[j][1]
    break

print(t)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define f0(a,b) for(lli i=a;i<b;i++)
#define fn(b,a) for(lli i=b;i>a;i--)
#define dbg(x); cout<<"\n"<<#x<<": "<<x;
#define ret return
#define pb push_back
#define pf push_front
#define mp make_pair
#define E9 1000000007
#define E5 100007
#define INF 1e18+7
#define PI 3.1415926
#define sq(a) (a)*(a)
#define fs first
#define sc second
#define el "\n"
#define all(a) a.begin(),a.end()
typedef vector<long long int> vll;
typedef vector<vector<long long int>> vvll;
typedef map<long long int,long long int> mll;
typedef pair<long long int,long long int> pll;
typedef long long int lli;  //  e-18 to e18
void solve(){
    lli n,k;
    cin>>n>>k;
    vector<lli> a(n+1);
    f0(1,n+1) cin>>a[i];
    vll b;
    mll c;
    lli pos=1,h=0;
    while(c.find(pos)==c.end()){
        c[pos]=h++;
        b.pb(pos);
        pos=a[pos];
    }
    if(k<c[pos]){
        cout<<b[k]<<el;
    }
    else{
        k-=c[pos];
        vll d;
        f0(c[pos],b.size()) d.pb(b[i]);
        cout<<d[k%d.size()]<<el;
    }
}
int main(){
    fastIO();
    lli t(1);
    // cin>>t;
    while(t--) solve();
    ret 0; 
}                                                             

Measured memory_bytes: 19036