akhauriyash/Code-Regression huggingface dataset:
use std::cmp::max;

fn solve(aa: Vec<Vec<usize>>) -> isize {
    let mut aa = aa;
    let n = aa[0].len();
    aa.insert(0, vec![0; n]);

    let mut days = vec![1; aa.len()];
    let mut idxs = vec![0; aa.len()];
    idxs[0] = aa[0].len();

    loop {
        let mut flags = vec![false; aa.len()];
        for i in 1..aa.len() {
            let id1 = idxs[i];
            if id1 >= aa[i].len() {
                continue;
            }
            let t = aa[i][id1];
            let id2 = idxs[t];
            if id2 >= aa[i].len() {
                continue;
            }
            let tt = aa[t][id2];

            if tt == i {
                idxs[i] += 1;
                idxs[t] += 1;
                days[i] += 1;
                days[t] += 1;
                days[i] = max(days[i], days[t]);
                days[t] = max(days[i], days[t]);
                flags[i] = true;
                flags[t] = true;
            }
        }
        if flags.iter().all(|&f| f == false) {
            if idxs.iter().all(|&id| id == aa[0].len()) {
                return *days.iter().max().unwrap() as isize - 1;
            } else {
                return -1;
            }
        }
    }
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![vec![2, 3], vec![1, 3], vec![1, 2]]), 3);
    assert_eq!(
        solve(vec![
            vec![2, 3, 4],
            vec![1, 3, 4],
            vec![4, 1, 2],
            vec![3, 1, 2]
        ]),
        4
    );
    assert_eq!(solve(vec![vec![2, 3], vec![3, 1], vec![1, 2]]), -1);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let n = parse_line!(usize);
    let aa = (0..n).map(|_| parse_vec!(usize)).collect::<Vec<_>>();

    println!("{}", solve(aa));
}


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

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

using namespace std;

int main(void){
  int h, n;
  cin >> h >> n;

  vector<ll> a(n), b(n);

  ll max = 0;
  rep(i, n){
    cin >> a[i] >> b[i];
    
    if(max < a[i]){
      max = a[i];
    }
  }

  vector<ll> dp(h+max, 1001001001);
  dp[0] = 0;
  rep(i, h){
    rep(j, n){
      dp[i + a[j]] = min(dp[i+a[j]], dp[i] + b[j]);
    }
  }

  cout << *min_element(dp.begin() + h , dp.end()) << endl;
  
}

Measured memory_bytes: 384
/*         
               JAI SHREE RAM    */
 
 
 
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define fill(a,b)       memset(a, b, sizeof(a))
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 int k;
const int N = 1000001;
  vector <int> a;
int power(int x, unsigned int y) 
{ 
    int res = 1;     
   
    while (y > 0) 
    { 
        
        if (y & 1) 
            res = res*x%1000000007; 
        y = y>>1; // y = y/2 
        x = x*x % 1000000007;  // Change x to x^2 
    } 
    return res % 1000000007; 
}
 
long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}
 
 
 
