akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(s.size()<=k){
		cout<<s;
		return 0;
	}
	rep(i,k)cout<<s[i];
	cout<<"...";
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int M;
int D[201010]; ll C[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> M;
	rep(i, 0, M) cin >> D[i] >> C[i];

	int cur = 0;
	ll ans = 0;
	rep(_, 0, M) {
		int d = D[_];
		ll c = C[_];

		if (c < 30) {
			rep(i, 0, c) {
				cur += d;
				ans++;
				if (10 <= cur) {
					cur = (cur / 10) + (cur % 10);
					ans++;
				}
			}
		}
		else {
			int idx = 0;

			map<int, int> loop;
			map<int, ll> need;
			loop[cur] = 0;
			need[cur] = ans;

			cur += d;
			ans++;
			if (10 <= cur) {
				cur = (cur / 10) + (cur % 10);
				ans++;
			}
			idx++;

			while (!loop.count(cur)) {
				loop[cur] = idx;
				need[cur] = ans;

				cur += d;
				ans++;
				if (10 <= cur) {
					cur = (cur / 10) + (cur % 10);
					ans++;
				}
				idx++;
			}

			ll ansd = ans - need[cur];
			int loopp = idx - loop[cur];

			c -= idx;

			ans += c / loopp * ansd;
			c %= loopp;
			rep(i, 0, c) {
				cur += d;
				ans++;
				if (10 <= cur) {
					cur = (cur / 10) + (cur % 10);
					ans++;
				}
			}
		}
	}
	cout << ans-1 << endl;
}







Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	static int[][] f = new int[21][21];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n==0)break;
			
			for(int i=0;i<=20;i++) {
				for(int j=0;j<=20;j++)
					f[i][j] = 0;
			}
			boolean ans = true;
			for(int i=0;i<n;i++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				f[x][y] = 1;
			}
		
			int m = sc.nextInt();
			int x=10;
			int y=10;
			for(int i=0;i<m;i++) {
				char a = sc.next().charAt(0);
				int d = sc.nextInt();
				switch(a) {
				case 'N':
					for(int k=y;k<=y+d;k++) {	
						f[x][k] = 0;
					}
					y += d;
					break;
				case 'E':
					for(int k=x;k<=x+d;k++) {
						f[k][y] = 0;
					}
					x += d;
					break;
				case 'S':
					for(int k=y;k>=y-d;k--) {
						f[x][k] =0;
					}
					y -= d;
					break;
				case 'W':
					for(int k=x;k>=x-d;k--) {
						f[k][y] =0;
					}
					x -= d;
					break;
				}
			}
			
			for(int i=0;i<=20;i++) {
				for(int j=0;j<=20;j++)
					if(f[i][j] != 0) {
						ans = false;
						break;
					}
				if(!ans)break;
			}
		
			if(ans)System.out.println("Yes");
			else System.out.println("No");
			
		}
		
	}
}


Measured memory_bytes: 43120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   /// BISMILLAHIR RAHMANIR RAHIM
   string s;
   cin>>s;
   int n=s.length();
   for(int i=0;i<s.length();i++){

    if( s[i]=='?'){
         s[i]='D';
    }
     cout<<s[i];

   }


    /// ALHAMDULILLAH
}


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

int main(void){
        int i,n;
        long H,cnt=0;

        cin >> H;
        for(i=0;i<40;i++){
                if(pow(2,i) <= H && H < pow(2,i+1)){
                        n = i;
                        break;
                }
        }
        for(i=0;i<=n;i++){
                cnt += pow(2,i);
        }
        cout << cnt << endl;

        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

ll dp[301][301][301];

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

  int n, m; cin >> n >> m;

  rep(i, 301) {
    rep(j, 301) {
      rep(k, 301) {
        // j: satisfy, k: moved (1 <= j <= k <= n)
        dp[i][j][k] = 0;
      }
    }
  }

  dp[0][1][1] = 1;
  rep(i, m) {
    for(int j=1; j<=n; j++) {
      for(int k=1; k<=n; k++) {
        dp[i+1][j][k] += dp[i][j][k]*(k-j);
        dp[i+1][j][k] %= mod;
        dp[i+1][j][k+1] += dp[i][j][k]*(n-k);
        dp[i+1][j][k] %= mod;
        dp[i+1][k][k] += dp[i][j][k]*j;
        dp[i+1][k][k] %= mod;
      }
    }
  }
  cout << dp[m][n][n] << endl;
}

