akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2000 + 10;

ll a[maxn];

map<pair<int,int>, ll>dp[maxn];

int n;

vector<pair<ll, int>>ord;

ll solve(int pos, int l, int r)
{
  if(pos == n)
    return 0;
  if(dp[pos].count({l, r}))
    return dp[pos][{l,r}];
  dp[pos][{l, r}] = 0;
  ll ans = 0; 

  ans = abs(ord[pos].second - l) * ord[pos].first + solve(pos + 1, l + 1, r);
  ans = max(ans, abs(ord[pos].second - r) * ord[pos].first + solve(pos + 1, l,  r - 1));

  return dp[pos][{l,r}] = ans;
}


int main()
{
  ios::sync_with_stdio(0);
  cin >> n;
  
  for(int i = 1; i <= n ; i++)
  {
    cin >> a[i];
    ord.push_back({a[i], i});
  }

  sort(ord.begin(), ord.end(), greater<pair<ll, int>>());

  cout << solve(0, 1, n) << endl;
  return 0;
} 

Measured memory_bytes: 129080
import java.util.Scanner;

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

        for(int i=1; i<=n; i++) {
            if(i % 3 == 0) {
                System.out.print(" " + i);
            } else{
            	for(int j=i; j>0; j/=10) {
            		if (j % 10 == 3) {
                        System.out.print(" " + i);
                        break;
                    }
            	}
            }
        }
        System.out.print("\n");
        sc.close();
    }
}

Measured memory_bytes: 24224
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <queue>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;
int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> goods(N);
	priority_queue<ll, vector<ll>, less<ll>> Q;
	for (ll i = 0; i < N; i++)
	{
		cin >> goods[i];
		Q.push(goods[i]);
	}

	
	while (M > 0)
	{
		ll curr = Q.top();
		Q.pop();
		curr /= 2;
		Q.push(curr);

		// iterate
		M--;
	}

	ll ans = 0;
	while (!Q.empty())
	{
		ans += Q.top();
		Q.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 2168
data = []
for i in range(2):
  data.append(input())

N = data[0]
S = data[1]

N = int(N)

if N%2 == 0:
        M = int(N/2)
        S1 = S[0:M]
        S2 = S[M:N]
        if S1 == S2:
          print('Yes')
        else:
          print('No')
else:
      print('No')

Measured memory_bytes: 3064
T=[(1,2),(2,5),(3,5),(4,4),(5,5),(6,6),(7,3),(8,7),(9,6)]

N,M=map(int, raw_input().split())
A=map(int, raw_input().split())


P=[]
for i in A:
	P.append(T[i-1])


dp=[ None for i in range(N+1) ]
dp[0]=""


for i in range(N):
	#print "i :::: ",i,dp
	if dp[i] is not None:
		for num, match in P:
			if i+match<=N:

				if dp[i+match] is None:
					dp[i+match]=dp[i]+str(num)
				else:
					l1=len(dp[i+match])
					l2=len(dp[i]+str(num))
					if l1>l2:
						pass
					elif l1<l2:
						dp[i+match]=dp[i]+str(num)
					else:
						dp[i+match]=max( dp[i+match] , dp[i]+str(num) )


print dp[N]


Measured memory_bytes: 57500
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long n = scan.nextLong();
        if (n % 2 == 1) {
            System.out.println(0);
            return;
        }
        String s = Long.toString(n);
        long answer = n/10;
        long current = 50;
        while (current <= n) {
            answer += n / current;
            current *= 5;
        }
        System.out.println(answer);
    }
}


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

int dig_sum(int n){
	if(n == 0){
		return 0;
	}
	else{
		return n % 10 + dig_sum(n / 10);
	}
}

