akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>
#define INF 100000000
#define MOD 1000000007
using namespace std;



int main(){
    int a[26]={};
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        char w;
        cin >> w;
        a[w-'A']=1;
        
    }
    
    int num=a['P'-'A']+a['W'-'A']+a['G'-'A']+a['Y'-'A'];
    if(num==3){
        cout<<"Three"<<endl;
    }else{
        cout<<"Four"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int k;
long long ans,power=1;
inline double div(long long x){
	int sum=0;
	long long tmp=x;
	while(tmp>0){
		sum+=tmp%10;
		tmp/=10;
	}
	return 1.0*x/sum;
}
int main(){
	scanf("%d",&k);
	for(register int i=1;i<=k;i++){
		while(div(ans+power)>div(ans+power*10)){
			power*=10;
		}
		ans+=power;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			String str = in.nextLine();
			if(str.equals("END OF INPUT"))
				return;
			char ch[]=str.toCharArray();
			int c=0;
			for(int i=0; i<ch.length; i++)
			{

				if(ch[i]!=' ')
					c++;
				if(ch[i]==' '||i==ch.length-1)
				{
					if(i+1<ch.length&&ch[i+1]==' ')
					{
						System.out.print(c);
						while(i+1<ch.length&&ch[i+1]==' ')
						{
							System.out.print(0);
							i++;
						}
						c=0;
						continue;
					}
					System.out.print(c);
					c=0;
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc164/abc164_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

/**
 * Sの部分文字列に2019が何個含まれるか？
 *
 * 部分文字列に含まれる約数を数える。
 * n が p の約数 であるとき、p が2,5の倍数でなければ 10n は p の約数である。
 * 部分文字列(i, j)が条件を満たすのは (10 ^ n - j)(Tn-1 - Tn) が p
 * の倍数のとき。 つまり Tn - 1 mod p == Tn mod p
 *
 * modPの数を数えたら、その組み合わせ nC2 の数え上げが答え。
 */
int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int N = S.size();
  int p = 2019;
  vector<int> a(N);
  rep(i, N) { a[i] = S[i] - '0'; }
  reverse(a.begin(), a.end());

  map<int, int> m;
  int t = 0;
  rep(i, N) {
    t += a[i] * modpow(10, i, p) % p;
    t %= p;
    m[t]++;
  }

  ll ans = m[0];
  for(auto kv : m) {
    ans += kv.second * (kv.second - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4332
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		rep(i,n){
			int a,b,c,d,e,f,g,h;
			cin>>a>>b>>c>>d>>e>>f>>g>>h;
			int x=a*e-b*f-c*g-d*h;
			int y=a*f+b*e+c*h-d*g;
			int z=a*g-b*h+c*e+d*f;
			int q=a*h+b*g-c*f+d*e;
			cout<<x<<" "<<y<<" "<<z<<" "<<q<<endl;
		}
	}
}

Measured memory_bytes: 1160
N = int(input())
B = [int(x) - 1 for x in input().split()]
#  print('b', B)
ans = []
while B:
    popped = -1
    for i in reversed(range(len(B))):
        if B[i] == i:
            ans.append(i + 1)
            popped = B.pop(i)
            break
    if popped == -1:
        print(-1)
        quit()
print(*ans[::-1], sep="\n")


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

int main() {
  int n,m,a,b,ans;
  cin >> n >> m;
  ans = n;
  vector<int> h(n);
  vector<bool> hi(n);
  for(int i = 0; i < n; i++){
    cin >> h.at(i);
    hi.at(i) = true;
  }
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    if(h.at(a - 1) > h.at(b - 1)){
      if(hi.at(b - 1)){
        hi.at(b - 1) = false;
        ans--;
      }
    }else if(h.at(a - 1) < h.at(b - 1)){
      if(hi.at(a - 1)){
        hi.at(a - 1) = false;
        ans--;
      }
    }else{
      if(hi.at(a - 1)){
        hi.at(a - 1) = false;
        ans--;
      }
      if(hi.at(b - 1)){
        hi.at(b - 1) = false;
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3788
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
#mod = 10**9 + 7
mod = 998244353

N, M, K = rl()

class CombMod:
	def __init__(self, N):
		self.fact = [1]
		self.rfact = [1]
		for i in range(1, N+1):
			self.fact.append(self.fact[i-1]*i % mod)
			self.rfact.append(pow(self.fact[i], mod-2, mod))

	def comb(self, n, k):
		return self.fact[n]*self.rfact[k]*self.rfact[n-k] % mod

cm = CombMod(N-1)

ans = 0
for k in range(K+1):
	ans = (ans + M * pow(M-1, N-1-k, mod) * cm.comb(N-1, k)) % mod
print(ans)


Measured memory_bytes: 98620
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

const int MAXH = 503;
const int MAXW = 503;
int H, W;
char G[MAXH][MAXW];
vector<pair<int,int> > pos[26];
int btween[26][2];

int main() {
  while(cin >> H >> W && (H|W)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	cin >> G[i][j];
      }
    }

    for(int i = 0; i < 26; ++i) pos[i].clear();
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	if(isalpha(G[i][j])) {
	  int k = G[i][j]-'A';
	  pos[k].push_back(make_pair(j,i));
	  sort(pos[k].begin(), pos[k].end());
	}
      }
    }

    fill(btween[0], btween[26], 1<<26);
    for(int k = 0; k < 26; ++k) {
      if(pos[k].empty()) continue;
      if(0) {
      } else if(pos[k][0].first == pos[k][1].first) {
	int begin = min(pos[k][0].second, pos[k][1].second);
	int end = max(pos[k][0].second, pos[k][1].second);
	if(end - begin == 1) continue;
	btween[k][0] = 0;
	int j = pos[k][0].first;
	for(int i = begin+1; i < end; ++i) {
	  if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
	}
      } else if(pos[k][0].second == pos[k][1].second) {
	int begin = min(pos[k][0].first, pos[k][1].first);
	int end = max(pos[k][0].first, pos[k][1].first);
	if(end - begin == 1) continue;
	btween[k][0] = 0;
	int i = pos[k][0].second;
	for(int j = begin+1; j < end; ++j) {
	  if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
	}
      } else if(pos[k][0].second < pos[k][1].second) {
	btween[k][0] = btween[k][1] = 0;
	for(int i = pos[k][0].second+1, j = pos[k][0].first;
	    i < pos[k][1].second; ++i) {
	  if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
	}
	for(int i = pos[k][1].second, j = pos[k][0].first;
	    j < pos[k][1].first; ++j) {
	  if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
	}

	for(int i = pos[k][0].second, j = pos[k][0].first+1;
	    j < pos[k][1].first; ++j) {
	  if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
	}
	for(int i = pos[k][0].second, j = pos[k][1].first;
	    i < pos[k][1].second; ++i) {
	  if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
	}
      } else {
	btween[k][0] = btween[k][1] = 0;
	for(int i = pos[k][0].second-1, j = pos[k][0].first;
	    i > pos[k][1].second; --i) {
	  if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
	}
	for(int i = pos[k][1].second, j = pos[k][0].first;
	    j < pos[k][1].first; ++j) {
	  if(isalpha(G[i][j])) btween[k][0] |= ( 1<<(G[i][j]-'A') );
	}

	for(int i = pos[k][0].second, j = pos[k][0].first+1;
	    j < pos[k][1].first; ++j) {
	  if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
	}
	for(int i = pos[k][0].second, j = pos[k][1].first;
	    i > pos[k][1].second; --i) {
	  if(isalpha(G[i][j])) btween[k][1] |= ( 1<<(G[i][j]-'A') );
	}
      }
    }

    int bit = 0;
    while(1) {
      bool flag = false;
      for(int i = 0; i < 26; ++i) {
	if(bit & (1<<i)) continue;
	if((btween[i][0] & ~bit) == 0 || (btween[i][1] & ~bit) == 0) {
	  bit |= (1<<i);
	  flag = true;
	  break;
	}
      }
      if(!flag) break;
    }
    cout << __builtin_popcount(bit)*2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1448
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>

using namespace std;
const int MOD=2e5+10;

int main()
{
    int n,left,right;
	LL A[MOD],ans=0;
	LL sum,sumx;

	cin>>n;
	
	rep(i,n) {
		cin>>A[i];
	}
	
	left=right=0;
	sum=sumx=A[0];
	
	while(1) {
		while(right<n-1) {
			if((sumx^A[right+1])!=sum+A[right+1]) break;
			right++;
			sumx^=A[right];
			sum=sumx;
		}
		ans+=(right-left+1);
		
		sumx^=A[left];
		sum-=A[left];
		if(left>=n-1) break;
		left++;
	}
	
	cout<<ans;
		
	rt0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  for(int i=K; i<N; i++){
    if(vec[i] > vec[i-K]){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4012
def solve():
	from collections import deque
	n,*l=map(int,open(0).read().split())
	con=[[] for _ in range(n)]
	dist=[None]*n
	dist[0]=0
	for a,b,c in zip(*[iter(l)]*3):
		con[a-1]+=[(b-1,c%2)]
		con[b-1]+=[(a-1,c%2)]
 
	stk=deque([0])
	while stk:
		cur=stk.pop()
		for nxt,d in con[cur]:
			if dist[nxt]==None:
				stk.append(nxt)
				dist[nxt]=(dist[cur]+d)%2

	print(*dist,sep="\n")

if __name__=="__main__":
	solve()

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

typedef long long Int;


int main(){
	Int n, dp[19][19][19];
	string str;
	Int cnt = 0;
	cin >> n;
	cin >> str;
	
	for(Int i = 0;i < (1 << n);i++){
		string a,b;
		for(Int j = 0;j < n;j++){
			if((i >> j) % 2 == 1)a += str[j];
			else b += str[j];
		}
		dp[0][0][0] = 1;
		for(Int i = 0;i <= n;i++){
			for(Int j = 0;j <= a.size();j++){
				for(Int k = 0;k <= b.size();k++){
					Int &res = dp[i][j][k];
					if(i == 0 && j == 0 && k == 0){res = 1;continue;}
					if(i == 0){res = 0;continue;}
					res = 0;
					if(j > 0 && str[n+i-1] == a[a.size() - j]){
						res += dp[i-1][j-1][k];
					}
					if(k > 0 && str[n+i-1] == b[b.size() - k]){
						res += dp[i-1][j][k-1];
					}
				}
			}
		}
		cnt += dp[n][a.size()][b.size()];
	}

	cout << cnt << endl;
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<ll>>;

int main(){
  int N; cin>>N;
  vector<int> A(N+1); rep1(i,N)cin>>A.at(i);
  int M = 0;
  vector<int> B(N+1,0);
  for(int i = N; i >= 1; i--){
    int tmp = 0;
    for(int j = 2; i*j <= N; j++){
      tmp += B.at(j*i);
    }
    if(tmp%2!=A.at(i)){
      B.at(i)++;
      M++;
    }
  }
  cout<<M<<endl;
  rep1(i,N)if(B.at(i))cout<<i<<" ";
  cout<<endl;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 310000;
#define LL long long
int ai[N];
priority_queue <int> H;
LL ans[N], sum, finans;
int main()
{
    cin >> n;
    for (int i = 1; i <= n * 3; ++ i) cin >> ai[i];
    sum = 0;
    for (int i = 1; i <= n; ++ i) H.push(-ai[i]), sum += ai[i];
    ans[n] = sum;
    for (int i = n + 1; i <= n * 2; ++ i)
    {
        H.push(-ai[i]); sum += ai[i];
        int x = -H.top(); H.pop();
        sum -= x;
        ans[i] = sum;
    }

    while (!H.empty()) H.pop();
    sum = 0;
    for (int i = n * 3; i > n * 2; -- i) H.push(ai[i]), sum += ai[i];
    ans[n * 2] -= sum;
    for (int i = n * 2; i > n; -- i)
    {
        H.push(ai[i]); sum += ai[i];
        int x = H.top(); H.pop();
        sum -= x;
        ans[i - 1] -= sum;
    }
    finans = -1e18;
    for (int i = n; i <= n * 2; ++ i) finans = max(finans, ans[i]);
    cout << finans;
}


Measured memory_bytes: 2680
N = int(input())
 
aa = [0] + list(map(int, input().split())) + [0]
 
 
dd = [0] * (N + 1)
for i in range(1, N + 2):
    dd[i - 1] = abs(aa[i] - aa[i - 1])
 
S = sum(dd)
 
for i in range(1, N + 1):
    print(S - dd[i] - dd[i - 1] + abs(aa[i + 1] - aa[i - 1]))

Measured memory_bytes: 14176
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	ll N; cin >> N;
	ll ans = 0;
	for (int n = 1; n <= N; n++) {
		if (n % 3 != 0 && n % 5 != 0) ans += n;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3672
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int a,b;
    cin >> a >> b;
    if( ((a == 1)&&(b == 2))|| ((a == 2)&&(b == 1)) ){
        cout << "3" << endl;
    }else if( ((a == 2)&&(b == 3))|| ((a == 3)&&(b == 2)) ){
        cout << "1" << endl;
    }else{
        cout << "2" << endl;
    }
}

Measured memory_bytes: 888
H, W = map(int, input().split())

remove = "." * W
A = []
for i in range(H):
    a = input()
    if a != remove:
        A.append(list(a))

remove_list = []
# print(A)
for i in range(W):
    if A[0][i] == ".":
        aa = A[0][i]
        flag = 0
        for a in A:
            if aa != a[i]:
                flag = 1
                break
        if flag == 0:
            remove_list.append(i)

# print(remove_list)

for a in A:
    print_list = []
    for idx, a_ in enumerate(a):
        if idx not in remove_list:
            print_list.append(a_)
    print("".join(print_list))

Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m,k;
  cin>>n>>m>>k;
  int now=0;
  if(k==0){cout<<"Yes"<<endl;return 0;}
  rep(i,m){
    now=n*(i+1);
    //cout<<now<<endl;
    if(k==now){cout<<"Yes"<<endl;return 0;}
    rep(j,n){
      now+=m-((i+1)*2);
      //cout<<now<<endl;
      if(k==now){cout<<"Yes"<<endl;return 0;}
    }
  }
  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>
typedef long long ll;
using namespace std;

ll row[3000][3000];
ll col[3000][3000];
string s[3000];
ll h,w;
ll dfsr(ll c,ll r, ll cnt){
  if(r>=w)return cnt;
  if(s[c][r]=='#')return cnt;
  else return row[c][r] = dfsr(c,r+1,cnt+1);
}
ll dfsc(ll c,ll r, ll cnt){
  if(c>=h) return cnt;
  if(s[c][r]=='#')return cnt;
  else return col[c][r] = dfsc(c+1,r,cnt+1);
}

int main(){
  ll i,j,k,n,m;
  cin >> h >> w;
  for(i=0;i<h;i++)cin >> s[i];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]=='.'){
        if(row[i][j]==0)row[i][j]=dfsr(i,j,0LL);
        if(col[i][j]==0)col[i][j]=dfsc(i,j,0LL);
      }
    }
  }
  ll ret = 0;
  ll x,y;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]=='.'){
        ll br = ret;
        ret = max(ret,row[i][j]+col[i][j]);
        if(br<ret){
          x=i,y=j;
        }
      }
    }
  }
  //cout << x << " " << y << endl;
  //cout << row[1][0] << " " << col[1][0] << endl;
  cout << ret-1 << endl;
  return 0;
}


Measured memory_bytes: 100352
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];

    ll sum=0, an=0, bn=0, sumn=0;
    for(an=0; an<n;){
        if(sum + a[an]<= k){
            sum += a[an];
            ++an;
        }else{
            break;
        }
    }

    for(bn=0; bn<m;){
        if(sum + b[bn]<= k){
            sum += b[bn];
            ++bn;
        }else{
            break;
        }
    }
    
    sumn = bn+an;
    if(sumn==m+n){
        cout << sumn << endl; return 0;
    } 

    ll rest=k-sum;

    for(; an>0;){
        --an;
        rest += a[an];
        while(rest-b[bn]>=0 && bn<m){
            rest-=b[bn];
            bn++;
            chmax(sumn, bn+an);
        }
    }
    cout << sumn << endl;

    return 0;
}


Measured memory_bytes: 6432
pub mod io {
    use std::io;

    pub fn read_line() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }

    pub trait Read {
        fn read(s: &str) -> Self;
    }

    macro_rules! def_read {
        ($t: ty) => {
            impl Read for $t {
                fn read(s: &str) -> $t {
                    s.parse().unwrap()
                }
            }
        }
    }

    def_read!(i32);
    def_read!(i64);
    def_read!(isize);
    def_read!(usize);
    def_read!(f64);

    impl<T: Read> Read for Vec<T> {
        fn read(s: &str) -> Self { s.split_whitespace().map(|w| T::read(w)).collect() }
    }

    macro_rules! def_read_tuple {
        ($($t: ident),*) => {
            impl<$($t : Read + Default),*> Read for ($($t),*) {
                fn read(s: &str) -> Self {
                    let ws = s.split_whitespace().collect::<Vec<_>>();
                    let mut i = 0;
                    ( $({i += 1; $t::read(ws[i - 1])}),* )
                }
            }
        };
    }

    def_read_tuple!(T0, T1);
    def_read_tuple!(T0, T1, T2);
    def_read_tuple!(T0, T1, T2, T3);
    def_read_tuple!(T0, T1, T2, T3, T4);

    pub fn readln<T: Read>() -> T { T::read(&read_line()) }
}