Measured memory_bytes: 213376
def print_frame(h, w):
    """
    h: int(3 <= h <= 300)
    w: int(3 <= w <= 300)
    outputs a rectangle frame h x w

    >>> print_frame(3, 4)
    ####
    #..#
    ####
    >>> print_frame(5, 6)
    ######
    #....#
    #....#
    #....#
    ######
    >>> print_frame(3, 3)
    ###
    #.#
    ###
    """
    print('#' * w)
    for i in range(h-2):
        print('#' + '.'*(w-2) + '#')
    print('#' * w)


if __name__ == '__main__':

    while True:
        (h, w) = [int(i) for i in input().split(' ')]
        if h == 0 and w == 0:
            break
        print_frame(h, w)
        print()

Measured memory_bytes: 7620
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int a1=in.nextInt(),m1=in.nextInt();
			int a2=in.nextInt(),m2=in.nextInt();
			int a3=in.nextInt(),m3=in.nextInt();
			int x=1,y=1,z=1;
			if((a1|a2|a3|m1|m2|m3)==0)
				return;
			long c1=modoru(x,a1,m1);
			long c2=modoru(y,a2,m2);
			long c3=modoru(z,a3,m3);
			c2=lcm(c1,c2);
			c3=lcm(c2,c3);
			System.out.println(c3);
		}
	}
	public static int modoru(int x,int a,int m)
	{
		int cnt=0;
		for(;;)
		{
			cnt++;
			x=(a*x)%m;
			if(x==1)
				break;
		}
		return cnt;
	}
	
	public static long gcd(long a,long b)
	{
		return b==0?a:gcd(b, a%b);
	}
	public static long lcm(long a,long b)
	{
		
		long gcd=gcd(a,b);
		long lcm=a/gcd*b;
		return lcm;
	}
}

Measured memory_bytes: 12000
#include <stdio.h>


int main(){
    int a,b,answer,outlet;
    scanf("%d%d",&a,&b);
    answer=0;
    outlet=1;
    while (outlet<b)
    {   outlet--;
        outlet=outlet+a;
        answer++;
    }
    
    printf("%d",answer);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int arr[N];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    int ans=1;
    for(int i=2,sign=0;i<=n;i++){
        if(arr[i]>arr[i-1])if(sign!=-1)sign=1;else ans++,sign=0;
        if(arr[i]<arr[i-1])if(sign!=1)sign=-1;else ans++,sign=0;
    }
    cout<<ans;


}


Measured memory_bytes: 768
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
		int c = a*b;
      	String result = "";
        if (c % 2 == 0) {
          result = "Even";
        } else {
		  result = "Odd";
        }
        System.out.println(result);
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

int main() {
	vector<int>A(5);
	for (size_t i = 0; i < 5; i++)
	{
		cin >> A.at(i);
		if (A.at(i) == 0)cout << i + 1;
	}
	return 0;
}

Measured memory_bytes: 3488
import math

n = int(input())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

one = sum(math.fabs(x[i] - y[i]) for i in range(n))
print("{0:5f}".format(one))

two = math.sqrt(sum((x[i] - y[i]) ** 2 for i in range(n)))
print("{0:5f}".format(two))

three = (sum(math.fabs((x[i] - y[i]) ** 3) for i in range(n))) ** (1/3)
print("{0:5f}".format(three))

