akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
    /* code */
    int N = 3;
   // cin >> N;
    vector<int> A(N,0);
    for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    int n = A.at(2)+A.at(2)-A.at(1)-A.at(0);

    cout << n/2 +(n%2)*2 << endl;
    return 0;
}

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

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));

    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while( x!=NIL ){
        y = x;
        if( z->key < x->key ){
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if ( y ==NIL ){
        root = z;
    } else {
        if( z->key < y->key ){
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder( Node *u )
{
    if( u==NIL )
        return;
    inorder(u->left);
    printf( " %d", u->key );
    inorder(u->right);
}

void preorder( Node *u )
{
    if( u==NIL )
        return;
    printf( " %d", u->key );
    preorder( u->left );
    preorder( u->right );
}

int main()
{
    int n, i, x;
    string com;

    scanf( "%d", &n );

    for( i=0; i<n; i++ ){
        cin >> com;

        if( com == "insert" ){
            scanf( "%d", &x );
            insert(x);
        } else if ( com == "print" ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}



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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n;
    cin >> n;
    vii arr(n);
    REP(i, 0, n) {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    vvi dp(n, vi(n+1, -1));
    sort(all(arr), greater<pi>());
    dp[0][1] = abs(arr[0].second - 0) * arr[0].first;
    dp[0][0] = abs(arr[0].second - (n-1)) * arr[0].first;
    REP(i, 1, n) {
        REP(j, 0, i+1) {
            dp[i][j] = max(dp[i][j], dp[i-1][j] + arr[i].first * abs(arr[i].second - (n-1-(i-j))));
            dp[i][j+1] = max(dp[i][j+1], dp[i-1][j] + arr[i].first * abs(arr[i].second - j));
        }
    }
    cout << *max_element(all(dp[n-1])) << endl;
}


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

int cost(int a[], int dp[], int n, int i)
{
	if(i > n-1)
		return 100000;
	if(i == n-1)
		return 0;
	if(dp[i] >= 0 )
		return dp[i];
	else
	{
		int k1 = abs(a[i+1] - a[i]) + cost(a, dp, n, i+1); 
		int k2 = abs(a[i+2] - a[i]) + cost(a, dp, n, i+2);
		if(k1 > k2)
		{
			dp[i] = k2;
		}
		else
		{
			dp[i] = k1;
		}
		return dp[i]; 
	}
}

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

	cin >> n;

	int a[n+2] = {};
	int dp[n];

	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		dp[i] = -1;	
	}

	// int k = cost(a, dp, n, 0);
	dp[1] = abs(a[1] - a[0]);
	dp[0] = 0;

	int k1, k2;
	for (int i = 2; i < n; ++i)
	{
		k1 = dp[i-1] + abs(a[i] - a[i-1]);
		k2 = dp[i-2] + abs(a[i] - a[i-2]);
		dp[i] = k1 < k2 ? k1 : k2; 
	}

	cout << dp[n-1]; 

	// cout << k;
	return 0;
}


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

using namespace std;

int main(void) {
	
	int n,k;
	cin >>n >>k;
	
	int h[n],i;
	for (i=0 ; i<n ; i++) {
		cin >>h[i];
	}
	
	sort(h,h+n);
	
	int d,dmin=h[n-1]-h[0];
	for (i=0 ; i<=n-k ; i++) {
		d=h[i+k-1]-h[i];
		if (d<dmin) dmin=d;
	}
	
	cout <<dmin <<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        int data[11][10010];
        rep(i,n)rep(j,m)cin>>data[i][j];
        
        
        int ans=0;
        rep(i,1<<n){
            int t=0;
            rep(j,m){
                int a=0;
                rep(k,n){
                    if((i&(1<<k))!=0){
                        a+=!data[k][j];
                    }
                    else a+=data[k][j];
                }
                t+=max(a,n-a);
            }
            ans=max(ans,t);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1560
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int q;
int ans[N];
vector < pair < pair < int , int > , int > > event;

int main(){
    scanf("%d%d" , &n , &q);
    for(int i = 1; i <= n; i++){
        int s , t , x;
        scanf("%d%d%d" , &s , &t , &x);
        event.push_back({{s - x , 0} , x});
        event.push_back({{t - x , 1} , x});
    }
    for(int i = 1; i <= q; i++){
        int d;
        scanf("%d" , &d);
        event.push_back({{d , 2} , i});
    }
    multiset < int > xx;
    memset(ans , -1 , sizeof ans);
    sort(event.begin() , event.end());
    for(auto v : event){
        int a = v.first.first;
        int b = v.first.second;
        int c = v.second;
        if(b == 0){
            xx.insert(c);
        } else if(b == 1){
            xx.erase(xx.lower_bound(c));
        } else {
            if(xx.empty())
                continue;
            ans[c] = *xx.begin();
        }
    }

    for(int i = 1; i <= q; i++){
        printf("%d\n" , ans[i]);
    }
}


Measured memory_bytes: 18664
a=[]
b=[]
while(True):
    x,y = map(int,input().split())
    if(x==0 and y==0):
        break
    a.append(x)
    b.append(y)
for qq in range(len(a)):
    for qqq in range(a[qq]):
        for qqqq in range(b[qq]):
            print("#",end="")
        print("")
    print("")


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

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

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

        if (x % 3 == 0){
            cout << " " << i;
            continue;
        }

        while(x != 0){
            if (x % 10 == 3){
                cout << " " << i;
                break;
            }
            x /= 10;
        }


    }
    cout << endl;
}


Measured memory_bytes: 3080
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();
        long ans = 0;
        if(h==1||w==1){
            System.out.println(1);
            return;
        }
        if(h%2==0){
            ans = h*w/2;;
        }else{
            if(w%2==0){
                ans = h*w/2;
            }else{ 
                ans = h*w/2+1;
            }
        }
        System.out.println(ans);
    }
    
}



Measured memory_bytes: 23252
#include <stdio.h>

int main(){
    int d1,d2,d3;
    scanf("%d %d %d",&d1,&d2,&d3);

    int t = 0;
    while(!(d1 <= d2 && d2 <= d3)){
        if(d1 > d2){
            t = d1;
            d1 = d2;
            d2 = t;
        } 

        if(d2 > d3){
            t = d2;
            d2 = d3;
            d3 = t;
        }
        
    }

    printf ("%d %d %d\n" , d1,d2,d3);
    return 0;
}


Measured memory_bytes: 2680
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int R = scanner.nextInt();
			int C = scanner.nextInt();
			if ((R | C) == 0)
				break;
			int[] b = new int[C];
			for (int i = 0; i < R; i++)
				for (int j = 0; j < C; j++) {
					int a = scanner.nextInt();
					b[j] = b[j] * 2 + a;
				}
			int ans = 0;
			for (int x = 0; x < (1 << R); x++) {
				int k = 0;
				for (int j = 0; j < C; j++) {
					int aa = b[j];
					int bb = aa ^ x;
					int cc = Integer.bitCount(bb);
					k += Math.max(cc, R - cc);
				}
				ans = Math.max(ans, k);
			}
			System.out.println(ans);
		}
	}
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end()))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0) { cout << 1 << endl; }
    if (b == 0) { cout << 2 << endl; }
    if (c == 0) { cout << 3 << endl; }
    if (d == 0) { cout << 4 << endl; }
    if (e == 0) { cout << 5 << endl; }
}


