akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split(" "))
l_init,r_init=map(int,input().split(" "))
ans_l=l_init
ans_r=r_init
isPossible=True
for i in range(m-1):
	l,r=map(int,input().split(" "))
	isupdated=False
	next_ans_l=ans_l
	next_ans_r=ans_r
	if ans_l <= l and l <= ans_r:
		next_ans_l=l
		isupdated=True
	if ans_l <= r and r <= ans_r:
		next_ans_r=r
		isupdated=True
	if l <= ans_l and ans_r <= r:
		isupdated=True
	if not isupdated:
		isPossible=False
		break
	ans_l=next_ans_l
	ans_r=next_ans_r
ans=ans_r-ans_l
if isPossible:
	print(ans+1)
else:
	print(0)

Measured memory_bytes: 3064
from collections import deque

h, w = map(int, input().split())
c = [list(input()) for _ in range(h)]

q = deque([])

for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            q.append([i, j])
            c[i][j] = 0

p = q.popleft()
max = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
while True:
    xx = p[0]
    yy = p[1]
    for i in range(4):
        x = xx + dx[i]
        y = yy + dy[i]
        if x < 0 or x > h - 1 or y < 0 or w - 1 < y:
            continue
        if c[x][y] == '.':
            q.append([x, y])
            count = c[xx][yy] + 1
            if max < count:
                max = count
            c[x][y] = count
    if len(q) == 0:
        break
    p = q.popleft()
print(max)


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

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    A--; B--; C--; D--;
    if (D < C)
    {
        bool ans = true;
        for (int i = A + 1; i < C; i++)
        {
            if (S[i] == '#' && S[i + 1] == '#')
            {
                ans = false;
            }
        }
        bool ans2 = false;
        for (int i = B; i <= D; i++)
        {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.')
            {
                ans2 = true;
            }
        }
        if (ans && ans2)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        bool ans = true;
        for (int i = A + 1; i < C; i++)
        {
            if (S[i] == '#' && S[i + 1] == '#')
            {
                ans = false;
            }
        }
        for (int i = B + 1; i < D; i++)
        {
            if (S[i] == '#' && S[i + 1] == '#')
            {
                ans = false;
            }
        }
        if (ans)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 640
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで標準include

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<pair<int,int>>data(n);
	for (int i = 0; i < n; i++) {
		cin >> data.at(i).first >> data.at(i).second;
	}
	sort(data.begin(), data.end());
	cout << data.at(n - 1).first + data.at(n - 1).second << endl;
}


Measured memory_bytes: 1024
N = int(input())
S = list(input())
alphabet=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
S_2=[]
for s in S:
    if alphabet.index(s)+N <= len(alphabet)-1:
        index = alphabet.index(s)+N
        S_2.append(alphabet[index])
    else:
        index = alphabet.index(s)+N - len(alphabet)
        S_2.append(alphabet[index])
print(''.join(S_2))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
 
struct segtree{
	static const int N=1<<18;
	int seg[N*2];
	segtree(){
		rep(i,N*2) seg[i]=0;
	}
	void update(int x,int v){
		x+=N;
		seg[x]=v;
		x/=2;
		while(x){
			seg[x]=max(seg[x*2],seg[x*2+1]);
			x/=2;
		}
	}
	int getmax(int a,int b,int l=0,int r=N,int k=1){
		if(b<=l||r<=a) return 0;
		if(a<=l&&r<=b) return seg[k];
		return max(getmax(a,b,l,(l+r)/2,k*2),getmax(a,b,(l+r)/2,r,k*2+1));
	}
}seg;
 
 
double pi = acos(-1);
const int MN = 200010;
ll sx,sy,tx,ty;
ll N;
ll x[MN],y[MN];
 
void input(){
	bool swapped = 0;
	cin>>sx>>sy>>tx>>ty;
	if(sy==ty){
		swapped = 1;
		swap(sx,sy);
		swap(tx,ty);
	}
	cin>>N;
	rep(i,N){
		cin>>x[i]>>y[i];
		if(swapped) swap(x[i],y[i]);
	}
}
int main(){
	input();
 
	if(sx==tx){
		bool is = 0;
		if(sy>ty) swap(sy,ty);
		rep(i,N){
			if(x[i] == sx && sy<y[i] && y[i]<ty) is = 1;
		}
		double ans = (ty-sy)*100;
		if(is)  ans += -20 + 10*pi;
		printf("%.12f\n",ans);
		return 0;
	}
 
	if(sx>tx){
		swap(sx,tx);swap(sy,ty);
	}
	if(sy>ty){
		int X = 1e8;
		sy = X - sy;
		ty = X - ty;
		rep(i,N) y[i] = X - y[i];
	}
 
	using P = pair<int,int>;
	vector<P> ps;
	rep(i,N){
		if(sx<=x[i]&&x[i]<=tx&&sy<=y[i]&&y[i]<=ty) ps.pb(P(x[i],y[i]));
	}
	sort(all(ps));
	N = ps.size();
	vector<int> xs,ys;
	for(P p:ps){
		ys.pb(p.sc);
	}
	sort(all(ys));
	rep(i,N){
		y[i] = lower_bound(all(ys),ps[i].sc) - ys.begin();
	}
	int is = 0;
	rep(i,N){
		int v = seg.getmax(0,y[i])+1;
		seg.update(y[i],v);
		chmax(is,v);
	}
	double ans = ((tx-sx) + (ty-sy))*100 - is*(20-5*pi);
	if(is == min(tx-sx,ty-sy)+1){
		ans = ((tx-sx) + (ty-sy))*100 - (is-1)*(20-5*pi) + (-20 + 10*pi);
	}
	printf("%.12f\n",ans);
}

