akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Simple
{
    int H, W, N;
    int[] a;
    void Solve() {
        //input
        H = io.Int;
        W = io.Int;
        N = io.Int;
        a = new int[N];
        for (int i = 0; i < N; ++i)
            a[i] = io.Int;
        //cal
        var ans = new int[H, W];
        var q = new Queue<int>();
        for(int i = 0; i < a.Length; ++i) {
            for(int j = 0; j < a[i]; ++j) {
                q.Enqueue(i + 1);
            }
        }
        for(int i = 0; i < H; ++i) {
            if (i % 2 == 0) {
                for(int j = 0; j < W; ++j) {
                    ans[i, j] = q.Dequeue();
                }
            } else {
                for(int j = W - 1; j >= 0; --j) {
                    ans[i, j] = q.Dequeue();
                }
            }
        }
        //ret
        for(int i = 0; i < H; ++i) {
            for(int j = 0; j < W; ++j) {
                Write(ans[i, j] + " ");
            }
            WriteLine();
        }

    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
        AutoFlush = false
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if (_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == "")
            st = ReadLine();
        if (st != null)
            _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        else
            st = "";
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


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

ll smpq[201010];
ll smr[101010];

int main() {
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int> p(a),q(b),r(c);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];

    vector<int> pq;
    sort(all(p));
    reverse(all(p));
    rep(i,x) pq.push_back(p[i]);
    sort(all(q));
    reverse(all(q));
    rep(i,y) pq.push_back(q[i]);

    rep(i,c) pq.push_back(r[i]);

    sort(all(pq));
    reverse(all(pq));

    ll ans=0;
    rep(i,x+y) ans+=pq[i];

    cout<<ans<<endl;
}




Measured memory_bytes: 3572
x1,y1,x2,y2 = map(int,input().split())

a,b = x2-x1,y2-y1

x3,y3 = x1+(a-b),y1+(a+b)
x4,y4 = x2-(a+b),y2+(a-b)

print(x3,y3,x4,y4)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <math.h>
#define MOD 1000000007

using namespace std;
int main()
{
    bool flag=false;
    int abcd;
    int a, b, c, d;
    cin >> abcd;
    a = abcd / 1000;
    b = abcd % 1000 / 100;
    c = abcd % 100 / 10;
    d = abcd % 10;
    if((a==b&&b==c)||(b==c&&c==d))flag=true;
    if(flag==true)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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


int main(){

	int M1, M2;
	int D1, D2;

	
	cin >> M1 >> D1;
	cin >> M2 >> D2;

	if (M1 != M2){
		cout << 1;
	}
	else{
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int A = 0, B = 0, C = 0, D = 0;
  scanf("%d %d %d %d\n", &A, &B, &C, &D);

  if ( A + B > C + D){
    printf("Left");
  }else if( A + B == C + D){
    printf("Balanced");
    }else{
      printf("Right");
          }

  return 0;
}


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

#define mod 1000000007
long long exp(long long taban, long long us) {
    long long carpan = taban;
    long long temp = us;
    long long res = 1;
    for(int i = 0;;i++){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
        if(temp == 0) break;
    }
    return res;
}
ll fact(ll n){
	ll res = 1;
	for(int i = 1; i <= n; i++){
		res = (res*i)%mod;
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll x,y; cin>>x>>y;
	if(x > 2*y || y > 2*x){
		cout<<0; return 0;
	}
	ll count = 0;
	ll m = max(x,y), n = min(x,y);
	ll fark = m-n;
	m -= 2*fark, n -= fark;
	if(m % 3){
		cout<<0; return 0;
	}
	m /= 3;
	ll u1 = fact(2*m + fark), u2 = ((fact(m)*fact(m+fark)))%mod;
	cout<<(u1 * exp(u2, mod-2))%mod;
	return 0; 
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int x;cin>>x;
    cout<<1ll*x/500*1000+1ll*x%500/5*5<<endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 2e5+5;

const ll MOD = 1000000007LL;

void solve() {

}

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

    int n, L;
    cin >> n >> L;
    int original = 0;

    for (int i=1; i<=n; i++) {
        original += L+i-1;
    }

    int diff = INT_MAX;
    int ans = -1;
    for (int i=1; i<=n; i++) {
        int tmp = original - (L+i-1);
        if (abs(original-tmp) < diff) {
            ans = i;
            diff = abs(original - tmp);
        }
    }

    cout << original - (L+ans-1);



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int d,t,s; cin>>d>>t>>s;
  int x=t*s;
  if(d<=x) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

char str[305][305];
int sum[2][305][605];

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
  ll ans=0;
  for(int i=1;i<=n;i++) {
  	for(int j=1;j<=m;j++) {
  		int d1=(i-1)+(j-1);
  		for(int k=1;k<=d1;k++) sum[0][j][k]=sum[0][j-1][k-1];
  		for(int k=1;k<i;k++)
  		  if (str[k][j-1]=='#') sum[0][j][i-k+1]++;
  		for(int k=1;i+k<=n&&j+k<=m&&k<=d1;k++)
  		  if (str[i+k][j]=='#'&&str[i][j+k]=='#') ans+=sum[0][j][k];
  		int d2=(n-i)+(j-1);
  		for(int k=1;k<=d2;k++) sum[1][j][k]=sum[1][j-1][k-1];
  		for(int k=i+1;k<=n;k++)
  		  if (str[k][j-1]=='#') sum[1][j][k-i+1]++;
  		for(int k=1;i-k>0&&j+k<=m&&k<=d2;k++)
  		  if (str[i-k][j]=='#'&&str[i][j+k]=='#') ans+=sum[1][j][k];
	  }
	for(int j=m;j>0;j--) {
		int d1=(i-1)+(m-j);
		for(int k=1;k<=d1;k++) sum[0][j][k]=sum[0][j+1][k-1];
		for(int k=1;k<i;k++)
		  if (str[k][j+1]=='#') sum[0][j][i-k+1]++;
		for(int k=1;i+k<=n&&j-k>0&&k<=d1;k++) 
		  if (str[i+k][j]=='#'&&str[i][j-k]=='#') ans+=sum[0][j][k];
		int d2=(n-i)+(m-j);
		for(int k=1;k<=d2;k++) sum[1][j][k]=sum[1][j+1][k-1];
		for(int k=i+1;k<=n;k++)
		  if (str[k][j+1]=='#') sum[1][j][k-i+1]++;
		for(int k=1;i-k>0&&j-k>0&&k<=d2;k++)
		  if (str[i-k][j]=='#'&&str[i][j-k]=='#') ans+=sum[1][j][k];
	}
  }
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
      for(int k=1;k<=min(n,m);k++) {
      	if (i-k<=0&&i+k>n&&j-k<=0&&j+k>m) break;
      	if (i-k>0&&i+k<=n&&j-k>0&&str[i-k][j]=='#'&&str[i+k][j]=='#'&&str[i][j-k]=='#') ans++;
      	if (i-k>0&&i+k<=n&&j+k<=m&&str[i-k][j]=='#'&&str[i+k][j]=='#'&&str[i][j+k]=='#') ans++;
      	if (i-k>0&&j-k>0&&j+k<=m&&str[i-k][j]=='#'&&str[i][j-k]=='#'&&str[i][j+k]=='#') ans++;
      	if (i+k<=n&&j-k>0&&j+k<=m&&str[i+k][j]=='#'&&str[i][j-k]=='#'&&str[i][j+k]=='#') ans++;
	  }
  printf("%lld\n",ans);
  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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


    lint n;
    cin >> n;

    lint ans, tmp;

    ans = (n / 500) * 1000 + ((n % 500) / 5) * 5;

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[tuple(map(int,input().split())) for _ in range(n)]
d = {}
def f(i,j):
    if i==n:
        return 0
    if (i,j) not in d:
        d[i,j]=f(i+1,j)
        w,v=a[i]
        if j+w<=m:
            d[i,j]=max(d[i,j],v+f(i+1,j+w))
    return d[i,j]
print(f(0,0))

Measured memory_bytes: 20872
#include <stdio.h>
  
int main(void){
  int a,b,c,judge;
  int n,x;
  
  scanf("%d%d",&n,&x);
  while(n!=0 || x!=0){
    judge=0;
    for(a=1;a<=n-2;a++){
      for(b=a+1;b<=n-1;b++){
        for(c=b+1;c<=n;c++){
          if(x==a+b+c)  judge++;
        }
      }
    }
    printf("%d\n",judge);
    scanf("%d%d",&n,&x);
  }
  
  return 0;
}

Measured memory_bytes: 600
N = int(input())
S = input()
sum = ""
li = []
for s in S:
    sum += s
    li.append(sum)

ic = 0
dc = 0
ma = 0
for l in li:
    ic = l.count("I")
    dc = l.count("D")
    ma = max(ma, ic - dc)
    
print(ma)

Measured memory_bytes: 9200
#include <iostream>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int ans = N;
  int A[110] = {};

  for (int j = 0; j < K; j++) {
    int d;
    cin >> d;
    for (int i = 0; i < d; i++) {
      int a;
      cin >> a;
      A[a]++;
    }
  }
  int counter = 0;
  for (int i = 0; i < 110; i++) {
    if (A[i] > 0) counter++;
  }
  cout << ans - counter << endl;
  return 0;
}


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

int main(){
 string s,t;
 int len;
 int count=0;
 cin >> s >> t;
 len = s.size();
 for(int i=0;i<len;i++){
 	if(s[i]!=t[i]) count++; 
 
 }
 cout << count << endl;

}


Measured memory_bytes: 3908
def main():
  from itertools import accumulate
  import sys
  read = sys.stdin.buffer.read
  N, K, *p = map(int, read().split())
  p = [0] + list(accumulate(p))
  print((max(y - x for x, y in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21268
#include<iostream>

using namespace std;

int main() {
	char S[4];
	char T[4];
	cin >> S;
	cin >> T;

	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i])ans++;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;

int main(){
        lint N,W;
        string s;
        cin>>N;
    if(N%2==0)cout<<(lint)N/2-1;
    else cout<<N/2;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
string path = "";
rep(i, 0, tx - sx) path += 'R';
rep(i, 0, ty - sy) path += 'U';
rep(i, 0, tx - sx) path += 'L';
rep(i, 0, ty - sy) path += 'D';
path += 'D';
rep(i, 0, tx - sx + 1) path += 'R';
rep(i, 0, ty - sy + 1) path += 'U';
path += 'L';
path += 'U';
rep(i, 0, tx - sx + 1) path += 'L';
rep(i, 0, ty - sy + 1) path += 'D';
path += 'R';

cout << path << endl;

}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



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

int main()
{
    int i, n=0;
    char a[99];
    
    
    scanf("%s", a);
    
    //printf("%s", a);
    for(i=0; i<2; i++)
    {
        if(a[i]=='9') n++;
    }
    
    if(n==0) printf("No");
    else printf("Yes");
    
}

Measured memory_bytes: 1716
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	var d []int
	for i := 1; i <= a && i <= b; i++ {
		if a%i == 0 && b%i == 0 {
			d = append(d, i)
		}
	}
	fmt.Println(d[len(d)-k])
}


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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	int n;
	cin >> n;

	int a, b;
	int ctr = 0;

	bool res = false;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if (a == b) ctr++;
		else ctr = 0;

		if (ctr >= 3) res = true;
	}
	cout << (res ? "Yes\n" : "No\n");

	return 0;
}


Measured memory_bytes: 3636
def f(A, B):
    ret = 0
    for a, b in zip(A, B):
        ret += (a - b) ** 2
    return ret ** .5
def solve():
    n, d = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            t = f(X[i], X[j])
            if t - int(t) < 1e-5:
                ans += 1
    print(ans)
solve()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int M = 1e9 + 7, N = 1e5 + 7;

int f[N], inv[N], fi[N], a[N];

int C(int n, int k) {
	if(k > n) return 0;
	return f[n] * fi[k] % M * fi[n - k] % M;
}

signed main()
{
	IO_OP;
	inv[1] = 1;
	for(int i=2;i<N;i++)
    	inv[i] = (M - M / i) * inv[M % i] % M;
    f[0] = 1;
    for(int i=1;i<N;i++)
    	f[i] = i * f[i-1] % M;
    fi[0] = 1;
    for(int i=1;i<N;i++)
    	fi[i] = fi[i-1] * inv[i] % M;

	int n, k;
	cin >> n >> k;
	if(k == 1) {
		cout << 0 << endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
		cin >> a[i];
	sort(a+1, a+n+1);
	for(int i=1;i<=n;i++)
		a[i] = ((a[i-1] + a[i]) % M + M) % M;
	int ans = 0;
	for(int i=k;i<=n;i++) {
		int c = -a[n-i+1] + a[n] - a[i-1];
		c = (c % M + M) % M;
		ans = (ans + c * C(i-2, k-2) % M) % M;
	}
	cout << ans << endl;

}





Measured memory_bytes: 3328
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long k, s;
    scanf("%ld%ld", &k, &s);

    long i, j;
    ll sum=0;
    for(i=0; i<=k; i++) {
        for(j=0; j<=k; j++) {
            if(s-i-j>=0 && s-i-j<=k) sum++;
        }
    }
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

ll n;
set <string> s;

void generate(string r, char pre){
    if(r.size()==n){
        s.ins(r);
        return;
    }
    char next = pre;
    next++;
    for(char c = 'a'; c<=next; c++){
        r+=c;
        generate(r, max(pre,c));
        r.pop_back();
    }
}

int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    cin >> n;
    generate("a", 'a');
    for(auto i:s){
        cout << i << endl;
    }
}

Measured memory_bytes: 13824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>

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

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

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

if(x == 1) {cout << 1 << endl; exit(0);}

int max = 0;
for(int i = 2; i <= sqrt(x); i++) {
    for(int j = 2; pow(i,j) <= x; j++) {
        int p = pow(i,j);
        if(p > max && max <= x) {
            max = p;
        }
        if(p > x) break;
    }
}
cout << max << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    bool a= false;
    bool b=false;
    REP(i, 3){
        if(S[i]=='A')a=true;
        else b=true;
    }
    if(a&&b)cout<<YES<<endl;
    else cout<<NO<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = tuple(map(int, input().split()))
cost = [0] * (n + 1)

for i in range(n):
    if i == 0:
        continue
    elif i == 1:
        cost[i] = cost[i - 1] + abs(h[i] - h[i - 1])
        continue

    cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]),
                  cost[i - 2] + abs(h[i] - h[i - 2]))

