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

int main() {
  int n,k,c,p,sum=0;
  bool tf=false;
  cin>>n>>k>>c;
  char a[n];
  bool b[n],d[n];
  for(int i=0;i<n;i++){
    char t;
    cin>>t;
    a[i]=t;
    if(t=='o')sum++;
    b[i]=false;
    d[i]=false;
  }
  p=k;
  for(int i=0;i<n;i++){
    if(a[i]=='o'){
      b[i]=true;
      i+=c;
      p--;
    }
  }
  if(sum==k){
    for(int i=0;i<n;i++){
      if(b[i])cout<<i+1<<endl;
    }
  }
  else if(p<0){
  }
  else{
    for(int i=n-1;i>=0;i--){
      if(a[i]=='o'){
        d[i]=true;
        i-=c;
      }
    }
    for(int i=0;i<n;i++){
      if(b[i]==true&&d[i]==true)cout<<i+1<<endl;
    }
  }
}

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

int main(){
  int n,k; cin >>n >>k;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  cout << (n+k-3)/(k-1) << endl;
  return 0; 
}

Measured memory_bytes: 3716
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//220
	string s;
	cin>>s;
	ll cnt = 0;
	int b=0;
	REP(i,0,s.length()-1) {
		if(s[i]=='W')cnt+=b;
		else b++;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int n){
    vector<vector<int>> v(n, vector<int>(n, 0));
    int y = n/2+1, x = n/2;
    int cnt = 1;
    while(cnt <= n*n){
        v[y][x] = cnt++;
        int yy = (y+1)%n, xx = (x+1)%n;
        if(v[yy][xx]) yy = (yy+1)%n, xx = (xx+n-1)%n;
        y = yy, x = xx;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            printf("%4d", v[i][j]);
        }
        puts("");
    }
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


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

using namespace std;

int main() {
    ll N,K,R,S,P;
    string T;
    cin >> N >> K >> R >> S >>P;
    cin >> T;
    ll score = 0;
    bool canWin[N];
    for(int i = 0; i< N; i++){
        canWin[i] = true;
    }
    for(ll i = 0; i < N; i++){
        char currentHand = T[i];
        if(i < K){

        }else{
            if(T[i - K] == currentHand){
                if(canWin[i - K]){
                    canWin[i] = false;
                    continue;
                }

            }
        }
        switch (currentHand){
            case 'r':
                score += P;
                break;
            case 's':
                score += R;
                break;
            case 'p':
                score += S;
                break;
        }
    }
    cout << score << endl;

}