Measured memory_bytes: 8816
let () =
  let a = Array.make 100 0 in
  let drop (x, y) =
    if x >= 0 && x <=9 && y >= 0 && y <= 9 then a.(10*y + x) <- a.(10*y + x) + 1 in
  let rec doit (x, y) = function
    | 1 -> List.iter drop [(x, y - 1); (x - 1, y); (x, y); (x + 1, y); (x, y + 1)]
    | 2 ->
      doit (x, y) 1;
      List.iter drop [(x - 1, y - 1); (x + 1, y - 1); (x - 1, y + 1); (x + 1, y + 1)]
    | 3 ->
      doit (x, y) 2;
      List.iter drop [(x, y - 2); (x - 2, y); (x + 2, y); (x, y + 2)]
    | _ -> assert false in
  try
    while true do
      let (x, y, s) = Scanf.scanf "%d,%d,%d " (fun x y s -> x, y, s) in
      doit (x, y) s
    done
  with _ ->
    Array.fold_left (fun z e -> z + if e = 0 then 1 else 0) 0 a |> Printf.printf "%d\n";
    Array.fold_left (fun z e -> max z e) 0 a |> Printf.printf "%d\n"

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

double a, b, x;


int main(){

	cin >> a >> b >> x;

	double t_rad, t_deg;
	if (x > a * a * b / 2) {
		t_rad = atan(2 * (a * a * b - x) / (a * a * a));
	} else {
		t_rad = atan(a * b * b / (2 * x));
	}

	t_deg = t_rad * 180.0 / M_PI;

	cout << fixed << setprecision(10);
	cout << t_deg << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define inf 1000000
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int n, G[MAX][MAX];

int prim();

int main(){
  int i, j, e;

  scanf("%d", &n);  
 
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      //scanf("%d",&e);
      scanf("%d", &G[i][j]);
      if(G[i][j] == NIL)    G[i][j] = inf;
      //G[i][j] = (e == NIL) ? inf : e;//if=true -> inf
      //printf("G[%d][%d] = %7d, e = %2d | ", i, j, G[i][j], e);
    }
    //    printf("\n");
  }

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

  return 0;
}

int prim(){
  int u, mincost, i, v, sum = 0;
  int d[MAX], pi[MAX], color[MAX];

  for(u = 0; u < n; u++){
    d[u] = inf;
    pi[u] = NIL;
    color[u] = WHITE;
  }

  d[0] = 0;

  while(1){
    mincost = inf;
    //u = NIL;
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    //if(u == NIL) break;
    if(mincost == inf) break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && G[u][v] < d[v]){
	//if(d[v] > G[u][v]){
	  pi[v] = u;
	  d[v] = G[u][v];
	  //color[v] = GRAY;
	  //	}
      }
    }
  }

  for(i = 0; i < n; i++){
    if(pi[i] != NIL){
      sum += G[i][pi[i]];
    }
  }

  return sum;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