Measured memory_bytes: 3584
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
    class MainClass {
        public static void Main(string[] args) { new MainClass().solve(); }

        Scanner cin = new Scanner();

        int a, b, c;
        void solve() {
            a = cin.nextInt();
            b = cin.nextInt();
            c = cin.nextInt();

            int[] candy = {a,b,c};

            Array.Sort(candy);
            Array.Reverse(candy);

            bool isEnable = candy[0] == (candy[1] + candy[2]);

            Console.WriteLine(isEnable?"Yes":"No");

        }
        class Scanner {
            string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' };
            public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; }
            public string next() {
                if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                BufferCnt = 0;
                return nextBuffer[BufferCnt++];
            }
            public int nextInt() { return int.Parse(next()); }
            public long nextLong() { return long.Parse(next()); }
            public double nextDouble() { return double.Parse(next()); }
        }
        class Mathf {
            private int mod = 1000000007;//10^9+7
            public int Mod { get; set; }
            public Mathf() { }
            public Mathf(int mod) { this.mod = mod; }
            public long Pow(long a, long b) {
                if (b == 0) return 1;
                if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
                else return Pow(a * a % mod, b / 2) % mod;
            }
            public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; }
            public long C(long n, long r) {if (r == 0 || n == r) return 1;
                else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod;}
        }
    }
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int alen = A.size(), blen = B.size();
  if (A[alen-1] == B[0] && B[blen-1] == C[0])
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

