akhauriyash/Code-Regression huggingface dataset:
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for x in range(M)]

parents = [-1]*(N+1)

def find(x):
    global parents
    if parents[x] < 0:
        return x
    else:
        return find(parents[x])

def union(x,y):#xにyを合体させる
    global parents
    X = find(x)
    Y = find(y)
    if X == Y:
        return
    if X > Y:
        X,Y = Y,X

    parents[X] += parents[Y]
    parents[Y] = X



for p in range(M):
    union(AB[p][0],AB[p][1])



print(min(parents)*-1)














"""
F = [[]]
L = []

for x in range(N+1):
    F += [[x+1]]

for p in range(M):
    F[AB[p][0]] += [AB[p][1]]
    F[AB[p][1]] += F[AB[p][0]]

for q in range(N+1):
    F[q] = list(set(F[q]))

for r in range(N+1):
    L += [len(F[r])]

print(L)
print(max(L))
"""

Measured memory_bytes: 47152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

void solve(long long A, long long B, long long C, long long D, long long E, long long F)
{

    set<ll> water;
    set<ll> sugar;

    for (size_t i = 0; i <= F; i++)
    {
        for (size_t j = 0; j <= F; j++)
        {
            ll tmpwater = 100 * A * i + 100 * B * j;
            if (tmpwater <= F)
            {
                water.insert(tmpwater);
            }
        }
    }

    for (size_t i = 0; i <= F; i++)
    {
        for (size_t j = 0; j <= F; j++)
        {
            ll tmpsugar = C * i + D * j;
            if (tmpsugar <= F)
            {
                sugar.insert(tmpsugar);
            }
        }
    }

    ll answater = 0;
    ll anssugar = 0;
    double maxdensity = -1;
    for (auto w : water)
    {
        for (auto s : sugar)
        {
            double density = (double)(100 * s) / (double)(w + s);
            double maxSugar = (double)(w * E) / (double)100;
            if (w + s <= F && s <= maxSugar)
            {
                if (maxdensity < density)
                {
                    answater = w + s;
                    anssugar = s;
                    maxdensity = density;
                }
            }
        }
    }

    cout << answater << " " << anssugar << endl;
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    long long E;
    scanf("%lld", &E);
    long long F;
    scanf("%lld", &F);
    solve(A, B, C, D, E, F);
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int n, m, a[50], b[50], i, j, count;
    scanf("%d%d", &n, &m);
    for (i=0; i<m; i++)
    {
        scanf("%d %d", &a[i], &b[i]);
    }
    for (i=1; i<=n; i++)
    {
        count = 0;
        for (j=0; j<m; j++)
        {
            if (a[j] == i || b[j] == i) {
                count ++;
            }
        }
        printf("%d\n", count);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int g[11][11];
int path[21];
int used[11][11];
int ans;
vector<int> anspath;
int n;
void solve(int now, int len, int dis) {
  //cout << string(len, ' ') << now << " "  << len << " " << dis << endl;
  bool f = 0;
  for (int i=1; i<=n; ++i) {
    if (g[now][i] != INF && !used[now][i]) {
      used[now][i] = 1;
      used[i][now] = 1;
      path[len] = i;
      solve(i, len+1, dis+g[now][i]);
      used[now][i] = 0;
      used[i][now] = 0;
      f = 1;
    }
  }
  if (!f) {
    if (ans < dis) {
      ans = dis;
      anspath = vector<int>(path, path+len);   
    }
  }
}

int main() {
  int m;
  while(cin >> n >> m, n||m) {
    REP(i,n+1) REP(j,n+1) g[i][j] = INF;
    REP(i, m) {
      int a,b,c;
      cin >> a>> b >> c;
      g[a][b] = c;
      g[b][a] = c;
    }
    REP(i,n) g[0][i+1] = 0;
    memset(used,0,sizeof(used));
    ans = 0;
    solve(0, 0, 0);
    cout << ans << endl;
    REP(i, anspath.size()) {
      if (i)  cout << " ";
      cout << anspath[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#B
import sys
s = list(input())
one=["R", "U", "D"]
two=["L", "U", "D"]
for i in range(len(s)):
    if i % 2 == 0 and (one[0] != s[i] and one[1]!=s[i] and one[2]!=s[i]):
        print("No")
        sys.exit()
    if i % 2 != 0 and(two[0] != s[i] and two[1]!=s[i] and two[2]!=s[i]):
        print("No")
        sys.exit()
print('Yes')

Measured memory_bytes: 8972
#include <stdio.h>
#define N 507

int main (void) {
  int n, m, k, l, r, p, q, a[N][N], b[N][N];

  scanf("%d %d %d", &n, &m, &k);

  for (int i = 0; i < m; i++)  {
    scanf("%d %d", &l, &r);
    a[l][r]++;
  }

  for (int i = 0; i <= n; i++)
    b[i][0] = b[0][i] = 0;

  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      b[i][j] = b[i-1][j] + b[i][j-1] - b[i-1][j-1] + a[i][j];
  
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &p, &q);
    printf("%d\n", b[q][q] - b[p-1][q] - b[q][p-1] + b[p-1][p-1]);
  }

  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main(){
    int a,b;
    cin>>a>>b;
    if(0<a&&0<b){
        cout<<"Positive"<<endl;
    }
    else if(a<=0&&0<=b){
        cout<<"Zero"<<endl;
    }
    else{
        if((b-a)%2==0){
            cout<<"Negative"<<endl;
        }
        else{
            cout<<"Positive"<<endl;
        }
    }
}

Measured memory_bytes: 3616
#include <iostream>
using namespace std;
typedef long long ll;
int n, a[100010], x;
int main() {
	cin >> n >> x;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for(int i = 2; i <= n; i++) {
		if (a[i-1] + a[i] > x) {
			ans += (a[i-1] + a[i] - x);
			if (a[i-1] > x) {
				a[i] = 0;
			} else {
				a[i] = x - a[i-1];
			}
		}
	}
	cout << ans;
	return 0;
}

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

int arra[100001];

int main()
{
    int N,a,b,i,j;



    scanf("%d",&N);

    for(i=0;i<N;i++)
        scanf("%d",&arra[i]);

    sort(arra,arra+N,greater<int>());

    bool a_found=false,b_found=false;

    for(i=0,j=1;j<N;i++,j++){

        if(arra[i]==arra[j]){

                a_found=true;

            a=arra[i];

            break;

        }
    }

    if(a_found){

        for(i=j+1,j=j+2;j<N;j++,i++){

            if(arra[i]==arra[j]){

                b_found=true;

                b=arra[i];

                break;

            }



        }

    }

      if((a_found==true)&&(b_found==true)){

        printf("%lld",(long long int)a*b);


      }


       else{

        printf("0");

       }

    return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-9;
struct dot{
	double x,y;
	double len(){return sqrt(x*x+y*y);}
	dot(double a=0.0,double b=0.0){x=a,y=b;}
	dot operator +(const dot&b)const {return dot(x+b.x,y+b.y);}
	dot operator -(const dot&b)const {return dot(x-b.x,y-b.y);}
	dot operator *(const double&z)const {return dot(x*z,y*z);}
	bool operator <(const dot&b)const {return (x<b.x)||(x==b.x&&y<b.y);}
};
struct line{
	dot x1,x2;
};
double chaji(dot x,dot y){
	return x.x*y.y-x.y*y.x;
}
double neiji(dot x,dot y){
	return x.x*y.x+x.y*y.y;
}
double cos(dot x,dot y){
	if (!x.len()||!y.len())return 0;
	return neiji(x,y)/x.len()/y.len();
}
dot Projection(dot x,line y){//求x关于直线y的投影点（垂足） 
	y.x2=y.x2-y.x1;
	x=x-y.x1;
	double len=cos(x,y.x2)*x.len()/y.x2.len();
	y.x2=y.x2*len;
	return y.x2+y.x1;
}
dot Reflection(dot x,line y){//求x关于直线y的对称点 
	dot z=Projection(x,y);
	return z*2-x;
}
int Counter_Clockwise(dot x,line y){//求两个向量的五种关系 
	x=x-y.x1;y.x2=y.x2-y.x1;
	if (chaji(y.x2,x)!=0){
		if (chaji(y.x2,x)>0)return 1;
		return 2;
	} 
	if (fabs(cos(x,y.x2)+1)<eps)return 3;
	if (x.len()>y.x2.len())return 4;
	return 5;
} 
int main(){
	line x;int T;
	scanf("%lf%lf%lf%lf",&x.x1.x,&x.x1.y,&x.x2.x,&x.x2.y);
	scanf("%d",&T);
	while (T--){
		dot y;
		scanf("%lf%lf",&y.x,&y.y);
		int ans=Counter_Clockwise(y,x);
		if (ans==1)puts("COUNTER_CLOCKWISE");
		if (ans==2)puts("CLOCKWISE");
		if (ans==3)puts("ONLINE_BACK");
		if (ans==4)puts("ONLINE_FRONT"); 
		if (ans==5)puts("ON_SEGMENT");
	}
	return 0;
}



Measured memory_bytes: 3256
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, h: int, w: int):
    ret = (H - h) * (W - w)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    h = int(next(tokens))  # type: int
    w = int(next(tokens))  # type: int
    solve(H, W, h, w)

if __name__ == '__main__':
    main()


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

#define llint long long int
int main(void){

  short count[512] = {};

  for(int i=0; i<4; i++){
    char s;
    std::cin >> s;
    count[s]++;
  }

  for(int i=0; i<512; i++){
    if(count[i]!=0 && count[i]!=2){
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

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

	S.at(K - 1) = S.at(K - 1) + ('a' - 'A');

	cout << S << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Airplane
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int p, q, r;
  scanf("%d%d%d", &p, &q, &r);

  printf("%d\n", min(p + q, min(q + r , r + p)));
  return 0;
}


Measured memory_bytes: 256
w, h, x, y, r = list(map(int, input().split()))
# max_height = y + r
# max_width = x + r
max_width = x + r if x >= 0 else x + -(r)
max_height = y + r if y >= 0 else y + -(r)
if max_height <= h and max_height >= 0 and max_width <= w and max_width >= 0:
    print('Yes')
else :
    print('No')


Measured memory_bytes: 5596
input = raw_input

n = int(input())
q3 = n // 3
q5 = n // 5
q15 = n // 15

out = n * (n+1) // 2 - ( 3 * q3 * (q3+1) // 2 + 5 * q5 * (q5+1) // 2) + 15 * q15*(q15+1) // 2
print(out)

Measured memory_bytes: 64120
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>

using namespace std;



int main() {
	string s, t, u;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0)t += "0";
		else t += "1";
	}
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 1)u += "0";
		else u += "1";
	}
	int ct = 0, cu = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i])ct++;
		if (s[i] != u[i])cu++;
	}
	cout << min(cu, ct) << endl;

	return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	string s;
	cin>>n>>s;

	string t;
	rep(i,s.size()){
		int pos = s[i]-'A';
		pos = (pos+n)%26;
		t += 'A'+pos;
	}
	cout<<t<<endl;

	return 0;
}

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(X+1, Y+1):
    if i > max(x) and i <= min(y):
        print('No War')
        break
