akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int g = sc.nextInt();
        int s = sc.nextInt();
        int b = sc.nextInt();
        int G = sc.nextInt();
        int S = sc.nextInt();
        int B = sc.nextInt();

        int ma=n;
        for (int i = 0; i <= n;  i++) {
        	if(n-i*g<0)break;
			for (int t = 0; t <= n ; t++) {
	        	if(n-i*g-t*s<0)break;
				int r=n-i*g-t*s, x=i*G+t*S;
				r = r%b + r/b * B + x;
				ma=max(ma,r);
			}
		}
        
        long dp[]=new long[ma+1];
        
        for (int i = 0; i < dp.length; i++) {
			if(i-G>=0) {
				dp[i] = max(dp[i],dp[i-G]+g-G);
			}
			if(i-S>=0) {
				dp[i] = max(dp[i],dp[i-S]+s-S);
			}
			if(i-B>=0) {
				dp[i] = max(dp[i],dp[i-B]+b-B);
			}
		}
		
        out.println(ma+dp[ma]);
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}
//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    double c;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    	this.c=(double)b/a;
//    }
//
//    public int compareTo(P p){
//        return Double.compare(p.c,c);
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int H, W, N;
priority_queue<int, vector<int>, greater<int>> pq[220000];

signed main() {
    cin >> W >> H >> N;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        pq[y].push(x);
    }
    for (int i = 1; i <= H; i++)pq[i].push(W + 1);
    for (int i = 1; i <= W; i++)pq[H + 1].push(i);
    int ans = 1e9;
    int cx = 1, cy = 1;
    while (true) {
        ans = min(ans, pq[cy].top() - 1);
        if (pq[cy].top() == cx + 1)break;
        cx++;
        while (pq[cy + 1].top() < cx)pq[cy + 1].pop();
        if (pq[cy + 1].top() != cx)cy++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 16632
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

int main(){
    int a , b, k,count =0;
    cin >> a >> b >> k;

    for(int i=100; i>=1; --i){
        if(a%i == 0 && b%i == 0){
            ++count;
        }
        if(count == k){
            cout << i << endl;
            return 0;
        }
        
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;



ll n,a[100010];
ll depth[100010];
vll I[101010];
ll cost[101010];
bool used[101010];
vector<ll> G[100010],H[100010];
ll cnttrue[100010]={};

void dfs(ll s){
    if(cnttrue[s]!=G[s].size()){
        for(auto i : G[s]){
            dfs(i);
        }
    }
    sort(all(I[s]));
    reverse(all(I[s]));
    rep(i,I[s].size()){
        cost[s]=max(cost[s],i+1+I[s][i]);
    }
    for(auto i:H[s]){
        I[i].push_back(cost[s]);
    }
    return ;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    depth[1]=0;
    cin>>n;
    rep(i,n-1){
        cin>>a[i];
        H[i+2].push_back(a[i]);
        G[a[i]].push_back(i+2);
    }
    ll maxd=0;
    queue<ll> que,q;
    que.push(1);
    while(!que.empty()){
        ll s=que.front();
        que.pop();
        for(auto i :G[s]){
            depth[i]=depth[s]+1;
            maxd=max(depth[i],maxd);
            que.push(i);
        }
    }
    rep2(i,1,n+1){
        depth[i]=maxd-depth[i];
    }
    dfs(1);
    cout<<cost[1]<<endl;
    return 0;
}

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

using namespace std;

int main(){
  int A, B, M;
  cin >> A >> B >> M;
  
  vector<int> priceA(A);
  vector<int> priceB(B);
  int minA=1000000, minB=1000000;

  for(int i = 0; i < A; i++){
    cin >> priceA[i];
    minA = min(minA, priceA[i]);
  }
  
  for(int i = 0; i < B; i++){
    cin >> priceB[i];
    minB = min(minB, priceB[i]);
  }
  
  int minV = 1000000;
  for(int i = 0; i < M; i++){
    int x, y, c;
    cin >> x >> y >> c;
    minV = min(minV, priceA[x-1] + priceB[y-1] - c);
  } 
  minV = min(minV, minA + minB);
  
  cout << minV;
  return 0;
}

Measured memory_bytes: 1152
#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     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll N, A, B;
//---------------------------------------------------------------------------------------------------
ll solve(ll a, ll b) {
	ll d = b - a;
	if (d % 2 == 0) return d / 2;

	ll ans = infl;

	// 最左へ
	chmin(ans, a + solve(1, b - a));

	// 最右へ
	chmin(ans, N - b + 1 + solve(a + (N - b + 1), N));

	return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> A >> B;
	cout << solve(A, B) << endl;
}







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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N, K, ans = 1;
	
	cin >> N >> K;
	
	for(int i=0; i<N; i++){
		if(ans >= K)
			ans += K;
		else
			ans *= 2;
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#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>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k;
ll dp[60][60][3000];

void solve(){
    cin >> n >> k;
    rep(i,n+1){
        rep(j,n+1){
            rep(m,k+1) dp[i][j][m]=0;
        }
    }
    dp[0][0][0]=1;
    rep(i,n){
        rep(j,n+1){
            rep(m,k+1){
                //cout << i << " " << j << " " << m << " " << dp[i][j][m] << endl;
                if (m+2*j<=k) {
                    dp[i+1][j][m+2*j]+=(2*j+1)*dp[i][j][m];
                    dp[i+1][j][m+2*j]%=mod;
                }
                if (j>=1 && m+2*j-2<=k) {
                    dp[i+1][j-1][m+2*j-2]+=j*j*dp[i][j][m];
                    dp[i+1][j-1][m+2*j-2]%=mod;
                }
                if (j+1<=n && m+2*j+2<=k){
                    dp[i+1][j+1][m+2*j+2]+=dp[i][j][m];
                    dp[i+1][j+1][m+2*j+2]%=mod;
                }
            }
        }
    }
    cout << dp[n][0][k] << endl;
}

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

Measured memory_bytes: 71680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int K;
    cin>>K;
    int terms[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<<terms[K-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: u64 = read();
    let m: u64 = read();

    let ps = m.prime_factorization();
    let mut ans = 1;
    let mod_comb = ModCombination::new();

    for &(_, c) in ps.iter() {
        ans = (ans * mod_comb.calc(c + n - 1, n - 1)) % 1_000_000_007;
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

// need IntegerSqrt
trait PrimeFactorization: Sized {
    fn prime_factorization(&self) -> Vec<(Self, Self)>;
}

impl PrimeFactorization for u64 {
    fn prime_factorization(&self) -> Vec<(Self, Self)> {
        let mut n = *self;
        let mut result = vec![];
        for p in 2..self.isqrt() + 2 {
            if n % p != 0 {
                continue;
            }
            let mut count = 0;
            while n % p == 0 {
                n /= p;
                count += 1;
            }
            result.push((p, count));
        }

        if n != 1 {
            result.push((n, 1));
        }

        result
    }
}

// https://en.wikipedia.org/wiki/integer_square_root
trait IntegerSqrt {
    fn isqrt(&self) -> Self;
}

impl IntegerSqrt for u64 {
    fn isqrt(&self) -> Self {
        if *self < 2 {
            *self
        } else {
            let s = (*self >> 2).isqrt() << 1;
            let l = s + 1;
            if l * l > *self {
                s
            } else {
                l
            }
        }
    }
}

struct ModCombination {
    fac: Vec<u64>,
    finv: Vec<u64>,
    modulo: u64,
}

impl ModCombination {
    fn new() -> ModCombination {
        let max = 210_000;
        let modulo = 1_000_000_007u64;
        let mut fac = vec![1; max];
        let mut inv = vec![1; max];
        let mut finv = vec![1; max];
        for i in 2..max {
            fac[i] = fac[i - 1] * i as u64 % modulo;
            inv[i] = modulo - inv[(modulo % i as u64) as usize] * (modulo / i as u64) % modulo;
            finv[i] = finv[i - 1] * inv[i] % modulo;
        }
        ModCombination {
            fac: fac,
            finv: finv,
            modulo: modulo,
        }
    }

    fn calc(&self, n: u64, k: u64) -> u64 {
        if n < k {
            0
        } else {
            self.fac[n as usize]
                * (self.finv[k as usize] * self.finv[(n - k) as usize] % self.modulo)
                % self.modulo
        }
    }
}


Measured memory_bytes: 10492
#include <stdio.h>

typedef struct {
    char name[6];
}STR;

int main(void)
{
    int H, W;
    int i, j, k;
    STR A[26][26] = {0};

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

    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            for (k = 0; k < 6; k++) {
                A[i][j].name[k] = getchar();
            }
        }
    }

    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            if (A[i][j].name[0] == 's' && A[i][j].name[1] == 'n' && A[i][j].name[2] == 'u'
             && A[i][j].name[3] == 'k' && A[i][j].name[4] == 'e') {
                printf("%C%d",'A'+j, i+1);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 5005;

ll sm[MAX_N][MAX_N];

void dfs(vvl& b,int kind,int l,int r)
{
    if(l > r){
        return;
    }
    int mx = 0,pos = 0;
    srep(i,l,r+1){
        if(mx < b[i][kind]){
            mx = b[i][kind];
            pos = i;
        }
    }
    sm[l][pos] += mx,sm[pos+1][pos] -= mx;
    sm[l][r+1] -= mx,sm[pos+1][r+1] += mx;
    dfs(b,kind,l,pos-1);
    dfs(b,kind,pos+1,r);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vl a(n-1);
    vl d(n,0);
    rep(i,n-1){
        cin >> a[i];
        d[i+1] = d[i]+a[i];
    }
    vvl b(n,vl(m));
    rep(i,n){
        rep(j,m){
            cin >> b[i][j];
        }
    }
    rep(i,m){
        dfs(b,i,0,n-1);
    }
    rep(i,n+1){
        rep(j,n){
            sm[i][j+1] += sm[i][j];
        }
    }
    rep(j,n+1){
        rep(i,n){
            sm[i+1][j] += sm[i][j];
        }
    }
    // rep(i,n){
    //     rep(j,n){
    //         cout << sm[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    ll ans = 0;
    rep(i,n){
        srep(j,i,n){
            cmx(ans,sm[i][j]-(d[j]-d[i]));
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 203904
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;


ll N,M;
struct edge{int to, cost;};
vector<edge>G[200010];
bool flag=true;
bool F[200010];
int X[200010];

void DFS(int s){
    F[s]=true;
    rep(i,G[s].size()){
        if(F[G[s][i].to]==true){
            if(X[G[s][i].to]!=X[s]+G[s][i].cost){
                flag = false;
                break;
            }
        }else{
            X[G[s][i].to]=X[s]+G[s][i].cost;
            DFS(G[s][i].to);
        }
    }
}

int main(){
    ll N,M;
    cin >> N >> M;
    int l,r,d;
    rep(i,M){
        cin >> l >> r >> d;
        edge e;
        e.to=r, e.cost=d;
        G[l].emplace_back(e);
        e.to=l, e.cost=-d;
        G[r].emplace_back(e);
    }

    for(int i=1; i<=N; i++){
        if(F[i]==false){
            DFS(i);
        }
        if(flag==false){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){
  ll n,k;
  cin>>n>>k;
  ll c1=0;
  if(k%2==0)
  c1=n/k+((n%k>=(k/2))?1:0);
  ll c2=n/k;
  cout<<c1+c2+3*(c1)*(c1-1)+3*c2*(c2-1)+c1*(c1-1)*(c1-2)+c2*(c2-1)*(c2-2);
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <functional>
using namespace std;
using ll = long long;

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

	int c = 0;
	int cl = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '(') c += 1;
		if (S[i] == ')') c -= 1;
		if (c < 0) {
			c = 0;
			cl += 1;
		}
	}

	c = 0;
	int cr = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '(') c -= 1;
		if (S[i] == ')') c += 1;
		if (c < 0) {
			c = 0;
			cr += 1;
		}
	}

	if (cl != 0) {
		string Sl(cl, '(');
		S = Sl + S;
	}
	if (cr != 0) {
		string Sr(cr, ')');
		S = S + Sr;
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,m;
	
	scanf("%d %d",&n,&m);
	
	int l[m],r[m];
	
	int l_max,r_min;
	
	int i,j;
	for(i = 0; i < m; i++){
		scanf("%d %d",&l[i],&r[i]);
	}
	
	//判断
	
	l_max = l[0];
	for(i = 0; i < m; i++){
		if(l[i] > l_max){
			l_max = l[i];
		}
	}
	
	r_min = r[0];
	for(i = 0; i < m; i++){
		if(r_min > r[i]){
			r_min = r[i];
		}
	}
	
	if(r_min - l_max >= 0){
		printf("%d\n",r_min - l_max + 1);
	}else{
		printf("0\n");
	}
		
	
	return 0;
}
				
			
			
	
	
	
	

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include <iomanip>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (ll)1e9+7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,s[2010],t[2010];
    ll dp[2010][2010];
    cin>>n>>m;
    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];
    rep(i,2010)rep(j,2010) dp[i][j]=1;
    rep2(i,1,n+1){
        rep2(j,1,m+1){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i][j-1]+dp[i-1][j];
            }else{
                dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1];
            }
            dp[i][j]+=MOD;
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[n][m]<<endl;
    return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long answer = 0;

        answer += dfs((long)3, n);
        answer += dfs((long)5, n);
        answer += dfs((long)7, n);

        Console.WriteLine(answer);
    }

    private static long dfs(long num, long n)
    {
        if (num > n)
        {
            return 0;
        }

        long ret = 0;
        string str = num.ToString();
        if (str.Contains('3') && str.Contains('5') && str.Contains('7'))
        {
            ret++;
        }
        ret += dfs(num * 10 + 3, n);
        ret += dfs(num * 10 + 5, n);
        ret += dfs(num * 10 + 7, n);
        return ret;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 28572
import sys
import fractions

n,m = map(int, input().split())
a = list(map(int, input().split()))

def div_count(n):
    count=0
    for i in range(1,100):
        if n%2**i!=0:
            count=i
            break
    return count
    

for i in range(len(a)):
    a[i]//=2

for i in range(1,len(a)):
    if div_count(a[i-1])!=div_count(a[i]):
        print(0)
        sys.exit()

_min=a[0]
for i in range(1, n):
    _min = _min * a[i] // fractions.gcd(_min, a[i])

print(m//_min-(m//_min)//2)

Measured memory_bytes: 16296
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define line cout<<"----------------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll mx=200009;
int main()
{
    int n ;
    cin>>n; 
    map<string,int> m; 
    int maxi=0; 
    for(int i=0;i<n;i++)
    {
        string str; 
        cin>>str; 
        m[str]++; 
        maxi=max(maxi,m[str]);
    }
    for(auto x: m) if(x.second==maxi) cout<<x.first<<endl; 
}


Measured memory_bytes: 19232
import java.io.*;
import java.rmi.MarshalledObject;
import java.util.*;

public class Main {
    static final long MOD = 1000000007;

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long M;
        M = sc.nextLong();
        Set<Long> a = new HashSet<>();
        for(int i = 0 ; i < M ; i++){
            a.add(sc.nextLong());
        }

        final Solver solver = new Solver();
        System.out.println(solver.solve(N, a));
    }
}

class Solver {
    final Map<Long, Long> memo = new HashMap<>();

    public long solve(long N, Set<Long> a) {

        long[] dp = new long[(int) (N + 1)];
        dp[0] = 1;
        for (long now = 0; now < N; now++) {
            for (long next = now + 1; next <= Math.min(now + 2, N); next++) {
                if (!a.contains(next)) {
                    dp[(int) next] += dp[(int) now];
                    dp[(int) next] %= Main.MOD;
                }
            }
        }
        return dp[(int) N];
    }

}



Measured memory_bytes: 63956
import sys

n, a, b = map(int, sys.stdin.readline().split())

def main():
    res = 0
    for i in range(1, n+1):
        s = sum([int(d) for d in str(i)])
        if a <= s <= b:
            res += i
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include<iostream> 
#include <iomanip> 
using namespace std;
  
// A utility function that returns maximum of two integers 
int max(int a, int b) { return (a > b)? a : b; } 
  
// Returns the maximum value that can be put in a knapsack of capacity W 
long knapSack01(int W, int weight[], int val[], int n) 
{ 
   	int k, w; 
   	long **F = new long *[n+1];
   	for(int i=0;i<n+1;i++)
   		F[i]= new long[W+1];
   
   	// Build table K[][] in bottom up manner 
   	for (k = 0; k <= n; k++) 
   	{ 
       	for (w = 0; w <= W; w++) 
       	{ 
			if (k==0 || w==0) 
			   F[k][w] = 0; 
			else if (weight[k-1] <= w) 
			    F[k][w] = max(F[k-1][w], F[k-1][w-weight[k-1]]+val[k-1]);  
			else
			     F[k][w] = F[k-1][w]; 
       	} 
   	} 
   	long result = F[n][W];
   	for(int i=0;i<n+1;i++)
		delete []F[i];
	delete []F;
   	return  result;
} 

int main() 
{ 
	std::ios::sync_with_stdio(false);
	int n, W;
	std::cin>>n>>W;
	//int *val=new int[n];
	//int *wt = new int[n];
	int val[n], wt[n];
	for(int i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
    std::cout<< knapSack01(W, wt, val, n)<<endl; 
    //delete []val;
	//delete []wt;
    return 0; 
}

Measured memory_bytes: 82340
#!/usr/bin/env python3
import collections
def solve(k):
    if k == 1:
        return 1, [ [ 1 ] ]
    n = (k + 3) // 4 * 2
    f = [ [ None ] * n for _ in range(n) ]
    for y in range(n):
        for x in range(n):
            f[y][x] = (y * n + (x - y) % n) % (2 * n) + 1
            if f[y][x] > n:
                if f[y][x] - n <= 2 * n - k:
                    f[y][x] -= n
                else:
                    f[y][x] -= 2 * n - k
    return n, f

if __name__ == '__main__':
    k = int(input())
    n, f = solve(k)
    print(n)
    for y in range(n):
        print(*f[y])


Measured memory_bytes: 12604
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//The Squares
public class Main{

	static class P{
		int i, j, dir;
		public P(int i, int j, int dir) {
			this.i = i;
			this.j = j;
			this.dir = dir;
		}
	}
	
	public static void main(String[] args) {
		int[][] move = {{-1,0},{0,-1},{1,0},{0,1}};
		Scanner sc = new Scanner(System.in);
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h)==0)break;
			char[][] map = new char[h][w];
			List<P> l = new ArrayList<P>();
			for(int i=0;i<h;i++){
				char[] s = sc.next().toCharArray();
				for(int j=0;j<w;j++){
					map[i][j] = s[j];
					if(s[j]!='.'&&s[j]!='#'&&s[j]!='X'){
						map[i][j] = 'P';
						int d = s[j]=='N'?0:s[j]=='W'?1:s[j]=='S'?2:3;
						l.add(new P(i,j,d));
					}
				}
			}
			String ans = "NA";
			int step = 1;
			while(step<=180){
				List<P> next = new ArrayList<P>();
				int[] nd = new int[l.size()];
				for(int i=0;i<l.size();i++){
					P p = l.get(i);
					nd[i] = -1;
					for(int k=3;k<7;k++){
						int ni = p.i+move[(p.dir+k)%4][0];
						int nj = p.j+move[(p.dir+k)%4][1];
						if(map[ni][nj]=='.'||map[ni][nj]=='X'){
							nd[i] = (p.dir+k)%4;
							break;
						}
					}
					if(nd[i]==-1)next.add(p);
				}
				for(int k=1;k<=4;k++){
					int kk = k%4;
					for(int i=0;i<l.size();i++){
						if(nd[i]==kk){
							P p = l.get(i);
							map[p.i][p.j] = '.';
							int ni = p.i+move[kk][0];
							int nj = p.j+move[kk][1];
							if(map[ni][nj]=='X'){
								map[ni][nj]='x';
								continue;
							}
							if(map[ni][nj]=='.'){
								map[ni][nj] = 'P';
								next.add(new P(ni,nj,nd[i]));
							}
							else{
								map[p.i][p.j] = 'P';
								next.add(new P(p.i,p.j,nd[i]));
							}
						}
					}
				}
				l = next;
				if(l.isEmpty()){
					ans = step+"";
					break;
				}
				for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(map[i][j]=='x')map[i][j]='X';
				step++;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int H, W;
const int MAX_HW = 510;
int board[MAX_HW][MAX_HW];
int main()
{
  cin >> H >> W;
  for (int i = 1; i <= H; i++)
  {
    for (int j = 1; j <= W; j++)
    {
      cin >> board[i][j];
    }
  }
  int y = 1;
  int x = 1;
  vector<pii> yx;
  vector<tuple<pii, pii>> paths;
  vector<pii> path;
  while (true)
  {
    if (y > H)
    {
      break;
    }
    // cerr << y << " " << x << endl;
    if (board[y][x] % 2 == 1)
    {
      if (yx.empty())
      {
        yx.push_back(mp(y, x));
      }
      else
      {
        //path
        int py = y;
        int px = x;
        
        for (int i = path.size() - 1; i >= 0; i--)
        {
          paths.push_back(mt(mp(py, px), mp(path[i].first, path[i].second)));
          
          py = path[i].first;
          px = path[i].second;
        }
        //clear
        yx.clear();
        path.clear();
      }
    }

    if (not yx.empty())
    {
      path.push_back(mp(y, x));
    }
    int dir = 1;
    if (y % 2 == 0)
    {
      dir *= -1;
    }
    x += dir;
    if (x < 1 || x > W)
    {
      x -= dir;
      y++;
    }
  }

  cout << paths.size() << endl;
  for (int i = 0; i < paths.size(); i++)
  {
    pii p, q;
    tie(p, q) = paths[i];
    cout << p.first << " " << p.second << " " << q.first << " " << q.second << endl;
  }
  return 0;
}


Measured memory_bytes: 5232
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#define N 100100
using namespace std;
struct node{
	int num, type;
}t[N];
int n, m;

int main(){
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; ++ i){
		t[i].num = 1;
		if (i == 1) t[i].type = 1;
		else t[i].type = 0;
	}
	for (i = 1; i <= m; ++ i){
		int x, y;
		scanf("%d%d", &x, &y);
		if (t[x].type == 1) 
			t[y].type = 1;
		t[x].num--;
		t[y].num++;
		if (!t[x].num)  t[x].type = 0;
	}
	int ans = 0;
	for (i = 1; i <= n; ++ i)
	if (t[i].type)  ans++;
	printf("%d\n", ans);
}

Measured memory_bytes: 1024
#pragma GCC optimize(2)
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e7+5+5e6;
using namespace std;
const ll INF=1e15+7;
const ll mod=1e9+7;
ll n,m,p;
vector<pair<int,int>>v[25];
int vis[20];
int work(int temp)
{
    for(int k=1;k<=n;k++)
    {
        if(temp&(1<<(k-1)))//这人说真话
        {
            int sz=v[k].size();
            for(int j=0;j<sz;j++)
            {
                int x=v[k][j].first;
                int y=v[k][j].second;
                if(y&&!(temp&(1<<(x-1)))) return 0;
                else if(!y&&(temp&(1<<(x-1)))) return 0;
            }
        }
    }
    return 1;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&m);
        for(int k=1;k<=m;k++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            v[i].push_back(make_pair(x,y));
        }
    }
    int res=0;
    for(int i=0;i<(1<<n);i++)
    {
        int f=work(i);
        if(f)
        {
            int cot=0;
            for(int k=1;k<=n;k++)
                cot+=(i&(1<<(k-1)))?1:0;
            res=max(res,cot);
        }
    }
    printf("%d\n",res);
    return 0;
}


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

int main() {
    string s; cin >> s;
    for(int i=0;i<s.size();i+=2)
    cout << s.at(i) << flush;
    cout << endl;

    return 0;
}

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

int main()
{
    int a, b, mn, mx;
    cin >> a >> b;
    mx = max(a, b);
    mn = min(a, b);
    string x=to_string(mn), str;
    for (int i = 0; i < mx; i++)
        str = str + x;
    cout << str;
}


Measured memory_bytes: 256
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
corner = (h // 2) * (w // 2)

cnt = 0
for i in a:
    if cnt == center:
        break
    if a[i] % 2 == 1:
        a[i] -= 1
        cnt += 1
cnt = 0
for i in a:
    if cnt == side:
        break
    if a[i] % 4 == 2:
        a[i] -= 2
        cnt += 1

print('Yes' if sum(a[i] % 4 for i in a) == 0 else 'No')


Measured memory_bytes: 9320
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int N;
  cin >> N;
  bool ok = true;
  int val = 0;
  for (int i = 0; i < N; i++)
  {
    int next;
    cin >> next;
    if (next < val)
    {
      ok = false;
    }
    else if (val < next)
    {
      val = next - 1;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll pl(ll a, ll b) {
    a %= mod, b %= mod;
    return (a+b) % mod;
}
ll mu(ll a, ll b) {
    a %= mod, b %= mod;
    return (a*b) % mod;
}
ll pow_mod(ll a, ll b) {
    if (b == 0) return 1;
    ll k = pow_mod(a, b/2);
    k = mu(k, k);
    if (b & 1) k = mu(k, a);
    return k;
}
ll di(ll a, ll b) {
    return mu(a, pow_mod(b, mod-2));
}
ll nCk(ll n, ll k) {
    ll X = 1, Y = 1;
    for (int a = n, b = k; b > 0; a--, b--) {
        X = mu(X, a);
        Y = mu(Y, b);
    }
    return di(X, Y);
}
int main () {
    ll p, q, K;
    cin >> p >> q >> K;
    ll ans = 0;
    for (int k = 0; k < 2; k++) {
        for (int i = 1; i <= q-1; i++) {
            ans += mu(mu(mu(p, p), q-i), i);
        }
        swap(p, q);
    }
    ans = di(ans, nCk(p*q, 2));
    ans = mu(ans, nCk(p*q, K));
    ans = mu(ans, nCk(K, 2));
    cout << ans << endl;
}

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

int main() {
  // ここにプログラムを追記
      string x;
      cin >> x;

      int s=0;
      for (int i=0; i<3 ; i++){
        if (x.at(i) =='1'){
          s++;}
        else {s +=0;
      }
      }
      cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct node{
  int p; 
  int l;
  int r;
}Node;

void print(int u);
int rec(int u, int p);

Node T[MAX];
int n = 0, D[MAX];

int main(){
  int i = 0, j = 0;
  int d = 0, v = 0, c = 0, l = 0, r = 0;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = T[i].l = T[i].r = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d",&v,&d);
    for(j = 0; j < d; j++){
      scanf("%d",&c);
      if(j == 0)T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == NIL)r = i;
  }

  rec(r, 0);

  for(i = 0; i < n; i++){
    print(i);
  }
  
  return 0;
}

void print(int u){
  int i = 0, c = 0;
  
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL)printf("root, [");
  else if(T[u].l == NIL)printf("leaf, [");
  else printf("internal node, [");

  c = T[u].l;
  for(i = 0; c != NIL; i++){
    if(i)printf(", ");
    printf("%d",c);
    c = T[c].r;
  }

  printf("]\n");

}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL)rec(T[u].r, p);
  if(T[u].l != NIL)rec(T[u].l, p+1);
}
/*Input
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d%d",&id,&k);
    T[i].sibling = k;
    if(k == 0){
      T[id].left[0] = -1;  子がいなければleftに-1  
    }
    T[i].parent = -2; もしrootだった時に-2のままのものを探す
    for(j = 0; j < k; j++){
      scanf("%d",&T[id].left[j]);
      T[T[id].left[j]].parent = id;
    }
  }

  Output
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, ",i,T[i].parent);
    
    depth = 0;
    j = i;
    while(T[j].parent != -1){
      j = T[j].parent;
      depth++;
    }
    printf("depth = %d, ",depth);
    
    if(T[i].parent == -2){
      printf("root, [");
    }
    else if(T[i].left[0] == -1)printf("leaf, []\n");
    else printf("internal node, [");

    if(T[i].left[0] != -1){
      for(l = 0; l < T[i].sibling; l++){
	if(l == T[i].sibling -1){
	  printf("%d]\n",T[i].left[l]);
	}
	else printf("%d, ",T[i].left[l]);
      }
    }
  }
*/



Measured memory_bytes: 6420
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

bool cmp(pii d1, pii d2){
	if(d1.second == d2.second){
    	return d1.first < d2.first;
    }
  	return d1.second < d2.second;
}

void Main()
{
	int n;
  	cin >> n;
   	vector<pii> data(n);

  	int x, y;
  	rep(i,n){
  		cin >> x >> y;
      	data[i].first = x-y;
      	data[i].second = x+y;
    }
  	sort(data.begin(),data.end(),cmp);
    //rep(i,n) cout << data[i].first << " " << data[i].second << endl;
  	
  	int count = 0;
  	int rmax = -INT_MAX;
  	rep(i,n){
      	if(rmax <= data[i].first){
			rmax = data[i].second;
        }
      	else{
        	count++;
        }
    }
  
  	cout << n - count << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const ll LINF = 1001002003004005006ll;

bool dfs(int now, int pre, int n, vector<vector<int>> &g, int cnt) {
    if (cnt == 2) {
        return now == n - 1;
    }
    bool ok = false;
    for (auto a: g[now]) {
        if (a == pre) continue;
        ok |= dfs(a, now, n, g, cnt+1);
    }
    return ok;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if (dfs(0, -1, n, g, 0)) {
        cout << "POSSIBLE" << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 15088
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&a!=c&&b!=c){
		printf("Yes");
	}
	else if(a==c&&a!=b&&c!=b)
	    printf("Yes");
	else if(b==c&&b!=a&&c!=a)
	    printf("Yes");
	else if(a==b&&a==c&&b==c)
	    printf("No");
	else if(a!=b&&a!=c&&b!=c)
	    printf("No");
	    
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<int> S[MAX],color(MAX,0),odd,even;

void DFS(int u){
    int cnt=1;
    bool ok=true;
    stack<int> ST;
    color[u]=1;
    ST.push(u);
    
    while(!ST.empty()){
        int a=ST.top();
        ST.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(color[b]==0){
                if(color[a]==1){
                    color[b]=2;
                    ST.push(b);
                    cnt++;
                }else{
                    color[b]=1;
                    ST.push(b);
                    cnt++;
                }
            }else if(color[a]==color[b]){
                ok=false;
            }
        }
    }
    
    if(ok) even.push_back(cnt);
    else odd.push_back(cnt);
    
    return;
}

int main(){
    
    int N,M;cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    
    for(int i=0;i<N;i++){
        if(S[i].size()==0||color[i]) continue;
        DFS(i);
    }
    
    int rem=N;
    
    ll ans=0;
    
    for(int i=0;i<odd.size();i++){
        rem-=odd[i];
    }
    
    for(int i=0;i<even.size();i++){
        rem-=even[i];
    }
    
    ans+=odd.size()+even.size()*2;
    ans+=ll(N)*ll(N)-ll((N-rem))*ll((N-rem));
    
    ans+=ll(4)*ll(even.size())*ll((even.size()-1))/2;
    ans+=ll(2)*ll(even.size())*ll(odd.size());
    ans+=ll(2)*ll(odd.size())*ll((odd.size()-1))/2;
    
    cout<<ans<<endl;
    //cout<<rem<<" "<<odd.size()<<" "<<even.size()<<endl;
    
}




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

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

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> lang(m);
    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        while (k--) {
            int l; cin >> l; l--;
            lang[l].push_back(i);
        }
    }
    UnionFind uf(n);
    for (int l = 0; l < m; l++) {
        vector<int> &cur = lang[l];
        for (int i = 0; i + 1 < cur.size(); i++) {
            uf.unionSet(cur[i], cur[i + 1]);
        }
    }
    if (uf.size() == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 4608
#include<stdio.h>
#include<string.h>

int main(void) {
	char str[102][102], temp[102];
	int N, L, i;
	scanf("%d %d", &N, &L);
	gets(temp);
	for (L = 0;L < N;L++)
		gets(str[L]);
	for (L = 0;L < N-1;L++) {
		for (i = 0;i < N - 1;i++) {
			if (strcmp(str[i], str[i + 1]) > 0) {
				strcpy(temp, str[i]);
				strcpy(str[i], str[i + 1]);
				strcpy(str[i + 1], temp);
			}
		}

	}
	for (i = 0;i < N;i++)
		printf("%s", str[i]);
	return 0;

}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

ll lcm( int m, int n )
{
	return (m / __gcd(m, n) * n);
}
 
 
int main()
{
  ll N,M;
  cin >> N >> M;
  string S;
  string T;
  cin >> S;
  cin >> T;
 
 
  int step = __gcd(N,M);
  ll L = N/step*M; 

  // cout << step << endl;
  for(int i=0;i<step;i++){
    // printf("===== i %d\n",i);
    // cout << L/M <<endl;
    // cout <<"S:" << S[i*N/step] << endl;
    // cout << L/N <<endl;
    // cout <<"T:" << T[i*M/step] << endl;
    if(S[i*N/step] != T[i*M/step]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (ll) L << endl;
  return 0;
}

Measured memory_bytes: 512
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const X = parseInt(arg[0]);
    
    let answer = 0;
    
    for(let i=1; i<=X+1; i++) {
        if(answer >= X) {
            console.log(i - 1);
            return;
        }
        
        answer += i;
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372