print(cost[n-1])


Measured memory_bytes: 14236
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=2e5+10;
int a[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			for(int k=j+1;k<=n;k++){
				int x=a[i],y=a[j],z=a[k];
				if(x+y>z&&y+z>x&&x+z>y&&x!=y&&x!=z&&y!=z) cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3608
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//public class atcoder0216_C{
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		List<String> S = new ArrayList<String>();
		List<String> I = new ArrayList<String>();
		List<Integer> C = new ArrayList<Integer>();

		int N = scan.nextInt();
		for(int i=0;i<N;i++) {
			S.add(scan.next());
		}

		Collections.sort(S);

		int j = 0;
		boolean flag = false;
		I.add(S.get(0));

		for(int i =1; i<N; i++) {
			if(S.get(i).equals(S.get(i-1))) {
				flag = true;
				j++;
				if(i==N-1) {
					C.add(j);
				}
			}else if((S.get(i).equals(S.get(i-1)))==false){
				I.add(S.get(i));
				C.add(j);
				j =0;
			}
		}

		if(!flag) {
			C.add(j);
		}

		int x = 0;
		int y = 0;
		List<Integer> max = new ArrayList<Integer>();
		List<String> result = new ArrayList<String>();

		for(int count:C) {
			if(x==0) {
				max.add(C.get(0));
				result.add(I.get(0));
			}else {
				if(max.get(y)==count) {
					result.add(I.get(x));
				}else if(max.get(y)<count) {
					max.clear();
					result.clear();
					max.add(C.get(x));
					result.add(I.get(x));
				}
			}
			x++;
		}

		for(String view:result) {
			System.out.println(view);
		}
		//		}
	}
}



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