else:
    print('War')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#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()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
long long dp[3001][3001];
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  for(int i=A;i<=C;i++){
    for(int j=B;j<=D;j++){
      if(i==A&&j==B) dp[A][B]=1;
      else if(i==A&&j!=B) dp[A][j]=(A*dp[A][j-1])%998244353;
      else if(i!=A&&j==B) dp[i][B]=(B*dp[i-1][B])%998244353;
      else{
       dp[i][j]=(i*dp[i][j-1]+j*dp[i-1][j]-((i-1)*(j-1)*(dp[i-1][j-1]%998244353))%998244353);
       if(dp[i][j]<0) dp[i][j]+=998244353;
       dp[i][j]=dp[i][j]%998244353;
      }
    }
  }
  cout<<dp[C][D]<<endl;
  
  return 0;
}

Measured memory_bytes: 73784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1ll << 60;

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

ll MOD = 1000000007;
constexpr ll MAX_N = 100010;
ll dp[MAX_N];

int main(int argc, char **argv)
{
	ll N, M;
	cin >> N >> M;
	vector<ll> a(M);
	for (int i = 0; i < M; ++i) cin >> a[i];

	vector<bool> is_ok(MAX_N, true);
	for (int i = 0; i < M; ++i)
		is_ok[a[i]] = false;

	// Initialzie
	dp[0] = 1;
	if (is_ok[1])dp[1] = 1;

	for (int i = 2; i <= N; ++i)
	{
		if (is_ok[i-1]) dp[i] += dp[i-1];
		if (is_ok[i-2]) dp[i] += dp[i-2];
		dp[i] %= MOD;
	}

	std::cout << dp[N] << std::endl;
}