const int maxn=1e3+7;
int main()
{
    int a[maxn][maxn];
    bool b[maxn];
    int c[maxn]={};
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        c[i]=1;
        for(int j=1;j<n;j++)
            scanf("%d",&a[i][j]);
    }
    int sum=0,s=1;
    while(s==1){
        s=0;
        for(int i=1;i<=n;i++)
            b[i]=0;
        for(int i=1;i<=n;i++){
            if (c[i]==n) continue;
            int v=a[i][c[i]];
            if(!b[i]&&!b[v]&&i==a[v][c[v]]){
                s=1;
                c[i]++;
                c[v]++;
                b[i]=b[v]=1;
            }
        }
        if(s==1) sum++;
        else {
            for(int i=1;i<=n;i++)
            if(c[i]<n){
                printf("-1\n");
                return 0;
            }
            printf("%d\n",sum);return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int check(string l[],string a,int j){
	for(int i=0;i<j;i++){
		if(a==l[i]) return i;
	}
	return 1000;
}
int main(){
	string l[300],a;
	int n[300]={0},b,r,j=0;
	cin>>b;
	for(int i=0;i<b;i++){
		cin>>a;
		if(check(l,a,j)==1000)
		{
			l[j]=a;n[j]=1;j++;
		}
		else n[check(l,a,j)]++;
	}
	cin>>r;
	for(int i=0;i<r;i++){
		cin>>a;
		if(check(l,a,j)!=1000)
		{
			n[check(l,a,j)]--;
		}
	}
	sort(n,n+j,greater<int>());
	if(n[0]<0) cout<<"0";
	else cout<<n[0];
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  if(N==1){cout<<1<<endl<<1<<endl;}
  else if(N==2){cout<<2<<endl<<0<<endl<<11<<endl;}
  else{
    cout<<N-1<<endl;
    for(int i=2;i<=N;i++){
      cout<<0;
      for(int j=1;j+1<i;j++){cout<<1;}
      cout<<0<<endl;
    }
  }

  return 0;
}



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

using namespace std;

string str;

long long dfs(int now, long long score) {
	if (str.size() == now) {
		return score;
	}
	if (now == 0) {
		return dfs(now + 1, str[now] - '0');
	}
	int res = score * pow(2, str.size() - now - 1);
	return dfs(now + 1, score * 10 + (str[now] - '0')) + res + dfs(now + 1, (str[now] - '0'));
}

void hawawa()
{
	cin >> str;
	cout << dfs(0, 0) << "\n";
}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
#define ll long long
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)(x.size())
#define all(x) (x).begin(),(x).end()
template<typename tp> void read(tp &x) {cin >> x;}
template<typename tp, typename... Args> void read(tp& x, Args&... args) {read(x);read(args...);}
const int mxN = (int)1e5,INF = (int)1e9,MOD = (int)1e9+7;

void solve()
{
	int n;
	read(n);
	int h[n];
	FOR(i,n) read(h[i]);
	int dp[n];
	dp[0] = 0,dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
		dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
	cout << dp[n-1] << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int test = 1;
	//read(test);
	while(test--)
		solve();
	return 0;
}



Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int ans=0;
    for(int i=l; i<=r; i++){
        if(i%d==0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
s = input()
if len(s) % 2 == 0:
    l = s[:int(len(s) / 2)]
    r = s[int(len(s) / 2):]
else:
    l = s[:len(s) // 2]
    r = s[(len(s) // 2) + 1:]
r = r[::-1]
ans = 0
for i in range(len(l)):
    if l[i] != r[i]: ans += 1
print(ans)

Measured memory_bytes: 9040
import java.util.*;

public class Main {

    static int MOD = 1000000007;
    public static void main(String[] args) {

        int ans=0;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();

        for(int i=0;i<n+1;i++)for(int j=0;j<n-i+1;j++){
            int k=n-i-j;
            if(y==i*10000+j*5000+1000*k){
                System.out.println(i+" "+ j+" "+k);
                return;
            }
        }

        System.out.println("-1 -1 -1");
    }

}


Measured memory_bytes: 22100
// start: 3:12

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

class Rec {
public:
    int x;
    int y;
    int d;
    int cost;

    Rec( int xx, int yy, int dd, int s): x(xx), y(yy), d(dd), cost(s){}
};

bool operator< (const Rec& rec1, const Rec &rec2) {
    return rec1.cost > rec2.cost;
}
bool operator> (const Rec& rec1, const Rec &rec2) {
    return rec1.cost < rec2.cost;
}

int mx[4][4] = {{1, 0, -1, 0},
                {0, -1, 0, 1},
                {-1, 0, 1, 0},
                {0, 1, 0, -1}};
int my[4][4] = {{0, 1, 0, -1},
                {1, 0, -1, 0},
                {0, -1, 0, 1},
                {-1, 0, 1, 0}};

void dump(vector<vector<int> > &f, int x = -1, int y = -1) {
    REP(i, f.size()) {
        REP(j, f[i].size()) {
            if ( i == x, j == y ) cout << "# ";
            else cout << f[i][j] << " ";
        }
        cout << endl;
    }
}

int main() {
    int w, h;

    while(cin >> w >> h, w||h) {
        // cout << w << " " << h << endl;
        priority_queue< Rec, vector<Rec>, less<vector<Rec>::value_type> > pq;

        vector< vector<int> > f(h, vector<int>(w));
        int closed[h][w][4];
        int COST[4];

        REP(y, h) REP(x, w) REP(i, 4) closed[y][x][i] = INF;

        REP(y, h) REP(x, w) cin >> f[y][x];
        REP(i, 4) cin >> COST[i];

        // dump(f);

        pq.push( Rec(0, 0, 0, 0));

        closed[0][0][0] = 0;

        while(!pq.empty()) {

            Rec tmp = pq.top(); pq.pop();
            int x = tmp.x,
                y = tmp.y,
                d = tmp.d,
                cost = tmp.cost,
                o = f[y][x];

            // printf("n:%d %d %d: %d\n", x, y, d, (0 <= x && x < w && 0 <= y && y < h));

            // ゴール
            if ( x == w-1 && y == h-1 ) {
                cout << cost << endl;
                break;
            }

            int nx = x + mx[d][o],
                ny = y + my[d][o],
                nd = (d+o) % 4;

            // マス目移動
            if ( o != 4 && 0 <= nx && nx < w && 0 <= ny && ny < h && cost < closed[ny][nx][nd] ) pq.push( Rec(nx, ny, nd, cost) );

            // 命令出す
            REP(i, 4) {
                if ( i == o ) continue; // マス目の命令と同じ

                int nx = x + mx[d][i],
                    ny = y + my[d][i],
                    nd = (d+i)%4;

                if ( 0 <= nx && nx < w && 0 <= ny && ny < h && cost+COST[i] < closed[ny][nx][nd] ) {
                    pq.push( Rec(nx, ny, nd, cost+COST[i]) );
                    closed[ny][nx][nd] = cost+COST[i];
                }
            }
        }
    }

    return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const char mp[] = "RYGB";
int n, m, d;

int get(int i, int j) {
  return (((j + 3) % 4 + 1) + ((i & 1) ? 0 : 2) + 3) % 4;
}

int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = (i + j + 19260817) / d;
      int y = (i - j + 19260817) / d;
      putchar(mp[get(x, y)]);
    }
    putchar(10);
  }
  return 0;
}

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

bool sosuu(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double dtmp = sqrt(num);
    for (int i = 3; i <= dtmp; i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}

int main()
{
    ll N; cin >> N;
    vector<ll> ans(N, 0);
    ll num = pow(10, 5);
    vector<ll> jj(num, 0);

    for (int i = 1; i <= num; i += 2) {
        ll t = (i+1) / 2;
        if (sosuu(i) == true && sosuu(t) == true) {
            jj[i-1] = 1;
        }
    }

    vector<ll> RR(num, 0);
    ll num3 = 0;
    for (int i = 0; i < num; ++i) {
        if (jj[i] == 1) num3++;
        RR[i] = num3;
    }

    ll num2 = 0;
    rep(i,N) {
        ll l, r; cin >> l >> r;
        ll lt = l - 2;
        if (lt < 0) lt = 0;
        ll rt = r - 1;
        if (rt < 0) rt = 0; 
        ans[i] = RR[rt] - RR[lt];
    }
    rep(i,N) {
        cout << ans[i] << endl;
    }



}


Measured memory_bytes: 5508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll n, t, ans = 1l, hs[100005];
vector<ll>A;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll fastpow_mod(ll a, ll b);
int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		A.push_back(t);
		hs[t]++;
	}
	if (A[0] != 0)
	{
		cout << 0 << endl;
		return 0;
	}
	SORT_UNIQUE(A);
	ll len = A.size();
	if (A[len - 1] != len - 1 || hs[0] != 1)
	{
		cout << 0 << endl;
	}
	else
	{
		for (int i = 2; i < len; i++)
		{
			ans = ans * fastpow_mod(hs[i - 1], hs[i]) % MOD;
		}
		cout << ans << endl;
	}
	return 0;
}
ll fastpow_mod(ll a, ll b)
{
	ll ans = 1;
	ll base = a % MOD;
	while (b)
	{
		if ((b & 1) != 0)
		{
			ans = ans * base % MOD;
		}
		b = b >> 1;
		base = base * base % MOD;
	}
	return ans;
}

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

using namespace std;
typedef long long ll;

ll res[50];
ll K;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> K;
    for (int i = 0; i < 50; i++)
        res[i] = 49 + (K / 50);
    for (int i = 0; i < K % 50; i++)
    {
        for (int j = 0; j < 50; j++)
            if (j == i) res[j] += 50;
            else res[j]--;
    }
    cout << "50\n";
    for (int i = 0; i < 50; i++)
        cout << res[i] << " ";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication22 {
    class Program {
        static void Main(string[] args) {
            string x = Console.ReadLine();
            var result = Method(x);
            Console.WriteLine(result.Length);
        }
        private static string Method(string x) {
              string result = "";
              var  first = x.IndexOf("A");//最初
              var  last = x.LastIndexOf("Z");//末尾

            result = x.Substring(first, last - first);
            return result +1;//0始まりで数えているので+1してあげる
        }
    }
}


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

#define rep(i, n) for(int i=0; i<n; i++)
#define erev(i, m, n) for(int i=n; i>=m; i--)
typedef long long int ll;

const ll MOD = 1000000007LL;
int N;
ll W;
ll w[222];
ll dp[11111];
ll v[222];

int main(int argc, char *argv[])
{
  cin >> N >> W;
  rep(i, N) cin >> w[i];

  sort(w, w + N, greater<int>());
  dp[0] = 1LL;
  ll res = 0LL;
  rep(i, N) v[N - i - 1] = v[N - i] + w[N - i - 1];
  reverse(v, v + N + 1);
  rep(i, N){
    erev(j, 0, W){
      if(W - w[i] < v[N - i - 1] + j && v[N - i - 1] + j <= W) res = (res + dp[j]) % MOD;
      if(j - w[i] >= 0) dp[j] = (dp[j] + dp[j - w[i]]) % MOD;
    }
  }
  
  cout << max(1LL, res) << endl;
  
  return 0;
}

Measured memory_bytes: 1256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
	class Program
	{
		static void Main(string[] args)
		{


			//テンプレート
			//// 整数の入力
			//int a = int.Parse(Console.ReadLine());

			//// スペース区切りの整数の入力
			//string[] input = Console.ReadLine().Split(' ');
			//int b = int.Parse(input[0]);
			//int c = int.Parse(input[1]);

			//// 文字列の入力
			//string s = Console.ReadLine();

			////出力
			//Console.WriteLine(a + b + c + " " + s);

			//A

			//string[] input = Console.ReadLine().Split(' ');
			//int s = int.Parse(input[0]);
			//int w = int.Parse(input[1]);

			//if (s <= w)
			//{
			//	Console.WriteLine("unsafe");
			//}
			//else
			//{
			//	Console.WriteLine("safe");
			//}

			//Console.ReadLine();

			//B
			//string[] input = Console.ReadLine().Split(' ');
			//var a = Double.Parse(input[0]);
			//var b = Double.Parse(input[1]);
			//var c = Double.Parse(input[2]);
			//var d = Double.Parse(input[3]);

			//double p1 = Math.Ceiling(c / b);
			//double p2 = Math.Ceiling(a / d);

			//if (p1 <= p2)
			//	Console.WriteLine("Yes");
			//else
			//	Console.WriteLine("No");

			//Console.ReadLine();

			//C.
			int n = int.Parse(Console.ReadLine());
			string[] s = new string[n];

			for(int j = 0;j < n; j++)
			{
				var check = Console.ReadLine().ToLower();

				s[j] = check;
			}


			string[] answer = s.Distinct().ToArray();

			Console.WriteLine(answer.Length);
			Console.ReadLine();
		}
	}
}

Measured memory_bytes: 50044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0; i<n; i++)
#define rep(i,start,n) for(int i=start; i<n; i++)

void solve(){
	int n;cin>>n;
	cout<<(n*(n-1))/(2)<<endl;
}	
signed main(){
    fast;    
    // int t;cin>>t;while(t--)
    solve();    
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;

string s;
int solve(int x)
{
	int n=s.length();
	vi pre(n);
	vi suf(n);
	for(int i=0;i<n;i++)
	{
		if(s[i]=='1') pre[i]=1;
		else pre[i]=-1;
		if(i) pre[i]+=pre[i-1];
	}
	for(int i=n-1;i>=0;i--)
	{
		suf[i]=pre[i];
		if(i!=n-1) suf[i]=max(suf[i],suf[i+1]);
	}
	int mi=0;
	int cur=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='?'&&suf[i]+2+cur<=x)
			cur+=2;
		mi=min(mi,pre[i]+cur);
	}
	return x-mi;
}
int main()
{
	cin>>s;
	if(s.length()==1)
	{
		print(1);
		return 0;
	}
	int cur=0,mx=0;
	for(auto u:s)
	{
		if(u=='?'||u=='0')
			cur--;
		else cur++;
		mx=max(mx,cur);
	}
	//dbg(mx);
	//for(int i=mx;i<mx+20;i++) dbg(i,solve(i));
	print(min(solve(mx),solve(mx+1)));
}