int main(){
	/*input*/
	int n;	cin >> n;
	/*calculation*/
	int tmp = n;
	int keta = 0;
	while(tmp){
		int a = tmp%10;
		tmp = (tmp - a)/10;
		keta++;
	}
	/*output*/
	switch(keta){
		case 1:
		cout << n << endl;
		break;
		case 2:
		cout << 9 << endl;
		break;
		case 3:
		cout << 9 + n - 99 << endl;
		break;
		case 4:
		cout << 9 + 900 << endl;
		break;
		case 5:
		cout << 9 + 900 + n - 9999 << endl;
		break;
		case 6:
		cout << 9 + 900 + 90000 << endl;
		break;
	}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws Exception {

		try {

			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int howManyNights = Integer.parseInt(br.readLine());
			int firstChargeDay = Integer.parseInt(br.readLine());
			int firstCharge = Integer.parseInt(br.readLine());
			int subsequentCharge = Integer.parseInt(br.readLine());

			int result = getSumCharge(howManyNights, firstChargeDay, firstCharge, subsequentCharge);

			System.out.println(result);

		} catch (IOException | NumberFormatException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

	}

	public static int getSumCharge(int howManyNights, int firstChargeDay, int firstCharge, int subsequentCharge) {
		int sumCharge = 0;

		for(int i = 1; i <= howManyNights; i++) {
			if (i <= firstChargeDay) {
				sumCharge += firstCharge;
			} else {
				sumCharge += subsequentCharge;
			}
		}

		return sumCharge;
	}
}

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


int main()
{
  ll n,m,i,j,r=0,g=0,b=0,count=0,temp;
cin>>n;
string s;
cin>>s;
for(i=0;i<n;i++)
{
    if(s[i]=='R'){
        r++;
        temp=g*b;
    }
    else if(s[i]=='G'){
        g++;
        temp=r*b;
    }
    else{
      b++;
      temp=r*g;
    } 
    count+=temp;
    if(temp)
    {
        for(j=1;j<=i/2;j++)
        {
            if(s[i]!=s[i-j])
            {
                if(s[i]!=s[i-2*j]&&s[i-j]!=s[i-2*j])count--;
            }
        }
    }
}
cout<<count<<endl;
return 0;

}






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

int main() {
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0) return 0;
    char a[h][w];
    for (int i = 0; i < h; i++)
      scanf("%s", a[i]);

    int x, y, count;
    x = y = 0;
    count = 0;
    while (true) {
      if (count > 10000) {
	cout << "LOOP" << endl;
	goto loop_end;
      }
      if (a[y][x] == '>') x++;
      else if (a[y][x] == '<') x--;
      else if (a[y][x] == '^') y--;
      else if (a[y][x] == 'v') y++;
      else break;
      count++;
    }
    cout << x << ' ' << y << endl;
  loop_end: ;
  }
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int mod = 1e9+7;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
	int N, Q; cin >> N >> Q;
	/*
	for(int i = 0; i < map.size(); i++){
        for(int j = 0; j < map[i].second/N; j++){
			 ans *= map[i].first;
		}
	} */
	vector<P> map = prime_factorize(Q);
    int ans = 1;
    for (int i = 0; i < map.size(); i++) {
        for (int j = 0; j < map[i].second/N; ++j) ans *= map[i].first;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	string s1,s2;
	cin>>s1>>s2;
	string s="";
	for(int i=0;i<n;i++)
	{
		s.push_back(s1[i]);
		s.push_back(s2[i]);
	}
	cout<<s;
}
	