Measured memory_bytes: 1792
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 1005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
char S[MAX_N];
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");
	
	int N, K;
	scanf("%d %s %d", &N, S, &K);
	for (int i = 0; i < N; i++) if (S[i] != S[K - 1]) S[i] = '*';
	puts(S);
	return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**6
for i in range(M):
    x,y,c=map(int,input().split())
    ans=min(ans,(a[x-1]+b[y-1])-c)
a.sort(key=int)
b.sort(key=int)
for i in range(min(A,B)):
    if a[i]+b[i]>=ans: break
    ans=min(ans,a[i]+b[i])
print(ans)

Measured memory_bytes: 18736
#include <iostream>

using namespace std;

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

    int sum = a + b + c;
    int m = max(a, (max(b, c)));
    if ((3 * m - sum) % 2 != 0) m++;
    cout << (3 * m - sum) / 2 << endl;
}

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
n = ip()                                     #入力整数1つ
#n,q= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
dlist = []
ulist = []
for i in range(n):
    if i%2:
        ulist.append(a[i])
    else: dlist.append(a[i])
ulist.sort()
dlist.sort()

firstupper = 0
secondupper = 0
maxupper = ulist[0]
maxlower = dlist[0]
c = 1
cnum = ulist[0]
for i in range(1,len(ulist)):
    if ulist[i] == cnum:
        c+=1
    else:
        cnum = ulist[i]
        if c > firstupper:
            maxupper = ulist[i-1]
            secondupper = firstupper
            firstupper = c
        elif c > secondupper and firstupper >= c:
            secondupper = c
        c = 1