Measured memory_bytes: 12128
import sys


def solve():
    input = sys.stdin.readline
    S = list(input().replace("B", "2").replace("W", "1"))[:-1]
    N = len(S)
    ans = N * (N - 1) // 2
    data = [0] * (N + 1)

    def add(k, v):
        while k <= N:
            data[k] += v
            k += k & -k

    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    for a in map({a: i + 1 for i, a in enumerate(sorted(S))}.__getitem__, S):
        ans -= get(a)
        add(a, 1)

    print(ans)


solve()


Measured memory_bytes: 9736
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
using namespace std;

int gcd(int x, int y) {
	if(y == 0) return x;
	return gcd(y, x%y);
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  vector<int> G[100001];
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int used[100001]={};
  int cntf=0,cnts=0;
  queue<P> fq,sq;
  fq.push(P(1,0));
  sq.push(P(n,0));
  int t=0;
  while(!fq.empty()||!sq.empty()){
    while(!fq.empty()&&fq.front().second==t){
      int to=fq.front().first;
      fq.pop();
      if(!used[to]){
	//cout<<to<<endl;
	for(int i=0;i<G[to].size();i++)fq.push(P(G[to][i],t+1));
	used[to]=1;
	cntf++;
      }
    }
    while(!sq.empty()&&sq.front().second==t){
      int to=sq.front().first;
      sq.pop();
      if(!used[to]){
	//cout<<to<<endl;
	for(int i=0;i<G[to].size();i++)sq.push(P(G[to][i],t+1));
	used[to]=1;
	cnts++;
      }
    }
    t++;
  }
  if(cntf>cnts)cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cstdlib>
#include <queue>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    int k, s, s_p;
    long long ans;
    ans = 0;
    cin >> k >> s;
    for(int x=0; x<=k; ++x){
        s_p = s - x;
        if(0 <= s_p && s_p <= 2 * k){
            for(int y=0; y<=k; ++y){
                if(0 <= s_p - y && s_p - y <= k){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
Original problem: 
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;


namespace SOLVE {
    void main() {
        int v, e, a, b;
        cin >> v >> e;
        vector < VI > edges(v + 1);
        VI vin(v + 1);
        VI vout(v + 1);
        queue < int > topo; // find topological order
        stack < int > dporder; // dporder is reverse topological
        VI dp(v + 1); // dp[i] stores the max length that ends at i

        REP(i, 0, e) {
            cin >> a >> b;
            edges[a].push_back(b);
            vout[a]++;
            vin[b]++;
        }

        // look for all vertices that have no vout
        REP(i, 1, v + 1) {
            if (vin[i] == 0) {
                topo.push(i);
            }
        }

        // finding topological order whilst creating the reversing topological order
        while (topo.size()) {
            int t = topo.front();
            dporder.push(t);
            topo.pop();

            // remove the top and remove all vertices outgoing from top
            for (int to: edges[t]) {
                vin[to]--;
                if (vin[to] == 0) {
                    topo.push(to); // to now has no incoming edges and is next in topo order
                }
            }
        }

        while (dporder.size()) {
            int t = dporder.top();
            dporder.pop();

            int best = 0;
            for (int to: edges[t]) {
                best = max(best, dp[to] + 1);
            }
            dp[t] = best;
        }

        int ans = 0;
        REP(i, 1, v + 1) {
            ans = max(ans, dp[i]);
        }
        cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 7296
#include <stdio.h>
int main()
{
  long long int N, K, S;
  scanf("%lld %lld %lld", &N, &K, &S);
  
  long long int i;
  
  long long int T;
  if(S == 1000000000) T=S-1;
  else T=S+1;
  for(i=0; i<N; i++){
    if(i<K)  printf("%d ", S);
    else printf("%d ", T);
  }
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
// ユークリッドの互除法で最大公約数を求める
int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
// 最小公倍数
int lcm(int a,int b){
  return a*b/gcd(a,b);
}
int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> rsum(n+1), lsum(n+1);
  lsum[0] = rsum[0] = 0;
  rep(i,n) {
    lsum[i+1] = gcd(lsum[i], a[i]);
  }
  for(int i = n; i > 0; --i) {
    rsum[i-1] = gcd(rsum[i], a[i-1]);
  }

  int res = 0;
  rep(i,n) {
    chmax(res, gcd(lsum[i], rsum[i+1]));
  }
  cout << res << "\n";
  
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int T, A;
  cin >> T >> A;
  double dif;
  double min = 10000000;
  int H[N];
  int res;
  for(int i = 0; i < N; i++){
    cin >> H[i];
    dif = abs(T - H[i] * 0.006 - A);
    if(dif < min){
      min = dif;
      res = i+ 1;
    }
  }
  cout << res<< endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

signed main(){
    int N,M;
    cin>>N>>M;
    if(N==M)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}   

Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    int sum;
    int n;
    cin>>n;
    sum = (1+n)*n/2;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,x,cnt;
	scanf("%d %d",&a,&b);
	cnt=0;
	x=1;
	while(1){
		if(x>=b)	break;
		x+=a-1;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

using namespace std;

bool good(int n) {
    int c = n % 10;
    int b = (n/10) % 10;
    int a = n/100;
    return a == b && a == c;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    while (!good(n)) {
        ++n;
    }
    cout << n << endl;
    return 0;
}


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

int main() {
  int m, n;
  cin >> m >> n;
  if(m>n) swap(m,n);
  rep(i,n) cout << m;
}


Measured memory_bytes: 256
n,d=map(int,input().split())
x=[[int(a) for a in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        s = sum([(a-b)*(a-b) for a,b in zip(x[i],x[j])])
        t = int(s**.5)
        if s == t*t:
            ans +=1
print(ans)

Measured memory_bytes: 3188
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,input().split())
PS = (input().split() for _ in range(M))

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == 'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)

Measured memory_bytes: 4596
#include <iostream>
#include <math.h>
using namespace std;

int main(){   
    int N;
    cin >> N;
    int64_t power = 1;
    for (int i = 1; i <= N; i++){
        power = fmod(i*power, (pow(10, 9) + 7));
    }
    cout << power << endl;
    return 0;
}

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

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

    if (c == "a" || c == "e" || c == "o" || c == "u" || c == "i"){
        cout << "vowel" << endl;
    } else {
        cout << "consonant"<< endl;
    }

	return 0;
}

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


signed main() {
  int N;
  cin >> N;
  int A = N;
  
  if( N % 2 == 1 || N < 2 ){
    cout << 0 << endl;
    return 0;
  }
  
  N /= 2;
  int waru = 5;
  int ans = 0;
  while( N / waru > 0 ){
    ans += N / waru;
    waru *= 5;
  }
  cout << ans << endl;
  
    
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
num,number,ans=[],[],0

for i in range(1,n+1):
  for j in range(len(str(i))):
    num.append(str(i)[j])
    
  number=[int(j) for j in num]
  number=sum(number)
  
  if number>=a and number<=b:
    ans+=i
    
  num,number=[],[]
  
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;

ll hako[222222];
ll res[222222];
vector<vector<int> >ab;

int dfs(int x, int ima){
  ima+=hako[x];
  res[x]+=ima;
  for(int i=0;i<ab[x].size();i++){
    dfs(ab[x][i],ima);
  }
}


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

  ab.resize(N+1);
  int a,b;

  for(int i=0;i<N-1;i++){
    cin>>a>>b;
    ab[a].pb(b);
  }

  int p,x;
  for(int i=0;i<Q;i++){
    cin>>p>>x;
    hako[p]+=x;
  }

  dfs(1,0);

  for(int i=1;i<=N;i++){
    cout<<res[i]<<" ";
    if(i==N) cout<<endl;
    //else cout<<" "<<endl;
  }

  return 0;
}


Measured memory_bytes: 22528
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
char x,y;

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

    if (x == 'H') cout << y << '\n';
    else {
        if (y == 'H') cout << 'D' << '\n';
        else cout << 'H' << '\n';
    }

    return 0;
}


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

int main(){
    int H,W;
    while(1){
        scanf("%d %d",&W,&H);
        if(W==0&&H==0) break;
        for (int i=0;i<W;i++){
            if(i ==0||i == W-1){
                for (int j=0;j<H;j++){
                    printf("#");
                }
            }else{
                for(int j = 0;j<H;j++){
                    if(j==0||j==H-1){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


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

typedef long long ll;


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

// vector の使い方
// 宣言：
// vector<int> v;
// vector<int> v(N);
// 初期化:
// vector<int> v(10, 5); 要素数10，全ての要素の値5．
// vector<int> v = {1, 2, 3};
// 代入：
// v[0] = 3;
// sort:
// sort(v.begin(), v.end());
//

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

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

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

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

ll pow(ll a, ll b) {
	ll a_powered = 1;
	for (int i=0; i<b; i++) {
		a_powered *= a;
	}
	return a_powered;
}


int main(int argc, char *argv[]){
    int A,B;
    cin >> A >> B;
    if(A>B){
        cout << 2*A - 1 << endl;
    } else if (A == B){
        cout << 2*A << endl;
    } else {
        cout << 2*B - 1 << endl;
    }
}


Measured memory_bytes: 256
n,k,q=map(int,input().split())
a=[0]*n
for i in range(q):
#    a(i)=int(input())
    j=int(input())-1
    a[j]=a[j]+1
    
#print(a)
for i in range(n):
    if a[i]>q-k:
        print("Yes")
    else:
        print("No")

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

int main(void){
  int w, h, n;
  int x, y, a;
  int area[100][100]{};
  int white = 0;

  cin >> w >> h >> n;

  for (int j = 0; j < h; j++){
    for (int i = 0; i < w; i++){
      area[j][i] = 1;
    }
  }

  for (int k = 0; k < n; k++){
    cin >> x >> y >> a;
    if (a == 1){
      for (int j = 0; j < h; j++){
        for (int i = 0; i < x; i++){
          area[j][i] = 0;
        }
      }
    }
    else if (a == 2){
      for (int j = 0; j < h; j++){
        for (int i = x; i < w; i++){
          area[j][i] = 0;
        }
      }
    }
    else if (a == 3){
      for (int j = 0; j < y; j++){
        for (int i = 0; i < w; i++){
          area[j][i] = 0;
        }
      }
    }
    else if (a == 4){
      for (int j = y; j < h; j++){
        for (int i = 0; i < w; i++){
          area[j][i] = 0;
        }
      }
    }
  }

  for (int j = 0; j < h; j++){
    for (int i = 0; i < w; i++){
      white += area[j][i];
    }
  }

  cout << white << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int n;
    static int w;
    static long[] value;
    static long[] weight;
    static long[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n= sc.nextInt();
        w = sc.nextInt();
        weight = new long[w+1];
        value = new long[n+1];
        dp = new long[n+1][w+1];

        for (int i=0; i<n; i++) {
            weight[i] = sc.nextInt();
            value[i] = sc.nextInt();
        }

        //dp[i][sum_w]にはi番目までの中でsum_wまでの重さが入る最大値が入る。
        for (int i=0; i<n; i++) {
            for (int sum_w=0; sum_w <=w; sum_w++) {
                if (sum_w - weight[i] >= 0) {
                    dp[i+1][sum_w] = Math.max(dp[i+1][sum_w], dp[i][sum_w - (int)weight[i]] + value[i]);
                }
                dp[i+1][sum_w] = Math.max(dp[i+1][sum_w], dp[i][sum_w]);
            }
        }
        System.out.println(dp[n][w]);
    }
}

Measured memory_bytes: 128084
a, b, k = map(int, input().split())
count = 0
list = [0]*(a + 1)
for i in range(a+1):
    if 0 < i:
        if (a % i == 0) and (b % i ==0):
            count += 1
            list[count] = i
print(list[count - k + 1])

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

int main(){
	int a, b, v[101] = {} , p = 0;
	while(cin >> a && cin >> b){
		v[a]++;
		v[b]++;
		if(a == 0){
			if (v[1]%2 == 0 || v[2]%2 == 0){
				p = 1;
			} 
			for (int i = 3; i <= 100; i++){
				if (v[i]%2 == 1){
					p = 1;
				        v[i] = 0;
				}
			}

			if (p == 1) 
				cout << "NG" << endl;
			else 
				cout << "OK" << endl;
			v[1] = 0;
			v[2] = 0;	
			p = 0;
		}
	}
}
					

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll w, h;
    while(cin >> w >> h) {
        if (w == 0 && h == 0) return 0;

        vector<vector<ll>> bh(h, vector<ll>(w-1)), bw(h-1, vector<ll>(w));
        rep(i, h-1) {
            rep(j, w-1) cin >> bh[i][j];
            rep(j, w) cin >> bw[i][j];
        }
        rep(j, w-1) cin >> bh[h-1][j];

        vector<vector<ll>> dist(h, vector<ll>(w, 0));
        dist[0][0] = 1;
        queue<pair<ll, ll>> que;
        que.emplace(0, 0);
        ll dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

        while(!que.empty()) {
            ll x = que.front().second, y = que.front().first;
            que.pop();

            rep(i, 4) {
                ll nx = x + dx[i], ny = y + dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny || dist[ny][nx] != 0) continue;
                else if (i == 0 && bw[y][x] == 1) continue;
                else if (i == 1 && bw[y-1][x] == 1) continue;
                else if (i == 2 && bh[y][x] == 1) continue;
                else if (i == 3 && bh[y][x-1] == 1) continue;

                dist[ny][nx] = dist[y][x] + 1;
                que.emplace(ny, nx);
            }
        }
        cout << dist[h-1][w-1] << endl;
    }

}



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

int main(){
    string s;
    cin >> s;
    
    long n = s.size();
    int a,b;
    a = 0;
    b = 0;
    rep(i,n){
        if(s[i]=='0') a++;
        else if (s[i]=='1') b++;
    }
    cout << 2*min(a,b);
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];

    rep(i, n) {
        int minv = 1e9, idx = 0;
        rep(j, m) {
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dist < minv) minv = dist, idx = j + 1;
        }
        cout << idx << endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int L[2*N]; rep(i,2*N) cin >> L[i];
  sort(L,L+2*N);
  int result = 0;
  rep(i,N) result += L[2*i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
N, T = [int(i) for i in input().split()]
cur_time = T+1
cur_cost = 1001
for n in range(N):
    c, t = [int(i) for i in input().split()]
    if t <= T:
        if c < cur_cost:
            cur_cost = c
if cur_cost == 1001:
    print('TLE')
else:
    print(cur_cost)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF =ll(1e18)+5;

int main() {
    ll N;
    cin >> N;
    ll minus =0;
    ll minV = INF;
    ll sum =0;
    for(int i=0;i<N;i++){
        ll A;
        cin >> A;
        if(A<0){
            minus++;
        }
        sum += abs(A);
        minV = min(minV,abs(A));
    }
    if(minus%2==1){
        sum -= (minV*2);
    }
    cout <<sum <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

// DAME:
int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = 0;
    int active = 0;
    rep(i, n){
        if(active >= h[i]){
            active = h[i];
        }else{
            ans += h[i] - active;
            active = h[i];
        }
    }

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


Measured memory_bytes: 256