Measured memory_bytes: 512
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll z[100004]={0};

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
int main()
{
    /*
   #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif */
    fio;

    forin(i,2,1e5)
    {
        ll d=0;
        forin(j,2,sqrt(i))
        {
            if(i%j==0)
            {
                d++;
                break;
            }
        }
        if(d)
        {
            z[i]=0;
        }
        else
        {
            z[i]=1;
        }
    }
    z[100003]=1;
    ll n;
    cin>>n;
    forin(i,n,100003)
    {
        if(z[i])
        {
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int n;cin>>n;
    int ans=0;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    int c=n;
    map<int,int>memo;
  	memo.clear();
    for(int i=2;i<=sqrt(n);i++){
        while(c%i==0){
            c/=i;
            memo[i]++;
        }
    }
    if(c!=1)memo[c]++;
    for(auto v:memo){
      	int sum=0;
        for(int i=1;sum+i<=v.second;i++){
          ans++;	
          sum+=i;
        }
    }
    cout<<ans<<endl;
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  map<string,int> m;

  rep(i, n) {
    string s; cin >> s;
    ++m[s];
  }

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;

}


Measured memory_bytes: 3668
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
/****************************/
int n,k;
int h[100010];
int dp[100010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n)
	{
		cin>>h[i];
	}
	memset(dp,1000010,sizeof(dp));
	dp[0]=0;
	rep3(i,1,k)
	{
		rep(j,i)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	rep3(i,k,n)
	{
		rep3(j,i-k,i)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
s=input()
t=input()

ds={}
dt={}
cnts=0
cntt=0
for si,ti in zip(s,t):
    if si not in ds:
        ds[si]=cnts
        cnts+=1
    sn=ds[si]
    if ti not in dt:
        dt[ti]=cntt
        cntt+=1
    tn=dt[ti]
    if sn!=tn:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
int A,B,C,D,L,R;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    L=A+B;
    R=C+D;
    if(L>R)
    {
        printf("Left");
    }
    if(L==R)
    {
        printf("Balanced");
    }
    if(L<R)
    {
        printf("Right");
    }
    return 0;
}

Measured memory_bytes: 1736
N = int(input())
S = input()

w_left = 0
e_right = S[1:].count("E")
ans = float('inf')
for i in range(N):
    if i != 0:
        if S[i] == "E":
            e_right -= 1
        if S[i-1] == "W":
            w_left += 1
    ans = min(ans, w_left + e_right)
print(ans)


Measured memory_bytes: 3700
h, w = map(int, input().split())
masu = [[0]*w for _ in range(h)]

for i in range(h):
    masu[i] = list(input())

for i in range(h):
    for j in range(w):
        if masu[i][j] == ".":
            count = 0
            for dx in range(-1, 2):
                for dy in range(-1, 2):
                    xx = j + dx
                    yy = i + dy
                    if 0 <= xx and xx < w and 0 <= yy and yy < h:
                        if masu[yy][xx] == "#":
                            count += 1
            masu[i][j] = count
for i in range(h):
    print("".join(map(str, masu[i])))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
//careful not to convert INF to int type.
typedef pair<int, int> P;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a-1;i>=b;i--)
#define rep0(i,n) for(int i=0;i<n;i++)
#define per0(i,n) for(int i=n+1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
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; }
 

void solve() {
    int n; cin >> n;
    ld p[n+1];
    p[0] = 0.0;
    rep(i,1,n+1){
        cin >> p[i];
    }
    ld dp[n+1][n+1];
    rep(i,0,n+1){
        rep(j,0,n+1){
            dp[i][j] = 0.0;
        }
    }
    dp[0][0] = 1.0;

    
    rep(i,0,n){
        dp[i+1][0] = (1-p[i+1]) * dp[i][0];
        rep(j,0,n){
                dp[i+1][j+1] = (1 - p[i+1]) * dp[i][j+1] + p[i+1] * dp[i][j];
        }
    }
    //rep(i,0,n+1){
        //rep(j,0,n+1){
            //cout << dp[i][j] << " ";
        //}
        //cout << "\n";
    //}
    ld ans;
    rep(i,(n>>1)+(n&1),n+1){
        ans += dp[n][i];
    }
    cout.precision(10);
    cout << ans;
    //cout << dp[n][(n>>1)+(n&1)];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

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

int main(){
  
  int a,b;
  cin >> a >> b;
 
  if( a-b == 0 ){
    
  cout << "Yes" << endl;
  
}
  
  else{
    
  cout << "No" << endl;
    
  }
  
}


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

import copy

from collections import Counter


ans = [0] * n
b = Counter(a)
sm = 0
for i,j in b.items():
    if j >= 2:
        sm += j*(j-1)//2

for i in range(n):
    ans[i] = sm - b[a[i]] + 1
print(*ans)


Measured memory_bytes: 92364
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

int main(){
  string s;
  cin >> s;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A') cnt++;
  }
  if(cnt==0 || cnt==s.size()) cout<< "No" <<endl;
  else cout<< "Yes" <<endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//String S = sc.next();
		//int N = Integer.parseInt(sc.next());
		//out.println();
		// ArrayList<String> list = new ArrayList<String>();
		// list.stream().sorted().distinct();
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		if(N%3==0 || M%3==0 || (N+M)%3 ==0){
			out.println("Possible");
		}else{
			out.println("Impossible");
		}
		out.flush();	
	}
}

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