if c > firstupper:
    maxupper = ulist[i-1]
    secondupper = firstupper
    firstupper = c
elif c > secondupper and firstupper >= c:
    secondupper = c


firstlower = 0
secondlower = 0
c = 1
cnum = dlist[0]
for i in range(1,len(dlist)):
 #   print("f",dlist[i])
    if dlist[i] == cnum:
        c+=1
    else:
        cnum = dlist[i]
        if c > firstlower:
            maxlower = dlist[i-1]
            secondlower = firstlower
            firstlower = c
        elif c > secondlower and firstlower >= c:
            secondlower = c
        c = 1
if c > firstlower:
  #  print("reqmet")
    maxlower = dlist[i-1]
    secondlower = firstlower
    firstlower = c
elif c > secondlower and firstlower >= c:
    secondlower = c
c = 0
"""
print(maxupper,maxlower)
print(firstupper,firstlower)
print(secondupper,secondlower)
"""
p = len(ulist)
if maxupper == maxlower:
    print(min(p-firstupper+p-secondlower,p-secondupper+p-firstlower))
else: print(2*p - firstupper - firstlower)


Measured memory_bytes: 24412
import java.util.Scanner;
class Main{
	public static void main(String artgs[]){
    	Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();
      	String[] strlist = S.split("");
        String ns = "";
        for(int n = 0;n < N;n++){
        	if(strlist[n].equals(strlist[K-1]) == false){
            	strlist[n] = "*";  
                ns = ns + strlist[n];
            }else {
            	ns = ns + strlist[n];
            }
        }
      	System.out.println(ns);
    }  
}

Measured memory_bytes: 21588
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        Tuple<int,int,long>[]array=new Tuple<int,int,long>[n];
        int W=0,S=0;
        for(int i=0;i<n;i++){
            int[]wsv=Console.ReadLine().Split().Select(int.Parse).ToArray();
            int w=wsv[0];
            int s=wsv[1];
            long v=wsv[2];
            array[i]=new Tuple<int,int,long>(w+s,s,v);
            Chmax(ref S, s);
            Chmax(ref W, w);
        }
        W+=S;
        Array.Sort(array);

        long[]dp=new long[W+1];
        for(int i=0;i<n;i++){
            int w=array[i].Item1-array[i].Item2;
            int s=array[i].Item2;
            long v=array[i].Item3;
            for(int j=s;j>=0;j--){
                Chmax(ref dp[j+w], dp[j]+v);
            }

            // Console.Write($"[w s v] {w} {s} {v}:");
            // for(int j=0;j<=W;j++){
            //     Console.Write($" {dp[j]}");
            // }
            // Console.Write("\n");
        }
        long ans=0;
        for(int i=0;i<=W;i++){
            Chmax(ref ans, dp[i]);
        }
        Console.WriteLine(ans);
    }

    public static void Chmax(ref int x, int y){
        x = Math.Max(x,y);
    }
    public static void Chmax(ref long x, long y){
        x = Math.Max(x,y);
    }
}


Measured memory_bytes: 13508
N = int(input())
a = list(map(int, input().split()))
kisu = 0
gusu = 0
num_4 = 0

for i in range(N):
    if a[i] % 2 == 1:
        kisu += 1
    elif a[i] % 4 == 0:
        num_4 += 1
    else:
        gusu += 1
if gusu != 0:
    kisu += 1

print('Yes' if kisu <= num_4+1 else 'No')

Measured memory_bytes: 14252
def L_search(A,key):
    for i in range(len(A)):
        if A[i] == key:
            return i

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

    Loop_set,Loop_list = set([1]),[1]
    pt = 1 #最初の町
    while True:
        pt = A[pt-1]
        if pt not in Loop_set:
            Loop_set.add(pt)
            Loop_list.append(pt)
        else:
            break

    gosa = L_search(Loop_list,pt)
    shuki = len(Loop_list) - gosa
    if K < gosa:
        print(Loop_list[K])
    else:
        K -= gosa
        K %= shuki
        K += gosa
        print(Loop_list[K])

if __name__ == "__main__":
    main()


