akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    auto dist = [&](int i, int j) {
        return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j])* (y[i] - y[j]));
    };
    vi id(n);
    rep(i, n) id[i] = i;
    double ans = 0;
    int cnt = 0;
    do {
        rep(i, n-1) ans += dist(id[i], id[i+1]);
        ++cnt;
    }while(next_permutation(all(id)));
    cout << fixed << setprecision(15) << ans / cnt << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
	let n : usize = sc.read();
        println!("{}", n.to_string().chars().fold(0, |acc, x| acc + if x.to_digit(10).unwrap() == 2 { 1 } else { 0 }));
	
}



Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>
#include<string.h>
int max(int a,int b){
   if(a>b) return a;
   return b;
}
int min(int a,int b){
   if(a<b) return a;
   return b;
}
void sort(char *a,int l){
    for(int i=0;i<l;i++){
       for(int j=i+1;j<l;j++){
          char t;
         if(a[i]>a[j]) {
            t=a[i];
            a[i]=a[j];
            a[j]=t;
         }

       }
    }


}

int main(){
    char a[100],b[1000];
    scanf("%s",a);
    int l=strlen(a),cnt=0;
    if(a[0]!='A') {
       printf("WA");
       return 0;
    }
    for(int i=1;i<l;++i){
       if(a[i]<'a') {
          if(i==1|| i==l-1 || a[i]!='C'){
             printf("WA"); return 0;
          }
          ++cnt;
       }
    }
   if(cnt==1) printf("AC");
   else printf("WA");
}
   
   
   
   
   
   

Measured memory_bytes: 128
/**
 *      ABC 86 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-02 23:26:24
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    vector<int> t, x, y;
    for (int i = 0; i < N; ++i) {
        int tt, xx, yy; cin >> tt >> xx >> yy;
        t.push_back(tt); x.push_back(xx); y.push_back(yy);
    }

    for (int i = 0; i < N; ++i) {
        if (t[i] % 2 == 0){
            if (abs(x[i]) + abs(y[i]) > t[i] || (abs(x[i]) + abs(y[i])) % 2 == 1){
                cout << "No" << endl;
                return 0;
            }
        }
        else if (t[i] % 2 == 1){
            if (abs(x[i]) + abs(y[i]) > t[i] || (abs(x[i]) + abs(y[i])) % 2 == 0){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 1644
# coding: utf-8
# Your code here!
N=int(input())
s=list(input())
s=list(map(lambda x:0 if x=="o" else 1,s))

#print(s)

ans=[0]*N
ans[0]=1
ans[1]=1
#sheep=0 wolf=1

for _ in range(2):
    ans[0]^=1
    for __ in range(2):
        ans[1]^=1
        for i in range(2,N):
            ans[i]=-1
        for i in range(2,N):
            ans[i]=ans[i-1]^s[i-1]^ans[i-2]
        if s[0]^ans[0]==ans[1]^ans[-1] and s[-1]^ans[-1]==ans[0]^ans[-2]:
            #print(ans)
            ans=list(map(lambda x:"S" if x==0 else "W", ans))
            print("".join(ans))
            exit()

print(-1)

Measured memory_bytes: 5528
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

const int Maxn = 500;

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

bool v[Maxn][Maxn];
string f[Maxn];

int h, w;

ll bfs(int i, int j) {
    ll cb = 1, cw = 0;
    queue<P> que;

    v[i][j] = true;
    que.push(P(i, j));
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int k = 0; k < 4; ++k) {
            int nx = p.first + dx[k], ny = p.second + dy[k];
            if (0 <= nx && nx < h && 0 <= ny && ny < w) {
                if (!v[nx][ny] && f[p.first][p.second] != f[nx][ny]) {
                    que.push(P(nx, ny));
                    v[nx][ny] = true;
                    if (f[nx][ny] == '.') ++cw;
                    else ++cb;
                }
            }
        }
    }

    return cb * cw;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        cin >> f[i];
    }


    ll ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (f[i][j] == '#') ans += bfs(i, j);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            final long N  = sc.nextLong();
            final long A  = sc.nextLong();
            final long B  = sc.nextLong();

            long kurikaesi = N / (A+B);
            long amari = N % (A+B);

            long tsuika = 0;
            if (amari > A) {
                tsuika = A;
            } else {
                tsuika = amari;
            }

            System.out.println(kurikaesi * A + tsuika);
        } finally {
            sc.close();
        }
    }
}


Measured memory_bytes: 23636
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M);
  ll before = -1;
  for (ll i = 0; i < M; i++) {
    ll a;
    cin >> a;
    if (a == before + 1) {
      cout << 0 << endl;
      return 0;
    }
    A[i] = a;
  }
  if (!A.empty())
    reverse(begin(A), end(A));

  vector<ll> dp(N + 1);
  constexpr ll mod = 1000000007;
  dp[0] = 1;
  for (ll i = 0; i < N; i++) {
    if (!A.empty()) {
      if (i == A.back()) {
        A.pop_back();
        continue;
      }
    }
    dp[i + 1] += dp[i];
    dp[i + 1] %= mod;
    if (i < N - 1) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= mod;
    }
  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = a + b;
if(c <= 9){
System.out.println(c);
}else{
System.out.println("error");
}

}
}

Measured memory_bytes: 23252
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
const ld RATE = 380000.0;
void good(){
  cout << "Heisei" << endl;
}
void bad(){
  cout << "TBD" << endl;
}
/*
  1 : +1
  1 : -1
  10: a+b
x  a    y
80
98 + 2
40 + 30 + 21 - 1

80
98 - 8
*/