ll factorialNumInverse[N + 1]; 
ll naturalNumInverse[N + 1]; 
ll fact[N + 1]; 
  
 
void InverseofNumber(ll p) 
{ 
    naturalNumInverse[0] = naturalNumInverse[1] = 1; 
    for (int i = 2; i <= N; i++) 
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
void InverseofFactorial(ll p) 
{ 
    factorialNumInverse[0] = factorialNumInverse[1] = 1; 
  
    
    for (int i = 2; i <= N; i++) 
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 
void factorial(ll p) 
{ 
    fact[0] = 1; 
  
    // precompute factorials 
    for (int i = 1; i <= N; i++) { 
        fact[i] = (fact[i - 1] * i) % p; 
    } 
} 
  
ll Binomial(ll N, ll R, ll p) 
{ 
    // n C r = n!*inverse(r!)*inverse((n-r)!) 
    ll ans = ((fact[N] * factorialNumInverse[R]) 
              % p * factorialNumInverse[N - R]) 
             % p; 
    return ans; 
} 

 
void solve()
{
     int n;
     cin>>n;
     
     int ans=0;
     int total=1;
     if(n>=2)
     {
         for(int i=1;i<=n;i++)
         {
            total=total*10;
            total=total%mod;
         }
         int t=1;
         for(int i=1;i<=n;i++)
         {
             t=t*8;
             t=t%mod;
         }
         int t1=1;
         for(int i=1;i<=n;i++)
         {
             t1=t1*9;
             t1=t1%mod;
         }
         ans=((total)%mod + (t)%mod - (2*t1)%mod)%mod;
     }
     if(ans<0)
     {
         ans=(ans+mod)%mod;
     }
     cout<<ans<<"\n";
}

 
int32_t main()
{ 
      
      ios;
      int test;
      
      
      test=1;
     // cin>>test;
    
      while(test--)
      {
          solve();
          
      }
       
    
    return 0;
	}

Measured memory_bytes: 3620
#include<stdio.h>

int main(){
    
    int a,i;
    int count=0;
    char s[100];
    scanf("%d",&a);
    scanf("%s",s);
    for(i=0;i<a-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
    count++;
    }
    printf("%d\n",count);
    return 0;
}

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#define IF_DEBUG 0
typedef long long ll;
typedef double db;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

string shit;

int main()
{
	cin >> shit;
	if(shit.size() >= 4 && shit[0] == 'Y' && shit[1] == 'A' && shit[2] == 'K' && shit[3] == 'I')
		pf("Yes");
	else
		pf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>

std::array<long,100000> cards;
int main(void){
	long N,M;
	std::cin>>N>>M;

	for(auto itr = cards.begin();itr !=cards.end();itr++){
		*itr = 0;
	}
	int maxL = 0,minR = N;
	for(int i=0;i<M;i++){
		int L,R;
		std::cin>>L>>R;
		if(maxL < L){
			maxL = L;
		}
		if(minR > R){
			minR = R;
		}
	}
	int ans = minR -maxL + 1;
	if(ans > 0){
		std::cout<<ans<<std::endl;
	}else{
		std::cout<<0<<std::endl;	
	}
	return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[][] n = new int[N][3];
        for (int i = 0; i < N; i++) {
            n[i][0] = Integer.parseInt(scanner.next());
            n[i][1] = Integer.parseInt(scanner.next());
            n[i][2] = Integer.parseInt(scanner.next());
        }
        int[][] dp = new int[N + 1][4];
        for (int i = 0; i < N; i++) {
            for (int j = 1; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    if (j != k)
                        dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][k] + n[i][j - 1]);
                }
            }
        }

        int max = 0;
        for (int i = 1; i < 4; i++) {
            max = Math.max(max, dp[N][i]);
        }

        System.out.println(max);
    }

}



Measured memory_bytes: 66276
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  ll a[N+2];
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }
  ll cnt1=0,cnt2=0;
  ll sum=0;
  for(int i=1,s=1;i<=N;i++,s*=-1){
    sum+=a[i];
    if(sum*s<=0) cnt1+=abs(sum-s),sum=s;
  }
  sum=0;
  for(int i=1,s=-1;i<=N;i++,s*=-1){
    sum+=a[i];
    if(sum*s<=0) cnt2+=abs(sum-s),sum=s;
  }
  cout << min(cnt1,cnt2) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	string s;
	cin>>s;
	int N=s.size();
	int a=0;
	rep(i,N-1) if(s[i]!=s[i+1]) a++;
	cout<<a<<endl;
}


Measured memory_bytes: 1020
n,m = map(int, raw_input().split())
s = set()
t = set()
for _ in range(m):
    a,b = map(int, raw_input().split())
    if a == 1:
        s.add(b)
    elif b == 1:
        s.add(a)
    if a == n:
        t.add(b)
    elif b == n:
        t.add(a)
u = s.intersection(t)
if len(u) == 0:
    print 'IMPOSSIBLE'
else:
    print 'POSSIBLE'


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n,X;
    cin>>n>>X;
    vector<ll> x(n);
    ll mi=INF;
    rep(i,0,n){
        cin>>x[i];
        mi=min(mi,abs(X-x[i]));
    }
    for(int i=mi;i>=0;i--){
        bool ok;
        rep(j,0,n){
            if(abs(x[j]-X)%i !=0) {ok=false;break;}
            ok=true;
        }
        if(ok){cout<<i<<endl;break;}
    }
    return 0;
}

