akhauriyash/Code-Regression huggingface dataset:
#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);
 
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, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  char c;cin>>c;
  string ans="consonant";
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')ans="vowel";
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125568
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            N = Sarray()[0];
            path = new long[N, N];
            for(var i=0;i<N;++i)
            {
                var t = ReadLine();
                for (var j = 0; j < t.Length; ++j)
                    path[i, j] = t[j] - '0';
            }
            //二部グラフに分けれるか確認。belong[i],belong[N+i]が両方trueなら分けれない
            visited = new bool[N];
            belong = new bool[2 * N];
            dfs(0, 0);
            for (var i = 0; i < N; ++i)
                if (belong[i] && belong[i + N])
                {
                    WriteLine(-1);
                    return;
                }
            
            //グラフの直径をワーシャルフロイドで求める(計算量O(N^3))
            long infty = 1L << 32;
            var wfd = new long[N, N];
            for (var i = 0; i < N; ++i)
                for (var j = 0; j < N; ++j)
                    if (i != j)
                        wfd[i, j] = path[i, j] == 0 ? infty : path[i, j];
            for (var k = 0; k < N; ++k)
                for (var i = 0; i < N; ++i)
                    if (wfd[i, k] != infty)
                        for (var j = 0; j < N; ++j)
                            if (wfd[k, j] != infty)
                                wfd[i, j] = Min(wfd[i, j], wfd[i, k] + wfd[k, j]);
            var ans = wfd.Cast<long>().Max() + 1;
            WriteLine(ans);
        }
        static long N;
        static bool[] visited;
        static bool[] belong;
        static long[,] path;
        static public void dfs(long node, long pdst)
        {
            long crr = 0 == pdst % 2 ? 0 : N;
            belong[crr + node] = true;
            if (visited[node]) return;
            visited[node] = true;
            for (var i = 0; i < N; ++i)
            {
                if(1==path[node,i])
                dfs(i, pdst + 1);
            }
        }
    }
}

Measured memory_bytes: 14036
n=int(input())
ls=list(map(int,input().split()))

s=1
over=False

if 0 in ls:
    s=0
else:
    for i in ls:
        s*=i
        if s>10**18:
            over=True
            break


if over:
    print(-1)
else:
    print(s)


Measured memory_bytes: 21704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

int main(){
    int a[9];
    for (int i=0;i<9;i++){
        cin >> a[i];
    }

    bool b[9];
    for (int i=0;i<9;i++){
        b[i] = false;
    }
    int N;
    cin >> N;

    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        for (int i=0;i<9;i++){
            if (a[i] == x){
                b[i] = true;
            }
        }
    }

    if (b[0] && b[1] && b[2]){
        cout << "Yes";
    }
    else if (b[3] && b[4] && b[5]){
        cout << "Yes";
    }
    else if (b[6] && b[7] && b[8]){
        cout << "Yes";
    }
    else if (b[0] && b[3] && b[6]){
        cout << "Yes";
    }
    else if (b[1] && b[4] && b[7]){
        cout << "Yes";
    }
    else if (b[2] && b[5] && b[8]){
        cout << "Yes";
    }
    else if (b[0] && b[4] && b[8]){
        cout << "Yes";
    }
    else if (b[2] && b[4] && b[6]){
        cout << "Yes";

    }
    else cout << "No";
    

}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  bool can = false;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K - i; j++) {
      for (int k = 0; k <= K - i - j; k++) {
        // 1 << 0 = 1   = 1
        // 1 << 1 = 10  = 2
        // 1 << 2 = 100 = 4
        int x = A * (1 << i);
        int y = B * (1 << j);
        int z = C * (1 << k);
        if (x < y && y < z) {
          can = true;
          break;
        }
      }
    }
  }

  cout << (can ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;

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

        int w = sc.nextInt();
        int n = sc.nextInt();
        int num[] = new int[w];
        for (int i = 0; i < w; i++) {
            num[i] = i + 1;
        }

        String s;

        for (int i = 0; i < n; i++) {
            s = sc.next();
            int camma_index = 0;
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == ',') {
                    camma_index = j;
                    break;
                }
            }
            int a = Integer.parseInt(s.substring(0, camma_index));
            int b = Integer.parseInt(s.substring(camma_index+1));
            int tmp = num[a - 1];
            num[a - 1] = num[b - 1];
            num[b - 1] = tmp; // swap
        }

        for (int i = 0; i < w; i++) {
            System.out.println(num[i]);
        }

        sc.close();
    }
}


