akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; using ll=int_fast64_t; using ld=long double; using pll=pair<ll,ll>; using pld=pair<ld,ld>;
const ll INF=1LL<<60; void solve(); int main(){cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n,m,p; cin>>n>>m>>p;
  vector<tuple<ll,ll,ll>> E;
  vector<vector<ll>> to(n),ot(n);
  vector<ll> state(n);
  rep(_,m){
    ll a,b,c; cin>>a>>b>>c;
    --a; --b;
    to[a].push_back(b);
    ot[b].push_back(a);
    E.emplace_back(a,b,p-c);
  }
  // dfs
  function<void(ll)> dfs=[&](ll v){
    if(state[v]&1) return;
    state[v]+=1;
    for(ll nv:to[v]) dfs(nv);
  };
  dfs(0);
  function<void(ll)> rdfs=[&](ll v){
    if(state[v]&2) return;
    state[v]+=2;
    for(ll nv:ot[v]) rdfs(nv);
  };
  rdfs(n-1);
  // Bellman-Ford
  vector<ll> d(n,INF);
  d[0]=0;
  rep(step,n){
    for(auto tup:E){
      ll a,b,c;
      tie(a,b,c)=tup;
      if(!(state[a]&1) || !(state[b]&2)) continue;
      if(chmin(d[b],d[a]+c) && step==n-1){
        cout<<-1<<"\n";
        return;
      }
    }
  }
  cout<<max(-d[n-1],(ll)0)<<"\n";
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string S;
  cin>>S;
  VEC<string>a={"", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  REP(i,0,a.size()){
    if(a[i]==S){
      cout<<i<<endl;
      break;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (true) {
            String str = scan.next();
            if(str.equals("-"))break;
            int n = str.length();
            String[] c = new String[n];

            for (int i = 0; i < n - 1; i++) {
                c[i] = str.substring(i, i + 1);
            }
            c[n - 1] = str.substring(n - 1);
            int hnum = scan.nextInt();
            int h;
            for (int i = 0; i < hnum; i++) {
                h = scan.nextInt();
                String[] A = new String[h];
                for (int j = 0; j < h; j++) {
                    A[j] = c[j];
                }
                for (int j = 0; j < n - h; j++) {
                    c[j] = c[j + h];
                }
                int num = 0;
                for (int j = n - h; j < n; j++) {
                    c[j] = A[num];
                    num++;
                }
            }
            for (int i = 0; i <n; i++) {
                System.out.printf("%s", c[i]);
            }
            System.out.printf("\n");
        }
    }
}


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

bool isPrime(int a){
    bool ans = true;
    if(a>3){
        int root = std::sqrt(a);
        for (int i=2; i<=root; i++){
            if (a%i==0){
                ans = false;
                break;
            }
        }
    }
    return ans;
}

int main(){
    int X;
    cin >> X;
    int ans;
    ans = X;
    while (true) {
        if (isPrime(ans)==true){
            break;
        }
        ans++;
    }
    cout << ans << endl;
}

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

typedef long long LL;
const int N = 1e5 + 50;
const LL mod = 1e9 + 7;

vector <int> G[N], cir;
int n, a[N], sz, pt;
int vis[N], cur;
int len[N], cnt[N];
LL fac[N], inv[N];

inline void Dfs(int x) {
  if (vis[x]) {
    if (vis[x] != cur) sz = 0;
    else pt = x;
    return;
  }
  vis[x] = cur; sz ++;
  Dfs(a[x]);
}

inline void Dfs1(int x) {
  if (vis[x] == cur) return;
  cir.push_back(x);
  vis[x] = cur;
  Dfs1(a[x]);
}

inline int iDfs(int x) {
  if (G[x].size() > 1u) return (int) -1e9;
  if (!G[x].size()) return 1;
  return 1 + iDfs(G[x][0]);
}

inline LL Pow(LL x, LL exp) {
  LL r = 1;
  for (; exp; exp >>= 1, x = x * x % mod)
    if (exp & 1) r = r * x % mod;
  return r;
}

inline void Init() {
  for (int i = fac[0] = 1; i < N; i ++)
    fac[i] = fac[i - 1] * i % mod;
  inv[N - 1] = Pow(fac[N - 1], mod - 2);
  for (int i = N - 1; i; i --)
    inv[i - 1] = inv[i] * i % mod;
}

inline LL C(int x, int y) {
  return fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main() {
  Init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++) {
    scanf("%d", &a[i]);
    G[a[i]].push_back(i);
  }
  LL res = 1;
  cir.reserve(n);
  for (int i = 1; i <= n; i ++)
    if (!vis[i]) {
      sz = 1; cur ++;
      Dfs(i); if (!sz) continue;
      cur ++; cir.clear();
      Dfs1(pt);
      reverse(cir.begin(), cir.end());
      int tot = 0, le = cir.size();
      for (int j = 0; j < le; j ++) {
        vector <int> &Gi = G[cir[j]];
        if (Gi.size() > 2u) return 0 * puts("0");
        if (Gi.size() == 1u) len[j + 1] = 0;
        else tot += (len[j + 1] = iDfs(Gi[vis[Gi[0]] == cur]));
        if (len[j + 1] < 0) return 0 * puts("0");
      }
      if (!tot) {
        cnt[le] ++; continue;
      }
      int dis = 0;
      for (int j = 1; j <= le; j ++)
        if (len[j]) {
          dis = j - 1; break;
        }
      for (int j = le; j; j --) {
        dis ++;
        if (!len[j]) continue;
        if (dis > len[j]) {
          res <<= 1;
          if (res >= mod) res -= mod;
        }
        else if (dis < len[j]) return 0 * puts("0");
        dis = 0;
      }
    }
  for (int i = 1; i <= n; i ++) {
    if (!cnt[i]) continue;
    LL t = ((i & 1) && i != 1) + 1;
    LL tmp = Pow(t, cnt[i]);
    for (int j = (cnt[i] >> 1); j; j --)
      tmp += C(cnt[i], j << 1) * C(j << 1, j) % mod * Pow((mod + 1) >> 1, j) % mod * fac[j] % mod * Pow(i, j) % mod * Pow(t, (LL) cnt[i] - (j << 1)) % mod;
    res = res * (tmp % mod) % mod;
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 9728
n=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
    print(0)
    exit()
l=[0]*n
for d in D[1:]:
    l[d]+=1
if l[0]!=0:
    print(0)
    exit()
ans=1
for i in range(n-2):
    ans=(ans*(l[i+1]**l[i+2]))%998244353
print(ans)

Measured memory_bytes: 13892
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 24 00:11:24 2019

@author: iwao_yuuki
"""

import math

n = int(input(""))

D = {}
Ans = []

for i in range(n):
    cm,text = input().split()

    if cm == "insert":
        D[text] = 1
    if cm == "find":
        if text in D.keys():
                Ans.append("yes")
        else:
            Ans.append("no")

for i in Ans:
    print(i)


Measured memory_bytes: 37180
#include<iostream>
using namespace std;
typedef long long ll;
bool p = true;
int a,b,c=0;

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

	while(t--){
		cin >> a >> b;
		if(a == b){
			c++;
			if(c == 3){
				break;
			}
		}else{
			c = 0;
		}
	}
	if(c == 3){
		cout << "Yes";
	}else{
		cout << "No";
	}
}		

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

int main() {
    int x;
    cin >> x;
    if (x == 3)
    cout << "YES" << endl;
    else if (x == 5)
    cout << "YES" << endl;
    else if (x == 7)
    cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double LD; 
typedef long long ll; 
#define int ll 
#define ff(i,a,b) for (int i = a; i < b; i++) 
#define bf(i,a,b) for (int i = a; i >= b; i--) 
#define all(v) v.begin(),v.end() 
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first 
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound   
#define ub upper_bound
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define intmx INT_MAX 
#define intmi INT_MIN
const int MOD=1e9+7;
int mod(int x){
    return ((x%MOD + MOD)%MOD);
}
int add(int a,int b){
    return mod(mod(a)+mod(b));
}
int mul(int a,int b){
    return mod(mod(a)*mod(b));
}
void solve(){
   int k;
   cin>>k;
   int tot=0;
   ff(i,1,10000001){
       tot=(tot*10+7)%k;
       if(tot==0){
           cout<<i<<endl;
           return;
       }
   }
   one;
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3636
N = int(input())
S = input()

op = 0
add_op = 0
for c in S:
    if c == '(': op += 1
    else: op -= 1
    if op < 0:
        add_op += 1
        op += 1
S = '('*add_op + S

cl = 0
add_cl = 0
for c in S[::-1]:
    if c == ')': cl += 1
    else: cl -= 1
    if cl < 0:
        add_cl += 1
        cl += 1
S += ')'*add_cl

print(S)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
    int Rcnt=0;
    int N;
    string s;
    cin >> N;
    cin >> s;
    for(int i=0; i<N; ++i){
      if(s[i]=='R') ++Rcnt;
    }
    if(Rcnt > N - Rcnt) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}

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


int main(int argc, char const *argv[]) {
    int A=0;
    int B=0;
    int ans=0;
    std::cin >>A>>B ;

    if(A>=B){
        ans += A--;
    }else {
        ans+=B--;
    }
    if(A>=B){
        ans += A--;
    }else {
        ans+=B--;
    }
    std::cout << ans << '\n';
    return 0;
}



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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> c(H);
  REP(i, H){
    cin >> c[i];
  }
  int ans = 0;
  REP(hbit, 1<<H){
    REP(wbit, 1<<W){
      int cnt = 0;
      REP(i, H){
        REP(j, W){
          if((hbit>>i&1) || (wbit>>j&1)) continue;
          if(c[i][j] == '#'){
            cnt++;
          }
        }
      }
      if(cnt == K){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL() {};
template <class T, class... Args> void _INPUT_IMPL(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL(args...); }
#define int_cin(...) ll __VA_ARGS__; _INPUT_IMPL(__VA_ARGS__);

int main() {
	int_cin(a, b);
	OddEven(a*b);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N 2200
#define mod 1000000007
using namespace std;
int f[N][N],s[N],n,k,ans;//设f[i][j]表示已经选取了1~i个位置 最小的那个数是j的方案数 
int main(){
	//freopen("arc.in","r",stdin);
	scanf("%d%d",&n,&k);f[0][n+1]=1;s[n+1]=1;
	for (int i=n;i>=1;--i) s[i]=s[i+1]+f[0][i];
	for (int i=1;i<=k-1;++i){
		for (int j=1;j<=n-i+1;++j) f[i][j]=s[j];
		s[n+1]=f[i][n+1];for (int j=n;j>=1;--j) s[j]=(s[j+1]+f[i][j])%mod;
	}for (int i=2;i<=n+1;++i) (ans+=f[k-1][i])%=mod;
	for (int i=1;i<=n-k-1;++i) (ans*=2)%=mod;printf("%d",ans);
	return 0;
}

Measured memory_bytes: 18560
///////////////////////////////////////////
//root@NULLCT$(☝ ՞ਊ ՞)☝  << "Be accept!!"//
///////////////////////////////////////////
//#define BOOST
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int66_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   //setfill(char)
#include <ios>       //left,right
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp> // cpp_int
using namespace boost::multiprecision;
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int setup(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }
int lenght(char* str) { int i = 0; while (str[i])i++; return i; }
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); }
int iinput(void) { int a = 0; cin >> a; return a; }
int dinput(void) { double a = 0; cin >> a; return a; }
string sinput(void) { string a = ""; cin >> a; return a; }
int kuriup(double a) { int b = int(a); if (a != b) { return b + 1; } else { return b; } }
int kuridown(double a) { int b = int(a); return b; }
int run(void);
int main() { setup(); run(); return 0; }
/////////////////////////////////////////////////////////////////////////////////////////
struct nums {
  int s;
  int c;
};
bool paircompare(const pair<int,int>& firstelof, const pair<int,int>& secondelof){
  return firstelof.first > secondelof.second;
}
int run(void) {

  int n=iinput();
  n++;
  cout<<n/2<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }

        long[] asum = new long[n + 1];
        long[] bsum = new long[m + 1];
        for (int i = 0; i < n; i++) {
            asum[i + 1] = asum[i] + a[i];
        }
        for (int i = 0; i < m; i++) {
            bsum[i + 1] = bsum[i] + b[i];
        }
        boolean cont = false;
        int retk = k;
        int ans = 0;
        int asid = 0;
        int bsid = 0;
        int aeid = n;
        int beid = m;
        while (true) {
            while (true) {
                if (asum[aeid] - asum[asid] > retk)
                    aeid--;
                else
                    break;
            }
            while (true) {
                if (bsum[beid] - bsum[bsid] > retk)
                    beid--;
                else
                    break;
            }
            
            int tmpa = aeid - asid;
            int tmpb = beid - bsid;
            if (tmpa == 0 && tmpb == 0)
                break;
            if (tmpa > tmpb) {
                retk -= a[asid];
                ans++;
                asid++;
            } else {
                retk -= b[bsid];
                ans++;
                bsid++;
            }
        }

        System.out.println(ans);
        



    }
}

Measured memory_bytes: 61632
n, m = map(int, input().split())
ab = [[] for _ in range(n)]
for i in range(m):
	a, b = map(int, input().split())
	ab[a-1].append(b-1)
	ab[b-1].append(a-1)
# print(ab)
cnt = 0
check = [False for _ in range(n)]
check[0] = True
listA = [0]
listB = []
michishirube = [-1 for _ in range(n)]
while len(listA) > 0:
	# print(listA,listB)
	listB = []
	for la in listA:
		for laa in ab[la]:
			if not check[laa]:
				michishirube[laa] = la
				listB.append(laa)
				check[laa] = True
				cnt += 1
	listA = listB

print("Yes")
for i in range(1,n):
	print(michishirube[i]+1)


Measured memory_bytes: 107364
#include <bits/stdc++.h>
using namespace std;
void dfs (
  const vector<vector<int>>& grh,
  vector<bool>& ckd,
  int crr = 0
) {
  ckd[crr] = true;
  for (int nxt : grh[crr]) if (!ckd[nxt]) {
    dfs(grh, ckd, nxt);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> grh(n);
  for (int i = 0; i < m; i++) {
    int s, t, z;
    cin >> s >> t >> z;
    grh[--s].push_back(--t);
    grh[t].push_back(s);
  }
  vector<bool> ckd(n, false);
  int ret = 0;
  for (int i = 0; i < n; i++) {
    if (!ckd[i]) {
      ret++;
      dfs(grh, ckd, i);
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 10368
#include <iostream>

using namespace std;

int main() {
  int N, K, X, Y;
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;

  const int d = N - K;
  if (d <= 0)
    cout << X * N << endl;
  else
    cout << X * K + d * Y << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define MAX 6000002
#define MOD 1000000007
typedef long long int ll;


/************************************


 
*************************************/


ll bs(ll a,vector<ll>v){
    ll l = 0,r=v.size()-1,mid;
    while(l<r){
        mid = l+((r-l)/2);
        if(v[mid]==a)
            break;
        else if(v[mid]>a)
            r = mid;
        else
            l = mid+1;

    }
    return v[l];
}

 
int main() 
{   
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(ll i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    // for(ll x:dp)
    //     cout<<x<<" ";
    //cout<<endl;
    cout<<dp[n-1]<<endl;
    
    return 0; 
} 

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

int main() {
  int D,N,x;
  N=0;
  x=0;
  cin >> D;
  vector<int> c(26);
  vector<int> last(26);
  for (int i=0;i<26;i++) {
    cin >> c.at(i);
  }
  vector<vector<int>> s(D,vector<int>(26));
  for (int i=0;i<D;i++) {
    for (int j=0;j<26;j++) {
      cin >> s.at(i).at(j);
    }
  }
  vector<int> t(D);
  for (int i=0;i<D;i++) {
    cin >> t.at(i);
  }
  for (int i=0;i<D;i++) {
    N=t.at(i)-1;
    x+=s.at(i).at(N);
    last.at(N)=i+1;
    for (int j=0;j<26;j++) {
      x-=c.at(j)*(i+1-last.at(j));
    }
    cout << x << endl;
  }
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

ll N;
ll m[51][51] = {};
bool v[51] = {};
void dfs(int n) {
	repe(i, 1, N) {
		if (m[n][i] == 1 && v[i] == false) {
			v[i] = true;
			dfs(i);
		}
	}
}

int main() {
	ll  M; cin >> N >> M;
	ll a[51] = {};
	ll b[51] = {};
	repe(i, 1, M) {
		cin >> a[i] >> b[i];
		m[a[i]][b[i]] = 1;
		m[b[i]][a[i]] = 1;
	}

	ll cnt = 0;
	repe(i, 1, M) {
		repe(j, 1, N) {
			v[j] = false;
		}

		m[a[i]][b[i]] = 0;
		m[b[i]][a[i]] = 0;
		v[1] = true;
		dfs(1);
		bool bridge = true;
		repe(j, 1, N) {
			bridge &= v[j];
		}
		if (!bridge) {
			cnt++;
		}

		m[a[i]][b[i]] = 1;
		m[b[i]][a[i]] = 1;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const ll N = 123456;

vector < pair < ll , pair < ll , ll > > > a;
ll dist[N];
ll len[N];

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

    ll n , m;
    cin >> n >> m;

    ll p;
    cin >> p;

    rep(i , 1 , m) {
        ll x , y , z;
        cin >> x >> y >> z;
        a.push_back({x , {y , -z + p}});
    }

    rep(i , 1 , n) dist[i] = INT_MAX;;

    dist[1] = 0;

    rep(i , 1 , 2 * n) {
        rep(j , 0 , m - 1) {
            ll u = a[j].first;
            ll v = a[j].second.first;
            ll w = a[j].second.second;
            if(dist[u] != INT_MAX && dist[u] + w < dist[v]) {
                dist[v] = w + dist[u];
                if(i >= n + 1) {
                    dist[v] = INT_MIN;
                }
            }
        }
    }

    int ans = 0;
    if(dist[n] == INT_MIN) {
        ans = -1;
    }
    else if(dist[n] > 0) {
        ans = 0;
    }
    else {
        ans = -dist[n];
    }

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


Measured memory_bytes: 704
import sys
import itertools as it
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input())
    ss = list(input().strip())
    m = {}
    for c in ss:
        if c not in m:
            m[c] = 0
        m[c] += 1
    ans = 1
    for k in m:
        ans *= m[k] + 1
        ans %= 10**9 + 7
    print(ans - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
using System;

namespace atCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[][] a = { Console.ReadLine().Split(' '), Console.ReadLine().Split(' ') };
            int result = 0;

            for (int x = 0; x < n; x++)
            {
                int i = 0;
                int j = 0;
                int count = int.Parse(a[0][0]);

                for (int times = 0; times < n; times++)
                {
                    if (x == times)
                    {
                        i++;
                    }
                    else
                    {
                        j++;
                    }

                    count += int.Parse(a[i][j]);
                }

                if (result < count)
                {
                    result = count;
                }
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13268
/**
 *	@file: B.cpp
 *	@author: Huy Le
 *	@created: 07/11/2020 18:52:28
**/


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int ts;
int n,a[105];

void solve() {
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if((i+1)&1 && a[i]&1)
			++ans;
	}
	cout << ans;
}

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

	//cin >> ts;
	//while(ts--) 
		solve();
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> xs(n),ys(n);
  vector<char> ds(n);
  for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i]>>ds[i];

  Int ans=0;
  {
    Int xmax=xs[0],xmin=xs[0];
    Int ymax=ys[0],ymin=ys[0];
    for(Int i=0;i<n;i++){
      chmax(xmax,xs[i]);
      chmin(xmin,xs[i]);
      chmax(ymax,ys[i]);
      chmin(ymin,ys[i]);
    }
    ans=(xmax-xmin)*(ymax-ymin);
  }

  {
    auto cs(ds);
    cs.erase(unique(cs.begin(),cs.end()),cs.end());
    if(cs.size()==1){
      cout<<ans<<endl;
      return 0;
    }
  }

  const Int INF = 1e9;
  Int pax=-INF,qax=-INF,rax=-INF;
  Int pix=+INF,qix=+INF,rix=+INF;
  Int pay=-INF,qay=-INF,ray=-INF;
  Int piy=+INF,qiy=+INF,riy=+INF;
  for(Int i=0;i<n;i++){
    if(ds[i]=='R'){
      chmax(qax,xs[i]);
      chmin(qix,xs[i]);
      chmax(ray,ys[i]);
      chmin(riy,ys[i]);
    }
    if(ds[i]=='L'){
      chmax(pax,xs[i]);
      chmin(pix,xs[i]);
      chmax(ray,ys[i]);
      chmin(riy,ys[i]);
    }
    if(ds[i]=='U'){
      chmax(qay,ys[i]);
      chmin(qiy,ys[i]);
      chmax(rax,xs[i]);
      chmin(rix,xs[i]);
    }
    if(ds[i]=='D'){
      chmax(pay,ys[i]);
      chmin(piy,ys[i]);
      chmax(rax,xs[i]);
      chmin(rix,xs[i]);
    }
  }
  ans*=4;
  pax*=2;qax*=2;rax*=2;
  pix*=2;qix*=2;rix*=2;
  pay*=2;qay*=2;ray*=2;
  piy*=2;qiy*=2;riy*=2;

  Int lx=INF,ly=INF;
  for(Int t=0;;t++){
    Int tx=max({pax-t,qax+t,rax})-min({pix-t,qix+t,rix});
    Int ty=max({pay-t,qay+t,ray})-min({piy-t,qiy+t,riy});
    chmin(ans,tx*ty);
    if(lx<=tx&&ly<=ty) break;
    lx=tx;ly=ty;
  }

  cout<<(double)ans/4<<endl;
  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr(a,b) for(int i=a;i<b;i++)
#define prDouble(x) cout<<fixed<<setprecison(18)<<x
#define mod 1000000007

int dp[22][(1 << 22)];

int solve(vector < vector<int> >& compat, int i, int womenSubset, int N)
{
	if (i == N + 1)
	{
		if (womenSubset == 0)
			return 1;
		return 0;
	}

	if (dp[i][womenSubset] != -1)
		return dp[i][womenSubset];

	ll ans = 0;
	for (int women = 0; women < N; women++)
	{
		bool available = (((1 << women) & (womenSubset)) == 0) ? 0 : 1;
		if (available and compat[i][women + 1])
		{
			ans = (ans + solve(compat, i + 1, womenSubset ^ (1 << women), N)) % mod;
		}
	}
	return dp[i][womenSubset] = ans;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	vector < vector<int>> compat(n + 1, vector<int>(n + 1));
	memset(dp, -1, sizeof dp);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			cin >> compat[i][j];
	cout << solve(compat, 1, ((1 << (n)) - 1), n);
}

Measured memory_bytes: 364104
#include <cstdio>

#define Int register int

inline void Work () {
    char s;
    bool f = false;
    while ( ~ ( s = getchar () ) ) {
        if ( ( f |= s == 'C' ) && s == 'F' ) {
            puts ( "Yes" );
            return ;
        }
    }
    puts ( "No" );
}

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

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

int main()
{

    int K, eve_co=0, odd_co=0;
    cin >> K;
    for (int i = 1; i <= K;i++)
    if(i%2==0){
        eve_co++;
    }
    else
    {
        odd_co++;
    }
    cout << eve_co * odd_co << endl;
}


Measured memory_bytes: 256
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i <= x + k - 1; ++i) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long hmax,x;
int main()
{
    bool flag=false;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        hmax=max(hmax,x);
        if(x<hmax&&hmax-x>1)
            flag=true;
    }
    if(flag)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{
	int x,y,i;
	char number[1001];
	while(1){
		x = 0;
	    scanf("%s", number);
	    if(number[0] == '0'){
	    	break;
	    }
	    for(i=0; number[i] != '\0'; i++){
	    	y = number[i] - '0';
	    	x += y;
	    }
	    printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 536
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<Integer> st = new HashSet<>();
        for(int i=0;i<N;i++){
            st.add(sc.nextInt());
        }
        if(st.size() == N){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 100664
_, _, M = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
min = min(a) + min(b)
for i in range(M):
  x, y, c = map(int, input().split(" "))
  s = a[x-1] + b[y-1] - c
  if min > s:
    min = s
print(min)

Measured memory_bytes: 18736
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,s;
    while(cin>>n>>s,n||s){
        vector<int>V(n);
        for(int i=0;i<n;i++)cin>>V[i];
        sort(V.begin(),V.end());
        int cnt=0;
        for(int i=0;i<n;i++){
            int t=s-V[i];
            int r=i+1,l=n;
            while(l-r>=1){
                int mid=(r+l)/2;
                if(V[mid]>t)l=mid;
                else r=mid+1;
            }
            cnt+=n-r;
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 1252
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;

ll GCD(ll x,ll y) {
	if (y == 0)return x;
	return GCD(y, x%y);
}


int main() {
	ll X, Y;
	cin >> X >> Y;
	cout << GCD(X, Y) << endl;
	
	return 0;
}




Measured memory_bytes: 3096
#include <stdio.h>

int main(void) {
	char S[4];
	if (scanf("%3s", S) != 1) return 1;
	printf("%d00\n", 7 + (S[0] == 'o') + (S[1] == 'o') + (S[2] == 'o'));
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int n,i,j=0,k=0,v[4][3][10];
    int b,f,r,a;
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                v[i][j][k]=0;
            }
        }
    }
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&a);
        v[b-1][f-1][r-1]=v[b-1][f-1][r-1]+a;
    }
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",v[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3){
            printf("####################\n");
        }
    }
    return 0;
}

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


void solve(long long a){
    cout << a + a * a + a*a*a << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    solve(a);
    return 0;
}


Measured memory_bytes: 3716
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	string s;
	cin >> s;
	REP(i, s.length()) {
		if (s[i] == '*') {
			int ans = 0;
			map<int, int> kouho;
			int now = 0;
			for (int q = i - 1; q >= 0; --q) {
				if (s[q] == '(') {
					now++;
				}
				else {
					now--;
				}
				if (now > 0) {
					kouho[now] = 1;
				}
			}
			now = 0;
			for (int q = i + 1; q < s.length(); ++q) {
				if (s[q] == ')') {
					now++;
				}
				else {
					now--;
				}
				ans += kouho[now];
				kouho[now] = 0;
			}
			cout << ans << endl;
			return;
		}
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3232
c=0
for W in iter(input,'0'):
 c+=1
 W=int(W)
 dp=[0]*-~W
 for _ in[0]*int(input()):
  v,w=map(int,input().split(','))
  for i in range(W,w-1,-1):
   if dp[i]<dp[i-w]+v:dp[i]=dp[i-w]+v
 print(f'Case {c}:\n{dp[W]}\n{dp.index(dp[W])}')


Measured memory_bytes: 5624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int x,y;
  cin >> x >> y;
  if(x==1&&y==1){
    cout << 1000000 << endl; return 0;
  }
  ll ans = 0;
  if(x==3) ans += 100000;
  if(x==2) ans += 200000;
  if(x==1) ans += 300000;
  if(y==3) ans += 100000;
  if(y==2) ans += 200000;
  if(y==1) ans += 300000;
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int m = 0, f = 0, r = 0;

	cin >> m >> f >> r;

	while ((m != -1) | (f != -1) | (r != -1)) {
		if ((m == -1) | (f == -1))
			cout << "F" << endl;
		else if (m + f >= 80)
			cout << "A" << endl;
		else if (m + f >= 65)
			cout << "B" << endl;
		else if (m + f >= 50)
			cout << "C" << endl;
		else if (m + f >= 30) {
			if (r >= 50)
				cout << "C" << endl;
			else
				cout << "D" << endl;
		}
		else
			cout << "F" << endl;

		cin >> m >> f >> r;
	}
	
    return 0;
}

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

int main() {

	int a, b, c, d, t_hp, a_hp;
	cin >> a >> b >> c >> d;

	t_hp = a;
	a_hp = c;

	while (t_hp > 0 || a_hp > 0) {
		a_hp = c - b;
		c = a_hp;
		if (t_hp <= 0) {
			cout << "No" << endl;
			break;
		}

		t_hp = a - d;
		a = t_hp;

		if (a_hp<=0){
			cout << "Yes" << endl;
			break;
		}


	}

}


Measured memory_bytes: 3636
using System;
using System.Linq;

class A
{
	static void Main()
	{
		var ms = new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine().Split()).ToArray();
		var x = Console.ReadLine();
		Console.WriteLine(ms.SkipWhile(m => m[0] != x).Skip(1).Sum(m => int.Parse(m[1])));
	}
}


Measured memory_bytes: 28344
#include<bits/stdc++.h>
using namespace std;
void solve()
{
   string s;
   cin>>s;
   if(s[2]==s[3] && s[4]==s[5])
   {
   	cout<<"Yes\n";
   }
   else
   {
   	 cout<<"No\n";
   }
}
main()
{
int t=1;
while(t--)
{
solve();

}
}

Measured memory_bytes: 768
n=input()
i=1
SP=[]
while i<=n:
  x=i
  if x%3==0:
    SP.append(str(i))
  else:
    while x:
      if x%10==3:
        SP.append(str(i))
        break
      x/=10
  i+=1
print "", " ".join(SP)

Measured memory_bytes: 4516
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100005];
    scanf("%s", s);
    int i, n = strlen(s);
    char ss[100005];
    for (i = 0; i < n; i++)
    {
        if (s[i] == 'b')ss[n - 1 - i] = 'd';
        if (s[i] == 'd')ss[n - 1 - i] = 'b';
        if (s[i] == 'p')ss[n - 1 - i] = 'q';
        if (s[i] == 'q')ss[n - 1 - i] = 'p';
    }
    for (i = 0; i < n; i++)
    {
        if (s[i] != ss[i])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

void solve()
{

}

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
if(n%1000==0)ol("0");
else ol(1000-n%1000);
return 0;
}



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

using namespace std;

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    int dp[s1.size() + 1][s2.size() + 1];
    memset(dp, 0, sizeof dp);
    for (int i = 0; i <= s1.size(); i++)
    {
        for (int j = 0; j <= s2.size(); j++)
        {
            if (i == 0 || j == 0)
                dp[i][j] = 0;
            else if (s1[i-1] == s2[j-1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    // cout << dp[s1.size()][s2.size()];
    int i = s1.size(), j = s2.size();
    string ans = " ";
    while(i > 0 && j > 0)
    {
        if(dp[i][j] > dp[i-1][j] && dp[i][j] > dp[i][j-1])
        {
            ans+= s1[i-1];
            i--;
            j--;
        }
        else 
        {
            if(dp[i][j-1] >= dp[i-1][j])
                j--;
            else
                i--;
            
        }
        
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 35456
n,k,*aa = map(lambda x:int(x)-1, open(0).read().split())
n += 1
k += 1
passed = set()

i = 0
while k and i not in passed:
    k -= 1
    passed.add(i)
    i = aa[i]

if k:
    fst = i
    cycle = [fst]
    i = aa[i]

    while i != fst:
        cycle.append(i)
        i = aa[i]
    ans = cycle[k%len(cycle)]
else:
    ans = i
print(ans+1)

Measured memory_bytes: 121600
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans=n;
	for(int i = 1 ; i < n; i++) {
		if (s[i] == s[i - 1]) {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

typedef std::pair<int, int> P;

ll h, w, n;
ll ans[10];
std::set<P> s;

int main(){
	std::cin >> h >> w >> n;
	ans[0] = (h - 2) * (w - 2);

	for(int i = 0; i < n; ++i){
		ll a, b;
		std::cin >> a >> b;
		
		for(int y = a - 1; y <= a + 1; ++y){
			for(int x = b - 1; x <= b + 1; ++x){
				if(x < 2 || x > w - 1 || y < 2 || y > h - 1)continue;

				int cnt = 0;
				for(int p = -1; p <= 1; ++p){
					for(int q = -1; q <= 1; ++q){
						if(s.find(P(x + q, y + p)) != s.end())++cnt;
					}
				}

				--ans[cnt];
				++ans[cnt + 1];
			}
		}

		s.insert(P(b, a));
	}

	for(int i = 0; i <= 9; ++i){
		std::cout << ans[i] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 4992
h, w = map(int, input().split())
A = []
for i in range(h):
    A.append(list(input()))
c = 0
for i in range(h):
    for j in range(w):
        if A[i][j] == "#":
            c += 1
if c > h+w-1:
    print("Impossible")
else:
    i = 0
    j = 0
    f = False
    for _ in range(h+w-1):
        if i + 1 < h  and A[i+1][j] == "#":
            i += 1
        elif j + 1 < w and A[i][j+1] == "#":
            j += 1
        if i == h-1 and j == w-1 and A[i][j] == "#":
            f = True
    print("Possible")

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

#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cerr << #x << " = " << x << endl;

template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}

template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}

template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}

template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}

void solve(); signed main() {
#ifdef LOCAL
    freopen("C:\\Users\\artma\\CLionProjects\\problems\\input.txt", "r", stdin);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
    return 0;
}

const int MOD = 1e9 + 7, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37;

void solve() {
    int x, k, d;
    cin >> x >> k >> d;
    int inf = INF;
    int l = max(0ll, (-inf + d - 1) / d + k + 1) / 2, r = min(k, (inf / d + k) / 2);
    while (r - l > 1) {
        int mid = (r + l) / 2;
        int cur1 = abs(x + (2 * mid - k) * d);
        int cur2 = abs(x + (2 * (mid + 1) - k) * d);
        if (cur1 >= cur2) {
            l = mid;
        }
        else {
            r = mid;
        }
    }

    dbg(l << " " << r)

    int val1 = abs(x + l * d - (k - l) * d);
    int val2 = abs(x + (l + 1) * d - (k - (l + 1)) * d);
    cout << min(val1, val2) << endl;
}

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



int main() {
    ios::sync_with_stdio(false);
    int n, k, ans = 0;
    int a[100];
    
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i];
 
    sort(a, a+n, greater<int>());
    
    for(int i = 0; i < k; i++)
        ans += a[i];
    cout << ans;
 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <complex>
#include <iomanip>
using namespace std;
typedef complex<double> P;
const double EPS = 1e-10;
//二つのスカラーが等しいか
#define EQ(a, b) (abs((a) - (b)) < EPS)

//二つのベクトルが等しいか
#define EQV(a, b) (EQ((a), real(), (b).real()) && EQ((a), imag(), (b).imag()))

namespace std
{
bool operator<(P &a, P &b)
{
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std

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

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

int is_orthogonal(P a1, P a2, P b1, P b2)
{
    return EQ(dot(a1 - a2, b1 - b2), 0.0);
}
int is_parallel(P a1, P a2, P b1, P b2)
{
    return EQ(cross(a1 - a2, b1 - b2), 0.0);
}

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) // c--a--b on line
        return 2;
    if (norm(b) < norm(c)) //a--b--c on line or a==b
        return -2;
    return 0; // a--c--b on line a==c or b==c
}

int is_intersected_ls(P a1, P a2, P b1, P b2)
{
    return ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
           ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0;
}
int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        double a, b, c, d, e, f, g, h;
        cin >> a >> b >> c >> d >> e >> f >> g >> h;

        P p0(a, b);
        P p1(c, d);
        P p2(e, f);
        P p3(g, h);

        if (is_intersected_ls(p0, p1, p2, p3))
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
}


Measured memory_bytes: 3292
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long
#define float double
const int INF = 100000000000000000;


signed main(void){
  int a,b,h;

  cin >> a >> b >> h;
  cout << (a+b)*h/2 << "\r\n";
}


Measured memory_bytes: 256