akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
	ll n,m;
	cin >>n>>m;
	for (ll i=0;i<max(n,m);i++){
		cout << min(n,m);
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

h,w=map(int, input().split())
m = [list(input().rstrip()) for i in range(h)]
ok_w=[True for i in range(h)]
ok_h=[True for i in range(w)]
#print(m)
for i in range(h):
    for j in range(w):
        #print(m[i][j])
        if "#" == m[i][j]:
           ok_w[i]=False
           ok_h[j]=False
#print(ok_h,ok_w)
for i in range(h):
    for j in range(w):
        if not ok_w[i] and not ok_h[j]:
            print(m[i][j],end="")
    print("\n",end="")

Measured memory_bytes: 4596
import sys

N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[(1+p)/2 for p in P]
temp=sum(Q[:K])
ans=temp
for i in range(N):
  try:
    temp=temp-Q[i]+Q[i+K]
    ans=max(ans,temp)
  except:
    pass
else:
  print(ans)


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

using namespace std;

int sum(int x)
{
    int ans = 0;
    while(x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    int ans = (int)1e9;
    for (int i = 1; i < n; i++)
    {
        ans = min(ans, sum(i) + sum(n - i));
    }
    cout << ans;
}


Measured memory_bytes: 256
//35
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    pair<string,int> t[20000];
    for(int i=0;i<n;i++){
      string s,g;
      cin>>s>>g;
      t[2*i]=make_pair(s,1);
      t[2*i+1]=make_pair(g,-1);
    }
    sort(t,t+2*n);
    int m=0,c=0;
    for(int i=0;i<n*2;i++){
      c+=t[i].second;
      m=max(m,c);
    }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 2468
#include <stdio.h>

char tolowr(char c);    /* 大文字を小文字に変換 */

int main(){
  int N,K;
  scanf("%d %d",&N,&K);
  
  char ch[100];
  scanf("%s",ch);
  
  ch[K-1] = tolowr(ch[K-1]);
  
  printf("%s",ch);
  
  return 0;
}

/* 大文字を小文字に変換 */
char tolowr(char c) {
  return (c + 0x20);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    bool check = false;
    vector<int> A(n);
    rep(i, n) {
        cin >> A[i];
        if(A[i] == 1) check = true;
    }
    int ans = 0, cnt = 1;
    for(int x : A) {
        if(x != cnt) {
            ans++;
        } else {
            cnt++;
        }
    } 
    if(check) cout << ans << endl;
    else cout << -1 << endl;
    
    return 0;
}

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

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

  vector<int> ans(N);
  vector<bool> is_fix(N);

  rep(i, M) {
    int keta, num;
    cin >> keta >> num;

    keta--;
    if (keta == 0 && num == 0 && N > 1) {
      cout << "-1" << endl;
      return 0;
    }
    if (!is_fix[keta]) {
      is_fix[keta] = true;
      ans[keta] = num;
    } else if (ans[keta] != num) {
      cout << "-1" << endl;
      return 0;
    }
  }

  rep(i, N) {
    if (!is_fix[i]) {
      if (i == 0) {
        if (N == 1) {
          ans[i] = 0;
        } else {
          ans[i] = 1;
        }
      } else {
        ans[i] = 0;
      }
    }
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}

char in[2100];
vector<int>R;
vector<int>B;
long long dp[2100][2100];
long long C[2100][2100];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			if(j<in[i]-'0')B.push_back(i);
			else R.push_back(i);
		}
	}
	C[0][0]=1;
	for(int i=0;i<2050;i++){
		for(int j=0;j<=i;j++){
			C[i+1][j]=(C[i+1][j]+C[i][j])%mod;
			C[i+1][j+1]=(C[i+1][j+1]+C[i][j])%mod;
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(dp[i][j]==0)continue;
			if(j<B.size()&&B[j]<=i){
				dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
			}
			if(i-j<R.size()&&R[i-j]<=i){
				dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			}
		}
	}
	long long ret=0;
	for(int i=0;i<=n;i++){
		if(dp[n][i]){

			int rm=B.size()-i;
			ret=(ret+dp[n][i]*C[n][rm])%mod;
	//		printf("%d %lld %lld\n",i,dp[n][i],C[n][rm]);
		}
	}
	printf("%lld\n",ret);
}


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