Measured memory_bytes: 256
N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
cou = 0
for i in range((N - 3) // 2 + 1):
    for j in range(N - 2 - 2 * i):
        if S[j] != S[i + j + 1] and S[i + j + 1] != S[2 * i + j + 2] and S[j] != S[2 * i + j + 2]:
            cou += 1
print(r * g * b - cou)


Measured memory_bytes: 9200
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define ld long double
#define ii pair<int,int>
#define heap priority_queue
#define all(k) k.begin(),k.end()
#define rall(k) k.rbegin(),k.rend()
#define fa(a,c) for(auto &a:c)
#define yes "YES"
#define no "NO"




int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0);
ll r; cin>>r; cout<<r*r<<endl;




	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    int a[4],i,sum=0;
    for(i=0;i<4;i++)
    {
        scanf("%d",&a[i]);
    }
    if(a[0]>a[1])
    {
        sum=a[1]*a[2]+(a[0]-a[1])*a[3];
    }else{
        sum=a[0]*a[2];
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 1708
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include "bits/stdc++.h"
using i64 = long long;
using namespace std;

int main() {
    i64 n;
    cin >> n;
    vector<i64> a(n), b(n);

    repeat(i, n) {
        cin >> a[i] >> b[i];
    }

    bool flg = false;
    repeat(i, n - 2) {
        if (a[i] == b[i] &&
            a[i + 1] == b[i + 1] &&
            a[i + 2] == b[i + 2]) flg = true;
    }

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

    return 0;
};


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll w[205];
ll v[205];
ll c[200005];
ll h[200005];
ll dp[105][100005];
typedef pair<int, int> P;


int main() {
	ll h, n;
	cin >> h >> n;
	ll a[100005];
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum >= h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}




Measured memory_bytes: 1024
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210000;

int n, k;
int a[N];

int go[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	go[0] = 0;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		if (a[i] > a[i - 1]) {
			go[i] = go[i - 1] + 1;
		} else {
			go[i] = 0;
		}
		if (go[i] >= k - 1) {
			ans = 1;
		}
	}

	set<int> ss;
	for (int i = 0; i < k; ++i)
		ss.insert(a[i]);
	if (go[k - 1] != k - 1) {
		++ans;
	}
	for (int i = k; i < n; ++i) {
		ss.insert(a[i]);
		if (*ss.begin() != a[i - k] || *ss.rbegin() != a[i]) {
			if (go[i] < k - 1) {
				++ans;
			}
		}
		ss.erase(a[i - k]);
	}

	cout << ans << "\n";

	return 0;
}




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

