akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_HUMAN_MAX		300000									// 最大人数

// 内部変数
static char sc1Human[D_HUMAN_MAX + 5];							// 人
static int siHCnt;												// 人数
static int si1W[D_HUMAN_MAX + 5];								// 西側の西向きの人数
static int si1E[D_HUMAN_MAX + 5];								// 東側の東向きの人数
static int siMin;												// 最小人数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// データ初期化
	memset(si1W, 0, sizeof(si1W));								// 西側の西向きの人数
	memset(si1E, 0, sizeof(si1E));								// 東側の東向きの人数
	siMin = INT_MAX;											// 最小人数

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 人数取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &siHCnt);

	// 人取得
#ifdef D_TEST
	fgets(sc1Human, sizeof(sc1Human), szpFpT);
#else
	fgets(sc1Human, sizeof(sc1Human), stdin);
#endif
	sc1Human[siHCnt] = 0;

	// 西側の人数カウント
	for (i = 1; i < siHCnt; i++) {

		// 累計
		si1W[i] = si1W[i - 1];

		// 西向きの人数
		if (sc1Human[i - 1] == 'W') {
			si1W[i]++;
		}
	}

	// 東側の人数カウント・最小人数取得
	for (i = siHCnt - 1; i >= 0; i--) {

		// 累計
		si1E[i] = si1E[i + 1];

		// 東向きの人数
		if (sc1Human[i + 1] == 'E') {
			si1E[i]++;
		}

		// 変える人数
		int liHCnt = si1W[i] + si1E[i];

		// 最小人数セット
		if (siMin > liHCnt) {
			siMin = liHCnt;
		}
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", siMin);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 2816
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int N;
	int a[101];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	int rate=0;
	int hum[11]={};
	for(int i=0;i<9;i++){
		for(int j=0;j<N;j++){
			//cout<<rate<<endl;
			if(rate<=a[j] && a[j]<(rate+400)){
				hum[i]++;
			}
		}
		rate+=400;
	}
	for(int i=0;i<N;i++){
		if(3200<=a[i]){
			hum[10]++;
		}
	}
	int ans=0;
	for(int i=0;i<8;i++){
		if(hum[i]){
			ans++;
		}
	}
	if(hum[10]==N){
		cout<<1<<" "<<hum[10]<<endl;
		return 0;
	}
	else
		cout << ans << " " << ans + hum[10] << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
s1 = [0]*n
s2 = [0]*n
s4 = [0]*n
for i in range(n):
    if a[i]%4 == 0:
        s4[i] = 1
    elif a[i]%2 == 0:
        s2[i] = 1
    else:
        s1[i] = 1
S1 = sum(s1)
S2 = sum(s2)
S4 = sum(s4)
if n >= 3:
    if S2 >= 1:
        if S1 + 1 <= S4 + 1:
            print("Yes")
        else:
            print("No")
    else:
        if S1 <= S4 +1:
            print("Yes")
        else:
            print("No")
else:
    if (a[0]*a[1])%4 == 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14480
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 998244353;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> L(K), R(K);
    for(int i = 0; i < K; i++) cin >> L[i] >> R[i];
    vector<long long> dp(N + 1, 0);
    vector<long long> sum(N + 1, 0);
    dp[1] = 1;
    sum[1] = 1;
    for(int i = 2; i < N + 1; i++){
        for(int j = 0; j < K; j++){
            dp[i] += sum[max(0, i - L[j])] - sum[max(0, i - R[j] - 1)];
            dp[i] %= MOD;
        }
        sum[i] += sum[i - 1] + dp[i];
        sum[i] %= MOD;
    }
    cout << (dp[N] + MOD) % MOD << endl;
}

Measured memory_bytes: 6416
def selection(n, data):
    __count = 0
    for i in range(n):
        min_i = i
        for j in range(i+1, n):
            if data[min_i] > data[j]:
                min_i = j
        tmp = data[i]
        data[i] = data[min_i]
        data[min_i] = tmp
        if min_i != i:
            __count += 1

    return data, __count

def show(data, count):
    for i in range(len(data)):
        if i != (len(data)-1):
            print(data[i], end = " ")
        else:
            print(data[i])
    print(count)

if "__main__" == __name__:
    n = int(input())
    data = list(map(int, input().rsplit()))
    data, count = selection(n, data)
    show(data, count)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int K,X;
  cin>>K>>X;
  FOR(i,X-K+1,X+K) {
    if (i < -1000000 || i > 1000000) continue;
    cout << i;
    if(i == X+K) break;
    cout << " ";
  }
  cout << endl;
  return 0;
}

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

int main()
{
   int64_t N,i,n,k;
  cin >> N;
  n=0;
  for(i=0;i*i<=N;i++)
  {
     n=i;
  }
  for(i=n;i>0;i--)
  {
    if(N%i==0)
    {
      k=i;
      break;
    }
  }
 //  cout << n << k << endl;
  cout << k+N/k-2 << endl;
  
}

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