signed main() {

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

    int n, m; cin >> n >> m;
    priority_queue<int> q;
    rep(i,n) {
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i,m) {
        int a = q.top(); q.pop();
        q.push(a/2);
    }
    long long ans = 0;
    rep(i,n) {
        ans += q.top(); q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3908
#include <iostream>
using namespace std;
int main(void){
    while(true){
        int s,f,S,M=0;
        int t;
        cin >>t;
        int n;
        cin >>n;
        if(t==0)break;
        for(int i=0;i<n;i++){
            cin >>s>>f;
            S=f-s;
            M=M+S;
        }
        if(M>=t){
            cout <<"OK"<<endl;
        }
        else{
            cout <<t-M<<endl;
        }
    }
}



Measured memory_bytes: 3080
#include <stdio.h>
#include <complex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;

int f(P p1, double r1, P p2, double r2) {
    const double d = abs(p1-p2);
    if (r1+r2 < d) return 0;
    if (r2+d < r1) return 2;
    if (r1+d < r2) return -2;
    return 1;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        double x1, y1, r1, x2, y2, r2;
        scanf("%lf%lf%lf", &x1, &y1, &r1);
        scanf("%lf%lf%lf", &x2, &y2, &r2);
        P p1(x1, y1), p2(x2, y2);
        printf("%d\n", f(p1, r1, p2, r2));
    }
    return 0;
}

Measured memory_bytes: 0
//package aoj2001;

import java.util.*;
import java.lang.*;

public class Main {
	static Scanner scan = new Scanner(System.in);
	public static void main (String args[]) {
		while (scan.hasNext()) {
			int n = scan.nextInt();
			int m = scan.nextInt();
			int a = scan.nextInt();
			if (n != 0) {
				solve(n, m, a);
			}
		}
	}

	static void solve(int n, int m, int a) {
		int[][] amida = new int[n+1][1001];
		int height = 1;
		for (int i = 0; i < m; i++) {
			int h = scan.nextInt();
			int p = scan.nextInt();
			int q = scan.nextInt();
			amida[p][h] = q;
			amida[q][h] = p;
			if (height < h) {
				height = h;
			}
		}

		for (int i = height; i >= 0; i--) {
			//System.out.println(amida[a][i]);
			if (amida[a][i] != 0) {
				a = amida[a][i];
			}
			//System.out.println(a);
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 66420
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005];
	for (i = 1; i < n; i++)
		scanf("%d", &a[i]);
	int cnt[200005];
	for (i = 0; i < n; i++)
		cnt[i] = 0;
	for (i = 1; i < n; i++)
		cnt[a[i] - 1]++;
	for (i = 0; i < n; i++)
		printf("%d\n", cnt[i]);
	return 0;
}

Measured memory_bytes: 3292
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int w,h;
ll solve(int n,int m)
{
	if(n%3==0)return 0;
	ll mn=min(n,m);
	for(int i=1;i<n;i++)
	{
		ll S1=1ll*i*m;
		ll S2=1ll*(n-i)*(m/2);
		ll S3=1ll*n*m-S1-S2;
		mn=min(mn,max(S1,max(S2,S3))-min(S1,min(S2,S3)));
	}
	return mn;
}
int main()
{
	cin>>w>>h;
	cout<<min(solve(w,h),solve(h,w))<<endl;
	return 0;
}

Measured memory_bytes: 256
x,y,a,b,c = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
rlen = len(R)
if (rlen < x + y):
    max = rlen
else:
    max = x + y

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

p = P[:x]
q = Q[:y]
r = R[:max]

p.extend(q)
p.sort()

ans = sum(p)

for i in range(max):
    diff = r[i] - p[i]
    if (diff > 0):
        ans = ans + diff
    else:
        break

print(ans)

Measured memory_bytes: 22560
#include <stdio.h>

int get_digit(int val){
        int res = 0;
        while(val > 0){
                val /= 10;
                res++;
        }
        return res;
}

int main(int argc, char *argv[]){
        long a,b;
        while(scanf("%ld %ld", &a, &b) != EOF){
                int sum = a+b;
                int d =0;
                if(sum == 0){
                        d = 1;
                }else{
                        d = get_digit(sum);
                }
                printf("%d\n", d);
        }
        return 0;
}


Measured memory_bytes: 2036
#include<iostream>

using namespace std;

int main()
{
	int n,k,i,j;
	int b[1012];
	
	for(;;)
	{
		cin >> n >> k ;
		if(n==0 && k==0)
			break;
		
		for(i=0;i<k;i++)
			cin >> b[i] ;
		
		int a,flag=1;
		
		for(i=0;i<n;i++)
		{
			for(j=0;j<k;j++)
			{
				cin >> a ;
				b[j]-=a;
				if(b[j]<0)
					flag=0;
			}
		}
		if(flag==1)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}

Measured memory_bytes: 856
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
int a[maxn];
int b[maxn];
int c[maxn];
int quick(int x,int n){
    int ans=1;
    while(n){
        if(n&1) ans=ans*x%mod;
        x=x*x%mod;
        n=n/2;
    }
    return ans;
}
int C(int x,int y){
    x--; y--;
    return b[y]*c[x]%mod*c[y-x]%mod;
}
int32_t main(){
    int n,k; cin>>n>>k;  int r=n-k;
    b[0]=1; for(int i=1;i<=2005;i++) b[i]=b[i-1]*i%mod;
    c[0]=1; for(int i=1;i<=2005;i++) c[i]=quick(b[i],mod-2);
    for(int i=1;i<=k;i++){
        int ans=C(i,k);
        int num=0;
        if(n==k && i==1 ) {
            cout<<1<<endl; continue;
        }
        if(r>=i-1 &&i-1>=1)  num+=C(i-1,r);
        if(r>=i && i>=1)     num+=C(i,r)*2;
        if(r>=i+1 && i+1>=1) num+=C(i+1,r);
        num%=mod;
        ans=ans*num%mod;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vll A(N+1);
    ll sum = 0;
    vll a(N+1);
    for(int i=1; i<N+1; i++){
        cin >> A[i];
        sum += A[i];
        a[i] = (A[i]%2);
    }
    ll min = 0;
    ll k = 0;
    for(int i=1; i<N+1; i++){
        if(A[i]>0){
            if(a[i]==k){
                k=0;
            }else{
                k=1;
            }
        }else{
            if(k==1){
                min++;
                k=0;
            }
        }
    }
    cout << (sum - min)/2;
}

Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
using namespace std;
const int num = 16, ud[] = { 0, -1, 0, 1 }, lr[] = { 1, 0, -1, 0 }, nd = 4;
int md[num][num];
struct puzzle {
	int sp, p[num], mdp, cost;
	bool operator < (const puzzle &pu) const {
		for (int i = 0; i < num; i++) {
			if (p[i] == pu.p[i]) continue;
			return p[i] < pu.p[i];
		}
		return false;
	}
};
struct state {
	puzzle pu;
	int es;
	bool operator < (const state &s) const {
		//return pu.mdp + pu.cost > s.pu.mdp + s.pu.cost;
		return es > s.es;
	}
};
int astar(puzzle pz) {
	priority_queue<state> pq;
	int sum = 0;
	for (int i = 0; i < num; i++) {
		if (pz.p[i] == num) continue;
		sum += md[i][pz.p[i] - 1];
	}
	pz.mdp = sum;
	pz.cost = 0;
	map<puzzle, bool> m;
	puzzle u, v;
	state initial;
	initial.pu = pz;
	initial.es = pz.mdp;
	pq.push(initial);
	while (!pq.empty()) {
		state st = pq.top(); pq.pop();
		u = st.pu;
		if (!u.mdp) return u.cost;
		m[u] = true;
		int sx = u.sp / nd;
		int sy = u.sp % nd;
		for (int r = 0; r < nd; r++) {
			int tx = sx + ud[r];
			int ty = sy + lr[r];
			if (tx >= nd || tx < 0 || ty >= nd || ty < 0) continue;
			v = u;
			//v.mdp = p.mdp - md[tx * nd + ty][tmp.p[tx * nd + ty] - 1] + md[sx*nd + sy][tmp.p[tx * nd + ty] - 1];
			v.mdp -= md[tx * nd + ty][v.p[tx * nd + ty] - 1];
			v.mdp += md[sx*nd + sy][v.p[tx * nd + ty] - 1];
			swap(v.p[sx * nd + sy], v.p[tx * nd + ty]);
			v.sp = tx * nd + ty;
			if (!m[v]) {
				v.cost++;
				state news;
				news.pu = v;
				news.es = v.cost + v.mdp;
				pq.push(news);
			}
		}
	}
	return -1;
}

int main() {
	puzzle in;
	for (int i = 0; i < num; i++)
		for (int j = 0; j < num; j++)
			md[i][j] = abs(i / nd - j / nd) + abs(i%nd - j%nd);
	for (int i = 0; i < num; i++) {
		cin >> in.p[i];
		if (!in.p[i]) { in.sp = i;  in.p[i] = num; }
	}
	cout << astar(in) << endl;
	return 0;
}

Measured memory_bytes: 257644
// Problem : B - ... (Triple Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k;
	cin>>k;
	string s;
	cin>>s;
	if((int) s.size() <= k)
	{
		cout<<s;
	}
	else
	{
		string t = s.substr(0, k);
		t = t + "...";
		cout<<t;
	}
	return 0;
}

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

using namespace std;

int main(){
    int A, B, K;
    cin>>A>>B>>K;
    int count=0;
    for(int i=100; i>=0; --i){
        if(A%i == 0 && B%i == 0){
            count++;
        }
        if(count == K){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

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

int partition(int *,int,int);

int main()
{
  int n,i,*A,hantei;

  scanf("%d",&n);
  if(n<1 || n>N) exit(1);

  A = (int *)malloc(sizeof(int)*n);
  
  for(i=0;i<n;i++){
    scanf(" %d",&A[i]);
    if(A[i]<0 || A[i]>N) exit(2);
  }

  hantei = partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    if(hantei == i) printf("[");
    printf("%d",A[i]);
    if(hantei == i) printf("]");
  }
  printf("\n");

  return 0;
}

int partition(int *A,int p,int r)
{
  int x,i,j,tmp;
  
  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
      if(A[j] <= x){
	i += 1;
	tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
      }
  }
  
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  
  return i+1;
      
}



Measured memory_bytes: 2128
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    if(a<=b){
        cout << a << endl;
    }else{
        cout << a-1 << endl;
    }
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n,k;
  cin >> n >> k;
  int64_t MOD = 1000000007;
  int64_t totalMod = 0;
  int64_t cmb = 1;
  int64_t min = 0;
  int64_t max = 0;
  for(int j=0;j<k;j++){
    min += j;
    max += n-j;
  }
  totalMod += max-min+1;
  totalMod %= MOD;
  for(int i=1;i<=n+1-k;i++){
    min += (k-1)+i;
    max += n-(k-1)-i;
    totalMod += max-min+1;
    totalMod %= MOD;
  }
  cout << totalMod << endl;
  return 0;
}
/*
n+1Ck = (n+1)*(n)*(n+1-k)/{(k)*(k-1)*...2*1}
n+1Ck+1 = (n+1)*(n)*(n+1-k)*(n-k)/{(k)*(k-1)*...2*1}
...
n+1C2 = n+1C2 = (n+1)*n/2
n+1C1 = (n+1)
n+1C0 = 1
*/

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int k; cin>>k;
   if(k==1){
      cout<<"1\n1"<<endl;
      return 0;
   }
   int n=2*((k+3)/4);
   cout<<n<<endl;
   rep(i,0,n)rep(j,0,n){
      int x=(i+j)%n; if(i&1 and x+n<k)x+=n;
      cout<<x+1<<(j==n-1?'\n':' ');
   }
   return 0;
}

Measured memory_bytes: 1152
/**< Winter is Coming - Game Of Thrones */
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = 1e9 + 7;
const ll mode = 1e6 + 3;

ll min(ll a, ll b)
{
    if(a > b) return b;
    else return a;
}
ll min_third(ll a, ll b ,ll c)
{
    return min(min(a,b),c);
}
ll GCD(ll A, ll B) {
    if(B == 0)
        return A;
    else
        return GCD(B, A % B);
}
ll LCM(ll A, ll B)
{
    return (A*B)/GCD(A, B);
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int fun(int x, int y)
{
    return x*y;
}
//4
//10 30 40 20

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

    ll A = 0,B = 0;cin >> A >> B;
    cout << LCM(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}
const ll INF = 1LL << 60;

//dp_a
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> h(n+2, 0);
    rep(i,n){
        cin>>h[i];
    }
    vector<ll> dp(n+2, INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
        chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
        chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1408
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int d, t, s; cin >> d >> t >> s;

    if(s*t >= d) pr("Yes");
    else pr("No");
    return 0;}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1e9 + 7;
typedef long long ll;
struct mint
{
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
};

mint comb(int n, int k)
{
    mint num1 = 1;
    mint num2 = 1;

    for (int i = n; i >= n - k + 1; i--)
    {
        num1 *= i;
    }
    for (int i = 1; i <= k; i++)
    {
        num2 *= i;
    }
    return num1 / num2;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if (n == 2 && a == 1 && b == 2)
    {
        cout << 0 << endl;
        return 0;
    }

    mint a_fact, b_fact;

    mint pow2 = 2;
    mint ans = pow2.pow(n);
    mint nCa = comb(n, a);
    mint nCb = comb(n, b);
    ans -= 1;
    ans -= nCa;
    ans -= nCb;
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int N,x=0,i;
	long a,ans[2];
	ans[0]=0;
	ans[1]=0;
	vector<long> v;
	cin >> N;
	for(i=0;i<N;i++){
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	/*for(int i=0;i<N;i++){
		cout << v[i] << endl;
	}*/
	for(i=N-1;i>0;i--){
		if(v[i]==v[i-1]){
			ans[x]=v[i];
			i--;
			x++;
			if(x==2)break;
		}
	}
	cout << ans[0]*ans[1] <<endl;
	return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=abs(a[i]-a[i-1])+dp[i-1];
		for(int j=i-1;j>=0 && i-j<=k;j--)
		{
			dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
		}
	}
	cout<<dp[n-1];
	return 0;
}

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

int main(){
  int N,a=0;
  cin >> N;
  vector<int> p(N);
  for(int i=0; i<N; i++){
    cin >> p.at(i);
    if(i+1!=p.at(i)){
      a++;
    }
  }
  if(a<=2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

int main() {
	int a,b,c;
	int first, second, third;
	cin >> a >> b>> c;
	if(a > b && a > c){
		third = a;
		if(b > c) {second = b; first = c;}
		else { second = c; first=b; }
	}
	else if(b > a && b > c) {
		third = b;
		if(a > c) {second = a; first = c;}
		else { second = c; first = a;}
	}
	else {
		third =c;
		if(a > b) {second =a; first =b;}
		else {second = b; first = a;}
	}
	// your code goes here
	
	cout << first <<" "<<second <<" "<< third << endl;
	return 0;
}

Measured memory_bytes: 1164
using System;
using System.Linq;
class E { static void Main() { new K(); } }
class K
{
	int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); }
	long Mod = 1000000007;
	public K()
	{
		var I = G();
		N = I[0]; C = I[1];
		A = G();
		B = G();
		memo = new long[N, C + 1];
		used = new bool[N, C + 1];
		pows = new long[401, C + 1];
		for (var x = 0; x <= 400; x++) pows[x, 0] = 1;
		for (var x = 0; x <= 400; x++) for (var c = 1; c <= C; c++) pows[x, c] = (pows[x, c - 1] * x) % Mod;
		powsum = new long[402, C + 1];
		for (var x = 1; x < 402; x++) for (var c = 0; c <= C; c++) powsum[x, c] = (powsum[x - 1, c] + pows[x - 1, c]) % Mod;
		Console.WriteLine(Calc(0, C));
	}
	int N, C;
	int[] A, B;
	long[,] memo, pows, powsum;
	bool[,] used;
	long Calc(int n, int s)
	{
		if (!used[n, s])
		{
			used[n, s] = true;
			var ans = 0L;
			if (n == N - 1) ans = (powsum[B[n] + 1, s] - powsum[A[n], s]) % Mod;
			else for (var t = 0; t <= s; t++) ans = (ans + ((powsum[B[n] + 1, t] - powsum[A[n], t]) % Mod) * Calc(n + 1, s - t) % Mod) % Mod;
			if (ans < 0) ans += Mod;
			memo[n, s] = ans;
		}
		return memo[n, s];
	}
}

Measured memory_bytes: 6872
import numpy as np
from itertools import product

def readlines(n):
    for _ in range(n):
        yield list(map(int, input().split()))

def main():
    N, M, X = map(int, input().split())

    books = np.array(list(readlines(N)))
    ans = np.inf
    for bit in product([0, 1], repeat=N):
        comb_sum = np.dot(np.array(bit), books)
        if all(comb_sum[1:] >= X):
            ans = min(ans, comb_sum[0])

    if ans == np.inf:
        print(-1)
    else: 
        print(ans)
        


main()

Measured memory_bytes: 27244
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int r = in.nextInt();
            int D = in.nextInt();
            int x = in.nextInt();
            for (int i = 0; i < 10; i++) {
                x = r * x - D;
                out.println(x);
            }
        }

    }
}



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