int main(){
	int N, A, B, i, ans = 0;
	scanf("%d%d%d", &N, &A, &B);
	for(i = 1; i <= N; i++){
		int d = dig_sum(i);
		if(A <= d && d <= B){
			ans += i;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 19191919;

int main(){
    int n,m;
    while(scanf(" %d %d", &n, &m),n){
        vector<int> a(n);
        rep(i,n) scanf(" %d", &a[i]);

        vector<int> c(1<<n);
        rep(mask,1<<n){
            rep(i,n)if(mask>>i&1) c[mask] += a[i];
        }

        vector<int> dp(m+1,INF);
        dp[0] = 0;
        rep(i,m){
            rep(mask,1<<n){
                if(i+c[mask]>m) continue;
                dp[i+c[mask]] = min(dp[i+c[mask]], dp[i]+1);
            }
        }
        printf("%d\n", dp[m]);
    }
    return 0;
}



Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const double PI = acos(-1);

double SQ(double x) { return x * x; }
double g(double tetha) { return tetha * PI / 180.0; }

double f(double tetha, double a, double b) {
	double hb = b * sin(g(tetha));
	double ap = hb / sin(g(90.0 - tetha));
	return a * (b * ap * 0.5 - SQ(max(0.0, ap - a)) * b * 0.5 / ap);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int a, b; cin >> a >> b;
	int x; cin >> x;
	double lo = 0, hi = 90;
	for (int i = 0; i < 60; i++) {
		double mi = (lo + hi) * 0.5;
		if (f(mi, a, b) < x) lo = mi;
		else hi = mi;
	}
	double ans = 90.0 - hi;
	cout << fixed << setprecision(6) << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;

int main(void){
	cin >> s;
	int cnt=0,ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='R'){
			cnt++;
		}else{
			cnt=0;
		}
		ans=max(ans,cnt);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(){
    int N, K, R,S,P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    string ttt;
    rep(i,K) ttt += 'o';
    ttt += T;

    int cr =0, cs =0, cp =0;
    for(int i=K; i<K+N; i++){
        if(ttt.at(i) == 'r'){
            if(ttt.at(i-K) == 'r') ttt.at(i) = 'o';
            else cr++;
        }
        if(ttt.at(i) == 's'){
            if(ttt.at(i-K) == 's') ttt.at(i) = 'o';
            else cs++;
        }
        if(ttt.at(i) == 'p'){
            if(ttt.at(i-K) == 'p') ttt.at(i) = 'o';
            else cp++;
        }
    }

    int ans = cr*P + cs*R + cp*S;
    cout << ans << endl;
}   

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

long long lcm( long long a, long long b )
{
	return a / __gcd( a, b ) * b;
}

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

	int n = 0;
	for( long long a = A[0]; a % 2 == 0; a /= 2 ) {
		n++;
	}
	for( int i = 1; i < N; i++ ) {
		int nn = 0;
		for( long long a = A[i]; a % 2 == 0; a /= 2 ) {
			nn++;
		}
		if( nn != n ) {
			cout << 0 << endl;
			return 0;
		}
	}
	long long lm = A[0] / 2;
	for( int i = 1; i < N; i++ ) {
		lm = lcm( lm, A[i] / 2 );
	}
	long long ans = M / lm;
	if( ans % 2 ) ans = ans / 2 + 1;
	else ans = ans / 2;

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif


const int MAXN = 100005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n;
ll a, sum;
ll cnt[60];
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;
    REP (j, n) {
        cin >> a;
        for (int i=0;i<60;i++) {
            if ((a>>i) & 1) {
                sum += (1LL<<i) % MOD * (j-cnt[i]);
                sum %= MOD;
                cnt[i]++;
            } else {
                sum += (1LL<<i) % MOD * cnt[i];
                sum %= MOD;
            }
        }
    }

    cout << sum << endl;

}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll D;
    cin >> D;
    vector<ll> c(27,0);
    for(ll i=0;i<26;++i)cin>>c[i+1];
    vector<vector<ll>> S(D+1, vector<ll>(27, 0));
    for(ll i=0;i<D;++i)
        for(ll j=0;j<26;++j)cin>>S[i+1][j+1];
    vector<ll> last(27,0);
    for(ll i=1;i<=D;++i){
        set<P> hoge;
        for(ll j=1;j<=26;++j){
            hoge.insert(P(S[i][j]+c[j]*12,j));
        }
        prt((*--hoge.end()).second);
    }fl

    return 0;
}



Measured memory_bytes: 3744
N,M=map(int, input().split())
H_list=list(map(int, input().split()))
ANS=[1]*N
for i in range(M):
    a,b=map(int, input().split())
    if H_list[a-1]<=H_list[b-1]:
        ANS[a-1]=0
    if H_list[a-1]>=H_list[b-1]:
        ANS[b-1]=0

print(sum(ANS))

Measured memory_bytes: 20092
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("Error.txt", "w", stderr);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i*i<=n;i++)
	{
		for(ll j=i;j<=n;j++)
		{
			if(i*j<n){
				if(i==j)
					ans++;
				else
					ans+=2;
			}
		}
	}
	cout<<ans;
}