Measured memory_bytes: 1024
a,b,c=map(int, input().split())
t=0
if a==5:
  if b==5:
    if c==7:
      t=1
  elif b==7:
    if c==5:
      t=1
elif a==7:
  if b==5:
    if c==5:
      t=1
if t==1:
  print('YES')
else:
  print('NO')
      

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

// ?????????????????????????????§????????£???????????????
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
	
    while(getline(ss, buffer, sep)){
        v.push_back(buffer);
    }
	
    return v;
}

int main(){
	
	string str;
	
	while(true){
		
		cin >> str;
		
		if(str.size() == 1){
			break;
		}
		
		vector<string> v;
		
		v = split(str, '|');
		
		bool flag = false;
		
		for(int i = 0; i < v.size(); i++){
			string str_c = v[i];
			//cout << str_c << endl;
			bool flag2 = true;
			for(int j = 0; j < 26; j++){
				string str11 = "&A";
				string str12 = "(A";
				string str2 = "~A";
				str11[1] = str12[1] = str2[1] = 'A' + j;
				if(((int)str_c.find(str11) != string::npos || (int)str_c.find(str12) != string::npos) && (int)str_c.find(str2) != string::npos){
					//cout << str11 << endl;
					flag2 = false;
				}
			}
			for(int j = 0; j < 26; j++){
				string str11 = "&A";
				string str12 = "(A";
				string str2 = "~A";
				str11[1] = str12[1] = str2[1] = 'a' + j;
				if(((int)str_c.find(str11) != string::npos || (int)str_c.find(str12) != string::npos) && (int)str_c.find(str2) != string::npos){
					//cout << str11 << endl;
					flag2 = false;
				}
			}
			flag = flag || flag2;
		}
		
				if(flag){
					cout << "yes" << endl;
				}else{
					cout << "no" << endl;
				}
		
	}
	
	return 0;
}

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

const int INF = 1001001001;
const int di[4] = { -1,0,1,0 };
const int dj[4]= { 0,-1,0,1 };

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int ans = 0;
	rep(si, h)rep(sj, w) {
		if (s[si][sj] == '#')continue;
		vector<vector<int>> dist(h, vector<int>(w, INF));
		queue<P> q;
		if (dist[si][sj] == INF) {
			dist[si][sj] = 0;
			q.push(P(si, sj));
		}
		while (!q.empty()) {
			int i = q.front().first;
			int j = q.front().second;
			q.pop();
			rep(dir, 4) {
				int ni = i + di[dir];
				int nj = j + dj[dir];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w)continue;
				if (s[ni][nj] == '#')continue;
				if (dist[ni][nj] == INF) {
					dist[ni][nj] = dist[i][j] + 1;
					q.push(P(ni, nj));
				}
			}
		}
		rep(i, h)rep(j, w) {
			if (dist[i][j] == INF)continue;
			ans = max(ans, dist[i][j]);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int A[n]; for (int i = 0; i < n; i++) cin >> A[i];
    vector<pair<int, int> > x;
    for (int i = 0; i < n; i++) x.push_back({A[i], i});
    sort(x.rbegin(), x.rend());
    long long dp[2][n+1];
    int cur = 0, prev = 1;
    dp[prev][0] = 0;
    for (int k = 0; k < n; k++) {
        auto p = x[k];
        for (int i = 0; i <= k+1; i++) {
            int j = n - 1 - k + i;
            long long v = 0;
            if (i > 0) v = max(v, dp[prev][i-1] + (long long)p.first * abs(p.second - (i - 1)));
            if (i <= k) v = max(v, dp[prev][i] + (long long)p.first * abs(p.second - j));
            dp[cur][i] = v;
        }
        // cerr << p.first << " " << p.second << endl;
        // for (int i = 0; i <= k+1; i++) cerr << dp[cur][i] << ' '; cerr << endl;
        swap(cur, prev);
    }
    long long ans = 0;
    // for (int i = 0; i <= n; i++) cerr << dp[prev][i] << endl;
    for (int i = 0; i <= n; i++) ans = max(ans, dp[prev][i]);
    cout << ans << endl;
}