fn mov(mut sx: i32, mut sy: i32, mut tx: i32, mut ty: i32) {
    while (sy != ty) {
        if (sy < ty) {
            print!("U");
            sy+=1;
        }
        else {
            print!("D");
            sy-=1;
        }
    }

    while (sx != tx) {
        if (sx < tx) {
            print!("R");
            sx+=1;
        }
        else {
            print!("L");
            sx-=1;
        }
    }
}

fn main() {
    let (sx, sy, tx, ty): (i32, i32, i32, i32) = io::readln();

    mov(sx, sy, tx, ty);
    mov(tx, ty, sx, sy);

    print!("L");
    mov(sx-1, sy, tx, ty+1);
    print!("DR");
    mov(tx+1, ty, sx, sy-1);
    print!("U");

    println!("");
}


Measured memory_bytes: 380
#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 all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  sort(all(v));
  reverse(all(v));
  ll ans = 0;
  int x = n - 1;
  rep(i,n){
    int cnt = 2;
    if(i == 0)cnt = 1;
    rep(j,cnt){
      if(x > 0){
        ans += v[i];
        x--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	sort(S.begin(), S.end(), greater<int>());
	for (auto i = 0; i < N; ++i)
	{
		if (S[0] == A[i])
		{
			cout << S[1] << endl;
		}
		else
		{
			cout << S[0] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3200
$m=$<.map(&:chop)*""
def f i
$m[i]==?1&&($m[i]=?/
i%12>0&&f(i-1)
i%12<11&&f(i+1)
i%144>11&&f(i-12)
i%144<132&&f(i+12)
1)end
j=c=0
(f(j)&&c+=1
j%144>142&&(p c
c=0)
j+=1)while$m[j]

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll n, ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    ans = n / 500;
    ans *= 1000;
    n %= 500;
    ans += (n - (n % 5));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 2e6 + 10;
const int mod = 1e9 + 7;

ll fac[N], inv[N];

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

void init() {
	fac[0] = 1;
	for (int i = 1; i < N; i++) 
		fac[i] = fac[i - 1] * i % mod;
	inv[N - 1] = binpow(fac[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--) 
		inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) {
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main() {
	init();
	int k; string s; cin >> k >> s;
	int n = k + s.size();
	ll ans = 0;
	for (int i = s.size(); i <= n; i++)
		ans += C(n, i) * binpow(25, n - i) % mod, ans %= mod;
	cout << ans << "\n";
}

Measured memory_bytes: 36560
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;

int main(int argc, char* argv[]){
  int a,i=5;
  cin >> a;
  int num[6] ={2,4,8,16,32,64};
  while(1){
    if (a>=num[i]){
      break;
    }else{
      i-=1;
    }
  }
  cout << num[i] << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    c = input()
    r = c.count('R')
    w = c.count('W')
    ropt = c[:r].count('R')
    wopt = c[r:].count('W')

    rnot = r - ropt
    wnot = w - wopt

    return min(rnot,wnot)
    
 
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 63180
#include<iostream>
#include<cstdio>
#include<cstdlib>

using namespace std;

int main(){
    
    char s[40][40];
    int h,w,cnt;
    
    cin >> h >> w;
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    
    cnt = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<h;k++){
                for(int l=0;l<w;l++){
                    if(s[i][j] == 'B' && s[k][l] == 'B') cnt = max(cnt,abs(i-k)+abs(j-l));
                }
            }
        }
    }
    
    cout << cnt << endl;
    
    return(0);
}


Measured memory_bytes: 3244
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: i32 = 1000000007;

#[fastout]
fn main() {
  input! {
    r: f64,
  }
  println!("{}", r * 2.0 * std::f64::consts::PI);
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

void dfs(const vvi& g, vector<bool>& seen, vi& d, vi& f, int& t, int v) {
    stack<int> st;
    st.push(v);
    d[v] = t++;
    seen[v] = true;

    while (!st.empty()) {
        int v = st.top();

        bool finished = true;
        for (auto itr = g[v].begin(); itr != g[v].end(); ++itr) {
            if (!seen[*itr]) {
                seen[*itr] = true;
                d[*itr] = t++;
                st.push(*itr);
                finished = false;
                break;
            }
        }

        if (finished) {
            st.pop();
            f[v] = t++;
        }
    }
}

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

    int n;
    cin >> n;

    vvi g(n);
    rep(i, 0, n) {
        int u, k;
        cin >> u >> k;

        rep(j, 0, k) {
            int v;
            cin >> v;
            g[u - 1].push_back(v - 1);
        }
    }

    int t = 1;

    vi d(n), f(n);
    vector<bool> seen(n, false);

    rep(i, 0, n) {
        if (!seen[i]) { dfs(g, seen, d, f, t, i); }
    }

    rep(i, 0, n) { cout << i + 1 << " " << d[i] << " " << f[i] << endl; }

    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n;
    cin >> n;

    if (n == 1)
        cout << "Hello World";
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}

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

using namespace std;

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

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    vector<vector<Pii>> prev(n+1, vector<Pii>(m+1, {0, 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] = dp[i-1][j-1] + 1;
                prev[i][j] = {i-1, j-1};
            }

            if(dp[i][j] < dp[i-1][j]) {
                dp[i][j] = dp[i-1][j];
                prev[i][j] = {i-1, j};
            }

            if(dp[i][j] < dp[i][j-1]) {
                dp[i][j] = dp[i][j-1];
                prev[i][j] = {i, j-1};
            }
        }
    }

    vector<char> ans;
    {
        int i = n, j = m, pi, pj;;
        while(i > 0 && j > 0) {
            tie(pi, pj) = prev[i][j];
            if(pi == i-1 && pj == j-1 && s[i-1] == t[j-1]) {
                ans.push_back(s[i-1]);
            }
            i = pi;
            j = pj;
        }
    }
    reverse(ans.begin(), ans.end());
    for(char c: ans) cout << c;
    cout << endl;

}


Measured memory_bytes: 106112
#include<stdio.h>
int main(){
    int a,b,c,d;scanf("%d %d %d %d",&a,&b,&c,&d);
    int x=c-a;
    int y=d-b;
    printf("%d %d %d %d\n",c-y,d+x,a-y,b+x);
}

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

const int MAXN = int( 2e5 );

int N;
int X[ MAXN ], Y[ MAXN ];

signed main() {
  ios::sync_with_stdio( 0 );
  cin >> N;
  for( int i = 0; i < N; ++i ) {
    cin >> X[ i ] >> Y[ i ];
  }
  long long ans = 1LL * 1e18;
  int mine = min( *min_element( X, X + N ), *min_element( Y, Y + N ) );
  int maxe = max( *max_element( X, X + N ), *max_element( Y, Y + N ) );
  { // case 1
    int max_min = 0, min_max = int( 1e9 ) ;
    for( int i = 0; i < N; ++i ) {
      max_min = max( max_min, min( X[ i ], Y[ i ] ) );
      min_max = min( min_max, max( X[ i ], Y[ i ] ) );
    }
    ans = 1LL * ( max_min - mine ) * ( maxe - min_max );
  }
  { // case2
    priority_queue< pair< int, int > > pq;
    multiset< int > bag;
    for( int i = 0; i < N; ++i ) {
      pq.emplace( -min( X[ i ], Y[ i ] ), max( X[ i ], Y[ i ] ) );
      bag.emplace( min( X[ i ], Y[ i ] ) );
    }
    ans = min( ans, 1LL * ( maxe - mine ) * ( *--bag.end() - *bag.begin() ) );
    for( int i = 0; i < N; ++i ) {
      int s, t;
      tie( s, t ) = pq.top();
      pq.pop();
      bag.erase( bag.find( -s ) );
      bag.emplace( t );
      ans = min( ans, 1LL * ( maxe - mine ) * ( *--bag.end() - *bag.begin() ) );
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12784
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using LL = long long;

const int N = 2000005;
int a[N];

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

	LL res = 0;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);

	sort(a + 1, a + n + 1, greater<int>());

	int p = n - 2;
	res = a[1];

	for (int i = 2; i <= n; ++i)
	{
		if (p >= 2) { res += a[i] * 2, p -= 2; continue; }
		if (p == 1) { res += a[i], p -= 1; break; }
		if (p == 0) break;
	}
	cout << res << endl;


	return 0;
}


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

typedef long long LL;

const int N=200000,INF=(1<<30)-1;

int n,a[N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
}

struct state{
  int v,p0,p1;
}dp[N+9];
int mn[5];

void Get_mn(int i,int p,int v){
  if (p>a[i-1]) return;
  int t=a[i]-a[i-1]+p;
  mn[v]=min(mn[v],max(p,t));
  mn[v+1]=min(mn[v+1],max(min(p,t),0));
  mn[v+2]=0;
}

void Get_dp(){
  dp[0].p0=dp[0].p1=1;
  for (int i=1;i<=n+1;++i){
	for (int j=0;j<5;++j) mn[j]=a[i]+1;
	Get_mn(i,0,2);
	Get_mn(i,dp[i-1].p0,1);
	Get_mn(i,dp[i-1].p1,0);
	for (int j=0;j<5;++j){
	  if (mn[j]==a[i]+1) continue;
	  dp[i].v=dp[i-1].v+j;
	  dp[i].p1=mn[j];
	  dp[i].p0=mn[j+1];
	  break;
	}
  }
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",dp[n+1].v-!dp[n+1].p0-!dp[n+1].p1);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 6804
import sys
#import cython

def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    #N: cython.longlong = 0
    N = read()
    print("hon" if N[-1] in '24579' else "pon" if N[-1] in '0168' else "bon")
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9032
#include <iostream>
#include<string>
#include<algorithm>
#include<stdio.h>

using namespace std;

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

    if(a==b){
        cout<<"Draw"<<endl;
        return 0;
    }
    if(a==1)a+=13;
    if(b==1)b+=13;

    cout<<(a>b?"Alice":"Bob")<<endl;
    return 0;

}

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

using namespace std;

int main() {
  int group[] = {0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
  int x, y;
  cin >> x >> y;
  if (group[x] == group[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
# AGC032B - Balanced Neighbors
def main():
    N = int(input())
    if N % 2:
        V = [(i, N - i) for i in range(1, N // 2 + 1)]  # pairs of vertices
        V += [(N,)]
    else:
        V = [(i, N - i + 1) for i in range(1, N // 2 + 1)]
    E, l = [], len(V)  # edges
    for i in range(l - 1):
        E += [(v, u) for v in V[i] for u in V[i + 1]]
    if l >= 3:
        E += [(v, u) for v in V[0] for u in V[-1]]
    print(len(E))
    print("\n".join(["{} {}".format(v, u) for v, u in E]))


if __name__ == "__main__":
    main()

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

int main()
{
    char a[120];
    ll i,j,k,n,l,c=0;
    scanf("%s",a);
    l=strlen(a);
    for(i=0;i<l/2;i++)
    {
       if(a[i]!=a[l-(i+1)]) c++;
    }
     printf("%lld\n",c);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define INF (1LL << 60)

void solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> csum(N+1);
    for1(i,N) {
        cin >> A[i];
    }
    csum[0] = 0;
    for1(i,N) {
        csum[i+1] = csum[i] + A[i];
    }
    ll ans = INF;
    for2(i,1,N) {
        ans = min(ans, abs(csum[N] - csum[i] - csum[i]));
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 3456
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=[int(input()) for i in range(n)]
ans=0
for i in range(n):
    ans+=a[i]//2
    if a[i]%2 and i!=n-1 and a[i+1]>0:
        a[i+1]-=1
        ans+=1

print(ans)

Measured memory_bytes: 44380
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n; cin >> n;
    vector<int>p(n);
    vector<int>a(n,0),b(n);
    for(auto & e : p) cin >> e;
    int base = 20001;//minimum value
    for(int i = 0; i < n;i++){
        a[i] += base*(i+1);
        b[i] =  base*(n-i-1)+1;
        a[p[i]-1] += (i+1);
    }
    for(int i = 0; i < n;i++)
        cout << a[i] << (i != n-1 ? " " : "\n");
    for(int i = 0; i < n;i++)
        cout << b[i] << (i != n-1 ? " " : "\n");
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
bool sortbysec(const pair<pair<string,int>,int> &a, 
              const pair<pair<string,int>,int> &b) 
{ 
	if(a.first.first==b.first.first)
		return a.first.second > b.first.second;
    return (a.first.first < b.first.first); 
} 
int main()
{
	fast;
	ll n;
	cin>>n;
	vector <pair<pair<string,int>,int>> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i].first.first;
		cin>>v[i].first.second;
		v[i].second=i+1;
	}
	sort(v.begin(),v.end(),sortbysec);
	for(int i=0;i<n;i++)
		cout<<v[i].second<<endl;
	return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'

const int mod = 998244353;

class segtree{
	int sz;
	vector<int>adds;
	vector<int>cnt;
public:
	segtree (int n){
		sz=1;
		while(sz<n){
			sz = sz*2;
		}
		adds.assign(2*sz,0LL);
		cnt.assign(2*sz,0LL);
	}
	void make(int l,int r,int v,int start,int left,int right){
		if(left>=r || right<=l){
			return;
		}
		if(left>=l && right<=r){
			adds[start]=(adds[start]+v)%mod;
			return;
		}
		int mid=(left+right)/2;
		make(l,r,v,2*start+1,left,mid);   
		make(l,r,v,2*start+2,mid,right);
	}
	void make(int l,int r,int v){
		make(l,r,v,0,0,sz);
	}
	int val(int i,int v,int start,int left,int right){
		if(right-left==1){
			return (v+adds[start])%mod;
		}	
		int mid=(left+right)/2;
		int num = (v+adds[start])%mod;
		if(i<mid){
			return val(i,num,2*start+1,left,mid)%mod;
		}else{
			return val(i,num,2*start+2,mid,right)%mod;
		}
	}
	int val(int i){
		return val(i,0,0,0,sz)%mod;
	}
};

void solve(){
	int n,k;
	cin>>n>>k;
	segtree st(n);
	vector<pair<int,int>>ranges;
	for(int j=0;j<k;j++){
		int u,v;
		cin>>u>>v;
		u--;
		ranges.push_back({u,v});
	}
	sort(all(ranges));
	for(pair<int,int>p:ranges){
		st.make(p.first+1,min(p.second+1,n),1);
	}
	for(int i=1;i<n;i++){
		int a=st.val(i);
		for(pair<int,int>p:ranges){
			st.make(p.first+i+1,min(p.second+i+1,n),a);
		}
	}
	cout<<st.val(n-1)<<endl;
}

int32_t main(){

	//remove for interactive problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

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

	return 0;
}

Measured memory_bytes: 11400
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  ll x, k, d;
  cin >> x >> k >> d;

  //まず0にちかづける
  //今の場所が０になったら
  if (x == 0) {
    if (k == 0 || k % 2 == 0) {
      cout << 0;
      return 0;
    } else {
      cout << abs(x + d);
      return 0;
    }
  } else {  //できるだけ近づける
    if (x > 0) {
      //動かしたほうが０に近い
      if (abs(x) > d) {
        ll waru = x / d;
        if (k > waru) {
          x -= d * waru;
          k -= waru;
        } else {
          x -= k * d;
          k = 0;
        }
      }
    } else {
      if (abs(x) > d) {
        ll waru = abs(x) / d;
        if (k > waru) {
          x += d * waru;
          k -= waru;
        } else {
          x += k * d;
          k = 0;
        }
      }
    }

    if (k == 0 || k % 2 == 0) {
      cout << abs(x);
      return 0;
    } else {
      if (x > 0) {
        cout << abs(x - d);
        return 0;
      } else {
        cout << abs(x + d);
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int cnt1 = c/b;if(c%b) cnt1++;
	int cnt2 = a/d;if(a%d) cnt2++;
	if(cnt1<=cnt2) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3636
n = int(input())
list_a = list(map(int, input().split()))
list_123 = []
for i in range(n):
    list_123.append(i+1)
list_dif = [0]*n
for i in range(n):
    list_dif[i] = list_a[i] - list_123[i]
list_dif_sorted = sorted(list_dif)
med = list_dif_sorted[n//2]
ans = 0
for i in range(n):
    ans += abs(list_dif[i] - med)
print(ans)


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll num(ll x){
    ll res = 0;
    while(x>0){
        if(x%2==1){
            res++;
        }
        x /= 2;
    }
    return res;
}

long long power_mod(long long x, long long y, long long m){
    long long res = 1 ;
    if(y>0){
        res = power_mod(x,y/2,m) ;
        if(y%2==0){
            res = (res*res)%m ;
        }
        else{
            res = (((res*res)%m)*x)%m ;
        }
    }
    return res ;
}
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    string s;
    cin >> n >> s;
    reverse(ALL(s));

    ll m = 0;
    REP(i,n){
        if(s[i]=='1'){
            m++;
        }
    }

    vll mp(n,0);
    vll pp(n,0);

    REP(i,n){
        if(m!=1){
            mp[i] = power_mod(2,i,m-1);
        }
        pp[i] = power_mod(2,i,m+1);
    }

    ll a = 0;
    ll b = 0;

    REP(i,n){
        if(s[i]=='1'){
            if(m!=1){
                a += mp[i];
                a %= (m-1);
            }
            b += pp[i];
            b %= (m+1);
        }
    }

    vll vec;

    ll hoge, ans;

    REP(i,n){
        if(s[i]=='0'){
            hoge = b;
            hoge += pp[i];
            hoge %= (m+1);
            ans = 1;
            while(hoge>0){
                ans++;
                hoge %= num(hoge);
            }
            vec.PB(ans);
        }
        else{
            if(m==1){
                vec.PB(0);
                continue;
            }
            hoge = a;
            hoge -= mp[i];
            hoge += (m-1);
            hoge %= (m-1);
            ans = 1;
            while(hoge>0){
                ans++;
                hoge %= num(hoge);
            }
            vec.PB(ans);
        }
    }

    reverse(ALL(vec));

    REP(i,n){
        cout << vec[i] <<endl;
    }






    
    return 0;
}



Measured memory_bytes: 8656
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
ll MOD = 1000000007ll;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)

const int MX = 20005;

int main()
{
	string D, E, A, B;
	cin >> D;
	E = D; reverse(E.begin(), E.end());
	for(char c : D) if(c != 'x') A += c;
	for(char c : E) if(c != 'x') B += c;
	if(A != B) return !printf("-1\n");
	int l = 0, r = 0, ans = 0;
	while(l < D.size() || r < E.size()){
		int a = 0, b = 0;
		while(l < D.size() && D[l] == 'x') l++, a++;
		while(r < E.size() && E[r] == 'x') r++, b++;
		ans += abs(a-b);
		l++, r++;
	}
	printf("%d\n", ans/2);
}


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

int main(){
  string a;
  cin >> a;
  if(a[0] == a[1] && a[1] == a[2] || a[1] == a[2] && a[2] == a[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> P; 
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int zero=-1;
    map<pair<ll,ll>,P> mp;
    rep(i,n){
        ll x,y;cin>>x>>y;
        if(x==0&&y==0){
            zero++;
            continue;
        }
        ll g=gcd(x,y);
        x/=g;
        y/=g;
        if(y<0)x=-x,y=-y;
        if(y==0&& x<0)x=-x;
        bool rot=(x<=0);
        if(rot){
            ll tmp=x;
            x=y;
            y=-tmp;
        }
        if(rot)mp[{x,y}].first++;
        else mp[{x,y}].second++;
    }
    mint ans=1;
    for(auto i:mp){
        int s=i.second.first;
        int t=i.second.second;
        mint now=1;
        now+=mint(2).pow(s)-1;
        now+=mint(2).pow(t)-1;
        ans*=now;
    }
    ans+=zero;
    cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 16032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  string s,t;
  cin >> s >> t;
  int n=s.size();
  int ans=0;
  rep(i,n)
    if(s.at(i)!=t.at(i))ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3928