void solve(){
    int a, v, b, w, t;
    cin >> a >> v >> b>> w>> t;

    if(a==b){
        cout << "YES\n";
        return;
    }
    if(w >= v){
        cout << "NO\n";
        return;
    }

    int ds = abs(b-a);
    int dv = abs(v-w);

    bool ans = (ll)dv*t >= (ll)ds;
    cout << (ans ? "YES\n" : "NO\n");
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int A, B, C, x;
	cin >> A >> B >> C >> x;
	int ans = 0;
	rep(a, A + 1) {
		rep(b, B + 1) {
			rep(c, C + 1) {
				if (500 * a + 100 * b + 50 * c == x)
					ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
P sg[10];
int d[1005][1005]={};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];

signed main(){
    int n,m;cin>>n>>m;
    int num[100005];
    rep(i,n){
        cin>>num[i];
    }
    int ans=0;
    if(num[0]>m){
        ans+=num[0]-m;
         num[0]=m;
    }
    for(int i=1;i<n; i++){
        int sum=num[i]+num[i-1];
        if(sum<=m)continue;
        num[i]-=sum-m;
        ans+=sum-m;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

        int N = Integer.parseInt(sc.next());
        int Y = Integer.parseInt(sc.next());

        // 紙幣は0枚～N枚数まで使用できるので、Nに1加算する
        String ans = countMoney(N, Y);
        System.out.println(ans);
    }

    private static String countMoney(int N, int Y) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < N + 1; i++) {
            for (int j = 0; j < N + 1; j++) {
                int remain = Y - (i * 10000 + j * 5000);
                int use = i + j + remain / 1000;
                if (use == N && remain / 1000 >= 0) {
                    sb.append(i + " ");
                    sb.append(j + " ");
                    sb.append(String.valueOf(remain / 1000));
                    return sb.toString();
                }
            }
        }
        return "-1 -1 -1";
    }
}


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



int main(){
    long long n; cin >> n;
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 3624
fn main() {
    let aaa = read_vec::<String>();

    let f = &aaa[0];
    let s = &aaa[1];
    
    println!("{}{}", s, f);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, l, n) for(int i=(l); i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int main(){
    char c;
    cin >> c;

    if (c >= 'A' && c <= 'Z') {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }

    return 0;
}



Measured memory_bytes: 3620
def g(x):
    if x == 0:
        return 0
    if x % 2 == 1:
        if x % 4 == 1:
            return 1
        else:
            return 0
    else:
        return g(x-1) ^ x

a, b = map(int, input().split())
if a == 0:
    print(g(b))
else:
    print(g(b) ^ g(a-1))

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 5005;

bool pdp[N][N];
bool sdp[N][N];
int ps[N][N + 1];

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	{
		pdp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int p = 0; p < N; p++) {
				if (!pdp[i][p]) continue;
				if (p + a[i] < N) {
					pdp[i + 1][p + a[i]] = 1;
				}
				pdp[i + 1][p] = 1;
			}
		}
	}
	{
		sdp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int p = 0; p < N; p++) {
				if (!sdp[i][p]) continue;
				if (p + a[n - 1 - i] < N) {
					sdp[i + 1][p + a[n - 1 - i]] = 1;
				}
				sdp[i + 1][p] = 1;
			}
		}	
	}
	{
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j < N; j++) {
				ps[i][j + 1] = ps[i][j] + sdp[i][j];
			}
		}
	}
	int c = n;
	for (int i = 0; i < n; i++) {
		int fu = 0;
		for (int p = 0; p < k; p++) {
			if (!pdp[i][p]) continue;
			int l = max(0, k - p - a[i]);
			int r = k - p;
			int any = (ps[n - 1 - i][r] > ps[n - 1 - i][l]);
			fu |= any;
		}
		c -= fu;
	}
	cout << c << endl;
}