int main()
{	
	checkpoint1();
/********************************************************/	
	auto startrrr = high_resolution_clock::now();
	cout << setprecision(20);
/*******************************************************/	
	
	solve();


/*******************************************************/	
	auto stoprrr = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stoprrr - startrrr);
	#ifndef ONLINE_JUDGE
		cerr << "Time: " << duration.count()/1000.0<<"\n";
	#endif
/*******************************************************/		
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
const int MAX_C = 35;
int s[MAX_N],t[MAX_N],c[MAX_N],sums[MAX_N],sumt[MAX_N];
bool cs[MAX_C][MAX_N],ct[MAX_C][MAX_N];

int main()
{
	int N,C;
	cin >> N >> C;
	rep(i,N)
	{
		int p;
		cin >> s[i] >> t[i] >> p;
		c[i] = p-1;
		sums[s[i]]++; sumt[t[i]]++;
		cs[c[i]][s[i]]++; ct[c[i]][t[i]]++;
	}
	rep(i,C)
	{
		rep(j,MAX_N)
		{
			if (cs[i][j] && ct[i][j])
			{
				sums[j]--; sumt[j]--;
			}
		}
	}
	rep(i,MAX_N-1)
	{
		sums[i+1] += sums[i];
		sumt[i+1] += sumt[i];
	}
	/*
	rep(i,15)
	{
		cout << sums[i] << " ";
	}
	cout << endl;
	rep(i,15)
	{
		cout << sumt[i] << " ";
	}
	cout << endl;
	*/
	int ans = 0;
	rep(i,MAX_N-1)
	{
		ans = max(ans,sums[i+1] - sumt[i]);
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

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

    int n;cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    int sm = accumulate(all(a), 0ll);
    int x = 0;

    int mi = inf;
    rep(i, n - 1) {
        x += a[i];
        int y = sm - x;
        chmin(mi, abs(x - y));
    }

    cout << mi << endl;
}


Measured memory_bytes: 1792
r,g,b,n=map(int,input().split())

ans=0
for i in [i*r for i in range(n//r+1)]:
    for j in [i*g for i in range(n//g+1)]:
        A=n-i-j
        if A%b==0 and A>=0:

            ans+=1

print(ans)

Measured memory_bytes: 43996
// Problem : C - Multiplication 3
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define umapii unordered_map<int,int>
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define MP(a,b) make_pair(a,b)
#define debug(x)       cerr<< #x << " : " << x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[i].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll gcd (ll x , ll y){
    if (x < y) swap (x , y);
    while (y){
        ll temp = y;
        y = x % y;
        x = temp; 
    }
    return x;
}

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

void solve(){
 long double a;
 long double b;
 cin >> a >> b;
 // cout<<b<<endl;
 long double c=a*b;
 
 // cout <<bi<<endl;
 ll x=c;
 cout <<x<<endl;
 // cout <<x<<endl;
   
}
int main(){
    IOS;
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
}


Measured memory_bytes: 3812
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

int n,q,k,X;
int rev[N];
int X0,Y0,X1,s,now;

void turn(int t){
	int v=(t-now);
	if (s==1){
		Y0+=v;
		int Y1=Y0+X1-X0;
		if (Y0>=X)X0=X,X1=X,Y0=X;
		else
			if (Y1>X)X1-=Y1-X;
	}
	else{
		Y0-=v;
		int Y1=Y0+X1-X0;
		if(Y1<=0)X0=X,X1=X,Y0=0;
		else
			if (Y0<0)X0-=Y0,Y0=0;
	}
	now=t;
}

int main(){
	X=get();
	k=get();
	fo(i,1,k)rev[i]=get();
	X0=0,Y0=0,X1=X,now=0,s=-1;
	q=get();
	int w=1;
	fo(i,1,q){
		int t=get(),a=get();
		while(w<=k&&rev[w]<t){
			turn(rev[w++]);
			s=-s;
		}
		turn(t);
		if (a<X0)printf("%d\n",Y0);
		if (a>=X0&&a<=X1)printf("%d\n",Y0-X0+a);
		if (a>X1)printf("%d\n",Y0+X1-X0);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;
  
  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,1);
    rep(i,n){
      par[i] = i;
    }
  }
  
  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      size[y] += size[x];
    }
    else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};

int main()
{
  int n,m; cin >> n >> m;
  UFT uf(n);
  while(m-- > 0) {
    int a,b; cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }

  int res = 0;
  rep(i,n) {
    chmax(res, uf.usize(i));
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 5516
#include<stdio.h>
int main()
{
    int N,i,j,count=0;
    scanf("%d",&N);
     for(i=2;i<=9;i++)
        {
    if(((N%i)==0)&&((N/i)==1||(N/i)==2||(N/i)==3||(N/i)==4||(N/i)==5||(N/i)==6||(N/i)==7||(N/i)==8||(N/i)==9))
            count++;
        }
        if(count>0||N==1)
            printf("Yes");
        else
            printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int n;
int A[30];

int ExhaustiveSearch(int,int);

int main(){
    int q,i;

    scanf("%d",&n);
    for(i=0; i<n; i++) scanf("%d",&A[i]);
    scanf("%d",&q);

    for(i=0; i<q; i++){
        int m;
        scanf("%d",&m);
        if(ExhaustiveSearch(0,m)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}

int ExhaustiveSearch(int i,int key){
    if(key == 0) return 1;
    if(i>= n) return 0;

    return ExhaustiveSearch(i+1,key) || ExhaustiveSearch(i+1,key-A[i]);
}



Measured memory_bytes: 2692
#include<bits/stdc++.h>
 
 
using namespace std;
 
#define max(a,b) ((a>b)?a:b)


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    string s,t;



    getline(cin,s);
    getline(cin,t);
 
    int n=s.size(),m=t.size();

    vector< vector<int> > dp(n+1,vector<int>(m+1,0));
        
        
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(s[i-1]==t[j-1])
                    dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                
            }
            
            
        }

int x=dp[n][m];

string alpha="";
 
while(m>0&&n>0)
    {
        if(s[n-1]==t[m-1])
            {
                alpha+=s[n-1];
                n--;
                m--;
 
            }
        else if(dp[n-1][m]>dp[n][m-1])
            n--;
        else m--;
    }
 
 
for(--x;x>-1;x--)
    cout<<alpha[x];


}



Measured memory_bytes: 35584
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <stdio.h>


using namespace std;


int main(){
    double a,b,C,S,L,h;
    cin>>a>>b>>C;
    
    double tmp=b*sin(C*M_PI/180.0);
    S=a*tmp/2;
    
    double d=a-b*cos(C*M_PI/180.0);
    double e=sqrt(d*d+tmp*tmp);
    L=a+b+e;
    h=S*2/a;

    printf("%lf\n",S);
    printf("%lf\n",L);
    printf("%lf\n",h);
    
}



Measured memory_bytes: 3608
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = chunk.split(" ");
  x[0] = Number(x[0])
  x[1] = Number(x[1])
  x[2] = Number(x[2])
  if ((x[0] < x[1]) && (x[1] < x[2])) {
    console.log("Yes")
  }else{
    console.log("No")
  }
}); 

Measured memory_bytes: 7644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n), b(n), res;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	ll sum1 = 0, sum2 = 0;
	rep(i, n) {
		if (a[i] < b[i]) {
			sum1 += b[i] - a[i];
			sum2++;
		}
		if (a[i] > b[i]) res.emplace_back(b[i] - a[i]);
	}
	sort(all(res));

	int i;
	for (i = 0; i < res.size(); ++i) {
		if (sum1 > 0) sum1 += res[i];
		else break;
	}
	if (sum1 > 0) dunk(-1);
	else dunk(i + sum2);
	

	return 0;
}

