akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
  int p;
  while(scanf("%d",&p)!=EOF)
    {
      int q[p],i;
      q[0]=1;
      q[1]=1;
      for(i=2;i<=p;i++)
	q[i]=q[i-1]+q[i-2];
      printf("%d\n",q[p]);
    }
  return 0;
}
  



Measured memory_bytes: 2108
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

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

fn main() {
  input! {
  n: usize,
  q: usize,
  s:Chars,
  mut q: [(Usize1, Usize1); q],
  }

  //i文字までのAの数
  let mut t = vec![0; s.len()];

  let mut cnt = 0;
  for i in 0..s.len() {
    if s[i] == 'A' {
      if i <= s.len() - 2 {
        if s[i + 1] == 'C' {
          cnt += 1;
        }
      }
    }
    if i < s.len() -1 {
      t[i+1] = cnt;
    }
  }

  debug!(q);
  debug!(t);

  for q1 in q {
    println!("{}", t[q1.1] - t[q1.0]);
  }
}


Measured memory_bytes: 6808
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int a, b, c, rect = 0, rhom = 0;
    while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
        if (a == b) {
            rhom++;
        }
        else if (a*a + b*b == c*c) {
            rect++;
        }
    }
    cout << rect << endl << rhom << endl;

    return 0;
}

Measured memory_bytes: 1208
n=int(input())
s=input()

result=""
cnt=0

#(を追加する
for ss in s:
    #print(result)
    if ss ==")":
        if cnt>0:
            result+=ss
            cnt-=1
        else:
            result="("+result+ss

    else:
        result+=ss
        cnt+=1

L=result.count("(")
R=result.count(")")

result+=")"*(L-R)

print(result)

Measured memory_bytes: 38384
#include <stdio.h>
#define N 100
#define MAX 10000000
#define W 0
#define B 1

int n,c[N],A[N][N],X[N],Y[N];

void prim(){
  int m,i,j;

  for(i=0;i<n;i++){
    X[i]=MAX;
    Y[i]=-1;
    c[i]=W;
  }

  X[0]=0;

  while(1){
    m=MAX;
    for(i=0;i<n;i++){
      if(c[i]!=B && X[i]<m){
	m=X[i];
	j=i;
      }
    }

    if(m==MAX) break;
    c[j]=B;

    for(i=0;i<n;i++){
      if(c[i]!=B && A[j][i]<X[i] && A[j][i]>=0){
	Y[i]=j;
	X[i]=A[j][i];
      }
    }
  }
}

  int main(){
    int i,j,count=0;

    scanf("%d",&n);

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf("%d",&A[i][j]);
      }
    }
    
    prim();
    for(i=0;i<n;i++)count+=X[i];

    printf("%d\n",count);

    return 0;
  }



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

int main(){

  int h, w;
  int i, j;

  while(1){
    cin >> h >> w;
    if(w == 0 && h == 0)
      break;

    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
	if(i > 0 && i < h-1 && j > 0 && j < w-1)
	  cout <<".";
	else
	  cout <<"#";
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3076
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int L;

// dijkstra O(ElogV)
// verify : https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
template<typename T>
struct Dijkstra {
private:
    const T inf = numeric_limits<T>::max();
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    vector<pair<int, T>> d;

    Dijkstra(int V) {
        G.resize(V);
    }

    // 辺の追加
    // 有向の場合　directed = true
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }

    void build(int s) {
        d.assign(G.size(), {INF,1});
        typedef pair<pair<int, T>, int> P; //((回数,-燃料),v)
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s] = {0,-L};
        pq.push({{0,-L}, s});
        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (edge &e : G[v])
            {
                // 補充無し
                if (d[v].second + e.cost <= 0 && (d[e.to].first > d[v].first || (d[e.to].first == d[v].first && d[e.to].second > d[v].second + e.cost))) {
                    d[e.to] = {d[v].first, d[v].second + e.cost};
                    pq.push({d[e.to], e.to});
                }
                // 補充アリ
                else if (d[e.to] >= make_pair(d[v].first + 1, -L + e.cost) && -L + e.cost <= 0) {
                    d[e.to] = {d[v].first + 1, -L + e.cost};
                    pq.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }
};

int main() {
    int n, m; cin >> n >> m >> L;
    Dijkstra<ll> G(n);
    REP(i, m) {
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        G.add_edge(a, b, c);
    }
    int q; cin >> q;
    vector<vector<pair<int, ll>>> ans(n);
    REP(i, n) {
        G.build(i);
        REP(j, n) {
            ans[i] = G.d;
        }
    }
    REP(i, q) {
        int s, t; scanf("%d %d", &s, &t);
        s--; t--;
        printf("%d\n", ans[s][t].first == INF ? -1 : ans[s][t].first);
    }
    return 0;
}

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

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

int main(void)
{
    ll a,b; cin>>a>>b;
    cout<<a*b<<" "<<2*(a+b)<<endl;
    return 0;
} 


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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    int used = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> m[i];
        used += m[i];
    }
    int left = x - used, min = m[0];
    for (int i = 0; i < n; i++)
    {
        if (min > m[i])
        {
            min = m[i];
        }
    }
    cout << n + left / min << endl;
    return 0;
}

