akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N;
  while(cin >> N){
    double ans = 0;

    REP(i,N){
      double x; cin >> x;
      string u; cin >> u;

      if(u=="JPY") ans += x;
      else ans += 380000.0 * x;
    }

    cout << setprecision(12) << ans << endl;
  }
  
  return 0;
}


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

struct UnionFind{
    vector<int> par;

    UnionFind(int N) : par(N){
        for(int i=0; i<N; i++)par[i]=i;
    }

    int root(int x){
        if(par[x]==x) return x;
        return par[x] = root(par[x]);
    } 

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;

    }

    bool same(int x, int y){
        return root(x) == root(y);
    }
};


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

    UnionFind tree(n);

    rep(i,m){
        int a,b;
        cin >> a >> b;
        tree.unite(a-1,b-1);
    }
    int cnt = 0;
    rep(i,n){
        if(!tree.same(0,i)){
            tree.unite(0,i);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

namespace AC {
#define ll long long
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define PDPLL pair<double, PLL>
#define PLPLL pair<ll, PLL>
#define pb push_back
#define fi first
#define se second
#define ls rt << 1
#define rs rt << 1 | 1

    const ll N = 2e5 + 66;

    ll BUGS = 1;

    inline ll read(){
        ll x = 0;    bool flag = 1;   char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = 0; ch = getchar(); }
        while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
        if(flag) return x;  return (~(x - 1));
    }

    inline void read(ll arr[], ll s, ll e) { for(ll i = s; i <= e; ++i) arr[i] = read(); }

    inline void write(ll x){
        if(x < 0) { x = ~(x - 1); putchar('-'); }
        if(x > 9) write(x / 10); putchar(x % 10 + '0');
    }

    inline void print(ll x) { write(x); puts(""); }

    inline void print(ll arr[], ll s, ll e) {
        for(ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
        write(arr[e]); puts("");
    }

    inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }

    inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }

    inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; }

    inline void debugArr(ll arr[], ll s, ll e, string ss) {
        cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
        for(ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl;
    }

    inline void IO() {
        //ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
        //cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位
        //cout << setprecision(1); //保留1位有效数字
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
}using namespace AC;

ll n, m, K, suma[N], sumb[N], arra[N], arrb[N];

int main() {
    //IO();
    while(~scanf("%lld", &n)) {
        m = read(), K = read(), read(arra, 1, n), read(arrb, 1, m);

        suma[1] = arra[1];
        for(ll i = 2; i <= n; ++i) {
            suma[i] = suma[i - 1] + arra[i];
        }

        sumb[1] = arrb[1];
        for(ll i = 2; i <= m; ++i) {
            sumb[i] = sumb[i - 1] + arrb[i];
        }

        ll ans = 0;
        for(ll i = 1; i <= n; ++i) {
            if(suma[i] > K) continue;
            ll idx = upper_bound(sumb + 1, sumb + 1 + m, K - suma[i]) - sumb - 1;
            //idx = max(1ll, idx), idx = min(m, idx);
            //cout << "i : " << i << endl <<  "idx : " << idx << endl;
            ans = max(ans, idx + i);
        }

        for(ll i = 1; i <= m; ++i) {
            if(sumb[i] > K) continue;
            ll idx = upper_bound(suma + 1, suma + 1 + n, K - sumb[i]) - suma - 1;
            //idx = max(1ll, idx), idx = min(n, idx);
            //cout << "i : " << i << endl <<  "idx : " << idx << endl;
            ans = max(ans, idx + i);
        }

        print(ans);
    }
    return 0;
}



Measured memory_bytes: 9988
import math


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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


a, b, c, d = map(int, input().split())
ans = 0

# 最小公倍数
cd = lcm(c, d)

bdiv = (b // c) + (b // d) - (b // cd)
adiv = ((a - 1) // c) + ((a - 1) // d) - ((a - 1) // cd)
ans = (b - a) - (bdiv - adiv) + 1

print(ans)


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

int main()
{
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	
	int a , b;
	cin>> a>> b;

	int c = a * b;

	cout << c;    

  return 0;
}


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

typedef complex<double> P;

#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

double cross(P a, P b){
  return a.real() * b.imag() - a.imag() * b.real();
}
double dot(P a, P b){
  return a.real() * b.real() + a.imag() * b.imag();
}

int ccw(P a, P b, P c){
  b -= a; c -= a;
  if(cross(b, c) > 0) return 1;
  if(cross(b, c) < 0) return -1;
  if(dot(b, c) < 0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}
// 2直線の直交判定 : a⊥b <=> dot(a, b) = 0
int is_orthogonal(P a1, P a2, P b1, P b2) {
  return EQ( dot(a1-a2, b1-b2), 0.0 );
}
// 2直線の平行判定 : a//b <=> cross(a, b) = 0
int is_parallel(P a1, P a2, P b1, P b2) {
  return EQ( cross(a1-a2, b1-b2), 0.0 );
}

int main()
{
  P a,b,c,d;
  double ax,bx,cx,dx,ay,by,cy,dy;
  for(;cin>>ax>>ay>>bx>>by>>cx>>cy>>dx>>dy;)
    {
      P a=P(ax,ay),b=P(bx,by),c=P(cx,cy),d=P(dx,dy);
      if(is_orthogonal(a,b,c,d))
	cout<<"YES"<<endl;
      else
	cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1216
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
cnt=[]
def dfs(pos,p):
    if p==0:
        #print(pos)
        if int("".join(pos))<=n and "3" in pos and "5" in pos and "7" in pos:
            cnt.append(pos)
    else:
        for j in [3,5,7]:
            dfs(pos+[str(j)],p-1)

if len(str(n))<=2:
    print(0)
    exit()

for i in range(3,len(str(n))+1):
    pos=[]
    p=i
    dfs(pos,p)
print(len(cnt))

Measured memory_bytes: 78040
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

struct edge
{
       ll l; ll r;ll c;
       bool operator<(const edge& rhs) const {
               if (l != rhs.l) {
                       return l < rhs.l;
               }
               else if(r != rhs.r){
                       return r   < rhs.r;  
               }else{
                       return c < rhs.c;
               }
       }
};
int main(){
        ll n, m;
        priority_queue<pll> pq;
        cin >> n >> m;
        vector<edge> e(m+1);
        REP(i,0,m-1){
                ll l,r,c;
                cin >> l >> r >> c;
                e[i] = {l,r,c};
        }
        ll MX = 1e18;
        e[m] = {MX,MX,MX};
        sort(e.begin(), e.end());
        vll a(n+1);
        a[1] = 0;
        ll cnt = 0;
        REP(i,1,n){
                if(i > 1){
                        if(pq.empty()){
                                cout << -1 << endl;
                                return 0;
                        }
                        while(pq.top().second < i){
                                pq.pop();
                                if(pq.empty()){
                                        cout << -1 << endl;
                                        return 0;
                                }
                        }
                        pll p = pq.top();
                        ll t = -p.first;
                        a[i] = t;

                }
                while(e[cnt].l == i){
                        pq.push({-(a[i] + e[cnt].c), e[cnt].r});
                        cnt++;
                }
        }
        cout << a[n] << endl;

}

Measured memory_bytes: 5880
s = input()
s = s[ : : -1]

n = len(s)
k = 0

flg = True
while k < n:
    if s[k : min(k + 7, n)] == 'remaerd':
        k += 7
    elif s[k : min(k + 6, n)] == 'resare':
        k += 6
    elif s[k : min(k + 5, n)] == 'maerd' or s[k : min(k + 5, n)] == 'esare':
        k += 5
    else:
        flg = False
        break

if flg:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9204
a = [list(map(int, input().split())) for _ in range(3)]

n = int(input())

for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = "#"
                break

for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == "#":
        print("Yes")
        break
    elif a[0][i] == a[1][i] == a[2][i] == "#":
        print("Yes")
        break
    elif a[0][0] == a[1][1] == a[2][2] == "#":
        print("Yes")
        break
    elif a[0][2] == a[1][1] == a[2][0] == "#":
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 61768
K = int(input())
A = list(map(int, input().split()))

sum = 1000
kabu = 0

for k in range(K):
    if k+1 ==K:
        sum +=kabu*A[K-1]
        break
    if A[k]<A[k+1] and A[k]<=sum:
        S = int(sum/A[k])
        sum = sum-A[k]*S
        kabu +=S
    elif A[k]>A[k+1] and kabu != 0:
        sum = sum + kabu * A[k]
        kabu = 0
    

print(sum)

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int maximum = max(a, max(b, c));
    cout << 10*maximum + a + b + c - maximum << endl;
    return 0;
}

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

namespace AOJ.Volume1
{
    public class RewardForCarpenter
    {
        private static int n;
        private static int[,] cost;

        private class Town
        {
            public int No { get; set; }
            public int Cost { get; set; }
            public bool Confirm { get; set; }
        }

        public static int Main()
        {
            n = int.Parse(Console.ReadLine());
            // ??????????????????????????????
            // ???????????????????????¢???????????§n+1?????§??¨?????????
            // cost[1,2]???1??????2???????????????
            cost = new int[n + 1, n + 1];
            // ??????????????????????????¨???????????´??????-1
            for(int i = 0; i <= n; i++)
            {
                for(int j = 0; j <= n; j++) { cost[i, j] = -1; }
            }

            int m = int.Parse(Console.ReadLine());
            for(int i = 0; i < m; i++)
            {
                var input = Console.ReadLine().Split(',');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[1]);
                int c = int.Parse(input[2]);
                int d = int.Parse(input[3]);
                cost[a, b] = c;
                cost[b, a] = d;
            }

            var data = Console.ReadLine().Split(',');
            int start = int.Parse(data[0]);
            int goal = int.Parse(data[1]);
            int capital = int.Parse(data[2]);
            int material = int.Parse(data[3]);

            // ???????????????????????§????????¢?´¢
            // ??????
            int c_go = Calc(start, goal);
            // ????????????????????????????????????
            capital = capital - c_go - material;

            // ??????
            int c_ret = Calc(goal, start);

            // ??±??¬????±????
            capital -= c_ret;

            Console.WriteLine(capital);
            return 0;
        }

        // ???????????????????????§??????????¨??????????
        private static int Calc(int s, int g)
        {
            var t = new List<Town>();
            for(int i = 1; i <= n; i++)
            {
                var tn = new Town();
                tn.No = i;
                tn.Cost = int.MaxValue;
                tn.Confirm = false;
                t.Add(tn);
            }

            var tmp = t.First(x => x.No == s);
            tmp.Cost = 0;
            tmp.Confirm = true;
            while (true)
            {
                for(int i = 1; i <= n; i++)
                {
                    if (cost[tmp.No, i] >= 0)
                    {
                        var to = t.First(x => x.No == i);
                        if (!to.Confirm) { to.Cost = Math.Min(to.Cost, tmp.Cost + cost[tmp.No, i]); }
                    }
                }

                tmp = t.Where(x => !x.Confirm).OrderBy(y => y.Cost).First();
                tmp.Confirm = true;
                if(tmp.No == g) { break; }
            }

            return tmp.Cost;
        }
    }
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,d;

int main(){
    cin>>n>>d;
    cout<<((n+d+d)/(d+d+1))<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0] + [float("inf")]*(10**5)
for i in range(n):
    for j in range(10**5,wv[i][1]-1,-1):
        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])

res = 0
for v,e in enumerate(dp):
    if e <= w:
        res = v
print(res)

Measured memory_bytes: 93244
#include<bits/stdc++.h>
#define l first
#define r second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666,inf=0x3f3f3f3f;
int n,res;Pii s[N];
int hz[N],mn[N],mn1[N];
int main() {
	read(n);rep(i,1,n)read(s[i].l),read(s[i].r);
	sort(s+1,s+n+1);rep(i,1,n)umax(res,s[i].r-s[i].l+1);
	hz[n+1]=inf;per(i,n,1)hz[i]=min(hz[i+1],s[i].r);
	mn[0]=mn1[0]=inf;
	rep(i,1,n){
		mn[i]=mn[i-1];mn1[i]=mn1[i-1];
		if(s[i].r<mn[i])mn1[i]=mn[i],mn[i]=s[i].r;
		else if(s[i].r<mn1[i])mn1[i]=s[i].r;
	}
	rep(p,1,n-1){
		int cur=max(min(hz[p+1],mn[p-1])+s[p].r,min(s[p].r,mn[p-1])+hz[p+1]);
	//	cerr<<p<<' '<<min(s[p].r,mn[p-1])<<' '<<hz[p+1]<<endl;
		umax(res,cur-s[n].l-s[p].l+2);
	}
	cout<<res;return 0;
}


Measured memory_bytes: 3072
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N,M = i_map()
    if M <= 2*N:
        print(M//2)
        exit()

    print(N + (M-2*N)//4)

if __name__=="__main__":
    main()


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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 100;
const int oo = 1e8;
const int mod = 1e9 + 7;

int n, k, ans;
int a[N];

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    cin >> k >> n;

    int cur = 0;
    FOR(i, 1, n) {
        cin >> a[i];
        if(i > 1) cur += a[i] - a[i - 1];
    }
    ans = cur;
    FOR(i, 2, n)    {
        cur -= (a[i] - a[i - 1]);
        if(i == 2) cur += k - a[n] + a[1];
        else cur += a[i - 1] - a[i - 2];
        ans = min(ans, cur);
    }
    cout << ans;
}


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

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<ll>());
  int i = N;
  int j = 0;
  ll ans = 0;
  while (i > 0) {
    if (i == N) {
      i--;
    } else if (i == N - 1) {
      ans += a[j];
      i--;
      j++;
    } else if (i >= 2) {
      ans += 2 * a[j];
      i -= 2;
      j++;
    } else {
      ans += a[j];
      i--;
      j++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4816
/* ( ε:)( ε:)(:ε )(:ε ) */
/* ( ε:)Give me AC(:ε ) */
/* ( ε:)( ε:)(:ε )(:ε ) */
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(count_ver, lower, upper) for (long long count_ver = lower; count_ver < upper; count_ver++)

typedef long long ll;
using namespace std;
const int MOD=10000007;

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

//--------------------------------

void execute(){
  int n;
  cin>>n;
  int a=n/1000;
  if(a*1000 == n){
    cout<<0<<endl;
  }else{
    cout<<abs(n-(a+1)*1000)<<endl;
  }
}

//--------------------------------

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

  execute();

  return (0);
}


Measured memory_bytes: 3224
LI = lambda: list(map(int, input().split()))

H, W = LI()
S = [input() for _ in range(H)]


def main():
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            if j > 0 and S[i][j - 1] == "#":
                continue
            if j < W - 1 and S[i][j + 1] == "#":
                continue
            if i > 0 and S[i - 1][j] == "#":
                continue
            if i < H - 1 and S[i + 1][j] == "#":
                continue
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll N,M;
    cin >> N >> M;
    ll ans;
    /*
    if (N > M){
        ans = M/2;
    }
    */
    if (2*N <= M){
        ans = N + (M-2*N)/4;
    } else {
        ans = M/2;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
	int n, p;
	cin >> n >> p;
	int n0=0, n1=0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a&1) n1++;
		else n0++;
	}
	long long x0 = pow(2, n0);
	long long x1;
	if (n1 >= 1) x1 = pow(2, n1-1);
	else if (p == 0) x1 = 1;
	else x1 = 0;
	long long ans = x0 * x1;
	cout << ans << endl;
	return 0;
}

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

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

    vector<int> neg, pos;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == 0) k--;
        else if (a < 0) neg.push_back(a);
        else if (a > 0) pos.push_back(a);
    }

    if(n == 1 && k == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1e17;


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


    for (int i = max(0 ,k - (int)pos.size() - 1); i < min(k, (int) neg.size()); i++) {
        ll dist = neg[i] * (-1);
        if(i != k - 1) {
            dist *= 2;
            ll cnt = k - i - 1;
            dist += (pos[cnt - 1]);
        }


        ans = min(ans, dist);
    }

    for (int i = max(0, k - (int)neg.size() - 1); i < min(k, (int) pos.size()); i++) {
        ll dist = pos[i];
        if(i != k - 1) {
            dist *= 2;
            ll cnt = k - i - 1;
            dist += (neg[cnt - 1] * (-1));
        }

        ans = min(ans, dist);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1020
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// $%U%$
// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	string s,t;
	cin >> s >> t;
	int n=s.size();
	int m=t.size();
	int ans=INT_MAX;
	for(int i=0;i<n;++i)
	{
		int cnt=0;
		if(i+m>n)
		break;
		for(int j=i;j<i+m && j<n;++j)
		{
			if(s[j]!=t[j-i])
			cnt++;
		}		
		ans=min(ans,cnt);
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(){

	string s;
	int m=0;
	int c=0;

	cin>> s;

	for(int i=0;i<(int)s.size();i++){
    		if(s[i]=='0'){
			//red
			if(c<0) m+=2;
			c++;
		}else{
			//blue
			if(0<c) m+=2;
			c--;
		}
	}

	cout<< m << endl;

}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, A[100005], B[100005], d[100005], topd, ans;
ll sumA, sumB, sumd;

int main(){
	getint(N);
	for(register int i = 1; i <= N; i++) getint(A[i]);
	for(register int i = 1; i <= N; i++) getint(B[i]);
	for(register int i = 1; i <= N; i++){
		sumA += A[i], sumB += B[i];
		if(A[i] < B[i]) sumd += B[i] - A[i], ans++;
		else if(A[i] > B[i]) d[++topd] = A[i] - B[i];
	}
	if(sumA < sumB) return puts("-1"), 0;
	sort(d + 1, d + topd + 1);
	for(register int i = topd; i && sumd > 0; i--) ans++, sumd -= d[i];
	return printf("%d\n", ans), 0;
}


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

int main(int argc, char const *argv[]) {
  int n,k;
  std::cin >> n >> k;

  long long s=k;
  for (size_t i = 0; i < n-1; i++) {
    s*=(k-1);
  }
  std::cout << s << std::endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){

        //入力を保持する
        var AB = Console.ReadLine().Split().Select(e => decimal.Parse(e)).ToArray() ;
        var A = AB[0];
        var B = AB[1];
 
        var ans = Math.Truncate(A * B);
 
        
        Console.WriteLine(ans);
    }
}


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

template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

void solve(int n){
	vector<int> v[n], w;
	for(int i=0; i<n; ++i){
		int m;
		cin >> m;
		readVector(m, v[i]);
		sort(v[i].begin(), v[i].end());
	}
	int k;
	cin >> k;
	readVector(k, w);
	sort(w.begin(), w.end());
	int res = -1;
	for(int i=0; i<n; ++i){
		bool f = true;
		int t = 0;
		for(int j=0; j<k; ++j){
//			cout << i << " " << j << " " << t << "\n";
			while(t < v[i].size() && v[i][t] != w[j]) ++t;
			if(t == v[i].size()){
//				cout << i << "\n";
				f = false;
				break;
			}
			++t;
		}
		if(f){
			if(res != -1){
				res = -1;
//				cout << i << " " << res << "\n";
				break;
			}else{
				res = i+1;
			}
		}
//		cout << i << " " << res << "\n";
	}
	cout << res << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}


Measured memory_bytes: 3160
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;


/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */

int main() {
	double a, b;
	cin >> a >> b;
	double k = (a + b) / 2;
	if (floor(k) == ceil(k))cout << (int)k;
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 0, sum = 0;
  rep1 (i, n - 1) {
    ++cnt;
    if (s[i] != s[i - 1]) {
      sum += cnt - 1;
      cnt  = 0;
    }
    if (i == n - 1) {
      sum += cnt;
    }
  }
  int change = 0;
  rep1 (i, n - 1) {
    if (s[i] != s[i - 1]) ++change;
  }
  change = (change + 1) / 2;
  sum += 2 * min(change, k);
  sum  = min(sum, n - 1);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 512
/*ex4_2
 Sweet_Sweet_Soul */
#include <stdio.h>

int ans(int wes,int eas);

int main(void) {
    int wes,eas;
    scanf("%d",&wes);
    scanf("%d",&eas);
    printf("%d\n",ans(wes,eas));
    return 0;
}

int ans(int wes,int eas){
    int dif=eas-wes;/*東側はdif番目の塔*/
    int tru_eas=(dif+1)*dif/2;/*東側の塔の本当の高さを総和公式で*/
    return tru_eas-eas;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define deb(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define debv(x) cout<<#x<<": " ;tr(it,x) cout<<*it<<" "
#define inputv(v) for(auto& x : v) cin >> x
#define output(x) cout<<x<<endl
#define vll vector<ll>
#define fast ios_base :: sync_with_stdio(false); cin.tie(0)
#define sublime freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
const ll MOD = 1e9 + 7;
    
void test_case(){
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll tmp1 = a*c;
	ll tmp2 = b*d;
	ll tmp3 = b*c;
	ll tmp4 = a*d;
	cout << max(tmp1,max(tmp2,max(tmp3,tmp4)));
	
}


int main() {
    fast;
    // sublime;
    ll T = 1; 
    // cin >> T;
    while(T--)
        test_case(); 

}



Measured memory_bytes: 3648
/*                              _______                                _________
        |\     |         /\         |      |        /\        |\     |    |
        | \    |        /  \        |      |       /  \       | \    |    |
        |  \   |       /    \       |\-----       /    \      |  \   |    |
        |   \  |      /======\      | \          /======\     |   \  |    |     ====|
        |    \ |     /        \     |  \        /        \    |    \ |    |         |
        |     \|    /          \    |   \      /          \   |     \|    |_________|
    */
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define mk make_pair
    #define endl "\n"
    #define vi vector<ll>
    #define vb vector<bool>
    #define pii pair<ll,ll>
    #define ss second
    #define ff first
    #define vpii vector<pii>
    #define vvi vector<vi >
    #define vs vector<string>
    #define vvs vector<vs >
    #define all(x) x.begin(),x.end()
    #define mii map<int,int>
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define per(i,n) for(ll i=n-1;i>=0;i--)
    #define rep1(i,n) for(ll i=1;i<=n;i++)
    #define per1(i,n) for(ll i=n;i>0;i--)
    #define repeat(i,start,n) for(ll i=start;i<n;i++)
    #define inp(arr,n) int arr[n];rep(i,n){ cin>>arr[i];}
    #define inp1(arr,n) ll arr[n+1];rep1(i,n){ cin>>arr[i];}
    #define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
    #define print1(a,n) for(ll i=1;i<=n;i++){ cout<<a[i]<<endl;}
    #define M 1000000007
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int t=1,T=1;
        //cin>>t;
        while(t--)
        {
            ll n,ans=0;
            cin>>n;
            inp(arr,n);
            mii m;
            rep(i,n)
            {
                m[arr[i]]++;
            }
            mii::iterator it;
            for(it=m.begin();it!=m.end();it++)
            {
                ll temp=it->ss;
                ans+=((temp*(temp-1))/2);
            }
            //cout<<ans;
            rep(i,n)
            {
                ll temp=m[arr[i]];
                ll temp2=ans-(temp*(temp-1))/2;
                ll temp3=temp2+((temp-1)*(temp-2))/2;
                cout<<temp3<<endl;
            }
        }

    }


Measured memory_bytes: 8320
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=b){
		for(int i=1;i<=b;i++){
			printf("%d",a);
		}
		printf("\n");
	}
	else{
		for(int i=1;i<=a;i++){
			printf("%d",b);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
#define sz(x) (int)x.size()
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	if(n >= 3200)
		cout << s << endl;
	else
		cout << "red" << endl;
	return 0;
}


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


int main()
{
    int n;
    cin >> n;
    vector<ll> a(n*3);
    for(int i = 0; i < n*3; ++i) cin >> a[i];

    vector<ll> l(n*2+1,0);
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    for(int i = 0; i < n; ++i) {
        l[i+1] = l[i] + a[i];
        que1.push(a[i]);
    }
    for(int i = n; i < n*2; ++i) {
        ll mi = que1.top();
        if(a[i] > mi) {
            l[i+1] = l[i] - mi + a[i];
            que1.pop();
            que1.push(a[i]);
        }
        else l[i+1] = l[i];
    }

    vector<ll> r(n*2+1,0);
    priority_queue<ll> que2;
    for(int i = 0; i < n; ++i) {
        r[i+1] = r[i] + a[n*3-1 - i];
        que2.push(a[n*3-1 - i]);
    }
    for(int i = n; i < n*2; ++i) {
        ll ma = que2.top();
        if(a[n*3-1 - i] < ma) {
            r[i+1] = r[i] - ma + a[n*3-1 - i];
            que2.pop();
            que2.push(a[n*3-1 - i]);
        } 
        else r[i+1] = r[i];
    }

    ll res = -(1LL<<60);
    for(int i = n; i <= n*2; ++i) {
        res = max(res, l[i] - r[n*3-i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 11088
program test
implicit none

character(4) :: eat
integer :: i,j,k,l,m,n

read(*,*) eat
if(eat=='++++') then
	write(*,*) 4
else if(eat=='-+++' .or. eat=='+-++' .or. eat=='++-+' .or. eat=='+++-') then
	write(*,*) 2
else if (eat=='----') then
	write(*,*) -4
else if (eat=='---+' .or. eat=='--+-' .or. eat=='-+--' .or. eat=='+---') then
	write(*,*) -2
else
	write(*,*) 0
endif

end program

Measured memory_bytes: 640
import Control.Monad
f1 x = do
  nx_in <- (return. map (read::String->Int) . words) =<< getLine
  let n:x:[] = nx_in
  if (n==0) && (x==0)
    then return () else do
      print $ f2 n x 1 2
      f1 x
      
f2 n x n1 n2 | n1 == (n-1) = 0
             | n2 == n = f2 n x (n1+1) (n1+2)
             | x-(n1+n2) > n2 && x-(n1+n2) <= n = 1 + f2 n x n1 (n2+1)
             | otherwise = 0 + f2 n x n1 (n2+1)

main = f1 0


Measured memory_bytes: 5500
//
// Created by yamunaku on 2019/11/03.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    string s;
    cin >> s;
    int n =s.size();
    vi ans(n+1,0);
    rep(i,n){
        if(s[i]=='<') ans[i+1] = ans[i]+1;
    }
    per(i,n){
        if(s[i]=='>') ans[i] = max(ans[i],ans[i+1]+1);
    }
    ll sum =0;
    rep(i,n+1) sum+=ans[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2820
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run() {
    int n, m;
    cin >> n >> m;
    vector<char> cool(n, 1);
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        for (int i = 0; i < k; ++i) {
            int v;
            cin >> v;
            cool[--v] = 0;
        }
    }
    cout << accumulate(all(cool), 0) << endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
#define TRUE 1
#define FALSE 0
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

int X[N][N];

void initialize(){
  int i;
  for(i=0 ; i< N ; i++){
    row[i]=FREE;/*行*/
    col[i]=FREE;/*列*/
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]= FREE;/*左下ななめ*/
    dneg[i]= FREE;/*右下ななめ*/
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
        if(row[i] != j)return;/*XがTRUEのときかつrowのiがjでないとき*/
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j){/*x[i][j]がFALSEでrow[i]がjのとき*/
        printf("Q");
    }
else{ printf(".");
}
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N){/*クイーンの配置に成功*/
    printBoard();
    return;
  }

  for(j=0;j<N;j++){
    /*(i,j)が他のクイーンに襲撃されてる時むし*/
    if(col[j] == NOT_FREE ||
       dpos[j + i] == NOT_FREE ||
       dneg[i - j + N - 1] == NOT_FREE) continue;
    /*(i,j)にクイーンをはいち*/
    row[i] =j;
    col[j] =dpos[i+j] = dneg[i-j+N-1] =NOT_FREE;
    recursive(i+1);
    /*(i,j)に配置されているクイーンを取り除く*/
    row[i]=col[j] = dpos[i+j]= dneg[i-j+N-1]=FREE;
  }
  /*くいいーんのはいちにしっぱい*/
}


int main(){
  int i,j,k,r,c;
  initialize();

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)X[i][j]=FALSE;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c] =TRUE;
  }
  recursive(0);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main(){
  long n; //整数の数
  cin >> n;
  long *a = new long[n];
  for(int i=0; i<n; i++){
    cin >> a[i]; //整数列
  }

  //そーと  
  std::sort(a, a + n);
  bool flag=true;
  for(int i=0; i<n; i++){
    if(a[i] == a[i+1]){
      cout << "NO";
      flag == false;
      return 0;
    }else{
      flag == true;
    }
  }
  if(flag==true){
    cout << "YES";
  }
  
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    getline(cin, s);
    int a = 0, ans = 0;
    for (int i = 0; i < s.length(); i++){
        if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') ans = max(++a, ans);
        else a = 0;
    }
    printf("%d", ans);
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
count = 0
isOK = True
for i in range(N):
    if p[i] - (i + 1) != 0:
        count += 1
    if count > 2:
        isOK = False
        break
if isOK:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

int a[sz], b[sz];

int main()
{
   int n, k;
   cin >> n >> k;
   for(int i=0; i<n; i++) scanf("%d", &a[i]);
   while(k--) {
      for(int i=0; i<n; i++) {
         int x = max(0, i - a[i]);
         int y = min(n, i + a[i] + 1);
         b[x]++, b[y]--;
      }
      for(int i=0, j=0; i<n; i++) {
         j += b[i];
         a[i] = j, b[i] = 0;
      }
      bool no = 1;
      for(int i=0; i<n; i++) if(a[i] < n) no = 0;
      if(no) break;
   }
   for(int i=0; i<n; i++) {
      if(i) printf(" ");
      printf("%d", a[i]);
   }
   puts("");
}


Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

int main() {
    int w, h;
    char c;
    cin >> w >> h >> c;
    P cent = P((h - 1) / 2, (w - 1) / 2);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if ((i == 0 && j == 0) || (i == 0 && j == w - 1) || (i == h - 1 && j == 0) || (i == h - 1 && j == w - 1)) {
                cout << '+';
            } else if (i == 0 || i == h - 1) {
                cout << '-';
            } else if (j == 0 || j == w - 1) {
                cout << '|';
            } else if (cent == P(i, j)) {
                cout << c;
            } else {
                cout << '.';
            }
        }
        cout << endl;
    }
}


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

const int64_t inf = 1e18;

vector < int64_t > s, t;

pair < int64_t, int64_t > closest_shrine (int64_t x) {
    auto it = upper_bound(s.begin(), s.end(), x);
    if (it == s.begin())
        return make_pair(-inf, *it);
    else if (it == s.end())
        return make_pair(*prev(it), inf);
    else
        return make_pair(*prev(it), *it);
}

pair < int64_t, int64_t > closest_temple (int64_t x) {
    auto it = upper_bound(t.begin(), t.end(), x);
    if (it == t.begin())
        return make_pair(-inf, *it);
    else if (it == t.end())
        return make_pair(*prev(it), inf);
    else
        return make_pair(*prev(it), *it);
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b, q;
    cin >> a >> b >> q;
    s.resize(a);
    t.resize(b);
    for (int i = 0; i < a; ++i)
        cin >> s[i];
    sort(s.begin(), s.end());
    for (int i = 0; i < b; ++i)
        cin >> t[i];
    sort(t.begin(), t.end());
    for (int i = 0; i < q; ++i) {
        int64_t x;
        cin >> x;
        pair < int64_t, int64_t > shrine = closest_shrine(x);
        pair < int64_t, int64_t > temple = closest_temple(x);
        int64_t through_temp = min(min(x - closest_shrine(temple.first).first, x - temple.first + closest_shrine(temple.first).second - temple.first),
        min(closest_shrine(temple.second).second - x, temple.second - x + temple.second - closest_shrine(temple.second).first));
        int64_t through_shri = min(min(x - closest_temple(shrine.first).first, x - shrine.first + closest_temple(shrine.first).second - shrine.first),
        min(closest_temple(shrine.second).second - x, shrine.second - x + shrine.second - closest_temple(shrine.second).first));
        cout << min(through_temp, through_shri) << '\n';
    }
}


Measured memory_bytes: 2944
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        int m = 1000;
        for(int i = 0;i < N;i++){
            int a = sc.nextInt();
            ans += a;
            if(a%10 != 0)   m = Math.min(m, a);
        }
        if(ans%10 == 0) ans -= m;
        if(ans%10 == 0) System.out.println(0);
        else    System.out.println(ans);
    }
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b;

int main()
{
    _FastIO;
    cin >> a >> b;
    cout << max(0 , (a - 2 * b)) << endl;
    return 0;
}


Measured memory_bytes: 256
num=list(map(int,input().split(" ")))
matrix=[list(map(int,input().split(" "))) for i in range(num[0])]
tmp=list(map(lambda x:x.append(sum(x)),matrix))
a=[sum([i[j] for i in matrix])for j in range(num[1]+1)]
matrix.append(a)
for i in matrix:
    print(" ".join(map(str,i)))


Measured memory_bytes: 5708