Measured memory_bytes: 2428
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 998244353;

ll dp[200001];

int main() {
	int N, K;
	cin >> N >> K;

	vector<pair<int, int>> step;
	for (int i=0; i<K; i++) {
		int L, R;
		cin >> L >> R;
		step.push_back(make_pair(L, R));
	}

	dp[1] = 1;
	dp[2] = -1;
	ll S = 0;
	for (int i=1; i<=N; i++) {
		S = (S + dp[i]) % MOD;
		for (auto p : step) {
			int L = p.first;
			int R = p.second;
			if (i+L <= N) {
				dp[i+L] = (dp[i+L] + S) % MOD;
			}
			if (i+R+1 <= N) {
				dp[i+R+1] = (dp[i+R+1] - S + MOD) % MOD;
			}
		}
	}

	ll ans = S;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
#define all int i=0; i<n; i++
#define pb push_back
#define pf push_front
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int> >
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
#define mp make_pair
#define pii pair<int,int>
#define T int t;cin>>t;while(t--)
#define I 
#define Think 
#define We 
#define Should 
typedef long long int ll;

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}

int main(){ 
	FAST_IO;
	int n,ans=0;
	cin>>n;
	int arr[n];
	for(all)cin>>arr[i];
	sort(arr, arr+n);
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			for(int k=j+1; k<n; k++){
				if(arr[i]+arr[j]>arr[k])ans++;
			}
		}
	}
	cout<<ans<<endl;
	I Think We Should return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 998244353

