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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int Signum(double x){
	return x<-EPS?-1:x>EPS?1:0;
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){
		x+=p.x,y+=p.y;
		return *this;
	}
	Point& operator-=(Point p){
		x-=p.x,y-=p.y;
		return *this;
	}
	Point& operator*=(double c){
		x*=c,y*=c;
		return *this;
	}
	Point& operator/=(double c){
		x/=c,y/=c;
		return *this;
	}
};
Point operator+(Point a,Point b){
	return a+=b;
}
Point operator-(Point a,Point b){
	return a-=b;
}
Point operator*(Point a,double c){
	return a*=c;
}
Point operator*(double c,Point a){
	return a*=c;
}
Point operator/(Point a,double c){
	return a/=c;
}
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}

struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
	Line(double px,double py,double dx,double dy):pos(px,py),dir(dx,dy){}
};
struct Segment{
	Point pos,dir;
	Segment(){}
	Segment(Point p,Point d):pos(p),dir(d){}
	Segment(double px,double py,double dx,double dy):pos(px,py),dir(dx,dy){}
	explicit Segment(Line l):pos(l.pos),dir(l.dir){}
	explicit operator Line()const{return Line(pos,dir);}
};

double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Dot(Point a,Point b){
	return a.x*b.x+a.y*b.y;
}
double Cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}

int CCW(Point a,Point b,Point c){
	b-=a,c-=a;
	if(int sign=Signum(Cross(b,c)))
		return sign; // 1:ccw,-1:cw
	if(Dot(b,c)<-EPS)
		return -2;   // c-a-b
	if(Abs2(b)<Abs2(c)-EPS)
		return 2;    // a-b-c
	return 0;        // a-c-b
}

bool IntersectSS(Segment a,Segment b){
	int c1=CCW(a.pos,a.pos+a.dir,b.pos),c2=CCW(a.pos,a.pos+a.dir,b.pos+b.dir);
	int c3=CCW(b.pos,b.pos+b.dir,a.pos),c4=CCW(b.pos,b.pos+b.dir,a.pos+a.dir);
	return c1*c2<=0 && c3*c4<=0;
}

void solve()
{
	Segment a; cin>>a.pos.x>>a.pos.y>>a.dir.x>>a.dir.y; a.dir-=a.pos;
	Segment b; cin>>b.pos.x>>b.pos.y>>b.dir.x>>b.dir.y; b.dir-=b.pos;
	cout<<IntersectSS(a,b)<<endl;
}

int main()
{
	int q; cin>>q;
	rep(_,q) solve();
}

Measured memory_bytes: 1240
N,M=map(int,input().split())
R=[True]+[False]*(N-1)
B=[1]*N
for i in range(M):
    x,y=map(int,input().split())
    if R[x-1]:
        R[y-1]=True
    B[x-1]-=1
    B[y-1]+=1
    if B[x-1]==0:
        R[x-1]=False
print(R.count(True))

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll n,k;
    cin >> n >> k;
        int l=n,m=0,i=0;
        while(l>=k){
            l=l/k;
            m=l%k;
            i++;
            //cout <<l<<"："<<m<<"："<<i<<endl;
        }
        cout << i+1;
        return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if (k % 2 == 0) {
        ans += pow((n - (k / 2) + k) / k, 3);
    }
    ans += pow(n / k, 3);
    cout << ans << endl;
    
}



Measured memory_bytes: 640
#include<iostream>

int main(){
	long long n,d,d2;
  	std::cin >> n >> d;
  	d2 = d*d;
  	int ans = 0;
  	for(int i=0; i<n; i++){
		long long x,y; std::cin >> x >> y;
      	long long dist2 = x*x + y*y;
      	if(dist2 <= d2) ans++;
    }
  	std::cout << ans << std::endl;
  	return 0;
}


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