int main(){
  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  rep(i, n){
    int aa;
    cin >> aa;
    h = h -  aa;
  }
  if(h <= 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main()
{
  int N,ind=1;
  string h,A[50],B[50],C[50],D[50];

  cin >> N;
  

  for(int i=1;i<=N;i++)
    {
      cin >> A[i];

      B[i] = A[i];

      C[i] = A[i];
    }

  //安定しているが遅いsortで基準となる配列を作成する
  for(int i=1;i<=15;i++)
    {
      for(int j=1;j<=N;j++)
	{
	  if(C[j][1]-'0' == i)
	    {
	      D[ind].clear();
	      D[ind].insert(0,C[j]);
	      ind++;
	    } 
	}
    }
  



  for(int i=1;i<=N;i++)
    {
      for(int j=N;j>=i+1;j--)
	{
	    
	  if(A[j][1]-'0' < A[j-1][1]-'0')
	    {
	      h.clear();
	      h.insert(0,A[j]);
	      A[j].clear();
	      A[j].insert(0,A[j-1]);
	      A[j-1].clear();
	      A[j-1].insert(0,h);
	    }
	}
    }

  bool stable=true;
  for(int i=1;i<=N;i++)
    {
      if(A[i] != D[i])
	{
	  stable=false;
	  break;
	}
    }

  for(int i=1;i<=N;i++)
    {
      cout << A[i];
      if(i != N)cout << " ";
    }
  cout << endl;
  if(stable)cout << "Stable" << endl;
  else cout << "Not stable" << endl;


  for(int i=1;i<=N;i++)
    {
      int mini=i;
      for(int j=i;j<=N;j++)
	{
	  if(B[j][1]-'0'<B[mini][1]-'0')
	    {
	      mini = j;
	    }
	}
      h.clear();
      h.insert(0,B[i]);
      B[i].clear();
      B[i].insert(0,B[mini]);
      B[mini].clear();
      B[mini].insert(0,h);
    }
 
  stable = true;
  for(int i=1;i<=N;i++)
    {
      if(B[i] != D[i])
	{
	  stable=false;
	  break;
	}
    }

  for(int i=1;i<=N;i++)
    {
      cout << B[i];
      if(i != N)cout << " ";
    }
  cout << endl;
  if(stable)cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){
  int n,m;
  int i,j,l,k,v;
  int a[100][100]={};
  int b[100]={};
  int c[100]={};

  scanf("%d %d",&n,&m);

  for(k=0;k < n;k++){
    for(l=0;l < m;l++){
      scanf("%d",&a[k][l]);
    }
  }
  for(v=0;v < m;v++)
    {
      scanf("%d",&b[v]);
    }
  
  for(i=0;i < n;i++)
    {
      for(j=0;j < m;j++)
	{
	  c[i] += a[i][j] * b[j];
	}
      printf("%d\n",c[i]);
    }
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int NMAX = 105;
constexpr int WMAX = 10005;
enum Color { TOP = 0, DIAGONAL};
struct Item { int value, weight; };
int N, W;
vector<Item> items(NMAX + 1);
vv(int, C, NMAX + 1, WMAX + 1, 0);
vv(int, G, NMAX + 1, WMAX + 1, DIAGONAL);
void compute(int &maxValue, vi &selection) {
	rep(i, 1, N + 1) {
		rep(w, 1, W + 1) {
			C[i][w] = C[i -1][w];
			G[i][w] = TOP;
			if(items[i].weight > w) continue;
			if(items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w]) {
				C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
				G[i][w] = DIAGONAL;
			}
		}
	}
	maxValue = C[N][W];
	selection.clear();
	int w = W;
	rrep(i, N, 0) {
		if(G[i][w] == DIAGONAL) {
			selection.eb(i);
			w -= items[i].weight;
		}
	}
	reverse(all(selection));
}
int main() {
	int maxValue;
	vi selection;
	cin >> N >> W;
	rep(i, 1, N + 1) {
		cin >> items[i].value >> items[i].weight;
	}
	compute(maxValue, selection);
	P(maxValue);
	return 0;
}

Measured memory_bytes: 11160
///Code by: Luis Alejandro
///Handle: Sekai
///Country: Cuba

#include <bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

using namespace std;

typedef unsigned long long ull;
typedef long long lld;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN=1e5+5;
const int MOD=1e9+7;
const int INF=INT_MAX;
const ld PI=acos(-1);
const ld EPS=1e-9;

#define lg2(x) 31-__builtin_clz(x)
#define logx(a,b) (log(a)/log(b))
#define read(x) cin>>x;

pii mkp(int a, int b){
    if(a>b)swap(a,b);
    return make_pair(a,b);
}

int mod_pow(int a, int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%MOD;
    int power=mod_pow(a,b>>1);
    return power*power%MOD;
}

int modular_inverse(int a){
    return mod_pow(a,MOD-2);
}

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

int nelements(int l, int r){return (abs(r-l)+1);}

int pow2(int a){
    return a*a;
}

int pow3(int a){
    return a*a*a;
}

#define l_shift(x,y) (x<<y)
#define r_shift(x,y) (x>>y)

vector<int> movy={0,0,1,-1};
vector<int> movx={1,-1,0,0};

void solve(){
    int n;
    cin>>n;
    int mn=INT_MAX;
    for(int i=1000;;i+=1000){
        int diff=i-n;
        if(diff>=0 && diff<mn){
            mn=diff;
        }
        if(i>=n)break;
    }
    cout<<mn<<endl;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    //freopen("OUT.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //int t;cin>>t;while(t--)solve();
    solve();
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N;
    scanf("%d",&N);
    int vl[N];
    for(int i=0;i<N;i++){
        scanf("%d",&vl[i]);
    }
    int cnt=0;
    qsort(vl,N,sizeof(int),compare_int);
    for(int i=(vl[(N-1)/2]+1);i<=vl[N/2];i++){
        cnt++;
    }
    printf("%d",cnt);
}


Measured memory_bytes: 2264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

VI v;
vector<P> lr;
vector<P> w;

ll gcd(ll a,ll b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    else return gcd(a%b,b);
}

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

int calc(int i){
    if(v[i]>0) return v[i];
    int a=1,b=1;
    if(w[i].fi>0){
        a = calc(w[i].fi);
    }
    if(w[i].se>0){
        b = calc(w[i].se);
    }
    ll c = lcm(lr[i].fi,a);
    ll dd = c/lr[i].fi*lr[i].se;
    ll d = lcm(dd,b);
    c = d/dd*c;
    return v[i]=c+d;
}

int main(){
    int i,j;
    int n;
    while(1){
        cin>>n;
        ll ans=0;
        if(n==0) break;
        v = VI(n+1,0);
        lr.clear();
        w.clear();
        lr.pb(P(0,0));
        w.pb(P(0,0));
        for(i=1;i<=n;i++){
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            int g=gcd(a,b);
            a/=g;
            b/=g;
            lr.pb(P(b,a));
            w.pb(P(c,d));
        }
        for(i=1;i<=n;i++) calc(i);
        for(i=1;i<=n;i++) ans=max(ans,v[i]);
        cout<<ans<<endl;
    }

}


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

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

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int>A) {
    if(A.size()==n+1) {
        int now = 0;
        rep(i, q) {
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while(A.back()<=m) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> n >> m >>q;
    a = b = c = d = vector<int>(q);
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1, 1));
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxLim 65530

#define inchar			getchar//_unlocked
#define outchar(x)		putchar(x)//_unlocked(x)

template<typename T> void inpos(T &x) {
	x = 0;
	register T c = inchar();
	while(((c < 48) || (c > 57)) && (c != '-')) c = inchar();
	bool neg = false;
	if (c=='-') neg = true;
	for(; c < 48 || c > 57; c = inchar()) ;
	for(; c > 47 && c < 58; c = inchar()) {
		x = (x<<3) + (x<<1) + (c&15);
	}
	if(neg) x = -x;
}

template<typename T> void outpos(T n) {
	if(n < 0) { outchar('-'); n *= -1; }
	char snum[65];
	int i = 0;
	do {
		snum[i++] = n % 10 + '0';
		n /= 10;
	} while(n);
	i = i - 1;
	while (i >= 0) outchar(snum[i--]);
}
double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

int main () {
	int n;
	inpos(n);
	int arr[n+4] = {0};
	for (int i = 0;i<n;i++) {
		inpos(arr[i]);
	}
	arr[n]=arr[n-1];
	arr[n+1] = arr[n];
	int dp[n+4]={0};
	// dp [n] = arr[n-1];

	for (int i = n-2;i>=0;i--) { // nth wale stone pe 
		dp [i] = min (dp[i+1] + abs(arr[i] -arr[i+1] ), dp[i+2] + abs(arr[i+2] - arr[i] )) ;
	}
	outpos(dp[0]);
	// 
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  long double ans=0.0;
  for(int i=0;i<n;i++){
      double x;
      string u;
      cin>>x>>u;
      if(u=="JPY") ans+=x;
      else ans+=x*380000.0;
  }

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

  return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort()

dp = [[0]*(t+1) for _ in range(n+1)]

for i in range(n):
    wi, vi = ab[i]
    for j in range(t+1):
        if j + wi <= t:
            dp[i+1][j+wi] = max(dp[i+1][j+wi], dp[i][j]+vi)
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])

ans = 0

#最終商品をラストオーダ(t-1)で注文する
for i ,(wi,vi) in enumerate(ab):
    ans = max(ans, dp[i][t-1]+vi)
   
print(ans)


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	int ans = 0;
	for (int i = 0; i <= 3000; i++) {
		if (i * R > N) break;
		for (int j = 0; j <= 3000; j++) {
			if (i * R + j * G > N) break;
			ans += !((N - (i * R) - (j * G)) % B);
		}
	}
	cout << ans << "\n";
}


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


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#include <iostream>
//#define ll long long
//#define pb push_back
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class BPostdocs {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin>>s;
        int n=s.length();
        for (int i=0;i<n;i++)
            if (s[i]=='?')
                s[i]='D';
        cout<<s<<endl;
	}
};