ll ans;
vl l;
ll a,b,c;

string next(string s){
  int incrementingRad = s.length()-1;
  while(incrementingRad > -1){
    if(s[incrementingRad] == '3') {incrementingRad--;continue;}
    break;
  }
  if(incrementingRad == -1) return "end";
  s[incrementingRad] = s[incrementingRad]+1;
  FOR(i,incrementingRad+1,s.length()) s[i] = '0';
  return s;
}

void nextStep(){
  // ll debugA, debugB, debugC;
  ll minCost = INF;
  string it = "";
  F0R(i,sz(l)) it = it + (string)"0";
  while(it != "end"){
    ll sum1 = 0;
    ll sum2 = 0;
    ll sum3 = 0;
    ll art1 = 0;
    ll art2 = 0;
    ll art3 = 0;
    ll cost = 0;
    F0R(i,it.length()){
      if(it[i] == '1'){
        sum1 += l[i];
        if(art1 != 0) cost += 10;
        art1++;
      }
      if(it[i] == '2'){
        sum2 += l[i];
        if(art2 != 0) cost += 10;
        art2++;
      }
      if(it[i] == '3'){
        sum3 += l[i];
        if(art3 != 0) cost += 10;
        art3++;
      }
    }
    cost += abs(a - sum1) + abs(b - sum2) +  abs(c - sum3);
    if(cost < minCost && art1*art2*art3 > 0) {
      minCost = cost;
      // debugA = abs(a - sum1);
      // debugB = abs(b - sum2);
      // debugC = abs(c - sum3);
    }
    // if(it == "1112223") {
    //   cout << "FOR A: "<<sum1<<" "<<a<<endl;
    //   cout << "FOR B: "<<sum2<<" "<<b<<endl;
    //   cout << "FOR C: "<<sum3<<" "<<c<<endl;
    //   cout << "cost : "<< cost << endl;
    // }
    it = next(it);
  }

  ans = minCost;
  // cout << "FOR A: "<<debugA<<endl;
  // cout << "FOR B: "<<debugB<<endl;
  // cout << "FOR C: "<<debugC<<endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n >> a >>b >> c;
    ll t;
    F0R(i,n) {cin >> t; l.pb(t);}
    nextStep();
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#ABC132B - Ordinary Number
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,n-1,1):
    if min(p[i-1],p[i],p[i+1]) < p[i] < max(p[i-1],p[i],p[i+1]):
        count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
int n;
cin>>n;
int r,sum=0,c=0;
int temp=n;
while(temp!=0)
{
	r=temp%10;
	if(r==9)
{
	c=1;
	break;
}
	
	temp=temp/10;
}

if(c==1)
cout<<"Yes";
else 
cout<<"No";


return 0;  
}

Measured memory_bytes: 3532
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <algorithm>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明


// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }


// ll my_gcd(ll a, ll b){
// 	return (b==0) ? a : my_gcd(b, a%b);
// }


//  ll my_lcm(ll a, ll b){
//  	return a*b / my_gcd(a,b);
//  }


// ll factorial(ll a){
// 	ll ans = 1;
// 	for(ll i=a; i>0; i--){
// 		ans *= i;
// 	}
// 	return ans;
// }