Measured memory_bytes: 26192
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans_1=0,ans_2=0;
  if(s[0]=='0'){
    ans_2=999999999;
    for(int i=0;i<s.size();i++){
      if(i%2==0){
        if(s[i]=='1')ans_1++;
      }else if(i%2==1){
           if(s[i]=='0')ans_1++;
      }
    }
  }
  if(s[0]=='1'){
    ans_1=99999999;
    for(int i=0;i<s.size();i++){
      if(i%2==0){
        if(s[i]=='0')ans_2++;
      }else if(i%2==1){
           if(s[i]=='1')ans_2++;
      }
    }
  }
  cout<<min(ans_1,ans_2)<<endl;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        int[][] dp = new int[n + 1][3];

        for (int i = 1; i <= n; i++) {

            int[] act = new int[3];
            
            for (int j = 0; j < act.length; j++) {
                
                act[j] = in.nextInt();
                
            }
            
            for (int j = 0; j < act.length; j++) {
                
                dp[i][j] = Math.max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + act[j];
            
            }
        }
        
        System.out.println(Arrays.stream(dp[n]).max().getAsInt());
        
    }

}


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



int main(){
    int N;
    cin >> N;
    vector<int> card(N+1);
    for(int i = 0;i<N;i++){
        cin >> card.at(i);
    }
    int alice = 0;
    int bob = 0;
    
    sort(card.begin(),card.end());
    reverse(card.begin(),card.end());
    
    bool which = true;
    for(int j = 0;j<N;j++){
        if(which == true){
            alice = alice + card.at(j);
            which = false;
        }
        else{
            bob = bob + card.at(j);
            which = true;
        }
        
        
        //cout << alice << " " << bob << endl;
    }

    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;
typedef pair<double,double> P;
int b[19][19];


int main(){
	
	map<string,string> ec;
    map<string,string> dc;
     
    ec[" "]="11010";
    ec["'"]="11110";
    ec[","]="11100";
    ec["-"]="11101";
    ec["."]="11011";
    ec["?"]="11111";
    ec["A"]="00000";
    ec["B"]="00001";
    ec["C"]="00010";
    ec["D"]="00011";
    ec["E"]="00100";
    ec["F"]="00101";
    ec["G"]="00110";
    ec["H"]="00111";
    ec["I"]="01000";
    ec["J"]="01001";
    ec["K"]="01010";
    ec["L"]="01011";
    ec["M"]="01100";
    ec["N"]="01101";
    ec["O"]="01110";
    ec["P"]="01111";
    ec["Q"]="10000";
    ec["R"]="10001";
    ec["S"]="10010";
    ec["T"]="10011";
    ec["U"]="10100";
    ec["V"]="10101";
    ec["W"]="10110";
    ec["X"]="10111";
    ec["Y"]="11000";
    ec["Z"]="11001";
     
    dc["100101"]="A";
    dc["10011010"]="B";
    dc["0101"]="C";
    dc["0001"]="D";
    dc["110"]="E";
    dc["01001"]="F";
    dc["10011011"]="G";
    dc["010000"]="H";
    dc["0111"]="I";
    dc["10011000"]="J";
    dc["0110"]="K";
    dc["00100"]="L";
    dc["10011001"]="M";
    dc["10011110"]="N";
    dc["00101"]="O";
    dc["111"]="P";
    dc["10011111"]="Q";
    dc["1000"]="R";
    dc["00110"]="S";
    dc["00111"]="T";
    dc["10011100"]="U";
    dc["10011101"]="V";
    dc["000010"]="W";
    dc["10010010"]="X";
    dc["10010011"]="Y";
    dc["10010000"]="Z";
    dc["101"]=" ";
    dc["010001"]=".";
    dc["000011"]=",";
    dc["10010001"]="-";
    dc["000000"]="'";
    dc["000001"]="?";
	
	string s;
	while(getline(cin,s)){
	
	string temp="";
	for(int i=0;i<s.size();i++){
		temp+=ec[s.substr(i,1)];
	}
	string a="";
	string ans="";
	for(int i=0;i<temp.size();i++){
		a+=temp[i];
		if(dc.count(a)==1){
			ans+=dc[a];
			a="";
		}
	}
	
	cout<<ans<<endl;
	}
}

Measured memory_bytes: 3024
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007LL;

typedef struct {
    string name;
    int point;
} rest;

bool cmp(const pair<int,rest> &a, const pair<int,rest> &b) {
    if (a.second.name < b.second.name) return true;
    else if (a.second.name == b.second.name && a.second.point > b.second.point) return true;
    else return false;
}

int main(void) {
    int N;
    cin >> N;
    vector<pair<int,rest>> r;
    for (int i=0;i<N;i++) {
        rest tmp;
        cin >> tmp.name >> tmp.point;
        r.push_back(make_pair(i+1,tmp));
    }
    sort(r.begin(), r.end(), cmp);
    for (auto itr = r.begin(); itr != r.end(); itr++) {
        cout << itr->first << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#define INF INT_MAX
using namespace std;

int ans;
int n;
int v[100010];
int m1[100010];
int m2[100010];
pair<int, int>p11, p12;
pair<int, int>p21, p22;

int main(){

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	  
	for (int i = 0; i < n; i += 2)m1[v[i]]++;

	for (int i = 1; i < n; i += 2)m2[v[i]]++;

	for (int i = 0; i < 100010; i++){
		if (m1[i] > p11.first){
			p12 = p11;
			p11 = { m1[i], i };
		}
		else if (m1[i] > p12.first){
			p12 = { m1[i], i };
		}

		if (m2[i] > p21.first){
			p22 = p21;
			p21 = { m2[i], i };
		}
		else if (m2[i] > p22.first){
			p22 = { m2[i], i };
		}
	}

	if (p11.second != p21.second){
		ans += n / 2 - p11.first;
		ans += n / 2 - p21.first;
		cout << ans << endl;
	}
	else{
		ans += n / 2 - p11.first;
		ans += n / 2 - p22.first;
		ans = min(ans, n - p12.first - p21.first);
		cout << ans << endl;
	}

	return 0;
}

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

const int MAX_A = 300005;

int op (int x, int y) {
    return max(x, y);
}

int e () {
    return 0;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    segtree<int, op, e> dp(MAX_A);
    rep(i,n) {
        int x = a.at(i);
        int l = max(0, x - k);
        int r = min(x + k + 1, MAX_A);
        int now = dp.prod(l, r) + 1;
        dp.set(x, max(dp.get(x), now));
    }

    cout << dp.all_prod() << endl;
    return 0;
}

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

int main()
{
    int n;
    bool y = false;
    cin >> n;
    vector<char> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s.at(i);
        if (s.at(i) == 'Y')
        {
            y = true;
            break;
        }
    }
    if (y)
    {
        cout << "Four" << endl;
    }
    else
    {
        cout << "Three" << endl;
    }
}


Measured memory_bytes: 256
#coding:utf-8
from scipy.misc import comb

n, k = map(int, input().split())
m = pow(10,9) + 7

for i in range(k):
    # 赤と赤の間に青を配置する場所の組み合わせ
    blue = comb(n-k+1, i+1, exact=True)
    # 青をいくつずつ配置するかの組み合わせ
    blue_num = comb(k-1, i, exact=True)
    print(blue * blue_num % m)

Measured memory_bytes: 14104
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
  int R[MAX],n;

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> R[i];
  }
  int maxv = -2000000000;
  int minv = R[0];

  for(int i = 1; i < n; i++){
    maxv = max(maxv,R[i] -minv);
    minv = min(minv, R[i]);
    
  }
  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const int N = 100;

template <class T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	char a, b;
	cin >> a >> b;
	string s1, s2;
	for (int i = 0; i < a - '0'; ++i)
		s1.push_back(b);
	for (int i = 0; i < b - '0'; ++i)
		s2.push_back(a);
	cout << min(s1, s2) << '\n';
	
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

bool isac[100010];
ll pen[100010];

int main(){
	int n, m; cin >> n >> m;
	ll ac = 0;
	ll wa = 0;
	while( m-- ){
		int k; cin >> k; k--;
		string s; cin >> s;
		if( isac[k] ) continue;
		if( s == "AC" ){
			++ac;
			wa += pen[k];
			isac[k] = true;
		} else {
			++pen[k];
		}
	}
	cout << ac << ' ' << wa << endl;
}

Measured memory_bytes: 1152
fun main(args: Array<String>) {
    abc143a()
}

fun abc143a() {

    val (a, b) = readLine()!!.split(" ").map(String::toInt)

    val length = b * 2

    val result = if (a - length > 0) {
        a - length
    } else {
        0
    }
    println(result)
}


Measured memory_bytes: 37932
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int sum = 0;
		
		if (k - a >= 0) {
		    k -= a;
		    sum += a;
		    if (k - b >= 0) {
		        k -= b;
		        if (k - c >= 0) {
		            sum -= c;
		        } else {
		            sum -= k;
		        }
		    }
		} else {
		    sum = k;
		}
		System.out.println(sum);
	}
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  bool can = true;
  if (N % 2 == 0) {
    int M = N / 2;
    for (int i = 0; i < M; i++) if (S.at(i) != S.at(i + M)) can = false;
  } else can = false;    
      
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
    int a;
    rep2(i, 1, 5) {
        cin >> a;
        if (a==0) cout << i << endl;
    }
    return 0;
}


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