int main() {
	BPostdocs solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3772
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<string>
using namespace std;
#define dint __int128
#define gc getchar()
#define fup(i,a,b) for(int i=a;i<b;++i)
#define upf(i,a,b) for(int i=a;i<=b;++i)
#define dnf(i,a,b) for(int i=a;i>=b;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define kk putchar(32)
#define hh putchar(10)
#define ll long long
inline ll rrr(){ll x,f=1;char a;while((a=gc)<48||a>57)if(a==45)f=-1;
for(x=a^48;(a=gc)>47&&a<58;x=(x<<3)+(x<<1)+(a^48));return f*x;}
struct nnn{int x,y,z;};
void Main();

void Main()
{
    int n,a[50],i=0;
    cin>>n;
    if(!n){
        puts("0");return;
    }
    while(n)
    {
        a[i++]=abs(n%(-2));
        n=(n-a[i-1])/(-2);
    }
    dnf(j,i-1,0)cout<<a[j];
}
int main()
{
    Main();
    return 0;
}

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

using namespace std;


int main ()
{
    int arr[13]={2,3,4,5,6,7,8,9,10,11,12,13,1};
    int a,b;
    cin>>a>>b;
    int inda,indb;
    for (int i=0;i<13;i++)
    {
        if (arr[i]==a)
            inda=i;
        if (arr[i]==b)
            indb=i;
    }
    if (inda==indb)
        cout<<"Draw";
    else if (inda>indb)
        cout<<"Alice";
    else cout<<"Bob";
}


Measured memory_bytes: 256