Measured memory_bytes: 147072
import java.util.Scanner;
public class Main {
	 public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);

	            while(true) {
	            int  H = sc.nextInt();
	            int W=sc.nextInt();	
	            if(W==0 && H==0)
	            		break;
	            	
	            	for(int i=0;i<H;i++) {
	            		for(int j=0;j<W;j++) {
	            			System.out.print("#");
	            	}
	            	System.out.println();
	            }
	            System.out.println();
	            }
	            sc.close();
	    }
	}


Measured memory_bytes: 34960
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int s = Input.Cin<int>();
        HashSet<int> hs = new HashSet<int>();
        hs.Add(s);
        while (true)
        {
            int box = (s % 2 == 0 ? s / 2 : 3 * s + 1);
            if (hs.Contains(box)) break;
            hs.Add(box);
            s = box;
        }
        Console.WriteLine(hs.Count()+1);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)(0);
    }
    public static T Line<T>()
    {
        foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        int c = queue.Count();
        if (typeof(T) == typeof(int[]))
        {
            int[] ret = new int[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<int>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(long[]))
        {
            long[] ret = new long[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<long>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(string[]))
        {
            string[] ret = new string[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<string>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(double[]))
        {
            double[] ret = new double[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<double>();
            return (T)(object)ret;
        }
        else return (T)(object)(0);
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	int n=s.length();
	int ans=1,flag=0;
	f(i,1,n)
	{
		if(s[i]==s[i-1]&&flag==0)
		{
			flag=1;
			ans++;
			i++;
		}
		else
		{
			flag=0;
			ans++;
		}
		if(i==n)
			ans--;
	}
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,k,a;cin>>n>>k;
  for(int i=0;i<n;i++){
    if(k<0){
      cout<<i;return 0;
    }
    cin>>a;k-=a;
  }if(k>=0)n++;
  cout<<n;
}

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

int main(){

 
  int n=0;
  cin>>n;
  int x[n];
  double ave=0;
  rep(i,n){
    cin>>x[i];
  	ave+=x[i];
  }
  ave/=n;
  
  ave=round(ave);
  
  int cost=0;
  rep(i,n){

    cost+=(x[i]-ave)*(x[i]-ave);
    
  }
  
  cout<<cost<<endl;
  
}

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

int main(){
    int n;
    while(cin >> n, n){
        int ans = 0, a;
        for(int i = 0; i < n/4; i++){
            cin >> a;
            ans += a;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
n,m=map(int,input().split())
i=2
s=[]
while i*i<=m:
  j=0
  while m % i == 0:
    m//=i
    j+=1 
  if j:
    s+=[j]
  i+=1
a=1
if m > 1:
  s+=[1]
  
for v in s:
  c = 1
  for i in range(v):
    c = c * (n+i) // (1+i)
  a = a * c % (10**9+7)
print(a)


Measured memory_bytes: 3064
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut face = 0;
    for i in 0..n {
        if s[i]=='W' {
            face += 1;
        }
    }

    let mut ans = 0;
    if s[0]=='W' {
        face -= 1;
    }
    ans = face;
    debug!(ans);
    for i in 1..n {
        if s[i-1]=='W' {
            if s[i]=='W' {
                face -= 1;
            }
        } else {
            if s[i]=='E' {
                face += 1;
            } 
        }  
        ans = max(ans, face);
        debug!(face);
    }

    println!("{}", n-ans-1);

}


Measured memory_bytes: 6720
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n, k, s;
    cin >> n >> k >> s;
    ll a[2] = {s/2, s%2 == 1 ? s/2 + 1 : s/2};
    rep(i, n){
        if(i > 0) cout << " ";
        if(k == n){
            cout << s;
            continue;
        }
        if(i <= k){
            if(s != 1) cout << a[i%2];
            else if(s == 1 && i < k) cout << "1";
            else cout << "2";
        }else{
            if(s == 1000000000) cout << "1";
            else cout << s+1;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    x = input()            
    cnt  = 0
    t = 0
    for i in x:
        if i == 'S':
            cnt += 1
        else:
            cnt -= 1
        t = min(t, cnt)
    print(cnt-2*t)



if __name__ == '__main__':
    main()

Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n;
    cin>>n;
    cout<<n*(n+1)/2<<endl;
}

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

int main()
{
	int n, m;
	std::cin >> n >> m;

	std::vector<int> vec(2 * n);
	for (int i = 0; i != 2 * n; ++i)
		vec[i] = i + 1;

	int k;
	for (int i = 0; i != m; ++i)
	{
		std::vector<int> vec2 = vec;
		std::cin >> k;
		if (k == 0)
		{
			for (int i = 0; i != n; ++i)
			{
				vec[2 * i] = vec2[i];
				vec[2 * i + 1] = vec2[i + n];
			}
		}
		else if (1 <= k&&k <= 2 * n - 1)
		{
			// 0から2n-k-1まで
			for (int i = k; i != 2 * n; ++i)
				vec[i - k] = vec2[i];

			// kから2n-1まで
			for (int i = 0; i != k; ++i)
				vec[i + 2 * n - k] = vec2[i];
		}
	}

	for (int i = 0; i != 2 * n; ++i)
		std::cout << vec[i] << std::endl;

	return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair
#define clamp(v,lo,hi) min(max(v,lo),hi)
#define ABS(x) max((x),-(x))
#define PQ(T) priority_queue<T,vector<T>,greater<T>>

template<typename T1, typename T2> inline void amin(T1 & a, T2 const & b) { if (a>b) a=b; }
template<typename T1, typename T2> inline void amax(T1 & a, T2 const & b) { if (a<b) a=b; }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
inline ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }

int dp[19][262144][51];

int solve(int N, vi& a, vi& b) {
    mset(dp, 0x7f);

    dp[0][0][0] = 0;
    int P = 1 << N;
    rep(i,N){
        rep(p,P){
            rep(last,51){
                if (dp[i][p][last] == 0x7f7f7f7f) continue;
                rep(j,N){
                    int mj = 1 << j;
                    if (p & mj) continue;
                    int d = ABS(j - i)%2;
                    int x = d ? b[j] : a[j];
                    if (last > x) continue;
                    int sw = __builtin_popcount(p >> j);
                    amin(dp[i+1][p|mj][x], dp[i][p][last]+sw);
                }
            }
        }
    }
    int res = 0x7f7f7f7f;
    rep(last,51){
        amin(res, dp[N][P-1][last]);
    }
    if (res == 0x7f7f7f7f) return -1;
    return res;
}

int main() {
    int N; cin >> N;
    vi a(N), b(N);
    rep(i,N) cin >> a[i];
    rep(i,N) cin >> b[i];
    cout << solve(N,a,b) << endl;
    return 0;
}


Measured memory_bytes: 992640
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<bitset>

using namespace std;



int main(){
  int n; cin>>n;
  if(n%2==0){
    cout<<n/2-1<<endl;
  }
  else{
  cout<<n/2<<endl; 
  }

}


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

int main(void) {
    int H1,M1,H2,M2,K;cin>>H1>>M1>>H2>>M2>>K;
    int result = H2 * 60 + M2 - K - (H1 * 60 + M1);
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str1 = sc.next();
    String str2 = sc.next();

    if(str1.length() > str2.length()){
      System.out.println("GREATER");
      return;
    }else if(str1.length() < str2.length()) {
      System.out.println("LESS");
      return;
    }

    for(int i = 0; i<str1.length(); i++) {
      char ch1 = str1.charAt(i);
      char ch2 = str2.charAt(i);
      if(ch1 > ch2) {
        System.out.println("GREATER");
        return;
      }else if(ch1 < ch2) {
        System.out.println("LESS");
        return;
      }
    }
    System.out.println("EQUAL");
  }
}


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

using namespace std;
typedef long long ll;
const long long mod=1e9+7; //10^9+7

int main() {
    int n, a[200001];
    cin >> n;
    a[0] = 0;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    int b[200001];
    for(int i=n; i>=1; i--){
        int x = 0;
        for(int j=i*2; j<=n;j+=i){
            x += b[j];
        }
        if(x%2==a[i]) b[i]=0;
        else b[i]=1;
        //cout << "b["<<i<<"]="<<b[i]<<endl;
    }
    //cout << "---------" << endl;
    int m=0;
    for(int i=1; i<=n; i++){
        if(b[i]==1) m++;
    }
    cout << m<<endl;
    for(int i=1; i<=n; i++){
        if(b[i]==1) cout << i << " ";
    }
    cout << endl;

  return 0;
}


Measured memory_bytes: 2432
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<cstring>
using namespace std;

int a[100005],b[100005],p[35];

int main(){
	int n,k;
	long long sum = 0,ans = 0; 
	scanf("%d %d",&n,&k);
	for(int i = 1;i <= n;i++){
		scanf("%d %d",&a[i],&b[i]);
		if((a[i] | k) == k) sum += b[i];
	}
	p[0] = 1;
	for(int i = 1;i <= 29;i++) p[i] = p[i - 1] * 2;
	for(int i = 1;i <= 29;i++){
		if(k & p[i]){
			ans = 0;
			int tot;
			tot = (k^p[i])|(p[i] - 1);
			for(int j = 1;j <= n;j++){
				if((a[j] | tot) == tot) ans += b[j];
			}
			sum = max(ans,sum);
		}
	}
	printf("%lld",sum);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

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

}
int main(){
  ll N;
  cin>>N;
  vector<ll>L(N);
  
  rep(i,N){
    cin>>L[i];
  }
  sort(all(L));
  ll ans=0;
  
  rep(i,N){
    if(i==N-1){
      break;
    }

    for(ll j=i+1;j<N;j++){
      if(j==N-1){
        break;
      }

    for(ll k=j+1;k<N;k++){
      if(L[i]+L[j]+L[k]>2*max(max(L[i],L[j]),L[k])){
        ans++;
      }
    }
    }
  }


cout<<ans<<endl;
}
      
      

Measured memory_bytes: 384
from math import floor
import heapq

n, m = map(int, input().split())
A = [-a for a in map(int, input().split())]
heapq.heapify(A)
for _ in range(m):
  num = heapq.heappop(A) / 2
  heapq.heappush(A, num)

print(sum(floor(-a) for a in A))

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

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	
	sort(d.begin(), d.end());
	int ans = d[n/2] - d[n/2-1];
	
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N,K,M;cin>>N>>K;
  if(K==10)cout<<to_string(N).size()<<endl;
  else{
    for(M=0;N>0;M++){
      N/=K;
    }
    cout<<M<<endl;
  }
}


Measured memory_bytes: 3632
import sys

R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
    for j in range(C + 1):
        for k in range(4):
            here = dp[k][i][j]
            # 次の行
            if i + 1 <= R:
                dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
            # 次の列
            if j + 1 <= C:
                dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                if k < 3:
                    dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)


Measured memory_bytes: 425568
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] input = Input.InputMultipleNum();
            int N = input[0], X = input[1];
            input = Input.InputMultipleNum();

            int count = 1, L = 0;
            for(int i = 0; i < N; i++)
            {
                L += input[i];
                if (L > X) break;
                count++;
            }
            Console.WriteLine($"{count}");
        }

    }

    static class Input
    {
        static public int InputSingleNum() { return int.Parse(Console.ReadLine()); }
        static public int[] InputMultipleNum() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }

        static public string InputSingleStr() { return Console.ReadLine(); }
        static public string[] InputMultipleStr() { return InputSingleStr().Split(' '); }
    }
}