int main()
{
	int n,W;cin>>n>>W;
	int v[100],w[100],m[100];
	for(int i=0;i<n;i++)cin>>v[i]>>w[i]>>m[i];
	int dp[10001]={};
	int deq[10001],deqv[10001];
	
	for(int i=0;i<n;i++)
	{
		for(int a=0;a<w[i];a++)
		{
			int s=0,t=0;
			for(int j=0;j*w[i]+a<=W;j++)
			{
				int val=dp[j*w[i]+a]-j*v[i];
				while(s<t&&deqv[t-1]<=val)t--;
				deq[t]=j;
				deqv[t++]=val;
				dp[j*w[i]+a]=deqv[s]+j*v[i];
				if(deq[s]==j-m[i])s++;
			}
		}
	}
	cout<<dp[W]<<endl;
	return 0;
}

Measured memory_bytes: 3212
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        s: String,
        t: String,
    }

    let mut ans = 0;
    for (ss, tt) in s.chars().zip(t.chars()) {
        if ss != tt {
            ans += 1;
        }
    }

    println!("{}", ans);
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for(int i = 0; i < n; i++){
        cin >> v.at(i);
    }
    for(int i = 0; i < n; i++){
        cin >> c.at(i);
    }
    int x_y = 0;
    for(int i = 0; i < n; i++){
        if(v.at(i) - c.at(i) > 0) x_y += v.at(i) - c.at(i);
    }
    cout << x_y << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5, MAXP = 2200;