Measured memory_bytes: 3696
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

    ll H, W, N;

    cin >> H >> W >> N;

    vector<vector<ll>> G(H, vector<ll>(W));
    ll tmp, x, y, cnt = 0;

    rep(i, N) {
        cin >> tmp;

        while (tmp != 0) {
            if (cnt / H % 2 == 0) {
                x = cnt % H;
            }
            else {
                x = H - cnt % H - 1;
            }
            y = cnt / H;

            G[x][y] = i + 1;
            tmp--;
            cnt++;
        }
    }

    rep(i, H) {
        rep(j, W) {
            cout << G[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}



ll gcd(ll a, ll b) {
    if (a % b == 0)return(b);
    else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

Measured memory_bytes: 3704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
vector<i64> a, s;
int main() {
  cin >> n >> k;
  read_n(a, n);

  s.resize(n + 1);
  for (int i = 1; i <= n; ++i) {
    s[i] = (s[i - 1] + a[i - 1] - 1) % k;
  }

  i64 ans = 0;
  map<int, int> mp;
  for (int i = 1; i <= n; ++i) {
    mp[s[i - 1]]++;
    if (i - k >= 0) mp[s[i - k]]--;
    ans += mp[s[i]];
  }

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

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    vi vec(3);
    cin >> vec[0] >> vec[1] >> vec[2];

    cout <<max(0, vec[2] - ( vec[0]-vec[1]) )<< endl;


    return 0;
}

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

int main(){
    int a, b;
    cin>>a>>b;
    double c=a, d=b;
    cout<<a/b<<" "<<a%b<<" ";
    printf("%.5lf\n", c/d);
    
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  vpii v;
  ll x[110],y[110],h[110];
  tuple<int,int,int>G=make_tuple(-1,-1,-1);
  rep(i,n){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]>0){
      G=make_tuple(x[i],y[i],h[i]);
    }
  }
  ireps(px,0,100){
    ireps(py,0,100){
      ll H=get<2>(G)+abs(get<0>(G)-px)+abs(get<1>(G)-py);
      bool flag=true;
      rep(i,n){
        ll v=H-abs(x[i]-px)-abs(y[i]-py);
        v=max(v,0LL);
        if(v!=h[i])flag=false;
      }
      if(flag==true){
        cout<<px<<" "<<py<<" "<<H<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
def main():
    n = int(input())

    T=[]
    A=[]
    for i in range(n):
        t,a=map(int,input().split())
        T.append(t)
        A.append(a)

    #比に対する掛け率
    kake = 1
    sum_tmp = 0
    t_tmp = 0
    a_tmp = 0
    for i in range(n):
        if i == 0:
            kake = 1
        else:
            #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する
            if sum_tmp % (T[i]+A[i]) == 0:
                kake_sum = sum_tmp // (T[i]+A[i])
            else:
                kake_sum = sum_tmp // (T[i]+A[i]) + 1
            
            if t_tmp % T[i] == 0:
                kake_t = t_tmp // T[i]
            else:
                kake_t = t_tmp // T[i] + 1
            
            if a_tmp % A[i] == 0:
                kake_a = a_tmp // A[i]
            else:
                kake_a = a_tmp // A[i] + 1
            
            kake = max(kake_sum, kake_t, kake_a)

        sum_tmp = kake*(T[i]+A[i])
        t_tmp = kake*T[i]
        a_tmp = kake*A[i]

    ans = kake * (T[n-1]+A[n-1])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n,k=map(int,input().split())
s=list(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
ans=""
for i in s:
    ans+=i
print(ans)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func parseToArray2d(lines []string) [][]int64 {
	var result [][]int64
	for _, line := range lines {
		var parsedLine []int64
		for _, element := range strings.Split(line, " ") {
			n, err := strconv.ParseInt(element, 10, 64)
			if err != nil {
				fmt.Printf("Error: element = %v\n", element)
			}
			parsedLine = append(parsedLine, n)
		}
		result = append(result, parsedLine)
	}
	return result
}

func printArray(arr []int64) {
	separator := " "
	for j, element := range arr {
		fmt.Print(element)
		if j < len(arr)-1 {
			fmt.Print(separator)
		}
	}
	fmt.Print("\n")
}

func insertionSort(arr []int64) {
	n := len(arr)

	printArray(arr)
	for i := 1; i < n; i++ {
		v := arr[i]
		j := i - 1
		for j >= 0 && arr[j] > v {
			arr[j+1] = arr[j]
			j--
		}
		arr[j+1] = v
		printArray(arr)
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	content := []string{}
	for scanner.Scan() {
		line := scanner.Text()
		content = append(content, line)
	}
	arr := parseToArray2d(content)[1]
	insertionSort(arr)
}



Measured memory_bytes: 1320
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a, b, c, n, m, ans = 0, max = 0;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    ans += a;
    if(max < a) max = a;
  }
  printf("%lld", ans - max / 2);
  return 0;
}


Measured memory_bytes: 128
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 11/27/2018, 8:28:59 PM
# Powered by Visual Studio Code
#

n = gets.to_i
t = gets.chomp.split(" ").map{|i| i.to_i}
m = gets.to_i
problems = []
m.times{
  problems << gets.chomp.split(" ").map{|i| i.to_i}
}
sum = t.inject(:+)
problems.each{|prob|
  puts sum - t[prob[0] - 1] + prob[1]
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
vector<int> mp[1100000];
int dp[1100000];

int check(int i){
    if(dp[i]!=-1) return dp[i];
    int re=0;
    for(int j=0;j<mp[i].size();j++){
        re=max(re,check(mp[i][j])+1);
    }
    dp[i]=re;
    return re;
}


int main() {
    int n,e;
    cin>>n>>e;
    for(int i=0;i<1100000;i++) dp[i]=-1;
    for(int i=0;i<e;i++){
        int x,y;
        cin>>x>>y;
        mp[x].push_back(y);
    }
    int ans=0;
    for(int i=0;i<1100000;i++){
        ans=max(ans,check(i));
    }
    
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 38840
package main

import "fmt"

func main() {
	var N, M, f, t int
	fmt.Scan(&N, &M)
	var from1 []int
	toN := map[int]int{}
	for i := 0; i < M; i++ {
		fmt.Scan(&f, &t)
		if f == 1 {
			from1 = append(from1, t)
		}
		if t == N {
			toN[f]++
		}
	}
	for i := 0; i < len(from1); i++ {
		if _, ok := toN[from1[i]]; ok {
			fmt.Println("POSSIBLE")
			return
		}
	}
	fmt.Println("IMPOSSIBLE")

}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int m = max(h, w);
  cout << (n + m - 1) / m << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=1010,M=1000010,P=1e9+7;
const int inf=0x3f3f3f3f;
const int INF=0xcfcfcfcf;
const db eps=1e-9,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(1ll*a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
inline ll gcd(ll x,ll y) { return y?gcd(y,x%y):x; }
inline ll lcm(ll x,ll y) { return (!x||!y)?x+y:x*y/gcd(x,y); }

int n;
ll a[N][N];
int p1[N],p2[N]; // p1 ÎªÕý¶Ô½ÇÏß, p2 Îª·´¶Ô½ÇÏß 
int now1,now2;
inline ll val(int x,int y) { return 1ll*p1[x-y+n]*p2[x+y]; }

bool prime[M];
int p[M],tot=0;
inline void init(int n=1e5)
{
	mem(prime,true);
	prime[1]=false;
	for(int i=2;i<=n;i++)
	{
		if(prime[i]) p[++tot]=i;
		for(int j=1;j<=tot&&p[j]*i<=n;j++)
		{
			prime[p[j]*i]=false;
			if(i%p[j]==0) break;
		}
	}
}

#ifdef FILE
const int RS=1<<20;
char buf[RS],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,RS,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	init();
	n=read(),now1=1,now2=2*n-(n&1^1);
	if(n==2)
	{
		printf("2 3\n5 16\n");
		return 0;
	}
	p1[0]=p2[0]=p1[2*n]=1;
	for(int i=(n&1^1)+1,flag=0;i<2*n;i+=2,flag^=1)
	{
		if(flag) p1[i]=p[now1++];
		else p1[i]=p[now2--];
	}
	for(int i=2,flag=0;i<=2*n;i+=2,flag^=1)
	{
		if(flag) p2[i]=p[now1++];
		else p2[i]=p[now2--];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i+j&1) printf("%lld ",1ll*p1[i-1-j+n]*p1[i+1-j+n]
										*p2[i-1+j]*p2[i+1+j]+1);
			else printf("%lld ",val(i,j));
		}
		putchar('\n');
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  int n;cin>>n;
  std::vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  std::vector<int> dp(10001,0);
  dp[0]=1;
  for(int i=0;i<n;i++){
      for(int j=10000;0<=j;j--){
          if(j-v[i]>=0) if(dp[j-v[i]]) dp[j]=1;
      }
  }
  int res=0;
  for(int i=0;i<=10000;i++)if(i%10 && dp[i])res=max(res,i);
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
const ll inf=(1e18);
const ll mod=1000000007;
vector<string> dp(10010);
int main(){
vector<int> match={0,2,5,5,4,5,6,3,7,6};
int n,m;
cin>>n>>m;
vector<char> hav(m);
for(int i=0;i<m;i++)cin>>hav[i];
sort(all(hav),greater<char>());
for(int i=0;i<m;i++){
    for(int j=n;j>=0;j--){
        if(j-match[(int)(hav[i]-'0')]>=0){
            if(j!=n&&dp[j].size()==0)continue;
            string tmp=dp[j];
            tmp.push_back(hav[i]);
           if(tmp.size()>dp[j-(int)(match[hav[i]-'0'])].size())dp[j-match[hav[i]-'0']]=tmp;
            else if(tmp.size()==dp[j-(int)(match[hav[i]-'0'])].size()){
                int k=tmp.size();
                while(--k>=0){
                      if(tmp[k]>dp[j-match[hav[i]-'0']][k]){dp[j-match[hav[i]-'0']]=tmp;break;}
                }
            }
        }
    }
}
sort(all(dp[0]),greater<char>());
cout<<dp[0]<<endl;
}




Measured memory_bytes: 43136
#include <bits/stdc++.h>
using namespace std;
vector<string> A(0);

void get(string s,int n,int m){
  if(s==""){
    for(int i=1;i<=m;i++){
      char c='0'+i;
      get(s+c,n-1,m);
    }
  }else if(n==0){
    A.push_back(s);
    return;
  }else{
    char a=s[s.size()-1]-'0';
    for(int i=a;i<=m;i++){
      char c='0'+i;
      get(s+c,n-1,m);
    }
  }
}

int main() {
  int N,M,Q;cin>>N>>M>>Q;
  vector<int> a(Q);
  vector<int> b(Q);
  vector<int> c(Q);
  vector<int> d(Q);
  for(int i=0;i<Q;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }
  get("",N,M);
  int m=0;
  for(int i=0;i<A.size();i++){
    int sum=0;
    string T=A[i];
    for(int j=0;j<Q;j++){
      if(T[b[j]-1]-T[a[j]-1]==c[j])sum+=d[j];
    }
    m=max(m,sum);
  }
  cout<<m<<endl;
}


Measured memory_bytes: 7380
s=gets.chomp.reverse
z=s.size
m=2019
l=[1]+[0]*(m-1)
ll=0
k=1
s.each_char do |ss|
  ll=(ll+k*ss.to_i)%m
  l[ll]+=1
  k=k*10%m
end
a=0
l.each do |li|
  a+=li*(li-1)/2
end
puts a


Measured memory_bytes: 14948
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<list>
#include<vector>
#include<forward_list>
#include<array>
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
#define inf 0x3f3f3f3f
#define IOS std::ios::sync_with_stdio(false)
#define undocin cin.tie(NULL)
using namespace std;
const int maxn=1e5+7;
const int maxm=2e6+7;
int Read(){
	int out=0,flag=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
	while(c>='0'&&c<='9'){out=out*10+c-'0';c=getchar();}
	return flag*out;
}

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
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;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int N;
int main() {
  cin >> N;
  bool ok = false;
  int cnt = 0;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (cnt == 3)
      ok = true;
  }
  if (ok)
    puts("Yes");
  else
    puts("No");
  return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int N, Q;
vector<int> G[200010];
vector<i64> a;
bool visited[200010];

void dfs(int u) {
    visited[u] = true;
    for (int nxt : G[u]) {
        if (visited[nxt]) continue;
        a[nxt] += a[u];
        dfs(nxt);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read(N, Q);
    rep(i, 0, N - 1) {
        var(int, a, b);
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    a.resize(N);

    rep(i, 0, Q) {
        var(int, p, x);
        --p;
        a[p] += x;
    }

    dfs(0);
    print(a);

    return 0;
}


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

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if((b-a)<=0) cout << "delicious" << endl;
    else if((b-a)<=x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string s;
    cin >> s;
    int ans = 1001001001;
    rep(i,s.size()-2) {
        int now = abs(753-stoi(s.substr(i,3)));
        ans = min(ans,now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
inputs = input().split()
nums = list(map(int, input().split()))

S = inputs[0]
T = inputs[1]

A = nums[0]
B = nums[1]
U = input()

if S == U:
    print(A-1, B)
elif T == U:
    print(A, B-1)
else:
    print(A, B)

Measured memory_bytes: 3060
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define  div "%lld"
#define  pdiv "%lld\n"
using namespace std;
///check n=1;
///check corner case;
map<ll,ll>check,str;

int main()
{
    FIO;
    ll  n,i,cc=0;
    cin>>n;
    vector<ll>ara(n);
    ll j[n+10LL]={0};
    for(i=0;i<n;i++){
        cin>>ara[i];
        check[ara[i]]++;
    }
    for(i=0;i<n;i++){
        if(j[ara[i]]==0){
            ll x=check[ara[i]];
            cc+=(x*(x-1))/2;
            j[ara[i]]=1;
        }
    }

    for(i=0;i<n;i++){
        cout<<cc-check[ara[i]]+1<<endl;
    }
	return 0;
}


Measured memory_bytes: 12672
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let K = input[0].split(' ')[1]
	let P = input[1].split(' ').map(p => Number(p))
	let sums = []
	let ruisekiwa = [P[0]]
	for(let i = 1; i < P.length ; i++) {
		ruisekiwa.push(ruisekiwa[i - 1] + P[i])
	}
	sums.push({v :ruisekiwa[K - 1], i: 0})
	for(let i = 0; i < P.length - K; i++) {
		sums.push({ v : ruisekiwa[i + Number(K)] - ruisekiwa[i], i: i + 1})
	}
	let dp = [0]
	for(let i = 1; i <= 1000 ; i++) {
		dp.push((dp[i - 1] + i))
	}
	sums = sums.sort((a, b) => a.v- b.v)
	let index = sums[sums.length - 1].i
	let tmp = P.slice(index, index + Number(K))
	let result = 0
	for(let i = 0; i < tmp.length ; i++) {
		result += dp[tmp[i]] / tmp[i]
	}
	console.log(result.toFixed( 12 ))
	
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int N; cin >> N;
  vector<int> a(N+1);
  for (int i = 0; i < N; i++) cin >> a[i+1];
  vector<int> b(N+1,0);
   vector<bool> c(N+1,false);
  int M = 0;
  
  for (int i = N; i > 0; i--) {
    if (b[i] % 2 != a[i]) {
      M++;
      c[i] = true;
      for (int j = 1; j*j <= i; j++) {
        if (i % j == 0) {
          if (j*j < i) { 
            b[j]++;
            b[i / j]++;
          } else b[j]++;
        }
      }
    }
  }
  
  cout << M << endl;
  for (int i = 0; i <= N; i++) {
    if (c[i]) cout << i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2560
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    N, M = map(int, readline().split())
    if N == M == 0:
        return False
    ca = ord('a')
    E = [list(map(lambda x: ord(x)-ca, readline().strip())) for i in range(N)]
    F = "".join(readline().strip() for i in range(M))
    L = sum(map(len, E))
    MOD = 10**9 + 9; base = 37
    ALL = (1 << N) - 1; bALL = (1 << (1 << N)) - 1
    pw = [1]*(L+1)
    for i in range(L):
        pw[i+1] = pw[i] * base % MOD
    V = [0]*N; P = [0]*N; K = [0]*N
    S = [0]*N
    for i in range(N):
        v = 0
        for c in E[i]:
            v = (v * base + c) % MOD
        V[i] = v
        K[i] = len(E[i])
        P[i] = pw[K[i]]
        r = bALL
        for s in range(ALL + 1):
            if s & (1 << i):
                r ^= 1 << s
        S[i] = r

    A = len(F)
    dp = [1] * (A+1)
    H = [0]*(A+1)
    ans = s = 0
    for i in range(A):
        H[i+1] = s = (s * base + (ord(F[i]) - ca)) % MOD
        r = 1
        for j in range(N):
            if K[j] <= i+1 and (s - H[i+1 - K[j]] * P[j]) % MOD == V[j]:
                r |= (dp[i+1 - K[j]] & S[j]) << (1 << j)
        dp[i+1] = r
        if r & (1 << ALL):
            ans += 1
    write("%d\n" % ans)
    return True
while solve():
    ...


Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int n; cin>>n;
    int ans = (1000-n%1000)%1000;
    cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  bool is_leap[3010] = {};
  for (int i = 0; i <= 3000; i++) {
    is_leap[i] = i % 400 == 0 || (i % 100 != 0 && i % 4 == 0);
  }
  int a, b;
  bool flag = false;
  while (cin >> a >> b, a) {
    if (flag) cout << endl;
    vector<int> ans;
    for (int i = a; i <= b; i++) {
      if (is_leap[i]) ans.emplace_back(i);
    }
    if (ans.empty()) cout << "NA" << endl;
    else {
      for (auto i : ans) {
        cout << i << endl;
      }
    }
    flag = true;
  }

  return 0;
}


Measured memory_bytes: 3144
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	
	LL n;
	cin>>n;
	
	LL c = n;
	vector<pair<int, int> > v;
	for(LL i=2;i*i<=n;i++) {
		int cnt = 0;
		while(c%i ==0) {
			cnt++;
			c/=i;
		}
		v.PB(MP(i, cnt));
	}
	
	if(c>1) v.PB(MP(c, 1));
	
	LL ans = 0;
	for(int i=0;i<v.size();i++) {
		int val = v[i].Y;
		int s = 1;
		while(val > 0) {
			if(val - s > s) {
				ans++;
				val-=s;
			} else {
				ans++;
				val = 0;
			}
			s++;
		}
	}
	cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 11656
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
// typedef vector<int,vector<int>> vvec;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define here  cout<<"Here"<<endl;


//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int S=0,mn=1e9+1,neg_cnt=0,tmp,N;cin>>N;
  REP(i,0,N){
    cin>>tmp;
    if(tmp<0)neg_cnt++;
    tmp=abs(tmp);
    mn=min(tmp,mn);
    S+=tmp;
  }

  int ans;
  if(neg_cnt%2==0){
    ans=S;
  }else{
    ans=S-2*mn;
  }
  print(ans);
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int h[110];

signed main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)cin >> h[i];
    int ans = 0;
    for (int a = 1; a < 110; a++) {
        for (int i = 1; i <= N; i++) {
            if (h[i - 1] < a && h[i] >= a)ans++;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N, min_count = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int A, count = 0;
    cin >> A;

    while (0 < A) {
      if (A % 2 == 0) {
        count += 1;
        A /= 2;
      } else {
        break;
      }
    }
    if (count < min_count) min_count = count;
  }
  cout << min_count << endl;
}


Measured memory_bytes: 256
n = int(input())

ans = [0] * n

for i in range(1, int((n+1)**0.5)):
    for j in range(i,int((n+1)**0.5)):
        for k in range(j,int((n+1)**0.5)):
            s = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if s > n:
                break
            
            check = len(set([i,j,k]))
            if check == 1:
                ans[s-1] += 1
            elif check == 2:
                ans[s-1] += 3
            elif check == 3:
                ans[s-1] += 6

for i in ans:
    print(i)
            

Measured memory_bytes: 9388
#include <stdio.h>

int main() {
	char s1[11], s2[11], s3[11];
	scanf("%s %s %s", s1, s2, s3);
	printf("%c%c%c\n", s1[0] - 32, s2[0] - 32, s3[0] - 32);
	return 0;
}

Measured memory_bytes: 1720