int main() {
  int K, S, count;
  cin >> K >>S;
  for(int X = 0; X <= K; ++X) {
    for(int Y = 0; Y <= K; ++Y) {
      if((S - X - Y <= K) && (X + Y <= S)) {
        ++count;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  priority_queue<long long> A;
  for(int i = 0; i < N; i++){
    long long a;
    cin >> a;
    A.push(a);
  }
/*  
  for(int i = 0; i < N; i++){
    cout << A.top() << " ";
    A.pop();
  }
  */  
  long long ans = 1;
  string answer = "YES";
  for(int i = 0; i < N-1; i++){
    long long a = A.top();
    A.pop();
    long long b = A.top();
    ans = (a - b);
    //cout << a << " " << b << endl;
    if(ans == 0){
      answer = "NO";
      break;
    }
  }

  cout << answer << endl;
  
}

Measured memory_bytes: 2420
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=205,mod=998244353;
typedef long long LL;
int n,tot;
LL ans,f[N][N],g[N][N];

struct P
{
	int x,y;

	P operator - (P t) {return (P){x-t.x,y-t.y};}
	int operator * (P t) {return -t.x*y+x*t.y;}
} dat[N],p[N],tmp;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

int sqr(int x)
{
	return x*x;
}

int dis(P a,P b)
{
	return sqr(a.x-b.x)+sqr(a.y-b.y);
}

bool cmp(P a,P b)
{
	int x=(a-tmp)*(b-tmp);
	return !x?(dis(a,tmp)<dis(b,tmp)):x>0;
}

bool check(P a,P b,P c,P d)
{
	int t=abs((a-c)*(b-c));
	int s=abs((a-c)*(d-c))+abs((b-a)*(d-a))+abs((c-b)*(d-b));
	return t==s && ((a-c)*(d-c));
}

void solve(int x)
{
	p[tot=1]=tmp=dat[x];
	rep(i,1,n) if(i!=x)
		if(dat[i].y>dat[x].y || (dat[i].y==dat[x].y && dat[i].x>=dat[x].x))
			p[++tot]=dat[i];
	sort(p+2,p+1+tot,cmp);
	rep(i,2,tot-1) rep(j,i+1,tot)
	{
		g[i][j]=1;
		rep(k,i+1,j-1)
			if(check(p[i],p[j],tmp,p[k]))
				g[i][j]=g[i][j]*2%mod;
	}
	rep(i,1,tot) rep(j,1,tot) f[i][j]=0;
	rep(i,2,tot)
	{
		f[1][i]=1;
		rep(j,2,i-1) if((p[i]-tmp)*(p[j]-tmp)==0) f[1][i]=f[1][i]*2%mod;
	}
	rep(i,1,tot-2)
		rep(j,i+1,tot-1)
			rep(k,j+1,tot)
				if((p[k]-p[j])*(p[i]-p[j])>0)
					f[j][k]=(f[j][k]+g[j][k]*f[i][j])%mod;
	rep(i,2,tot-1) rep(j,i+1,tot) 
		if((tmp-p[j])*(p[i]-p[j])>0) ans=(ans+f[i][j])%mod;
}

int main()
{
	n=getint();
	rep(i,1,n)
		dat[i].x=getint(),dat[i].y=getint();
	rep(i,1,n)
		solve(i);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007
#define w while
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
long double PI=acos(-1);
//////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
int main()
{
	int n;
	cin>>n;
	ll a[n+1];
	map<ll,ll>m;
	ll sum=0;
	fr(i,1,n)
	{
		cin>>a[i];
		m[a[i]]++;
		sum+=a[i];
	}
	int q;
	cin>>q;
	w(q--)
	{
		ll b,c;
		cin>>b>>c;
		sum-=(b*m[b]);
		sum+=(c*m[b]);
		m[c]+=m[b];
		m[b]=0;
		cout<<sum<<"\n";
	}
	
    return 0;
}





Measured memory_bytes: 10212
#include <bits/stdc++.h>
using namespace std;
     
#define int  long long
#define endl '\n'
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 310 + 1;
int dp[N][N];
int new_dp[N][N];

void solve(){
  int n, m, cap;
  cin >> n >> m >> cap;
  for (int i = 0; i < n; i++)
   for (int j = 0; j < n; j++)
     if (i == j) dp[i][j] = 0;
     else dp[i][j] = INF;
  
  for (int i = 0; i < m; i++){
	  int x, y, dist;
	  cin >> x >> y >> dist;
	  x--, y--;
	  dp[x][y] = dist;
	  dp[y][x] = dist;
	}  	
  for (int k = 0; k < n; k++){
   for (int i = 0; i < n; i++){
	  for (int j = 0; j < n; j++){
		  if (dp[i][k] == INF || dp[k][j] == INF) continue;
		  dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);  
		} 
	  }  
	}
  for (int i = 0; i < n; i++)
   for (int j = 0; j < n; j++)
     if (dp[i][j] <= cap) dp[i][j] = 1;
     else dp[i][j] = INF;
  for (int k = 0; k < n; k++){
	for (int i = 0; i < n; i++){
	  for (int j = 0; j < n; j++){
		if (dp[i][k] == INF | dp[k][j] == INF) continue;
		dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);  
	  }	
	}  
  }
  int Q;
  cin >> Q;
  while (Q--){
	int x, y;
	cin >> x >> y;
	x--, y--;
	int dist = dp[x][y];
	if (dist >= INF) cout << -1 << endl;
	else cout << dp[x][y] - 1 << endl;  
  }
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();	
}


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

int n;
int pre, nw, nxt, ans;

int main(){
	scanf("%d", &n);
	scanf("%d %d", &nw, &nxt);
	ans = 0;
	for(int i = 1; i <= n - 2; i++){
		pre = nw; nw = nxt;
		scanf("%d", &nxt);
		if(min(pre, nxt) < nw && nw < max(pre, nxt)) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  int n; cin >> n;
  bool ans = false;
    for(int i=1;i<10; i++){
      for(int j=1;j<10;j++){
        if(n == i*j){
          ans = true;
          break;
        }
      }
    }

  if(ans==false){
    cout << "No" << endl;
  }if(ans== true){
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    int n,m,a[100000],c=0;
    bool b[100000];
    cin>>n>>m;
    fill(a, a+n, 1);
    fill(b, b+n, false);
    b[0]=true;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        if(b[x])b[y]=true;
        a[x]--;
        a[y]++;
        if(a[x]==0)b[x]=false;
    }
    for(int i=0;i<n;i++){
        if(b[i])c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int n, m;
    cin >> n >> m;
    
    int ans = 0;
    int s, c;
    int v[3] = {-1, -1, -1};
    for (int i = 0; i < m; i++) {
        cin >> s >> c;
        s--;
        if (v[s] == -1 || v[s] == c) {
            v[s] = c;
        } else {
            ans = -1;
            goto fin;
        }
    }
 
    if (n == 1) {
        if (v[0] == -1) {
            v[0] = 0;
        }
        ans = v[0];
    } else {
        if (v[0] == 0) {
            ans = -1;
            goto fin;
        } else  if (v[0] == -1) {
            v[0] = 1;
        }
        ans = v[0];
        for (int i = 1; i < n; i++) {
            ans = 10 * ans + max(v[i], 0);
        }
    }

 fin: 
    cout << ans << endl;
}

Measured memory_bytes: 256
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [| for i in 1..n -> stream.ReadLine().Split() |> Array.map f |]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let fl = util.Scan1 string

if fl = "1"
  then printfn "Hello World"
  else
    let a = util.Scan1 int
    let b = util.Scan1 int
    printfn "%d" (a+b)

util.Close()


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

using namespace std;

typedef long long int64;
const int mod = 1e9 + 7;

int N, X, Y, Z;
int dp[41][1 << 17], mask;

int rec(int idx, int bit)
{
  if((bit >> (Z - 1)) & 1 && (bit >> (Z + Y - 1)) & 1 && (bit >> (Z + Y + X - 1)) & 1) return (0);
  if(idx == N) return (1);
  if(~dp[idx][bit]) return (dp[idx][bit]);
  int ret = 0;
  for(int i = 1; i <= 10; i++) (ret += rec(idx + 1, ((bit << i) | (1 << (i - 1))) & mask)) %= mod;
  return (dp[idx][bit] = ret);
}


int main()
{
  memset(dp, -1, sizeof(dp));
  cin >> N >> X >> Y >> Z;
  mask = (1 << (X + Y + Z)) - 1;
  int64 ret = 1;
  for(int i = 0; i < N; i++) (ret *= 10) %= mod;
  cout << (ret + mod - rec(0, 0)) % mod << endl;
}

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

int main()
{
    int n,num,min=1000000000,max=0;
    cin>>n;
    vector<int> v;
    for(int i=0; i<n; i++){
        cin >> num;
        v.push_back(num);
        if(num>max) { max=num;}
        if(num<min) { min=num;}
    }
    cout<<max-min<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

int main() {
    int X;
    vector<int> div;
    cin >> X;
    int p4 = pow(X,0.25) +1;
    int p5 = pow(X,0.2) +1;
    rep(i,p4+p5){
        int j = i+1;
        if(X%j == 0){
            div.push_back(j);
        }
    }

    int A,B;
    bool fl = 0;
    rep(i,div.size()){
        int D = div.at(i);
        for(int i = -p5; i+D <= p4; i++){
            B = i;
            A = B+D;
            int ans = pow(A,5) - pow(B,5);
            if(ans == X){
                cout << A << " " << B << endl;
                fl = true;
                break;
            }
        }
        if(fl) break;
    }
    return 0;
}


Measured memory_bytes: 4108
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[] nums = new int[N];
    for(int i = 0; i < N; i++){
      nums[i] = Integer.parseInt(sc.next());
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++){
      if(i == N-1){
        if(nums[i] == i+1){
          ans++;
        }
        break;
      }
      if(nums[i] == i+1){
        ans++;
        nums[i+1] = nums[i];
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 48928
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int cnt=0;
vector<int> G;

void insertsort(int A[],int n,int g){
	for(int i = g; i<n;i++){
		int temp=A[i],j=i-g;
		while(j>=0&&A[j]>temp){
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=temp;
	}
	return ;
}

void shellsort(int A[],int n){
	//generate the G array
	for (int h =1;;){
		if (h>n) break;
		G.push_back(h);
		h=3*h+1;
	}
	
	for(int i=G.size()-1;i>=0;i--)	insertsort(A,n,G[i]);
	
	return ;
}

int main (){
	int n ,A[1000010];
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	
	shellsort(A,n);

	cout<<G.size()<<endl;
	for(int i =G.size()-1;i>=0;i--){
		printf("%d",G[i]);
		if(i) printf(" ");
	}
	printf("\n%d\n",cnt);
	for(int i =0;i<n;i++) printf("%d\n", A[i]);
	return 0;
}


Measured memory_bytes: 7100
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()

mod = 998244353

have = [0]*8
target_bit = 1

ans = 1

for s in S:
    if s == "R":
        bit = 1
    elif s == "G":
        bit = 2
    else:
        bit = 4
    update = False
    for bit2 in [3, 5, 6]:
        if have[bit2] > 0 and ((bit2&bit) == 0):
            if bit != target_bit:
                ans = ans * have[bit2] % mod
            have[bit2] -= 1
            update = True
    if update:
        continue
    for bit1 in [1, 2, 4]:
        if have[bit1] > 0 and ((bit1&bit) == 0):
            if bit != target_bit:
                if (target_bit&bit1) == 0:
                    ans = ans * (have[bit1|bit]+1) % mod
                else:
                    ans = ans * have[bit1] % mod
            have[bit1] -= 1
            have[bit1|bit] += 1
            update = True
    if update:
        continue
    
    if bit != target_bit:
        ans = ans * (have[bit] + 1) % mod
    have[bit] += 1


for n in range(1, N+1):
    ans = ans * n % mod

print(ans)


Measured memory_bytes: 3828
main = do
  s <- getLine
  t <- getLine
  putStr $ solve (length s) s t

solve :: Int -> String -> String -> String
solve 0 _ _ = "No"
solve n (x:xs) ys
  | (x:xs) == ys
    = "Yes"
  | otherwise
    = solve (n - 1) (xs ++ [x]) ys
  


Measured memory_bytes: 764
#include <iostream>
#include <cstring>
#include <map>
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX 20000000
#define INFTY (1<<30)

int H,A[MAX+1];

void maxheapify(int i){
  int l, r ,largest;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;

  if(largest !=i){
    swap(A[i],A[largest]);
    maxheapify(largest);
  }
}

int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=A[1];
  A[1]=A[H];
  H--;
  maxheapify(1);
  return maxv;
}

void increaseKey(int i,int key){
  if(key<A[i])return;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    swap(A[i],A[i/2]);
    i/=2;
  }
}

void insert(int key){
  H++;
  A[H]= -INFTY;
  increaseKey(H,key);
}

int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n') break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;
}


Measured memory_bytes: 7056
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};


#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

ll g(ll r, ll c, const combination& fact) {
    ll ans = 0;
    REP(i, r+1) {
        ans = (ans + fact.fact[i+c+1] * fact.inv[i+1] % mod * fact.inv[c] % mod) % mod;
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    combination fact(r2+c2+10);
    ll ans = g(r2, c2, fact);
    ans = (ans - g(r1-1, c2, fact) + mod) % mod;
    ans = (ans - g(r2, c1-1, fact) + mod) % mod;
    ans = (ans + g(r1-1, c1-1, fact) + mod) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31488
N = int(input())
A = list(map(int, input().split()))
#print(sorted(list(enumerate(A)),key=lambda x:x[1]))
#print(*[i[0]+1 for i in sorted(list(enumerate(A)),key=lambda x:x[1])])

ans = [0]*N
for i,a in enumerate(A):
  ans[a-1] = i+1
print(*ans)

Measured memory_bytes: 13812
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

template<typename T>
struct ST{
  using F = function<T(T, T)>;
  int size_ = 1, n_; vector<T> node; T initial; F query_, update_;
  ST(int n, T initial, F query, F update){
    while(size_ < n) size_ *= 2;
    node.resize(2*size_-1, initial);
    n_ = n;
    query_ = query;
    update_ = update;
  }
  void printnodes(){
    rep(i, node.size()) cout << node[i] << endl;
    return;
  }
  void build(vector<T> v){
    rep(i, v.size()) node[i+size_-1] = v[i];
    rrep(i, size_ - 1) node[i] = query_(node[2*i+1], node[2*i+2]);
    return;
  }
  void update(int j, T x){
    j += size_-1;
    node[j] = update_(node[j], x);
    while(j > 0){
      j = (j-1)/2;
      node[j] = query_(node[2*j+1], node[2*j+2]);
    }
    return;
  }
  T query(int l, int r){
    l += size_-1;
    r += size_-1;
    T ql = node[l], qr = node[r];
    while(l < r-1){
      if(l % 2 == 1) ql = query_(ql, node[l+1]);
      if(r % 2 == 0) qr = query_(node[r-1], qr);
      l = (l-1)/2;
      r = (r-1)/2;
    }
    return query_(ql, qr);
  }
  T entire(){
    return node[0];
  }
  int lb(T x){
    int tmp = 0;
    while(tmp < size_-1){
      if(x <= node[tmp*2+1]) tmp = tmp*2+1;
      else tmp = tmp*2+2;
    }
    if(node[tmp] < x) ++tmp;
    return min(tmp+1-size_, n_);
  }
  int ub(T x){
    int tmp = 0;
    while(tmp < size_-1){
      if(x < node[tmp*2+1]) tmp = tmp*2+1;
      else tmp = tmp*2+2;
    }
    if(node[tmp] <= x) ++tmp;
    return min(tmp+1-size_, n_);
  }
};

int main() {
  lint n;
  cin >> n;
  vector<pli> v(n); vector<lint> x(n), r(n), s(n+1); s[n] = 1;
  rep(i, n) cin >> v[i].fi >> v[i].se;
  auto f = [](lint a, lint b){return max(a, b);};
  ST<lint> st(n, -1*1e9, f, f);
  sort(v.begin(), v.end());
  rep(i, n) x[i] = v[i].fi;
  rrep(i, n) st.update(i, v[i].fi+v[i].se);
  rrep(i, n){
    int j = lower_bound(x.begin(), x.end(), v[i].fi+v[i].se)-x.begin()-1;
    r[i] = st.query(i, min(j, (int)n-1));
    st.update(i, r[i]);
  }
  rep(i, n) r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();
  rep(i, n){
    s[n-i-1] = s[n-i] + s[r[n-i-1]];
    s[n-i-1] %= mod2;
  }
  cout << s[0] << endl;
  return 0;
}

Measured memory_bytes: 12160
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
 
#define A first
#define B second
 
typedef long long ll;
constexpr int MOD = 1e9 + 7;

void solve() {
  int X;
  cin >> X;
  cout << 1 - X;
}

 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int a,b,m;
    cin >> a >> b >> m;
    vector<int> A(a),B(b);
    
    int mna = mod,mnb = mod;
    for(int i = 0; i < a; i++){
        cin >> A[i];
        mna = min(mna,A[i]);
    }
    for(int i = 0; i < b; i++){
        cin >> B[i];
        mnb = min(mnb,B[i]);
    }
    ll ans = mna+mnb;
    for(int i = 0; i < m; i++){
        int y,x,c;
        cin >> x >> y >> c;
        x--;y--;
        int mon = A[x]+B[y]-c;
        if(ans > mon) ans = mon;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
S = Number(require('fs').readFileSync('/dev/stdin').toString())
ary = [];
for (i = 0; i < 3; i++) {
	d = Math.pow(60, 2 - i)
	r = d * 60
	ary.push(Math.floor((S % r) / d))
}
console.log(ary.join(":"))

Measured memory_bytes: 15460
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <tuple>
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define REP(i,n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vint;

int main() {
	int a[5], k;
	for(int i = 0; i < 5; i++) {
		scanf("%d", &a[i]);
	}
//	scanf("%d", &k);
	int min{10};
	int mini{100};
	for(int i = 0; i < 5; i++) {
		if(a[i] % 10 > 0 && a[i] % 10 < min) {
			min = a[i] % 10;
			mini = i;
		}
		a[i] = (a[i] % 10) ? (a[i] / 10 + 1) * 10 : a[i];
	}
	int sum{};
	for(int i = 0; i < 5; i++) {
		sum += a[i];
	}
	sum -= 10;
	sum += min;
	printf("%d\n", sum);
	return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int cnt[111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	int muda=0;
	rep(i,n){
		int a;
		cin>>a;
		a--;
		cnt[a]++;
		if(cnt[a]>1)muda++;
	}
	cout<<n-muda-muda%2<<endl;
	return 0;
}


Measured memory_bytes: 640
id division.
  program-id. abc169c.

data division.
  working-storage section.
  77 ab pic x(21).
  77 a pic 9(16).
  77 b pic 9v99 usage packed-decimal.
  77 ans pic z(16)9.

procedure division.
  accept ab.
  unstring ab delimited by space into a b.
  compute ans = a * b.
  display ans.
  stop run.


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

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> ps(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> ps[i];
    ps[i]--;
  }
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int x,y; cin >> x >> y;
    uf.unionSet(x - 1, y - 1);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (uf.findSet(ps[i], i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import math

def main():
    N=int(input())
    Ps=[tuple(map(int, input().split())) for _ in range(N)]

    s = 0
    for i in range(N-1):
        for j in range(i+1,N):
            s += math.hypot(Ps[i][0]-Ps[j][0], Ps[i][1]-Ps[j][1])

    print(s*2/N)
    

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc145","c",main)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)

const int mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(m);
    for (auto&& i : x) scanf("%d", &i);
    for (auto&& i : y) scanf("%d", &i);

    ll ans = 0;
    ll xs = 0, ys = 0;
    rep(i, n) {
        xs += 1LL * i * x[i] - 1LL * (n - i - 1) * x[i];
        xs %= mod;
    }
    rep(i, m) {
        ys += 1LL * i * y[i] - 1LL * (m - i - 1) * y[i];
        ys %= mod;
    }

    cout << (xs * ys) % mod << endl;

    return 0;
}

Measured memory_bytes: 1024
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 1e5 + 5;
int a[N], n; 
int main() {
	int n; cin >> n;
	repn(i, n) cin >> a[i];
	LL ans = 0;
	repn(i, n) {
		ans += a[i] / 2;
	    a[i] %= 2;
	    if (i + 1 <= n && a[i] && a[i + 1]) ans++, a[i]--, a[i + 1]--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
  int n;
  
  scanf("%d",&n);
  
  int h[n];
  for(int i = 0;i<n;i++){
    scanf("%d",&h[i]);
  }//h数値に収納
  
  int ans[n],count,tmp;
  
  count =1;
  tmp=0;
  
  for(int j = 0;j<n-1;j++){
    ans[j]=0;
    if(h[j]>=h[j+1]){
      ans[j]=count;
      count++;
      if(tmp<ans[j]){
        tmp =ans[j];
      }
    }else{
      count=1;
    }
  }
  
 /* if(tmp<count){
    tmp =count-1;
  }*/
  
  
  printf("%d",tmp);
  
  return 0;
}



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

int main(){
    int T,n,m,k;
    char c[10000];
    long long a,b,x;
    scanf("%lld%lld%lld",&a,&b,&x);
    long long ans = (b / x) - (a / x);
    if(a % x == 0){ans ++;}
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector< int > g[n];
	int arr[n],brr[n];
	for ( int i=0;i<m;i++){
		int aa,bb;
		cin>>aa>>bb;
		aa--;bb--;
		g[aa].push_back( bb);
		g[bb].push_back( aa);
	}
	for ( int i=0;i<n;i++)
		arr[i]=1e9;
	arr[0]=0;
	deque< int > q;
	q.push_back( 0);
	while (q.size()){
		int x=q.front();
		q.pop_front();
		for ( int i:g[x])
			if ( arr[i]>arr[x]+1){
				q.push_back(i);
				arr[i]=arr[x]+1;
				brr[i]=x;
			}
	}
	for (int i=1;i<n;i++)
		if ( arr[i]==1e9){
			cout<<"No\n";
			return 0;
		}
	cout<<"Yes\n";
	for ( int i=1;i<n;i++)
		cout<<brr[i]+1<<'\n';
}

Measured memory_bytes: 10924
N = gets.to_i
ary = Array.new

ary << N
def solve(ary)
    num = ary.pop
    if num > 0 then
        if (num % 4 == 0) or (num % 7 == 0) then
            return 1
        end
        ary.push(num - 7)
        ary.push(num - 4)
        solve(ary)
    end
end

if solve(ary) == 1 then
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 1788
dec = {}
dec["a"] = 0
dec["b"] = 0
dec["c"] = 0
dec["d"] = 0
dec["e"] = 0
dec["f"] = 0
dec["g"] = 0
dec["h"] = 0
dec["i"] = 0
dec["j"] = 0
dec["k"] = 0
dec["l"] = 0
dec["m"] = 0
dec["n"] = 0
dec["o"] = 0
dec["p"] = 0
dec["q"] = 0
dec["r"] = 0
dec["s"] = 0
dec["t"] = 0
dec["u"] = 0
dec["v"] = 0
dec["w"] = 0
dec["x"] = 0
dec["y"] = 0
dec["z"] = 0
while True:
    try:
        for s in list(input()):
            if s.lower() in dec:
                dec[s.lower()] += 1
    except:
        break
for n in dec:
    print(f"{n} : {dec[n]}") 




Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
long long k,ans=0;
map<long long,bool>vis;
void fun(long long x)
{

	if(x==1)return;
	long long y=k;
	while(y%x==0)y/=x;
	y%=x;
	if(y==1)
	{
		if(!vis[x])
		{
			ans++;vis[x]=1;
		}
	}
}
int main()
{
	cin>>k;
	for(long long i=1;i*i<=k;i++)
	{
		if(k%i==0)
		{
			fun(i);fun(k/i);
		}
	}
	for(long long i=1;i*i<=k-1;i++)
	{
		if((k-1)%i==0)
		{
			fun(i);fun((k-1)/i);
		}
		
	}
	cout<<ans;
	return 0;
}

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

using ll = long long;

int N, A;
int x[111];
ll dp[111][111][5555];

int main() {
   cin >> N >> A;
   for (int i = 0; i < N; i++) cin >> x[i];

   dp[0][0][0] = 1;
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         for (int k = 0; k <= 5000; k++) {
            // 選ばない
            dp[i+1][j][k] += dp[i][j][k];
            // 選ぶ
            if (k >= x[i]) {
               dp[i+1][j+1][k] += dp[i][j][k-x[i]];
            }
         }
      }
   }

   ll ans = 0;
   for (int j = 1; j <= N; j++) {
      ans += dp[N][j][j*A];
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 201728
#include<stdio.h>
int main ()
{
    int A1,A2,A3,C;
    scanf("%d%d%d",&A1,&A2,&A3);
    C=A1+A2+A3;
    if(C>=22){
        printf("bust\n");
    }
    else{
        printf("win\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N,K,ans=0;
    cin >> N >> K;
    vector<int> v(N);
    for(int i=0;i<N;i++){
        cin >> v.at(i);
    }
    
    sort(v.begin(),v.end(),greater<int>());
    //reverse(v.begin(), v.end()); ↑のようにやれば最初から
    
    for(int i=0;i<K;i++){
        ans += v.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math

x = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    d = is_prime(x)
    if d == False:
        x += 1
    else:
        print(x)
        break


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

using namespace std;

typedef long long ll;

ll inq(ll x, ll y, ll mod)
{
    if (y == 0) return 1 % mod;
    ll l = inq(x, y / 2, mod);
    if (y % 2) return l * l % mod * x % mod;
    return l * l % mod;
}

ll gcdex(ll a, ll b, ll &x, ll &y)
{
    // Solves the equation ax + by = gcd(a, b)
    // returns gcd(a, b)
    // save x and y in given values
    //
    // Correctness tested on random tests.
    //
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    ll x1, y1;
    ll g = gcdex(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return g;
}

pair<ll, ll> crt(vector<ll> r, vector<ll> m)
{
    // Finds such x, that x mod m[i] = r[i] for each i
    // if such x does not exist returns {0, 0}
    //
    // Correctness tested on random tests.
    //
    int n = r.size();
    for (int i = 0; i < n; i++) r[i] %= m[i];
    ll r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++)
    {
        ll r1 = r[i], m1 = m[i];
        if (m0 < m1)
        {
            swap(m0, m1);
            swap(r0, r1);
        }
        if (m0 % m1 == 0)
        {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        ll x, y;
        ll g = gcdex(m0, m1, x, y);
        ll u = m1 / g;
        if ((r0 - r1) % g != 0)
            return {0, 0};
        ll z = (r1 - r0) / g % u * x % u;
        r0 += z * m0;
        m0 *= u;
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

const int K = 1;

ll solve(ll a, ll m)
{
    if (m == 1) return K;
    ll phi = m;
    ll z = m;
    for (int i = 2; i * i <= z; i++)
    {
        if (z % i == 0)
        {
            phi /= i;
            phi *= (i - 1);
            while (z % i == 0)
            {
                z /= i;
            }
        }
    }
    if (z > 1)
    {
        phi = phi / z * (z - 1);
    }
    ll g = __gcd(m, phi);
    ll y = solve(a, g);
    vector<ll> R = {y, inq(a, y, m)};
    vector<ll> M = {phi, m};
    pair<ll, ll> ze = crt(R, M);
    while (ze.first < K) ze.first += ze.second;
    return ze.first;
}

int main()
{
    int q;
    cin >> q;
    while (q--)
    {
        ll a, m;
        cin >> a >> m;
        ll r = solve(a, m);
        ll phi = m;
        ll z = m;
        for (int i = 2; i * i <= z; i++)
        {
            if (z % i == 0)
            {
                phi /= i;
                phi *= (i - 1);
                while (z % i == 0)
                {
                    z /= i;
                }
            }
        }
        if (z > 1)
        {
            phi = phi / z * (z - 1);
        }
        cout << m * phi + r % (m * phi) << "\n";
    }
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(){
	
	int m,f,r,s;
	
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1 && f==-1 && r==-1)break;
		s=m+f;
		if(m==-1 || f==-1)printf("F\n");
		else if(s>=80)printf("A\n");
		else if(s>=65 && s<80)printf("B\n");
		else if(s>=50 && s<65)printf("C\n");
		else if(s>=30 && s<50){
			if(r>=50)printf("C\n");
			else printf("D\n");
		}
		else printf("F\n");
	}
	
	return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main() {
    int n,ans = 0;
    cin >> n;
    string s;
    cin >> s;
    char tmp = s[0];
    ans++;
    for (int i = 0; i < s.size(); ++i) {
        if(tmp != s[i]){
            tmp = s[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>

using namespace std;

#define H 10

int map[10][5];

int calc_and_remove() {
  int res = [&]{
    int res = 0;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < 5; j++) {
        int left = j;
        int right = left;
        int prev = map[i][left];
        while(right < 5  && map[i][right] && map[i][right] == prev) right++;
        if (right - left >= 3) {
          for(int k = left; k < right; k++) {
            res += map[i][k];
            map[i][k] = 0;
          }
        }
      }
    }
    return res;
  }();

  for(int i = H-1; i >= 0; i--) {
    for(int j = 0; j < 5; j++) {
      int cnt = 0;
      while (map[i][j] == 0 && cnt < 5) {
        for(int k = i; k >= 0; k--) {
          if (k-1 == -1) {
            map[k][j] = 0;
          }
          else {
            map[k][j] = map[k-1][j];
          }
        }
        cnt ++;
      }
    }
  }

  return res;
}

int main() {
  int h;
  while(cin >> h, h) {
    memset(map, 0, H*5*sizeof(int));
    for(int i = 0; i < h; i++)
      for(int j = 0; j < 5; j++)
        cin >> map[i+(10-h)][j];

    int res = 0;
    for(int k = 0; k < 20; k++) {
      res += calc_and_remove();
    }

    cout << res << endl;
  }

  return 0;
}

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

Measured memory_bytes: 2440
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	for (Int i = 0; i < tx-sx; i++) {
		printf("R");
	}
	for (Int i = 0; i < ty-sy; i++) {
		printf("U");
	}
	for (Int i = 0; i < tx - sx; i++) {
		printf("L");
	}
	for (Int i = 0; i < ty - sy; i++) {
		printf("D");
	}

	printf("D");

	for (Int i = 0; i <= tx - sx; i++) {
		printf("R");
	}
	for (Int i = 0; i <= ty - sy; i++) {
		printf("U");
	}

	printf("L");
	printf("U");

	for (Int i = 0; i <= tx - sx; i++) {
		printf("L");
	}
	for (Int i = 0; i <= ty - sy; i++) {
		printf("D");
	}
	printf("R\n");

}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  vector<vector<int> > board(3, vector<int>(3));
  int n = 3;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &board[i][j]);
    }
  }

  vector<int> hsum(3, 0), vsum(3, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      hsum[i] += board[i][j];
      vsum[j] += board[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (abs(hsum[i] - hsum[j]) % 3 != 0 or abs(vsum[i] - vsum[j]) % 3 != 0) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=2e5+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll n,m,a[55][55],b[55][55];

int main()
{
    string s;
    cin>>s;
    set<char> c;
    for(ll i=0;i<s.length();i++){c.insert(s[i]);}
    if(c.size()==2){cout<<"Yes"<<endl;exit(0);}
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int inf = numeric_limits<int>::max();
int main(){
	int n, x;
	cin>>n>>x;
	vector<int> vec;
	vec.push_back(x);
	for(int i = 0; i < n; ++i){int a;cin>>a;vec.push_back(a);}
	sort(vec.begin(), vec.end());
	n = vec.size();
	set<int> s;
	for(int i = 1; i < n; ++i){
		s.insert(vec[i] - vec[i - 1]);
	}
	int res = inf;
	for(auto x : s)res = min(res, x);
	for(int i = 0; i < n; ++i){
		if(vec[i] == x)continue;
		else{
			int d = abs(x - vec[i]);
			if(d % res != 0){
				res = d % res;
			}
			else continue;
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 892
#include <stdio.h>

int main(void){

    int n,ans=0,a=0;
    scanf("%d",&n);
    int p[n];
    for(int i=0;i<n;i++) scanf("%d",&p[i]);
    if(p[0]<p[1]) a=1;
    for(int i=1;i<n-1;i++){
        if(a==0){
            if(p[i]>p[i+1]) ans++;
            else a=1;
        }
        else{
            if(p[i]<p[i+1]) ans++;
            else a=0;
        }
    }
    printf("%d\n",ans);

    return 0;

}

Measured memory_bytes: 128