Measured memory_bytes: 13396
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

X=l()[0]
i=1
while(X-i>0):
    X-=i
    i+=1

print(i)


Measured memory_bytes: 5376
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF (__INT32_MAX__ / 2)
#define MAX_LEN 100000

using namespace std;

int min(int l, int r) { return l < r ? l : r; }

int main(int argc, char **argv) {
    char str[MAX_LEN + 1];
    scanf("%s", str);

    int red = 0;
    int blue = 0;
    for(int i = 0; i < strlen(str); ++i)
        if(str[i] == '0')
            ++red;
        else if(str[i] == '1')
            ++blue;

    printf("%d\n", 2 * min(red, blue));
}

Measured memory_bytes: 256
a,b=map(int,input().split())
ans=0
if a%2==0:
    ans^=a
    a+=1
if b%2==1:
    ans^=b
    b-=1
if a>b:
    print(ans)
else:
    lst=[0]
    i=1
    while b//(2**i)>0:
        lst.append(b//(2**i)-(a-1)//(2**i))
        i+=1
    h=len(lst)
    for i in range(1,h-1):
        if (lst[i]-lst[i+1])%2==1:
            ans^=2**(i+1)-1
    if lst[h-1]%2==1:
        ans^=2**h-1
    print(ans)

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

int main () 
{
    int Z[3];
    
    std::cin >> Z[0] >> Z[1] >> Z[2];
    
    sort(Z, Z+3);
    
    int count = Z[2] - Z[1];
    
    int dif = Z[1] - Z[0];
    
    if(dif % 2 == 0)
    {
        count += dif / 2;
    }
    else
    {
        count += (dif + 1) / 2 + 1;
    }
    
    std::cout << count << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

typedef long long int Int;

int main(void) {
    int N;
    cin>>N;
    vector<int> a(N),b(N);
   
    for(int i = 0;i < N;i++) {
        cin>>a[i];
    }
    for(int i = 0;i < N;i++) {
        cin>>b[i];
    }

    int ans = 0;
    for(int k = 28;k >= 0;k--) {
        int i1 = 0,i2 = 0,i3 = 0;
        int T = 1 << k;
        int ad = 0;
        
        for(int i = 0;i < N;i++) {
            a[i] %= 2*T;
            b[i] %= 2*T;
        }
        sort(a.begin(),a.end(),greater<int>());
        sort(b.begin(),b.end());
        for(int i = 0;i < N;i++) {
            while(i1 < N && a[i] + b[i1] < T) i1++;
            while(i2 < N && a[i] + b[i2] < 2*T) i2++;
            while(i3 < N && a[i] + b[i3] < 3*T) i3++;
            ad += (i2 - i1) + (N - i3);
        }
        if(ad % 2)
            ans += T;
    }

    cout<<ans<<endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int r, minv, ret;
  cin >> r; minv = r;
  for (int i = 1; i < n; i++) {
    cin >> r;
    if (i == 1) ret = r - minv;
    else ret = max(ret, r - minv);
    minv = min(minv, r);
  }
  cout << ret << endl;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;
int d[100009];

int main()
{
	int n, x;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		d[x] = i;
	}
	for (int i = 1; i <= n; i++)
		cout << d[i] << " ";
}

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    A,B = map(int, input().split())
    ps = set(prime_factorize(A)) & set(prime_factorize(B))
    print(len(ps)+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) {
		cin >> a.at(i);
		a.at(i) = a.at(i) - 1;
	}
	vector<int> check_a(N, 0);

	int light = 0;
	int cnt = 0;
	while (1) {
		if (light == 1) {
			break;
		}
		else if (check_a[light] == 0) {
			check_a[light] = 1;
		}
		else {
			cnt = -1;
			break;
		}
		light = a[light];
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 1024
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, r, k, p;
	static int[][] router, packet;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		n = sc.nextInt();
		router = new int[n+1][n+1];
		for(int[] init : router)Arrays.fill(init, 1<<29);
		for(int i = 0; i < n; i++){
			r = sc.nextInt();
			k = sc.nextInt();
			for(int j = 0; j < k; j++){
				int t = sc.nextInt();
				router[r][t] = 1;
			}
		}
		p = sc.nextInt();
		packet = new int[p+1][3];
		for(int i = 1; i <= p; i++){
			for(int j = 0; j < 3; j++){
				packet[i][j] = sc.nextInt();
			}
		}
		return true;
	}
	
	static void solve(){
		for(int k = 1; k <= n; k++){
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					router[i][j] = Math.min(router[i][j], router[i][k] + router[k][j]);
				}
			}
		}
		for(int i = 1; i <= p; i++){
			int source = packet[i][0];
			int destination = packet[i][1];
			int TTL = packet[i][2];
			if( router[ source ][ destination ] < TTL ){
				System.out.println(router[ source ][ destination ]+1);
			}else{
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 26480
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {

	int a, b, c,d;
	cin >> a >> b >> c>>d;
	string s = "No";
	if ((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) {
		s = "Yes";
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int N;
long long A[305][305];
bool take[305][305];
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)cin>>A[i][j];
    for(int k=1;k<=N;k++)
    {
        for(int i=1;i<=N;i++)
        {
            if(i!=k&&A[i][k])
            {
                for(int j=1;j<=N;j++)
                {
                    if(j!=k&&j!=i&&A[j][k])
                    {
                        if(!A[i][j]||A[i][j]>A[i][k]+A[j][k])
                        {
                            cout<<-1;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    long long rez=0;
    for(int k=1;k<=N;k++)
    {
        for(int i=1;i<=N;i++)
        {
            if(i!=k&&A[i][k])
            {
                for(int j=1;j<=N;j++)
                {
                    if(j!=k&&j!=i&&A[j][k])
                    {
                        if(A[i][j]==A[i][k]+A[j][k])
                        {
                            take[i][j]=1;
                        }
                    }
                }
            }
        }
    }
    for(int i=1;i<=N;i++)for(int j=1;j<i;j++)rez+=(A[i][j]*(!take[i][j]));
    cout<<rez;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  string str;
  cin>>str;
  int now=str[0]-'0';
  string ans="";
  ans+=str[0];
  int flag=0;
  for(int i=0;i<2;i++){
    int now2;
    if(i%2==0){
      now2=now+(str[1]-'0');
    }else{
      now2=now-(str[1]-'0');
    }
    for(int j=0;j<2;j++){
      int now3;
      if(j%2==0)
	now3=now2+(str[2]-'0');
      else
	now3=now2-(str[2]-'0');
      for(int k=0;k<2;k++){
	int now4;
	if(k%2==0)
	  now4=now3+(str[3]-'0');
	else
	  now4=now3-(str[3]-'0');
	if(now4==7){
	  if(i==0)ans+='+';
	  else ans+='-';
	  ans+=str[1];
	  if(j==0)ans+='+';
	  else ans+='-';
	  ans+=str[2];
	  if(k==0)ans+='+';
	  else ans+='-';
	  ans+=str[3];
	  flag=1;
	  break;
	}
      }
      if(flag)
	break;
    }
    if(flag)
      break;
  }
  cout<<ans<<"=7"<<endl;
  return 0;
}


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

ll sum=0;

ll cost(ll wt[],ll val[],ll n,ll w)
{
    ll c[n+1][w+1];
    
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0||j==0)
            c[i][j]=0;
            else if(wt[i-1]<=j)
            c[i][j]=max(val[i-1]+c[i-1][j-wt[i-1]],c[i-1][j]);
            else c[i][j]=c[i-1][j];
        }
    }
    
    cout<<c[n][w];
    
}

int main()
{
    ll n,w;
    cin>>n>>w;
    ll val[n+1],wt[n+1];
    for(ll i=0;i<n;i++)
    cin>>wt[i]>>val[i];
    cost(wt,val,n,w);

    return 0;
}


Measured memory_bytes: 79104