inf = max(math.fabs(x[i] - y[i]) for i in range(n))
print("{0:5f}".format(inf))



Measured memory_bytes: 5708
#include <stdio.h>
int main(void){
    int a,hou,min,sec;
    scanf("%d",&a);
        {
            hou=a/3600;
            min=(a%3600)/60;
            sec=(a%3600)%60;
        }
    printf("%d:%d:%d\n",hou,min,sec);
    return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<ll mod>
struct RollingHash{
	vector<ll> hash, power;

	RollingHash(const string &s, ll base=10007){
		int sz=s.size();
		hash.resize(sz+1);
		power.resize(sz+1);
		power[0]=1;
		for(int i=0; i<sz; i++){
			power[i+1]=power[i]*base%mod;
			hash[i+1]=(hash[i]*base+s[i])%mod;
		}
	}

	ll get(int l, int r) const{ // [l, r)
		ll ret=hash[r]-hash[l]*power[r-l]%mod+mod;
		if(ret>=mod) ret-=mod;
		return ret;
	}

	ll concat(ll h1, ll h2, int len2) const{ //h1+h2
		ll ret=h1*power[len2]%mod+h2;
		if(ret>=mod) ret-=mod;
		return ret;
	}
};
int main()
{
	int n; cin>>n;
	string s; cin>>s;
	const ll MOD1=1e9+7;
	const ll MOD2=1e9+9;
	RollingHash<MOD1> rh1(s);
	RollingHash<MOD2> rh2(s);
	int ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			while(i+ans<j && j+ans<n){
				ll h1=rh1.get(i, i+ans+1)-rh1.get(j, j+ans+1), h2=rh2.get(i, i+ans+1)-rh2.get(j, j+ans+1);
				if(h1!=0 || h2!=0) break;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
s = input()
t = True

if s == s[::-1]:
  if s[:(int)((len(s) - 1)/2)] == s[:(int)((len(s) - 1)/2):-1]:
    if s[(int)((len(s) + 3)/2 - 1):] == s[-1:len(s) - (int)((len(s) + 3)/2) + 1:-1]:
      print("Yes")
      t = False
if t:
  print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
 
if(a>=b) {
if(b>=c) cout<<c<<" "<<b<<" "<<a<<endl;
else if(b<c){ 
if(a<=c) cout<<a<<" "<<c<<" "<<b<<endl;
else if(a>c) cout<<b<<" "<<c<<" "<<a<<endl;
}
}
 
if(a<b) {
if(b<=c) cout<<a<<" "<<b<<" "<<c<<endl;
else if(b>c){ 
if(a>=c) cout<<c<<" "<<a<<" "<<b<<endl;
else if(a<c) cout<<a<<" "<<c<<" "<<b<<endl;
}
}
return 0;
}


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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
//int INF = 1e9;
const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if (a > b)  a = b; }

const int MAX_N = 110;
const int MAX_V = 100100;
int N;
int W, weight[MAX_N], value[MAX_N]; 
int dp[MAX_N][MAX_V];

signed main() {
	ios::sync_with_stdio(false);
	cin >> N >> W;
	rep(i, N) cin >> weight[i] >> value[i];
	rep(i, MAX_N) {
		rep(j, MAX_V) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	rep(i, N) {
		rep(j, MAX_V) {
			if (j - value[i] >= 0)
				chmin(dp[i + 1][j], dp[i][j - value[i]] + weight[i]);
			chmin(dp[i + 1][j], dp[i][j]);
		}
	}
	int ans = 0;
	rep(i, MAX_V) if (dp[N][i] <= W) ans = i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 86272
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
int x,l,r,n;
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	scanf("%d",&n);
	l=1000;
	r=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		l=min(l,x);
		r=max(r,x);
	}
	printf("%d\n",r-l);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    ll ans = 0;
    rep(0, i, N + 1)
    {
        if ((i % 3 == 0) || (i % 5 == 0))
        {
            continue;
        }
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct stone{
    
    int w,s;ll v;
}a[1005];
int n;ll f[20005],ans;
bool cmp(stone x,stone y){return x.w+x.s<y.w+y.s;}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d%lld",&a[i].w,&a[i].s,&a[i].v);
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
    for(int j=a[i].s;j>=0;j--)
    f[j+a[i].w]=max(f[j+a[i].w],f[j]+a[i].v);
    for(int i=0;i<20001;i++) ans=max(ans,f[i]);
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 384
MOD = 10 ** 9 + 7
def main():
    N, K = (int(_) for _ in input().split())
    A = [int(_) for _ in input().split()]

    R, L = [], []
    for i in range(N):
        cr = cl = 0
        for j in range(N):
            if i == j: continue
            if A[i] > A[j]:
                if i > j: cl += 1
                if i < j: cr += 1
        R.append(cr)
        L.append(cl)

    output = 0
    for i in range(N):
        output += (K*R[i] + K*(K-1)*(R[i]+L[i])//2)
        output %= MOD
    print(output)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    ll n, x, b = -1, sum = 0;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        cin >> x;
        a[i] = x - (i + 1);
    }
    sort(a, a + n);
    if (n % 2 == 1) {
        b = a[n/2];
    }else{
        b = (a[n/2] + a[n/2-1]) / 2;
    }
    for (ll i = 0; i < n; i++) {
        sum += abs(a[i] - b);
    }
    cout << sum << endl;
    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n;
    int a;

    int hit[100002] = {};

    Scd(n);
    Rep(i,n){
        Scd(a);
        hit[a++]++;
        hit[a++]++;
        hit[a++]++;
    }

    int ans = 0;
    Rep(i,100000){
        ans = max(ans,hit[i]);
    }


    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

s = input()
 
i = 0
 
while i <= len(s)-1:
	print(s[i], end="")
	i += 2
 
print()

Measured memory_bytes: 14844
#include<bits/stdc++.h>
using namespace std;
long long a;
long long b;
long long c;
int main()
{
    cin>>a>>b>>c;
    for(long long i=a;i<=a*1000;i+=a)
        if(i%b==c) 
        {
            cout<<"YES";
            return 0;
        }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		String s = sc.next();

		if (a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}

		sc.close();
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define P pair<int,int>
using namespace std;
const int maxn = 100100;
int indegree[maxn];
vector<int>g[maxn];
int root, n, m, parent[maxn];
bool visited[maxn];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    int x, y;
    for(int i=0;i<n-1+m;i++) {
        cin>>x>>y;
        g[x].pb(y);
        indegree[y]++;
    }

    priority_queue<P, vector<P>, greater<P> > pq;

    for(int i=1;i<=n;i++) {
        pq.push(mp(indegree[i], i));
    }

    while(!pq.empty()) {
        P curr = pq.top();
        pq.pop();

        if(visited[curr.second]) continue;

        visited[curr.second] = true;

        int node = curr.second;
        for(int i:g[node]) {
            if(!visited[i]) {
                indegree[i]--;
                if(indegree[i] == 0) {
                    parent[i] = curr.second;
                    pq.push(mp(indegree[i], i));
                }
            }
        }
    }

    for(int i=1;i<=n;i++) {
        cout<<parent[i]<<"\n";
    }

    return 0;
}

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

struct segment_tree {
  vector<bitset<26>> node;
  int n;

  segment_tree(int n) {
    int msb = 1LL << ((n==0) ? 0 : 64 - __builtin_clzll(n)-1);
    this->n = (n==msb) ? n : msb << 1;
    node.resize(2 * this->n - 1);
  }

  inline int r_child(int v) { return v*2+2; }
  inline int l_child(int v) { return v*2+1; }
  inline int parent(int v) { return (v + (v%2)) / 2 - 1; }

  bitset<26> query(int ql, int qr, int v=0, int l=0, int r=-1) {
    r = (r==-1) ? n-1 : r;
    if(ql<=l && r<=qr) return node[v];
    bitset<26> ret;
    int mid=(l+r)/2;
    if(ql <= mid)   ret |= query(ql, qr, l_child(v), l,     mid);
    if(qr >= mid+1) ret |= query(ql, qr, r_child(v), mid+1, r  );
    return ret;
  }

  void set_value(int index, char val) {
    int v = node.size()/2 + index;
    node[v].reset();
    node[v][val-'a'] = 1;
    while((v=parent(v)) != -1) node[v] = node[l_child(v)] | node[r_child(v)];
  }
};

int N, Q;
string S;

signed main() {
  cin >> N;
  cin >> S;

  segment_tree st(N);
  for(int i=0; i<N; i++) {
    st.set_value(i, S[i]);
  }

  cin >> Q;
  for(int q=0; q<Q; q++) {
    int t;
    cin >> t;
    if(t==1) {
      int i; char c; cin >> i >> c;
      st.set_value(i-1, c);
    }
    else {
      int l,r; cin >> l >> r;
      l--; r--;
      cout << st.query(l,r).count() << endl;
    }
  }
}


Measured memory_bytes: 9092
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

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

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll N, M,sum=0;
	cin >> N >> M;
	vll A(N);
	rep(i, 0, N) {
		cin >> A[i];
		sum += A[i];
	}

	sort(A.begin(), A.end(), greater<ll>());

	bool flg = true;
	rep(i, 0, M) {
		if (4 * M * A[i] < sum) {
			flg = false;
			break;
		}
	}

	if (flg) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main (){
  int a,i,n,j,k,l,box,m=0;
  int b[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    b[i]=a;
  }
  
    for(j=0;j<n;j++){
      for(k=n-1;k>=j+1;k--){
	if(b[k]<b[k-1]){
	  box=b[k];
	  b[k]=b[k-1];
	  b[k-1]=box;
	  m++;
	}
      }
    }
      for(l=0;l<n-1;l++){
      printf("%d ",b[l]);
    }
    printf("%d\n",b[l]);
    printf("%d\n",m);
      return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

signed main(){
  string s; cin >> s;
  lint K; cin >> K;
  lint N = s.size();
  bool judge = true;
  for(lint i = 1; i < N; i++){
    if(s[i] != s[i - 1]) judge = false; 
  }
  if(judge && N % 2 == 1){
    if(K % 2 == 0) cout << N * (K / 2) << endl;
    else cout << N * ((K - 1) / 2) + N / 2 << endl;
  }
  else{
    string t;
    t = s; t += s;
    lint cs = 0, ct = 0;
    for(lint i = 1; i < N; i++){
      if(s[i] == s[i - 1]) {
        cs++; i++;
      }
    }
    for(lint i = 1; i < t.size(); i++){
      if(t[i] == t[i - 1]) {
        ct++; i++;
      }
    }
    lint ans = cs + (ct - cs) * (K - 1);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int a, b, cur = 1, ans = 0;
    cin >> a >> b;

    while (cur < b)
    {
        cur += a - 1;
        ans++;
    }

    cout << ans << "\n";

    return 0;
}


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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {	
	IO;
	
	int n; cin >> n;
	
	map<string, int> mp;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		
		mp[s]++;
	}
	
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
	
}


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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 1; i <= k; ++i) {
        if(i % 2 == 0) {
            b /= 2;
            a += b;
        }
        else {
            a /= 2;
            b += a;
        }
    }

    cout << a << " " << b;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[0] << s3[0] << endl;
  return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    string S;
    int Q;
    cin >> S;
    cin >> Q;

    char ans[1000000];
    REP(i, S.length()){
        ans[500000+i] = S[i];
    }
    int start = 500000;
    int end = 500000 + S.length() - 1;

    int direction = 1;
    REP(i, Q){
        int t;
        cin >> t;
        if(t == 1){
            // cout << "kkk" << endl;
            // 向きを反転
            direction *= -1;
            continue;
        }
        int f;
        char c;
        cin >> f >> c;
        // cout << f << " " << c << endl;
        if(f == 1){
            if(direction == 1){
                // cout << "kkk2" << endl;
                ans[start-1] = c;
                start--;
                continue;
            }
            else{
                // cout << "kkk3" << endl;
                ans[end+1] = c;
                end++;
                continue;
            }
        }
        else{
            if(direction == 1){
                // cout << "kkk4" << endl;
                ans[end+1] = c;
                end++;
                continue;
            }
            else{
                // cout << "kkk5" << endl;
                ans[start-1] = c;
                start--;
                continue;
            }
        }
    }
    if(direction == 1){
        for(int i=start; i<=end; i++){
            cout << ans[i];
        }
        cout << endl;
    }
    else{
        for(int i=end; i>=start; i--){
            cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}

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


Measured memory_bytes: 14380
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  string S;
  cin>>N>>S;
  int ans=1;
  for(int i=0;i<N-1;i++)
    if(S.at(i)!=S.at(i+1))
      ans++;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 512
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, x, t; read(n, x, t);
  write((n + x - 1) / x * t);
}



Measured memory_bytes: 3636
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;

int H,W;


int main(){
    int W,H,n;
    cin>>W>>H>>n;
    vector<vector<bool> > field(H, vector<bool>(W));
    vector<int>x(n);
    vector<int>y(n);
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>a[i];
    }
    

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            field[i][j]=false;
        }
    }

    for(int i=0;i<n;i++){
        if(a[i]==1){
            for(int h=0;h<H;h++){
                for(int w=0;w<x[i];w++){
                    field[h][w]=true;
                }
            }
        }
        else if(a[i]==2){
            for(int h=0;h<H;h++){
                for(int w=x[i];w<W;w++){
                    field[h][w]=true;
                }
            }
        }else if(a[i]==3){
            for(int h=0;h<y[i];h++){
                for(int w=0;w<W;w++){
                    field[h][w]=true;
                }
            }
        }else if(a[i]==4){
            for(int h=y[i];h<H;h++){
                    for(int w=0;w<W;w++){
                        field[h][w]=true;
                }
            }
        }
    }


       
    int count=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(!field[i][j]) count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int A, B, X;
    cin >> A >> B;
    X = A+B;
    if (2*A-1 > X) X = 2*A-1;
    if (2*B-1 > X) X = 2*B-1;
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n,x[101010];

int main() {
	cin >> n >> x[0];
	for (int i = 1; i <= n; i++)cin >> x[i];
	n++;
	sort(x, x + n);
	int num;
	REP(i, n-1) {
		if (i == 0) {
			num = x[i + 1] - x[i];
		}
		else {
			num = gcd(num, x[i + 1] - x[i]);
		}
	}
	cout << num << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<setprecision(7)<<x<<endl
vector<int> vec;

int a,b;
int main(void){
    cin>>a>>b;
    if(b%a==0)p(a+b);
    else p(b-a);
    return 0;
}


Measured memory_bytes: 256
var body = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  body += chunk;
});
  