int main(int argc, char *argv[]){
    int n; cin >> n;
    int v[n];
    for(int i=0; i<n; i++){
        cin >> v[i];
    }

    int countv_evn[100000] = {};
    int countv_odd[100000] = {};

    for(int i=0; i<n; i++){
        if(i%2 == 0){
            countv_evn[v[i]]++;
        } else {
            countv_odd[v[i]]++;
        }
    }

    int countv_evn_max1 = 0;
    int countv_evn_max1_ptr = 0;
    int countv_odd_max1 = 0;
    int countv_odd_max1_ptr = 0;

    int countv_evn_max2 = 0;
    int countv_evn_max2_ptr = 0;
    int countv_odd_max2 = 0;
    int countv_odd_max2_ptr = 0;

    for(int i=0; i<100000; i++){
        int i_tmp = i;
        if(countv_evn[i] > countv_evn_max1){
            swap(countv_evn_max1, countv_evn[i]);
            swap(countv_evn_max1_ptr, i_tmp);
        }
        if(countv_evn[i] > countv_evn_max2){
            swap(countv_evn_max2, countv_evn[i]);
            swap(countv_evn_max2_ptr, i_tmp);
        }

        i_tmp = i;
        if(countv_odd[i] > countv_odd_max1){
            swap(countv_odd_max1, countv_odd[i]);
            swap(countv_odd_max1_ptr, i_tmp);
        }
        if(countv_odd[i] > countv_odd_max2){
            swap(countv_odd_max2, countv_odd[i]);
            swap(countv_odd_max2_ptr, i_tmp);
        }
    }

    int result;
    result = countv_evn_max1 + countv_odd_max1;

    if(countv_evn_max1_ptr == countv_odd_max1_ptr){
        int x = countv_evn_max1 + countv_odd_max2;
        int y = countv_evn_max2 + countv_odd_max1;
        result = max(x, y);
    }

    cout << n - result << endl;



	return 0;
}


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

int main(){

	int a,b,c;

	cin>>a>>b>>c;
	if(a==7&&b==5&&c==5){
		cout<<"YES"<<endl;
	}else if(a==5&&b==7&&c==5){
		cout<<"YES"<<endl;
	}else if(a==5&&b==5&&c==7){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;


}

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

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    int A[N][M];

    for(int i=0; i<M; i++){
        cin >> B[i];
    }
    for(int k=0; k<N; k++){
        for(int j=0; j<M; j++){
            cin >> A[k][j];
        }
    }
    int ans = 0;
    for(int l=0; l<N; l++){
        int work = C;
        for(int p=0; p<M; p++){
            work += A[l][p]*B[p];
        }//cout << ans; //テスト用
        if(work > 0){
            ans += 1;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
li = list(map(int, input().split()))

dp = [float('inf')] * n

dp[0] = 0

for i in range(n):
  for j in range(1, k + 1):
    if i + j < n:
      dp[i + j] = min(dp[i + j], dp[i] + abs(li[i] - li[i + j]))

print(dp[n-1])

Measured memory_bytes: 55264
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,l,sum=0,cnt=0;
  cin >> n >> l;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=1;i<n;i++){
    if(a[i-1]+a[i]>=l){
      cout << "Possible\n";
      for(int j=1;j<i;j++){
        cout << j << endl;
      }
      for(int j=n-1;j>=i;j--){
        cout << j << endl;
      }
      return 0;
    }
  }
  cout << "Impossible\n";
  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int k;
  char s[102];
  scanf("%d %s", &k, &s);

  if(strlen(s)<=k) printf("%s", s);
  else{
    s[k]='\0';
    printf("%s", s);
    printf("...");
  }
  return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

class Main{


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		String S = sc.next();
		String ans = "abcdefghijklmnopqrstuvrxyz";
		for(int i = 0;i < S.length();i++){

			ans = 	ans.replace(String.valueOf(S.charAt(i)), "");

		}

		if(ans.length()==0){
			System.out.println("None");
		}else{
			System.out.println(ans.charAt(0));
		}
	}

}

Measured memory_bytes: 58268
n = int(input())
apart = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for joho in range(n):
    x = [int(i) for i in input().split()]
    apart[x[0]-1][x[1]-1][x[2]-1] += x[3]

for tou in range(4):
    for stair in range(3):
        for room in range(10):
            print(" ",apart[tou][stair][room],sep="",end="")
        print("")
    if tou != 3:
        print("####################")



Measured memory_bytes: 5636
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toLong)
    val sum = an.sum()
    var count = 0L
    var min = sum
    for (i in 0 until an.lastIndex) {
        count += an[i]
        min = Math.min(min, Math.abs(sum - count * 2))
    }
    println(min)
}