int main() {
	int n,i,k;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	  cin>>a[i];
	sort(a,a+n);
	int min1=INT_MAX;
	for(i=k-1;i<n;i++)
	  {	
	  	 min1=min(min1,a[i]-a[i-k+1]);
	  }
	cout<<min1<<'\n';  
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
pair<int,int>a[214514];
signed main(){
	ic(n) ic(d)
	c((n-1)/(d*2+1)+1)
}	

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    public static int gcd(int a,int b)
    {
        if(b==0)
            return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 32772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,m;
char ch[205][205];
short dp[205][205][205][20];
vector<int>forbid[205][205];
vector<int>forbid2[205][205];
int rui[205][205];
int rui2[205][205];
int calc(int xa,int xb,int yc,int yd){
	return rui[xb+1][yd+1]-rui[xa][yd+1]-rui[xb+1][yc]+rui[xa][yc];
}
int calc2(int xa,int xb,int yc,int yd){
	return rui2[xb+1][yd+1]-rui2[xa][yd+1]-rui2[xb+1][yc]+rui2[xa][yc];
}
int lm[205];
int main(){
	cin>>n>>m;
	rep(i,n) scanf("%s",&ch[i]);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++){
	    rui[i+1][j+1] = rui[i][j+1]+rui[i+1][j]-rui[i][j]+(ch[i][j]=='#');
	    rui2[i+1][j+1] = rui2[i][j+1]+rui2[i+1][j]-rui2[i][j]+(ch[i][j]!='#');
	}
	rep(i,n) rep(j,n) rep(k,m) rep(a,20) dp[i][j][k][a] = -10000;
	rep(i,n) for(int j=i;j<n;j++){
		for(int k=0;k<m;k++){
			if(calc(i,j,k,k) > 0) {forbid[i][j].pb(k);}
			if(calc2(i,j,k,k) > 0) {forbid2[i][j].pb(k);}
		}
	}
	for(int i=1;i<=200;i++) for(int j=0;;j++) if((1<<j) >= i){ lm[i] = j; break; }
    for(int i=n-1;i>=0;i--) for(int j=i;j<n;j++){
		for(int k=m-1;k>=0;k--){
			//dp[i][j][k][*]
			if(ch[i][k] == '.'){
    			int x = POSL(forbid[i][j],k);
    			if(x == forbid[i][j].size()){
    				rep(x,18) dp[i][j][k][x] = m-1;
    				continue;
    			}
    			else if(forbid[i][j][x] > k) dp[i][j][k][0] = forbid[i][j][x]-1;
			}
			else{
			   int x = POSL(forbid2[i][j],k);
    			if(x == forbid2[i][j].size()){
    				rep(x,18) dp[i][j][k][x] = m-1;
    				continue;
    			}
    			else if(forbid2[i][j][x] > k) dp[i][j][k][0] = forbid2[i][j][x]-1;
			}
			for(int x=1;x<=lm[j-i+1]+lm[m-k];x++){
				dp[i][j][k][x] = max(dp[i][j][k][x],dp[i][j][k][x-1]);
				if(dp[i][j][k][x] == m-1) continue;
				//tate
				if(dp[i][j][k][x-1] >= 0){
					int pos = dp[i][j][k][x-1]+1;
					if(pos == m) dp[i][j][k][x] = m-1;
					else{
						if(dp[i][j][pos][x-1] >= pos){
							dp[i][j][k][x] = max(dp[i][j][k][x],dp[i][j][pos][x-1]);
						}
					}
				}
				//yoko
				int lb = i,ub = j-1;
				while(ub-lb > 1){
					int mid = (lb+ub)/2;
					if(dp[i][mid][k][x-1] < 0 && dp[mid+1][j][k][x-1] < 0 ) break;
					if(dp[i][mid][k][x-1] <= dp[mid+1][j][k][x-1]){
						ub = mid;
					}
					else{
						lb = mid;
					}
				}
				for(int xx=-1;xx<=1;xx++){
					int V = ub+xx;
					if(i <= V && V <= j-1){
						dp[i][j][k][x] = max(dp[i][j][k][x],min(dp[i][V][k][x-1],dp[V+1][j][k][x-1]));
					}
				}
			}
			for(int x=lm[j-i+1]+lm[m-k]+1;x<18;x++) dp[i][j][k][x] = m-1;
		}
	}
	for(int i=0;i<18;i++){
		if(dp[0][n-1][0][i] >= m-1){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 342272
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>> v(n);

    string s;
    int val;
    for(int i=0;i<n;i++){
        cin>>s>>val;
        v[i].first.first=s;
        v[i].first.second=-1*val;
        v[i].second=i+1;
    }

    sort(all(v));
    for(int i=0;i<n;i++){
       cout<<v[i].second<<endl;
    }

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,j,k) for(int i=j;i<(k);i++)

int main(){
	set<char> set_R;
	set_R.insert('y');
	set_R.insert('u');
	set_R.insert('i');
	set_R.insert('o');
	set_R.insert('p');
	set_R.insert('h');
	set_R.insert('j');
	set_R.insert('k');
	set_R.insert('l');
	set_R.insert('n');
	set_R.insert('m');
	string str;
	while(cin >> str){
		int flag=0,sum = 0;
		if(str == "#"){ return 0;}
		if(set_R.count(str[0])==1) { flag = 1 ;}
		rep(i,str.length()){
			if(flag==0&&set_R.find(str[i])!=set_R.end()){
				sum++;
				flag = 1;
			}else if(flag==1&&set_R.find(str[i])==set_R.end()){
				sum++;
				flag = 0;
			}
			
		}
		cout << sum << endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int i = 1;
        int x = in.nextInt();

        while (x != 0) {
            System.out.println("Case " + i + ": " + x);
            x = in.nextInt();
            i++;
        }

        System.exit(0);
    }
}



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

typedef long long ll;
const int mod = 1000000007;

int main() {
  int N;
  cin >> N;
  
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll sum = 0;
  // 各桁について調べる。「0の個数」×「1の個数」に桁分を乗じた数を足していく
  for (ll d = 0; d < 60; d++) {
    ll count0 = 0;
    ll count1 = 0;
    for (ll i = 0; i < N; i++) {
      if((A[i] >> d) & 1LL) {
        count1++;
      } else {
        count0++;
      }
    }
    sum = ((sum % mod) + (count0 * count1 % mod) * ((1LL << d) % mod) % mod) % mod;
  }
  
  cout << sum % mod << endl;
  return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        if (a <= 9 && a > 0 && b <= 9 && b > 0) {
            System.out.println(a * b);
        } else {
            System.out.println(-1);
        }
    }
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	vector<LL> a(N),s(N+1,0);
	vector<vector<LL>> dp(N,vector<LL>(N,1e18));
	repp(i,0,N){
		cin >> a[i];
		s[i+1] = s[i]+a[i];
		dp[i][i] = 0;
	}
	repp(d,1,N) repp(i,0,N-d){
		int j = i+d;
		repp(k,i,j) dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]-s[i]+s[j+1]);
	}
	cout << dp[0][N-1] << endl;
	return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
	private void calc(){
		Scanner scanner = new Scanner(System.in);
		int x =scanner.nextInt();
		int y =scanner.nextInt();
		if(x>y){
			System.out.println("a > b");
		}else if(x<y){
			System.out.println("a < b");
		}else{
			System.out.println("a == b");
		}
	}
	
	public static void main(String[] args) {
		Main run =new Main();
		run.calc();

	}
}

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