readable.on( 'end', function() {
  var data = body.split( '\n' );
  var output = [];
  for( var i=0; i<data.length; i++ ) {
    if( 0 != data[i] ) {  
      output.push( 'Case '+(i+1)+': '+data[i] );
    }
  }
  console.log( output.join( '\n' )  );
});

Measured memory_bytes: 19532
// SeeAlso: https://atcoder.jp/contests/abc149/submissions/9220255
package main

import (
	"fmt"
)

// r: グー
// s: チョキ
// p: パー
func solution(n, k, r, s, p int, t string) int {
	var ans int

	point := map[rune]int{
		'r': p,
		's': r,
		'p': s,
	}

	check := make(map[int]bool, len(t))

	for i, v := range t {
		if i < k {
			ans += point[v] // 前回の手を考慮しなくていい場合は勝ち手を出すので最大点数を獲得
		} else {
			// 前回の手と同じ場合
			if t[i] == t[i-k] {
				// 前回の手に次回を考慮したフラグが立っているか確認。
				// フラグが立っている場合は前回考慮済なので、今回は勝ち手を出して最大点数を獲得
				if check[i-k] {
					ans += point[v]
				} else {
					// 前回の手に次回考慮フラグが立っていないので今回は点数獲得なしでフラグを立てる
					check[i] = true
				}
			} else {
				// 前回の手を考慮しなくていいので勝ち手を出して最大点数を獲得
				ans += point[v]
			}
		}
	}
	return ans
}

