akhauriyash/Code-Regression huggingface dataset:
#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()
#define rall(x) (x).rbegin(),(x).rend()
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;
int d[2] = {1,-1};

signed main(){
    int n, m; cin >> n >> m;
    vector<priority_queue<int>> sum(8);
    REP(i,n){
        int a, b, c; cin >> a >> b >> c;
        REP(s,2)REP(t,2)REP(u,2){
            sum[4*s+t*2+u].push(a*d[s]+b*d[t]+c*d[u]);
        }
    }
    int ans = 0;
	REP(i,8){
        int pre = 0;
        REP(_,m){
            pre += sum[i].top();
            sum[i].pop();
        }
        chmax(ans,pre);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    //static List<string> str = new List<string>();
    static void Main(string[] args)
    {
        // 入力
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        List<int> candle = new List<int>();
        for(int i=0; i<N; i++)
        {
            candle.Add(int.Parse(input[i]));
        }

        // 座標0にもっとも近い、正の座標の配列番号を取得する
        int zeroCandle = lower_bound(candle, 0, N-1);

        // 左に移動して、0～K本火をつけてから、右に移動して火をつける・・・をK通り確かめる
        int minDist = -1; // 最小移動距離
        //Console.WriteLine(zeroCandle);
        for (int i = 0; i <= K; i++ )
        {
            //Console.Write(i + " ");
            // 左側でi本、右側で残りに火をつける
            // 左を先につけたときと、右を先につけたとき・・・
            if(zeroCandle - i < 0 || zeroCandle + (K-i-1) >= N)
            {
                // 左か右でろうそくの本数が足りなくなるので
                //Console.WriteLine();
                continue;
            }
            //左にi本付けにいったときの距離
            int left = i == 0 ? 0 : Math.Abs(candle[zeroCandle - i]);
            int right = zeroCandle == N ? 0 : Math.Abs(candle[zeroCandle + (K - i - 1)]);

            // 左を先につけた場合
            int leftFirst = 2 * left + right;
            // 右を先につけた場合
            int rightFirst = left + 2 * right;

            if(minDist < 0 || minDist > Math.Min(leftFirst, rightFirst))
            {
                minDist = Math.Min(leftFirst, rightFirst);
            }

            //Console.WriteLine(leftFirst + " " + rightFirst);
        }

        // 出力
        Console.WriteLine(minDist);
       
    }

    static int lower_bound(List<int> candle, int first, int last)
    {
        if(last - first <= 1)
        {
            if (candle[first] >= 0)
                return first;
            else
                return last;
        }
        // 座標が0にもっとも近い、正の座標を取得する
        if (candle[first] >= 0)
            return first;

        if (candle[last] < 0)
            return last + 1;

        int next = (first + last) / 2;

        //Console.WriteLine("lower_bound:" + first + " " + last + " " + next + " " + candle[next]);

        if (candle[next] > 0)
            return lower_bound(candle, first, next);
        else
            return lower_bound(candle, next, last);


    }
}

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

int main(){
  int n,k,q;
  int a[100010];
  int member[100010];
  cin >> n >> k >> q;
  for(int i=0;i<n;i++){
    member[i] = k - q;
  }
  for(int i=0;i<q;i++){
    cin >> a[i];
    member[a[i]-1]++; 
  }
  for(int i=0;i<n;i++){
    if(member[i] > 0){
      cout << "Yes\n";
    }else{
      cout << "No\n";
    }
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  vector<int> ans(100005, 0);
  int minl = 0;
  int maxr = 100005;
  for (int i = 0; i < m; i++) {
    cin >> l.at(i) >> r.at(i);
    if (l.at(i) > minl) minl = l.at(i);
    if (r.at(i) < maxr) maxr = r.at(i);
  }

  if (maxr - minl + 1 < 0) {
    cout << 0;
    return 0;
  } else {
    cout << maxr - minl + 1;
    return 0;
  }
}


Measured memory_bytes: 1408
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

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

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;
int Time;
typedef pair<string,int> P;
queue<P> que;
int main()
{
  string str;
  int work;
  cin >>n;
  cin >>Time;
  for(int i = 0;i < n;i++){
    
    cin >>str;
    cin>>work;
    que.push(P(str,work));
  }
  int time = 0;
  while(!que.empty()){
    str =que.front().first;
    work = que.front().second;
    que.pop();
    int diff =min(Time,work);
    work -=diff;
    time +=diff;
    if(work ==0){
      cout <<str <<" "<<time<<endl;
    }else{
      que.push(P(str,work));
    }
  }
  return 0;
}

Measured memory_bytes: 4404
#include<iostream>
#include<string>
#include<cstring>
#include<map>
using namespace std;

int main(){
  int N;
  
  while(cin>>N){
    if(N==0){
      break;
    }
    int max=0,min=1001,sum=0,a;
    for(int i=0;i<N;i++){
      cin >>a;
      if(max<a){ max=a; }
      if(min>a){ min=a; }
      sum+=a;
  }
    sum-=max;
    sum-=min;
    int ave = sum/(N-2);
    cout << ave <<endl;
  }

  return 0;
}

Measured memory_bytes: 1160
n=int(input())
A=[]
A=input().split()
A=[int(u) for u in A]
q=int(input())
B=[]
B=input().split()
B=[int(u) for u in B]
count=0
for j in range(0,q):
    right=n-1
    left=0
    while 1:
        k=int((right+left)/2)
        if A[k]>B[j]:
            right=int(k)
        elif A[int(k)]==B[j]:
            count=count+1
            right=n-1
            left=0
            break
        else:
            left=int(k)
        if right-left==1 or left-right==1:
            if A[right]==B[j] or A[left]==B[j]:
                count=count+1
                right=n-1
                left=0
                break
            else :
                right=n-1
                left=0
                break
print(count)


Measured memory_bytes: 16900
n = int(input())
l0 = 2
l1 = 1
if (n>=2):
    for i in range(n-1):
        l2 = l0 + l1
        l0 = l1
        l1 = l2
elif n == 0:
    l2 = 2
elif n == 1:
    l2 = 1
print(l2)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  int two = 0, four = 0;
  int val;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &val);
    if (val % 4 == 0) { ++four; }
    else if (val % 2 == 0) { ++two; }
  }
  int odd = N - two - four;
  if (two > 0) {
    printf("%s\n", four >= odd ? "Yes" : "No");
  }
  else {
    printf("%s\n", four >= odd - 1 ? "Yes" : "No");
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main {

	public static void main(String[] args)throws IOException{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		while(true){
			String str = br.readLine();
			if(str == null)
				break;
			int n = Integer.parseInt(str);
			int s = 0;
			for(int i = 0; i < 600/n; i++){
				s += (i*n)*(i*n)*n;
			}
			System.out.println(s);
		}

		
	}

}

Measured memory_bytes: 9156
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M,C;
  cin>>N>>M>>C;
  int B[M];
  int A[N][M];
  REP(i,M)cin>>B[i];
  REP(i,N)REP(j,M)cin>>A[i][j];
  int ans=0;
  REP(i,N){
    int temp=C;
    REP(j,M)temp+=B[j]*A[i][j];
    if(temp>0)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

int hayamin(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int N;
int A[271828], B[271828];

int main(void) {
	int i;
	int ayane, asumi;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d" ,&A[i], &B[i]) != 2) return 1;
	}
	qsort(A, N, sizeof(*A), hayamin);
	qsort(B, N, sizeof(*B), hayamin);
	if (N % 2 == 0) {
		ayane = A[N / 2 - 1] + A[N / 2];
		asumi = B[N / 2 - 1] + B[N / 2];
	} else {
		ayane = A[N / 2];
		asumi = B[N / 2];
	}
	printf("%d\n", asumi - ayane + 1);
	return 0;
}


Measured memory_bytes: 4048
a, b = [int(i) for i in input().split()]

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

    # divisors.sort()
    return divisors

  
import math

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

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

    return True
ad = make_divisors(a)
bd = make_divisors(b)
ans = 0
for i in ad:
  if i in bd:
    if is_prime(i):
      ans += 1
print(ans)

Measured memory_bytes: 3516
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000
#define MAX 200001
#define PI 3.141592653589793

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> cnt(N+1);
    rep(i,N){
        if(S[i] == '.') cnt[i+1] = cnt[i] + 1;
        else cnt[i+1] = cnt[i];
    }
    ll ans = INF;
    rep(i,N+1){
        ll white = cnt[N] - cnt[i];
        ans = min(ans, white+i-cnt[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5168
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::HashMap;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, m) = (line[0], line[1]);
    let m: u64 = m as u64;
    let a: Vec<u64> = read_as_vec();


    let mut b: Vec<u64> = vec![0];
    let mut sum = 0;
    for elem in a{
        sum = (elem + sum) % m;
        b.push(sum);
    }

    let mut map = HashMap::new();
    let mut ans: u64 = 0;

    for elem in b{
        let x = map.entry(elem).or_insert(0);
        ans += *x;
        *x += 1;
    }


    /*
    for i in 0..n + 1 {
        let x = map.entry(b[i]).or_insert(0);
        ans += *x;
        *x += 1;
    }
    */


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


Measured memory_bytes: 12756
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <stack>
#include <list>

using namespace std;

#define rep(i,j,k) for(int i=j;i<k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define vi vector<int>
#define vc vector<char>
#define INF 1e9
#define MOD 1e9+7



int main(void){
    int x;
    cin>>x;
    int pos=0,add=1;
    while(pos<x) {
        pos+=add;
        add++;   
    }
    
    cout<<add-1<<endl;
    
    
    
    return 0;
    
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main()
{
  ll N,M; cin>>N;
  vector<string> s(N); rep(i,N) cin>>s[i];
  cin>>M;
  vector<string> t(M); rep(i,M) cin>>t[i];
  
  map<string,ll> mp;
  for(auto str:s){
    if(!mp.count(str)) mp[str]=1;
    else mp.at(str)++;
  }
  for(auto str:t){
    if(!mp.count(str)) mp[str]=-1;
    else mp.at(str)--;
  }
  
  ll ans=0;
  for(auto p:mp){
    string str; ll mon; tie(str,mon)=p;
    chmax(ans,mon);
  }
  
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define MODULE 1000000007
#define MP make_pair

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef pair<int, int> P;
typedef long long int LL;
const LL INF = std::numeric_limits<LL>::max() / 2;    //int_max->2*e+9
const int MAXN = 100001;

struct edge {
    edge() {}

    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
struct edge2 {
    edge2() {}

    edge2(LL from, LL to, LL cost) : from(from), to(to), cost(cost) {}
    LL from, to, cost;

    bool operator==(const edge2 &rhs) const {
        return from == rhs.from &&
               to == rhs.to &&
               cost == rhs.cost;
    }

    bool operator!=(const edge2 &rhs) const {
        return !(rhs == *this);
    }
};
namespace std{
    template<>
    class hash<edge2>{
    public:
        size_t operator () ( const edge2 &e ) const{ return std::hash<LL>()(e.from+e.to*1000000000+e.cost);}
    };
}


vector<edge> graph[200001];

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

//-----Template---------

unordered_map<LL,LL> vertexNum; //R:0~r-1 C:r~C+r-1
unordered_set<LL> usedVertex;
unordered_set<edge2> edges;

int r,c,n;
int tmpR,tmpC,tmpA;

void decideVertex(int v,LL cost){
    if(usedVertex.find(v)==usedVertex.end()){
        usedVertex.insert(v);
        vertexNum[v]=cost;
        for (edge e:graph[v]) {
            decideVertex(e.to,e.cost-cost);
        }
    }
}
bool check2(){
    for(edge2 e:edges){
        if((vertexNum[e.from]+vertexNum[e.to])!=e.cost)
            return false;
    }
    return true;
}
unordered_set<LL> used4getMinDfs;
void getMinDfs(int v,LL& minR,LL& minC){
    if(used4getMinDfs.find(v)==used4getMinDfs.end()){
        used4getMinDfs.insert(v);
        if(v>=r) {
            chmin(minC, vertexNum[v]);
        }else{
            chmin(minR,vertexNum[v]);
        }
        for (edge e:graph[v]) {
            getMinDfs(e.to,minR,minC);
        }
    }
}
bool check1(){      //各連結成分の左右の最小値をもとめて，minR+minC>=0かどうかを返す
    for(int i=0;i<r;i++){
        LL minR=INF,minC=INF;
        getMinDfs(i,minR,minC);
        if(minR+minC<0)return false;
    }
    return true;
}

int main(){
    scanf("%d%d",&r,&c);
    scanf("%d",&n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d",&tmpR,&tmpC,&tmpA);
        tmpR--; tmpC--;
        graph[tmpR].push_back(edge(tmpC+r,tmpA));
        graph[tmpC+r].push_back(edge(tmpR,tmpA));
        edges.insert(edge2(tmpR,tmpC+r,tmpA));
    }
    for (int i = 0; i < r; ++i) {
        decideVertex(i,0);
    }
    if(check2() && check1()){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 41580
#include <iostream>

int main(){
    std::string str;
    std::cin >> str;

    int ans;

    if("SUN" == str){
        ans = 7;
    }else if("MON" == str){
        ans = 6;
    }else if("TUE" == str){
        ans = 5;
    }else if("WED" == str){
        ans = 4;
    }else if("THU" == str){
        ans = 3;
    }else if("FRI" == str){
        ans = 2;
    }else if("SAT" == str){
        ans = 1;
    }

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

    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<ll, ll> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int N,M; cin >> N >> M;
    vector<P> v(N); REP(i,N) cin >> v[i].first >> v[i].second;
    SORT(v);
    ll ans = 0;
    REP(i,N){
        if(v[i].second <= M){
            ans += v[i].first*v[i].second;
            M -= v[i].second;
        }
        else{
            ans += v[i].first*M;
            M = 0;
        }
        if(M == 0) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 60;
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;

  vector<int> op;
  for (int i = 1; pow(9, i) <= n; i++) {
    op.push_back(pow(9, i));
  }
  for (int i = 1; pow(6, i) <= n; i++) {
    op.push_back(pow(6, i));
  }
  op.push_back(1);

  sort(op.begin(), op.end());
  op.erase(unique(op.begin(), op.end()), op.end());

  sort(op.rbegin(), op.rend());

  // i 回目までの操作を使って j 引き出す場合の最小操作回数（j円ぴったりにできない場合はINF）
  vector<ll> dp(n + 1, INF);
  dp[0] = 0;
  for (auto& p : op) {
    for (int i = 0; i < n; i++) {
      if (dp[i] != INF && i + p <= n) {
        chmin(dp[i + p], dp[i] + 1);
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}


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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    string s;
    cin >> s;
    if (s.substr(0, 2) == "00" and s.substr(2, 2) > "12")
        return cout << "NA" << endl, 0;
    if (s.substr(2, 2) == "00" and s.substr(0, 2) > "12")
        return cout << "NA" << endl, 0;
    if (s.substr(2, 2) == "00" and s.substr(0, 2) == "00")
        return cout << "NA" << endl, 0;
    if (s.substr(0, 2) > "12" and s.substr(2, 2) > "12")
        return cout << "NA" << endl, 0;
    if (s.substr(0, 2) <= "12" and s.substr(2, 2) <= "12" and s.substr(2, 2) > "00" and s.substr(0, 2) > "00")
        return cout << "AMBIGUOUS" << endl, 0;
    if (s.substr(0, 2) <= "12" and s.substr(0, 2) > "00")
        cout << "MMYY" << endl;
    else
        cout << "YYMM" << endl;
    return 0;
}

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


template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

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

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<ll> A(N), S(N+1), B(N+1);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  S.at(0) = 0;
  B.at(0) = 0;
  for (int i = 0; i < N; i++) {
    S.at(i+1) = (S.at(i) + A.at(i)) % K;
    int j = (i + 1) % K;
    B.at(i+1) = (K + S.at(i+1) - j) % K;
  }
  ll cnt = 0;

  unordered_map<ll,ll> mp;
  for (int i = 0; i <= N; i++) {
    int b = B.at(i);
    cnt += mp[b];
    mp[b]++;
    if (i - K + 1 >= 0) {
      int bb = B.at(i-K+1);
      mp[bb]--;
    }
  }
  cout << cnt << endl;
    
  return 0;
}



Measured memory_bytes: 13256
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = stoi(readL(br));
    long count=0;
    int a[]=new int[n-1];
    for(int i=0;i<n;i++){
      int k = readI(br);
      if(0<i-k){
        count+=a[i-k];
      }
      if(i+k<n-1){
        a[i+k]++;
      }
    }
    pl(count+"");
  }

  public static String readL(BufferedReader br){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(BufferedReader br){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static int readI(BufferedReader br){
    return stoi(readS(br));
  }
  public static String[] readSs(BufferedReader br){
    return readL(br).split(" ");
  }
  public static int[] readIs(BufferedReader br){
    return stoi(readSs(br));
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
}


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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long 

using namespace std;

int32_t main()
{
	fio;
	int n;
	cin>>n;
	int *a=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	unordered_map<int,int> sum,diff;
	for(int i=0;i<n;i++)
	{
		int d=a[i]-i-1;
		int s=a[i]+i+1;
		if(sum.count(s))
		{
			sum[s]++;
		}
		else
		{
			sum[s]=1;
		}

		if(diff.count(d))
		{
			diff[d]++;
		}
		else
		{
			diff[d]=1;
		}
	}

	int ans=0;
	for(auto it:sum)
	{
		int c1=it.second;
		if(diff.count(-it.first))
		{
			ans+=c1*diff[-it.first];
		}
	}

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

Measured memory_bytes: 20164
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
const int N=100500;
string s;
int d;
const int mod=1e9+7;
int dp[N][100][2][2];
int add(int a, int b){
	a+=b;
	if(a>=mod)a-=mod;
	return a;
}
int f(int i, int r, bool b, bool zero){
	if(i==SZ(s))return !r;
	int &q=dp[i][r][b][zero];
	if(q!=-1)return q;
	q=0;
	for(int j=zero;j<=9;j++){
		if(!b&&j>s[i]-'0')continue;
		q=add(q,f(i+1,(r+j)%d,b|(j<s[i]-'0'),0));
	}
	return q;
}
int main(){FIN;
	cin>>s>>d;
	memset(dp,-1,sizeof dp);
	int r=f(0,0,0,1);
	fore(i,1,SZ(s))r=add(r,f(i,0,1,1));
	cout<<r<<"\n";
}

Measured memory_bytes: 158080
#include<iostream>

using namespace std;

int main() {
	
	int n, x, i=0;
	cin >> n;
	while( ++i <= n) {
		x = i;
		if( x % 3 == 0){
		cout << " " << i;
		continue;
	}
	while(x){
		if(x % 10 == 3 ){
		cout << " " << i;
		break;
	}
		x /= 10;
	}
}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 3072
#include <iostream>

using namespace std;

int n, k;

int a[105];
bool dp[100005];

int main(void)
{
	cin >> n >> k;
	for(int i = 0 ; i < n; i++) cin >> a[i];
	
	for(int i = 0; i <= k; i++){
		for(int j = 0; j < n; j++){
			if(i < a[j]) continue;
			dp[i] |= !dp[i-a[j]];
		}
	}
	if(dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;
	
	return 0;
}

Measured memory_bytes: 384
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 
N =  int(sys.stdin.readline())
L =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N - 1)]

for i in range(N - 1):
    start = L[i]
    cnt = start[0] + start[1]
    for j in range(i + 1, N - 1):
        next = L[j]
        # 開通しているか確認
        if cnt < next[1]:
            cnt = next[1]
        else:
            # 貪欲法で探す？
            x = next[1]
            while True:
                if x >= cnt:
                    # print(x, cnt, next[1])
                    break
                x += next[2]
            cnt += (x - cnt)
        cnt += next[0]
    print(cnt)

print(0)

Measured memory_bytes: 71384
// https://atcoder.jp/contests/abc139/tasks/abc139_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: i32, b: i32
    };
    if b >= 2 {
        let mut w = 1;
        let mut now = a;
        while now < b {
            w += 1;
            now += a-1;
        }
        println!("{}", w);
    } else {
        println!("0");
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    cin>>A>>B;
    if(A==1||B==1){
        if(A==2||B==2){
            C=3;
        }
        else{
            C=2;
        }
    }
    else if(A==2||B==2){
        if(A==3||B==3){
            C=1;
        }
    }
    cout<<C<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
const int MAXN = 100000;
struct edge{
	int to; edge *nxt;
}edges[2*MAXN + 5], *adj[MAXN + 5], *ecnt=edges;
void addedge(int u, int v) {
	edge *p = (++ecnt);
	p->to = v, p->nxt = adj[u], adj[u] = p;
	p = (++ecnt);
	p->to = u, p->nxt = adj[v], adj[v] = p;
}
vector<pii>ans;
int dfn[MAXN + 5], dcnt = 0;
int f[MAXN + 5];
void add(int x, int y) {
	ans.push_back(make_pair(x, y)), f[x] ^= 1;
}
void dfs(int x, int fa) {
	dfn[x] = (++dcnt);
	for(edge *p=adj[x];p;p=p->nxt) {
		if( p->to == fa ) continue;
		if( dfn[p->to] ) {
			if( dfn[p->to] < dfn[x] )
				add(x, p->to);
		}
		else {
			dfs(p->to, x);
			if( f[p->to] ) add(p->to, x);
			else add(x, p->to);
		}
	}
}
int main() {
	int N, M; scanf("%d%d", &N, &M);
	for(int i=1;i<=M;i++) {
		int u, v; scanf("%d%d", &u, &v);
		addedge(u, v);
	}
	for(int i=1;i<=N;i++) {
		if( !dfn[i] ) {
			dfs(i, 0);
			if( f[i] ) {
				puts("-1");
				return 0;
			}
		}
	}
	for(int i=0;i<M;i++)
		printf("%d %d\n", ans[i].first, ans[i].second);
}

Measured memory_bytes: 13172
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	long long N = 0;
	long long a[10010];
	cin >> N;
	for (int i = 1; i < N + 1; i++) {
		cin >> a[i];
	}

	long long b[10010];

	for (int i = 1; i < N + 1; i++) {
		long long count = 0;
		for (int j = 1; j < 31; j++) {
			if (a[i] % 2 == 0) {
				count++;
				a[i] = a[i] / 2;
			}
			else {
				b[i] = count;
			}
		}

	}

	long long Ans = 0;
	for (int i = 1; i < N + 1; i++) {
		Ans = Ans + b[i];
	}

	cout << Ans;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std; 
string a,b,c;
int d,e;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>a;
	for(int i=0;i<a.size();i++)b+='x';
	cout<<b<<endl;
    return 0; 
}/*
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main(){
        int x, a, b;
        scanf("%d %d %d", &x, &a, &b);
        int minCake = x - a;
        int cntDough = minCake / b;
        printf("%d", x - a - cntDough * b);
    }

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long gcd = Euclid(c, d);
		long lcm = c * d / gcd;
		System.out.println(b - b/c - b/d + b/lcm - a + a /c + a/d - a/lcm);
	}
	public static long Euclid(long n, long m) {
		if(m==0) return n;
		return Euclid(m, n%m);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int K;
		String S;

		//System.out.println("整数を入力");
		K=sc.nextInt();  //整数

		//System.out.println("文字列を入力");
		S=sc.next();  //文字列

		//System.out.println(K);  //整数
		//System.out.println(S);  //文字列


		if(S.length()<=K) {
			System.out.println(S);
		}else {
			System.out.println(S.substring(0,K)+"...");
		}

		sc.close();



	}
}


Measured memory_bytes: 38532
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n,m; cin >> n >> m;
  int maxL = 1;
  int minR = n;
  vector<int>R(m),L(m);
  rep(i,m)cin >> L[i] >> R[i];
  rep(i,m){
    maxL = max(maxL,L[i]);
    minR = min(minR,R[i]); 
  }
  int ans = minR-maxL+1;
  ans = max(ans,0);
  cout << ans << endl;
  return 0;
}



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

int main() {
  string X;
  cin >> X;
  int sc = 0, ans = X.size();
  for (char c : X) {
    if (c == 'S') sc++;
    else if (0 < sc) {
      sc--;
      ans -= 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int i,N,x;

    scanf("%d",&N);
    int K[N];
    int P[N];

    for(i=0;i<N;i++){
        scanf("%d %d",&K[i],&P[i]);
    }
    for(i=0;i<N;i++){
        if(K[i]%P[i]==0)
           printf("%d",P[i]);
        else if(K[i]<P[i])
            printf("%d",K[i]);
        else
            printf("%d",K[i]%P[i]);
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 600
a, b = map(int, input().split())

if (int(12.5*a)+(a%2)) > 10*b+9 or (int(12.5*a)+(a%2))+12-(a%2) < 10*b:
    print(-1)
else:
    print(max((int(12.5*a)+(a%2)), 10*b))


Measured memory_bytes: 9116
#import <Foundation/Foundation.h>
#define $(...)  ([NSSet setWithArray: @[__VA_ARGS__]])
int main(){
    @autoreleasepool {
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        NSSet *set = $(@(a),@(b),@(c),@(d));
        puts([set isEqualToSet:$(@1,@9,@7,@4)] ? "YES": "NO");
    }
}


Measured memory_bytes: 9116
n, q = map(int, input().split())
s = list(input())
lrs = [list(map(int, input().split())) for _ in range(q)]
d = [0] * n
cnt = 0
for i in range(n-1):
    if s[i:i + 2] == ['A', 'C']:
        cnt += 1
    d[i+1] = cnt
for j in range(q):
    l, r = lrs[j][0], lrs[j][1]
    print(d[r - 1] - d[l - 1])

Measured memory_bytes: 31392
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

const int INF = 100000000;

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

struct e
{
	int s;
	int t;
	long long cst;
};

vector<vector<long long>> wf(vector<e> & ve,int n)
{
	vector<vector<long long>> dist(n,vector<long long>(n,INF));
	rep(i,ve.size())
	{
		dist[ve[i].s][ve[i].t] = min(ve[i].cst,dist[ve[i].s][ve[i].t]);
		dist[ve[i].t][ve[i].s] = min(ve[i].cst,dist[ve[i].t][ve[i].s]);
	}
	rep(i,n)
	{
		rep(j,n)
		{
			rep(k,n)
			{
				dist[j][k] = min(dist[j][i]+dist[i][k],dist[j][k]);
			}
		}
	}
	return dist;
}

long long mny(int dist,const vector<long long> & md,const vector<long long> & mr)
{
	auto it = upper_bound(md.begin(),md.end(),dist);
	it--;
	long long sum = 0;
	int j = 0;
	for(auto i = md.begin();i != it;i++)
	{
		sum += mr[j]*(*(i+1) - *i);
		j++;
	}
	sum += mr[j]*(dist - *it);
	return sum;
}

bool operator<(const e & lhs,const e & rhs)
{
	return lhs.cst > rhs.cst;
}

int main()
{
	while(1)
	{
		int n,m,c,s,g;
		cin >> n >> m >> c >> s >> g;
		if(!(n||m||c||s||g))
			break;
		vector<vector<e>> lines(c);
		rep(i,m)
		{
			int x,y,d,ci;
			cin >> x >> y >> d >> ci;
			e ed = {x-1,y-1,d};
			lines[ci-1].push_back(ed);
		}
		vector<vector<long long>> cost(n,vector<long long>(n,INF));
		vector<int> mcut(c);
		vector<vector<long long>> md(c);
		vector<vector<long long>> mr(c);
		rep(i,c)
		{
			cin >> mcut[i];
			md[i] = vector<long long>(mcut[i],0);
			mr[i] = vector<long long>(mcut[i],0);
		}
		rep(i,c)
		{
			rep2(j,mcut[i]-1)
			{
				cin >> md[i][j];
			}
			rep(j,mcut[i])
			{
				cin >> mr[i][j];
			}
		}
		rep(i,c)
		{
			auto dist = wf(lines[i],n);
			rep(j,n)
			{
				rep(k,n)
				{
					if(j == k)
						continue;
					cost[j][k] = min(cost[j][k],mny(dist[j][k],md[i],mr[i]));
				}
			}
		}
		vector<e> edges;
		rep(i,n)
		{
			rep(j,n)
			{
				if(cost[i][j] < INF)
				{
					e e1 = {i,j,cost[i][j]};
					edges.push_back(e1);
				}
			}
		}
		auto table = wf(edges,n);
		if(table[s-1][g-1] < INF)
		{
			cout << table[s-1][g-1] << endl;
		}
		else
		{
			cout << "-1" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 300000>;
comb cb;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, N;
	cin >> H >> W >> N;
	vector<pair<int, int> > vp(N);
	vector<int> X(N);
	vector<int> Y(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	sort(vp.begin(), vp.end());
	for (int i = 0; i < N; i++) {
		X[i] = vp[i].first;
		Y[i] = vp[i].second;
	}
	X.push_back(H);
	Y.push_back(W);
	vector<int> dp(N + 1, 0);
	for (int i = 0; i <= N; i++) {
		dp[i] = cb.binom(X[i] + Y[i] - 2, X[i] - 1);
		
		for (int j = 0; j < N; j++) {
			if (i != j && X[j] <= X[i] && Y[j] <= Y[i]) {
				//cerr << i << "  " << j << endl;
				int dx = X[i] - X[j];
				int dy = Y[i] - Y[j];
				dp[i] -= (dp[j] * cb.binom(dx + dy, dx)) % MOD;
			}
		}
		//cerr << i << " " << dp[i] << endl;
		dp[i] %= MOD; dp[i] += MOD; dp[i] %= MOD;
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 5120
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		StringBuffer sb=new StringBuffer(a);
		String b=sb.reverse().toString();

		if(Integer.parseInt(a)-Integer.parseInt(b)==0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21972
#include <iostream> // cout, cin, swapなど
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdio>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// 間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	// 数列G = {1, 4, 13, 40, 121, 364, 1093, ...}を生成
	for (int h = 1; ; ) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	// 逆順にG[i] = gを生成
	for (int i = G.size() - 1; i >= 0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main() {
	cin >> n;

	// より高速なscanfの利用
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

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

	return 0;
}


Measured memory_bytes: 7164
#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <unordered_map>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last)
			out << ",";
	}
	out << "]";
	return out;
}

void solve() {
	int n;
	cin >> n;
	cout << n * 800 - (n / 15) * 200 << endl;
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define abs(x) ((x) > 0 ? (x) : -(x))

int gcd(int x, int y){
  if(x == 0 || y == 0) return x + y;
  if(y > x) return gcd(y, x);
  return gcd(y, x % y);
}

int
main(int argc, char *argv[])
{
  int n, X, x[100000];
  scanf("%d %d", &n, &X);
  for(int i = 0; i < n; ++i){
    scanf("%d", &x[i]);
    x[i] = abs(x[i] - X);
  }

  int y = x[0];
  for(int i = 1; i < n; ++i){
    y = gcd(y, x[i]);
  }
  printf("%d\n", y);

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  long long ans=0;
  long long cnt=0;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    if(s[i]=='W'){
      cnt++;
    }else{
      ans+=cnt;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define rpz(i,e) rp(i,0,e)
#define irpz(i,s) rp(i,s,-1)

int main(){
	int N; cin>>N;
	vi A(N);
	rpz(i,N) cin>>A[i];
	sort(all(A));
	int n=0,r=0;

	n = A[N-1];
	int mindiff = INT_MAX;
	// irpz(i,N-1){
	rpz(i,N-1){
		int ai = A[i];
		int diff = abs((n+2-1)/2-A[i]);
		if(mindiff > diff){
			mindiff = diff;
			r = A[i];
		}

	}

	cout<< n <<" "<< r <<endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    cout << (X/500) * 1000LL + ((X % 500) / 5) * 5 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
ll ans;
char s[10];
inline void query(ll x)
{if(x==1){s[0]='Y';return ;}printf("? %lld\n",x);fflush(stdout);scanf("%s",s);}
inline int check(ll x)
{
    reg ll y=x*10;
    reg int l=0,r=10,mid;
    while(l<r-1)
    {
        mid=(l+r)>>1;
        query(y+mid);
        if(s[0]=='N')r=mid;
        else l=mid;
    }
    return r-1;
}
int main()
{
    reg ll x;reg int i;
    x=1;reg int len=15;
    for(i=1;i<=10;++i)
    {
        query(x);
        if(s[0]=='N')
        {
            len=i-1;break;
        }x*=10;
    }
    if(len==15)
    {
        x=9;
        for(i=1;i<=10;++i)
        {
            query(x);
            if(s[0]=='Y')
            {
                len=i;break;
            }x=x*10+9;
        }
        if(len>1)
        {
            ans=1;
            for(i=1;i<len;++i)ans=ans*10;
            printf("! %lld\n",ans);return 0;
        }
    }
    for(i=1;i<len;++i)
        x=check(ans),ans=ans*10+x;
    if(len==1)
    {
        for(i=9;i>=1;--i)
        {
            query(i*10+1);
            if(s[0]=='N'){printf("! %d\n",i+1);exit(0);}
        }
        puts("! 1");return 0;
    }
    for(i=0;i<=9;++i)
    {
        x=(ans*10+i)*10+1;
        query(x);
        if(s[0]=='Y')
        {
            ans=ans*10+i;
            printf("! %lld\n",ans);exit(0);
        }
    }
	return 0;
}


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

#define endl '\n'

using namespace std;

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

    int n, arr[100], cnt = 0;
    cin >> n;
    for(size_t i = 0; i < n; i++) cin >> arr[i];

    for(int i = 0; i < n; i++)
    {
        int mini = i;
        bool flag = false;
        for(int j = i; j < n; j++)
        {
            if(arr[j] < arr[mini])
            {
                mini = j;
                flag = true;
            }
        }
        swap(arr[i], arr[mini]);
        if(flag) cnt++;
    }

    for(size_t i = 0; i < n; i++)
    {
        cout << arr[i];
        if(i < n - 1) cout << " ";
    }
    cout << endl << cnt << endl;

    return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{	
  ll a,b;
  cin>>a>>b;
  ll k = (a+b)/2;
  if(2*k==a+b)cout<<k<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

#define PI 3.141592653589

using namespace std;

int main() {
	double r, s, l;
	cin >> r;

	l = 2*PI*r;
	s = r*r*PI;

	cout << fixed << setprecision(5) << s << " " << l << endl;

	return 0;
}

Measured memory_bytes: 1288
import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();int a = s.nextInt();int b = s.nextInt();
		int ans = (x-a);
		int quot = ans/b;
		System.out.println(ans- quot*b);
	}
}

Measured memory_bytes: 21844