int main(int argc, const char * argv[]) {
    int x,y;
    
    while(true){
        cin >> x >> y;
        
        if(x==0 && y==0)
            break;
        
        if(x<y){
            cout << x << " " << y << endl;
        }else if(y<=x){
            cout << y << " " << x << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3132
use proconio::input;

fn main() {
    input!(n: usize, l: u64, s: [proconio::marker::Chars; n]);
    let s: Vec<Vec<usize>> = s
        .iter()
        .map(|s| {
            s.iter()
                .map(|c| match c {
                    '0' => 0,
                    '1' => 1,
                    _ => panic!(),
                })
                .collect()
        })
        .collect();
    let mut g = vec![[None, None]];
    let mut ckd = vec![false];
    let mut add = |s: &[usize]| {
        let mut now = 0;
        for &c in s {
            if g[now][c].is_none() {
                g.push([None, None]);
                ckd.push(false);
                g[now][c] = Some(g.len() - 1)
            }
            now = g[now][c].unwrap();
        }
        ckd[now] = true;
    };
    s.iter().for_each(|s| add(s));

    fn dfs(ans: &mut u64, x: usize, h: u64, g: &[[Option<usize>; 2]], ckd: &[bool]) {
        for &option_y in &g[x] {
            if let Some(y) = option_y {
                dfs(ans, y, h - 1, g, ckd);
            } else if h != 0 && !ckd[x] {
                *ans ^= 2u64.pow(h.trailing_zeros());
            }
        }
    }
    let mut ans = 0;
    dfs(&mut ans, 0, l, &g, &ckd);
    println!("{}", if ans == 0 { "Bob" } else { "Alice" });
}


Measured memory_bytes: 15932
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
  int m,n,i;
  string a,b,c;
  while(1){
    cin >> a;
    if(a=="-") break;
    cin >> m;
    for(i=1;i<=m;i++){
      cin >> n;
      b=a.substr(0,n);
      c=a.erase(0,n);
      a=c+b;
    }
    cout << a << endl;
  }
}

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

int main() {
	
	int N, D, X;
	
	std::cin >> N >> D >> X;
	
	int A[N];
	int choco[110] = {0};
	for (int i = 0; i < N; i++) std::cin >> A[i];
	
	for (int i = 0; i < N; i++) {
	    
	    for (int j = 0; j * A[i] + 1 <= D; j++) {
	        
	        choco[i]++;
	    }
	}
	
	int sum = X;
	for (int i = 0; i < N; i++) {
        sum += choco[i];
	}
	
	std::cout << sum << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
# sumitb2019_d.py
'''
重複考えないとどうなるか
-> 単に nC3 個( N 個から 3 つ選び出す順列と同じ)
というところまで考えたが、結局わからず解説AC
重複を考えるとかなり厳しいので重複がないものに着目する。
（今回であれば 000~999 までのパスワード）
発想の転換が凄い。これ思いつくの天才だろ…。
'''
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    C = [str(i//100), str(i//10%10), str(i%10)]
    f = 0
    for s in S:
        if s == C[f]:
            f += 1
        if f == 3:
           break
    if f == 3:
        cnt += 1
    if cnt ==1000:
        break
print(cnt)


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

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

int main() {
    string s;
    int w;
    cin >> s >> w;
    int len = s.length();
    int i = 0;
    while (i <= len - 1){
        cout << s[i];
        i += w;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int N;
int f[10009];

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

    for (int x = 1; x <= 150; x++) {
        for (int y = 1; y <= 150; y++) {
            for (int z = 1; z <= 150; z++) {
                int n = x*x + y*y + z*z + x*y + y*z + z*x;
                if (n <= N) f[n]++;
            }
        }
    }

    for (int i = 1; i <= N; i++) PRINT(f[i]);
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  int count = 0;
  for(int i = 0;i<3;i++){
    if(s.charAt(i) == '1'){count = count +1;}
  }
  System.out.println(count);
}
}


Measured memory_bytes: 22868
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
S = np.array(list(input().rstrip()), dtype='U1')
T = np.array(list(input().rstrip()), dtype='U1')

equal = (S[:,None] == T[None,:])

LS = len(S)
LT = len(T)

dp = [np.zeros(LT+1, dtype=np.int16)]

for i in range(LS):
    prev = dp[-1]
    x = prev.copy()
    np.maximum(x[1:], prev[:-1] + equal[i] * 1, out = x[1:])
    np.maximum.accumulate(x, out = x)
    dp.append(x)

x = LS
y = LT
rev_ans = []

while x >= 1 and y >= 1:
    if equal[x-1][y-1]:
        rev_ans.append(str(S[x-1]))
        x -= 1
        y -= 1
        continue
    n1 = dp[x-1][y]
    n2 = dp[x][y-1]
    if n1 < n2:
        y -= 1
        continue
    x -= 1
    continue

answer = ''.join(rev_ans[::-1])

print(answer)

Measured memory_bytes: 39252
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var N = line[0];
            var M = line[1];

            return M / GetYakusu(M).Where(i => N <= i).Min();
        }

        IEnumerable<int> GetYakusu(int n)
        {
            int amari;
            var sqrt = (int)Math.Sqrt(n);
            for (int i = 1; i <= sqrt; i++)
            {
                var d = Math.DivRem(n, i, out amari);
                if (amari == 0)
                {
                    yield return i;
                    if (i != d)
                        yield return d;
                }
            }
        }

        public const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}

Measured memory_bytes: 13396
k,n = map(int, input().split())
a = list(map(int, input().split()))
max_diff = -float("inf")
ind = 0
for i in range(n):
    if i == n-1:
        x = (k-a[i]) + a[0]
        if x > max_diff:
            max_diff = x
            ind = i
    else:
        x = a[i+1] - a[i]
        if x > max_diff:
            max_diff = x
            ind = i
dist = 0
for i in range(n):
    if i == ind:
        continue
    if i == n-1:
        dist += (k-a[i])+a[0]
    else:
        dist += a[i+1] - a[i]
print(dist)

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

int main() {
  int n;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
    long long k;
    cin>>k;
    a[i]=k;
  }
  sort(a,a+n);
  pair<long long,long long> b[n-1];
  for(int i=0;i<n-1;i++){
    b[i]=make_pair(abs(2*a[i]-a[n-1]),a[i]);
  }
  sort(b,b+n-1);
  cout<<a[n-1]<<' '<<b[0].second<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
// tala
const int N = 1e5 + 10;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	long long n;
	cin >> n;
	long long ans = n + 1;
	for (long long i = 1; i * i <= n; i++)
	{
		if(n % i == 0)
		{
			long long x = n / i;
			ans = min(ans, abs(i - 1) + abs(x - 1));
		}
	}
	cout << ans << "\n";
}

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

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

    map<string, int> str;
    for(int i=0; i<N; i++){
        string s;
        cin>>s;
        str[s]++;
    }


       cout<<"AC x "<<str["AC"]<<endl;
       cout<<"WA x "<<str["WA"]<<endl;
       cout<<"TLE x "<<str["TLE"]<<endl;
       cout<<"RE x "<<str["RE"]<<endl;



}


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

using namespace std;

int main(){
  string a[100];
  int h, w; cin >> h >> w;
  for(int i = 0; i < h; i++){
    cin >> a[i];
  }
  
  for(int i = 0; i < w + 2; i++){
    cout << "#";
  }
  cout << endl;

  for(int i = 0; i < h; i++){
    cout << "#" + a[i] + "#" << endl;
  }
  
  for(int i = 0; i < w + 2; i++){
    cout << "#";
  }
  cout << endl;
  
}

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

int main() {
  string S;
  cin >> S;
  if (S.at(0)==S.at(1) && S.at(2)==S.at(3) && S.at(1)!=S.at(2)) {
    cout << "Yes" << endl;
  }
  else {
    if (S.at(0)==S.at(2) && S.at(1)==S.at(3) && S.at(1)!=S.at(2)) {
      cout << "Yes" << endl;
    }
    else {
      if (S.at(0)==S.at(3) && S.at(1)==S.at(2) && S.at(0)!=S.at(1)) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
  }
}

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

int main() {
  int N = 0;
  int a = 0;
  int b = 0;
  double ans = 0.0000000;
  
  cin >> N;
  
  a = N / 2;
  b = N % 2;
  (double) a, b;
  
  ans = (a + b)/((2.0000000*a) + b);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

int main(){
	int n, m; scanf("%d %d", &n, &m);
	vector<int> d;
	for(int i = 1; i * i <= m; i++){
		if(m % i == 0){ d.push_back(i); d.push_back(m / i); }
	}
	sort(d.begin(), d.end(), greater<int>());
	for(int i = 0; i < d.size(); i++){
		if(m / d[i] >= n){ printf("%d\n", d[i]); break; }
	}
	return 0;
}

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

#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")



#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n;
pii arr[100005];
vi X[100005],Y[100005],adj[100005];

bool vis[100005];
set<int> S;
int dfs(int so)
{
	vis[so]=true;
	for (auto x: X[so])S.insert(x);
	int ret=1;
	for (auto x:adj[so])
	{
		if (vis[x])continue;
		ret+=dfs(x);
	}
	return ret;
}

void solve()
{
	cin>>n;rep(i,0,n)cin>>arr[i].ff>>arr[i].ss,X[arr[i].ff].pb(arr[i].ss),Y[arr[i].ss].pb(arr[i].ff);

	rep(i,0,100005)
	{
		if (Y[i].size()<2)continue;
		int r=Y[i][0];
		rep(j,1,Y[i].size())
		{
			adj[r].pb(Y[i][j]);adj[Y[i][j]].pb(r);
		}
	}

	int ans=0;fill(vis,vis+100005,false);
	rep(i,0,100005)
	{
		if (!vis[i])
		{
			S.clear();int cp=dfs(i);
			ans+=S.size()*cp;
		}
	}
	cout<<ans-n<<"\n";



	


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

    #ifdef local
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    #endif

    clock_t qwertyuiop = clock();
    int t=1;
    ///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


Measured memory_bytes: 17920
import sys, re
import math
import numpy as np
from decimal import Decimal
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

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()))
sys.maxsize = 10 ** 15
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

n,d = MAP()
d *= d
x = 0
y = 0
count = 0

for x in range(0, n):
    x , y = MAP()
    if x * x + y * y <= d:
        count += 1
print(count)

Measured memory_bytes: 27276
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	string s; cin>>s;
	rep(i,0,s.size()-1){
		if(s[i]==s[i+1]){
			printf("%d %d",i+1,i+2);
			return 0;
		}
	}
	rep(i,0,s.size()-2){
		if(s[i]==s[i+2]){
			printf("%d %d",i+1,i+3);
			return 0;
		}
	}
	printf("-1 -1");
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll


void f(int n,int m){
  vector<P> v(n);
  int sum=0;
  rep(i,n){
    int a,b;
    cin>>a>>b;
    v.push_back(P(b,a));
    sum+=a*b;
  }
  sort(all(v));
  reverse(all(v));
  rep(i,n){
    sum-=v[i].F*min(v[i].S,m);
    m-=v[i].S;
    if(m<0) break;
  }

  cout<<sum<<endl;
}





signed main(){
  int n,m;
  while(1){
    cin>>n>>m;
    if(!n) break;
    f(n,m);
  }
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  scanf("%d", &n);
  m = n+1;
  for(int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if(m >= a) {
      m = a;
      ans++;
    }
  }
  printf("%d\n", ans);
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

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

int d[1010][1010];

int main() {
	int h, w; cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];

	queue<pii> que;
	memset(d, -1, sizeof(d));

	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') {
				que.push(mp(i, j));
				d[i][j] = 0;
			}
		}
	}

	while (!que.empty()) {
		pii p = que.front(); que.pop();
		int i = p.fi, j = p.se;
		rep(dir, 4) {
			int ni = i + dx[dir];
			int nj = j + dy[dir];
			if (ni >= 0 && nj >= 0 && ni < h && nj < w && d[ni][nj] == -1) {
				d[ni][nj] = d[i][j] + 1;
				que.push(mp(ni, nj));
			}
		}
	}

	int ans = 0;
	rep(i, h) rep(j, w) ans = max(ans, d[i][j]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13456
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**9 + 10

for i in range(n-k+1):
    left = i
    right = i+k-1
    to_right = abs(x[left]) + abs(x[right]-x[left])
    to_left = abs(x[right]) + abs(x[right]-x[left])
    if min(to_right, to_left) < ans:
        ans = min(to_right, to_left)

print(ans)

Measured memory_bytes: 14224
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>

typedef long long int ll;

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    sort(a.begin(), a.end(), greater<int>());

    ll sum = 0;
    for (int i = 1; i < n; i++) {
        sum += a[i - 1 - (i - 1) / 2];
    }

    cout << sum << endl;

    return 0;
}

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