char is_p[MAXP];

ll p3[MAXP];

vi p;

ll v[MAXN];

map<ll, ll> nxt;
map<ll, int> cnt;

void solve(){
	is_p[0] = is_p[1] = 0;
	REP(i, 2, MAXP){
		is_p[i] = 1;
		for(int j = 2; j * j <= i; j++){
			if (!(i % j)){
				is_p[i] = 0;
				break;
			}
		}
		if (is_p[i]){
			p.pb(i);
		}
	}
	REP(i, 1, MAXP){
		p3[i] = (ll)i * (ll)i * (ll)i;
	}
	int n;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%lld", &v[i]);
		REP(j, 0, SZ(p)){
			while(!(v[i] % p3[p[j]])){
				v[i] /= p3[p[j]];
			}
		}
		cnt[v[i]]++;
		if (nxt.find(v[i]) == nxt.end()){
			ll cur = v[i];
			ll cur_nxt = 1ll;
			REP(j, 0, SZ(p)){
				if (!(v[i] % p[j])){
					cur_nxt *= p[j];
					v[i] /= p[j];
					if (v[i] % p[j]){
						cur_nxt *= p[j];
					} else {
						v[i] /= p[j];
					}
				}
			}
			if (v[i] > 1){
				ll sq = (ll)sqrt(v[i] + 0.5);
				if (sq * sq == v[i]){
					cur_nxt *= sq;
				} else {
					cur_nxt *= v[i] * v[i];
				}
			}
			nxt[cur] = cur_nxt;
		}
	}
	int ans = 0;
	FA(it, cnt){
		ll cur = it->first;
		if (cur == 1ll){
			ans++;
		} else {
			ll cur_nxt = nxt[cur];
			if (cnt.find(cur_nxt) == cnt.end()){
				ans += it->_2;
			} else if (cur < cur_nxt){
				int cnt_nxt = cnt[cur_nxt];
				ans += max(it->_2, cnt_nxt);
			}
		}
	}
	printf("%d\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 13568
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char S[11];

int main()
{
	scanf("%s", S);
	puts(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I' ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
void cmn(lint&x,lint y){if(x>y)x=y;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint inf=numr<lint>::max();
    lint n,k;std::cin>>n>>k;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    lint ans=inf;
    for(lint i=0;i<=n-k;i++){
        cmn(ans,std::min(std::abs(a.at(i)),std::abs(a.at(i+k-1)))+std::abs(a.at(i)-a.at(i+k-1)));
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] += 0x20;
    cout << s << endl;
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T ll
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}


int main(){
    IOS
    int a,b;
    cin>>a>>b;
    int k = (a+b)/2;
    if(a+b == 2*k){
    	cout<<k;
    }
    else{
    	cout<<"IMPOSSIBLE";
    }
    
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100

i64 N;
i64 W[MAX_N];
i64 cuml[MAX_N];

void solve() {
  REP(i, N) {
    if (i == 0) {
      cuml[i] = W[i];
    } else {
      cuml[i] = W[i] + cuml[i-1];
    }
  }

  i64 minv = 1000000000;
  i64 s1, s2;
  REP(i, N) {
    s1 = cuml[i];
    s2 = cuml[N-1] - cuml[i];
    if (abs(s2 - s1) < minv) {
      minv = abs(s2 - s1);
    }
  }

  cout << minv << endl;
}

int main() {
  cin >> N;
  REP(i, N) cin >> W[i];

  solve();

  return 0;
}

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

ll N,W;
ll w[100];
ll v[100];

ll dp[105][405];

int main(){
  cin>>N>>W;
  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }

  int dw=w[0];
  dw--;
  
  for(int i=0;i<N;i++){
    w[i]-=dw;
  }

  fill(dp[0] ,dp[105],-(1LL<<50) );
  
  dp[0][0]=0;
  ll ans=0;
  
  for(ll i=0;i<N;i++){
    for(ll j=N;j>=1;j--){
      for(ll k=400;k>=0;k--){
        if(k-w[i]>=0){
          dp[j][k]=max(dp[j][k],dp[j-1][k-w[i]]+v[i]);
          if( k+dw*j <=W)ans=max(ans,dp[j][k]);
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
    string s;
    cin >> s;

    reverse(s.begin(), s.end());

    for(int i = 0; i < 4; i++)
        reverse(divide[i].begin(), divide[i].end());
    
    bool flag = true;

    for(int i = 0; i < s.size();){
        bool flag2 = false;
        for(int j = 0; j < 4; j++){
            string div = divide[j];
            if(s.substr(i, div.size()) == div){
                flag2 = true;
                i += div.size();
            }
        }
        if(!flag2){
            flag = false;
            break;
        }
    }

    if(flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <strstream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;

int main(){
	float a,b;
	while(cin>>a>>b){
	if( a<35.5 && b<71 )puts("AAA");
	else if( a<37.5 && b<77 )puts("AA");
	else if( a<40 && b<83 )puts("A");
	else if( a<43 && b<89 )puts("B");
	else if( a<50 && b<105 )puts("C");
	else if( a<55 && b<116)puts("D");
	else if( a<70 && b<148)puts("E");
	else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
int main(){
	int n;
	double x1,y1,x2,y2,x3,y3,x4,y4,a,b;
	std::cin>>n;
	while(n>0){
		std::cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		//y=ax+b
		//y1=a*x1+b
		//y2=a*x2+b
		//a(x1-x2)=y1-y2
		//a=(y1-y2)/(x1-x2)
		a=(y1-y2)/(x1-x2);
		b=(y3-y4)/(x3-x4);
		if(a==b)std::cout<<"YES"<<std::endl;
		else std::cout<<"NO"<<std::endl;
		n--;
	}
}

Measured memory_bytes: 1224
#include <stdio.h>

int main(void)
{
	int n;
	int a[1000];
	int b;
	int c;
	
	scanf("%d", &n);
	
	for (b = 0; b < n; b++){
		scanf("%d", &a[b]);
	}
	
	for (c = b - 1; c >= 0; c--){
		if (c == 0){
		printf("%d", a[0]);
		}
		else printf("%d ",a[c]);
	}
	printf("\n");
	
	
	return (0);
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#define ll long long
using namespace std;
int main(void){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c-a-b > 0 && (c-a-b)*(c-a-b)>4*a*b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define INF 100000

typedef long long ll;

#define N_MAX 200

int dist[N_MAX][N_MAX];
int color[N_MAX];

bool dfs(int node){
	bool flg  = true;

	REP(i, N_MAX){
		if(dist[node][i] == 1){
			if(color[i] == 0){
				color[i] = -1*color[node];
				flg = flg && dfs(i);
			}else if(color[i] == color[node]) return false;
		}
	}

	return flg;
}

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

	REP(i, n) REP(j, n) dist[i][j] = INF;
	REP(i, n) dist[i][i] = 0;

	string s;
	REP(i, n){
		cin >> s;
		REP(j, n){
			if(s[j] == '1') dist[i][j] = 1;
		}
	}

	memset(color, 0, sizeof(color));

	color[0] = 1;
	if(!dfs(0)){
		cout << -1 << endl;
		return 0;
	}

	REP(k, n) REP(i, n) REP(j, n) dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]);

	int max = 0;
	REP(i, n) REP(j, n) if(dist[i][j] != INF) max = MAX(max, dist[i][j]);

	cout << max+1 << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;

public class Main{
	
	static class Vertex {
		int id;
		int deg;
		int[] neighbors;
		
		public Vertex(int id, int[] neighbors) {
			this.id = id;
			this.deg = neighbors.length;
			this.neighbors = neighbors;
		}
		
		public boolean hasNeighbor(int id) {
			for (int n : neighbors) {
				if (n == id) {
					return true;
				}
			}
			return false;
		}
	}
	
	HashMap<Integer, Vertex> vertices;
	
	public Main() {
		vertices = new HashMap<>();
	}
	
	public Main(Vertex[] v) {
		this();
		for (Vertex vertex : v) {
			this.vertices.put(vertex.id, vertex);
		}
	}
	
	public void addVertex(Vertex v) {
		vertices.put(v.id, v);
	}
	
	public Vertex get(int id) {
		return this.vertices.get(id);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int dim = Integer.parseInt(in.nextLine());
		int[][] adjM = new int[dim][dim];
		Main g = new Main();
		
		String[] info;
		int id;
		for (int i = 0; i < dim; i++) {
			info = in.nextLine().split(" ");
			id = Integer.parseInt(info[0]);
			int[] neighbors = new int[Integer.parseInt(info[1])];
			for (int j = 0; j < neighbors.length; j++) {
				neighbors[j] = Integer.parseInt(info[j + 2]);
			}
			g.addVertex(new Vertex(id, neighbors));
		}
		
		for (int row = 0; row < dim; row++) {
			String buffer = "";
			for (int col = 0; col < dim; col++) {
				adjM[row][col] = 0; // default
				
				if (g.get(row + 1).hasNeighbor(col + 1)) { // if there is an adjacency
					adjM[row][col] = 1;
				}
				buffer += adjM[row][col];
				if (col != dim - 1) {
					buffer += " ";
				}
			}
			System.out.println(buffer);
		}
	}
}


Measured memory_bytes: 47132
#include<bits/stdc++.h>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    string s[H];
    for (int i = 0; i < H; i++)
    {
        cin >> s[i];
    }

    int a[H][W];
    memset(a, 0, sizeof(a));

    for (int i = 0; i < H; i++)
    {
        bool b = true;
        for (int j = 0; j < W; j++)
        {
            if(s[i][j] == '#') b = false;
        }
        if(b){
            for (int j = 0; j < W; j++)
            {
                a[i][j] = 1;
            }
        }
    }

    for (int i = 0; i < W; i++)
        {
            bool b = true;
            for (int j = 0; j < H; j++)
            {
                if(s[j][i] == '#') b = false;
            }
            if(b){
                for (int j = 0; j < H; j++)
                {
                    a[j][i] = 1;
                }
            }
        }

    int cnt;
    for (int i = 0; i < H; i++)
    {
        cnt = 10;
        for (int j = 0; j < W; j++)
        {
            cnt = min(a[i][j], cnt);
            if(a[i][j] == 0) {
                cout << s[i][j];
            }
        }
        if(cnt == 0) cout << endl;
    }
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int x = 0;
  for (int i = 0; i + 1 < n; i++) x += s[i] == s[i + 1];
  cout << min(n - 1, x + 2 * k) << endl;
}


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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int sum=0;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      if((X-500*i-100*j)%50==0 && (X-500*i-100*j)/50<=C && (X-500*i-100*j)>=0)sum++;
    }
  }
  cout << sum;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  vector<int> news(4);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'N') news[0] = 1;
    if (s[i] == 'E') news[1] = 1;
    if (s[i] == 'W') news[2] = 1;
    if (s[i] == 'S') news[3] = 1;
  }
  cout << ((~(news[0] ^ news[3]) & (~(news[1] ^ news[2])) & 1) ? "Yes" : "No") << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=53,INF=1<<30;
int N,M;
vector<int> A,B;
bool seen[MAX][MAX][2][MAX][MAX][2];
int dp[MAX][MAX][2][MAX][MAX][2];

int solve(int anow,int bnow,int turn,int astart,int bstart,int pass){
    if(seen[anow][bnow][turn][astart][bstart][pass]) return dp[anow][bnow][turn][astart][bstart][pass];
    //cout<<anow<<" "<<bnow<<" "<<turn<<" "<<astart<<" "<<bstart<<" "<<pass<<endl;
    
    seen[anow][bnow][turn][astart][bstart][pass]=1;
    
    if(turn==0){
        int ret=-INF;
        if(pass==1){
            assert(anow==astart+1&&bnow==bstart+1);
            ret=max(ret,0);
        }
        if(anow==astart+1&&bnow==bstart+1&&pass==0){
            ret=max(ret,solve(anow,bnow,1,astart,bstart,1));
        }
        if(anow!=astart+1||bnow!=bstart+1){
            assert(pass==0);
            int sum=0;
            int a=anow-1,b=bnow-1;
            bool oka=true,okb=true;
            while(1){
                if(b>bstart){
                    if(B[b]>=0&&okb) sum-=B[b];
                    else if(B[b]<0) oka=false;
                }else break;
                b--;
                
                if(a>astart){
                    if(A[a]>=0&&oka) sum+=A[a];
                    else if(A[a]<0) okb=false;
                }else break;
                a--;
            }
            
            ret=max(ret,sum+solve(anow,bnow,1,anow-1,bnow-1,0));
        }
        
        if(anow<N) ret=max(ret,solve(anow+1,bnow,1,astart,bstart,0));
        
        return dp[anow][bnow][turn][astart][bstart][pass]=ret;
    }else{
        int ret=INF;
        if(pass==1){
            assert(anow==astart+1&&bnow==bstart+1);
            ret=min(ret,0);
        }
        if(anow==astart+1&&bnow==bstart+1&&pass==0){
            ret=min(ret,solve(anow,bnow,0,astart,bstart,1));
        }
        if(anow!=astart+1||bnow!=bstart+1){
            assert(pass==0);
            int sum=0;
            int a=anow-1,b=bnow-1;
            bool oka=true,okb=true;
            while(1){
                if(a>astart){
                    if(A[a]>=0&&oka) sum+=A[a];
                    else if(A[a]<0) okb=false;
                }else break;
                a--;
                
                if(b>bstart){
                    if(B[b]>=0&&okb) sum-=B[b];
                    else if(B[b]<0) oka=false;
                }else break;
                b--;
            }
            
            ret=min(ret,sum+solve(anow,bnow,0,anow-1,bnow-1,0));
        }
        
        if(bnow<M) ret=min(ret,solve(anow,bnow+1,0,astart,bstart,0));
        
        return dp[anow][bnow][turn][astart][bstart][pass]=ret;
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        A.push_back(a);
    }
    for(int i=0;i<M;i++){
        int a;cin>>a;
        B.push_back(a);
    }
    
    cout<<solve(0,0,0,-1,-1,0)<<endl;
}






Measured memory_bytes: 87124
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		set<int>s[101];
		for(int i=0;i++<n;)
		{
			int m;cin>>m;
			for(;m--;)
			{
				int a;cin>>a;s[i].insert(a);
			}
		}
		int m;cin>>m;set<int>t;
		for(;m--;)
		{
			int a;cin>>a;t.insert(a);
		}
		int cnt=0,I=-1;
		for(int i=0;i++<n;)
		{
			int f=1;
			for(int it:t)
			{
				f&=s[i].find(it)!=s[i].end();
			}
			if(f)
			{
				cnt++;
				if(cnt==1)I=i;
				else I=-1;
			}
		}
		cout<<I<<endl;
	}
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define all(x) x.begin(), x.end()

int main(){
  string s;
  cin >> s;
  string t = s.substr(2,s.size() - 2);
  t = t.substr(0,t.size() - 1);
  bool OK = true;
  int A = 1;
  int C = 1;
  for(char c : s){
    if('a' <= c && c <= 'z'){

    }
    else if(c == 'A'){
      A--;
    }
    else if(c == 'C'){
      C--;
    }
    else{
      cout << "WA" << endl;
      return 0;
    }
  }
  if(s[0] == 'A' && t.find('C') != t.npos && A == 0 && C == 0){
    cout << "AC" << endl;
  }
  else{
    cout << "WA" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
a = []
visit = [0] * n
for _ in range(n):
    a.append(int(input()))
i = 0
cnt = 0
flag = False
while visit[i] == 0:
    visit[i] = 1
    i = a[i] - 1
    cnt += 1
    if visit[1] == 1:
        flag = True
        break
if flag:
    print(cnt-1)
else:
    print(-1)

Measured memory_bytes: 7932
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define endl 			"\n"
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void Raghav()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(100);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	Raghav();
	int n, a;
	cin >> n;
	a = n;
	while (n % 1000 != 0)
	{
		n++;
	}
	cout << abs(n - a);
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long ;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    vector<string> ss;
    string hi = "";
    rep(i,6){
        hi += "hi";
        ss.push_back(hi);
    }
    string res = "No";
    for(string ps:ss){
        if(ps==s) res = "Yes";
    }
    cout << res << endl;
}

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

#define endl "\n"
#define long long long

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

    long int n;
    cin>>n;

    vector<long int> v(n);
    for(long int i = 0; i < n; i++)
        cin>>v[i];
    
    long int sum =  0;
    for(long int i = 0; i < n; i++)
        if(i & 1)
            sum -= v[i];
        else
            sum += v[i];
        
    vector<long int> ans(n);
    ans[0] = sum;

    for(long int i = 1; i < n; i++, sum *= -1)
        ans[i] = -ans[i-1] + 2 * v[i-1];
    
    for(auto ele : ans)
        cout<<ele<<" ";

    return 0;
}


Measured memory_bytes: 2944
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

struct Scanner {
    FILE* fp = nullptr;
    char line[1<<15];
    size_t st = 0, ed = 0;
    void reread() {
        memmove(line, line + st, ed - st);
        ed -= st;
        st = 0;            
        ed += fread(line + ed, 1, (1<<15) - ed, fp);
    }
    void succ() {
        while (true) {
            if (st == ed) reread();
            while (st != ed && isspace(line[st])) st++;
            if (st != ed) break;
        }
        if (ed - st <= 50) reread();
    }
    template <class T, enable_if_t<is_integral<T>::value, int> = 0>
    bool read_single(T& ref) {
        succ();
        bool neg = false;
        if (line[st] == '-') {
            neg = true;
            st++;
        }
        ref = T(0);
        while (isdigit(line[st])) {
            ref = 10 * ref + (line[st++] - '0');
        }
        if (neg) ref = -ref;
        return true;
    }
    Scanner(FILE* _fp) : fp(_fp) {}
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    Scanner sc(stdin);
    int n;
    sc.read_single(n);
//    cin >> n;
    V<int> freq(n);
    for (int i = 0; i < n; i++) {
        int a;
        sc.read_single(a); a--;
//        cin >> a; a--;
        freq[a]++;
    }
    sort(freq.begin(), freq.end());
    V<int> fsm(n + 1);
    for (int i = 0; i < n; i++) {
        fsm[i + 1] = fsm[i] + freq[i];
    }


    for (int k = 1; k <= n; k++) {
        int lw = 0, up = n + 1;
        while (up - lw > 1) {
            int md = (lw + up) / 2;
            int idx = lower_bound(freq.begin(), freq.end(), md) - freq.begin();
            int u = fsm[idx] + (n - idx) * md;
            if (u >= ll(md) * k) lw = md;
            else up = md;
        }
        cout << lw << "\n";
    }

    dbg(freq);


    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	pair<int, int> A[100010]; 
	int mx = 0; 
	for(int i = 0; i < N; i++){
		cin >> A[i].second >> A[i].first; 
		mx = max(mx, A[i].first - A[i].second); 
	}
	int L1[100010] = {}; int R1[100010] = {};
	int L2[100010] = {}; int R2[100010] = {};
	sort(A, A+N); 
	L1[0] = A[0].second; 
	R1[0] = A[0].first; 
	L2[N-1] = A[N-1].second; 
	R2[N-1] = A[N-1].first; 
	for(int i = 1; i < N; i++){
		L1[i] = max(L1[i-1], A[i].second); 
		R1[i] = min(R1[i-1], A[i].first); 
	}
	for(int i = N-2; i >= 0; i--){
		L2[i] = max(L2[i+1], A[i].second); 
		R2[i] = min(R2[i+1], A[i].first);	
	}
	int ans1 = max(R1[N-1] - L1[N-1] + 1, 0) + mx + 1;
	int ans2 = 0; 
	for(int i = 1; i <= N-1; i++){
		int a = max(R1[i-1] - L1[i-1] + 1, 0); 
		int b = max(R2[i] - L2[i] + 1, 0); 
		ans2 = max(ans2, a+b); 
	}
	cout << max(ans1, ans2) << endl; 
}

Measured memory_bytes: 2560
def main():
    m = 1000000007

    h, w = map(lambda x: int(x), input().split())

    grid = []
    for row in range(h):
        grid.append(input())

    count = []
    for row in range(h):
        count.append([0] * w)

    for row in range(h):
        if grid[row][0] == "#":
            break
        count[row][0] = 1

    for column in range(w):
        if grid[0][column] == "#":
            break
        count[0][column] = 1

    for row in range(1, h):
        for column in range(1, w):
            if grid[row][column] == ".":
                count[row][column] = (
                    (count[row - 1][column] % m) +
                    (count[row][column - 1] % m)
                ) % m

    print(count[-1][-1])

main()


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

R, C, K = map(int, input().split())

I = [[0]*C for i in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    I[r-1][c-1] = v   # 0-indexed

dp0 = [[0 for j in range(C+1)] for i in range(R+1)]
dp1 = [[0 for j in range(C+1)] for i in range(R+1)]
dp2 = [[0 for j in range(C+1)] for i in range(R+1)]
dp3 = [[0 for j in range(C+1)] for i in range(R+1)]
for i in range(R):
    for j in range(C):
        dp3[i][j] = max(dp3[i][j], dp2[i][j]+I[i][j])
        dp2[i][j] = max(dp2[i][j], dp1[i][j]+I[i][j])
        dp1[i][j] = max(dp1[i][j], dp0[i][j]+I[i][j])
        dp0[i+1][j] = max(dp0[i+1][j], dp0[i][j], dp1[i]
                          [j], dp2[i][j], dp3[i][j])
        dp0[i][j+1] = max(dp0[i][j+1], dp0[i][j])
        dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j])
        dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j])
        dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j])


# print(*dp, sep=' \n')

ans = max(dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1])
print(ans)


Measured memory_bytes: 465136