#define DEBUG(X) if(X)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int main()
{
  FASTIO;
  string str;
  long long n, a, b;
  cin >> n >> a >> b;
  if(a == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  long long j = a * (n / (a + b));
  if((n % (a + b)) != 0)
    j += min(a, (n % (a + b)));
  cout << j << endl;
  return 0;
}
// coloco a , n -= a, 
/*
  12 3 4
  bbbrrrrbbbrr
*/


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0

dp = [[0]*10 for _ in range(10)]

for i in range(1,n+1):
    s,t = int(str(i)[0]),int(str(i)[-1])
    dp[s][t] += 1

ans = 0
for i in range(1,n+1):
    s,t = int(str(i)[0]),int(str(i)[-1])
    ans += dp[t][s]
print(ans)

Measured memory_bytes: 40812
#include<stdio.h>
 int n,a[50];
 int solve(int i,int m){
   if(m == 0)return 1;
   if(i >= n)return 0;
   int res = solve(i + 1,m) || solve(i +1,m - a[i]);
     return res;
 }
int main(){
  int q,M,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2108
import fractions
n=int(input())
a=list(map(int,input().split()))
l=[a[0]]
for i in range(1,n):
    l.append(fractions.gcd(l[-1],a[i]))
    if l[-1]==1:
        for j in range(n-len(l)):l.append(1)
        break
r=[a[-1]]
for i in range(n-2,-1,-1):
    r.append(fractions.gcd(r[-1],a[i]))
    if r[-1]==1:
        for j in range(n-len(r)):r.append(1)
        break
r=r[::-1]
ans=max(l[-2],r[1])
for i in range(1,n-1):ans=max(ans,(fractions.gcd(l[i-1],r[i+1])))
print(ans)


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

int main() {  
  int n;
  cin >> n;
  vector<int> p(n),a(n);
  rep(i,n) {
  	cin >> p[i];
  }
  rep(i,n) {
  	a[i] = i+1;
  }
  int pi,pj;
  bool flag = false;
  if(p != a){
  	rep(i,n) {
  		for(int j = i+1; j < n; j++){
        	pi = p[i];
          	pj = p[j];
          	swap(p[i],p[j]);
          	if(p == a){
            	cout << "YES" << endl;
                flag = true;
              break;
            }
          	else {
          		p[i] = pi;
              	p[j] = pj;
            }
        }
  	}
  }
  else {cout << "YES" << endl; flag = true;}
  if(!flag) cout << "NO" << endl;
}

Measured memory_bytes: 256
n=int(input())

a=0
w=0
t=0
r=0
for i in range(n):
  s=input()
  if s=='AC':
    a=a+1
  if s=='WA':
    w=w+1
  if s=='TLE':
    t=t+1
  if s=='RE':
    r=r+1

print('AC x',a)
print('WA x',w)
print('TLE x',t)
print('RE x',r)

Measured memory_bytes: 9208
using System;

namespace ABC158B
{
    static class Program
    {
        static void Main()
        {
            long[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            var total = (nbrs[0] / (nbrs[1] + nbrs[2])) * nbrs[1];
            var remaining = Math.Min(nbrs[1], nbrs[0] % (nbrs[1] + nbrs[2]));
            total += remaining;
            Console.WriteLine(total);
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
struct area { 
	int x,y,val;
	bool operator == (const area &a) const { 
		return x==a.x&&y==a.y;
	} 
};
vector<area>lis[1000000];
int n,h,w;
long long hsh(area a) { 
	return (1ll*a.x*19260817+a.y)%922021;
} 

void ins(int y,int x) { 
	for(int i=0;i<=2;++i) { 
		for(int j=0;j<=2;++j) { 
			int tx=x-i,ty=y-j;
			if(tx<=0||ty<=0||tx+2>w||ty+2>h) continue;
			int loc=hsh({tx,ty,0});
			bool in=1;
			for(int i=0;i<lis[loc].size();++i) { 
				if(lis[loc][i]==(area){tx,ty,0}) { 
					lis[loc][i].val++;
					in=0;break;
				} 
			}
			if(in==1) lis[loc].push_back((area){tx,ty,1});
		} 
	} 
} 

int ans[12];

int main() { 
	int x,y;
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;++i) { 
		scanf("%d%d",&y,&x);
		ins(y,x);
	} 
	long long tans=0;
	for(int i=0;i<922021;++i) { 
		for(int j=0;j<lis[i].size();++j) { 
			ans[lis[i][j].val]++;
			tans++;
		} 
	} 
	printf("%lld\n",1ll*(h-2)*(w-2)-tans);
	for(int i=1;i<=9;++i) printf("%d\n",ans[i]);
	return 0;
} 


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

int main(){
  int n,count=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<n-2; i++){
    if(s.at(i) == 'A'){
      if(s.at(i+1) == 'B'){
        if(s.at(i+2) == 'C'){
          count++;
        }
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
import numpy as np
n,k,q=[int(x) for x in input().split()]
j=0
v=np.zeros(n)
while j<q:
	i=int(input())
	v[i-1]+=1
	j+=1
j=0
while j<n:
	if(k>q-v[j]):
		print('Yes')
	else:
		print('No')
	j+=1

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

int main() {
  rep(i, 5){
    int x;
    cin >> x;
    if(x == 0){
      cout << i + 1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3568
import sys
input=sys.stdin.readline
n=int(input())
arr=list(map(int,input().split()))
have=0
ans=1000
rate=0
for i in range(n-1):
    
    if(have!=0):
        if(arr[i+1]<arr[i]):
            ans+=have*(arr[i]-rate)
            have=0
    else:
        if(arr[i+1]>arr[i]):
            have=ans//arr[i]
            rate=arr[i]
    #print(have,ans,rate)
#print(have)
if(have!=0):
    ans+=have*(arr[-1]-rate)
    have=0
print(ans)            
    
           
        

    

Measured memory_bytes: 9104
#include <stdio.h>

int main(void) {
    int M;
    int N;
    scanf("%d",&N);
    M = N;
    int dig;
    int Sn = 0;

    while(M){
        dig = M % 10;
        Sn = Sn + dig;
        M = M/10;
    }
    if(N%Sn == 0){
        printf("Yes\n");
    } else {
        printf("No\n");
    }

}

Measured memory_bytes: 128
#include <iostream>

using namespace std;
int main(){
	int a,b,now = 1,i;
	cin >> a >> b;
	if(b==1){
		cout << 0 << endl;
		return 0;
	}
	for(i=1;i<=100;i++){
		now += a - 1;
		if(now>=b){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
S = input()
w = int(input())

sl = []
ans = ''
tmp_s = ''
for i, s in enumerate(S):
    tmp_s += s
    if (i+1) % w == 0:
        ans += tmp_s[0]
        tmp_s = ''
else:
    if len(tmp_s) >= 1:
        ans += tmp_s[0]
print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	struct max_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}
}

void Main()
{
	int A, B, C, D;
	std::cin >> A >> B >> C >> D;
	while (true)
	{
		C -= B;
		if (C <= 0)
		{
			std::cout << "Yes" << std::endl;
			return;
		}
		A -= D;
		if (A <= 0)
		{
			std::cout << "No" << std::endl;
			return;
		}
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3576
from collections import deque
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
def dfs(h,w):
    q=deque()
    q.append((h,w))
    s[h][w]='.'

    dx=[0,1,0,-1]
    dy=[1,0,-1,0]
    cnt=0
    while q:
        task=q[-1]
        for i in range(4):
            nx=task[0]+dx[i]
            ny=task[1]+dy[i]
            if not(0<=nx<H and 0<=ny<W):continue
            if s[nx][ny]!='#':continue
            q.append((nx,ny))
            s[nx][ny]='.'
            cnt+=1
            break
        else:
            if cnt==0:
                print('No')
                exit()
            q.pop()
    return s
for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            s=dfs(i,j)
"""
for i in s:
    for j in i:
        if j=='#':
            print('No')
            exit()
"""
print('Yes')

Measured memory_bytes: 3444
#include<stdio.h>
#include<limits.h>
#define N 500000
void Merge(int[],int,int,int);
void MergeSort(int[],int,int);
int s;
int main(){
  int n,i,A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  MergeSort(A,0,n);
  for(i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",s);
  return 0;
}

void Merge(int A[],int left,int mid,int right){
  int nn,nnn,i,j,k;
  nn=mid-left;
  nnn=right-mid;
  int L[nn+1],R[nnn+1];
  for(i=0;i<nn;i++)
    L[i]=A[left+i];
  for(i=0;i<nnn;i++)
    R[i]=A[mid+i];
    L[nn]=INT_MAX;   
    R[nnn]=INT_MAX;   
    i=0;
    j=0;
    for(k=left;k<right;k++){
      s++;
      if(L[i]<=R[j]){
	A[k]=L[i];
	i=i+1;
      }
      else{
	A[k]=R[j];
	j=j+1;
      }
    }
}       


void MergeSort(int A[],int left,int right){
  int mid;  
  if(left+1<right) {
    mid=(left+right)/2;
    MergeSort(A,left,mid);    
    MergeSort(A,mid,right);    
    Merge(A,left,mid,right);    
  }
}

Measured memory_bytes: 4504
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>

using namespace std;

string s;

int main(){
	bool c = 0;
	cin >> s;
	
	for(int i = 2; i < s.size(); i+=2){
		string a = s.substr(0, (s.size()-i)/2), b = s.substr((s.size()-i)/2, (s.size()-i)/2);
		if(a == b){
			cout << s.size() - i << endl;
			c = 1;
			break;
		}
	}
	if(!c)
		cout << 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 205
#define ll long long
using namespace std;
int n;
int a[maxn];
int sum;
int main()
{sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        {scanf("%d",&a[i]);
    sum+=a[i];
}
int x=(sum/n);
ll ans=0;
if(sum%n==0)
{for(int i=1;i<=n;i++)
    ans=(ans+(x-a[i])*(x-a[i]));
    printf("%lld\n",ans);
}
else
{

    int x2=x+1;
    ll ans1=0,ans2=0;
    for(int i=1;i<=n;i++)
        {ans1=(ans1+(x-a[i])*(x-a[i]));
        ans2=(ans2+(x2-a[i])*(x2-a[i]));
}
printf("%lld\n",min(ans1,ans2));
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  
  int answer = 0;
  int max_r = floor(N/R);
  int max_g = floor(N/G);
  int max_b = floor(N/B);
  
  for (int g = 0; g <= max_g; g++){
    for (int b = 0; b <= max_b; b++){
      if((N-b*B-g*G) % R == 0 && (N-b*B-g*G) >= 0){
        answer ++;
        //cout << b << g << endl;
      }
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a,b,s,ans,i=1;
    cin >> a >> b;
    if(b<10) s=10*a+b;
    else if(b<100) s = 100*a + b;
    else s = 1000*a+b;
    ans = 0;
    while(i*i<=s){
        if(s == i*i) ans = 1;
        i++;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

    int n, k, r, s, p;
    map<char, int> score;
    string t;
    cin >> n >> k >> score['r'] >> score['s'] >> score['p'] >> t;
    int ans = 0;

    map<char, char> beat;
    beat['p'] = 's';
    beat['s'] = 'r';
    beat['r'] = 'p';

    // map<string, char> oth;
    // oth["rp"] = oth["pr"] = oth["pp"] = oth["rr"] = 's';
    // oth["rs"] = oth["sr"] = oth["ss"] = 'p';
    // oth["ps"] = oth["sp"] = 'r';

    vector<bool> win(n, false);

    for (int i = 0; i < n; i++) {
        if (i < k || (t[i] != t[i - k]) || (t[i] == t[i - k] && !win[i - k])) {
            win[i] = true;
            ans += score[beat[t[i]]];
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 512
$,=$";$k=(4-($K=<>)%4)%4;print$K-1?(($n=$K+3>>2<<1),map{map{($t=($'+$_)%$n)+1+($'%2?$n-$k:$t<$n-$k?0:$K-$n)}//..$n}1..$n):(1,1)

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    rep(i,1000000){
        if(floor(i*1.08)==n){puta(i);return 0;}
    }
    puta(":(");;
    return 0;
}

Measured memory_bytes: 256
N, X, M = map(int,input().split())
A = [X]
As = set(A)
Lstart = 0
for i in range(N):
    An = A[-1]**2 % M
    if An in As:
        Lstart = A.index(An)
        break
    else:
        A.append(An)
        As.add(An)
LenBefL = Lstart
LenLoop = len(A) - Lstart
if LenLoop > 0:
    ans = sum(A[:Lstart])+sum(A[Lstart:])*((N-LenBefL)//LenLoop) + sum(A[Lstart:Lstart + (N-LenBefL)%LenLoop])
else:
    ans = sum(A)
print(ans)

Measured memory_bytes: 13104
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x: -x, a))
heapq.heapify(a)

#print(a)

for i in range(m):
    x = heapq.heappop(a)
    x = (-x)//2
    heapq.heappush(a,-x)
print(-sum(a))


Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int N = 105;

template <typename T> inline void read(T &AKNOI) {
    T x = 0, flag = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    AKNOI = flag * x;
}

int n, k, vis[N << 1];
char s[N << 1];

void solve() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	read(k);
	LL ans1 = 0, ans2 = 0;
	for (int i = 1; i <= n; ++i) {
		s[n + i] = s[i];
	}
	for (int i = 1; i <= n; ++i) {
		if (s[i] == s[i - 1] && !vis[i - 1]) {
			++ans1;
			vis[i] = 1;
		}
	}
	for (int i = n + 1; i <= n + n; ++i) {
		if (s[i] == s[i - 1] && !vis[i - 1]) {
			++ans2;
			vis[i] = 1;
		}
	}
	if (s[1] == s[n] && !vis[n + n]) {
		printf("%lld\n", ans1 + ans2 * (k - 1));
	} else {
		printf("%lld\n", ans1 * ((k + 1) / 2) + ans2 * (k / 2));
	}
}

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


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

int main () {
  string s; cin >> s;
  if ((s[1] == s[0] and s[1] == s[2]) or (s[2] == s[1] and s[2] == s[3]))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
vector<pair<int, int>>v;
signed main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end());
	int cost = 0, cnt = 0, i = 0;
	while (cnt < m) {
		pair<int, int>p = v[i]; i++;
		if (cnt + p.second >= m) {
			cout << cost + (m - cnt)*p.first << endl;
			return 0;
		}
		else {
			cost += p.first*p.second;
			cnt += p.second;
		}
	}
}

Measured memory_bytes: 2420
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);

    int simulate(){
        int a = 0, b = 0, c = 0, out = 0, point = 0;
        while(out < 3){
            String s = in.nextLine();
            switch(s){
                case "HIT":
                    point += c;
                    c = b;
                    b = a;
                    a = 1;
                break;
                case "HOMERUN":
                    point += a + b + c + 1;
                    a = b = c = 0;
                break;
                case "OUT":
                    out++;
                break;
            }
        }
        return point;
    }

    void solve(){
        int n = getInt();
        for(int i = 0; i < n; i++){
            System.out.println(simulate());
        }
    }
    
    public static void main(String[] args){
        new Main().solve();    
    }

    int getInt(){
        return Integer.parseInt(in.nextLine());
    }
}

Measured memory_bytes: 26200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define show(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;
#define MOD 1000000007
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define SZ(x) ((int)(x).size())
#define sum(v,i) accumulate(all(v),i)
//#define int long long
using ll = long long;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }//最大公約数
int lcm(int a, int b) { return a * b / gcd(a, b); }	//最小公倍数
//template <typename... Args>void IN(Args& ... args) {cin >>args;IN(args...);return;} //まとめて入力　IN(a,b,c,d...)

void Main() {
	int a; cin >> a;
	rrepi(i, 9, 0) {
		if (a % i == 0) {
			if (a / i < 10)  cout << "Yes"; 
			else  cout << "No"; 
			return;
		}
			
		
	}
	cout << "No";

}

signed main() {
	Main();

	return 0;
}


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

int main(void){
  int N, A, B, C, X;
  while(cin >> N >> A >> B >> C >> X , N | A | B | C | X){
    int Y[10001];
    int now_num = X, flame = 0;
    bool flag = true;
    for(int i=0; i < N; i++){
      cin >> Y[i];
    }
    for(int i = 0; i < N; i++){
      while(1){
	if(flame > 10000){
	  cout << -1 << endl;
	  flag = false;
	  break;
	}

	if(Y[i] == now_num){
	  now_num = (A * now_num + B) % C;
	  flame++;
	  break;
	}else{
	  now_num = (A * now_num + B) % C;
	  flame++;
	}
      }
      if(!flag) break;
    }
    if(!flag) continue;
    cout << flame-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cmath>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
const ll INF =0x3f3f3f3f3f3f3f3f;
int main()
{
    ll n, k,ans;
    cin>>n>>k;
    ans=n;
    if(n>k)
    {
        n=n%k;
        ans=min(ans,n);//想清楚，这里余数可能是距离，
    }
    //走到这里肯定n比k小，所以再判定一下是否成立。
    ll temp=abs(n-k);
    ans=min(temp,ans);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll dp[3][10010];
int main() {
    ll N, A, B; scanf("%lld%lld%lld", &N, &A, &B);
    vector<ll> P(N);
    for(int i=0; i<N; i++) {
        int v; scanf("%d", &v); v--;
        P[v] = i;
    }

    fill(dp[0], dp[2], LONGINF);
    dp[0][0] = 0;
    for(int i=0; i<N; i++) {
        int cur = i % 2, nxt = cur ^ 1;
        int pos = (P[i] << 1) | 1;
        ll mi = LONGINF;
        for(int j=0; j<=2*N; j++) {
            chmin(mi, dp[cur][j]);
            if(j % 2 == 1 and pos != j) continue;
            ll C = 0;
            if(pos < j) C = A;
            if(pos > j) C = B;
            chmin(dp[nxt][j], mi + C);
        }
        fill(dp[cur], dp[cur+1], LONGINF);
    }
    printf("%lld\n", *min_element(dp[N%2], dp[N%2] + 2*N + 1));
    return 0;
}


Measured memory_bytes: 512
n, m = map(int, input().split())
k = []
s = []
for _ in range(m):
    inp = list(map(int, input().split()))
    k.append(inp[0])
    s.append(set(inp[1:]))
p = list(map(int, input().split()))
 
cnt = 0
for i in range(2 ** n):
    pattern = list(bin(i)[2:].zfill(n))
    lamp = p.copy()
    for j in range(n):
        if pattern[j] == "1":
            for l in range(m):
                if (j+1) in s[l]:
                    lamp[l] ^= 1
    f = False
    for j in range(m):
        f |= lamp[j]
 
    if not f:
        cnt += 1
 
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int H,W;
    cin >> H >> W;
    vector<string>A(H);
    int cnt = 0;
    for(int i = 0; i < H; i++) {
        cin >> A[i];
        for(int j = 0; j < W; j++) {
            if(A[i][j] == '#') {
                cnt++;
            }
        }
    }
    if(cnt == H+W-1) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const double EPS=1e-10;
const ll INF=1000000000;
vector<int> G[2010];
int dfs(int now,int pre,int cnt){
    if(cnt==0){
        return 1;
    }
    int ret=1;
    for(int i=0;i<G[now].size();i++){
        if(G[now][i]==pre){
            continue;
        }
        ret+=dfs(G[now][i],now,cnt-1);
    }
    return ret;
}
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans=INF;
    if(k%2==0){
        for(int i=0;i<n;i++){
            ans=min(ans,n-dfs(i,-1,k/2));
        }
    }else{
        for(int i=0;i<n;i++){
            for(int j=0;j<G[i].size();j++){
                ans=min(ans,n-(dfs(i,G[i][j],k/2)+dfs(G[i][j],i,k/2)));
            }
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  vector<int> b(N + 1, -1);
  rep(i, N) cin >> a[i + 1];

  for (int i = N; i > 0; i--) {
    int sum = 0;
    for (int j = i; j <= N; j += i) {
      if (b[j] == 1)
        sum++;
    }
    if ((a[i] == 1 && (sum % 2 == 0)) || (a[i] == 0 && (sum % 2 == 1))) {
      b[i] = 1;
    } else {
      b[i] = 0;
    }
  }

  vector<int> c;
  for (int i = 1; i <= N; i++) {
    if (b[i])
      c.push_back(i);
  }

  cout << c.size() << endl;
  if (c.size() != 0) {
    rep(i, c.size()) {
      if (i != 0)
        cout << " ";
      cout << c[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200 + 7, INF = 1e7;
int n, dis[maxn][maxn], bel[maxn], fl;
char s[maxn];

int col[maxn], zz[maxn], t;
void dfs(int pos, int d) {
	bel[pos] = d;
	for (int i = 1; i <= n; ++i) if(dis[pos][i] == 1) {
		if(!col[i]) {col[i] = 3 - col[pos]; dfs(i, d);}
		else {
			if(col[i] == col[pos]) { fl = 1; return; }
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) {
		if(i == j) continue;
		dis[i][j] = INF;
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= n; ++j) {
			if(s[j] == '1') {
				if(i == j) {
					fl = 1; break;
				}
				else dis[i][j] = dis[j][i] = 1;
			}
		}
	}
	for (int i = 1; i <= n && fl == 0; ++i) if(!col[i]) {
		col[i] = 1; dfs(i, i);
	}
	if(fl) {
		printf("-1\n");
		return 0;
	}

	for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) 
		dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	int ans = 0;
	for (int k = 1; k <= n; ++k) if(bel[k] == k) {
		t = 0; int now = 0;
		for (int i = 1; i <= n; ++i) if(bel[i] == k) zz[++t] = i;
		for (int i = 1; i <= t; ++i) for (int j = i + 1; j <= t; ++j) now = max(now, dis[i][j]);
		ans += now + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3968
n = int(input())
p = [int(item) for item in input().split()]

a = []
for i in range(n):
    a.append(20001 * (i+1))
b = list(reversed(a))

for i, item in enumerate(p):
    a[item-1] -= n - i
    b[item-1] -= n - i
print(" ".join([str(item) for item in a]))
print(" ".join([str(item) for item in b]))

Measured memory_bytes: 7232
using System;
using System.Text;
					
public class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		
		int[] heap = Array.ConvertAll(Console.ReadLine().Split(" ".ToCharArray()), int.Parse);
		
		BuildMaxHeap(heap);
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i ++)  {
			sb.Append(" " + heap[i]);
		}
		Console.WriteLine(sb);
	}
	
	public static string ConvertString(int[] heap, int i)
	{
		string result = "node " + (i + 1) ;
		
		result += ": key = " + heap[i];
		
		if(i > 0) {
			result += ", parent key = " + heap[(i-1)/2];
		}
		
		if( 2*i+1 < heap.Length) {
			result += ", left key = " + heap[2*i+1];
		}
		
		if( 2 * (i+1) < heap.Length) {
			result += ", right key = " + heap[2*i + 2];
		}
		
		return result + ", ";
	}
	
	public static void BuildMaxHeap(int[] A)
	{
		for(int i = A.Length / 2; i >= 0; i--){
			MaxHeapify(A, i);
		}
	}
	
	public static void MaxHeapify(int[] A, int i)
	{
		int l = Left(A, i);
		int r = Right(A, i);
		int largest = i;
		
		//l,r,i?£???????????£???§???????\???§?£???????????£???¶?£????
		if(l >= 0) {
			if(A[l] > A[largest]) largest = l;	
		}
		if(r >= 0) {
			if(A[r] > A[largest]) largest = r;
		}
		
		if(i != largest) {
			Swap(A, i, largest);
			MaxHeapify(A, largest);
		}
	}
	
	public static int Left(int[] A, int i)
	{	
		return ( (2*i + 1) < A.Length )? (2*i + 1) : -1;
	}
	
	public static int Right(int[] A, int i)
	{	
		return ( 2 * (i+1) < A.Length )? (2*i + 2) : -1;
	}
	
	public static void Swap(int[] A, int i, int j)
	{
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
}

Measured memory_bytes: 68640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&b==c)||(a!=b&&b!=c&&a!=c)) cout<<"No";
    else cout<<"Yes";
    cout<<endl;
}

Measured memory_bytes: 256
SX, SY, TX, TY = gets.chomp.split.map{|v| v.to_i}

out = ""

vx = TX - SX
vy = TY - SY

# 1回目
out += "U" * vy
out += "R" * vx

out += "D" * vy
out += "L" * vx

# 2回目
out += "L"
out += "U" * (vy + 1)
out += "R" * (vx + 1)
out += "D"

out += "R"
out += "D" * (vy + 1)
out += "L" * (vx + 1)
out += "U"

puts out


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int N_MAX = 110;
const int W_MAX = 1000000;


int main(void){

	int N, W; cin >> N >> W;
	vector<int> w(N);
	vector<int> v(N);
	REP(i,N) cin >> w[i] >> v[i];
	vector<vector<long long>> dp(N+1, vector<long long>(W+1, 0));

	REP(i,N){
		REP(sum_w,W+1){
			if(sum_w - w[i] >= 0){
				dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i]);
			}
			dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
		}
	}

	cout << dp[N][W] << endl;

	return 0;

}


Measured memory_bytes: 80256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 300

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 300031;

string st;
int loses;

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);

	cin>>st;
	for (int i=0;i<st.size();i++){
		if (st[i]=='x')
			++loses;
	}
	if (loses>=8)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;

//    cin.get(); cin.get();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int64_t& f(int *i) {
    return *(int64_t *)i;
}

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

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

    char s[3][2001] = {};
    int k = 1;
    vector<int[2001]> v(n + 1);
    vector<int[2001][2]> e(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> s[k];
        int t = 0;
        for (int j = 0; j < m; j++) {
            v[i + 1][j + 1] = v[i][j + 1] + (t += (s[k][j] -= '0'));
            f(e[i + 1][j + 1]) = f(e[i][j + 1]) + f(e[i + 1][j]) - f(e[i][j]) + (s[k][j] & s[k][j - 1]) + ((int64_t)(s[k][j] & s[k ^ 3][j]) << 32);
        }
        k ^= 3;
    }

    for (int i = 0; i < q; i++) {
        int x0, y0, x1, y1;
        cin >> y0 >> x0 >> y1 >> x1;
        int x2 = x0 - 1, y2 = y0 - 1;

        cout << (v[y1][x1] - v[y1][x2] - v[y2][x1] + v[y2][x2]) - (e[y1][x1][0] - e[y1][x0][0] - e[y2][x1][0] + e[y2][x0][0]) - (e[y1][x1][1] - e[y1][x2][1] - e[y0][x1][1] + e[y0][x2][1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 48768
#include <bits/stdc++.h>
#define fio     ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pi      3.14159265
#define ll      long long
#define repe    ll tc,cas=0;cin>>tc;while(tc--)
#define op      freopen("output.txt", "w", stdout);

#define maxn 10000010
using namespace std;

int dp[100005];
int arr[100005],n,k;

int main()
{
    fio;

    cin>>n>>k;
    for(int i=0;i<n;i++){cin>>arr[i];dp[i]=1e9;}

    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++){
            if(i+j<n){
                dp[i+j] = min(dp[i+j],dp[i]+abs(arr[i]-arr[i+j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;;
    return 0;
}


Measured memory_bytes: 4436
# from sys import stdin
# input = stdin.readline
from collections import Counter

MOD = 10**9 + 7
MAX = 2000001
def solve():
    k = int(input())
    s = input().strip()
    ns = len(s)
    res = 0
    fac = [1,1] + [0] * MAX
    inv = [1,1] + [0] * MAX
    for i in range(2,MAX+1):
        fac[i] = fac[i-1] * i % MOD
    inv[MAX] = pow(fac[MAX],MOD-2,MOD)
    for i in range(MAX-1,1,-1):
        inv[i] = inv[i+1]*(i+1)%MOD

    def c(a,b):
        return fac[b]*inv[a]*inv[b-a] % MOD



    for left in range(0,k+1):
        right = k - left
        temp = pow(25,left,MOD) * pow(26,right,MOD)
        temp *= c(ns - 1, left + ns -1)
        temp %= MOD
        res += temp
        res %= MOD
    print(res)







if __name__ == '__main__':
    solve()


Measured memory_bytes: 138828