int main()
{
	int i2, n, k = 0, i, i1, cnt = 0;
	int **p, **f;
	int *sum;

	cin >> n;

	p = new int *[n];
	f = new int *[n];
	sum = new int[n];

	for (i = 0; i < n; i++){
		p[i] = new int[3];
		f[i] = new int[3];
		sum[i] = 0;
	}

	for (i = 0; i < n; i++){
		for (i1 = 0; i1 < 3; i1++){
			f[i][i1] = 0;
		}
	}

	for (i = 0; i < n; i++){
		for (i1 = 0; i1 < 3; i1++){
			cin >> p[i][i1];
		}
	}

	for (i2 = 0; i2 < 3; i2++){
		for (i = 0; i < n - 1; i++){
			for (i1 = i + 1; i1 < n; i1++){
				if (p[i][i2] == p[i1][i2]){
					f[i][i2] = 1;
					f[i1][i2] = 1;
				}
			}
		}
	}

	for (i = 0; i < n; i++){
		for (i1 = 0; i1 < 3; i1++){
			if (f[i][i1] == 1){
				p[i][i1] = 0;
			}
		}
	}

	for (i = 0; i < n; i++){
		for (i1 = 0; i1 < 3; i1++){
			sum[i] += p[i][i1];
		}
	}

	for (i = 0; i < n; i++){
		cout << sum[i] << endl;
	}

	return 0;
}

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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