func main() {
	var n, k, r, s, p int
	var t string
	fmt.Scan(&n, &k)
	fmt.Scan(&r, &s, &p)
	fmt.Scan(&t)
	fmt.Println(solution(n, k, r, s, p, t))
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll count=0,n,count_r=0;
    string str;
    cin>>n;
    cin>>str;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='R')
        {
            count_r++;
        }
    }
    ll var=count_r;
    for(int i=0;i<var;i++)
    {
        if(str[i]=='R')
        {
            count_r--;
        }
    }
    cout<<count_r<<'\n';
    return 0;
}

Measured memory_bytes: 3752
#include <cstdio>

using namespace std;

template<typename Type>
void Get_Val(Type &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

const int Max_N(100050);
const int Max_Q(100050);
typedef long long int LL;

int N, Q;
LL V[Max_Q];

void init()
{
	int _Q;
	Get_Val(N), Get_Val(_Q);
	V[++Q] = N * 1LL;
	while (_Q--)
	{
		Get_Val(V[++Q]);
		while (Q - 1 >= 1 && V[Q - 1] >= V[Q])
			V[Q - 1] = V[Q], --Q;
	}
}

//设S[i]表示进行前i次操作得到的答案
//solve(i, l)表示进行前i次操作，序列前l个数的答案
//S[i] = solve(i, V[i])
//solve(i, l) = S[i - 1] * (l / V[i - 1]) + solve(i - 1, l % V[i - 1])
//找到第一个l >= V[j - 1]
//考虑记录Cnt[i]表示S[i]在最终答案中出现了多少次，倒推计算Cnt[i] 
//对于i = 1，记录每个数在最终答案中出现了多少次 

LL Cnt[Max_Q], Ans[Max_N];

inline void insert(const int &l, const int &r, const LL &v)
{
	Ans[l] += v, Ans[r + 1] -= v;
}

void solve(const int &x, const LL &l, const LL &cnt)
{
	if (x == 1)
	{
		Cnt[1] += cnt * (l / V[1]);
		insert(1, static_cast<int>(l % V[1]), cnt);
	}
	else
	{
		Cnt[x - 1] += cnt * (l / V[x - 1]);
		if (l % V[x - 1] == 0LL)
			return;
		int up(1), down(x), mid;
		while (up < down)
		{
			mid = up + ((down - up) >> 1);
			if (l % V[x - 1] >= V[mid - 1])
				up = mid + 1;
			else
				down = mid;
		}
		solve(up - 1, l % V[x - 1], cnt);
	}
}

int main()
{
	init();
	Cnt[Q] = 1LL;
	for (int i = Q;i >= 2;--i)
		solve(i, V[i], Cnt[i]);
	insert(1, V[1], Cnt[1]);
	for (int i = 1;i <= N;++i)
		printf("%lld\n", Ans[i] += Ans[i - 1]);
	return 0;
}

Measured memory_bytes: 3968
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) {
	n, m := sc.getInt2()
	ps := make([]int, n)
	for i := range ps {
		ps[i] = sc.getInt() - 1
	}

	graph := make([][]int, n)
	for i := 0; i < m; i++ {
		x, y := sc.getInt()-1, sc.getInt()-1
		graph[x] = append(graph[x], y)
		graph[y] = append(graph[y], x)
	}

	seen := make([]bool, n)
	groups := make([][]int, n)
	var dfs func(int, int)
	dfs = func(now, id int) {
		if seen[now] {
			return
		}
		seen[now] = true
		groups[id] = append(groups[id], now)
		for _, next := range graph[now] {
			dfs(next, id)
		}
	}
	for i := 0; i < n; i++ {
		dfs(i, i)
	}

	ans := 0
	for _, g := range groups {
		qs := make([]int, 0, len(g))
		for _, i := range g {
			qs = append(qs, ps[i])
		}
		sort.Ints(g)
		sort.Ints(qs)

		i, j := 0, 0
		for i < len(g) && j < len(g) {
			if g[i] == qs[j] {
				ans++
				i++
				j++
			} else if g[i] < qs[j] {
				i++
			} else {
				j++
			}
		}
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 36188
import sys
import math
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(input())
    S = input().strip()

    MOD = 10 ** 9 + 7

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    def cmb(n, k, p):
        if (k < 0) or (n < k):
            return 0
        r = min(k, n - k)
        return fact[n] * factinv[k] * factinv[n - k] % p

    N = 10 ** 6 * 2
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    ans = 0
    a = 1
    b = pow(26, K, MOD)
    for i in range(K + 1):
        ans += a * cmb(i + len(S) - 1, len(S) - 1, MOD) * b
        a = a * 25 % MOD
        b = b * pow(26, MOD - 2, MOD) % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()


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

int main() {
  int K;
  cin >> K;
  if (K % 2 == 1)
    cout << (K / 2 + 1) * (K / 2) << endl;
  else
    cout << (K / 2) * (K / 2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string S; int N, cnt;
 
int main() {
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		int c[3] = {i / 100, (i / 10) % 10, i % 10};
		int f = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == ('0' + c[f])) f++;
			if (f == 3) break;
		}
		if (f == 3) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#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 rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

// 素因数分解
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

void solve_abc_d() {
	ll n, m, x, k;
	cin >> n;

	ll ans = 0;

	map<ll, ll> prime = prime_factor(n);

	for (auto itr = prime.begin(); itr != prime.end(); itr++) {
		rep(i, 1000000) {
			if (i * (i + 1) > 2 * itr->second) {
				ans += i - 1;
				break;
			}
		}
	}

	cout << ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 3664
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func solve(n int64, k int64, hs []int64) int64 {
	ret := int64(0)
	for _, h := range hs {
		if h >= k {
			ret ++
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	k := nextInt()
	hs := nextInts(n)
	res := solve(n, k, hs)
	fmt.Fprintln(out, res)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
    char c;
    cin>>c;
    if(isupper(c))
    {
        cout<<"A\n";
        return;
    }
    cout<<"a\n";
    return;
}
 

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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
	int n; std::cin >> n;
	std::vector<int> cnt(n + 2);
	for (int i = 0; i < n - 1; i++) {
		int a; std::cin >> a;
		cnt[a]++;
	}
	for (int i = 1; i <= n; i++) {
		std::cout << cnt[i] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define Rep(i,k,n) for(long long i=k;i<=(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvi=vector<vvi>;
int main(){
    int n;
    cin>>n;
    vi fb(n);
    ll ans=0;
    Rep(i,1,n){
        if(i%3!=0&&i%5!=0)ans+=i;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 11172
#include <stdio.h>
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	char str[n];
	scanf("%s",str);
	for(int i=0;i<n;i++){
		if(i+1==k){
			str[i]=str[i]-'A'+'a';
			printf("%c",str[i]);
		}
		else{
			printf("%c",str[i]);
		}
	}
}

Measured memory_bytes: 128