akhauriyash/Code-Regression huggingface dataset:
// 0514 Quality Checking (????????????)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0514
// by Equim on 16-12-21

#include <cstdio>

int main()
{
    while (true)
    {
        // INPUT
        int a, b, c, Cases;
        scanf("%d%d%d", &a, &b, &c);
        if (a == 0)
            break;
        scanf("%d", &Cases);
        
        int Result[a + b + c + 1];                  //Result[0] reserved.
        for (int i = 1; i <= a + b + c; i++)
        {
            Result[i] = 2;
        }
        
        int RawData[Cases][4];
        for (int i = 0; i < Cases; i++)
        {
            scanf("%d%d%d%d", &RawData[i][0], &RawData[i][1], &RawData[i][2], &RawData[i][3]);
        }
        
        int Unqualified, QualifiedCount, ChekcedInThisRun;
        
        
        // PROCESS
        for (int i = 0; i < Cases; i++)
        {
            if (RawData[i][3] == 1)
            {
                Result[RawData[i][0]] = 1;
                Result[RawData[i][1]] = 1;
                Result[RawData[i][2]] = 1;
            }
        }
        
        do
        {
            ChekcedInThisRun = 0;
            
            for (int i = 0; i < Cases; i++)
            {
                if (RawData[i][3] == 0 && RawData[i][0] + RawData[i][1] + RawData[i][2] > 0)
                {
                    Unqualified = 0;
                    QualifiedCount = 0;
                    for (int j = 0; j <= 2; j++)
                    {
                        if (Result[RawData[i][j]] == 1 || RawData[i][j] == 0)
                        {
                            RawData[i][j] = 0;
                            QualifiedCount++;
                        }
                        else
                            Unqualified = j;
                            
                    }
                    if (QualifiedCount == 2)
                    {
                        Result[RawData[i][Unqualified]] = 0;
                        RawData[i][Unqualified] = 0;
                        ChekcedInThisRun++;
                    }
                }
            }
        } while (ChekcedInThisRun > 0);

        
        // OUTPUT
        for (int i = 1; i < a + b + c + 1; i++)
        {
            printf("%d\n", Result[i]);
        }
    }
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  if(n <= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());
    int X = Integer.parseInt(sc.next());
    int Y = Integer.parseInt(sc.next());

    int xMax = X, yMin = Y;
    for (int i = 0; i < N; i++) {
      int x = Integer.parseInt(sc.next());
      if (xMax < x) {
        xMax = x;
      }
    }
    for (int i = 0; i < M; i++) {
      int y = Integer.parseInt(sc.next());
      if (yMin > y) {
        yMin = y;
      }
    }

    if (xMax < yMin) {
      System.out.println("No War");
    } else {
      System.out.println("War");
    }
  }
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void){
    char c,S[300010];
    int i,N;
    scanf("%d",&N);
    for(i = 1;i <= N;i++){
        scanf("%c",&c);
        if(c == 'W'||c == 'E'){
            S[i] = c;
            }else{
            i--;
            }
        }
    // printf("%d\n",N);
    // for(i = 1;i <= N;i++) printf("%c",S[i]);

    // test用
    int Reader = 1;
    int countb = 0;
    for(i = 1;i < Reader;i++){
        if(S[i] == 'W') countb++;
    }
    
    for(i = N;Reader < i;i--){
        if(S[i] == 'E') countb++;
    }

    // printf("%d\n",countb);

    // printf("%d",count);
    
    // test用 終わり

    // 実際処理用
    // int Reader,ans = 999999;
    // for (Reader = 1;Reader <= N;Reader++){
    //     int count = 0;
        
    //     for(i = 1;i < Reader;i++){
    //         if(S[i] == 'W') count++;
    //     }
    
    //     for(i = N;Reader < i;i--){
    //         if(S[i] == 'E') count++;
    //     }

    //     if(count <= ans) ans = count;
    // }
    // 実際処理用 終わり

    int ans = countb;
    for(i = 2;i <= N;i++){
        if(S[i] == 'E') countb--;
        if(S[i - 1] == 'W') countb++;

        if(countb <= ans) ans = countb; 
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Arrays;

class Solver {
    public void Solve() {
        int n = sc.nextInt();
        String[] str = new String[n];
        for (int i = 0; i < str.length; i++) {
            str[i] = sc.next();
        }
        Arrays.sort(str);
        int max = 0;
        String s = "";
        int cnt = 0;
        for (int i = 0; i < str.length; i++) {
            if (s.equals(str[i])) {
                cnt++;
                max = Math.max(max, cnt);
            } else {
                s = str[i];
                cnt = 0;
            }
        }
        s = "";
        for (int i = 0; i < str.length; i++) {
            if (s.equals(str[i])) {
                cnt++;
            } else {
                s = str[i];
                cnt = 0;
            }
            if (cnt == max) {
                System.out.println(str[i]);
                cnt = 0;
            }
        }
    }

    Scanner sc;

    Solver(Scanner in) {
        this.sc = in;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Solver s = new Solver(sc);
        s.Solve();
        sc.close();
    }
}


Measured memory_bytes: 77832
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
asc(const void *a, const void *b)
{
  ll x = *(ll *)a, y = *(ll *)b;
  if (x > y) return  1;
  if (x < y) return -1;
  return 0;
}

long long
dfs(int f, int b, int l, int sign, ll *a)
{
  if (f == l) {
    ll sum = a[l];
    if (sign == 1) {
      for (int i = l + 1; i <= b - 1; i++) {
	printf("%lld %lld\n", sum, a[i]);
	sum -= a[i];
      }
      printf("%lld %lld\n", a[b], sum);
      sum = a[b] - sum;
      return sum;
    } else {
      for (int i = l + 1; i <= b; i++) {
	printf("%lld %lld\n", sum, a[i]);
	sum -= a[i];
      }
      return sum;
    }
  }
  if (b == l + 1) {
    ll sum = a[l + 1];
    if (sign == 1) {
      for (int i = f; i <= l; i++) {
	printf("%lld %lld\n", sum, a[i]);
	sum -= a[i];
      }
      return sum;
    } else {
      for (int i = f; i < l; i++) {
	printf("%lld %lld\n", sum, a[i]);
	sum -= a[i];
      }
      printf("%lld %lld\n", a[l], sum);
      sum = a[l] - sum;
      return sum;
    }
  }
  if (sign == 1) {
    printf("%lld %lld\n", a[b], a[f]);
    ll x = dfs(f + 1, b - 1, l, -sign, a);
    printf("%lld %lld\n", a[b] - a[f], x);
    return a[b] - a[f] - x;
  } else {
    printf("%lld %lld\n", a[f], a[b]);
    ll x = dfs(f + 1, b - 1, l, -sign, a);
    printf("%lld %lld\n", a[f] - a[b], x);
    return a[f] - a[b] - x;
  }
}
      
    

int
main(int argc, char *argv[])
{
  int n; ll a[100010];
  scanf("%d", &n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum += abs(a[i]);
  }
  qsort(a, n, sizeof(ll), asc);

  if (a[0] >= 0) {
    printf("%lld\n", sum - a[0] - a[0]);
    ll x = a[0];
    for (int i = 1; i < n - 1; i++) {
      printf("%lld %lld\n", x, a[i]);
      x -= a[i];
    } printf("%lld %lld\n", a[n - 1], x);
  }
  else if (a[n - 1] <= 0) {
    printf("%lld\n", sum + a[n - 1] + a[n - 1]);
    ll x = a[n - 1];
    for (int i = 0; i < n - 1; i++) {
      printf("%lld %lld\n", x, a[i]);
      x -= a[i];
    }
  }
  else {
    printf("%lld\n", sum);
    int l = 0, r = n, med;
    while (r - l > 1) {
      med = (l + r) / 2;
      if (a[med] < 0) l = med;
      else r = med;
    } //printf("l : %d\n", l);
    dfs(0, n - 1, l, 1, a);
  }
  return 0;
}
    
    


Measured memory_bytes: 6124
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int h, w, m;
char c[55][55];
lint run[55][55], on[55][55], off[55][55];
pii pos[1010];
vector<int> visited_time[55][55];

int dfs(int x, int y, int px, int py, int tx, int ty, int cur){
    if(x == tx && y == ty){
        visited_time[tx][ty].push_back(cur);
        return cur;
    }
    rep(i, 4){
        int nx = x + dx[i], ny = y + dy[i];
        if(0 <= nx && nx < h && 0 <= ny && ny < w && c[nx][ny] == '.'){
            if(nx != px || ny != py){
                int ret = dfs(nx, ny, x, y, tx, ty, cur + 1);
                if(ret >= 0){
                    visited_time[x][y].push_back(cur);
                    return ret;
                }
            }
        }
    }
    return -1;
}

int main(){
    scanf("%d%d%d", &h, &w, &m);
    rep(i, h)rep(j, w) scanf(" %c", &c[i][j]);
    rep(i, h)rep(j, w) scanf("%lld", &run[i][j]);
    rep(i, h)rep(j, w) scanf("%lld", &on[i][j]);
    rep(i, h)rep(j, w) scanf("%lld", &off[i][j]);
    rep(i, m) scanf("%d%d", &pos[i].fi, &pos[i].se);

    int now = 0;
    rep(i, m - 1){
        now = dfs(pos[i].fi, pos[i].se, -1, -1, pos[i + 1].fi, pos[i + 1].se, now);
    }
    lint ans = 0;
    rep(x, h)rep(y, w)if(!visited_time[x][y].empty()){
        visited_time[x][y].erase(unique(visited_time[x][y].begin(), visited_time[x][y].end()), visited_time[x][y].end());
        ans += on[x][y] + off[x][y];
        rep(i, visited_time[x][y].size() - 1){
            ans += min(off[x][y] + on[x][y], run[x][y] * (visited_time[x][y][i + 1] - visited_time[x][y][i]));
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 8396
#include<bits/stdc++.h>
using namespace std;
const int N =100096;
int r[N], c[N], a[N];
int R, C, n;
bool vr[N], vc[N];
vector<int> er[N], ec[N];

bool ok = true;
int64_t low, up;

int64_t xr[N], yc[N];
void dfsr(int);
void dfsc(int);



int main() {
	scanf("%d%d%d", &R, &C, &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d%d%d", r + i, c + i, a + i);
		er[r[i]].push_back(i);
		ec[c[i]].push_back(i);
	}
	for(int i = 1; i <= R && ok; ++i)
	if(!vr[i]) {
		low = -1e18;
		up = 1e18;
		dfsr(i);
		vr[i] = true;
		ok &= (up >= 0 && low <= up);
	}
	puts(ok ? "Yes" : "No");
}

void dfsr(int i) {
	low = max(low, -xr[i]);
	for(int j : er[i]) {
		int c = ::c[j], a = ::a[j];
		up = min(up, a - xr[i]);
		if(!vc[c]) {
			vc[c] = true;
			yc[c] = a - xr[i];
			dfsc(c);
		} else {
			ok &= (yc[c] + xr[i] == a);
		}
	}
}

void dfsc(int j) {
	up = min(up, yc[j]);
	for(int i : ec[j]) {
		int r = ::r[i], a = ::a[i];
		low = max(low, yc[j] - a);
		if(!vr[r]) {
			vr[r] = true;
			xr[r] = a - yc[j];
			dfsr(r);
		} else {
			ok &= (yc[j] + xr[r] == a);
		}
	}
}

Measured memory_bytes: 14208
#include<iostream>
using namespace std;
int main(){
	int N,T;
	int c[100],t[100];
	int min_c=1001;
	cin>>N>>T;
	for(int i=0;i<N;i++){
		cin>>c[i]>>t[i];
	}
	for(int i=0;i<N;i++){
		if(t[i]<=T&&c[i]<min_c){
			min_c=c[i];
		}
	}
	if(min_c==1001)cout<<"TLE"<<endl;
	else cout<<min_c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#define INF 10000000
#define I64 long long int
#define FOR(a,start,end) for(I64 a=(start);a<(end);a++)
using namespace std;

int main(){
	//4ûüpzñ
	int vec[] = {1, -1, 4, -4};
	queue<string> que;
	que.push("01234567");

	//TõÏÝe[u
	map<string, int> d;

	//"01234567"©çtü«ÉDæTõµÈªçTõÏÝe[uðßé
	while(!que.empty()){
		string str = que.front();
		que.pop();
		int zero = str.find("0");

		string str2;
		FOR(i, 0, 4){
			int next_z;
			next_z = zero + vec[i];
			if(next_z >= 0 && next_z <= 7 && !((zero == 3 && next_z == 4) || (zero == 4 && next_z == 3))){
				str2 = str;
				swap(str2[zero], str2[next_z]);
				if(d.find(str2) == d.end()){
					que.push(str2);
					d[str2] = d[str] + 1;
				}
			}
		}
	}

	//üÍ©ç' 'ð¢ÄTõÏÝe[u©ç¦ðoÍ
	string num;
	while(getline(cin, num)){
		string::iterator end_it = remove(num.begin(), num.end(), ' ');
		num.erase(end_it, num.end());
		cout << d[num] << endl;
	}
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
using ll=long long;


int main(){
  int N,K;
  cin>>N>>K;
  vector<int> P(N);
  vector<ll> C(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
    P[i]--;
  }
  for(int i=0;i<N;i++){
    cin>>C[i];
  }

  ll ans=-1000000000;
  vector<pair<ll,int>> loop_score(N);
  vector<bool> seen(N,false);
  for(int i=0;i<N;i++){
    if(seen[i]==false){
      seen[i]=true;
      int v=i;
      ll score=0;
      int count=0;
      while(true){
        count++;
        v=P[v];
        seen[v]=true;
        score+=C[v];
        if(v==i){
          break;
        }
      }
      loop_score[i]=make_pair(score,count);
      v=i;
      while(true){
        v=P[v];
        if(v==i){
          break;
        }
        loop_score[v]=make_pair(score,count);
      }
    }
  }

  for(int i=0;i<N;i++){
    if(loop_score[i].first<0){
      ll score=0;
      int v=i;
      for(int j=0;j<min(N,K);j++){
        v=P[v];
        score+=C[v];
        ans=max<ll>(ans,score);
      }
    }else{
      int count=loop_score[i].second;
      int x=K/count;
      if(x==0){
        ll score=0;
        int v=i;
        for(int j=0;j<K;j++){
          v=P[v];
          score+=C[v];
          ans=max<ll>(ans,score);
        }
      }else{
        ll score=loop_score[i].first*(ll)x;
        ans=max<ll>(ans,score);
        int v=i;
        int n=K%count;
        for(int j=0;j<n;j++){
          v=P[v];
          score+=C[v];
          ans=max<ll>(ans,score);
        }
        x--;
        score=loop_score[i].first*(ll)x;
        v=i;
        if(x>0){
          ans=max<ll>(ans,score);
        }
        for(int j=0;j<count;j++){
          v=P[v];
          score+=C[v];
          ans=max<ll>(ans,score);
        }
      }
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll NINF = -1e18L;

// INT VS LL

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll k;
    cin >> n >> k;
    vector<int> to(n);
    for (int i = 0; i < n; ++i){
    	int x; cin >> x;
    	to[i] = x - 1;
    }
    vector<ll> c(n);
    for (int i = 0; i < n; ++i){
    	cin >> c[i];
    }
    ll sum = 0, ans = NINF;
    vector<bool> vis(n);
    vector<ll> sms;
   	function<void(int, int)> dfs = [&](int u, int cnt){
   		if (cnt == k) return;
   		int v = to[u];
   		if (!vis[v]){
   			sum += c[v];
   			ans = max(ans, sum);
   			sms.push_back(sum);
   			vis[v] = 1;
   			dfs(v, cnt + 1);
   		}
   	};
   	for (int u = 0; u < n; ++u){
   		dfs(u, 0);
   		assert(!sms.empty());
   		int len = (int) sms.size();
   		int turns = k / len;
   		if (turns){
	   		ll cur = sms.back() * (turns - 1);
	   		for (int i = 0; i < (int) sms.size(); ++i) ans = max(ans, cur + sms[i]);
	   		cur += sms.back();
	   		for (int i = 0; i < k - (turns * len) ; ++i) ans = max(ans, cur + sms[i]);
	   		sum = 0;
	   		vis.assign(n, 0);
	   		sms.clear();
   		}
   	}
   	assert(ans != NINF);
   	cout << ans << '\n';
   	// cout << NINF << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

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

    ll W, H, x, y;
    std::cin >> H >> W >> x >> y;
    long double ans = H * W / 2.0;
    if(H / 2.0 == x && W / 2.0 == y) {
        std::cout << ans << setprecision(20) << " " << 1 << std::endl;
    }
    else {
        std::cout << ans << setprecision(20) << " " << 0 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
char pos[100][100] = {};
int X, Y, mem[100][100] = {}, n, m;
int f(int x, int y) {
	if (mem[x][y] == 1) {
		return 1;
	}
	mem[x][y] = 1;
	if (pos[x][y] == '<') {
		if (y == 0)
			return 1;
		y -= 1;
	}
	else if (pos[x][y] == '>') {
		if (y == m - 1)
			return 1;
		y += 1;
	}
	else if (pos[x][y] == '^') {
		if (x == 0)
			return 1;
		x -= 1;
	}
	else if (pos[x][y] == 'v') {
		if (x == n - 1)
			return 1;
		x += 1;
	}
	else if (pos[x][y] == '.') {
		X = x;
		Y = y;
		return 0;
	}
	return f(x, y);
}
int main() {
	while (std::cin >> n >> m, n + m != 0) {
		X = 0, Y = 0;
		for (int i = 0; i < n; i += 1)
			for (int j = 0; j < m; j += 1) {
				std::cin >> pos[i][j];
				mem[i][j] = 0;
			}
		int ans = f(0, 0);
		if (ans == 1)
			std::cout << "LOOP" << std::endl;
		else std::cout << Y <<" "<< X << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<map>

std::string to_bs(int i){
	std::string s = "";
	while(i > 0){
		s = static_cast<char>(i%2+'0') + s;
		i /= 2;
	}
	while(s.length() < 5){
		s = '0' + s;
	}
	return s;
}

int main(){
	std::map<char, std::string> input;
	std::map<std::string, char> output;
	output["101"] = ' ';
	output["000000"] = '\'';
	output["000011"] = ',';
	output["10010001"] = '-';
	output["010001"] = '.';
	output["000001"] = '?';
	output["100101"] = 'A';
	output["10011010"] = 'B';
	output["0101"] = 'C';
	output["0001"] = 'D';
	output["110"] = 'E';
	output["01001"] = 'F';
	output["10011011"] = 'G';
	output["010000"] = 'H';
	output["0111"] = 'I';
	output["10011000"] = 'J';
	output["0110"] = 'K';
	output["00100"] = 'L';
	output["10011001"] = 'M';
	output["10011110"] = 'N';
	output["00101"] = 'O';
	output["111"] = 'P';
	output["10011111"] = 'Q';
	output["1000"] = 'R';
	output["00110"] = 'S';
	output["00111"] = 'T';
	output["10011100"] = 'U';
	output["10011101"] = 'V';
	output["000010"] = 'W';
	output["10010010"] = 'X';
	output["10010011"] = 'Y';
	output["10010000"] = 'Z';
	
	for(int i=0;i<26;i++){
		input['A' + i] = to_bs(i);
	}
	input[' '] = "11010";
	input['.'] = "11011";
	input[','] = "11100";
	input['-'] = "11101";
	input['\''] = "11110";
	input['?'] = "11111";

	std::string s;
	while(std::getline(std::cin, s), !std::cin.eof()){
		std::string code;
		for(int i=0;i<s.size();i++){
			code += input[s[i]];
		}

		std::string res = "", temp_s = "";
		for(int i=0;i<code.size();i++){
			temp_s += code[i];
			if(output[temp_s]){
				res += output[temp_s];
				temp_s = "";
			}
		}
		
		std::cout << res << std::endl;
		std::cin.clear();
	}
}

Measured memory_bytes: 2988
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int power(int x,int y){
    int res = 1;

    while(y){
        if(y&1) res = res*x;
        x = x*x;
        y >>= 1;
    }
    return res;
}

void solve(){
    int n; cin>>n;

    int val = n-1;

    set<int> sol;

    for(int i=2;i*i<=val;i++){
        if(val%i == 0){
            sol.insert(i);
            sol.insert(val/i);
        }
    }

    sol.insert(val);

    for(int i=1;i*i<=n;i++){
        if(n%i == 0){
            if(i != 1){
                val = n;
                while(val%i == 0) val = val/i;
                val = val%i;
                if(val == 1) sol.insert(i);
            }
            
            if((n/i) != 1){
                val = n;
                while(val%(n/i) == 0) val = val/(n/i);
                val = val%(n/i);
                if(val == 1) sol.insert((n/i));
            }
        }
    }

    sol.erase(1);
    cout<<sz(sol)<<endl;
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int n;
	string ans="";
	cin >>n>>s;
	int st=0,en=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('){
			st++;
			ans+=s[i];
		}else{
			en++;
			ans+=s[i];
		}
		while(st <en){
			st++;
			ans='('+ans;
		}
	}
	while(st >en){
		en++;
		ans+=')';
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define rg register
using namespace std;
template<typename T>inline void in(T &a)
{
	T ch=getchar(),f=1;
	for(a=0;!isdigit(ch);ch=getchar())
	  ch=='-'?f=-1:f=f;
	for(;isdigit(ch);ch=getchar())
	  a=(a<<3)+(a<<1)+ch-'0';
	a*=f;
}
template<typename T>inline void print(T x)
{
	if(x<0)
	  putchar('-'),x=-x;
	if(x>9)
	  print(x/10);
	putchar(x%10+'0');
}
long long a[100010];
long long n,k;
signed main()
{
	cin>>n>>k;
	for(long long i=1;i<=n;i++)
	  in(a[i]);
	sort(a+1,a+1+n);
	long long ans=1000200000ll;
	for(long long i=1;i<=n-k+1;i++)
	  ans=min(a[i+k-1]-a[i],ans);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
s = []
for _ in range(N):
    s.append(int(input()))
s = sorted(s)
ans = sum(s)
i = 0
#print(s)
while ans % 10 == 0:
    ans = sum(s)
    #print(i)
    ans -= s[i]
    i += 1
    if i >= N:
        ans = 0
        break
print(ans)

Measured memory_bytes: 63376
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll K,N,X,A[200010];
ll ans=0;
ll S[3][5000];
map< int64_t, int > ret;
int main(){
    cin>>N;
    REP(i,N){cin>>A[i];}
    REP(i,N){
        if(i==0)X=A[i];
        else X=(X^A[i]);
    }
    REP(i,N){
        cout<<(X^A[i]);
        if(i!=N-1)cout<<" ";
    }

    //std::cout<<ans<<endl;

}

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

public class Program{
  public static void Main(){
    var n = Int32.Parse(Console.ReadLine());
    var a = new Int32[2,n];
    for(var i=0; i<2; i++){
      var l = Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);
      for(var j=0; j<n; j++) a[i,j] = l[j];
    }
    var m = 0;
    for(var i=0; i<n; i++){
      var t = 0;
      for(var j=0; j<i+1; j++) t += a[0, j];
      for(var k=i; k<n; k++)   t += a[1,k];
      if(m < t) m=t;
    }
    Console.WriteLine(m);
  }
}


Measured memory_bytes: 11220
n = int(input())
a = [int(input()) for _ in range(n)]
s = set()
x = 0
for i in range(n):
    x ^= a[i]
    s.add(len(bin(a[i] & -a[i])) - 3)
res = 0
for i in range(50, -1, -1):
    if (x >> i) & 1:
        if i in s:
            x ^= (1 << (i + 1)) - 1
            res += 1
        else:
            print(-1)
            exit(0)
print(res)


Measured memory_bytes: 7108
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
if oc.most_common(1)[0][0] != ec.most_common(1)[0][0]:
    a = h - oc.most_common(1)[0][1]
    b = h - ec.most_common(1)[0][1]
    print(a+b)
else:
    if len(oc) == 1:
        print(h)
        exit()
    E1 = E2 = 0
    for i, (k, v) in enumerate(ec.most_common(2)):
        if i == 0:
            E2 = E1 = k
        else:
            E2 = k
    O1 = O2 = 0
    for i, (k, v) in enumerate(oc.most_common(2)):
        if i == 0:
            O2 = O1 = k
        else:
            O2 = k
    print(min(h-ec[E1] + h - oc[O2], h - ec[E2] + h - oc[O1]))


Measured memory_bytes: 19040
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int N,M,a[2000][3];
long double ex[2001][3],dp[2001][3];
long double C[2001],up[2001],jus[2001];
long double Up(int x){
	if(x<=M) return up[x];
	return 0;
}
int main(){
	cin>>N>>M;
	C[0]=1;
	rep(i,M){
		C[i+1]=C[i]*(M-i)/(i+1)/3;
	}
	rep(i,N) rep(j,3) cin>>a[i][j];
	rep(i,M+1) jus[i]=C[i]*pow(2.0/3,M-i);
/*	up[M]=jus[M];
	up[0]=1;
	for(int i=M;i>M/2;i--) up[i-1]=up[i]+jus[i-1];
	for(int i=0;i<M/2;i++) up[i+1]=up[i]-jus[i];*/
	up[M]=jus[M];
	for(int i=M;i>0;i--) up[i-1]=up[i]+jus[i-1];
/*	up[0]=1;
	for(int i=0;i<M;i++) up[i+1]=up[i]-jus[i];*/
//	rep(i,M+1) show(up[i]);
//		show((double)up[0]);
	rep(j,3){
		rep(t,M+1){
			int me=a[0][j]*t;
			rep(i,N) rep(j,3) dp[i][j]=0;
			dp[0][0]=1;
			long double worst=1;
			rep1(i,N-1){
				long double p=Up((me+a[i][j]-1)/a[i][j]);
//				show(me);
//				show(a[i][j]);
//				show(p);
				rep(k,3){
					dp[i][k]+=dp[i-1][k]*(1-p);
					if(k<2) dp[i][k+1]+=dp[i-1][k]*p;
				}
				worst*=p;
			}
			long double coef=5;
			if(j==1) coef=3;
			if(j==2) coef=2;
			ex[t][j]=coef*(dp[N-1][0]+dp[N-1][1]+dp[N-1][2])-worst;
//			printf("ex[%d][%d]=%.3f\n",t,j,ex[t][j]);
		}
	}

	long double ans=-1e9;
	for(int x=0;x<=M;x++) for(int y=0;x+y<=M;y++){
		int z=M-x-y;
		ans=max(ans,ex[x][0]+ex[y][1]+ex[z][2]);
	}
	printf("%.12f\n",(double)ans);
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 2000
#define ull unsigned long long
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Bitset
{
	ull	s[32];
	void Reset(){memset(s,0,sizeof(s));}
	Bitset operator &(const Bitset&y)
	{
		Bitset c;
		for(int j=0;j<32;++j) c.s[j]=s[j]&y.s[j];
		return c;	
	}
	bool has(int y){return bool(s[y>>6]&(1ULL<<(y&63)));}
	void Mod(int y){s[y>>6]^=1ULL<<(y&63);}
	int lowbit()
	{
		for(int j=0;j<32;++j) if(s[j])
		{
			ull x=s[j];int pos=j*64;
			while(!(x&255)) x>>=8,pos+=8;
			for(int k=0;k<8;++k) if(x&(1<<k)) return pos+k;
		}
		return -1;	
	}
}b[MN+5],to,Left;
inline int gcd(int x,int y){return y?gcd(y,x%y):x;}
int n,a[MN+5],head[MN+5],cnt=0,res,vis[MN+5],used[MN+5],ths[MN+5],isnear[MN+5];
struct edge{int to,next;}e[MN*MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;b[f].Mod(t);
	e[++cnt]=(edge){f,head[t]};head[t]=cnt;b[t].Mod(f);
}
void Mark(int x)
{
	to.Mod(x);ths[x]=0;if(isnear[x]&&a[x]<a[res]) res=x;isnear[x]=0;
	int low=(to&b[x]).lowbit();
	while(low!=-1)
	{
		Mark(low);
		low=(to&b[x]).lowbit();
	}
}
void dfs(int x,int v)
{
	vis[x]=v;if(a[x]<a[res]) res=x;
	for(int i=head[x];i;i=e[i].next)
		if(vis[e[i].to]!=v&&!used[e[i].to]) dfs(e[i].to,v); 
}
int main()
{
	n=read();a[0]=int(1e9);
	for(int i=1;i<=n;++i) a[i]=read(),Left.Mod(i);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) 
			if(gcd(a[i],a[j])>1) ins(i,j);
	for(int j=1;j<=n;++j) if(vis[j]!=n+1) 
		res=0,dfs(j,n+1),ths[j]=res;
	for(int i=1;i<=n;++i)
	{
		int mx=0,from=0;
		for(int j=1;j<=n;++j) if(!used[j]&&ths[j]&&a[ths[j]]>mx) mx=a[ths[j]],from=ths[j];
		printf("%d ",mx);used[from]=1;Left.Mod(from);ths[from]=0;
		to=Left;
		for(int j=head[from];j;j=e[j].next) isnear[e[j].to]=1;
		for(int j=head[from];j;j=e[j].next) if(to.has(e[j].to)) res=0,Mark(e[j].to),ths[e[j].to]=res;
	}
	return 0;
}

Measured memory_bytes: 21888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
vector< pll > pii;
int main(){
	ll n, m, rew = 0, next = 0; 
	cin >> n >> m;
	for(int i = 0; i < n; i++){
	    ll a, b; cin >> a >> b;
	    pii.push_back(pll(a,b));
	}
	sort(pii.begin(), pii.end());
	priority_queue<ll> fila;
	for(int i = 1; i < m+1; i++){
	    while(next < n && pii[next].first == i){
	        fila.push(pii[next].second);
	        next++;
	    }
	    if(!fila.empty()){
	        rew += fila.top();
	        fila.pop();
	    }
	}
	//for(int i = 0; i < pii.size(); i++)cout << pii[i].first << " " << pii[i].second << endl;
   cout << rew << endl;
	return 0;
}


Measured memory_bytes: 3568
/*
 *
 */
#include <cstdio>
#include <iostream>

#define DEBUG 0

using namespace std;

int main(){
    //freopen("b3.in", "r", stdin);

    string s;
    cin >> s;

    string ans = "";
    int pos = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '0') {
            s[pos++] = '0';
        } else if (s[i] == '1') {
            s[pos++] = '1';
        } else if (s[i] == 'B') {
            pos--;
            if (pos < 0) pos = 0;
        }
    }
    ans = s.substr(0, pos);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//D - Knapsack 1

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll inf = 1e15L;
const int maxn = 123456;
ll dp[maxn];
int w[110], v[110];

int main(){
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, W;
    cin >> n >> W;
    memset(dp, 0, sizeof(dp));
    int sum_value = 0;
    for(int i = 0; i < n; ++i){
        cin >> w[i] >> v[i];
        sum_value += v[i];
    }
    for(int i = 0; i <= sum_value; ++i)dp[i] = inf;
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = sum_value; j >= 0; --j){
            if(dp[j] + w[i] <= W)
            dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
        }
    }

    ll res = 0;
    for(int i = 1; i <= sum_value; ++i){
        if(dp[i] <= W)
        res = max(res, (ll)i);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;
//bool comp(
//
//	st pll &a, const pll &b) {
//	return a.first < b.first;
//}
//std::vector<int> enum_div(int n)//nの約数を列挙
//{
//	std::vector<int> ret;
//	for (int i = 1; i*i <= n; ++i)
//	{
//		if (n%i == 0)
//		{
//			ret.push_back(i);
//			if (i != 1 && i*i != n)
//			{
//				ret.push_back(n / i);
//			}
//		}
//	}
//	return ret;
//}

template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}

int main()
{
	priority_queue<int> q;
	ll h = 0, w = 0, a = 0, b = 0, ans = 0;
	string s = {};
	ll x[200005];
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> x[i];
		b += x[i];
	}
	ans = 9999999999999;
	for (int i = 0; i < a; i++)
	{
		h += x[i];
		ans = min(ans, abs(b - h * 2));
	}

	//cout<<factorial<10><<endl;

	cout << ans << endl;
	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

	//cout << ans << endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 1792
import math
N ,X ,Y = map(int,input().split())
x = [0] * (N-1)
for i in range(1,N+1):
    for u in range(i+1,N+1):
        y =[abs(u - i), abs(X - i) + 1 + abs(u - Y ), abs(Y - i) + 1 + abs(u - X)]
        x[min(y)-1] += 1
for h in x:
    print(h)

Measured memory_bytes: 47836
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;

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

ll mod=(ll)1e9+7,sum=1;
int n;
bool flag;

int main(void){
    cin>>n;
    vector<pair<int,int> > v;
    for(int i=2;i<n+1; i++){
        int ti = i;
        while(ti>1){
            flag = 1;
            rep(j, v.size()){
                if(ti%v[j].first==0){
                    flag=0;
                    ti/=v[j].first;
                    v[j].second++;
                    break;
                }
            }
            if(flag){
                v.push_back(make_pair(ti,1));
                break;
            }
        }
    }
    rep(j, v.size()){
        sum*=(v[j].second+1);
        sum%=mod;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>& s, llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid] >= a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x = 0;
	while (n) {
		x += n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}


int F(int n) {
	int x = 0;
	while (n) {
		x += n % 10;
		n /= 10;
	}
	return x;
}


int main() {
	int n;
	cin >> n;
	hei(int) a(n);
	int x = 0;
	rep(i, 0, n)cin >> a[i];
	int ans = 0;
	rep(i, 0, n) {
		if (a[i] > 0) {
			a[i]--;
			ans++;
			rep(j, i+1, n) {
				if (a[j] <= 0)break;
				if (a[j] > 0)a[j]--;
			}
			for (int j = i-1; j >= 0; j--) {
				if (a[j] <= 0)break;
				if (a[j] > 0)a[j]--;
			}
			i = -1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def findlcs(x, y):
    dp = [0]*(len(y)+1)

    for c in x:
        tmp = dp[:]
        for j in range(len(y)):
            if c == y[j]:
                dp[j+1] = tmp[j] + 1
            elif dp[j+1] < dp[j]:
                dp[j+1] = dp[j]

    return dp[-1]


q = int(input())
for k in range(q):
    X = input()
    Y = input()
    print(findlcs(X, Y))

Measured memory_bytes: 7740
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <cstdio>
using namespace std;

template<class T>
vector<vector<T> > matrixProduct(const vector<vector<T> >& x, const vector<vector<T> >& y)
{
	int a = x.size();
	int b = x[0].size();
	int c = y[0].size();
	vector<vector<T> > z(a, vector<T>(c, 0));
	for(int i=0; i<a; ++i){
		for(int j=0; j<c; ++j){
			for(int k=0; k<b; ++k){
				z[i][j] += x[i][k] * y[k][j];
			}
		}
	}
	return z;
}

template <class T>
vector<vector<T> > matrixPower(const vector<vector<T> >& x, int k)
{
	int n = x.size();
	vector<vector<T> > y(n, vector<T>(n, 0));
	for(int i=0; i<n; ++i)
		y[i][i] = 1;

	vector<vector<T> > z = x;
	while(k > 0){
		if(k & 1)
			y = matrixProduct(y, z);
		z = matrixProduct(z, z);
		k >>= 1;
	}
	return y;
}

void linearSystem(vector<vector<double> >& mat, vector<double>& x)
{
	int n = mat.size();
	x.resize(n);

	for(int i=0; i<n; ++i){
		for(int j=n; j>=i; --j)
			mat[i][j] /= mat[i][i];
		for(int j=0; j<n; ++j){
			if(j == i)
				continue;
			for(int k=n; k>=i; --k){
				mat[j][k] -= mat[i][k] * mat[j][i];
			}
		}
	}

	for(int i=0; i<n; ++i)
		x[i] = mat[i][n];
}

int main()
{
	int s, n, k;
	cin >> s >> n >> k;
	s = abs(s);
	if(n == 1){
		if(s % k == 0)
			cout << (s / k) << endl;
		else
			cout << -1 << endl;
		return 0;
	}

	vector<double> prob(n*k+1, 0.0);
	prob[0] = 1.0;
	for(int i=0; i<k; ++i){
		vector<double> nextProb(n*k+1, 0.0);
		for(int j=0; j<=n*(k-1); ++j){
			for(int l=1; l<=n; ++l){
				nextProb[j+l] += prob[j] / n;
			}
		}
		prob.swap(nextProb);
	}

	vector<vector<double> > mat(n*k*2-1, vector<double>(n*k*2, 0.0));
	for(int i=0; i<n*k*2-1; ++i){
		mat[i][i] = 1.0;
		if(i == n*k-1){
			continue;
		}
		mat[i][n*k*2-1] = 1.0;
		if(i < n*k-1){
			for(int j=1; j<=n*k; ++j){
				mat[i][i+j] = -prob[j];
			}
		}else{
			for(int j=1; j<=n*k; ++j){
				mat[i][i-j] = -prob[j];
			}
		}
	}
	vector<double> x;
	linearSystem(mat, x);
	x = vector<double>(x.rbegin(), x.rbegin()+n*k);
	if(s < n*k){
		printf("%.10f\n", x[n*k-1-s]);
		return 0;
	}

	vector<vector<double> > y(n*k+1, vector<double>(n*k+1, 0.0));
	y[0][n*k] = 1.0;
	y[n*k][n*k] = 1.0;
	for(int i=0; i<n*k-1; ++i)
		y[i+1][i] = 1.0;
	for(int i=0; i<n*k; ++i)
		y[0][i] = prob[i+1];
	y = matrixPower(y, s-n*k+1);

	double ret = y[0][n*k];
	for(int i=0; i<n*k; ++i)
		ret += y[0][i] * x[i];
	printf("%.10f\n", ret);

	return 0;
}

Measured memory_bytes: 1524
/*３つの整数を読み込み、それらを値が小さい順に並べて出力するプログラム*/

#include <stdio.h>

int main(){

    int a,b,c;
    int tmp;
    
    do{
        scanf("%d %d %d",&a,&b,&c);
    }while(a<1 || a>100000 || b<1 || b>100000 || c<1 || c>100000); /*1 ≤ a, b, c ≤ 10,000を満たすまで繰り返す*/
    
    /*a,b,cを小さい順に並べ替え*/
    if(a>b){
        tmp = a;    
        a   = b;   
        b   = tmp; 
    } 
    if(a>c){
        tmp = a;   
        a   = c;  
        c   = tmp; 
    }
    if(b>c){
        tmp = b;  
        b   = c;  
        c   = tmp; 
    }
    
    printf("%d %d %d\n",a,b,c);
    
    return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){

	int sum = 0,digit = 0,rest,ans,count,tmp;
	char buf[13];

	scanf("%s",buf);

	for(int i = 11; i >= 1; i--){
		if(buf[11-i] >= '0' && buf[11-i] <= '9'){
			if(i >= 7 && i <= 11){
				sum += (buf[11-i] - '0')*(i-5);
			}else{
				sum += (buf[11-i] - '0')*(i+1);
			}

		}else{
			digit = i;
		}
	}

	if(digit == 0){
		rest = sum%11;
		if(rest <= 1){
			printf("0\n");
		}else{
			printf("%d\n",11-rest);
		}
	}else{
		rest = buf[11] - '0';
		count = 0;

		if(digit >= 7){

			for(int i = 0; i <= 9; i++){
				tmp = (sum+i*(digit-5))%11;
				if((tmp <= 1 && rest == 0) || (11-tmp == rest)){
					ans = i;
					count++;
				}
			}

			if(count == 1){
				printf("%d\n",ans);
			}else{
				printf("MULTIPLE\n");
			}

		}else{

			for(int i = 0; i <= 9; i++){
				tmp = (sum+i*(digit+1))%11;
				if((tmp <= 1 && rest == 0) || (11-tmp == rest)){
					ans = i;
					count++;
				}
			}

			if(count == 1){
				printf("%d\n",ans);
			}else{
				printf("MULTIPLE\n");
			}
		}
	}
	return 0;
}

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

double n, a, kq;

main()
{
    cout << setprecision(12) << fixed;
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> a;
        kq += ((double)1 / a);
    }
    kq = (double)1 / kq;
    cout << kq;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
#define REP(i, n) for (ll i = 1; i <= n; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ld long double
using namespace std;

int main()
{
    ll D, G;
    cin >> D >> G;
    vector<ll> p(D);
    vector<ll> c(D);
    vector<ll> perfectScores(D);
    ll ans = INT_MAX;
    rep(i, D)
    {
        cin >> p[i];
        cin >> c[i];
    }

    REP(i,D){
        ll score = 0;
        score += 100 * i * p[i - 1];
        score += c[i - 1];
        perfectScores[i - 1] = score;
    }

    for(int tmp = 0; tmp < (1 << D);tmp++){
        bitset<10> bs(tmp);
        string cut = bs.to_string();
        cut = cut.substr(10 - D);
        //cout << cut << endl;
        ll currentScore = 0;
        ll count = 0;

        rep(i,D){
            if(cut.at(i) == '1'){
                currentScore += perfectScores[i];
                count += p[i];
            }
        }
        rep(i,D){
            rep(j,p[D - i - 1]){
                if(cut.at(D - i - 1) == '0'){
                    if(currentScore < G){
                        currentScore += 100 * (D - i);
                        count += 1;
                    }
                }
            }
        }
        ans = min(ans,count);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;

int main() {
    int N, T;
    cin >> N >> T;
    int minimum = -1;
    for (int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        if (t <= T && (minimum < 0 || minimum > c)) minimum = c;
    }
    if (minimum > 0) cout << minimum << endl;
    else cout << "TLE" << endl;
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0;i < N;++i) cin >> p.at(i);
	int ans = 0;
	for (int i = 0;i < N - 2;++i) {
		if (p.at(i) + p.at(i + 1) + p.at(i + 2) - min({ p.at(i),p.at(i + 1),p.at(i + 2) }) - max({ p.at(i),p.at(i + 1),p.at(i + 2) }) == p.at(i + 1)) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, M, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

v = 0
for i in range(N):
    if v + A[i] <= K:
        v += A[i]
    else:
        mi = i-1
        break
else:
    mi = N-1

ans = mi+1

for j in range(M):
    while mi > -1 and v + B[j] > K:
        v -= A[mi]
        mi -= 1
    v += B[j]
    if v <= K:
        ans = max(ans, mi+1+ j+1)

print(ans)


Measured memory_bytes: 42172
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	int f=s[0]==s[n-1];
	if(f){
		if(n&1){
			cout<<"Second"<<endl;
		}else{
			cout<<"First"<<endl;

		}
	}else{
		if(n&1){
			cout<<"First"<<endl;
		}else{
			cout<<"Second"<<endl;

		}
	}
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int s[n];
  REP(i, n) cin >> s[i];
  int q;
  cin >> q;
  int ans = 0;
  REP(i, q) {
    int t;
    cin >> t;
    int ng = -1, ok = n;
    while (1 < abs(ok - ng)) {
      int mid = (ok + ng) / 2;
      if (t <= s[mid]) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    if (s[ok] == t) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int n,m,c=0,chec=0;
char pn[100][100],pm[100][100];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",pn[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%s",pm[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(pn[i][j] == pm[0][0]){
				c = 0;
				for(int k=0;k<m;k++){
					for(int l=0;l<m;l++){
						if(pn[i+k][j+l] != pm[k][l]){
							c = 1;
						}
					}
				}
				if(c == 0){
					chec = 1;
				}
			}
		}
	}
	if(chec == 0){
		printf("No");
	}
	else{
		printf("Yes");
	}
}

Measured memory_bytes: 256