#define int long long
#define trace(x) cerr << #x << ": " << x << " " << endl;


inline int add(int a, int b){a += b; if(a >= MOD)a -= MOD; return a;}
inline int sub(int a, int b){a -= b; if(a < 0)a += MOD; return a;}
inline int mul(int a, int b){return (int)((int) a * b %MOD);}


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

signed main()
{
    IOS
    int a, b;
    cin >> a >> b;
    cout << ((a*b)/__gcd(a,b));
    
}

Measured memory_bytes: 256
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<vector<int>> A(3,vector<int> (3));
    rep(i,0,3){
        rep(j,0,3){
            cin >> A.at(i).at(j);
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,0,n){
        cin >> b.at(i);
    }
    vector<vector<bool>> a(3,vector<bool>(3));
    rep(k,0,n){
        rep(i,0,3){
            rep(j,0,3){
                if(A.at(i).at(j)==b.at(k)){
                    a.at(i).at(j)=1;
                    //cout << "called" ENDL;
                }
            }
        }
    }
    
    // rep(i,0,3){
    //     rep(j,0,3){
    //         cout << a.at(i).at(j);
    //     }cout ENDL;
    // }

    bool flag=0;
    //横
    rep(i,0,3){
        if(a.at(i).at(0) && a.at(i).at(1) && a.at(i).at(2)) flag=1;
    }
    //縦
    rep(j,0,3){
        if(a.at(0).at(j) && a.at(1).at(j) && a.at(2).at(j)) flag=1;
    }
    //斜め
    if(a.at(0).at(0) && a.at(1).at(1) && a.at(2).at(2)) flag=1;
    if(a.at(0).at(2) && a.at(1).at(1) && a.at(2).at(0)) flag=1;

    if(flag) cout << "Yes" ENDL;
    else cout << "No" ENDL;

    return 0;
}