Measured memory_bytes: 32448
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 1000000007
using namespace std;
int main(void)
{
	int n,i,j,k,l,m,sum,dp[101][4][4][4];
	scanf("%d",&n);
	for(i=0;i<4;i++)	{
		for(j=0;j<4;j++)	{
			for(k=0;k<4;k++)	{
				if(!((i==0 && j==2 && k==1) ||
					(i==0 && j==1 && k==2) ||
					(i==2 && j==0 && k==1)))	{
						dp[3][i][j][k]=1;
					}
					else dp[3][i][j][k]=0;
			}
		}
	}
	for(i=4;i<=n;i++)	{
		for(j=0;j<4;j++)	{
			for(k=0;k<4;k++)	{
				for(l=0;l<4;l++)	dp[i][j][k][l]=0;
			}
		}
	}
	for(i=3;i<n;i++)	{
		for(j=0;j<4;j++)	{
			for(k=0;k<4;k++)	{
				for(l=0;l<4;l++)	{
					for(m=0;m<4;m++)	{
						if(!((k==0 && l==2 && m==1) ||
							(k==0 && l==1 && m==2) ||
							(k==2 && l==0 && m==1)	||
							(j==0 && l==2 && m==1) ||
							(j==0 && k==2 && m==1)))	{
								dp[i+1][k][l][m]+=dp[i][j][k][l];
								dp[i+1][k][l][m]%=MM;
						}
					}
				}
			}
		}
	}
	sum=0;
	for(i=0;i<4;i++)	{
		for(j=0;j<4;j++)	{
			for(k=0;k<4;k++)	{
				sum+=dp[n][i][j][k];
				sum%=MM;
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

int main() {
  int ans=0,res=0;
  string s;
  cin>>s;
  for(int i=0; i<s.size(); i++){
    if(s[i]!='A'&&s[i]!='T'&&s[i]!='G'&&s[i]!='C'){
      ans=max(ans,res);
      res=0;
    }
    else res++;
  }
  cout<<max(ans,res);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Prop
{
    internal Vector P1;
    internal Vector P2;
    internal Vector Q;
}
class Vector
{
    internal double X;
    internal double Y;
}
public class Pg
{
    IEnumerable<Prop> Read()
    {
        string line;
        while (!string.IsNullOrEmpty(line = Console.ReadLine()))
        {
            var tmp = line.Split(',').Select(double.Parse).ToList();
            var p = new Prop
            {
                P1 = new Vector { X = tmp[0], Y = tmp[1] },
                P2 = new Vector { X = tmp[2], Y = tmp[3] },
                Q = new Vector { X = tmp[4], Y = tmp[5] }
            };
            yield return p;
        }
    }

    void Run()
    {
        Read().ForEach(delegate (Prop p)
        {
            if (p.P1.X == p.P2.X)
            {
                p.Q.X = p.Q.X + (p.P1.X - p.Q.X) * 2;
                Console.WriteLine($"{p.Q.X:f5} {p.Q.Y:f5}");
            }
            else if (p.P1.Y == p.P2.Y)
            {
                p.Q.Y = p.Q.Y + (p.P1.Y - p.Q.Y) * 2;
                Console.WriteLine($"{p.Q.X:f5} {p.Q.Y:f5}");
            }
            else
            {
                var a = (p.P1.Y-p.P2.Y)/(p.P1.X-p.P2.X);
                var b = p.P1.Y-p.P1.X*a;
                var x = (2*p.Q.Y*a-2*a*b+p.Q.X-a*a*p.Q.X)/(a*a+1);
                var y = (p.Q.X-x)/a+p.Q.Y;
                Console.WriteLine($"{x:f5} {y:f5}");
            }
        });
    }

    public static void Main() => new Pg().Run();
}
public static class Ext
{
    public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
    {
        foreach (var item in source)
        {
            action(item);
        }
    }
}


Measured memory_bytes: 16332
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int x;
    cin >> x;
    int ans = 0;
    if(x <= 2){
        cout << 2 << endl;
        return 0;
    }else if(x % 2 == 0){
        x += 1;
    }
    while(1){
        bool f = true;
        for(int i = 3; i * i <= x; i += 2){
            if(x % i == 0){
                f = false;
                break;
            }
        }
        if(f){
            break;
        }
        x += 2;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>

#define ALL(a)  (a).begin(),(a).end()

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

int main() {
    string s;
    int n, ans = 0;


    cin >> n >> s;

    if (s.length() % 2 == 0) {
        for (int i = 0; i < (int)s.length() / 2; i++) {
            if (s[i] != s[i + (int)s.length() / 2]) ans++;
        }
    }
    else ans++;


    (ans == 0) ? (cout << "Yes" << endl) : (cout << "No" << endl);
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=2e5+10;
int n, k;  
int a[N];

bool check(int mid){
	int res=0;
	for(int i=0;i<n;i++)
		res+=(a[i]-1)/mid;
	return res<=k;	
}
 
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];	
	sort(a, a+n);
	
	int l=1,r=1e9;
	while(l<r){
		int mid=l+r>>1;
		if(check(mid)) r=mid;
		else l=mid+1;	
	}
	
	cout<<l;

	return 0;
}


Measured memory_bytes: 4424
#include <cmath>
#include <iostream>
using namespace std;
int main(int argc, char const* argv[]) {
    int n, m;
    cin >> n >> m;
    auto a = floor(m / n);
    for (int i = a; i >= 1; --i) {
        if (m % i == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pf printf
#define sc scanf
#define endl "\n"
#define dbug(x) cout << #x << ": " << x << endl
#define gi(k) scanf("%d",&k)
#define gl(k) scanf("%lld",&k) 
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define rep(i,n) for(int i = 1; i <= n; i++)
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,cur) N=(N|(1LL<<cur))
#define Reset(N,cur) N=(N&(~(1LL<<cur)))
#define Check(N,cur) (!((N&(1LL<<cur))==0))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define NMAX 2147483647
#define LMAX 9223372036854775807LL
#define mem CLR
 
using namespace std;
 
 
#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
 
inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

 
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;
 
 
int t,n,x,sum; 
bitset<4000006>dp;

int main () {
    
    #ifdef forthright48
    freopen ( "00_input.txt", "r", stdin ); //freopen ( "00_output.txt", "w", stdout );
    #endif

    dp[0] = 1;

    cin >> n;
    rep(i,n) {
        cin >> x;

        dp |= (dp << x);
        sum += x;
    }

    sum = (sum + 1) / 2;

    for(int i = sum; ; i++) {
        if(dp[i]) {
            cout << i << endl;
            return 0;
        }
    }
 
    return 0;
}

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

int main()
{
	int i,b,c,d;
	vector< int > a;

	cin >> i;
	for(int j=0; j<i; j++){
		cin >> b >> c >> d;
		a.push_back( b );
		a.push_back( c );
		a.push_back( d );
		sort(a.begin(), a.end());
		if(a[0]*a[0] + a[1]*a[1] == a[2]*a[2]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
		a.clear();
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }


int main(void){

    ll N, K; cin >> N >> K;
    ll ans = 0LL;
    for(int b=1; b<=N; b++){
        ll p = N/b;
        ll r = N%b;

        ans += p * max(0LL, b-K);
        ans += max(0LL, r-K+1);
        
    }

    if(K == 0) ans -= N;
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;

int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    for(int i = 0; i < 8; i++){
        int ans = 0;
        for(int j = 3; j >= 0; j--){
            if(j == 3){
                ans += s[j] - '0';
            }else{
                if(((i >> j) & 1) == 1){
                    ans += s[j] - '0';
                }else{
                    ans -= s[j] - '0';
                }
            }
        }
        if(ans == 7){
            for(int k = 3; k >= 0; k--){
                if(k == 3){
                    cout << s[k];
                }else{
                    if(((i >> k) & 1) == 1){
                        cout << "+" << s[k];
                    }else{
                        cout << "-" << s[k];
                    }
                }
            }
            cout << "=7" << endl;
            break;
        }
    }
}



Measured memory_bytes: 256
X = int(input())
if X >= 100:
    first = int(str(X)[:-2])

    last = int(str(X)[-2:])
    p = [0 for i in range(6)]
    for i in range(5,0,-1):
        p[i] = last // i
        last = last - p[i] * i
    sump = sum(p)
    if first >= sump:
        print(1)
    else:
        print(0)
else:
    print(0)

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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
  if(A.size() == n+1){
    int now = 0;
    for(int i=0; i<q; i++){
      if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans,now);
    return;
  }
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}
  

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  for(int i=0; i<q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 3620
primes = [0, 0] + [1]*9999
for i in range(2, 100):
    for j in range(i*i, 10001, i):
        primes[j] = 0

while True:
    n = int(input())
    if n == 0:
        break
    for i in range(2, n+1)[::-1]:
        if primes[i-2] and primes[i]:
            print(i-2, i)
            break

Measured memory_bytes: 7652
sx, sy, tx, ty = gets.split(" ").map{|v|
	v.to_i
}

x = tx-sx
y = ty-sy

ans = ""
ans << "R"*x
ans << "U"*y
ans << "L"*x
ans << "D"*y

ans << "D"
ans << "R"*(x+1)
ans << "U"*(y+1)
ans << "L"

ans << "U"
ans << "L"*(x+1)
ans << "D"*(y+1)
ans << "R"

puts ans


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

using namespace std; 

int main() { 

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	string s;
	cin >> s;
	
	sort(s.begin(), s.end());
	
	if(s[0] == s[1] and s[2] == s[3] and s[0] != s[2]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0; 
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
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() {
    ll a,b;
    std::cin >> a>>b;
    if(a >= 13){
        std::cout << b << std::endl;
    }else if(a >= 6){
        std::cout << b/2 << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }
}


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

using namespace std;

int main (){

	int cnt;
	int mi =0;
	int ta;
	int to = -999999999;
	int a[200000];
	cin >> cnt;
	for(int i = 1;i <= cnt;i++){
	cin >> a[i - 1];
	if(i == 1) {mi = a[0] ;
	}else{
	to = max(to,a[i - 1] - mi);
	mi = min(mi,a[i - 1]);
	}
	}
	cout << to <<endl;


	return 0;
}

Measured memory_bytes: 3880
R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    if R * r <= N:
        for g in range(min(3000, 3000 // G) + 1):
            v = R * r + G * g
            if N >= v and (N - v) % B == 0:
                ans += 1

print(ans)


Measured memory_bytes: 9116
#include <algorithm>
#include <iostream>

using namespace std;

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

int N, A, B, C, X;
int Y[101];

int next(int x) { return (A * x + B) % C; }
void solve() {
    int cnt = 0;
    int ans;
    int pos = 0;
    while (1) {
        if (cnt == 10001) {
            cnt = -1;
            break;
        }
        if (X == Y[pos]) pos++;
        X = next(X);
        if (pos == N) break;
        cnt++;
    }
    cout << cnt << endl;
}

int main() {
    while (cin >> N >> A >> B >> C >> X) {
        if (N == 0) break;
        rep(i, N) cin>>Y[i];
        solve();
    }
}

Measured memory_bytes: 3064
import java.io.PrintWriter
import java.math.BigDecimal

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val aa = listOfInt()
    var count = 0

    aa.forEach {
        var num = it
        while (num % 2 == 0) {
            num /= 2
            count++
        }
    }

    println(count)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 41772
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  string S;
  cin >> S;
  int ans = 0;
  int tmp = 0;
  for(int i=0; i<S.size(); i++) {
    if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
      tmp++;
    else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define int long long
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[111100];
bool ii[11111];
int u;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=1,h=2,j;
  cin >>a>>b>>c>>d;
  a=c-a,b=d-b;
  d+=a,c-=b;
  cout <<c<<' '<<d<<' ';
  cout <<c-a<<' '<<d-b<<'\n';
  return (0);
}


Measured memory_bytes: 256
def dfs(i, f, sum):
    if i == n-1:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i+1, f+'-'+s[i+1], sum - int(s[i+1]))
        dfs(i+1, f+'+'+s[i+1], sum + int(s[i+1]))

s = input()
n = len(s)

print(dfs(0, s[0], int(s[0])))

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++) {
            if(i == k-1) sb.append(String.valueOf(s.charAt(i)).toLowerCase());
            else sb.append(s.charAt(i));
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
 
typedef long long LL;
typedef unsigned long long LONG;
const int N = 1e5 + 5;
using namespace std;
typedef pair<int, int> PII;
#define ft fisrt
#define sd second
#define eb emplace_back
 
template<class T>
inline bool read(T &ret) {
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF) return 0;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
 
LL a[N * 5], k, n;
LL ans = 0, sum[N * 5] = {0};
map<unsigned int, LL> num;
 
int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        read(a[i]);
        sum[i] = sum[i - 1] + a[i];
    }
    for (int i = 0; i <= n; ++i) {
        if (i - k >= 0) {
            num[(sum[i - k] - (i - k)) % k]--;
        }
        if (num.count((sum[i] - i) % k)) {
            ans += num[(sum[i] - i) % k];
        }
        num[(sum[i] - i) % k]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, D, A;
  cin >> N >> D >> A;
  vector<pll> X(N);
  for (ll i = 0; i < N; ++i) {
    ll x, h;
    cin >> x >> h;
    X.at(i) = {x, h};
  }
  sort(X.begin(), X.end(), [] (pll a, pll b) {
    return a.first < b.first;
  });
  // for (ll i = 0; i < N; ++i) {
  //   cout << X.at(i).first << ' ' << X.at(i).second << endl;
  // }
  ll ans = 0;
  vector<ll> cumulative_sum(N + 1, 0);
  for (ll i = 0; i < N; ++i) {
    if (i != 0) {
      cumulative_sum.at(i) += cumulative_sum.at(i - 1);
    }
    X.at(i).second -= cumulative_sum.at(i) * A;
    if (X.at(i).second <= 0) {
      continue;
    }
    ll attack_time = X.at(i).second / A + min(1ll, X.at(i).second % A);
    ans += attack_time;
    cumulative_sum.at(i) += attack_time;

    ll l = i, r = N;
    while (l + 1 != r) {
      ll m = (l + r) / 2;
      if (X.at(m).first - X.at(i).first > 2 * D) {
        r = m;
      }
      else {
        l = m;
      }
    }
    cumulative_sum.at(r) -= attack_time;

    // ll cnt = 0;
    // while (true) {
    //   if (i + cnt == N) {
    //     break;
    //   }
    //   if (X.at(i + cnt).first - X.at(i).first > 2 *  D) {
    //     break;
    //   }
    //   X.at(i + cnt).second -= attack_time * A;
    //   cnt += 1;
    // }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
x, k, d = map(int, input().split())
x = abs(x)

p = x // d
if p > k:
  print(x - k * d)
else:
  min = [x, x]
  min[p%2] = x - p * d
  min[(p+1)%2] = abs(min[p%2] - d)
  print(min[k%2])

Measured memory_bytes: 9164
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M, K = [int(x) for x in input().split()]

    u = UnionFind(N)
    ans1 = [0] * N
    for _ in range(M):
        a, b = [int(x) for x in input().split()]
        ans1[a - 1] += 1
        ans1[b - 1] += 1
        u.union(a - 1, b - 1)

    ans2 = [0] * N
    for _ in range(K):
        a, b = [int(x) for x in input().split()]
        if u.same(a - 1, b - 1):
            ans2[a - 1] += 1
            ans2[b - 1] += 1

    for i in range(N):
        print(u.size(i) - ans1[i] - ans2[i] - 1, end=" ")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
int main()
{
 
  int n,k,d,i;
  cin>>n>>k;
  int a[n+3];
  for(i=1;i<=n;i++)
  {
    a[i]=i;
  }
   while(k--)
   {
    cin>>d;
    while(d--)
    {
        int x;
        cin>>x;
        a[x]=0;
    }
   }
  int c=0;
   for(i=1;i<=n;i++)
   {
    if(a[i]!=0)
    {
        c++;
    }

   }
   cout<<c<<endl;
   return 0;
}

Measured memory_bytes: 3636
sa = input()
sb = input()
sc = input()

word = sa[0]
sa = sa[1:]
while True:
    if word == "a":
        if len(sa) == 0:
            print("A")
            break
        else:
            word = sa[0]
            sa = sa[1:]
    elif word == "b":
        if len(sb) == 0:
            print("B")
            break
        else:
            word = sb[0]
            sb = sb[1:]
    else:
        if len(sc) == 0:
            print("C")
            break
        else:
            word = sc[0]
            sc = sc[1:]


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}

int N, M, K;
string S, T;
vector<int> V;
void input() {

}
void solve() {
  cin>>S;
  cin>>T;
  int ans = 0;
  rep(i,0,2){
    if (S[i]==T[i])ans++;

  }
  cout<<ans<<endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20,MOD=2019;

int n;
char a[N];
long long v,ans;

int main()
{
	scanf(" %s",a+1);
	n=strlen(a+1);

	vector <int> prev(MOD,0);
	prev[0]++;
	for(int i=1;i<=n;i++)
	{
		vector <int> curr(MOD,0);
		for(int i=0;i<MOD;i++) curr[(i*10)%MOD]+=prev[i];
		prev=curr;


		v=(v*10+a[i]-'0')%MOD;
		prev[v]++;
		ans+=prev[v]-1;
	}

	printf("%lld",ans);
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
typedef long long ll;
using namespace std;
const int inf=1e9;

int effect[100010];
int edge[100010];
bool visited[100010];
int dfs(int x) {
	if (effect[x]==0) return edge[x] = x;
	if (edge[x]!=-1) return edge[x];
	if (visited[x]) return inf; //roop?
	visited[x]=true;
	return edge[x] = dfs(x + effect[x]);
}

int main(){
	int n;
	cin>>n;
	int d[100010];
	REP(i,0,n) {
		cin>>effect[i];
		visited[i]=false;
		edge[i]=-1;
		d[i]=inf;
	}
	REP(i,0,n)	if(edge[i] == -1) dfs(i);
	priority_queue<pair<int,int>> pq;//cost,node
	d[0]=0;
	pq.push({0,0});
	while(!pq.empty()){
		int now = pq.top().second;
		pq.pop();
		REP(i,1,7){
			if(edge[now+i]==inf) continue;
			int next = edge[now+i];
			if(d[next] > d[now] + 1){
				d[next] = d[now] + 1;
				pq.push({-d[next],next});
			}
		}
		if(d[n-1] != inf) break;
	}
	p(d[n-1]);
	return 0;
}

Measured memory_bytes: 5568
s = list(input())

def sum_list(S,stock):
    if len(S) == 2:
        return int(S[0]) + int(S[1]) + int(S[0]+S[1]) + stock * 2
    elif len(S) == 1:
        return int(S[0])
    else:
        return sum_list(S[1:],int(S[0])+stock) + sum_list([S[0]+S[1]]+S[2:],stock)
                                                 
print(sum_list(s,0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    ll X; cin >> X;
    ll ans;
    for (int i = 0; i <= X; i++)
    {
        if(i*(i+1)/2>=X){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    vl a(n);rep(i,n)cin >> a[i];
    ll mini=0;
    ll ans=0;
    rep(i,n){
        if(mini>=a[i])ans+=mini-a[i];
        else mini=a[i];
    }
    cout << ans <<endl;
} 

Measured memory_bytes: 4836