int main(){
    string a;
    cin >> a;
    int num=0;
    for(int i=0;i<(1<<3);i++){
        string op="";
        for(int j=0;j<3;j++){
            if(i&(1<<j)){
                op[j]='+';
            }else{
                op[j]='-';
            }
            //cout << op[j];
        }
        
        string ans=to_string(a[0]-'0');
        num = (int)(a[0]-'0');
        for(int k=0;k<3;k++){
            if(op[k]=='+'){
                num+=(int)(a[k+1]-'0');
                ans+='+'+to_string(a[k+1]-'0');
            }else{
                num-=(int)(a[k+1]-'0');
                ans+='-'+to_string(a[k+1]-'0');
            }
        }
        if(num==7){
            ans+="=7";
            cout << ans << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    ll X;
    cin >> X;
    while(true){
        if(IsPrime(X)){
            cout << X << endl;
            return 0;
        }
        X++;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,m,a[100010],b[100010],j,k,ans;
priority_queue<ll> Q;
void Ad(ll c,ll d){
    for(;j<n&&a[j]<c;j++)Q.push(b[j]);
    for(;k>d;k--)if(!Q.empty()){ans+=Q.top(); Q.pop();}
}
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    j=0,k=n+1,ans=0;
    for(int i=0;i<m;i++){
	ll c,d;cin>>c>>d;Ad(c,d);
    }
    Ad(2e9,1);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 5476
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

sum=0
prev=-1000

for a in A:
    sum+=B[a-1]
    if a-prev==1:
        sum+=C[a-2]
    prev=a
    
print(sum)
    

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

int main()
{
    int n = 0;
    cin >> n;
    vector<int> S(n);
    for (int i = 0; i != n; ++i) cin >> S[i];
    int q = 0;
    cin >> q;
    vector<int> T(q);
    for (int i = 0; i != q; ++i) cin >> T[i];
    int counts = 0;
    for (auto ti : T){
        for (auto si : S){
            if (ti == si){
                ++counts;
                break;
            }
        }
    }
    cout << counts << endl;
    return 0;
}

Measured memory_bytes: 3120
#include <stdio.h>
#include <math.h>

int main()
{
  int a,b,c,d,e=0,f;
  scanf("%d",&a);
  for(b=0;b<a;b++)
    {
      scanf("%d",&c);

      
      for(d=2;d<=sqrt(c);d++)
	{
	    
	  if(c%d==0)
	    {
	      e++;
	      break;
	    }
	   
	}
      
    }
  f=a-e;
  printf("%d\n",f);
  return 0; 
}



Measured memory_bytes: 2084
#include <stdio.h>
int main(void)
{
    int H, W;
    int i, j, k;

    do{
        scanf("%d %d", &H, &W);

        if(H == 0 && W == 0) break;

        for(i = 1; i <= H; i++){
        if(i == 1){
            for(j = 1; j <= W; j++)
                printf("#");
            putchar('\n');
            }
        
            else if(i == H){
            for(j = 1; j <= W; j++)
                printf("#");
            putchar('\n');
            break;
            }

            else{
                printf("#");
                for(k = 1; k <= W - 2; k++)
                    printf(".");
                printf("#\n");
            }
        }
    putchar('\n');
    }while(H != 0 || W != 0);
    
    return 0;
}


Measured memory_bytes: 1988
#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 MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int a,b;
  cin >> a >> b;
  int x = b-a-1;
  int sum = 0;
  REP(i,x+1){
    sum+=i;
  }

  cout << sum-a << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void)
{
	int t,n,s,f,i,r;
	while(1)	{
		scanf("%d",&t);
		if(t==0)	break;
		scanf("%d",&n);
		r=0;
		for(i=0;i<n;i++)	{
	//		n????????????;
			scanf("%d",&s);
			scanf("%d",&f);
			r=r+(f-s);
		}
		if(t <= r)	{
			printf("OK\n");
		}
		else {
			printf("%d\n",t-r);
		}
	}
	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int main() {
  int D;
  ll G;
  cin >> D >> G;
  vector<ll> P(D), C(D);

  for (int i = 0; i < D; i++) {
    cin >> P[i] >> C[i];
  }

  ll res = 1 << 29;
  for (int bit = 0; bit < (1 << D); bit++) {
    ll sum = 0;
    ll num = 0;
    for (int i = 0; i < D; i++) {
      if ((bit >> i) & 1) {
        sum += (i + 1) * 100 * P[i] + C[i];
        num += P[i];
      }
    }
    if (sum >= G)
      res = min(res, num);

    for (int i = D - 1; i >= 0; i--) {
      if ((bit >> i) & 1)
        continue;
      for (int j = 0; j < P[i]; j++) {
        sum += (i + 1) * 100;
        num++;
        if (sum >= G) {
          res = min(res, num);
          break;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<pll> e;
};

Vertex V[100005];
//! Kまでのコスト
ll C[100005];

int main()
{
    int N;
    cin >> N;
    REP(i, N - 1)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        V[a].e.push_back(pll(b, c));
        V[b].e.push_back(pll(a, c));
    }
    REP(i, N)
    {
        C[i] = INF;
    }

    int Q, K;
    cin >> Q >> K;
    K--;
    C[K] = 0;
    queue<ll> q;
    q.push(K);
    while (!q.empty())
    {
        ll t = q.front();
        q.pop();
        REP(i, V[t].e.size())
        {
            pll e = V[t].e[i];
            if (C[t] + e.second >= C[e.first])
                continue;
            C[e.first] = C[t] + e.second;
            q.push(e.first);
        }
    }

    REP(i, Q)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << C[x] + C[y] << endl;
    }
    return 0;
}

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


def solve(N: int, M: int, X: int, Y: int, x: "List[int]", y: "List[int]"):
    ymin = min(min(y), Y)
    Z = ymin
    if max(max(x), X) < Z:
        print("No War")
    else:
        print("War")


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    y = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, X, Y, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int a[100];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  int ans = 0;
  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] == 0 || a[i] % 2 != 0) {
        cout << ans << endl;
        exit(0);
      }
      else
        a[i] /= 2;
    }
    ans++;
  }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Read in = new Read(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Read in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            int p = Integer.parseInt(a + b);
            int t = (int) Math.sqrt(p);
            if (t * t == p) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class Read {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public Read(InputStream inputStream) {
            din = new DataInputStream(inputStream);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Read(String file_name) {
            try {
                din = new DataInputStream(new FileInputStream(file_name));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String next() {
            byte[] buf = new byte[1 << 20]; // line length
            int cnt = 0, c;
            while ((c = read()) == ' ' || c == '\n') ;
            buf[cnt++] = (byte) c;
            while ((c = read()) != -1) {
                if (c == ' ' || c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        private void fillBuffer() {
            try {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}



Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int lengtha = str[0].Length;
        int lengthb = str[1].Length;
        string end_a = str[0].Substring(lengtha - 1, 1);
        string start_b = str[1].Substring(0, 1);
        string end_b = str[1].Substring(lengthb - 1, 1);
        string start_c = str[2].Substring(0, 1);

        if(end_a == start_b && end_b == start_c){
            Console.WriteLine("YES");
        }else{
            Console.WriteLine("NO");
        }
    }
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21736
#include<iostream>
#include<vector>
#include<string>
#include<string.h>
using namespace std;

vector< vector<char> >V(8,vector<char>(8));
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};

bool update;
int idx,idy,count;
bool can[8];

bool in(int x,int y){
	return x>=0 && y>=0 && x<8 && y<8;
}

void check(int k){
	char me,you;
	bool tcan[8];
	count=0;
	memset(can,false,sizeof(can));
	if(k==0){me='o';you='x';}
	else{me='x';you='o';}
	if(k==0){
	for(int y=0;y<8;y++){
		int tcount,ttcount;
		for(int x=0;x<8;x++){
			tcount=0;
			memset(tcan,false,sizeof(tcan));
			if(V[y][x]!='.')
				continue;
			for(int d=0;d<8;d++){
				int nx=x+dx[d],ny=y+dy[d];
				ttcount=0;
				while(in(nx,ny)&&V[ny][nx]==you){
					nx+=dx[d];ny+=dy[d];ttcount++;
				}
				if(in(nx,ny) && V[ny][nx]==me &&ttcount>0){
					tcount+=ttcount;
					update=true;
					tcan[d]=true;
				}
			}
			if(tcount>count){
				idx=x;idy=y;count=tcount;update=true;
				for(int i=0;i<8;i++) can[i]=tcan[i];
			}
		}
	}
	}
	else{
	for(int y=7;y>=0;y--){
		int tcount,ttcount;
		for(int x=7;x>=0;x--){
			tcount=0;
			memset(tcan,false,sizeof(tcan));
			if(V[y][x]!='.')
				continue;
			for(int d=0;d<8;d++){
				int nx=x+dx[d],ny=y+dy[d];
				ttcount=0;
				while(in(nx,ny)&&V[ny][nx]==you){
					nx+=dx[d];ny+=dy[d];ttcount++;
				}
				if(in(nx,ny) && V[ny][nx]==me &&ttcount>0){
					tcount+=ttcount;
					update=true;
					tcan[d]=true;
				}
			}
			if(tcount>count){
				idx=x;idy=y;count=tcount;update=true;
				for(int i=0;i<8;i++) can[i]=tcan[i];
			}
		}
	}
	}
}

void put(int k){
	char me,you;
	if(count==0)
		return;
	if(k==0){me='o';you='x';}
	else{me='x';you='o';}
	V[idy][idx]=me;
	for(int d=0;d<8;d++){
		if(can[d]){
			int nx=idx+dx[d],ny=idy+dy[d];
			while(in(nx,ny) && V[ny][nx]==you){
				V[ny][nx]=me;nx+=dx[d];ny+=dy[d];
			}
		}
	}
}

void print(){
	for(int y=0;y<8;y++){
		for(int x=0;x<8;x++)
			cout<<V[y][x];
		cout<<endl;
	}
}


int main()
{
	for(int y=0;y<8;y++)
		for(int x=0;x<8;x++)
			cin>>V[y][x];

	update=true;
	while(update){
		update=false;
		check(0);
		put(0);
		check(1);
		put(1);
	}
	print();
	return 0;
}

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

int main(){
	ll N, E, T; cin >> N >> E >> T;
	ll x[N+1];
	for(int i=0; i<N; i++) cin >> x[i];
	x[N] = E;
	ll dp[N+1];
	dp[N-1] = T + E - x[N-1];
	dp[N] = 0;
	int now = N-1, prev = N-1;
	priority_queue<ll, vector<ll>, greater<ll> > pq;
	ll mi = 1e18;
	for(int i=N-2; i>=0; i--){
		while(2*(x[now] - x[i]) >= T){
			now--;
		}
		for(; prev>=now+1; prev--){
//			pq.push(dp[prev] + 2*x[prev-1] + x[prev]);
			if(mi > dp[prev+1] + 2*x[prev] + x[prev+1]) mi = dp[prev+1] + 2*x[prev] + x[prev+1];
		}
		if(now != N-1){
			dp[i] = min(mi - 3*x[i], T + x[now+1] - x[i] + dp[now+1]);
		}else{
			dp[i] = min(mi - 3*x[i], T + E - x[i]);
		}
	}
	cout << dp[0] + x[0] << endl;
	return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }


    for(int i = k, j = 0; i < n; i++, j++){
        if(a[i] > a[j]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 4408
import java.util.Scanner;

public class Main{
  static String s;

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

    s = sc.next();
    String[] a = s.split(",");

    System.out.println(a[0] + " " + a[1] + " " + a[2]);
  }
}


Measured memory_bytes: 23764