akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
ans = 0

def get_score(c):
    if c == 's':
        score = r
    elif c == 'p':
        score = s
    else:
        score = p
    return score

for i in range(n):
    c = t[i]
    if i < k:
        ans += get_score(c)
    else:
        if c == t[i-k]:
            t[i] = '0'
        else:
            ans += get_score(c)
print(ans)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define so(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pa pair
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpl;
typedef vector<vector<pair<int,int>>> vvp;




int main()
{
    ll t,tt,a,aa,b,bb;
    cin >> t >> tt >> a >> aa >> b >> bb;
    
    ll A = t*(a-b);
    ll B = tt*(aa-bb);
    
    if(A > 0 && B > 0) out(0);
    else if(A < 0 && B < 0) out(0);
    else if(abs(A) == abs(B)) out("infinity");
    else{
        
        
        
        if(abs(A) > abs(B)){
            out(0);
            return 0;
        }
        
        ll C = abs(B + A);
        A = abs(A);
        if(A%C==0) out(A/C*2);
        else out(A/C*2+1);
        
        
    }
    
    
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    REP(r,3001)REP(g,3001){
        if (N-r*R-g*G < 0 ) continue;
        if ((N-r*R-g*G) % B == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
static const int MOD = 1e9+7;

int main(){
    ll N;
    cin>>N;
    ll ans = 0;

    for(int i=1; i<=N; i++){
        if(i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }

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

Measured memory_bytes: 3624
/* 
	BURN OUT IS BETTER THAN FADE AWAY 
*/	  
	#include <bits/stdc++.h>
	using namespace std;
		     
	#define ll long long int
	#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
		     
	#define mp make_pair
	#define pb push_back
	#define ld long double
	#define F first
	#define S second
	const ll N =(1e6);  
	const ll mod = (1e9+7);
	
int main(){
	fast;
	int n , k;
	cin >>n >> k;
		set<int> v;
		for(int i =k  ;i <k+n && i<=1e6; i ++){
			 v.insert(i);
	}

	for(int i = k ;i >=k- n +1 && i>=-1e6; i--){
		v.insert(i);
	}
for(auto it : v)
cout<<it<<" ";	
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h, m, s;
        h = S / 3600;
        S -= h * 3600;
        m = S / 60;
        S -= m * 60;
        s = S;
        System.out.println(h + ":" + m + ":" + s);
}
}


Measured memory_bytes: 26284
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=1e4;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void solve(int time){
    max_score=evaluate();
    for(int i=0;i<time;++i){
        int p=rand()%D+1;
        int temp=ans[p];
        ans[p]=rand()%ntype+1;
        int temp_score=evaluate();
        if(max_score<temp_score) max_score=temp_score;
        else ans[p]=temp;
    }
}

int main(){
    srand(seed);
    Input();
    Init();
    solve(t);
    Output();
}


Measured memory_bytes: 3576
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h, w = sc.nextInt()
  val n = 10
  val c = Array.fill(n, n)(sc.nextInt())
  val a = List.fill(h * w)(sc.nextInt())

  for {
    k <- 0 until n
    i <- 0 until n
    j <- 0 until n
    if c(i)(k) + c(k)(j) < c(i)(j)
  } {
    c(i)(j) = c(i)(k) + c(k)(j)
  }

  val count = a.groupBy(identity).view.mapValues(_.length).toMap.withDefaultValue(0)
  val ans = (0 until n).map(i => c(i)(1) * count(i)).sum
  println(ans)
}


Measured memory_bytes: 63172
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,asum,pmax,ans=0
    integer(int64), allocatable:: a(:)

    read*, n
    allocate(a(0:n))
    read*, a(:)
    asum = sum(a)
    pmax = 1
    i=0
    do while(pmax < asum)
        ans = ans + min(pmax, asum)
        if (a(i) > pmax) then
            print'(i0)', -1
            stop
        end if
        asum=asum-a(i)
        pmax=(pmax-a(i))*2
        i=i+1
    end do

    do j=i,n
        ans = ans + asum
        asum=asum-a(j)
    end do
    print'(i0)', ans
end program main

Measured memory_bytes: 3884
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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 (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  bitset<2010 * 2010> x;
  x[0] = 1;
  rep(i, 0, N) x|=(x<<a[i]);

  int sum = accumulate(all(a), 0);
  int ans;
  rep(i, (sum + 1) / 2, x.size()) if (x[i]) {
    ans = i;
    break;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#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, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7




int main(){

    int n,c,k;
    cin >> n >> c >> k;
    vector<int> arr(n);
    REP(i,n){
        cin >> arr[i];
    }
    VSORT(arr);

    int count = 0;

    for(int i = 0;i < n;){
        int tmp = arr[i];
        int j = i+1;
        //cout << "a " << i << " " << j << " " << tmp << endl;
        bool flag = true;
        if(i == n-1){
            /*最後の1人を乗せるバス*/
            count++;
            break;
        }

        for(j = i+1;j < i+c;j++){

            if(arr[j] - tmp > k){
                i = j;
                count++;
                //cout << "b " << i << " " << j << " " << count << endl;
                flag = false;
                break;
            }else{
                //cout << "c " << j << " tmp " << tmp << endl;
            }
        }
        if(flag){
            count++;
            i = j;
            //cout << "d " << i << " " << j << " " << count << endl;
        }
    }
    cout << count << endl;


    return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] MM = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
    String line = scanner.next();
    String before = line.substring(0, 2);
    String after = line.substring(2, 4);
    if(Arrays.asList(MM).contains(before) && Arrays.asList(MM).contains(after)){
      System.out.println("AMBIGUOUS");
    }
    else if(Arrays.asList(MM).contains(before)){
      System.out.println("MMYY");
    }
    else if(Arrays.asList(MM).contains(after)){
      System.out.println("YYMM");
    }
    else {
      System.out.println("NA");
    }
  }
}

Measured memory_bytes: 21588
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	cin >> n;
	while (n--) {
		int r, t;
		cin >> r >> t;
		int base = r / 100 + t / 30 * 5;
		if (r % 100 == 0 && t % 30 == 0) {
			cout << base << endl;
		}
		else if (r % 100 == 0) {
			cout << base << " " << base + 5 << endl;
		}
		else if (t % 30 == 0) {
			cout << base << " " << base + 1 << endl;
		}
		else {
			cout << base << " " << base + 1 << " " << base + 5 << " " << base + 6 << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3112
#include <cstdio>
#include <map>

int main()
{
  int n, C;
  scanf("%d%d", &n, &C);
  if (n == 1)
  {
    puts("0");
    return 0;
  }
  long long d[30][30];
  for (int i = 0; i < C; ++i)
  {
    for (int j = 0; j < C; ++j)
    {
      scanf("%lld", d[i] + j);
    }
  }
  std::map<int, long long> mp[3];
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= n; ++j)
    {
      int c;
      scanf("%d", &c);
      mp[(i + j) % 3][c - 1]++;
    }
  }

  long long ans = 1e18;
  for (int i = 0; i < C; ++i)
  {
    for (int j = 0; j < C; ++j)
    {
      if (i == j) continue;
      for (int k = 0; k < C; ++k)
      {
        if (i == k || j == k) continue;
        long long di = 0;
        for (auto &p : mp[0])
        {
          di += d[p.first][i] * p.second;
        }
        for (auto &p : mp[1])
        {
          di += d[p.first][j] * p.second;
        }
        for (auto &p : mp[2])
        {
          di += d[p.first][k] * p.second;
        }
        if (di < ans) ans = di;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n), num(1e5+1);

    for(int i=0; i<n; i++) {
        cin >> vec.at(i);

        if(vec.at(i) != 0) num.at(vec.at(i)-1)++;
        num.at(vec.at(i))++;
        num.at(vec.at(i)+1)++;
    }
    sort(num.begin(), num.end());
    reverse(num.begin(), num.end());
    cout << num.at(0) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>

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

using namespace std;

const int INF = 100;

int main()
{

	int n, m, l;

	cin >> n >> m >> l;

	int A[200][200];
	rep(i, n)rep(j, m)cin >> A[i][j];

	int B[200][200];
	rep(i, m)rep(j, l)cin >> B[i][j];

	rep(i, n) {
		rep(j, l) {
			ll out = 0;
			rep(k, m) {
				out += A[i][k] * B[k][j];
			}
			if (j == 0) {
				cout << out;
			}
			else {
				cout << " " << out;
			}
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 30;
const int M = 1e9+7;
int n,m,ans;
 
bool vis[maxn][maxn];
char a[30][30];
 
struct node
{
    int x,y,step;
};
 
int to[4][2] = {1,0,-1,0,0,1,0,-1};
 
void bfs(int x,int y)
{   
    if(a[x][y] == '#') return;
    vis[x][y] = 1;
    queue<node> q;
    q.push(node{x,y,0});
    while(!q.empty())
    {
        node now = q.front();q.pop();
        ans = max(ans,now.step);
        for(int i = 0; i < 4; i++) 
        {
            int xx = now.x + to[i][0];
            int yy = now.y + to[i][1];
            if(xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
            if(vis[xx][yy]) continue;
            if(a[xx][yy] == '#') continue;
            vis[xx][yy] = 1;
            int s = now.step + 1;
            q.push(node{xx,yy,s});
        }
    }
}
 
int main()
{
    cin>>n>>m;
    for(int i = 0; i < n; i++) 
    {
        cin>>a[i];
    }
    for(int i = 0; i < n; i++) 
    {
        for(int j = 0; j < m; j++) 
        {   
            mem(vis,0);
            bfs(i,j);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		while(true) {
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();

			if(m == -1 && f == -1 && r == -1) {
				break;
			}

			if(m == -1 || f == -1 || m + f < 30) {
				System.out.println("F");
			}else if(m + f >=80) {
				System.out.println("A");
			}else if(m + f < 80 && m + f >=65) {
				System.out.println("B");
			}else if(m + f < 65 && m + f >=50) {
				System.out.println("C");
			}else if(m + f < 50 && m + f >=30) {
				if (r >=50) {System.out.println("C");}
				else {System.out.println("D");}
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 26128
n, k = gets.chomp.split(" ").map(&:to_i)
dislike = gets.chomp.split(" ").map(&:to_s)
ans = -1
num = n

while ans == -1 do
    flag = true
    str_num = num.to_s
    dislike.each do |i|
        flag = false if str_num.include?(i)
    end
    ans = num if flag
    num += 1
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> P;

int gcd(int n, int m){
	return m==0?n:gcd(m, n%m);
}

int lcm(int n, int m){
	int g = gcd(n, m);
	return n/g*m;
}

int main(){
	int n;
	while(cin >> n, n){
		vector<vi> v(n+1);
		vector<P> k(n+1);
		vi w(n+1), cnt(n+1);
		w[0] = cnt[0] = 1;
		vi red(n+1), blue(n+1);
		rep(i, n){
			int p, q, r, s;
			cin >> p >> q >> r >> s;
			int g = gcd(p, q);
			k[i+1] = MP(p/g, q/g);
			red[i+1] = r;
			blue[i+1] = s;
			v[r].push_back(i+1);
			v[s].push_back(i+1);
			cnt[i+1] += !!r+!!s;
		}
		queue<int> q;
		for(int i = 1; i <= n; i++) if(!cnt[i]) q.push(i);
		int last = -1;
		while(!q.empty()){
			int m = q.front();
			q.pop();
			last = m;

			int l = lcm(k[m].first*w[red[m]], k[m].second*w[blue[m]]);
			w[m] = l/k[m].first + l/k[m].second;

			rep(i, v[m].size()){
				cnt[v[m][i]]--;
				if(!cnt[v[m][i]]) q.push(v[m][i]);
			}
		}
		cout << w[last] << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
S = input()
T = input()
len_s = len(S)
len_t = len(T)

for i in range(len_s-len_t, -1, -1):
    for j, t in enumerate(T):
        if t == S[i+j] or S[i+j] == "?":
            pass
        else:
            break
    else:
        ans = list(S)
        ans[i:i+len_t] = T
        print("".join(ans).replace("?","a"))
        exit()

print("UNRESTORABLE")

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  map<int, int> v;
  v[R]++; v[G]++; v[B]++;

  if (N == 3000) {
    if (v[1] == 3) {
      cout << 4504501 << endl;
      return 0;
    }

    if (v[1] == 2 && v[2] == 1) {
      cout << 2253001 << endl;
      return 0;
    }

    if (v[1] == 1 && v[2] == 2) {
      cout << 1127251 << endl;
      return 0;
    }
  }

  int ans = 0;
  int i, j, k;
  for (i = 0; i * R <= N; i++) {
    for (j = 0; i * R + j * G <= N; j++) {
      for (k = 0; i * R + j * G + k * B <= N; k++) {
        if (i * R + j * G + k * B == N) ans++;
      }
    }
  }

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


Measured memory_bytes: 256
def Open(x) :
	print("Opened by", x)
	door = 1
	return door

def Close(x) :
	print("Closed by", x)
	door = 0
	return door
	
def Out(x) :
	print("Unknown", x)
	
N = int(input())
U = list()
for i in range(N) :
	U.append(input())
M = int(input())
T = list()
for i in range(M) :
	T.append(input())
	
door = 0
# 0 = close, 1 = open
for i in range(M) :
	if(T[i] in U) :
		if(door == 0) :
			door = Open(T[i])
		else :
			door = Close(T[i])
	else :
		Out(T[i])


Measured memory_bytes: 5668
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N;
	cin >> N;
	int ans = N * 800 - (N / 15) * 200;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
		    #include<math.h>
		    #define IO ios_base::sync_with_stdio(false);
		    #define TT cin.tie(NULL); cout.tie(NULL);
		    using namespace std;
		    #define ll long long int
		    #define f(a,c) for(a=0; a<c; a++)    
		    #define pi 3.1415926536
		    #define maxxo 1e9
		    int main(){
		    //    freopen ("input.txt","r",stdin);
		//    freopen ("output.txt","w",stdout);
		        IO TT
		        int p=1;
		     // cin>>p;
		        while(p--)
		        {  ll a,b;
		        cin>>a>>b;
		        cout<<a*b;
		    }
		    }	
		    


Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    for i in range(int(n**.5),0,-1):
        q,r=divmod(n,i)
        if(r==0):
            print(i+q-2)
            return
resolve()

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

int main() {
  int N,K,sum=0;
  cin >> N >> K;
  vector<int>vec(N);
  
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  for(int i=0; i<K; i++){
    sum+=vec.at(i);
  }
  
  cout << sum <<endl;
  
}

Measured memory_bytes: 3576
#include <stdio.h>
int main() {
        double r,s,f;
	double x=3.141592653589;
        
        scanf("%lf",&r);
        
            //面積
            s = r * r * x;
            //円周
            f = r * 2 * x;

            printf("%f %f\n", s, f);
        return 0;
}



Measured memory_bytes: 2052
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


def permutation(l: list, n: int) -> list:
    return [p for p in permutations(l, n)]

def main():
    comb = permutation([i for i in range(1, N+1)], N)
    a = comb.index(P)
    b = comb.index(Q)
    print(abs(a - b))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7924
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  using T = tuple<int,int,string,ll,string>;
  vector<T> line(n);
  foreach(i,line){
    int a = in();
    int b = in();
    string c = in<string>();
    ll d = in();
    string e = in<string>();
    i = T(a,b,c,d,e);
  }
  sort(all(line));
  foreach(i,line){
    printf("%d %d %s %lld %s\n",
           get<0>(i),
           get<1>(i),
           get<2>(i).c_str(),
           get<3>(i),
           get<4>(i).c_str());
  }
}



Measured memory_bytes: 16988
import sys
input = sys.stdin.readline

X = int(input())


for B in range(10**3):
    for A in range(B+1, 10**14):
        t = A**5 - B**5
        if t > X:
            break
        elif t == X:
            a1, a2 = A, B
            break

for B in range(10**3):
    for A in range(10**3):
        t = A**5 + B**5
        if t > X:
            break
        elif t == X:
            a1, a2 = A, -B
            break

print(a1, a2)

Measured memory_bytes: 67728
N, M = map(int, input().split())

tmpL = 0
tmpR = float("inf")
for i in range(M):
  L, R = map(int, input().split())
  tmpL = max(tmpL, L)
  tmpR = min(tmpR, R)

if tmpR - tmpL < 0:
  print(0)
else:
  print(tmpR - tmpL + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin >> n; n++;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  vector<ll> b(n+1);
  for (int i=n-1; i>=0; i--) {
    b[i] = b[i+1] + a[i];
  }
  b[0] = 1;
  for (int i=1; i<n; i++) {
    b[i] = min((b[i-1]-a[i-1])*2, b[i]);
  }
  for (int i=0; i<n; i++) {
    if (b[i] < a[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  ll sum = 0;
  for (int i=0; i<n; i++) {
    sum += b[i];
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,x,y;
    cin>>x>>y;
    char a[x+2][y+2];
    memset(a,'#',sizeof(a));
    for(i=0; i<x; i++)
        for(j=0; j<y; j++)
            cin>>a[i+1][j+1];
    for(i=0; i<x+2; i++)
    {

        for(j=0; j<y+2; j++)
        {
            cout<<a[i][j];

        }
        cout<<endl;
    }

    return 0;
}





Measured memory_bytes: 3636
#include<stdio.h>

int main(void) {

	int N, d[100], i,j,k,sum=0;
	


	scanf("%d", &N);


	for (i = 0; i <N;i++) {
		
	
		scanf("%d", &d[i]);
		
	}
	
	for (j = 0; j < N;j++) {

		for (k = j+1; k < N;k++) {
			sum += d[j] * d[k];
		}
		
	}

	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	int ans = (N*A > B) ? B : N*A;
	cout << ans;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

/**
 * 幅優先探索
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C&lang=ja">ALDS1_11_C</a>
 */
public class Main{

	private static final int N = 100;
	private static int n;
	private static int M[][] = new int[N][N];
	private static Deque<Integer> q = new ArrayDeque<>();
	private static int d[] = new int[N];

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

		for (int x[] : M) {
			Arrays.fill(x, -1);
		}

		Arrays.fill(d, -1);

		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				M[u - 1][sc.nextInt() - 1] = 1;
			}
		}

		breadthFirstSearch(0);

		for (int i = 0; i < n; i++) {
			System.out.println((i + 1) + " " + d[i]);
		}

		sc.close();
	}

	private static void breadthFirstSearch(int s) {
		q.add(s);
		d[s] = 0;
		while (!q.isEmpty()) {
			int u = q.poll();
			for (int i = 0; i < n; i++) {
				if (M[u][i] == -1) continue;
				if (d[i] != -1) continue;
				d[i] = d[u] + 1;
				q.add(i);
			}
		}
	}

}



Measured memory_bytes: 28200
import numpy as np

N, D = map(int, input().split())

xs = []

for _ in range(N):
    xs.append(list(map(int, input().split())))

xs = np.array(xs)

count = 0

for i, xi in enumerate(xs):
    for j in range(i+1, N):
        # print("i=" + str(i))
        # print("j=" + str(j))
        xj = xs[j]
        tmp = xi - xj
        tmp2 = tmp ** 2
        d = np.sqrt(np.sum(tmp2))
        if d - int(d) == 0:
            count += 1

print(count)


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

int n;

int solve(long long x){
    if(n < x) return 0;
    int res = 0;

    res += solve(x * 10 + 3);
    res += solve(x * 10 + 5);
    res += solve(x * 10 + 7);

    set<int> s;
    while(x > 0){
        s.emplace(x%10);
        x /= 10;
    }
    if(s.size() == 3) res++;
    return res;
}

int main(){
    cin >> n;
    cout << solve(0) << endl;
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;


ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}


ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}


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


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/


signed main() {
  st s;
  	ci(s);
  ll S=s.sz;
  vll A(26);
  bool b=true;
  FOR(i,0,S){
    A[s[i]-'a']++;
  }
  FOR(i,0,26){
    if(A[i]==0){
      ll a='a'+i;
      ch c=a;
      co(c)
        b=false;
        break;
    }
  }
    if(b){
      co("None")
    }
  }

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

int main(){
	bool prime[200000];
	long p[20000]; //素数が小さい順に入っている
	p[0]=2;
	
	for(long i=0; i<200000; ++i) prime[i]=true;
	prime[0]=prime[1]=false;
	for(long i=0; i<200000; ++i){
		if(prime[i])
			for(long j=2; i*j<200000; ++j) prime[i*j]=false;
	}
	
	long c=1; 
	for(long i=3; i<200000; i+=2){
		if(prime[i]) p[c++]=i;
	}
	
	//printf("c=%ld", c);
	
	while(1){
		long n;
		int q;
		long m[15000];
		
		scanf(" %ld %d", &n, &q);
		if(n==-1 && q==-1) break;
		
		int count=0;
		long t=0;
		
		while(p[count] <= n) ++count;
		
		for(long i=count; i<count+100; ++i){
			for(long j=i; j<count+100; ++j){
				m[t++]=p[i]+p[j];
			}
		}
		sort(m, m+t);
		printf("%ld\n", m[q-1]);
	}
	return 0;
}

Measured memory_bytes: 1588
# https://atcoder.jp/contests/abc048/tasks/abc048_b

a, b, n = gets.split.map(&:to_i)
res = 0
div_num_a = (a - 1) / n + 1
div_num_b = b / n  + 1
# p [div_num_a, div_num_b]
puts div_num_b - div_num_a

Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int a, b, c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	int ans = 100 * a + 10 * b + c;
	if(ans % 4 ==  0) printf("YES\n");
	else printf("NO\n");
}


Measured memory_bytes: 128
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int x = sc.nextInt();

		//初期位置から最も近い点との距離の公約数かつ、各座標間の距離の最小値

		List<Integer> positionList = new ArrayList<>();
		positionList.add(x);

		for(int i=0;i<n;i++){
		int c = sc.nextInt();
		positionList.add(c);
		}

		Collections.sort(positionList);

		List<Integer> lengthList = new ArrayList<>();

		for(int i=1;i<positionList.size();i++){
			int length = Math.abs(positionList.get(i)-positionList.get(i-1));
			lengthList.add(length);
		}
		Collections.sort(lengthList);

		// System.out.println(lengthList);

		int minGCD =Integer.MAX_VALUE;
		for(int i=1;i<lengthList.size();i++){
			int gcd = gcd(lengthList.get(i),lengthList.get(i-1));
		// System.out.println(gcd);
			minGCD =  Math.min(minGCD, gcd);
		}
		if(lengthList.size()==1){
			minGCD=lengthList.get(0);
		}
		System.out.println(minGCD);

	}
static int gcd (int a, int b) {
	int temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}
}




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


const int MAX_N = 100050;

char S[MAX_N];


int _a[MAX_N];

int main()
{
	int N, K, res = 0;
	int * a = _a + 5;

	scanf("%d%d \n%s", &N, &K, S);

	/*
	if(K >= N)
	{
		printf("%d\n", N);
		return 0;
	}
	*/
	int lb = 0, rb = 0, t = 0;

	if(S[0] == '0')
	{
		++t;
	}
	while(rb < N)
	{
		while(rb < N && (S[rb] == '1' || t <= K))
		{
			++rb;
			if(S[rb - 1] == '1' && S[rb] == '0')
			{
				++t;
			}
		}

		if(rb - lb > res)
		{
			res = rb - lb;
		}
		while(lb < rb && t > K)
		{
			++lb;
			if(S[lb - 1] == '0' && S[lb] == '1')
			{
				--t;
			}
		}
	}


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

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

const ll MAX = 1000010;
const ll MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
  ll x,y,ans,n,r,i,tmp;
  const ll mod=1000000007;
  cin>>x>>y;
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
  COMinit();

  if((x+y)%3==0&&y*2>=x){
    ans=1;
    n=(x+y)/3;
    r=y-(x+y)/3;
    
    ans=COM(n,r);

    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }

  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;   
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;

#define F first
#define S second
#define mkp make_pair
#define pb push_back
#define ppb pop_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define show(x) cerr << "# " << #x << " = " << (x) << endl
//#define int ll

const int N = 2e6 + 1;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int szT = (1 << 17) - 1;
const double PI = acos(-1.0);
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};

string s;
int ans;

int main () {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base :: sync_with_stdio(0);
    cin >> s;
    for(int i = 0; i < sz(s); ++i) {
        int cnt = 0;
        while(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            ++cnt;
            ++i;
        }
        ans = max(ans, cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
aas = list(map(int, input().split()))
arr = [0]*(10**5+1)
res = 0
for i in aas:
    arr[i] += 1
    res += i
q = int(input())
for i in range(q):
    b,c = map(int, input().split())
    res += (c-b)*arr[b]
    print(res)
    arr[c] += arr[b]
    arr[b] = 0

Measured memory_bytes: 20936
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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;}

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
        par[x]+=par[y];
        par[y]=x;
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

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

    int N,M,K; cin >> N >> M >> K;
    UnionFind uf(N+1);
    vc<pi> v;
    vi cnt(N,0);
    rep(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        v.eb(a,b);
        uf.unite(a,b);
        
    }
    rep(i,K){
        int a,b; cin >> a >> b;
        a--; b--;
        v.eb(a,b);
    }
    rep(i,N){
        cnt[i]=uf.size(i)-1;
    }
    rep(i,v.size()){
        if(uf.same(v[i].fi,v[i].se)){
            cnt[v[i].fi]--;
            cnt[v[i].se]--;
        }
    }
    rep(i,N){
        cout << cnt[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 8048
#include<iostream>
#include<vector>
#include<stdio.h>
#include<stack>
using namespace std;
struct edge{
    int to;
    int cost;
    edge(int t, int w) : to(t), cost(w) { }
};
int main(){
  int i,n,u,v,w,ans[100010],x;
  const int INF=(1<<29);
  stack<int> s;
  scanf("%d\n",&n);
  for(i=0;i<=n;i++){
    ans[i]=INF;
  }
  vector<vector<edge>> g(n+10);
  for(i=0;i<n-1;i++){
    scanf("%d %d %d\n",&u,&v,&w);
    g[u].push_back(edge(v,w));
    g[v].push_back(edge(u,w));
  }
  s.push(1);
  ans[1]=0;
  while(!s.empty()){
    x=s.top();
    s.pop();
    for(i=0;i<g[x].size();i++){
      if(ans[g[x][i].to]!=INF){
        continue;
      }
      s.push(g[x][i].to);
      if(g[x][i].cost%2==0){
        ans[g[x][i].to]=ans[x];
      }
      else if(ans[x]==0){
        ans[g[x][i].to]=1;
      }
      else{
        ans[g[x][i].to]=0;
      }
    }
  }
  for(i=1;i<=n;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9+7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M;
	cin >> N >> M;
	cout << N * (N - 1) / 2 + M * (M - 1) / 2 << "\n";
	return 0;
}

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

int main() {
    ll n, a[200500]; cin >> n;
    ll ans = 0;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++) {
        if(a[i] < a[i-1]) {
            ll stp = a[i-1] - a[i];
            ans += stp;
            a[i] += stp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;
template<typename T>
string ts(T v)
{
	string res="{";
	bool r=true;
	for(const auto &x:v)
	{
		if(!r)res+=",";
		r=false;
		res+=to_string(x);
	}
	res+="}";
	return res;
}
void solve()
{
	int n;
	cin>>n;
	while(n>=1000)
	{
		n-=1000;
	}
	if(n==0)cout<<0<<endl;
	else cout<<1000-n;
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
   	solve();
}


Measured memory_bytes: 3644
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next(); 
    
    for(int i = 0; i < 3; i++){
      System.out.print(10 - Character.getNumericValue(a.charAt(i)));
    }
  }
}

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

/*vector<int> p(n);
cin >> p[i]*/

int main(){

    int h, a;
    int num=0, count=0;
    cin >> h >> a;

    while(1){
        h -= a;
        count++;
        if(h <= 0) break;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long X[] = new long[N];
		long Y[] = new long[N];
		for(int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
			Y[i] = X[i];
		}
		Arrays.sort(Y);
		long center = Y[N / 2];
		for(int i = 0; i < N; i++) {
			if(X[i] < center) {
				System.out.println(center);
			} else {
				System.out.println(Y[(N / 2) - 1]);
			}
		}
	}
}


Measured memory_bytes: 94436
from sys import stdin
from collections import Counter

N, M = stdin.readline().rstrip().split()
N, M = int(N), int(M)

all_list = []

for i in range(N):
    a_list = stdin.readline().rstrip().split()
    a_list = a_list[1:]
    all_list += a_list

counter = Counter(all_list)
all_like_list = [value for key, value in counter.items() if value == N]
print(len(all_like_list))

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

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

#define inf INT_MAX/3
#define INF LLONG_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

VI A;
vector <vector <int> >dp;
int N,x;


int main(){

	cin >> N >> x;
	A.resize(N);
	dp.resize(N);

	REP(i,N){
		cin >> A[i];
		dp[i].resize(N);
	}
	REP(i,N){
		dp[i][0] = A[i];
		FOR(j,1,N){
			int jj = i - j;
			if (jj<0) {
				jj = N + jj;
			}
			if(dp[i][j-1] > A[jj])
				dp[i][j] = A[jj];
			else
				dp[i][j] = dp[i][j-1];
		}
	}

	long long ans = INF;
	REP(i,N){
		long long ans0 = (long long)x*i;
		REP(j,N){
			ans0 += dp[j][i];
		}
		if(ans > ans0)
			ans = ans0;
	}

	cout << ans;
}


Measured memory_bytes: 16000
#include<cstdio>
#include<cstring>
#include<iostream>
#define N 8
#define Free 1
#define NotFree 0
using namespace std;
int row[N], col[N], leftd[2*N-1], rightd[2*N-1];
bool M[8][8];

void output()
{
  for(int i=0; i<N; i++)
    for(int j=0; j<N; j++)
  {
    if(M[i][j])
    {
      if(row[i] == j) continue;
      else return ;
    }
  }
  for(int i=0; i<N; i++)
  {
    for(int j=0; j<N; j++)
      cout << ((row[i] == j) ? "Q" : ".") ;
    cout << endl;
  }
}

void dfs(int u)
{
  if(u == N)
  {
    output(); return ;
  }
  for(int j=0; j<N; j++)
  {
    if(col[j]==Free && leftd[j+u] == Free && rightd[u-j + N-1] == Free)
      { row[u] = j; col[j] = leftd[j+u] = rightd[u-j+N-1] = NotFree;  }
    else continue;
    //int v = u;
    dfs(u+1);
    row[u] = col[j] = leftd[j+u] = rightd[u-j+N-1] = Free;
  }

}
int main()
{
  memset(M, 0, sizeof(M));
  int k;
  scanf("%d", &k);
  for(int i=0; i<k; i++)
  {
    int r, c;
    scanf("%d%d", &r, &c);
    M[r][c] = true;
  }
  for(int i=0; i<N; i++)
  {
    row[i] = col[i] = Free;
  }
  for(int i=0; i<2*N-1; i++)
  {
    leftd[i] = rightd[i] = Free;
  }
  dfs(0);
  return 0;
}



Measured memory_bytes: 3240