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

typedef pair<int, int> PII;
#define fi first
#define se second

const int N=105;
vector<PII> g[N];
int dist[N];
bool vis[N];
int n;

void dijkstra(){
    dist[0]=0;
    priority_queue<PII, vector<PII>, greater<PII>> q;
    q.push({0, 0});
    while(!q.empty()){
        int node=q.top().se;
        q.pop();
        if(vis[node]) continue;
        vis[node]=true;
        for(auto &e: g[node]){
            int v=e.fi;
            int w=e.se;
            if(dist[v]>dist[node]+w){
                dist[v]=dist[node]+w;
                q.push({dist[v], v});
            }
        }
    }
}

int main(){
    memset(dist, 0x3f, sizeof dist);
    memset(vis, 0x00, sizeof vis);
    cin>>n;
    for(int i=0; i<n; ++i){
        int u, k;
        cin>>u>>k;
        for(int j=0; j<k; ++j){
            int v, w;
            cin>>v>>w;
            g[u].push_back({v, w});
        }
    }
    
    dijkstra();
    for(int i=0; i<n; ++i) cout<<i<<" "<<dist[i]<<endl;
    
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define H 2000005
using namespace std;
int h,A[H];

void maxHeapify(int x){
  int l=x*2,r=x*2+1,lag;
  if(l<=h&&A[l]>A[x])lag=l;
  else lag=x;
  if(r<=h&&A[r]>A[lag])lag=r;
  if(lag!=x){
    swap(A[x],A[lag]);
    maxHeapify(lag);
  }
}

void heapIncreaseKey(int x,int key){
  A[x]=key;
  while(x>1&&A[x/2]<A[x]){
    swap(A[x],A[x/2]);
    x=x/2;
  }
}

void insert(int key){
  A[++h]=-1;
  heapIncreaseKey(h,key);
}

int extractMax(){
  int res=A[1];
  A[1]=A[h--];
  maxHeapify(1);
  return res;
}

int main(){
  string s;
  int key;
  while(1){
    cin>>s;
    if(s=="end")break;
    if(s=="extract")cout<<extractMax()<<endl;
    if(s=="insert"){
      cin>>key;
      insert(key);
    }
  }
  return 0;
}

Measured memory_bytes: 5300
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int a = ni();
		int p = ni();
		
		System.out.println((a * 3 + p)/2) ;		
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23124
import java.util.*;
public class Main{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long count = 0;
        for(int i = 0;i<n;i++)a[i]=sc.nextLong();
        for(int i = 0;i<n;i++){
            while(a[i]%2==0){
                a[i]/=2;
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 48328
import java.util.Scanner;

class Main{

  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int[] c = new int[101];
      int m = 0;
      while(sc.hasNext()) m = Math.max(m, ++c[sc.nextInt()]);
      for(int i=1;i<=100;i++)if(m==c[i])System.out.println(i);
  }
}
 

Measured memory_bytes: 18116
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<iostream>
#include<string>
#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
typedef long long ll;
const int maxn = (ll) 2e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
using namespace std;
int main() { 
	start;
	string a,b;cin>>a>>b;
	int l=b.length();
	int ans = inf;
	for(int i=0;i<a.length();i++){
		int cnt = 0;
		if(i+l>a.length()) break;
		for(int j=0;j<l;j++){
			if(a[i+j]!=b[j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout<<ans;
	return 0; 
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using P = std::tuple<int,int>;
using ll = long long;

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

int A[100000];

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

    int N;
    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    int pair_n = 0;
    for(int i=0;i<N;++i){
        if(i == A[A[i]-1]-1){
            // std::cout << i << std::endl;
            ++pair_n;
        }
    }

    std::cout << (pair_n / 2) << std::endl;
}


Measured memory_bytes: 640
N = int(input())
S = str(input())
V = []
f=0
s=set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            V.append(str(i)+str(j)+str(k))

for v in V:
    for a in range(N):
        if S[a]==v[0]:
            for b in range(a+1, N):
                if S[b]==v[1]:
                    for c in range(b+1, N):
                        if S[c]==v[2]:
                            s.add(v)
                            break
                    break
            break
print(len(s))

Measured memory_bytes: 42332
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    double b;
    cin >> A >> b;
    B = b * 100 + 0.5;
    cout << (A * B) / 100L << endl;
}


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

int main(void) {
    string S;cin>>S;
    int one = 0;
    int zero = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '1') one++;
        else zero++;
    }
    cout << S.size() - abs(one - zero) << endl;
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#define ll long long;

using namespace std;
int n;
int a[100];

void InsertionSort(int a[]) {
	for (int i = 0; i < n; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (int i = 0; i < n-1; i++) {
			cout << a[i] << ' ';
		}
		cout << a[n - 1] << endl;
	}
}

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

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

int main(void) {
    ios::sync_with_stdio(0);
    
    string s; cin >> s;
    int ans = 0;
    int a = -1;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'A') a = (a == -1? i : min(a, i));
        else if (s[i] == 'Z' && a != -1) ans = max(ans, i - a + 1);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 720
fun main(args : Array<String>) {
    val n = readLine()!!.toDouble()
    val price = n / 1.08

    if (price == price.toInt().toDouble()) {
        println(price.toInt())
    } else {
        if (((price + 1).toInt() * 1.08).toInt() == n.toInt()) {
            println((price + 1).toInt())
            return
        }
        println(":(")
    }
}

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

using namespace std;
typedef long long ll;


string s, t;
int dp[3010][3010];

int f(int i, int j)
{
    if (i == s.size() || j == t.size()) return 0;
    int &ret = dp[i][j];
    if (~ret) return ret;
    if (s[i] == t[j])
        ret = f(i+1, j+1) + 1;
    ret = max(ret, f(i+1, j));
    ret = max(ret, f(i, j+1));
    return ret;
}
void print(int i, int j)
{
    if (i == s.size() || j == t.size()) return ;
    if (f(i+1, j) == dp[i][j])
    {
        print(i+1, j);
        return;
    }
    if (f(i, j+1) == dp[i][j])
    {
        print(i, j+1);
        return;
    }
    cout << s[i] ;
    print(i+1, j+1);
}
int main()
{
    memset(dp, -1, sizeof dp);

    cin >> s >> t;

    f(0, 0);
    print(0, 0);
    cout << "\n";

    return 0;
}


Measured memory_bytes: 35968
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
	int  N;
	cin >> N;
	
	int sum=0;
	int L,l;
	for(int i=0; i<N; i++) {
		cin >> l;
		L = max(L,l);
		sum += l;
	}
	sum = sum - L;
	if ( L < sum ) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

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


void a(){
    int N,K; cin >> N >> K;

    cout << N - K + 1;

}

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

    int count = 0;
    for(int r = 0; r*R <= N; r++)
        for(int g = 0; r*R + g*G <= N; g++){
            int rg = r*R + g*G;
            if ((N - rg) % B == 0){
                count++;
            }
        }

    cout << count;

}

int main(){

    b();
    return 0;


}

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

typedef long long ll;

ll N;
ll Q,H,S,D;

int main()
{
    scanf("%lld%lld%lld%lld",&Q,&H,&S,&D);
    scanf("%lld",&N);
    S = min(S,min(Q * 4,H * 2));
    D = min(D,S * 2);
    printf("%lld\n",(N / 2) * D + (N % 2) * S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
vector<int> match = {-1,2,5,5,4,5,6,3,7,6};
void Main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> approval(m);//first:本数　second:数
    For(i,0,m) {
        cin >> approval[i].second;
        approval[i].first = match[approval[i].second];
    }
    sort(ALL(approval), [](auto const& l, auto const& r) {//本数は少なく、数は大きくしたい
       if(l.first!=r.first) return l.first < r.first;
       else return l.second > r.second;
    });
    for (int i=1;i<approval.size();) {
    // 本数が同じ要素を削除する
        if (approval[i].first == approval[i-1].first) {
            approval.erase(approval.begin()+i);
        }
        else {
            i++;
        }
    }
    sort(ALL(approval), [](auto const& l, auto const& r) {//数の大きい順に再ソート
       if(l.second != r.second) return l.second > r.second;
       else return l.first > r.first;
    });
    m = approval.size();
    vector<vector<string>> dp(m+1,vector<string> (n+1));
    For(j,0,n+1) dp[0][j]="";
    For(i,0,m+1) dp[i][0]="";
    For(i,0,m){
        For(j,1,n+1){
            if(j<approval[i].first) dp[i+1][j]=dp[i][j];
            else{
                string str1 = dp[i][j];
                string str2 = dp[i+1][j-approval[i].first];
                if(str2 == "" && j != approval[i].first) dp[i+1][j]=str1;
                else{
                    str2.push_back(char(approval[i].second + '0'));
                    if(str1.size()>str2.size()) dp[i+1][j]=str1;
                    else if(str1.size()<str2.size()) dp[i+1][j]=str2;
                    else if(str1>str2) dp[i+1][j]=str1;
                    else dp[i+1][j]=str2;
                }
            }
        }
    }
    cout << dp[m][n] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 99712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

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

  int trimn = S.size() - 7;
  for (int i = 0; i <= S.size() - trimn; ++i) {
    string ss = S;
    ss.erase(i, trimn);
    if (ss == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	char c;
	int ans=0;
	for(int i=0;i<3;i++)
	{
		cin>>c;
		if(c=='o') ans++;
	}
	int sum=700+ans*100;
	cout<<sum<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//const long long LIM = 1000000000000000000LL;// 10の18乗！！
int main()
{
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    ll LIM = 1e+18;
    rep(i, n)
    {
        if (LIM/ans < a[i])
        {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N,x;cin>>N>>x;
  static int a[100010];
  for(int t=1;t<=N;t++)cin>>a[t];

  int cont=0;
  for(int t=1;t<N;t++){
    int delta=max(0LL,a[t]+a[t+1]-x);
    a[t+1]-=delta;
    if(a[t+1]<0){
      a[t]+=a[t+1];
      a[t+1]=0;
    }
    cont+=delta;
  }

  cout<<cont<<endl;
  return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) for(int i = 0; i < n; ++i)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> point;

int readint() {
   int ret = 0, d;
    d = getchar();
    while (d < 48 || d > 57)
       	d = getchar();
    do {
        ret = ret * 10 + d - 48;
        d = getchar();
    } while (d > 47 && d < 58);
    return ret;
}

const int MAXN = 1e3 + 5;

int a[MAXN][MAXN], dp[MAXN][MAXN];

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

   int uk = 0;
   REP(i, n) REP(j, m) {
      char c; cin >> c;
      if(c == '#') {
         a[i][j] = 1;
         uk ++;
      }
   }

   dp[0][0] = 1;

   REP(i, n) REP(j, m) {
      if(!a[i][j]) {
         dp[i][j] = 0;
         continue;
      }

      if(i - 1 >= 0 && dp[i - 1][j]) dp[i][j] = 1;
      if(j - 1 >= 0 && dp[i][j - 1]) dp[i][j] = 1;
   }

   if(dp[n - 1][m - 1] && uk == n + m - 1) cout << "Possible";
   else cout << "Impossible";
}


Measured memory_bytes: 2304
"""
マスターオブ整数
"""
import fractions

N, X = map(int, input().split())
cities = list(map(int, input().split()))

dist = [abs(i - X) for i in cities]
division = dist[0]
for i in dist[1:]:
    division = fractions.gcd(division, i)

print(division)

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		temp += n % 10;
		n = n / 10;
		// temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}


int main() {
	int i, m, n, k, c = 0, sum = 0;
	c_p_c();
		// cout<<"Sd"<<endl;>
	cin>>n>>m;
	string s;
	cin>>s;
	// if(s[n]==)
	bool yep=false;
	for (int i = 0; i < s.size(); ++i)
	{
		/* code */
		if(s[i]=='-' and i==n)
			yep=true;
		if(s[i]=='-' and i!=n){
			yep=false;
			break;
		}

	}
	// cout<<sum<<endl;
	// cout<<(yep)?"Yes":"No"<<endl;
	if(yep)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;





	

}

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

using namespace std;

template <typename T>
class WeightedUnionFind {
 private:
  std::vector<int> parent;
  std::vector<T> weight;

 public:
  WeightedUnionFind(int n) : parent(n, -1), weight(n, 0) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    int rx = root(parent[x]);
    weight[x] += weight[parent[x]];
    return parent[x] = rx;
  }

  bool is_same(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -parent[root(x)]; }

  T diff(int x, int y) {
    root(x), root(y);
    return weight[y] - weight[x];
  }

  bool unite(int x, int y, T w) {
    int rx = root(x), ry = root(y);
    w += weight[x] - weight[y];
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry), w *= -1;
    weight[ry] = w;
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  WeightedUnionFind<int64_t> uf(N);
  for (int i = 0; i < M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    if (!uf.unite(l, r, d) && uf.diff(l, r) != d) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
const int N = 303;
int dp[N][N][N];
int n,m;
struct cond{
    int l,r, x;
};

vector<vector<cond> > vec(N);

bool check(int ind,int rd,int g ,int b) {
    for(int i = 0;i<vec[ind].size();i++) {
        int l = vec[ind][i].l, r = vec[ind][i].r, x = vec[ind][i].x;
        int cnt = (rd >= l && rd <= r) + (b >= l && b <= r) + (g >= l && g <= r);
        if(cnt != x)
            return false;
    }
    return true;
}

int solve(int r,int g,int b) {
    int ind = max(r,max(g,b));
    if(!check(ind,r,g,b))
        return 0;
    if(ind == n)
        return 1;
    if(dp[r][g][b] != -1)
        return dp[r][g][b];
    return dp[r][g][b] = ((solve(ind+1,g,b) + solve(r,ind+1,b)) % MOD + solve(r,g,ind+1) ) % MOD;
}


int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 0;i<m;i++) {
        int l,r,x;
        scanf("%d%d%d",&l,&r,&x);
        vec[r].push_back(cond{l,r,x});
    }
    memset(dp,-1,sizeof dp);
    printf("%d",solve(0,0,0));
    return 0;
}


Measured memory_bytes: 108928
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 666666666

vector<array<ll,2>>A[200005];
ll seg[800005][2];

void lazy(int c, int l, int r)
{
    seg[c][0]+=seg[c][1];
    if(l!=r)
    {
        seg[2*c][1]+=seg[c][1];
        seg[2*c+1][1]+=seg[c][1];
    }
    seg[c][1]=0;
}

void update(int c, int l, int r, int L, int R, ll val)
{
    lazy(c,l,r);
    if(l>r || r < L || l > R)return;
    if(l>=L && r<=R)
    {
        seg[c][1]+=val;
        lazy(c,l,r);
        return;
    }
    int m = (l+r)/2;
    update(2*c,l,m,L,R,val);
    update(2*c+1,m+1,r,L,R,val);
    seg[c][0]=max(seg[2*c][0],seg[2*c+1][0]);
}

ll get(int c, int l, int r, int L, int R)
{
    lazy(c,l,r);
    if(l>r || r < L || l > R)return -1e18;
    if(l>=L && r<=R)return seg[c][0];

    int m = (l+r)/2;
    ll ats = max(get(2*c,l,m,L,R), get(2*c+1,m+1,r,L,R));
    seg[c][0]=max(seg[2*c][0],seg[2*c+1][0]);
    return ats;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;

    while(m--)
    {
        ll L,R,val;
        cin>>L>>R>>val;
        A[L].push_back({val,L});
        A[R+1].push_back({-val,L});
    }

    ll ats = 0;

    for(int i=1; i<=n; i++) //lets choose which position in string should be '1'
    {
        for(auto&x : A[i])update(1,0,n,0,x[1]-1,x[0]);
        //^if some interval starts here we increase all previous positions [0,L-1] by its value
        //because i is in the interval
        //if some interval ends when we decrease all previous positions [0,L-1] by its value
        //because i is not in interval anymore
        ll cur = get(1,0,n,0,i-1); //we get maximum value of prefix [0,i-1] -
        //^its the best we can get with prefix[1...i] bits done
        ats=max(ats,cur);
        update(1,0,n,i,i,cur);//finally we add our current best for prefix[0,i] to the tree
        //now other queries can try extending this answer

        //its like brute-force where we would choose some j in range [0,i-1]
        //(0 meaning no bits on yet) to extend answer
        //yet segment tree saves us from N^2, and we can do this in N log N
    }

    cout<<ats;
}


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

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a <= 5)
        cout << 0 << ln;
    else if (6 <= a && a <= 12)
        cout << b / 2 << ln;
    else
        cout << b << ln;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int s, ans;

  scanf("%d", &s);

  ans = 0;
  while (s > 0) {
    if (s % 10 == 1) {
      ans++;
    }
    s = s / 10;
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
3
2 93 78
1 71 59
3 57 96

15 15 0
12 0  0
0  0  0
T*Nは間に合わないか

1 2 3 4 5 6 7
2 1 1 0 0 0 2
え、T*NlogNって間に合うの？全然ダメそうに見えるんだけど


N
 の総和は 
2
×
10
5
 を超えない
 
ほいきたーーーーー
やっぱ考え方あってたんや

あれ、WAとTLEだな・・・
箱の大きさ小さくしたらTLE消えたな、なんでだ。スタックオーバーフローするかな
そしてWAとれないなんだろう。何の漏れだろう

4
1 10 20
1 20 10
3 10 20
3 20 10

10 20 20 20
20 10 10 10
10 10 10 20
20 20 20 10

ああ、これ、
1
3
1 10 5
2 20 10
2 30 10

LL 0 1 2
   1 2 0
55になるべき

やっぱり都度いれ都度だししないとだめか
*/
int main(){
  ll T; cin>>T;
  rep(j, T){
    ll N,ans=0; cin>>N;
    vector<vector<ll>> LL(N+10, vector<ll>(0,0)), RR(N+10, vector<ll>(0,0));
    priority_queue<ll, vector<ll>, greater<ll>> LQ, RQ;
    rep(i, N){
      ll K,L,R; cin>>K>>L>>R;
      if(L>R) LL[K-1].push_back(L-R);
      else if(R>L && K<N) RR[K].push_back(R-L);
      ans += min(R,L);
    }

    rep(i,N){
      for(auto v: LL[i]) LQ.push(v);
      while(LQ.size()>i+1) LQ.pop();
    }
    rep(i,N){
      for(auto v: RR[N-1-i]) RQ.push(v);
      while(RQ.size()>i+1) RQ.pop();
    }
    while(!LQ.empty()){
      ans+=LQ.top();
      LQ.pop();
    }
    while(!RQ.empty()){
      ans+=RQ.top();
      RQ.pop();
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 19620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll MOD = 998244353;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    vector<P> p(n);
    for(int i = 0; i < n; i++)
    {
        p[i] = P(b[i], a[i]);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(int i = 0; i < n; i++)
    {
        if(a[i] > b[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    sort(p.begin(), p.end());
    for(int i = 0; i < n; i++)
    {
        b[i] = p[i].first;
        a[i] = p[i].second;
    }

    vector<set<int>> add(n);
    vector<int> dis(n);
    for(int i = 0; i < n; i++)
    {
        dis[i] = distance(b.begin(), lower_bound(b.begin(), b.end(), a[i]));
        add[dis[i]].insert(i);
    }
    set<int> s;
    for(int i = 0; i < n-2; i++)
    {
        if(a[i] <= b[i])
        {
            cout << "Yes" << endl;
            return 0;
        }
        s.insert(add[i].begin(), add[i].end());
        int cand = *s.rbegin();
        swap(a[i], a[cand]);
        s.erase(cand);
        add[dis[i]].erase(i);
        add[dis[i]].insert(cand);
        swap(dis[i], dis[cand]);
    }
    if(a[n-2] <= b[n-2] && a[n-1] <= b[n-1])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

#define min(x,y) x<y ? x:y

int k[1001];
int t[1001];
long long dp[1001][1001];

int main() {

	int n, m,i,j;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) scanf("%d", &k[i]);
	for (i = 0; i < m; i++) scanf("%d", &t[i]);

	memset(dp, 0x7f, sizeof(dp));
	dp[0][0] = 0;
	for (i = 0; i <= n; i++) {
		for (j = 0; j < m; j++) {
			dp[i+1][j + 1] = min(dp[i][j] + k[i] * t[j],dp[i+1][j+1]);
			dp[i][j + 1] = min(dp[i][j],dp[i][j+1]);
			
		}
	}
	
	printf("%lld\n", dp[n][m]);
	return 0;
}



Measured memory_bytes: 9692
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int d;
    cin>>d;
    cout<<"Christmas ";
    for(int i=0;i<25-d;i++)
    	cout<<"Eve ";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	long a,b,a1,a2,i,t;
	
	while(scanf("%ld %ld",&a,&b)!=EOF){
		if(a>b){
			t=a;
			a=b;
			b=t;
		}
		
		/*
		for(i=a;i>0;i--){
			if(a%i==0 && b%i==0){
				a1=i;
				break;
			}
			if(i==a)a/2+1;
			if(i==a/2)
		}
		*/
		
		a1=1;
		while(a%2==0 && b%2==0){
			a/=2;
			b/=2;
			a1*=2;
		}
		for(i=3;i<=a;i+=2){
			while(a%i==0 && b%i==0){
				a/=i;
				b/=i;
				a1*=i;
			}
		}
		
		
		//a2=a/a1*b;
		
		a2=a1*a*b;
		
		printf("%ld %ld\n",a1,a2);
		
		
		
	}
	
	
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

int comb(int n, int k) {
  int m = 1;
  if(n < 2 * k) { k = n - k; }
  FOR(i, 1, k + 1) { m = m * (n - i + 1) / i; }
  return m;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  vector<int> R(N + 1);
  R[0] = 0;
  for(int i = 0; i < N; i++) {
    R[i + 1] = R[i] + A[i];
  }
  map<int, int> M;
  REP(i, N + 1) { M[R[i]]++; }
  int ans = 0;
  for(auto x : M) {
    if(x.second > 1) { ans += comb(x.second, 2); }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15872
N, L = [int(i) for i in input().split()]

max_taste = L + N - 1
# おいしさの絶対値が最も小さいりんごを食べ、残りでアップルパイを作る
if max_taste <= 0:
    eat_taste = max_taste
elif L >= 0:
    eat_taste = L
else:
    eat_taste = 0
print((L + max_taste) * (max_taste - L + 1) // 2 - eat_taste)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int keta(ll num){
  for(int i = 1;i<10+1;i++){
    if(num/10 != 0){
      num = num/10;
    }
    else{
      return i;
    }
  }
}

int main() {
  ll N; cin >> N;
  int ans = INF;
  rep2(i, 1, sqrt(N)+1) {
    if (N % i == 0) {
    ll A = i, B = N / A;
    int n = max(keta(A), keta(B));
    ans = min(ans, n);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
X, N = map(int,input().split())
answer = 0
if N != 0:
  mapped_list = map(int,input().split())
  list = list(mapped_list)
  for i in range (N):
    if (X-i in list) == False:
      answer = X-i
      break
    elif (X+i in list) == False:
      answer = X+i
      break
else:
  answer =X

print(answer)
  

Measured memory_bytes: 9076
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    for(int i=0;i<n;i++) cin >> t[i];
    vector<ll> diff(n-1);
    for(int i=0;i<n-1;i++) diff[i] = t[i+1] - t[i];
    sort(t.begin(), t.end());
    int cnt = 0;
    for(int i=0;i<n;i++) {
        int sum=0, ini = t[i];
        int j;
        for(j=i+1;j<i+c&&j<n;j++) {
            if(t[j] - ini > k) break;
        }
        i = j-1;
        cnt++;
        //cout << i << " "<< j << " "<< cnt << endl;
    }
    cout << cnt << endl;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int n, k;
ll ans = 1;
vector<int> g[maxn];

void dfs(int u, int par, int col){
  int haveCol = k;

  ans = (ans * col) % mod;

  if (par == -1) --haveCol;
  else haveCol -= 2;

  haveCol = max(0, haveCol);

  for (int i = 0; i < g[u].size(); ++i){
    int v = g[u][i];
    if (v == par) continue;
    dfs(v, u, haveCol);
    --haveCol;
    haveCol = max(0, haveCol);
  }

}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  cin >> n >> k;

  for (int i = 1; i < n; ++i){
    int u, v; cin >> u >> v;
    g[u].push_back(v); g[v].push_back(u);
  }

  dfs(1, -1, k);
  cout << ans;
return 0;
}



Measured memory_bytes: 16028
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
l=lnii()

def eratosthenes(lim):
  num=[1 for i in range(lim)]
  for i in set(l):
    for j in range(i+i,lim,i):
      num[j]=0
  return num

lim=10**6+5
num=eratosthenes(lim)

count=Counter(l)

ans=0
for i in l:
  if num[i]==1 and count[i]==1:
    ans+=1

print(ans)

Measured memory_bytes: 166352
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout) 
using namespace std;

int abc[3];

int main(){
	//IO("input.txt", "output.txt");
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> abc[0] >> abc[1] >> abc[2];
	sort(abc, abc + 3);
	if(abc[0] == 5 && abc[1] == 5 && abc[2] == 7) cout << "YES\n";
	else cout << "NO\n";
 	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#define MaxN 20000+100
using namespace std;
int a[MaxN];
int main()
{
	string s;
	cin >>s;
	s[3]='8';
	cout << s;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    Factorial[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}


//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    vl c(n + 1,0);
    ll ans = 0;
    rep1(i, n){
        rep1(j, 1e7){
            if(i * j > n)break;
            ++c[i * j];
        }
        ans += c[i] * i;
    }
    pf(ans);
    return 0;
}



Measured memory_bytes: 81396
#include<stdio.h>
int main(){
    int a, b, i, j;
    for(;;){
        scanf("%d %d", &b, &a);
        if(a==0 && b==0) break;
        for(i=0;i<b;i++){
            for(j=0;j<a;j++)
                printf("#");
            printf("\n");
        }
    printf("\n");
    }
    return 0;
}


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

static const int MMAX = 20;   //N中硬币的面值
static const int NMAX = 50000;   //金额M的最优解
static const int INFITY = (1 << 20);//设置一个无限大的值，方便下面的初始化


int dp[MMAX + 1][NMAX + 1] = { 0 };//这里的数组大小应该为
int C[25];
void solve(int n, int m)
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			if (j <C[i])   dp[i][j] = dp[i - 1][j]; //当金市的值小于硬币的面值时，则此时只能不选次硬市
			else           dp[i][j] = min(dp[i - 1][j], dp[i][j - C[i]] + 1); //“使用 第i种硬币”和“不使用第i种硬市”
		}

	cout << dp[n][m] << endl;  //打印最优解
}
int main(void)
{
	int n, m;
	cin >> m >> n;
		for (int i = 0; i <= m; i++) dp[0][i] = INFITY; //初始化
	for (int i = 0; i <= n; i++)     dp[i][0] = 0;     //初始化


	for (int i = 1; i <= n; i++)
		cin >> C[i];     //输入n个硬币的面值

	solve(n, m);//动态规划求解

	return 0;
}


Measured memory_bytes: 7184
n, m = map(int, (input().split()))

chk = [-1] * n
if n == 1:
    ans = [0]
else:
    ans = [1] + [0] * (n - 1)

for i in range(m):
    s, c = map(int, (input().split()))
    if (chk[s - 1] not in (-1, c)) or (n >= 2 and s == 1 and c == 0):
        print(-1)
        exit()
    chk[s - 1] = ans[s - 1] = c

print(*ans, sep="")

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

int main(){
    string s;
    cin >> s;
    string ans = "";
    if(s.size() == 1){
        cout << 0 << endl;
    } else {
        if(s.at(0) == '0'){
            for(int i = 0; i < s.size(); i++){
                if(i % 2 == 0){
                    ans += "0";
                } else {
                    ans += "1";
                }
            }
        } else {
            for(int i = 0; i < s.size(); i++){
                if(i % 2 == 0){
                    ans += "1";
                } else {
                    ans += "0";
                }
            }
        }
        int count = 0;
        for(int i = 0; i < s.size(); i++){
            if(s.at(i) != ans.at(i)){
                count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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 all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    ll k;cin>>k;
    ll q=k/50;ll r=k%50;
    cout<<50<<endl;
    rep(i,r)cout<<q-r+100<<" ";
    rep2(i,r,49)cout<<q-r+49<<" ";
    cout<<q-r+49<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n,m;
    string s,t;
    cin >> n >> m>> s>>t;
    int l = n*m/__gcd(n,m);
    int a = l/m;
    int b = l/n;
    rep(i,n/a+1) {
        if(s[i*a]!=t[i*b]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;

    return 0;
}



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

int main(void){
    int n;
    cin >> n;
    
    vector<int> l(n);
    rep(i, n){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    
    int sum = 0;
    string s = "Yes";
    rep(i, n-1){
        sum += l.at(i);
    }
    
    if(l.at(n-1) >= sum) s = "No";
    
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,K;cin>> N >> K;
    string S;cin >> S;
    vector<int> nums;
    int now=1;
    int cnt=0;
    for(int i=0;i<N;i++){
        if(S[i]-'0'==now)cnt++;
        else{
            nums.push_back(cnt);
            now=1-now;
            cnt=1;
        }
    }
    nums.push_back(cnt);
    if(now==0)nums.push_back(0);

    int left=0,right=0,res=0,tmp=0;
    for(int i=0;i<nums.size();i+=2){
        int nleft = i,nright=min(i+2*K+1,(int)nums.size());
        while(left<nleft){
            tmp-=nums[left];
            left++;
        }
        while(right<nright){
            tmp+=nums[right];
            right++;
        }
        res = max(res,tmp);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1020
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int a[55][55];
int main()
{
	string s;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		for(int j=1;j<=m;j++)
		{
			if(s[j-1]=='.') continue;
			a[i][j]=-1;
			for(int k=i-1;k<=i+1;k++)
			for(int l=j-1;l<=j+1;l++)
			{
				if(a[k][l]==-1) continue;
				a[k][l]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		if(a[i][j]==-1) printf("#");
		else printf("%d",a[i][j]);
		printf("\n");
	}
	return 0;
}

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

int main() {
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<int> p(a);
  vector<int> q(b);
  vector<int> r(c);
  for (int i=0;i<a;++i) {
    cin>>p[i];
  }
  for (int i=0;i<b;++i) {
    cin>>q[i];
  }
  for (int i=0;i<c;++i) {
    cin>>r[i];
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  int ooo=min(c,(x+y));
  vector<int> zz(x+y+ooo);
  for (int i=0;i<x;++i) {
    zz[i]=p[i];
  }
  for (int i=0;i<y;++i) {
    zz[i+x]=q[i];
  }
  for (int i=0;i<ooo;++i) {
    zz[i+x+y]=r[i];
  }
  sort(zz.begin(), zz.end());
  reverse(zz.begin(), zz.end());
  long long int ans=0;
  for (int j=0;j<(x+y);++j) {
    ans+=zz[j];
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
struct data_t
{
    long price;
    long limit;
    bool operator<(const data_t &right) const
    {
        //return price == right.price ? limit < right.limit : price < right.price;
        return price < right.price;
    }
};

int main()
{
    int N, M;
    long answer = 0, cnt = 0;
    ;
    cin >> N >> M;
    vector<data_t> data_array(N);

    for (int i = 0; i < N; i++)
    {
        cin >> data_array[i].price >> data_array[i].limit;
    }

    sort(data_array.begin(), data_array.end());
    for (int i = 0; i < N; i++)
    {
        while (data_array[i].limit > 0)
        {
            answer += data_array[i].price;
            cnt++;
            data_array[i].limit--;
            if (cnt == M)
            {
                cout << answer << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n, k, cnt=0; cin >> n >> k;
    REP(i, n){
        int h; cin >> h;
        if(h >= k) ++cnt;
    }
    cout << cnt << "\n";
    return 0;
}

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

using namespace std;

// 素数判定
bool isPrimeNumber(int64_t number) {
    if (number == 1) return false;
    bool isPrime = true;
    for (int i = 2; i <= sqrt(number); i++) {
        if (number % i == 0) isPrime = false;
    }
    return isPrime;
}

int main() {
    int64_t N;
    cin >> N;

    vector<int64_t> x;
    for (int i = 0; i < N; i++) {
        int64_t tmpX;
        cin >> tmpX;
        x.push_back(tmpX);
    }

    int64_t primeNumberCount = 0;
    for (int i = 0; i < N; i++) {
        if (isPrimeNumber(x.at(i))) {
            primeNumberCount++;
        }
    }

    cout << primeNumberCount << endl;

    return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

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

	auto h = K / 2;

	cout << (K - h) * h << endl;

	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int costmin(int n,int h[]){
	int *dp=new int[n+1];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
 	for(int i=2;i<n;i++){
    	dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
 	}
   return dp[n-1];
}
int main(){
 	fastio();
	int n;cin>>n;
	int a[n];
	for(int&x:a) cin>>x;
	int ans=costmin(n,a);
	cout<<ans<<endl;
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int s=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(i!=j)s+=(a[i]*a[j]);
        }
    }
    cout<<s<<'\n';
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int n, a[100];
	int ans = 0;

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 0; i < n; i++){
		int minj = i;
		for (int j = i; j < n; j++){
			if (a[j] < a[minj])
				minj = j;
		}
		swap(a[i], a[minj]);
		if(i!=minj) ans++;
	}

	for (int i = 0; i < n; i++){
		cout << a[i];
		if (i < n - 1) cout << " ";
		else cout << endl;
	}
	cout << ans << endl;

	return 0;
}



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

int main(){
    int N,ans=0;
    bool flag = false;
    cin>>N;
    vector<int> a(N);
    
    for (int i=0;i<N;i++){
        cin>>a.at(i);
    }
    
    for (int i=0;i<N;i++){
        for (int j=1;i<N;i++){
            if(a.at(i)!=j){
                ++ans;
            }else if(a.at(i)==j){
                flag = true;
                ++j;
            }
        }
    }
    if(flag){
        cout<<ans<<endl;
    }else{
        cout<<"-1"<<endl;
    }
}


Measured memory_bytes: 1024