Measured memory_bytes: 3632
n,k=map(int,input().split())
a=[]
i=0
if k>1:
    while len(a)==0 or a[-1]!=1:
        a.append((k-1)//(2**i))
        i+=1
else:
    a.append(0)
n1=len(a)
if n>=k:
    s=(n-k+1)/n
    for i in range(n1):
        if i!=n1-1:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        else:
            s+=a[i]/(n*(2**(i+1)))
else:
    s=0
    for i in range(n1):
        if i!=n1-1 and a[i]>=n>a[i+1]:
            s+=(n-a[i+1])/(n*(2**(i+1)))
        elif i!=n1-1 and n>a[i+1]:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        elif n>=a[i]:
            s+=a[i]/(n*(2**(i+1)))
print(s)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int Nmax = 100001;
const int RCmax = 100001;
const long long INF = 10e10;
int R,C,N;
int r[Nmax], c[Nmax];
long long a[Nmax];
long long x[RCmax], y[RCmax];
vector<pair<int, long long> > xedge[RCmax];
vector<pair<int, long long> > yedge[RCmax];

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

  for(int i=0; i<N; i++){
    cin >> r[i] >> c[i] >> a[i];
    xedge[r[i]].push_back(make_pair(c[i],a[i]));
    yedge[c[i]].push_back(make_pair(r[i],a[i]));
  }

  for(int i=1; i<=R; i++) x[i]=INF;
  for(int i=1; i<=C; i++) y[i]=INF;

  int ok=1;
  for(int i=1; i<=R; i++){
    if(x[i]!=INF) continue;
    queue<int> que;
    x[i]=0;
    que.push(i);
    while(!que.empty()){
      int ri=que.front(); que.pop();
      for(int k=0; k<xedge[ri].size(); k++){
        int ci = xedge[ri][k].first;
        long long ai = xedge[ri][k].second;
        if(y[ci]==INF){
          y[ci]=ai-x[ri];
          for(int l=0; l<yedge[ci].size(); l++){
            int rj=yedge[ci][l].first;
            long long aj=yedge[ci][l].second;
            if(x[rj]==INF){
              x[rj] = aj-y[ci];
              que.push(rj);
            }
            else if(x[rj]+y[ci]!=aj) ok=0;
          }
        }
        else{
          if(x[ri]+y[ci]!=ai) ok=0;
        }
      }
    }
  }

  //cout << ok << endl;
  //for(int i=1; i<=R; i++) cout << x[i] << " ";
  //cout<<endl;
  //for(int i=1; i<=C; i++) cout << y[i] << " ";
  //cout<<endl;

  int xdone[RCmax];
  int ydone[RCmax];
  for(int i=1; i<=R; i++) xdone[i] = 0;
  for(int i=1; i<=R; i++) ydone[i] = 0;

  for(int i=0; i<=R; i++){
    if(xdone[i]) continue;
    long long xmin=x[i], ymin=INF;
    queue<int> que;
    xdone[i] = 1;
    que.push(i);
    while(!que.empty()){
      int ri = que.front(); que.pop();
      for(int j=0; j<xedge[ri].size(); j++){
        int ci = xedge[ri][j].first;
        if(ydone[ci] > 0) continue;
        ydone[ci] = 1;
        ymin = y[ci] < ymin ? y[ci] : ymin;
        for(int k=0; k<yedge[ci].size(); k++){
          int rj = yedge[ci][k].first;
          if(xdone[rj] > 0) continue;
          xdone[rj] = 1;
          xmin = x[rj] < xmin ? x[rj] : xmin;
          que.push(rj);
        }
      }
    }
    if(xmin+ymin<0) ok=0;
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool cmp(int x,int y){
    return abs(0-x)<abs(0-y);
}

int main(){
    CIN(N,X);
    vi l(N+1),dis(N+1);
    l[0]=0;
    dis[0]=0;
    RepS(i,1,N){
        cin>>l[i];
        dis[i]=dis[i-1]+l[i];
    }
    int ans=0;
    rep(i,N+1){
        if(dis[i]<=X) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
/*  ex4_2 Colon
    pandacodeb  */

#include <stdio.h>
#include <math.h>

double findAng(double h, double m);
double findDist(double lenH, double lenM, double h, double m);

int main(void){
    double lenH, lenM, h, m;
    scanf("%lf %lf %lf %lf", &lenH, &lenM, &h, &m);
    printf("%.10f\n", findDist(lenH, lenM, h, m));
    return 0;
}

double findAng(double h, double m){
    double angleH = (2 * M_PI * h/12) + (M_PI/6 * m/60);
    double angleM = 2 * M_PI * m/60;
    return angleM - angleH;
}

double findDist(double lenH, double lenM, double h, double m){
    double angle = findAng(h, m);
    double dist = sqrt(lenH*lenH + lenM*lenM - 2*lenH*lenM*cos(angle));
    return dist;
}

Measured memory_bytes: 2664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int m = (h2 - h1) * 60 + (m2 - m1) - k;

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define MAX 100001
using namespace std;

vector<int> g[MAX];
bool visited[MAX];
int pre[MAX], par[MAX], lowest[MAX], timer;

void dfs(int cur, int prev){
  // cur????¨????????????´????????????
  pre[cur] = lowest[cur] = timer;
  timer++;
  visited[cur] = true;
  int next;
  for(int i = 0; i < g[cur].size(); i++){
    next = g[cur][i];
    if(!visited[next]){
      // cur??????next????¨????????????´????????????
      par[next] = cur;
      dfs(next, cur);
      // next?????¢?´¢?????????????????´????????????
      lowest[cur] = min(lowest[cur], lowest[next]);
    }else if(next != prev){
      // cur --> next???back-edge?????´????????????
      lowest[cur] = min(lowest[cur], pre[next]);
    }
  }
}

int main(){

  int v, e;
  cin >> v >> e;
  for(int i = 0; i < e; i++){
    int s, t;
    cin >> s >> t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  for(int i = 0; i < v; i++) visited[i] = false;
  timer = 1;
  dfs(0, -1);
  set<int> ap;
  int np = 0;
  for(int i = 1; i < v; i++){
    int p = par[i];
    if(p == 0) np++;
    else if(pre[p] <= lowest[i]) ap.insert(p);
  }
  if(np > 1) ap.insert(0);
  for(set<int>::iterator it = ap.begin(); it != ap.end(); it++){
    cout << *it << endl;
  }
  return 0;
}


Measured memory_bytes: 6924
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a;
int b[100000];

int main(){
  cin >> a;
  REP(i,a) cin >> b[i];
  sort(b,b+a);
  reverse(b,b+a);
  int ans =0;
  b[0] /= 2;
  REP(i,a) ans += b[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <cmath>

#include <set>

#include <map>



using namespace std;


const int INF = 100000;

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

char maze[100][101];

ll n, m;

int sx, sy;

int gx, gy;



//各座標までの最短距離

int d[100][100];


//移動方向のベクトル

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

int main() {

	cin >> n >> m;
	if (n == 1&&m == 1) {
		cout << 1 << endl;
	}
	else if (n == 2 || m == 2) {
		cout << 0 << endl;
	}
	else if (n == 1 || m == 1) {
		cout << max(n, m) - 2 << endl;
	}
	else {
		cout << (n - 2)*(m - 2) << endl;
	}


	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=305,INF=1<<25;
int A[MAX],dp[MAX][MAX];

int solve(int l,int r){
    if(dp[l][r]!=-1) return dp[l][r];
    if(r-l<=1) return dp[l][r]=0;
    if(r-l==2){
        if(abs(A[l]-A[l+1])<=1) return dp[l][r]=2;
        else return dp[l][r]=0;
    }
    
    int ma=0;
    
    for(int i=l+1;i<=r-1;i++){
        ma=max(ma,solve(l,i)+solve(i,r));
    }
    
    if(solve(l+1,r-1)==r-l-2) ma=max(ma,solve(l+1,r-1)+2*(abs(A[l]-A[r-1])<=1));
    
    return dp[l][r]=ma;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        for(int i=0;i<N;i++) cin>>A[i];
        memset(dp,-1,sizeof(dp));
        
        cout<<solve(0,N)<<endl;
    }
}





Measured memory_bytes: 3532
main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- (map read . words) <$> getLine :: IO [Int]
  print $ count as 0

count :: [Int] -> Int -> Int
count as carry
  | all (\a -> a `mod` 2 == 0) as = count (map (`div` 2) as) (carry + 1)
  | otherwise = carry


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans = 2 * max(a, b);
    cout << (max(a, b) - 1 >= min(a, b) ? --ans : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=2e5+10;
int judge(int n)
{
	 if(n/100000) return 6;
	 if(n/10000)  return 5;
	 if(n/1000)   return 4;
	 if(n/100)    return 3;
	 if(n/10)     return 2;
	 return 1;
}
int init[10];
int main()
{
    int n;
    init[2]=9; init[4]=909; init[6]=90909;
    while(cin>>n)
	{
		int len=judge(n);
    if(len==1)
		cout<<n<<endl;
	if(len==2)
		cout<<init[2]<<endl;
	if(len==3)
		 cout<<init[2]+n-100+1<<endl;
	if(len==4)
		 cout<<init[4]<<endl;
	if(len==5)
		 cout<<init[4]+n-10000+1<<endl;
	if(len==6)
		 cout<<init[6]<<endl;

	}

    return 0;
}


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

typedef struct Point{
	double x, y, z;
}Point;

//ax + bx + c = d
typedef struct Line{
	double a, b, c, d;
}Line;


double sarrus( double A[][3] ){
	double s=0;

	s += A[0][0]*A[1][1]*A[2][2];
	s += A[2][1]*A[1][0]*A[0][2];
	s += A[2][0]*A[0][1]*A[1][2];
	s -= A[0][2]*A[1][1]*A[2][0];
	s -= A[1][0]*A[0][1]*A[2][2];
	s -= A[0][0]*A[1][2]*A[2][1];
	
	return s;
}


Point simul_equation(Line l1, Line l2, Line l3){
	int i;
	Point P;
	double A[3][3];
	double detA;
	double d[3];

	/***Cramer's rule***/
	
	/*Calc d*/
	A[0][0]=l1.a; A[0][1]=l1.b; A[0][2]=l1.c;
	A[1][0]=l2.a; A[1][1]=l2.b; A[1][2]=l2.c;
	A[2][0]=l3.a; A[2][1]=l3.b; A[2][2]=l3.c;
	detA = sarrus( A );

	for( i=0; i<3; i++ ){
		A[0][0]=l1.a; A[0][1]=l1.b; A[0][2]=l1.c;
		A[1][0]=l2.a; A[1][1]=l2.b; A[1][2]=l2.c;
		A[2][0]=l3.a; A[2][1]=l3.b; A[2][2]=l3.c;

		A[0][i]=l1.d;
		A[1][i]=l2.d;
		A[2][i]=l3.d;

		d[i] = sarrus( A );
	}
		
	/*Calc Answer*/
	P.x = d[0]/detA;
	P.y = d[1]/detA;
	P.z = d[2]/detA;
	
	return P;
}

int main(){
	Line l[3];
	Point abc;
	int i, j, n;
	double x, y;
	double px, py;
	double r;

	scanf("%d", &n);

	for( i=0; i<n; i++ ){

		for( j=0; j<3; j++ ){
			scanf("%lf %lf", &x, &y);
			l[j].a=x; l[j].b=y; l[j].c=1; l[j].d=-x*x-y*y;
		}

		//find a, b, c of x^2+y^2+ax+by+c=0
		abc = simul_equation( l[0], l[1], l[2] );
		
		//(x-a)^2+(y-b)^2=c^2 竊絶・ x^2-2ax+a^2+y^2-2by+b^2-c^2=0
		px = -abc.x/2;
		py = -abc.y/2;
		
		r = sqrt( pow(px-x, 2) + pow(py-y, 2) );

		printf("%.3f %.3f %.3f\n", px, py, r );
		
	}
	
	return 0;
}

	

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

const int MOD = (int)1e9+7;

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

	if(N==1 || N==2){
		cout << 0 << endl;
		return 0;
	}
	
	long long ans=0;
	for(long long i=1;i*(i+2)<=N;i++){
		if(N%i==0){
			ans+=(N/i-1);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int max=-1,minVal;
	for(int i=0;i<n;i++){
		int r,v;
		scanf("%d%d",&r,&v);
		if(r>max){
			max=r;
			minVal=v;
		}
	}
	printf("%d\n",max+minVal);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> W;
  int w;
  for(int i = 0; i < N; ++i) {
    cin >> w;
    W.push_back(w);
  }

  int ans = 10000;

  for(int i = 1; i < N; ++i) {
    int s_1 = 0, s_2 = 0;

    for(int j = 0; j <= i; ++j) {
      s_1 += W[j];
    }
    for(int j = i + 1; j < N; ++j) {
      s_2 += W[j];
    }

    ans = min(ans, abs(s_1 - s_2));
  }

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        boolean win = false;
        while (a >= 0 && c >= 0) {
            c = c - b;
            if (c <= 0) {
                win = true;
                break;
            }
            a = a - d;
            if (a <= 0) {
                break;
            }
        }

        System.out.println(win ? "Yes" : "No");


    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 35704
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#define ull unsigned long long
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n;
char s[maxn];
ll ans;
map<ull, int>mp;

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;	
}
 
int main()
{
	read(n);
	scanf("%s", s+1);
	for(int i=0;i<(1<<n);i++)
	{
		ull hs=0, cnt=n;
		for(int j=1;j<=n;j++)
		if(i&(1<<(j-1))) hs=hs*233+s[j]-'a'+1, cnt--;
		while(cnt--) hs*=233;
		cnt=n;
		for(int j=n;j;j--)
		if(!(i&(1<<(j-1)))) hs=hs*233+s[j]-'a'+1, cnt--;
		while(cnt--) hs*=233;
		mp[hs]++;
//		printf("i:%d hs:%llu\n", i, hs);
	}
	for(int i=0;i<(1<<n);i++)
	{
		ull hs=0, cnt=n;
		for(int j=n;j;j--)
		if(!(i&(1<<(j-1)))) hs=hs*233+s[j+n]-'a'+1, cnt--;
		while(cnt--) hs*=233;
		cnt=n;
		for(int j=1;j<=n;j++)
		if(i&(1<<(j-1))) hs=hs*233+s[j+n]-'a'+1, cnt--;
		while(cnt--) hs*=233;
		ans+=mp[hs];
//		if(mp[hs]) printf("%d %llu %d\n", i, hs, mp[hs]);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 33024
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        String s = scan.next();
        String t = scan.next();
        for(int i = 0; i < n; i++){
            System.out.print(s.charAt(i));
            System.out.print(t.charAt(i));
        }
        scan.close();
    }
}

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int num[] = new int[n];
		int arr[] = new int[n];
		int t;
		boolean f = false;
		for (int i = 0; i < n; i++) {
			t = in.nextInt();
			num[i] = t;
			arr[i] = t;
		}
		Arrays.sort(arr);
		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= 0; j--) {
				if (!f && num[i] == arr[j]) {
					f = true;
					continue;
				}
				if (num[i] != arr[j]) {
					System.out.println(arr[j]);
					f = false;
					break;
				} else if (num[i] == arr[j] && f) {
					System.out.println(arr[j]);
					f = false;
					break;
				}
			}
		}
		in.close();
	}
}


Measured memory_bytes: 104620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define _GLIBCXX_DEBAC
using namespace std;
	
int findx(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}



int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int total = 0;
	for (int i = 1; i <= n; i++) {
		int sum = findx(i);
		if (sum >= a and sum <= b) total += i;
	}
	cout << total;
	
	return 0;
}










Measured memory_bytes: 384
import math

r = 999999
sqrt = int(math.sqrt(r))
prime = [1 for i in range(r)]
prime[0] = 0
for i in range(2,r/2):
    prime[2*i-1] = 0
for i in range(3,sqrt,2):
    mx = 2*i
    while mx <= r:
        prime[mx-1] = 0
        mx += i

while True:
    try:
        n = int(raw_input())
        print sum(prime[:n])
    except:
        break

Measured memory_bytes: 43964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int m, k;
  cin >> m >> k;

  int n = (1<<m);

  if (m == 1) {
    if (k == 0) {
      cout << "0 0 1 1" << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (k >= n) {
    cout << -1 << endl;
    return 0;
  }

  cerr << n << endl;
  vector<int> ans;
  rep(i, n) {
    if (i == k) continue;
    ans.push_back(i);
  }
  ans.push_back(k);
  rep(i, n) {
    if (n-1-i == k) continue;
    ans.push_back(n-1-i);
  }
  ans.push_back(k);

  rep(i, n*2) {
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2932
import sys
from itertools import accumulate

circumference, n = map(int, input().split())
lll = list(map(int, sys.stdin.readlines()))
rrr = [circumference - l for l in lll]
rrr.reverse()
lll = [0] + lll
rrr = [0] + rrr
acc_l = list(accumulate(lll))
acc_r = list(accumulate(rrr))

ans = max(lll[-1], rrr[-1])
for take_l in range(1, n):
    take_r = n - take_l

    # l last
    tmp_l = lll[take_l] + 2 * (acc_l[take_l - 1] + acc_r[take_r])
    # r last
    tmp_r = rrr[take_r] + 2 * (acc_r[take_r - 1] + acc_l[take_l])

    if take_l < take_r:
        tmp_l -= 2 * acc_r[take_r - take_l]
        tmp_r -= 2 * acc_r[take_r - 1 - take_l]
    elif take_l > take_r:
        tmp_l -= 2 * acc_l[take_l - 1 - take_r]
        tmp_r -= 2 * acc_l[take_l - take_r]

    ans = max(ans, tmp_l, tmp_r)
print(ans)


Measured memory_bytes: 39432
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
     
    int main() {
        int N, Q;
        cin >> N >> Q;
     
        vector<int> a(N + 1), b(N + 1);
        for (int i = 1; i <= N; ++i) a[i] = b[i] = N;
     
        ll black = ll(N - 2) * (N - 2);
     
        int H = N, W = N;
     
        while (Q--) {
            int t, x;
            cin >> t >> x;
            if (t == 1) {
                if (x < W) {
                    for (int i = x; i < W; ++i) {
                        b[i] = H;
                    }
                    W = x;
                }
                black -= b[x] - 2;
     
            } else {
                if (x < H) {
                    for (int i = x; i < H; ++i) {
                        a[i] = W;
                    }
                    H = x;
                }
                black -= a[x] - 2;
            }
        }
        cout << black << endl;
     
        return 0;
    }

Measured memory_bytes: 4828
// AOJ 0284: Happy End Problem
// 2018.1.30 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define M2	6.283185307179586476925286766559	// 2*pi

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

typedef struct { int id, x, y; } P;
P p[41];
double a[41][41];
int c[41][41];
double dp[41][41][41][41]; char f[41][41][41][41];
int prev[41][41][41][41];
int ans[42];

int cmp(P *a, P *b) { if (a->y - b->y) return a->y - b->y; return a->x - b->x; }
int cross(int i, int j) { return p[i].x*p[j].y - p[i].y*p[j].x; }

int main()
{
	int N, Q, K, i, j, k, m, n;
	int ii, mm;
	double min;

	N = in();
	for (i = 0; i < N; i++) {
		p[i].id = i+1, p[i].x = in(), p[i].y = in();
	}
	qsort(p, N, sizeof(P), cmp);

	for (i = 0; i < N; i++ ) for(j = 0; j < N; j++) {
		c[i][j] = cross(i, j);
		if (i != j) {
			a[i][j] = atan2(p[j].y-p[i].y, p[j].x-p[i].x);
			if (a[i][j] < 0) a[i][j] += M2;
		}
	}

	for (i = 0; i < N; i++) {
		for (j = i+1; j < N; j++) dp[i][1][j][i] = c[i][j], f[i][1][j][i] = 1;
		for (j = 1; j < N; j++) for (k = i+1; k < N; k++) for (m = i; m < N; m++) {
			if (!f[i][j][k][m]) continue;
                         
			for (n = i; n < N; n++) if (n != m && n != k) {
				if (a[m][k] > a[k][n]) continue;
				if (!f[i][j+1][n][k] || dp[i][j+1][n][k] > dp[i][j][k][m] + c[k][n]) {
					dp[i][j+1][n][k] = dp[i][j][k][m] + c[k][n];
					f[i][j+1][n][k] = 1;
					prev[i][j+1][n][k] = m;
				}
			}
		}
	}

    Q = in();
	while (Q--) {
        K = in();
        min = 1e20, ii = mm = 0;
        for (i = 0; i < N; i++) for(m = 0; m < N; m++) {
			if (f[i][K][i][m] && min > dp[i][K][i][m]) {
				min = dp[i][K][i][m];
				ii = i, mm = m;
			}
		}

		if (min == 1e20) { puts("NA"); continue; }
		for (k = ii, i = 0; i < K; i++) {
			j = prev[ii][K-i][k][mm];
			k = mm, mm = j;
			ans[K-1-i] = p[k].id;
        }

		printf("%d", ans[0]);
		for (i = 1; i < K; i++) printf(" %d", ans[i]);
        putchar('\n');
    }
}


Measured memory_bytes: 9288
#include <iostream>
#include <cstdlib>

double a, b, c, d, e, f;

bool get_input()
{
	return (std::cin >> a >> b >> c >> d >> e >> f);
}

void solve()
{
	double det = a * e - b * d;
	double x, y;

	x = (c * e - b * f) / det;
	y = (a * f - c * d) / det;

	if (x == 0) x = 0.000;
	if (y == 0) y = 0.000;

	std::cout.setf(std::ios::fixed, std::ios::floatfield);
	std::cout.precision(3);
	std::cout << x << ' ' << y << std::endl;
}


int main()
{
	while (get_input()) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int h=0;h < 241;h++){
			if(n >= 3600){
				n = n-3600;
			}else{
				System.out.print(h+":");
				break;
			}
		}
		for(int m=0;m < 60;m++){
			if(n >=60){
				n = n-60;
			}else{
				System.out.println(m+":"+n);
				break;
			}
		}
	}
}

Measured memory_bytes: 17360
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;

const int S = 1000010;
int dp[S][2];

signed main() {
    rep(i,1,S) rep(j,0,2) dp[i][j] = INF;
    repq(i,1,210) rep(j,0,S) {
        int d = i * (i+1) * (i+2) / 6;
        if(j-d < 0) continue;
        chmin(dp[j][0], dp[j-d][0] + 1);
        if(d % 2) chmin(dp[j][1], dp[j-d][1] + 1);
    }

    while(cin >> N, N) {
        printf("%lld %lld\n", dp[N][0], dp[N][1]);
    }
    return 0;
}

Measured memory_bytes: 18832
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let (n, _m, x, y) = {
        let i = read::<isize>();
        (i[0], i[1], i[2], i[3])
    };

    let mut xn = read::<isize>();
    let mut ym = read::<isize>();

    xn.sort();
    ym.sort();

    let n = n as usize;

    if xn[n-1] < ym[0] && xn[n-1] < y && ym[0] > x && y-x > 1{
        println!("No War");
    } else {
        println!("War");
    }   
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

bool cmp(const pair<LL, LL> &x, const pair<LL, LL> &y)
{
    if(x.first==y.first){
        return x.second > y.second;
    }else{
        return x.first < y.first;
    }
}

int main() {
    int n;
    int m;
    vector<pair<LL, LL>> ab;
    LL tmp_a;
    LL tmp_b;
    vector<LL> a;
    vector<LL> b;
    priority_queue<LL> PQ;
    LL ans=0;
    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> tmp_a >> tmp_b;
        ab.push_back(make_pair(tmp_a, tmp_b));
    }
    sort(ab.begin(),ab.end(),cmp);

    for(int i=0; i<n; i++){
        a.push_back(ab[i].first);
        b.push_back(ab[i].second);
    }

    for(int i=1; i<=m; i++){
        auto pos_start=lower_bound(a.begin(), a.end(), i);
        auto pos_end=lower_bound(a.begin(), a.end(), i+1);
        int idx_start=distance(a.begin(), pos_start);
        int idx_end=distance(a.begin(), pos_end);
        for(int i=idx_start; i<idx_end; i++){
            PQ.push(b[i]);
        }
        if(!PQ.empty()){
            ans+=PQ.top();
            PQ.pop();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5488
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int main(void){
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		h[i] = tmp;
	}

	ll dp[100010] = {INF};

	dp[0] = 0;

	dp[1] = abs(h[1] - h[0]);

	for(int i = 2; i < n; i++){
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
		// cout << dp[i] << endl;
	}

	cout << dp[n - 1] << endl;


}


Measured memory_bytes: 1408
def main():
    H, W = map(int, input().split())
    a = [input() for _ in range(H)]
    row = [False] * H
    col = [False] * W

    for i in range(H):
        for j in range(W):
            if a[i][j] == '#':
                row[i] = True
                col[j] = True
    for i in range(H):
        if row[i] is True:
            for j in range(W):
                if col[j] is True:
                    print(a[i][j], end='')
            print()


main()


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

int main(){
  int A, B;
  int cnt = 0;
  int tmp;
  cin >> A >> B;
  for(int i = A; i <= B; i++){
    tmp = i;
    if(tmp / 10000 == tmp % 10){
      tmp %= 10000;
      if(tmp / 1000 == (tmp % 100)/10){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>

#define MAXN 100000
#define MAXQ 50000

using namespace std;

int n,q;
int S[MAXN+1],T[MAXQ+1];
int cnt=0;

bool binarySearch( int num )
{
	int lo,mi,hi;
	bool res=false;
	lo=0;
	mi=hi=n;
	while( lo <= hi ) {
		mi=(lo+hi)/2;
		if( num < S[mi] ) {
			hi=mi-1;
		} else if( S[mi] < num ) {
			lo=mi+1;
		} else {
			res=true;
			break;
		}
	}
	

	return res;
}

int main()
{
	cin>>n;
	for( int i=0; i<n; i++ ) {
		cin>>S[i];
	}

	cin>>q;
	for( int i=0; i<q; i++ ) {
		cin>>T[i];
		cnt += binarySearch( T[i] );
	}
	cout<<cnt<<endl;
	
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    k--;

    string s;
    cin >> s;
    if(s.at(k) == 'A') {
        s.at(k) = 'a';
        
    }else if(s.at(k) == 'B') {
        s.at(k) = 'b';
    }else if(s.at(k) == 'C') {
        s.at(k) = 'c';
    } else {
        cout << "入力がおかしい" << endl;
        return 0;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int prime[200],dprime[100];
int dp[2000001],ddp[2000001];
int main(){
	int a=1,b=2,count=1,dcount=1;
	prime[0]=1,dprime[0]=1;
	while(true){
		a+=b;
		b++;
		if(prime[count-1]+a>=1000000)
			break;
		if((prime[count-1]+a)%2==1){
			dprime[dcount]=prime[count-1]+a;
			dcount++;
		}
		prime[count]=prime[count-1]+a;
		count++;
	}
	for(int i=0;i<=2000000;i++)
			dp[i]=i%4+i/4;
	for(int i=0;i<=999999;i++){
		for(int j=0;j<count;j++)
			dp[i+prime[j]]=min(dp[i+prime[j]],dp[i]+1);
	}
	for(int i=0;i<=2000000;i++)
			ddp[i]=i%35+i/35;
	for(int i=0;i<=999999;i++){
		for(int j=0;j<dcount;j++)
			ddp[i+dprime[j]]=min(ddp[i+dprime[j]],ddp[i]+1);
	}
	int n;
	while(true){
		cin>>n;
		if(n==0)
			break;
		cout<<dp[n]<<" "<<ddp[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 16784
#include<iostream>
#include<algorithm>
#include <string>
#include <cstring>
#include<climits>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll d[2000010]; 
ll go(ll x, ll y) {
	if (y == 0)return 1;
	else if (y == 1)return x;
	else if (y == 2)return x * x % mod;
	else if (y & 1) {
		return (x * go(x, y - 1)) % mod;
	}
	else {
		ll tmp = go(x, y / 2) %  mod;
		return (tmp * tmp) % mod;
	}
}
ll go2(ll x, ll y) {
	if (x == 0 && y == 0)return 0;
	ll cnt = d[x];
	ll tmp = d[y] * (d[x - y]) % mod;
	tmp = go(tmp, mod - 2);
	cnt *= tmp; cnt %= mod;
	return cnt;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	ll r, c, r1, c1; cin >> r >> c >> r1 >> c1;
	ll ans = 0;
	d[0] = 1;
	d[1] = 1;
	for (ll i = 2; i <= 2000002; i++) {
		d[i] = d[i - 1] * i; d[i] %= mod;
	}

	ans = go2(r1 + c1 + 2, r1 + 1);
	ll tmp = go2(c1 + r + 1, r);
	ans -= tmp;
	while (ans < 0)ans += mod;
	ans %= mod;
	tmp = go2(r1 + c + 1, r1 + 1);
	tmp -= go2(r + c, r); 
	while (tmp < 0)tmp += mod;
	ans -= tmp;
	while (ans < 0)ans += mod;

	cout << ans << '\n';



}

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

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

int main() {
    ll N, A, B;
    cin>>N>>A>>B;
    ll ans = 0;
    for (ll n = 1; n <= N; n++) {
        string str = to_string(n);
        ll sum = 0;
        for (ll l = 0; l < str.length(); l++) sum += str[l] - '0';
        if (A <= sum && sum <= B) ans += n;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.*;

/**
 *
 * @author Admin
 */
public class Main {
    
    
    public static void main(String args[])
    {
    Scanner s=new Scanner(System.in);
    
    int ss=s.nextInt();
    
    int w=s.nextInt();
    
    if(ss>w)
        System.out.println("safe");
    else
    System.out.println("unsafe");
   
         
    
    
    
    }
    
    
}


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

int main(){
	int n;
	cin >> n;
	vector<int> A(n+1);
	vector<int> B(n);
	for(int i=0;i<n+1;++i){
		cin >> A[i];
	}
	for(int i=0;i<n;++i){
		cin >> B[i];
	}
	
	long long res = 0;
	for(int i=0;i<n;++i){
		int tmp = min(A[i],B[i]);
		res += tmp;
		A[i] -= tmp; B[i] -=tmp;
		
		tmp = min(B[i],A[i+1]);
		res += tmp;
		A[i+1] -= tmp; B[i] -=tmp;
	}
	
	cout << res <<endl;
	
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

int main() {
;
    int	a, b, x;

    std::cin >>	a;
    std::cin >>	b;
    std::cin >>	x;

    if ((x >= a) && (x <= a+b))
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,K;
    cin>>N>>K;
    map<ll,ll> m;
    rep(i,N){
        ll a;
        cin>>a;
        m[a]++;
    }
    vl num;
    for(auto p:m){
        ll X=p.second;
        num.pb(X);
    }
    sort(all(num));
    ll y=num.size();
    ll Ans=0;
    ll i=0;
    while(y>K){
        y--;
        Ans+=num.at(i);
        i++;
    }
    cout<<Ans<<endl;
}


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


int main()
{
	int n,count=0,max=0;
	cin>>n;
	int arr[n+10];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int i=n-1;i>0;i--)
	{
		if(arr[i]<=arr[i-1])
			count++;
		else
			count=0;
		if(count>max)
			max=count;
	}
	cout<<max;
}

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

using namespace std;

int n, k, a[100010], dp[100010];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for(int i = 0; i < 100010; i++) {
		for(int j = 0; j < n; j++) {
			if(i + a[j] < 100010) {
				if(dp[i] == 0) {
					if(dp[i + a[j]] == 0)
					dp[i + a[j]] = 1;
				}
			}
		}
	}
	if(dp[k] == 0) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int X[] = {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};
    int K;
    cin >> K;
    cout << X[K-1]<< endl;

    return 0;    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int N, M;
    while (cin >> N >> M, N || M)
    {
        vector<pair<int, int>> vp;
        for (int i = 0; i < N; ++i)
        {
            int D, P;
            cin >> D >> P;
            vp.push_back({P, D});
        }

        sort(vp.begin(), vp.end());
        reverse(vp.begin(), vp.end());

        ll ans = 0;
        for (int i = 0; i < N; ++i)
        {

            if (M == 0)
            {
                ans += vp[i].second * vp[i].first;
                continue;
            }
            if (M >= vp[i].second)
            {
                M -= vp[i].second;
            }
            else if (M - vp[i].second < 0)
            {
                ans += (vp[i].second - M) * vp[i].first;
                M = 0;
            }
            //cout << vp[i].first << " " << vp[i].second << endl;
        }
        cout << ans << endl;
    }
    return 0;
}


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

typedef long long ll;

const int Maxn = 200005;

int n;
ll k;
int a[Maxn];
int f[Maxn];
ll res;

bool Ok(ll al)
{
    ll res = 0;
    for (int i = 0; i < n; i++) {
        ll nd = al / f[n - 1 - i];
        if (a[i] > nd) res += a[i] - nd;
    }
    return res <= k;
}

int main()
{
    scanf("%d %lld", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for (int i = 0; i < n; i++)
        scanf("%d", &f[i]);
    sort(a, a + n); sort(f, f + n);
    ll lef = 0, rig = 1000000000000000000ll;
    while (lef <= rig) {
        ll mid = lef + rig >> 1ll;
        if (Ok(mid)) rig = mid - 1;
        else lef = mid + 1;
    }
    cout << rig + 1 << endl;
    return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m, s;
    cin >> n >> m >> s;
    int C = 55 * 55;
    yukari<pair<int, i64>> g(n * C);
    for (int i = 0; i < m; i++)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        for (int j = 0; j < C - 1; j++)
        {
            g[n * min(j + a, C - 1) + u].emplace_back(n * j + v, b);
            g[n * min(j + a, C - 1) + v].emplace_back(n * j + u, b);
        }
    }
    for (int i = 0; i < n; i++)
    {
        int c, d;
        cin >> c >> d;
        for (int j = 0; j < C - 1; j++)
        {
            g[n * j + i].emplace_back(n * min(j + c, C - 1) + i, d);
        }
    }
    akari<i64> dp(n * C + 10, 1e15);
    akane<pair<i64, int>> pq;
    s = min(s, 51 * 51);
    dp[n * s] = 0;
    pq.push({0, n * s});
    while (!pq.empty())
    {
        auto p = pq.top();
        pq.pop();
        int v = p.second;
        i64 c = p.first;
        //print(v % n, c);
        for (auto &e : g[v])
        {
            int nv = e.first;
            i64 nc = c + e.second;
            if (dp[nv] > nc)
            {
                dp[nv] = nc;
                pq.push({nc, nv});
            }
        }
    }
    for (int v = 1; v < n; v++)
    {
        i64 ans = 1e15;
        for (int j = 0; j < C; j++)
        {
            ans = min(ans, dp[j * n + v]);
        }
        cout << ans << endl;
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 27796