Measured memory_bytes: 81144
#define MAXN (500000+50)

#include<iostream>

using namespace std;

int arr[MAXN];
int exc[MAXN];

int N;
int T(0);

void msort(int l,int r)
{
	int mid((l+r)>>1);
	if(r-l<=1)
		return;
	msort(l,mid);
	msort(mid,r);
	int p1(mid-1),p2(r-1);
	for(int i=r-1;i>=l;--i)
	{//++T;
		if(p1<l)
		{
			exc[i]=arr[p2--];
			continue;
		}
		if(p2<mid)
		{
			exc[i]=arr[p1--];
			continue;
		}
		if(arr[p1]<arr[p2])
			exc[i]=arr[p1--];
		else
			exc[i]=arr[p2--];
	}
	for(int i=l;i<r;++i)
	{
		++T;
		arr[i]=exc[i];
	}
}
int main()
{
	cin>>N;
	for(int i=0;i<N;++i)
		cin>>arr[i];
	msort(0,N);
	for(int i=N-1;i>0;--i)
		cout<<arr[i]<<' ';cout<<arr[0]<<endl;
	cout<<T<<endl;
	return 0;
}

Measured memory_bytes: 6920
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse = True)
res = 0
l = 0
r = 10 ** 12
m = int((l + r) / 2)
c = 0
if sum(a) <= K:
  print(0)
  exit(0)
def check(x):
  k = K + 0
  for i in range(N):
    if a[i] * f[i] > x:
      k -= abs((x - a[i] * f[i]) // f[i])
    if k < 0:
      return False
  return True
while c <= 64:
  m = int((l + r) / 2)
  if check(m) == True:
    r = m
  else:
    l = m
  c += 1
if check(m + 1): print(m + 1)
elif check(max(0, m - 1)): print(m - 1)
else: print(m)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
 long long a,b,c;
  cin >> a >> b >> c;
  
  if(4*a*b<(c-a-b)*(c-a-b)&&c-a-b>=0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

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

int main(){
    int W,H,N;
    cin>>W>>H>>N;
    int W_l = 0,W_r= W ,H_u = H,H_d = 0;
    vector<int> x(N),y(N),a(N);
    for (int i=0;i<N;i++){
        cin>>x.at(i)>>y.at(i)>>a.at(i);
        if (a.at(i)==1&&W_l<x.at(i)){
            W_l = x.at(i);
        }else if (a.at(i)==2&&W_r>x.at(i)){
            W_r = x.at(i);
        }else if (a.at(i)==3&&H_d<y.at(i)){
            H_d = y.at(i);
        }else if (a.at(i)==4&&H_u>y.at(i)){
            H_u = y.at(i);
        }
    }
    if(H_u-H_d<0){
        H_u = H_d;
    }
    if(W_r-W_l<0){
        W_r = W_l;
    }
    cout<<(W_r-W_l)*(H_u-H_d)<<endl;
}


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

using namespace std;

int main() {
  long long n, p;
  cin >> n >> p;
  long long i = 2;
  long long ans = 1;
  while (i * i <= p) {
    int power = 0;
    while (p % i == 0) {
      p /= i;
      power++;
    }
    long long mul = 1;
    for (int j = 0; j < power / n; j++) mul *= i;
    ans *= mul;
    i++;
  }
  if (p > 1) {
    if (n == 1) ans *= p;
  }
  cout << ans;

}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a[ohara],b[ohara],c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,t;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

long long gcd(long long aaa,long long bbb){
    if(bbb==0){
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}
 
long long lcm(long long aaa,long long bbb){
    long long g = gcd(aaa,bbb);
    return aaa/g * bbb;
}

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n>>m;
      cin>>s;
      cin>>t;
      if(n==1||m==1){
       if(s[0]==t[0])Cout(max(n,m));
       else Cout(-1);
       return 0;
      }
      pos=lcm(n,m);
      ll cntt=1;
      cnt=1;
      a[0]=1;
      b[0]=1;
      ll kake=1;
      while(1){
        a[cnt++]=kake*pos/n+1;
        kake++;
        if(kake==n)break;
      }
      kake=1;
      while(1){
        b[cntt++]=kake*pos/m+1;
        kake++;
        if(kake==m)break;
      }
      map<ll,ll> mp;
      map<ll,ll> mpp;
      rep(i,cnt)mp[a[i]]=i,mpp[a[i]]++;
      rep(i,cntt){
        //Cout(b[i]);
        if(mpp[b[i]]>0){
          if(s[mp[b[i]]]!=t[i]){
            Cout(-1);
            return 0;
          }
        }
      }
      Cout(pos);
    
       
return 0;
}


Measured memory_bytes: 20352
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int col[214];
vector<int> es[214];

int Dfs(int v, int c) {
  col[v] = c;
  for (int u : es[v]) {
    if (col[u]) {
      //cout << "u: " << col[u] << endl;
      //cout << "v: " << col[v] << endl;
      if (col[u]+col[v] != 3) return -1;
      continue;
    }
    if (Dfs(u, 3-c) == -1) return -1;
  }
  return 0;
}

int Try(int st) {
  queue<int> que;
  vector<int> grp(N);
  grp[st] = 1;
  que.push(st);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int u : es[v]) {
      if (grp[u]) {
        assert(abs(grp[v]-grp[u]) == 1);
        continue;
      }
      grp[u] = grp[v]+1;
      que.push(u);
    }
  }
  int ret = 0;
  rep(i, N) {
    assert(grp[i] > 0);
    MX(ret, grp[i]);
  }
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N;
  rep(i, N) {
    string S;
    cin >> S;
    assert(S.size() == N);
    rep(j, N) {
      if (S[j] == '1') es[i].eb(j);
    }
  }

  if (Dfs(0, 1) == -1) {
    //rep(i, N) cout << "col[" << i<<"]: " << col[i] << endl;
    cout << "-1" << endl;
    return 0;
  }

  int ans = 0;
  rep(i, N) {
    MX(ans, Try(i));
  }
  assert(ans > 0);
  cout << ans << endl;
}


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