int main() {
	int n = ri();
	int s = ri();
	int a[n];
	for (auto &i : a) i = ri();
	int dp[s + 1];
	memset(dp, 0, sizeof(dp));
	auto add = [] (int &i, int j) {
		i += j;
		if (i >= MOD) i -= MOD;
	};
	int res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = s; j >= 0; j--) {
			if (j + a[i] == s) add(res, (int64_t) dp[j] * (n - i) % MOD);
			if (j + a[i] <= s) add(dp[j + a[i]], dp[j]);
		}
		if (a[i] <= s) add(dp[a[i]], i + 1);
		if (a[i] == s) add(res, (int64_t) (i + 1) * (n - i) % MOD);
	}
	printf("%d\n", res);
	return 0;
}


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

int main() {
  int N, K;
  
  cin >> N >> K;
  vector<int> a(N);
  
  rep(i, N){
    cin >> a.at(i);
  }
  
  for(int i = K; i < N; i++){
    if(a.at(i - K) < a.at(i)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  

}


Measured memory_bytes: 4008
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n = 5, sum = n * (n + 1) / 2;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    sum -= x;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

bool used[11];
int num[11];
int cnt;

void dfs(int pos){
	if(pos==10){
		int tmp=-1;
		int mod=num[9];
		for(int i=0;i<3;i++){
			int sum=0;
			for(int j=0;j<3;j++)sum+=num[i*3+j];
			if(tmp==-1)tmp=sum%mod;
			else if(tmp!=sum%mod)return;
		}
		for(int j=0;j<3;j++){
			int sum=0;
			for(int i=0;i<3;i++)sum+=num[i*3+j];
			if(tmp==-1)tmp=sum%mod;
			else if(tmp!=sum%mod)return;
		}
		int sum=num[0]+num[4]+num[8];
		int sum2=num[2]+num[4]+num[6];
		if(tmp==sum%mod&&tmp==sum2%mod)cnt++;
	}
	else{
		if(num[pos]==0){
			for(int i=1;i<=10;i++){
				if(!used[i]){
					used[i]=true;
					num[pos]=i;
					dfs(pos+1);
					used[i]=false;
					num[pos]=0;
				}
			}
		}
		else dfs(pos+1);
	}
}

int main(){

	while(cin>>num[0]&&num[0]!=-1){
		memset(used,0,sizeof(used));
		if(num[0]!=0)used[num[0]]=true;
		for(int i=1;i<10;i++){
			cin>>num[i];
			if(num[i]!=0)used[num[i]]=true;
		}
		dfs(0);
		cout<<cnt<<endl;
		cnt=0;
	}
	for(int i=1;i<10;i++)cin>>num[i];

	return 0;
}

Measured memory_bytes: 868
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

ll gcd (ll a, ll b) { return (a == 0) ? b : gcd(b % a, a); }
const int N = 100010;
ll n, a[N], pref[N], suff[N];

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	pref[0] = a[0];
	for (int i = 1; i < n; i++) pref[i] = gcd(a[i], pref[i - 1]);
	suff[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--) suff[i] = gcd(a[i], suff[i + 1]);


	ll ans = 1;
	for (int i = 1; i < n - 1; i++) ans = max(ans, gcd(pref[i - 1], suff[i + 1]));
	ans = max(ans, pref[n - 2]);
	ans = max(ans, suff[1]);
	printf("%lld\n", ans);
}

Measured memory_bytes: 2560
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll H, W;
    cin >> H >> W;
    ll ans=1000000000000, mins, maxs;
    ll tmp, tmp1, tmp2, tmp3;
    if(H%3==0 || W%3==0){
        ans = 0;
    }
    for(ll i=1; i<H; i++){
        tmp=W/2;
        tmp1=i*W;
        tmp2=(H-i)*tmp;
        tmp3=(H-i)*(W-tmp);
        maxs = max(tmp1,max(tmp2,tmp3));
        mins = min(tmp1,min(tmp2,tmp3));
        tmp=maxs-mins;
        if(tmp<ans){
            ans=tmp;
        }
        tmp=(H-i)/2;
        tmp1=i*W;
        tmp2=tmp*W;
        tmp3=(H-i-tmp)*W;
        maxs = max(tmp1,max(tmp2,tmp3));
        mins = min(tmp1,min(tmp2,tmp3));
        tmp=maxs-mins;
        if(tmp<ans){
            ans=tmp;
        }
    }
    for(ll i=1; i<W; i++){
        tmp=H/2;
        tmp1=i*H;
        tmp2=(W-i)*tmp;
        tmp3=(W-i)*(H-tmp);
        maxs = max(tmp1,max(tmp2,tmp3));
        mins = min(tmp1,min(tmp2,tmp3));
        tmp=maxs-mins;
        if(tmp<ans){
            ans=tmp;
        }
        tmp=(W-i)/2;
        tmp1=i*H;
        tmp2=tmp*H;
        tmp3=(W-i-tmp)*H;
        maxs = max(tmp1,max(tmp2,tmp3));
        mins = min(tmp1,min(tmp2,tmp3));
        tmp=maxs-mins;
        if(tmp<ans){
            ans=tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())

if a == 1:
  if b == 2:
    print(3)
  elif b == 3:
    print(2)
elif a == 2:
  if b == 1:
    print(3)
  elif b == 3:
    print(1)
elif a == 3:
  if b == 1:
    print(2)
  if b == 2:
    print(1)

Measured memory_bytes: 3060
s = gets.chomp
t = gets.chomp
c1, c2 = {}, {}

s.size.times do |i|
  if c1[s[i]] == nil && c2[t[i]] == nil
    c1[s[i]] = t[i]
    c2[t[i]] = s[i]
  elsif c1[s[i]] != t[i] || c2[t[i]] != s[i]
    puts :No
    exit
  end
end
puts :Yes


Measured memory_bytes: 2752
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

int mod;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	string s;
	int k;
	cin >> s >> k;
	rep(i, s.size()) {
		if (s[i]-'0' > 1 || k - 1 == i) {
			cout << s[i]-'0' << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#pragma region Macros
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7932
#include <stdio.h>

int main(void)
{
	char s[99];
	int n;
	int i;

	scanf("%s", s);

	n = 2;

	/* 文字数を数える。 */
	while (s[n] != '\0')
	{
		n++;
	}
	
	/* sが回文であるかどうか調べる。 */
	for (i = 0; i  < n / 2; i ++)
	{
		if (s[i] != s[n - 1 - i])
		{
			printf("No\n");
			return 0;
		}
	}

	/* s全体が回文なので、前半のみ回文かどうか調べる。 */
	for (i = 0; i < (n - 1) / 4; i++)
	{
		if (s[i] != s[n / 2 - 1 - i])
		{
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

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

        long[] sum = new long[N];
        sum[0] = a[0];
        for(int i = 1; i < N; i++){
            sum[i] = sum[i-1] + a[i];
        }
        long[] diff = new long[N];
        long min = Long.MAX_VALUE;
        for(int i = 0; i < N-1; i++){
            diff[i] = Math.abs(2*sum[i] - sum[N-1]);
            min = Math.min(min, diff[i]);
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 88396
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

map<int,string> namee;
int timee[40][40];
int point[40][40];

int main() {
	int n;
	for(;;){
		cin>>n;
		if(n==0)break;
		namee.clear();
		memset(timee,0,sizeof(timee));
		memset(point,0,sizeof(point));
		for(int i=0;i<n;++i){
			string nm;
			cin>>nm;
			namee[i]=nm;
			int m;
			cin>>m;
			for(int j=0;j<m;++j){
				int x;
				cin>>x;
				timee[i][x]=1;
			}
		}
		for(int i=0;i<n;++i){
			for(int j=0;j<30;++j){
				if(timee[i][j]==0)continue;
				int cnt=0;
				for(int k=0;k<n;++k){
					cnt+=timee[k][j];
				}
				point[i][j]=n+1-cnt;
			}
		}
		int mn=100100100,res=0;
		for(int i=0;i<n;++i){
			int cnt=0;
			for(int j=0;j<30;++j)cnt+=point[i][j];
			if(mn>cnt){
				res=i;
				mn=cnt;
			}else if(mn==cnt){
				if(namee[res]>namee[i]){
					res=i;
				}
			}
		}
		cout<<mn<<" "<<namee[res]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
n,m = map(int,input().split())
bc = {}
a = list(input().split())
for i in a:
  if i in bc:
    bc[i] += 1
  else:
    bc[i] = 1
for i in range(m):
  b,c = input().split()
  b = int(b)
  if c in bc:
    bc[c] += b
  else:
    bc.update({c:b})
key = sorted(bc)
for k in range(len(key)):
  key[k] = int(key[k])
key.sort()
key.reverse()
for k in range(len(key)):
  key[k] = str(key[k])
c = 0
s = 0
for i in key:
  if i in bc:
    s += int(i) * bc[i]
    c += bc[i]
    if c > n:
      s -= int(i) * (c-n)
      c -= c-n
  if c == n:
    break
print(s)

Measured memory_bytes: 52244
h,w,k = map(int,input().split())
import copy
p = []
for i in range(h):
    q = input()
    q = list(q)
    p.append(q)
def kaz(p):
    an = 0
    for i in range(len(p)):
        for j in range(len(p[i])):
            if p[i][j] == '#':
                an += 1
    return an
ans = 0
for i in range(2**(h+w)):
    s = copy.deepcopy(p)
    u = copy.deepcopy(i)
    for j in range(h):
        if u & 1:
            s[j] = [0]*w
        u = u >> 1
    u = copy.deepcopy(i)
    u = u >> h
    for e in range(w):
        if u &1:
            for m in range(h):
                s[m][e] = 0
        u = u >> 1
    if kaz(s) == k:
        ans += 1
print(ans)

Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;

    int v[10][10]={};

    Fr(i,n){
        int a=i%10,b=i;
        while(b>=10) b/=10;
        v[a][b]++;

    }
    ll ans{};
    Fr(i,9) Fr(j,9) ans+=v[i][j]*v[j][i];
    cout<<ans<<endl;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

template<class T>struct dijkstra{
  struct Node{
    vector<T> edges_to;
    vector<T> edges_cost;
    bool done;
    T cost=-1;
  };
  vector<Node> graph;
  void init(T N){
    graph.resize(N);
  }
  void add(T from, T to, T cost){
    graph[from].edges_to.push_back(to);
    graph[from].edges_cost.push_back(cost);
  }
  void shortest(T start){
    priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>> d;
    d.push(make_pair(0,start));
    while(!d.empty()){
      pair<T,T> p = d.top();
      d.pop();
      Node &point = graph[p.second];
      if(point.done) continue;
      point.done = true;
      point.cost = p.first;
      for(T i = 0; i < (T)point.edges_to.size(); i++){
        if(graph[point.edges_to[i]].done)continue;
        d.push(make_pair(point.cost+point.edges_cost[i],point.edges_to[i]));
      }
    }
  }
};

int main() {
  ll N,M;
  cin>>N>>M;
  dijkstra<ll> line;
  line.init(N);
  for(ll i = 0; i < M; i++){
    ll x,y,z;
    cin>>x>>y>>z;
    line.add(x-1,y-1,z);
  }
  for(ll i = 0; i < N-1; i++){
    line.add(i+1,i,0LL);
  }
  line.shortest(0LL);
  cout<<line.graph[N-1].cost<<endl;
}

Measured memory_bytes: 14968
#include<stdio.h>
#include<stdlib.h>
#define N 100
 
int p[N],m[N][N];
 int n;
void matrixChain();
 
int main(){
 
  int i;
 
  scanf("%d",&n);
  for(i=1; i <=n; i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  
  //fprintf(stderr,"err\n");
  matrixChain();
printf("%d\n",m[1][n]);
  return 0;
}
 
void matrixChain(){
  int t,k;
  int i,j;
  int l;
 
  for(i=1; i < n; i++){
    m[i][j]=0;
  }
 
  for(l=2; l <= n; l++){
    for(i=1; i <= n-l+1; i++){
      j=i+l-1;
      m[i][j]=1000000;
    for(k=i; k < j; k++){
      t=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      if(t < m[i][j]) m[i][j]=t;
    }
  }
  }
}

Measured memory_bytes: 636
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int solve(int n)
{
  for (int i = 1000; i <= 11000; i += 1000) {
    const auto x = i - n;
    if (x >= 0) return x;
  }
  return -1;
}

int main()
{
  int n;
  std::cin >> n;

  std::cout << std::setprecision(20);
  std::cout << solve(n) << std::endl;
}


Measured memory_bytes: 3632
#include <iostream>

int main() {
    std::string str;
    std::cin >> str;
//    std::cout << str;

    int sum=0;
    for(int i=0; i<str.length(); i++) {
       sum += str[i] - '0';
    }
    if(sum%9==0) 
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 3756
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,k,m1,m2,fl,ans,a[100005],b[100005],s1[100005],s2[100005];
string s;
int main(){
	in(n);in(k);
    cin>>s;
    if(s[0]=='1')fl=1;
    for(int i=0;s[i];i++){
        if(s[i]=='0'){
            int sum=0;
            while(s[i]=='0'){
                sum++;
                i++;
            }
            a[++m1]=sum;
            i--;
        }
        else{
            int sum=0;
            while(s[i]=='1'){
                sum++;
                i++;
            }
            b[++m2]=sum;
            i--;
        }
    }
    if(m1==0){
        printf("%d\n",n);
        return 0;
    }
    for(int i=1;i<=m1;i++)s1[i]=s1[i-1]+a[i];
    for(int i=1;i<=m2;i++)s2[i]=s2[i-1]+b[i];
    for(int i=1;i<=m1;i++){
        int j=min(i+k-1,m1);
        int sum1=s1[j]-s1[i-1];
        int l=i,r=j;
        if(fl)r++;
        else l--;
        if(l<1)l=1;
        if(r>m2)r=m2;
        int sum2=s2[r]-s2[l-1];
        ans=max(ans,sum1+sum2);
    }
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1280