Measured memory_bytes: 3616
package main

import "fmt"

func main() {
	var s string
	var k int
	fmt.Scan(&s, &k)
	ans := ""
	for i := 0; i < len(s)-1; i++ {
		d := 26 - (s[i] - 'a')
		var c byte
		if s[i] == 'a' {
			c = 'a'
		} else if k >= int(d) {
			k -= int(d)
			c = 'a'
		} else {
			c = s[i]
		}
		ans += string(c)
	}
	if k > 0 {
		k %= 26
		ans += string('a' + (s[len(s)-1]-'a'+byte(k))%26)
	} else {
		ans += string(s[len(s)-1])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int isPrime[111111];

signed main(){
	IOS();
	vector<int>ans;
	while(1){
		int T,P,R;
		cin>>T>>P>>R;
		if(!T&&!P&&!R)break;
		vector<int>t(T,0);
		int solved[T][P]={};
		int wa[T][P]={};
		rep(i,0,R){
			int teamID,problemID,time;
			string message;
			cin>>teamID>>problemID>>time>>message;
			teamID--;
			problemID--;
			if(solved[teamID][problemID]>0)continue;
			if(message=="CORRECT"){
				t[teamID]+=time;
				solved[teamID][problemID] = 1;
			}else{
				wa[teamID][problemID]++;
			}
		}
		vector<pair<pair<int,int>,int>>v(T);
		rep(i,0,T){
			int cnt = 0;
			int wrong = 0;
			rep(j,0,P)if(solved[i][j]){
				cnt++;
				wrong+=wa[i][j];
			}
			v[i].fi.fi=-cnt;
			v[i].fi.se=t[i]+wrong*1200;
			v[i].se=i;
		}
		sort(all(v));
		for(auto e:v){
			cout<<e.se+1<<" "<<-e.fi.fi<<" "<<e.fi.se<<endl;
		}
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 1e16
#define N 100004
int fact[N],ifact[N];

ll fastexpom(ll a,ll b,ll m)
{
  ll res=1;
      while(b>0)
      {
        if(b%2==1)
          res=(((res)%m)*((a)%m))%m;
        a=(((a)%m)*((a)%m))%m;
        b/=2;
      }
      return res;
}
ll modinv(ll a, ll m=1000000007)
{
  return fastexpom(a,m-2,m);
}
void preprocess()
{
    fact[0] = 1;
    ifact[0] = 1;
    for(int i = 1;i < N;i++)
    {
        fact[i] = (fact[i-1] * i)%mod;
        ifact[i] = modinv(fact[i]);
    }
}
int nCr(int n,int r)
{
    if(n == 0 and r == 0)
        return 1;
    if(r > n or r < 0 or n == 0)
        return 0;
    int ans = (fact[n] * ifact[n-r])%mod;
    ans = (ans * ifact[r])%mod;
    return ans;
}
int32_t main()
{
    IOS;
   
    preprocess();
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0;i < n;i++)
        cin >> v[i];
    int cur = 0;
    int ans = 0;
    for(int i = 0;i < n - 1;i++)
    {
        cur = (cur +  (fact[n - 1] * modinv(i + 1))%mod)%mod;
        ans = (ans + (cur * (v[i + 1] - v[i]))%mod)%mod;
    }
    cout << ans;
    return 0;

}
 


Measured memory_bytes: 2560
'''
問題：
    高橋君の夏休みは N 日間です。
    夏休みの宿題が M 個出されており、i 番目の宿題をやるには Ai 日間かかります。

    複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
    夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
    ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。
'''

'''
制約：
    1 ≦ N ≦ 1000000
    1 ≦ M ≦ 10000
    1 ≦ Ai ≦ 10000
'''

# 標準入力からN, M, Ai を取得する
n, m = map(int, input().split())
a = list(map(int, input().split()))

# 宿題にかかる日数を計算する
work_days = 0
for i in range(0, m):
    work_days += a[i]

# 遊べる日を計算して出力する
result = 0
if n >= work_days:
    result = n - work_days
else:
    result = -1

print(result)


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

//Graph in adjcency list
struct Graph{
    struct Edge{
        int from;
        int to;
        ll cost;
        Edge(int a, ll b) : to(a), cost(b) {}
        Edge(int a, int b, ll c) : from(a), to(b), cost(c) {}
    };

    int N;  //頂点数
    vector<vector<Edge>> edges;   //隣接リスト
    vector<int> ans;
    vector<ll> num;
    vector<ll> lis;

    Graph(int n) : N(n), edges(n), ans(n), lis(n, INF), num(n) {
        REP(i, n){
            cin >> num[i];
        }
    }

    void connect(int a, int b, ll c){   //辺を追加
        edges[a].emplace_back(Edge(a, b, c));
    }

    void dfs(int p, int v){    //深さ優先探索
        auto itr = lower_bound(all(lis), num[v]);
        ll b = *itr;
        *itr = num[v];

        ans[v] = distance(lis.begin(), lower_bound(all(lis), INF));

        for(auto e : edges[v]){
            if(e.to == p) continue;
            dfs(v, e.to);
        }
        *itr = b;
    }
};

signed main(){
    int n;
    cin >> n;

    Graph G(n);
    REP(i, n-1){
        int a, b;
        cin >> a >> b;
        G.connect(a-1, b-1, 1);
        G.connect(b-1, a-1, 1);
    }

    G.dfs(-1, 0);

    REP(i, n){
        cout << G.ans[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 35256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    for i in 1.. {
        let x: i32 = read();
        if x == 0 {
            break;
        }
        println!("Case {}: {}", i, x);
    }
}


Measured memory_bytes: 5036
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	ll H;
	int N;
	cin >> H;
	cin >> N;
	ll sum = 0;
	for (int i = 0; i < N; i++)
	{
		ll A;
		cin >> A;
		sum += A;
	}
	if (sum >= H)
		puts("Yes");
	else
		puts("No");
}


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

int n;
long long int a[100000];
long long int r, tmp;
long long int d;

long long int gcd(long long int a, long long int b) {
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

void solve() {
  d = a[0];
  for (int i = 1; i < n; i++) {
    d = gcd(d, a[i]);
    if (d == 1) {
      break;
    }
  }
}
 
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  solve();
  printf("%lld\n", d);
 
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

set<P> st[2], tp[2];

int main() {
    ll n, W;
    ll v[2][25], w[2][25];
    cin >> n >> W;
    ll m[] = {n / 2, n - n / 2};
    REP(i, 2) { REP(j, m[i]) cin >> v[i][j] >> w[i][j]; }
    REP(k, 2) {
        REP(i, (1 << m[k])) {
            ll vt = 0, wt = 0;
            REP(j, m[k]) {
                if (i & (1 << j)) {
                    vt += v[k][j];
                    wt += w[k][j];
                }
            }
            st[k].insert({wt, vt});
        }
    }
    
    REP(k, 2) {
        ll vmax = 0, wmax = 0;
        for (auto itr : st[k]) {
            ll v0 = itr.second, w0 = itr.first;
            if (w0 > W) continue;
            if (w0 > wmax && v0 > vmax) {
                tp[k].insert({wmax, vmax});
                wmax = w0;
            }
            vmax = max(vmax, v0);
        }
        tp[k].insert({wmax,vmax});
        st[k] = tp[k];
    }
    ll ans = 0;
    for (auto itr : st[0]) {
        ll v0 = itr.second, w0 = itr.first, v1, w1;
        if (w0 > W) continue;
        v1 = (*--st[1].upper_bound({W - w0 + 1, -1})).second;
        ans = max(ans, v0 + v1);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 134168