using namespace std;

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

    if(s == "SUN") cout << "7\n";
    if(s == "MON") cout << "6\n";
    if(s == "TUE") cout << "5\n";
    if(s == "WED") cout << "4\n";
    if(s == "THU") cout << "3\n";
    if(s == "FRI") cout << "2\n";
    if(s == "SAT") cout << "1\n";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int main(){
	char number[1000];
	while(1){
		scanf("%s", number);
		if(number[0] == '0') break;
		int sum = 0;
		for(int i = 0; i < strlen(number); i++){
			sum += (number[i]-'0');
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 964
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  ll x,y; cin >> x >> y;
  int ans = 0;
  while(x <= y){
    x *= 2;
    ans++;
  }
  
  cout << ans << endl;
  return 0;
}

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


def solve(A: int, B: int):
    sum = A + B
    sub = A - B
    mul = A * B

    max = sum if sum > sub else sub
    max = max if max > mul else mul

    print(max)
    return 


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)

        return divisors
        
    div_n = make_divisors(N)
    ans = 0
    for num in div_n:
        if num == 1:
            continue
        else:
            _N = N
            while _N%num == 0:
                _N //= num
            if _N%num == 1:
                ans += 1
    
    div_n = make_divisors(N-1)
    for num in div_n:
        if num == 1:
            continue
        else:
            _N = N
            while _N%num == 0:
                _N //= num
            if _N%num == 1:
                ans += 1
                
    print(ans)
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 39024
#include <iostream>

using namespace std;

int main(){
    int x = 0;
    int a, b, c;
    cin >> a >> b >> c;
    int y = a;
    int count = 0;
    while(true){
        if(count >= (b - a + 1)){
            break;
        }
        else{
            if((c % y) == 0){
                x = x + 1;
            }
            y = y + 1;
        }
        count = count + 1;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3096
r, c = map(int, input().split())
d = [list(input()) for i in range(r)]
bom = [(x,y) for (x,i) in enumerate(d) for (y,j) in enumerate(i) if j == '#']
temp = []
for b in bom:
    temp += [(b[0]+x, b[1]+y) for y in [1,0,-1] for x in [1,0,-1]]
print('\n'.join([''.join([str(temp.count((i,j))) if d[i][j] != '#' else '#' for j in range(c)]) for i in range(r)]))

Measured memory_bytes: 4724
#include<stdio.h>
int main() {
	int n,c[510],s[510],f[510];
	scanf("%d",&n);
	for(int i=1; i<n; i++) {
		scanf("%d%d%d",&c[i],&s[i],&f[i]);
	}
	for(int i=1; i<n; i++) {
		int t=c[i]+s[i];
		for(int j=i+1; j<n; j++) {
			if(t%f[j]==0 && t<s[j]) {
				t=s[j];
			}else{
				while(t%f[j]!=0 || t<s[j]){
					t++;
				}
			}
			t+=c[j];
		}
		printf("%d\n",t);
	}
	printf("0\n");
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int a[200005],b1[200005];
        for(int i = 0;i<n;i++)
        {
            scanf("%lld",&a[i]);
            b1[i]=a[i]-(i+1);
        }
        sort(b1,b1+n);
        long long int sum=0;
        for(int i=0;i<n/2;i++)
        {
            sum=sum+abs(b1[i]-b1[n-1-i]);
        }
        printf("%lld\n",sum);
    }
    return 0;
}


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

int main() {
  int n; cin>>n;
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<a[n-1]<<endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b,c,d,e,f;
    cin>>a>>b>>c;
    d=a+b;
    e=b+c;
    f=a+c;
    if((d<e) && (d<f)) cout<<d<<endl;
    else if((e<f) && (e<d)) cout<<e<<endl;
    else cout<<f<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int bsearch(int a[], int x, int n)
{
    int lb, ub;
    int m;

    lb = -1;
    ub = n;

    while (ub - lb > 1) {
        m = (ub + lb) / 2;
        if (a[m] >= x) ub = m;
        else lb = m;
    }

    return a[ub] == x;
}

int main() 
{
    int n, q;
    int s[1<<17];
    int i;
    int cnt, tmp;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", s+i);
    scanf("%d", &q);
    cnt = 0;
    for (i = 0; i < q; i++) 
        if (bsearch(s, (scanf("%d", &tmp), tmp), n)) cnt++;
    printf("%d\n", cnt);

    return 0;
}



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vector<vpii > G;
vb visited;
void bfs(int node,vl &distK){
  queue<int> que;
  que.push(node);
  while(!que.empty()){
    int vert = que.front();
    visited[vert]=true;
    que.pop();
    for(auto next:G[vert]){
      int nv = next.first;
      int cost = next.second;
      if(visited[nv])continue;
      distK[nv] = distK[vert]+cost;
      que.push(nv);
    }
  }
}
signed main()
{   
  gearup;
  int n;cin>>n;
  G.resize(n);
  visited.resize(n);
  rep(i,n-1){
    int a,b,c; cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  int q,k; cin >> q >> k;
  k--;
  vl distK(n); // Kまでの距離
  bfs(k,distK);
  rep(i,q){
    int x,y; cin >> x >> y;
    x--;y--;
    out(distK[x]+distK[y]);
  }
}

Measured memory_bytes: 8820
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/













int A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B;

	int ans = max({ A + B, A - B, A * B });

	cout << ans << endl;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
int n,a,b;
int main(){
    scanf("%d",&n);
    if(n==1){
        printf("Hello World\n");return 0;
    }
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
    return 0;
}

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


int main() {
    int A, B; cin >> A >> B;
    int ans = 0;
    for (int i = 0; i < 2; i++) {
        if (A >= B) {
            ans += A;
            A--;
        } else {
            ans += B;
            B--;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
lopFlg = True
ansLst = 0
ans = 0
for i in range(1, N + 1):
    tmp = i * 2
    cnt = 1
    while True:
        if i >= K:
            ans += 1
            break
        if K > tmp:
            tmp = tmp * 2
            cnt += 1
        else:
            ans += float(1 / (2 ** cnt))
            break

ans = 1 / N * ans
print(ans)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint x;
  cin >> x;

  cout << (x/500)*1000 + ((x%500)/5)*5 << "\n";
  return 0;
}


Measured memory_bytes: 256
S = input()

List = []
for i in range(len(S)-2):
    a = int(S[i])
    b = int(S[i+1])
    c = int(S[i+2])
    List.append(a*100+b*10+c)

ans = List[0]
for j in range(len(List)):
    if abs(ans-753) > abs(List[j]-753):
        ans = List[j]

print(abs(ans-753))

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
# def LIST(): return list(map(str, input().split()))
# def LIST(): return list(input())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
h = LIST()

dp = [INF] * N
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i + j < N:
            dp[i+j] = min(dp[i] + abs(h[i] - h[i+j]), dp[i+j])
        # if dp[i] >= dp[i-j] + abs(h[i]-h[i-j]):
        #     dp[i] = dp[i-j] + abs(h[i]-h[i-j])
print(dp[-1])


Measured memory_bytes: 76952
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		for(int i=1; i<=N; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			
			if(a < c && b < c) {
				if(c * c == a * a + b * b) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} else if(a < b && c < b) {
				if(b * b == a * a + c * c) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} else {
				if(a * a == b * b + c * c) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			}
		}
		sc.close();
	}

}

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

typedef long long ll;

int N;
string S;
ll dp[5010][5010];
ll mod = 1000000007;

ll pow_mod(ll a,ll b)
{
    if(b == 0)return 1;
    ll res = pow_mod(a * a % mod,b / 2);
    if(b & 1)res = res * a % mod;
    return res;
}

int main()
{
   scanf("%d",&N);
   cin >> S;

   dp[0][0] = 1;

   for(int i = 0; i <= N; i++)
   {
       for(int j = 0; j <= N; j++)
       {
           dp[i][j] %= mod;
           dp[i + 1][max(j - 1,0)] += dp[i][j];
           dp[i + 1][j + 1] += 2 * dp[i][j];
       }
   }

   ll R = 1;
   for(int i = 0; i < S.size(); i++)R = R * 2 % mod;
   printf("%lld\n",dp[N][S.size()] * pow_mod(R,mod - 2) % mod);
   return 0;
}


Measured memory_bytes: 196096
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;

  if (n >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>


// ヒープソート(昇順) *****************************************************************

int A[200001], B[200001], tmp; // Bでソート(Aは従属) 必要に応じて要素数と型を変える
int length;                    // 要素数:sort()を呼び出す前に設定する


void swap(int i, int j) {
    int tmp;
    tmp  = A[i];
    A[i] = A[j];
    A[j] = tmp;
    tmp  = B[i];
    B[i] = B[j];
    B[j] = tmp;
}

void downheap(int k, int r) {
    int j, v, w;
    v = B[k];
    w = A[k];
    while (1) {
        j = 2 * k + 1;
        if (j > r) break;
        if (j != r) {
            if (B[j + 1] > B[j]) {
                j = j + 1;
            }
        }
        if (v >= B[j]) break;
        B[k] = B[j];
        A[k] = A[j];
        k = j;
    }
    B[k] = v;
    A[k] = w;
}

void sort() {
    int i;
    for (i = (length - 2) / 2; i >= 0; i--) {
        downheap(i, length - 1);
    }
    for (i = length - 1; i > 0; i--) {
        swap(0, i);
        downheap(0, i - 1);
    }
}

// ***************************************************************** ヒープソート(昇順) 


int main() {
  int N, i;
  int tot;
  scanf ("%d", &N);
  for (i=0;i<N;i++) {
    scanf ("%d %d", &A[i], &B[i]);
  }
  
  length = N;
  sort();
  
  tot = 0;
  
  for (i=0;i<N;i++) {
      tot += A[i];
      if (tot>B[i]) {
          printf("No");
          return (0);
      }
  }
  printf("Yes");
  return 0;
}




Measured memory_bytes: 1664
use contest::io::Scanner;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let H = sc.next::<i32>();
    let W = sc.next::<i32>();
    let h = sc.next::<i32>();
    let w = sc.next::<i32>();
    println!("{}", (H - h) * (W - w));
}
pub mod contest {
    pub mod io {
        /// Scanner
        ///
        /// # Example
        /// ```
        /// use contest::io::Scanner;
        /// let mut sc = Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
        /// assert_eq!("1".to_string(), sc.next::<String>());
        /// assert_eq!(2, sc.next());
        /// assert_eq!(3.5, sc.next());
        ///
        /// // To create a scanner from stdin:
        /// Scanner::new(std::io::stdin());
        /// ```
        use std;
        use std::io;
        use std::io::BufRead;

        pub struct Scanner<R: io::Read> {
            br: io::BufReader<R>,
            // Read tokens are stored in reversed order per line.
            buf: Vec<String>,
        }

        pub fn new<R: io::Read>(r: R) -> Scanner<R> {
            Scanner::new(r)
        }

        impl<R: io::Read> Scanner<R> {
            #[inline]
            pub fn new(r: R) -> Scanner<R> {
                Scanner {
                    br: io::BufReader::new(r),
                    buf: vec![],
                }
            }
            #[inline]
            pub fn next<T>(&mut self) -> T
            where
                T: std::str::FromStr,
                T::Err: std::fmt::Debug,
            {
                self.next_string()
                    .map(|s| s.parse::<T>().expect("Parse failed: "))
                    .expect("Unexpected EOF")
            }
            #[inline]
            pub fn next2<T1, T2>(&mut self) -> (T1, T2)
            where
                T1: std::str::FromStr,
                T2: std::str::FromStr,
                T1::Err: std::fmt::Debug,
                T2::Err: std::fmt::Debug,
            {
                (self.next(), self.next())
            }
            fn next_string(&mut self) -> Option<String> {
                self.buf.pop().or_else(|| match self.update() {
                    true => self.next_string(),
                    false => None,
                })
            }
            #[inline]
            fn update(&mut self) -> bool {
                let mut s = String::new();
                let res = self.br.read_line(&mut s);
                match res.expect("I/O error.") {
                    0 => false,
                    _ => {
                        self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                        true
                    }
                }
            }
        }

        #[test]
        fn test_next() {
            let mut sc = new("hoge".as_bytes());
            let s: String = sc.next();
            assert_eq!("hoge", s);
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    int n; cin >> n;
    int w;
    ll ans = 0;
    w = n / 3;

    for(int i = 1; i <= w; ++i){
        int m = n - 3 * i;
        ans += COM(m+i-1,i-1);
        ans %= MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 15596
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];


void merge(struct Card A[] , int n , int left , int mid , int right)
{
	int n1 = mid - left;
	int n2 = right -mid;
	for( int i = 0; i < n1; i++) L[i] = A[left+i];
	for( int i = 0; i < n2; i++) R[i] = A[mid+i];
	L[n1].value = R[n2].value = SENTINEL;
	int i = 0 , j = 0;
	for( int k = left; k < right; k++)
	{
		if(L[i].value <= R[j].value)
		{
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(struct Card A[] , int n , int left , int right)
{
	if(left + 1 < right)
	{
		int mid = (left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}


int partition(struct Card A[] , int n , int p , int r)
{
	struct Card x = A[r];
	struct Card t;
	int i = p-1;
	int j;
	for( j = p; j < r; j++)
	{
		if(A[j].value <= x.value)
		{
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	t = A[i+1];
	A[i+1] = A[r];
	A[r] = t;
	return i+1;
}

void quickSort(struct Card A[], int n , int p , int r)
{
	int q;
	if(p < r){
		q = partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(void)
{
	int n , i , v;
	struct Card A[MAX] , B[MAX];
	char S[10];
	int stable = 1;
	scanf("%d",&n);
	for( i = 0; i < n; i++)
	{
		scanf("%s %d",S,&v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for( i = 0; i < n; i++)
	{
		if(A[i].suit != B[i].suit) stable = 0;
	}
	
	if(stable == 1) printf("Stable\n");
	else printf("Not stable\n");
	for( i = 0; i < n; i++)
	{
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}


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

const int N = 300030;
int n , num[N] , type[N];
int tot , val[N] , pre[N] , suf[N];

inline int read() {
    int x = 0 ; char c = getchar(); bool f = 0;
    while(c < '0' || c > '9') f |= (c=='-') , c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + (c^48) , c = getchar();
    return f ? -x : x;
}

int main() {
    n = read();
    for(int i = 1 ; i <= n ; ++i) {
        num[i] = read();
        type[i] = (num[i] == i);
    }
    for(int i = 2 ; i < n ; ++i)
        if(type[i - 1] + type[i] + type[i + 1] == 0) return puts("No") & 0;
    
    for(int i = 1 , j; i <= n ; i = j + 1) {
        for(j = i ; j < n && type[j] != type[j + 1] ; ++j) {}
        tot = 0;
        for(int k = i ; k <= j ; ++k) {
            if(num[k] < i || num[k] > j) return puts("No") & 0;
            if(type[k] == 0) {
                val[++tot] = num[k];
                pre[tot] = suf[tot] = num[k];
            }
        }
        if(tot < 3) continue;
        for(int k = 2 ; k <= tot ; ++k) pre[k] = max(pre[k] , pre[k - 1]);
        for(int k = tot - 1 ; k ; --k) suf[k] = min(suf[k] , suf[k + 1]);
        for(int k = 2 ; k < tot ; ++k)
            if(val[k] < pre[k] && val[k] > suf[k]) return puts("No") & 0;
    }
    return puts("Yes") & 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    ll k,m = 0;
    cin >> k;
    for (int i = 0;i < k*2;++i) {
        m = (m*10+7)%k;
        if (m == 0) {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    vector<ll> s(n);
    rep(i,n) cin>>s[i];
    ll q; cin>>q;
    vector<ll> t(q);
    rep(i,q) cin>>t[i];
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    ll res=0;
    rep(i,q){
        auto Iter1=upper_bound(s.begin(),s.end(),t[i]);
        auto Iter2=upper_bound(s.begin(),s.end(),t[i]-1);
        if(Iter1-Iter2>0) res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3736