akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

struct p{
	double x;
	double y;

	p operator -(p& rh){
		p pnt;
		pnt.x = this->x - rh.x;
		pnt.y = this->y - rh.y;
		return pnt;
	}

	void print(){
		cout << this->x << ", " << this->y << endl;
	}
};

double cross(p a, p b){
	return a.x*b.y - a.y*b.x;
}

bool isLeft(p a, p b, p c){	// c が ab より左ならtrue
	//a.print();
	//b.print();
	//c.print();
	//cout << "cross:" << cross(b-a, c-a) << endl << endl;
	return (cross(b-a, c-a) > 0);
}

bool isInside(p a, p b, p c, p d){ // d が abc 内部なら true
	bool left = false;
	bool right = false;

	bool m, n, l;
	m = isLeft(a, b, d);
	n = isLeft(b, c, d);
	l = isLeft(c, a, d);
	left = m || n || l;
	right = !m || !n || !l;
	
	return left^right;
}

int main(){

	p pnt[4];

	while(scanf("%lf", &pnt[0].x) != EOF){
		scanf(",%lf", &pnt[0].y);
		for(int i = 1; i < 4; i++){
			scanf(",%lf", &pnt[i].x);
			scanf(",%lf", &pnt[i].y);
		}

		bool b = true;

		for(int i = 0; i < 4 && b; i++){
			b &= !isInside(pnt[(i+0)%4], pnt[(i+1)%4], pnt[(i+2)%4], pnt[(i+3)%4]);
		}

		if(b){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1224
N = int(input())
work = [list(map(int, input().split())) for i in range(N)]

work = sorted(work, key = lambda x: x[1])

time = 0
for i in range(N):
    time += work[i][0]
    if time > work[i][1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 55264
let input = require("fs").readFileSync("/dev/stdin", "utf8");
let cin = input.split(/ |\n/), cid = 0;
function next() { return +cin[cid++]; }
//input from catoonさん


class UnionFind {
    p: number[];
    sizes: number[];
    tmpsize: number;
    constructor(n: number) {
        this.p = new Array(n);
        this.sizes = new Array(n,1);
        for (let i = 0; i < n; i++) {
            this.p[i] = i;
        }
        this.tmpsize = n;
    }
    find(x: number) {
        if (this.p[x] === x) {
            return x;
        } else {
            let tmp = this.find(this.p[x]);
            return tmp;
        }
    }
    unite(x: number, y: number) {
        let findx = this.find(x);
        let findy = this.find(y);
        if (findx === findy) return;

        let [large, small] = this.sizes[findx] >= this.sizes[findy] ? [findx, findy] : [findy, findx];

        this.p[small] = large;
        this.sizes[large] += this.sizes[small];
        this.tmpsize--;

    }
    is_same(x: number, y: number) {
        return this.find(x) === this.find(y);
    }
}
function main() {
    let n = next();
    let q = next();
    let uf = new UnionFind(n);
    while (q--) {
        let condition = next();
        let tmp = next();
        let tmp1 = next();
        if (condition === 0) {
            uf.unite(tmp, tmp1);
        }
        else {
            if (uf.is_same(tmp, tmp1)) {
                console.log(1);
            }
            else {
                console.log(0);
            }

        }
    }
    return;
}
main();


Measured memory_bytes: 104888
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)
#define mp make_pair

using namespace std;
const int N = 1e3 + 5, MI = 1e6;
int n, m, ok[N][N], cn, cm, dn, dm, dis[N][N], vis[N][N];
deque <pair <int, int> > q;
int chk(int x, int y) { return x && x <= n && y && y <= m && ok[x][y]; }
int chk(int x, int y, int v) {
	if(v < dis[x][y]) return dis[x][y] = v, 1;
	return 0;
}
int main() {
	#ifdef local
		freopen("in.txt", "r", stdin);
	#endif
	mem(dis, 0x3f);
	cin>>n>>m>>cn>>cm>>dn>>dm;
	char s[N];
	rep(i, 1, n) {
		scanf("%s", s + 1);
		rep(j, 1, m) ok[i][j] = s[j] == '.';
	}
	dis[cn][cm] = 0, q.push_back(mp(cn, cm));
	while(!q.empty()) {
		int x = q.front().first, y = q.front().second;
		q.pop_front();
		if(vis[x][y]) continue;
		vis[x][y] = 1;
		if(x == dn && y == dm) return !(cout << dis[x][y]);
		rep(i, -1, 1) if(chk(x + i, y) && chk(x + i, y, dis[x][y]))
			q.push_front(mp(x + i, y));
		rep(i, -1, 1) if(chk(x, y + i) && chk(x, y + i, dis[x][y]))
			q.push_front(mp(x, y + i));
		rep(i, -2, 2) rep(j, -2, 2) if(chk(x + i, y + j) && chk(x + i, y + j, dis[x][y] + 1))
			q.push_back(mp(x + i, y + j));
	}
	return puts("-1"), 0;
}

Measured memory_bytes: 15484
#include <stdio.h>
int main(){
    int a,b,c[100]={},d[100][100]={},i=0,count[101]={},ans=0;
    scanf("%d%d",&a,&b);
  
  for(i=0;i<b;i++){
  scanf("%d",&c[i]);
  for(int j=0;j<c[i];j++){
  scanf("%d",&d[i][j]);
  }
  }
  
  for(i=0;i<100;i++){
    for(int j=0;j<100;j++){
      count[d[i][j]]++;
    }
  }
  for(i=1;i<101;i++){
    if(count[i]!=0)
      ans++;
  }
  printf("%d",a-ans);
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[n];
		Arrays.fill(dp, 2000000000);
		dp[0] = 0;
		int[] ashiba = new int[n];

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

		for(int i = 1; i < n; i++) {
			if(i < 2) dp[i] = Math.min(dp[i], dp[i - 1] + Math.abs(ashiba[i - 1] - ashiba[i]));
			else {
				dp[i] = Math.min(dp[i], dp[i - 1] + Math.abs(ashiba[i - 1] - ashiba[i]));
				dp[i] = Math.min(dp[i], dp[i - 2] + Math.abs(ashiba[i - 2] - ashiba[i]));
			}
		}

		System.out.println(dp[n - 1]);
		sc.close();
	}
}


Measured memory_bytes: 50712
#include<iostream>
#include<string>
using namespace std;
int main()
{ int k;
 cin>>k;
 string s;
 cin>>s;
 string s1;
 int len=s.length();
 if(len<=k)
   cout<<s<<endl;
 else
 {
  s.erase(k,len-k);
   s.append("...");
   cout<<s<<endl;
 }

return 0;
}

Measured memory_bytes: 3588
s = list(input())
m = 114514
for i in range(0, len(s) - 2):
    l = 100 * int(s[i]) + 10 * int(s[i + 1]) + int(s[i + 2])
    if abs(l - 753) < m:
        m = abs(l - 753)
print(m)

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

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

    int c, t;

    bool isTLE = true;
    int bestC = 1000;
    for (int i = 0; i < N; i++){
        cin >> c >> t;
        if (t <= T){
            isTLE = false;
            if (c < bestC){
                bestC = c;
            }
        }
    }
    if (isTLE){
        cout << "TLE" << endl;
    }else{
        cout << bestC << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

VB is_prime(100001, true);
VI table(100001, 0);

void Eratosthenes(auto limit)
{
  for (int i = 0; i*i <= limit; ++i)
  {
    if (i == 0 || i == 1) is_prime[i] = false;
    else if (is_prime[i]) for (int j = 2; i*j <= limit; ++j) is_prime[i*j] = false;
  }
}

int main()
{
  int Q;
  scanf("%d", &Q);
  Eratosthenes(100000);
  REP2(i, 1, 100001)
  {
    if (i % 2 == 0)
    {
      table[i] = table[i-1];
      continue;
    }
    if (is_prime[i] && is_prime[(i+1)/2]) table[i] = table[i-1] + 1;
    else table[i] = table[i-1];
  }
  REP(query, Q)
  {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", table[r] - table[l-1]);
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int q;
    cin>>q;
    set<int> st;
    rep(i, q) {
        int m, x;
        cin>>m>>x;
        if (m == 0) {
            st.insert(x);
            cout<<st.size()<<endl;
        }
        else if (m == 1) {
            cout<<st.count(x)<<endl;
        }
        else if (m == 2) {
            st.erase(x);
        }
        else {
            int r;
            cin>>r;
            auto it = st.lower_bound(x);
            auto cl = st.upper_bound(r);
            for (; it != cl; ++it) {
                cout<<*it<<endl;
            }
        }
    }
}


Measured memory_bytes: 12472
#include<stdio.h>
	int main()
{
	int d,t,s,ans;
	scanf("%d%d%d",&d,&t,&s);
	ans=t*s;
	if(d<=ans){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int main() {
  int X, A, B;
  cin >> X >> A >> B;
  cout << (X - A) % B << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 
bool cmp(pair<string, int>& a, 
         pair<string, int>& b) 
{ 
    return a.second < b.second; 
} 
 

int main(){
	//in_o();
    map<string,int>m;
    int n,mx=0;
    string s;
    cin>>n;
    FOR(i,0,n){
        cin>>s;
        m[s]++;
        if(mx<m[s]){
            mx=m[s];
        }
    }
    for(auto i:m){
        if(i.second==mx)
            cout<<i.first<<endl;
    }
	return 0;
}


Measured memory_bytes: 19148
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

def ume(x):
    x = str(x)
    if len(x) < 6:
        return '0'*(6-len(x)) + x
    return x

def main():
    N, M = mi()

    l = dp2(0, 3, M)
    cnt = [0]*(N+1)
    ans = dp2(0, 2, M)
    for i in range(M):
        p, y = mi()
        l[i][0], l[i][1], l[i][2] = p-1, y, i
        cnt[p] += 1
    for i in range(N):
        cnt[i+1] += cnt[i]

    l.sort(key=lambda x: x[0])
    for i in range(N):
        ichibu = l[cnt[i]:cnt[i+1]]
        ichibu.sort(key=lambda x: x[1])
        for j in range(cnt[i+1]-cnt[i]):
            ans[ichibu[j][2]][0] =ichibu[j][0]+1
            ans[ichibu[j][2]][1] =j+1
    
    for x, y in ans:
        print(ume(x)+ume(y))


if __name__ == "__main__":
    main()

Measured memory_bytes: 75884
#include <iostream>
#include <math.h>

using namespace std;

typedef long long int lli;

int main(int argc, char const *argv[]) {
  lli x, ans = 0;
  cin >> x;
  double n = (-1+sqrt(1+8*x))/2;
  ans = ceil(n);
  cout << ans << endl;
  return 0;
}


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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while(true)
    {
        int w, h; cin >> w >> h;
        if(w == 0 && h == 0) break;
        vvb wall(2*h-1);
        REP(i, 2*h-1)
        {
            int t;
            REP(j, w-1) cin >> t, wall[i].pb(t);
            if(i % 2 == 1) cin >> t, wall[i].pb(t);
        }
        vvi grid(h, vi(w, INF));
        queue<pi> q;
        // bfs
        grid[0][0] = 1;
        q.push(mp(0, 0));
        while(!q.empty())
        {
            pi p = q.front(); q.pop();
            if(p.fi != 0) // 上
            {
                if(!wall[2*p.fi-1][p.se] && chmin(grid[p.fi-1][p.se], grid[p.fi][p.se]+1)) q.push(mp(p.fi-1, p.se));
            }
            if(p.se != w-1) // 右
            {
                if(!wall[2*p.fi][p.se] && chmin(grid[p.fi][p.se+1], grid[p.fi][p.se]+1)) q.push(mp(p.fi, p.se+1));
            }
            if(p.fi != h-1) // 下
            {
                if(!wall[2*p.fi+1][p.se] && chmin(grid[p.fi+1][p.se], grid[p.fi][p.se]+1)) q.push(mp(p.fi+1, p.se));
            }
            if(p.se != 0) // 左
            {
                if(!wall[2*p.fi][p.se-1] && chmin(grid[p.fi][p.se-1], grid[p.fi][p.se]+1)) q.push(mp(p.fi, p.se-1));
            }
        }
        cout << ((grid[h-1][w-1] == INF) ? 0 : grid[h-1][w-1]) << endl;
    }
}


Measured memory_bytes: 3180
def bubblesort(a):
    count = 0
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                count += 1
                swap = True           
    print(" ".join(map(str,a)))
    print(count)
    
n = int(input())
a = list(map(int,input().split()))
bubblesort(a)

Measured memory_bytes: 7664
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    ll ans = -1;
    ll a,b;
    cin >> a >> b;
    for (ll i=1;i<=100000;i++){
        if(a == i * 8 / 100 and b == i * 10 / 100){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int n,k,i,r=1;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++){r=min(r*2,r+k);}
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
from collections import deque

N = int(input())
result = set()

queue = deque([3, 5, 7])

count = 0
while queue:
    number = queue.pop()

    if number <= N:
        string = str(number)
        if '3' in string and '5' in string and '7' in string:
            result.add(number)
        for i in range(3, 8, 2):
            queue.appendleft(number * 10 + i)

print(len(result))


Measured memory_bytes: 15220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

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

  if (n%2 == 0) cout << n / 2 - 1 << endl;
  else cout << (n+1) / 2 - 1<< endl;

  return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
const ll MAX = 2000010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
//階乗
long long factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%mod;
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//aの逆元求めるならn=mod-2
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
COMinit();
ll n,a,b,c;
cin>>n>>a>>b>>c;
ll an=modpow(a,n),bn=modpow(b,n);
ll ans=0;
for(int i=n;i<2*n;i++){
    ll res;
    res=(an*modpow(b,i-n)%mod+bn*modpow(a,i-n)%mod)%mod;
    (res*=i)%=mod;
    (res*=modpow(modpow(a+b,i),mod-2))%=mod;
    (res*=COM(i-1,n-1))%=mod;
    (ans+=res)%=mod;
}
(ans*=100)%=mod;
(ans*=inv[a+b])%=mod;
cout<<ans<<endl;
}


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

int main(){
  int X, A;
  cin >> X >> A;
  if (X < A){
    cout << 0 << endl;
  }
  else
  {
    cout << 10 << endl;
  }
  
}

Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		for (int i = A; i <= B; i++) {
			if (i < A + K || i > B - K) {
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 22996
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


func main() {

	var n int
	fmt.Scan(&n)

	ans := 2 * n / gcd(2, n)
	fmt.Println(ans)
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> s(n,1);
  
  rep(i,k){
    int d; cin >> d;
    rep(j,d){
      int a; cin >> a;
      s.at(a-1)=0;
    }
  }
  int ans=0;
  rep(i,n) ans += s.at(i);
  cout << ans << endl;  
}

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

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 2e5+100;
int n , m;
long long ans[MAX_N];
int l, r, d;
vector<pair<int , int>> g[MAX_N];
bool used[MAX_N];
bool ok;

void add_edge(int from, int to, int cost)
{
	g[from].push_back({to,cost});
	g[to].push_back({from,-cost});
}

void dfs(int x)
{
	used[x] = true;
	if(ok){
		for(const auto& e : g[x]){
			const int to = e.first, len = e.second;
			if (ans[to] == INF) ans[to] = ans[x] + len;
			if (ans[to] != ans[x] + len){
				ok = false;
				return;
			}
			if (!used[to]) dfs(to);
		}
	}
} 

void solve()
{
	ok = true;
	memset(ans,0x3f,sizeof(ans));
	for(int i=1; i<=n; i++){
		if (!used[i]){
			ans[i] = 0;
			dfs(i);
		}
	}
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> l >> r >> d;
		add_edge(l,r,d);
	}
	solve();
	return 0;
}

Measured memory_bytes: 19908
#include<bits/stdc++.h>
using namespace std; 
#define all(c) c.begin(),c.end()
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ; 
typedef vector<int> vi;
#define mod 1000000007 

int main()
{
  //  freopen("input.txt","r",stdin);
   ios::sync_with_stdio(0);
// cin.tie(0);
ll n,w;
cin>>n>>w;
vector<ll>a(n),b(n);
REP(i,0,n-1)
cin>>a[i]>>b[i];
vector<vector<ll>>dp(w+1,vector<ll>(n+1));
for(int k=1;k<=n;++k){
  for(int i=1;i<=w;++i){
    if(i-a[k-1]>=0)
    dp[i][k]=max({dp[i][k],dp[i][k-1],dp[i-a[k-1]][k-1]+b[k-1]});
    dp[i][k]=max(dp[i][k],dp[i][k-1]);
  }
}
ll best=0;
for(int i=0;i<=w;++i)
for(int j=0;j<=n;++j)
best=max(best,dp[i][j]);
cout<<best;
    return 0;
}

Measured memory_bytes: 85264
N = int(input())
Str_V = input()
Str_C = input()
V = [0]*N
C = [0]*N
V = Str_V.split(" ")
C = Str_C.split(" ")
ans = 0

for i in range(N):
    V[i] = int(V[i])
    C[i] = int(C[i])
    delta = V[i] - C[i]
    if (delta >= 0):
        ans += delta

print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
 
int L[MAX/2+2],R[MAX/2+2];
int cnt;
 
void merge(int A[],int n,int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i = 0; i < n1; i++)L[i] = A[left + i];
  for(int i = 0; i < n2; i++)R[i] = A[mid + i];
  L[n1]= R[n2] = SENTINEL;
  int i = 0, j = 0;
  for(int k = left; k < right; k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(int A[], int n,int left,int right){
  if(left+1 < right){
    int mid = (left + right) /2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}
 
int main(){
  int A[MAX],n,i;
  cnt = 0;
 
  cin >> n;
  for(i =0;i<n;i++)cin >> A[i];
 
  mergeSort(A,n,0,n);
 
  for(i = 0; i < n; i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
 
  cout << cnt << endl;
 
  return 0;
 
}


Measured memory_bytes: 6984
#!/usr/bin/env python3
def solve():
    N, M_a, M_b = [int(x) for x in input().split()]
    inf = 100000
    t = [[inf] * (10 * N + 1) for _ in range(10 * N + 1)]
    t[0][0] = 0
    for _ in range(N):
        ai, bi, ci = [int(x) for x in input().split()]
        for ta in reversed(range(ai, len(t))):
            for tb in reversed(range(bi, len(t[0]))):
                t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
    ans = min(
        t[k * M_a][k * M_b]
        for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
    )
    print(-1 if ans >= inf else ans)


solve()


Measured memory_bytes: 41964
#include<iostream>
#include<string>

using namespace std;

string a,b;

int main(){
	
	cin >> a >> b;
	int i;
	for (i=0; i<3; i++){
		if (a[i] != b[2-i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int A, B;
        cin >> A >> B;

        if (B%A==0)
        {
                cout << A + B << endl;
        } else{
                cout << B - A << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 200010;

P p[Maxn];
int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        p[i] = P(b, a);
    }
    sort(p, p + n);
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        if (cur + p[i].second > p[i].first){
            cout << "No" << endl;
            return 0;
        }
        cur += p[i].second;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
const int N=1000+5;
int a[N*N],b[N][N],c[N*N];
int main(){
	int i,j,n,h,k,w;
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int cnt=0;
	for(j=0;j<n;j++){
		for(k=0;k<a[j];k++){
			c[cnt++]=j+1;
		}
	}
	cnt=0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			b[i][j]=c[cnt++];
		}
	}
	for(i=0;i<h;i++){
		if(i%2){
			for(j=w-1;j>=0;j--){
				if(j<w-1)printf(" ");
				printf("%d",b[i][j]);
			}
		}
		else {
			for(j=0;j<w;j++){
				if(j)printf(" ");
				printf("%d",b[i][j]);
			}
		}
		printf("\n");
	}
}

Measured memory_bytes: 6400
//abc166_e.cpp
//Sun May  3 20:54:16 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll a[n];
	ll rui[n];
	fill(rui,rui+n,0);
	unordered_map<ll,ll> mp;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i>0){
			rui[i] = rui[i-1]+(a[i-1]-a[i]-1);
			auto itr = mp.find(rui[i]);
			if (itr != mp.end()){
				mp[rui[i]]++;
			}else {
				mp[rui[i]] = 1;
			}
		}else {
			mp[0] = 1;
		}
	}

//	for (auto itr = mp.begin();itr!=mp.end();itr++){
//		cout << " " << itr->first << " " << itr->second << endl;
//	}

	ll ans = 0;
	for (int i=n-1;i>0;i--){
		ll start = i-a[0];
//		cout << i << " " << mp[a[i]-start] << endl;
		ans += mp[a[i]-start];
		mp[rui[i]]--;
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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



int main(void){
    
    int N;
    cin >> N;
    long long A;
    map<long long,long long> mp;
    long long ans = 0;
    for(int i = 0; i < N;i++){
        cin >> A;
        ans+=mp[i-A];
        mp[i+A]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 26236
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#include <stdio.h>

struct UnionFind {
  // まとめる 判定 サイズを知る
  // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。
  vector<int> par;

  //初期化
  UnionFind(int N) {
    par = vector<int>(N, -1);
  }

  // Aのrootを調べる
  int root(int A) {
    if (par[A] < 0) return A;  // マイナスならそれはroot
    return par[A] = root(par[A]);
  }

  // rootの値をプラスに戻して返す(サイズ)
  int size(int A) {
    return -par[root(A)];
  }

  // くっつける関数
  bool unite(int A, int B) {
    // AとBのroot同士をくっつける
    A = root(A);  // ここのAは、rootの場所,の意味
    B = root(B);
    if (A == B) return false;  // 既にくっついている
    if (size(A) < size(B))
      swap(A, B);  // 大きい方にくっつけるために中身交換
    par[A] += par[B];  // 中身更新
    par[B] = A;
    return true;
  }
};

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> fri(n);
  vector<vector<int>> block(n);

  UnionFind tree(n);

  rep1(i, m){//zero base
    int a, b;
    scanf("%d%d", &a, &b);
    fri[a-1].emplace_back(b-1);
    fri[b-1].emplace_back(a-1);
    tree.unite(a-1, b-1);
  }
  rep1(i, k){//zero base
    int a, b;
    scanf("%d%d", &a, &b);
    block[a-1].emplace_back(b-1);
    block[b-1].emplace_back(a-1);
  }

  int ans;
  rep1(i, n){
    ans = tree.size(i) - fri[i].size() - 1;
    rep1(j, block[i].size()){
      if(tree.root(block[i][j]) == tree.root(i))ans--;
    }
    cout << ans << "\n";
  }


}



Measured memory_bytes: 20992
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
//#include <stdio.h>
#define ll long long

int main(void)
{
    ll n, ans = 0;
    bool judge = false;
    cin >> n;
    string c;   ll i = 0, j = n - 1; 
    cin >> c;

while(1) {
    while(1) {
        if(i == j) {
            judge = true;  break;
        }
        else if(c.at(i) == 'W')
            break;
        else
            i++;
    }

    while(1) {
        if(i == j) {
            judge = true;  break;
        }
        else if(c.at(j) == 'R')
            break;
        else
            j--;
    }

    if(judge)
        break;
    else {
        c.at(i) = 'R'; c.at(j) = 'W';
        ans++;
    }
}
cout << ans;
}

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

int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  if(op == '+') {
    cout << A+B <<endl;
    }
  
  else if(op == '-') {
    cout << A-B << endl;
    }
  
  }
    

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P       = pair<int, int>;

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

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

map<P, int> mp;

int memo(string &s, int n) {
    int k = 0;
    rep(i, 0, n - 1) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            k++;
            mp[P(i, i + 1)] = k;
        }
    }
    return k;
}

signed main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> acc(n + 1, 0);
    rep(i, 0, n) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            acc[i + 1] = acc[i] + 1;
        } else {
            acc[i + 1] = acc[i];
        }
    }

    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        int ans = acc[r-1] - acc[l-1];
        cout << ans << endl;
    }
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vi a(N), b(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    for (int i = 0; i < N; i++)
        cin >> b[i];

    int res = 0;
    for (int bit = 0; bit < 29; bit++) {
        int M = 1 << (bit + 1);

        vi av;
        for (int v : a) {
            av.push_back(v & (M - 1));
        }
        sort(all(av), greater<int>());

        vi bv;
        for (int v : b) {
            bv.push_back(v & (M - 1));
        }
        sort(all(bv));

        // count a + b >= 2^b mod 2^(b+1)
        // b in [M/2 - a, M - a)
        ll app = 0;

        int i = 0, j = 0, k = 0;
        for (int v : av) {
            while (i < N && v + bv[i] < M/2) i++;
            while (j < N && v + bv[j] < M) j++;
            while (k < N && v + bv[k] < 3*M/2) k++;
            app += j - i + N - k;
        }

        if (app&1) res ^= 1 << bit;
    }

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 4492
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  ll ans = 0;

  rep2(i, 1, n) {
    ll cnt = 0;

    for (int j = 1; i*j <= n; ++j) ++cnt;
    ans += i * (cnt * (cnt+1)) / 2;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll x, y;
class FermatCombination {
private:
    long long factrial[1010101];
    long long inverse[1010101];
    long long MOD;

public:
    FermatCombination(int size, long long mod);
    long long combine(int n, int k);
    long long fast_pow(long long x, int n);
};

FermatCombination::FermatCombination(int size, long long mod) {

    MOD = mod;

    factrial[0] = 1;
    inverse[0] = 1;

    for (int i = 1; i <= size; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;
        inverse[i] = fast_pow(factrial[i], (int)MOD - 2) % MOD;
    }
}

long long FermatCombination::combine(int n, int k) {
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

long long FermatCombination::fast_pow(long long x, int n) {
    long long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}

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

    ll n, r;
    bool check=false;
    if((x+y)%3==0){
        n=(x+y)/3;
        ll yy=2*n, xx=n;
        REP(i, 0, n+1){
            if(y==(yy-i) && x==(xx+i)){
                check=true;
                r=i;
                break;
            }
        }
    }

    if(check){
        FermatCombination fc(n, mod);
        long long ans = fc.combine(n, r);
        cout<<ans<<endl;
    }
    else cout<<0<<endl;
    return 0;
}

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

int n;
vector<int> A;

int bubbleSort(int n)
{
    bool flag = 1;
    int counter = 0;

    while (flag) {
        flag = 0;

        for (int i = n-1; i > 0; --i) {
            if (A[i-1] > A[i]) {
                swap(A[i-1], A[i]);
                flag = 1;
                counter++;
            }
        }
    }
    return counter;
}

int main()
{
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    int counter = bubbleSort(n);

    for (int i = 0; i < n-1; ++i) {
        cout << A[i] << " ";
    }
    cout << A[n-1] << endl;
    cout << counter << endl;
    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < w + 2; i++)
    {
        cout << "#";
    }
    cout << "\n";
    for (int i = 0; i < h; i++)
    {
        cout << "#";
        string s;
        cin >> s;
        cout << s;
        cout << "#" << "\n";
    }
    
    for (int i = 0; i < w + 2; i++)
    {
        cout << "#";
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	string aa;
	cin>>a>>b;
	cin>>aa;
	for(int i=0;i<a+b;i++)
	{
		if(aa[a]!='-')
		{
			cout<<"No"<<endl;
			return 0;
		}
		if(i!=a)
		{
			if(!(aa[i]>='0'&&aa[i]<='9'))
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl; 
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val k = sc.nextInt()
    val uf = UnionFind(n)
    val friends = Array(n) { 0 }
    for (i in 0 until m) {
        val a = sc.nextInt() - 1
        val b = sc.nextInt() - 1
        uf.unite(a, b)
        friends[a]++
        friends[b]++
    }

    val ans = Array(n) { 0 }
    for (i in 0 until n) {
        ans[i] = uf.size(i) - friends[i] - 1
    }
    for (i in 0 until k) {
        val c = sc.nextInt() - 1
        val d = sc.nextInt() - 1
        if (uf.same(c, d)) {
            ans[c]--
            ans[d]--
        }
    }
    println(ans.joinToString(" "))
}

class UnionFind(n: Int) {
    private val rank = IntArray(n) { 0 }
    private val parent = IntArray(n) { -1 }

    fun find(x: Int): Int {
        if (parent[x] < 0) {
            return x
        }
        parent[x] = find(parent[x])
        return parent[x]
    }

    fun unite(x: Int, y: Int) {
        val x1 = find(x)
        val y1 = find(y)
        if (x1 == y1) {
            return
        }
        if (rank[x1] < rank[y1]) {
            parent[y1] += parent[x1]
            parent[x1] = y1
        } else {
            parent[x1] += parent[y1]
            parent[y1] = x1
            if (rank[x1] == rank[y1]) {
                rank[x1]++
            }
        }
    }

    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    fun size(x: Int): Int {
        return -parent[find(x)]
    }
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 54964
def solve():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    if 0 in X:
        N -= 1
        K -= 1
        if K == 0:
            return 0
        X.remove(0)
    ans = 10**9
    for i in range(N-K+1):
        if X[i+K-1]<=0:
            p = -X[i]
        elif X[i]>=0:
            p = X[i+K-1]
        else:
            p = X[i+K-1]-X[i]+min(X[i+K-1],abs(X[i]))
        ans = min(ans,p)
    return ans
print(solve())

Measured memory_bytes: 14252
q = int(input())
info = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    min_, max_ = info[i]
    min_, max_ = min(min_, max_), max(min_, max_)
    
    # a, b = 1, 1 のときREが出る
    if min_ == 1 and max_ == 1:
        print(0)
        continue

    mul = min_ * max_
    ans = 2 * (min_ - 1)

    ok = 0
    ng = max_ + 10
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid <= (mul - 1) // mid:
            ok = mid
        else:
            ng = mid
    ans += max(ok - (min_ - 1), 0)
    ans += max(ok - min_, 0)
    
    if ok == (mul - 1) // ok:
        ans -= 1
    print(ans)

Measured memory_bytes: 38768
#include <iostream>
using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

template<int MOD> struct MInt {
  long long val;
  MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt operator/(const MInt& n) const { return MInt(val) /= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  MInt& operator/=(const MInt& n) { val = (*this * n.inv()).val; return *this; }
  bool operator==(const MInt& n) { return val == n.val; }
  bool operator!=(const MInt& n) { return val != n.val; }
  MInt pow(long long n) const {
    MInt pow = val, ans = 1;
    for (long long p = n; p > 0; p >>= 1) {
      if (p & 1) ans *= pow;
      pow *= pow;
    }
    return ans;
  }
  MInt inv() const { return pow(MOD-2); }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
using mint = MInt<1000000007>;


int N;
constexpr int MAX_N = 21;
int A[MAX_N][MAX_N];
constexpr int MAX = (1 << 21) + 1;
mint dp[MAX];
bool visited[MAX];

mint dfs(int used) {
  int idx = __builtin_popcount(used);
  if (idx == N)
    return 1;
  if (visited[used])
    return dp[used];

  mint ans = 0;
  rep(j, N) {
    if (used & (1 << j))
      continue;
    if (A[idx][j]) {
      ans += dfs(used + (1 << j));
    }
  }
  visited[used] = true;
  return dp[used] = ans;
}

int main() {
  in(N);

  rep(i, N) rep(j, N) {
    cin >> A[i][j];
  }

  cout << dfs(0) << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int a, b, c, d;
  a = (int)s[0] - '0';
  b = (int)s[1] - '0';
  c = (int)s[2] - '0';
  d = (int)s[3] - '0';

  for (int i = 0; i < 8; i++) {
    int sum = a;
    if (i & 1) sum -= b; else sum += b;
    if (i & 2) sum -= c; else sum += c;
    if (i & 4) sum -= d; else sum += d;
    if (sum == 7) {
      cout << a << (i & 1 ? '-' : '+') << b << (i & 2 ? '-' : '+') << c << (i & 4 ? '-' : '+') << d << "=" << sum << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  cin>>A>>B;
  if(A==B) {
    cout<<"Draw"<<endl;
    return 0;
  }
  if(A<B) {
    if(A==1) cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
    return 0;
  }
  if(B==1) cout<<"Bob"<<endl;
  else cout<<"Alice"<<endl;
}


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

int main() {
    int ans=0;
    string s, t;
    cin >> s >> t;
    if (s.at(0) == t.at(0)) ans++;
    if (s.at(1) == t.at(1)) ans++;
    if (s.at(2) == t.at(2)) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256