akhauriyash/Code-Regression huggingface dataset:
//Author: ZindagiMeBasAishHiChahiye
//WA/TLE
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        7340033
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  400005
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ll          long long
// ll po(ll a,ll b,ll m){
// 	a%=m;
// 	if(b==0) return 1;
// 	if(b%2) return (a*(po((a*a)%m,b/2,m)%m)%m)%m;
// 	return po((a*a)%m,b/2,m)%m;
// }

void solve(){
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll z=x/d;
	if(z>k){
		cout<<x-d*k<<endl;
		return;
	}
	k-=z;
	x-=z*d;
	// cout<<k<<x;
	if(k%2){
		cout<<abs(x-d)<<endl;
	}
	else
		cout<<x<<endl;

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin>>TESTS;
	while(TESTS--){
		solve();

	}
	return 0;
}

Measured memory_bytes: 3560
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e9;

int main(){
  int n,l;
  cin >> n >> l;
  
  int s = 0;

  int mi = 100000;

  REP(i,n){
    s += l+i;
    if (abs(l+i) < abs(mi)) mi = l+i; 
  }

  cout << s - mi << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll a;
    string b;
    cin >> a >> b;

    ll y = 100 * (b[0] - '0') + 10 * (b[2] - '0') + (b[3] - '0');
    ll ans = a * y;

    ans /= 100;

    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>

int pow2(int N)
{
    int r = 1;
    for(int i=0; i<N; i++)
        r *= 2;
    return r;
}

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int k[M];
    int s[M][N];
    int p[M];
    for(int i=0; i<M; i++){
        scanf(" %d", &k[i]);
        for(int j=0; j<k[i]; j++){
            scanf(" %d", &s[i][j]);
        }
    }
    for(int i=0; i<M; i++)
        scanf(" %d", &p[i]);
    
    bool on[10];
    int count = 0;
    int max_loop = pow2(N);
    for(int loop=0; loop<max_loop; loop++){
        int cmp = 1;
        for(int i=0; i<10; i++){
            on[i] = loop & cmp;
            //printf("%d", on[i]);
            cmp *= 2;
        }
        //printf("\n");
        bool flag = true;
        for(int i=0; i<M; i++){
            int num = 0;
            for(int j=0; j<k[i]; j++){
                if(on[s[i][j]-1] == true) num++;
            }
            if(num % 2 != p[i]){
                flag = false;
                break;
            }
        }
        if(flag == true) count++;
    }
    printf("%d\n", count);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

struct edge{
    int to, id;
};

vector<vector<edge>> g;
vector<int> ans;

void dfs(int v, int from = -1, int c = -1) {
    int k = 1;
    rep(i, 0, g[v].size()) {
        int nv = g[v][i].to;
        int e = g[v][i].id;
        if (nv == from) continue;
        if (k == c) k++;
        ans[e] = k;
        k++;
        dfs(nv, v, ans[e]);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n);
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back((edge){b, i});
        g[b].push_back((edge){a, i});
    }
    dfs(0);
    int mx = 0;
    rep(i, 0, n) mx = max(mx, (int)g[i].size());
    cout << mx << endl;
    rep(i, 0, n - 1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 8320
#include <cstdio>

const int MAXN = 200000 + 10;

int n;
int a[MAXN];

int main() {
	int i, j = 0, k;
	
	scanf("%d", &n);
	for(i=1; i<=n; i++) {
		scanf("%d", &a[i]);
		if(!j and a[i] == 1)
			j = i;
	}
	
	if(!j) {
		printf("-1\n");
		return 0;
	}
	k = 1;
	while(true) {
		while(j <= n and a[j] ^ (k + 1))
			j++;
		if(j <= n)
			k++;
		else {
			printf("%d\n", n - k);
			return 0;
		}
	}
}

Measured memory_bytes: 896
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

vll three ;
string s ;
ll mx = 0 ;

ll DFS(ll d){
	if(d==mx) return three.at(d-1) ;
	if(d==2){
		if(s.at(1)=='1') return 5 ;
		else return (s.at(0)=='1'?3:1) ;
	}
	if(s.at(d-1)=='1') return (three.at(d-2)+2*DFS(d-1))%mod ;
	else return DFS(d-1) ;
}

int main(){
	cin >> s ;
	ll n = s.size() ;
	three.emplace_back(3) ;
	for(int i=1;i<n;i++) three.emplace_back(three.at(three.size()-1)*3%mod) ;
	ll ans = 0 ;
	for(int i=n-1;i>=0;i--){
		if(s.at(i)=='1') mx++ ;
		else break ;
	}
	reverse(s.begin(),s.end()) ;
	cout << DFS(n) << endl ;
}



Measured memory_bytes: 2932
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int N,M;cin>>N>>M;
    vl info(3,-1);
    bool check=0;
    rep(i,M){
        int s,c;cin>>s>>c;
        s--;
        if(info[s]==-1 or info[s]==c)info[s]=c;
        else check=1;
    }
    if(N==1 and info[0]==-1)cout<<0<<endl;
    else if(check)cout<<-1<<endl;
    else if(N!=1 and info[0]==0)cout<<-1<<endl;
    else{
        rep(i,N){
            if(!i and info[i]==-1)cout<<1;
            else if(info[i]==-1)cout<<0;
            else cout<<info[i];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int isSorted(int,int,int);
int main(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(isSorted(a,b,c)==1) printf("Yes\n");
  else printf("No\n");
  return 0;
}
int isSorted(int a,int b,int c)
{
  if(a<b&&b<c) return 1;
  else return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> A(N), count(N, 0);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
		A[i]--;
		count[A[i]]++;
	}
	int all = 0;
	for(i = 0; i < N; i++){
		all += (count[i] * (count[i] - 1)) / 2;
	}
//	printf("all = %lld\n", all);
	for(i = 0; i < N; i++){
		int x = count[A[i]];
		printf("%lld\n", all - x + 1);
	}
	return 0;
}

Measured memory_bytes: 5760
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	while (N) {
		M = INT_MAX;
		for (int i = 0; i <= 100; i++) {
			for (int j = 0; j < 1000; j++) {
				if (N - i*i*i - j*j >= 0) {
					M = min(M, i + j + N - i*i*i - j*j);
				}
			}
		}
		cout << M << endl;
		cin >> N;
	}
	return 0;
}

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

int main() {
  string n;
  cin >> n;
  int a = 0;
  for(int i = 0; i < n.size(); i++) {
    a += stoi(n.substr(i, 1));
  }
  cout << ((stoi(n) % a == 0) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define mp make_pair
ll check (ll n,ll m,ll i,ll j)
{
	if(i>=0 && i<n && j<m && j>=0)
	   return 1;
	else
	 return 0;   
}
int main()
{
	ll t;
	t = 1;
	while(t--)
	{
		ll i,n;
		cin>>n;
		ll f = n/1000;
		ll ans = 0;
		if(n%1000!=0)
		   ans += (f+1)*1000 - n;
		cout<<ans;   
	}
	return 0;
} 

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define MOD 1000000007



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

  string ans = "";
  while(n > 0) {
    int x = (n - 1) % 26;
    ans += 'a' + x;
    n = (n - 1) / 26;
  }

  rep(i, ans.length()) {
    cout << ans[ans.length() - i - 1];
  }

}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int INF = 1001001001;

int main() {
    ll l, r;
    cin >> l >> r;
    r = min(l+2019, r);
    ll ans = INF;
    for (ll i = l; i <= r; i++) {
        for (ll j = i+1; j <= r; j++) {
            //i = i%2019;
            //j = j%2019;
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		long sum = a[0];
		int ans = n;
		int idx = 0;
		for (int i = 1; i < n; i++) {
			if (sum * 2 >= a[i]) {
				sum += a[i];
			} else {
				sum += a[i];
				idx = i;
			}
		}
		System.out.println(ans - idx);
	}
}

Measured memory_bytes: 50228
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int ans = 0;
    int g = 0;
    rep(i,0,s.size()){
        if(s[i]=='g' && g>0){
            g--;
            ans++;
        } else if(s[i]=='g'){
            g++;
        } else if(s[i]=='p' && g>0){
            g--;
        } else{
            g++;
            ans--;
        }
    }
    cout << ans << endl;
} 

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){

  int i,x[3],max=0,s=0;
  for(i=0;i<3;i++){
  scanf("%d",&x[i]);
  if(max<=x[i]){
    max=x[i];
    s=i; //maxの時のi
   }
  }
  printf("%d",x[0]+x[1]+x[2]-x[s]);
}

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

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int a, b, x;
  cout << setprecision(10) << fixed;
  cin >> a >> b >> x;
  if (2 * x >= a * a * b) {
    cout << 90.0 - atan(1.0 * a * a * a / (2.0 * (a * a * b - x))) / M_PI * 180 << endl;
  } else {
    cout << atan(1.0 * a * b * b / (2.0 * x)) / M_PI * 180 << endl;
  }
}

Measured memory_bytes: 256
from math import ceil, log2
N, K = map(int, input().split())

max_t = int(ceil(log2(K)))

cnt = 0
for n in range(1, N + 1):
    t = max(int(ceil(log2(K / n))), 0)
    cnt += 2 ** (max_t - t)

print (cnt / 2 ** max_t / N)


Measured memory_bytes: 3060
S = input()
SS = list(S)
T = input()
TT = list(T)
X = len(SS) -len(TT)
mini = 1000
for i in range(X+1):
  count = 0
  for j in range(len(TT)):
    if SS[j + i] != TT[j]:
      count +=1
  if count < mini:
    mini = count
print(mini)

Measured memory_bytes: 9124
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, m = LI()
cnt = Counter(LI())
L = []
for k, v in cnt.items():
    L += [(k, v)]

for b, c in LIR(m):
    L += [(c, b)]


ans = 0
L.sort(reverse=True)
ret = 0
for k, v in L:
    if ret + v >= n:
        ans += (n - ret) * k
        break
    else:
        ans += v * k
        ret += v


print(ans)



Measured memory_bytes: 83896
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n, k;
    cin>>n>>k;
    cout<<max(n - k + 1, 0)<<endl;
}

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

int main() {
  string x;
  cin >> x;
  stack<char> s;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'S') {
      s.push(x[i]);
    }
    else if (x[i] == 'T') {
      if (s.empty()) {
        s.push(x[i]);
      }
      else if (s.top() == 'S') {
        s.pop();
      }
      else {
        s.push(x[i]);
      }
    }
  }
  int ans = s.size();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INF = 1LL << 60;

int main(){
    int A,B,M; cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    int x,y,c;
    long long  ans = INF;

    for(int i=0;i<A;i++) cin >> a[i];
    for(int i=0;i<B;i++) cin >> b[i];
    for(int i=0;i<M;i++){
        cin >> x >> y >> c;
        x--; y--;
        if(ans > a[x]+b[y]-c) ans = a[x]+b[y]-c;
    }

    sort(a.begin(),a.end()) ;
    sort(b.begin(),b.end()) ;
    int nodis = a[0]+b[0];
    if(nodis < ans) ans = nodis;
    cout << ans << endl;
}


Measured memory_bytes: 1024
/*input
41 59 31
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	// cin >> t;
	while(t--) {
		run();
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
int main(){
    int n; cin >> n;
    int w[n]; cinf(n,w);
    int ans=1000000;
    for(int i=0;i<n-1;i++){
        int s1=0; int s2=0;
        for(int j=0;j<=i;j++){
            s1+=w[j];
        }
        for(int j=i+1;j<n;j++){
            s2+=w[j];
        }
        ans=min(ans,abs(s1-s2));
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    ll n,m,k;
    ll ans = -1;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    
    vector<ll> r_a(n+1);
    vector<ll> r_b(m+1);
    r_a[0] == 0;
    r_b[0] == 0;
    
    for(int i=1; i<n+1; i++){
        r_a[i] = r_a[i-1] + a[i-1];
    }
    for(int i=1; i<m+1; i++){
        r_b[i] = r_b[i-1] + b[i-1];
    }

    rep(i,n+1){
        ll time = r_a[i];
        if(time > k) continue;
        ll hon = upper_bound(r_b.begin(),r_b.end(),k-time) - r_b.begin()-1;
        ans = max(ans,hon+i);
    }
    cout << ans << endl;

}

Measured memory_bytes: 9496
#include<bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
#define coutd if(DEBUG) cout 
#define ff first
#define ss second
#define debug(x) cout << "> x:" << x << endl;
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(){
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<double> vs(n);
	for(int i=0; i<n; ++i) cin >> vs[i];
	sort(all(vs));
	double ans=vs[0];
	for(int i=0; i<n; ++i)
		ans = (ans+vs[i])/2.0;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 110;
string s;
int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		char vis;
		cin >> s;
		int k;
		cin >> k;
		vis = s[k-1];
		for (int i = 0; i < s.size(); i++) {
			if (s[i] != vis)
				s[i] = '*';
		}
		cout << s << endl;
	}

	//system("pause");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
const ll INF = (1ll)<<60;
const int MOD = 998244353;

int n;
ll a[maxN];
ll f[maxN];
ll g[maxN];

int main()
{

	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	f[2] = a[1];  //没有操作 
	g[2] = -a[1]; //操作了 
	for(int i=3;i<=n;i++)
	{
		f[i] = max(f[i-1]+a[i-1],g[i-1]-a[i-1]);
		g[i] = max(f[i-1]-a[i-1],g[i-1]+a[i-1]); 
	}
	ll ans = max(f[n]+a[n],g[n]-a[n]);
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int N, M;
    cin >> N >> M;

    int dp[N][N];
    int v[N][N];
    const int INF = 1000000005;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            dp[i][j] = INF;
            v[i][j] = INF;
        }
        dp[i][i] = 0;
        v[i][i] = 0;
    }

    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dp[a][b] = c;
        dp[b][a] = c;
        v[a][b] = c;
        v[b][a] = c;
    }

    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(v[i][j] == INF) continue;
            if(v[i][j] != dp[i][j]) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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


///////////////////////////////////////////////////
//bに9.79を入れると9.789999999となっておかしくなる
///////////////////////////////////////////////////
int main() {
    ll a;
    long double b;
    cin>>a>>b;
    //このようにして回避
    ll intb = (int)(b*100+.1) ;
    cout<< a*intb/100<<endl;


    return 0;
}



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

typedef long long ll;

const int MAX_M = 100005;
const int MAX_N = 100005;
int a[MAX_N];
int m[2*MAX_M];
ll additional_push[MAX_M];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int ai;
    cin >> ai;
    a[i] = ai-1;
  }
  // count separation that satisfies a_i < x < a_i+1
  ll count = 0; // count when x = 1
  for (int i = 1; i < N; i++) {
    int begin = a[i-1] + 1;
    int end = a[i];
    if (begin > end) {
      end += M;
    }
    m[begin]++;
    m[end]--;

    if (a[i-1] < a[i]) {
      count += a[i] - a[i-1] ;
    }
    else {
      count += a[i] + 1;
    }

    additional_push[a[i]] +=  (M + a[i] - a[i-1]) % M - 1;
  }

  for (int i = 1; i < 2*M; i++) {
    m[i] += m[i-1];
    if (i >= M) {
      m[i-M] += m[i];
    }
  }
  // for (int i = 0; i < M; i++) {
  //   cout << m[i] << " ";
  // }
  // cout << endl;

  // cout << "x = 0: " << count << endl;
  ll ans = count;
  for (int i = 1; i < M; i++) {
    ll cx = count - m[i-1] + additional_push[i-1];
    // cout << "x = " << i << ": " << cx << endl;
    ans = min(ans, cx);
    count = cx;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,m;
  cin >> n >> m;
  vec a(n);
  ll sum=0;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  if(4*m*a[m-1]<sum) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

int main() {
  int n;
  string w;
  char c;
  set<string> s;
  cin >> n;
  cin >> w;
  c = w[w.length() - 1];
  s.insert(w);

  REP(i, n - 1) {
    cin >> w;
    if (s.find(w) != s.end() || c != w[0]) {
      cout << "No" << endl;
      return 0;
    }
    c = w[w.length() - 1];
    s.insert(w);
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

int main() {
    int N,M,t;
    ll mod=1e9+7;
    cin >> N >> M;
    Vi vs(N),vt(M);
    vector<Vi> a(N,Vi(M,0));
    REP(i,N) {
        cin >> vs[i];
    }
    REP(i,M) {
        cin >> t;
        vt[i] = t;
        REP(j,N) {
            if (vs[j] == t) {
                a[j][i] = 1;
            }
        }
    }
    
    ll ans;
    vector<Vl> dp(N+1, Vl(M+1,0));
    vector<Vl> sum(N+1, Vl(M+1,0));
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < M; ++j){
            if (a[i][j] == 0) dp[i+1][j+1] = 0;
            else dp[i+1][j+1] = (sum[i][j] + 1)%mod;
            sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + mod + dp[i+1][j+1])%mod;
            }
    }
    ans = (sum[N][M] + 1)%mod;
    cout << ans << endl;
}

Measured memory_bytes: 78720
#include<iostream>
#include<cmath>
using namespace std;
const int maxn=1e5+5;
int h[maxn],dp[maxn];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		for(int i=1;i<=n;i++)
		  scanf("%d",&h[i]);
		dp[0]=0,dp[1]=0,h[0]=h[1];
		for(int i=2;i<=n;i++)
		{
			dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
		}
		cout<<dp[n]<<endl;
	}
}

Measured memory_bytes: 4432
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val dList = readIntegerList()
    val dMap = elementCountMap(dList)
    
    val m = readInteger()
    val tList = readIntegerList()
    val tMap = elementCountMap(tList)
    
    for (e in tMap) {
        val dCount = dMap.getOrDefault(e.key, 0)
        if (dCount < e.value) {
            out.print("NO")
            return
        }
    }
    out.println("YES")
}

/** O(n) */
fun <T>elementCountMap(list: List<T>): Map<T, Int> {
    val countMap = mutableMapOf<T, Int>()
    for (e in list) {
        countMap[e] = (countMap[e] ?: 0) + 1
    }
    return countMap
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 88284
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	
	ll n,k,memo = 0,ans = 0;
	string s;
	
	ll cnt[200001] = {},cnt_index = 0;
	ll cnt2[200001]= {},l = 0,r = 0;
	
	cin >> n >> k;
	cin >> s;
	
	cnt[cnt_index]++;
	
	rep(i,1,s.size()){
		if(s[i-1] != s[i]) cnt_index++;
		cnt[cnt_index]++;
	}
	
	
	
	cnt2[0] = cnt[0];
	
	rep(i,1,cnt_index+1){
		cnt2[i] = cnt2[i-1] + cnt[i];
		//cout << cnt2[i] << endl;
	}
	
	
	
	if(s[0] == '0'){
		ans = cnt2[min(cnt_index,2*k-1)];
		l = -1;
		r = min(cnt_index,2*k-1);
		
		ans = max(ans,cnt2[min(cnt_index,2*k+1)] - cnt2[0]);
		r = min(cnt_index,2*k+1);
		l = 0;
		
		while(1){
			if(r >= cnt_index) break;
			else if(r+1 == cnt_index){
				ans = max(ans,cnt2[r+1] - cnt2[l+2]);
				break;
			}
			else{
				ans = max(ans,cnt2[r+2] - cnt2[min(l+2,cnt_index)]);
				r += 2;
				l += 2;
			}
		}
	}
	else{
		ans = cnt2[min(cnt_index,2*k)];
		//cout << cnt[min(cnt_index,2*k)] << endl;
		l = -1;
		r = min(cnt_index,2*k);
		
		
		while(1){
			//cout << l << " " << r   << endl;
			if(r >= cnt_index) break;
			else if(r+1 == cnt_index){
				//cout <<  cnt2[r+1] - cnt[l+2]  << " " << cnt2[r+1] << " " << cnt2[l+2]<< endl;
				ans = max(ans,cnt2[r+1] - cnt2[l+2]);
				break;
			}
			else{
				//cout <<  cnt2[r+2] - cnt2[l+2] << " " << cnt2[r+2] << " " << cnt2[l+2] << endl;
				ans = max(ans,cnt2[r+2] - cnt2[l+2]);
				r += 2;
				l += 2;
			}
			
		}
	}
	
	if(s.size() == 1 && k >= 1) ans = 1;
	else if(cnt_index == 0) ans = (ll)s.size();
	
	cout << ans << endl;
	
	return 0;

}

Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;

int main()
{
    ll n,pos=1,tem,flag,mx=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>tem;
        if(abs(tem)>mx)
        {
            mx=abs(tem);
            pos=i;
            if(tem>0)
            {
                flag=1;
            }
            else
            {
                flag=0;
            }
        }
    }
    cout<<2*n-2<<endl;
    for(int i=1; i<=n; i++)
    {
        if(i!=pos)
        {
            cout<<pos<<" "<<i<<endl;
        }
    }
    if(flag)
    {
        for(int i=2; i<=n; i++)
        {
            cout<<i-1<<" "<<i<<endl;
        }
    }
    else
    {
        for(int i=n; i>1; i--)
        {
            cout<<i<<" "<<i-1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    int a,b;
    std::cin >> a>>b;
    std::cout << ceil((b-1)/double(a-1)) << std::endl;
}

Measured memory_bytes: 256
console.log((args=>{
  const [[N],A] = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0) );
  A.sort((a,b)=>a-b);
  let sum = A[0], n = 0;
  for ( let i = 1; i < N; i++ ) {
    if ( sum * 2 >= A[i] ) n++;
    else n = 0;
    if ( sum + A[i] >= 1e9 ) return `${n+N-i}`;
    sum = sum + A[i];
  }
  return `${n+1}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 41048
#include<bits/stdc++.h>
using namespace std;
/*
#ifndef ONLINE_JUDGE
    #define cin f
    #define cout g
    ifstream cin("a.in");
    ofstream cout("a.out");
#endif
*/
int n;
long long v[1<<13],dp[2][3002][3002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;++i) cin>>v[i];
    for(int i=n;i>0;--i)
        for(int j=i;j<=n;++j)
        {
            dp[0][i][j]=max(dp[1][i+1][j]+v[i],dp[1][i][j-1]+v[j]);
            dp[1][i][j]=min(dp[0][i+1][j]-v[i],dp[0][i][j-1]-v[j]);
        }
    cout<<dp[0][1][n];
    return 0;
}


Measured memory_bytes: 139776
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
bool Query(int64 t) {
    putchar('?');space;out(t);enter;fflush(stdout);
    char s[5];scanf("%s",s);
    return s[0] == 'Y';
}
void Solve() {
    int64 v = 1;
    bool f = 0;
    for(int i = 1 ; i <= 10 ; ++i) {
        if(!Query(v)) {f = 1;v /= 10;break;}
        v *= 10;
    }
    if(!f) {
        v = 1;
        for(int i = 1 ; i <= 10 ; ++i) {
            if(Query(v * 10 - 1)) {putchar('!');space;out(v);enter;return;}
            v *= 10;
        }
    }
    int64 L = v,R = min(v * 10 - 1,(int64)1e9);
    while(L < R) {
        int64 mid = (L + R + 1) >> 1;
        if(!Query(mid * 10)) L = mid;
        else R = mid - 1;
    }
    putchar('!');space;out(L + 1);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

//a^n (mod m)
const long long mod = 1e9+7;
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

const int MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

    ll n,k;
    cin>>n>>k;
    COMinit();
    if(n>k){
        cout << 0 << endl;
        return 0;
    }
    cout << fac[k]*finv[k-n]%mod <<endl;
    

}


Measured memory_bytes: 15164
#include<stdio.h>
#include<set>
using namespace std;

int par[100000 * 2];

void init(int n) {
    for(int i = 0; i < n; i++) par[i] = i;
}

int root(int x) {
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
}

void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
}

bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    init(n * 2);

    for(int i = 0; i < m; i++) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        x--;y--;

        if(z%2 == 0) {
            unite(x, y);
            unite(x + n, y + n);
        } else {
            unite(x, y + n);
            unite(x + n, y);
        }
    }

    set<int> s;
    for(int i = 0; i < n * 2; i++) s.insert(root(i));

    printf("%d\n", s.size() / 2);
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005, LG = 19;
int n, k, p[MX], mn[LG][MX], mx[LG][MX], ft[MX];
set<ii> st;

void update (int i, int k) {
	while (i < MX) {
		ft[i] += k;
		i += i & -i;
	}
}

int query (int i) {
	int s = 0;
	while (i) {
		s += ft[i];
		i -= i & -i;
	}
	return s;
}

int query (int i, int j) {
	if (i > j) return 0;
	return query(j) - query(i - 1);
}

ii rmq (int i, int j) {
	if (i > j) return {MX, -MX}; 
	int k = log2(j - i + 1);
	return {
		min(mn[k][i], mn[k][j - (1 << k) + 1]),
		max(mx[k][i], mx[k][j - (1 << k) + 1])
	};
}

bool isLower (int l, int m, int r) {
	return query(l + 1, m) || p[m] > rmq(m + 1, r).fi;
}

bool isUpper (int l, int m, int r) {
	return rmq(l, m - 1).se > p[m] || query(m + 1, r); 
}

void find (int l, int r) {
	int i = l, j = r, rep = 20;
	ii res;

	while (rep--) {
		int m = (i + j) / 2;
		if (isLower(l, m, r)) j = m;
		else i = m;
	}

	if (!isLower(l, j, r)) {
		st.emplace(0, n - 1);
		return;
	}
	res.fi = j;
	
	i = l, j = r, rep = 20;

	while (rep--) {
		int m = (i + j + 1) / 2;
		if (isUpper(l, m, r)) i = m;
		else j = m;
	}

	res.se = i;
	st.emplace(res);
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;
	forn (i, n) {
		cin >> p[i];
		mx[0][i] = p[i];
		mn[0][i] = p[i];
		if (i && p[i - 1] > p[i]) update(i, 1);
	}

	for (int j = 1; (1 << j) <= n; j++)
		for (int i = 0; i + (1 << j) - 1 < n; i++) {
			mn[j][i] = min(mn[j - 1][i], mn[j - 1][i + (1 << j - 1)]);
			mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << j - 1)]);
		}

	for (int i = 0; i + k - 1 < n; i++)
		find(i, i + k - 1);
	cout << st.size() << endl;

	return 0;
}


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

using namespace std;

int main() {

	int a,b,t;
	cin >> a >> b >> t;

	int n = 1;
	int total = 0;
	while (a*n < t + 0.5) {
		total += b;
		n++;
	}
	cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
vector<ll> V;
int pre[maxn];
int main() {
	int a;cin>>a;
	cout<<a*(1+a*(1+a))<<endl;    
    return 0;
}

Measured memory_bytes: 3624
n, m, q = map(int, input().split())
ques = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    ques.append((a, b, c, d))

def score(List):
    res = 0
    for a, b, c, d in ques:
        if List[b] - List[a] == c:
            res += d

    return res


def dfs(i, x):
    res = 0
    if i == n:
        return score(x)

    for j in range(max(x[-1], 1), m+1):
        res = max(res, dfs(i+1, x+[j]))

    return res

print(dfs(0, [0]))

Measured memory_bytes: 9228
import sys
import math

N = 1000000
primes = [1] * (N//2)
primes[0] = 0

for i in (x for x in range(3,int(math.sqrt(N)),2) if primes[x//2]):
    primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])

for i in sys.stdin:
    n = int(i)
    if n == 1:
        print(0)
    elif n == 2:
        print(1)
    else:
        print(sum(primes[0:(n+1)//2])+1)

Measured memory_bytes: 16960
n, m, x, y = map(int, input().split())
xc = list(map(int, input().split()))
yc = list(map(int, input().split()))
xc.append(x)
yc.append(y)
xc.sort(reverse=True)
yc.sort()
if xc[0] < yc[0]:
    print("No War")
else:
    print("War")

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n;
ll d[333][333],dd[333][333];

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n)rep(j,n)cin>>d[i][j];
  memcpy(dd,d,sizeof(d));
  rep(k,n)rep(i,n)rep(j,n)minch(dd[i][j],dd[i][k]+dd[k][j]);
  rep(i,n)rep(j,n){
    if(dd[i][j]!=d[i][j]){
      cout<<-1<<endl;
      return 0;
    }
  }
  ll res=0;
  rep(i,n)rep(j,i){
    bool dame=false;
    rep(k,n){
      if(k==i||j==k)continue;
      if(d[i][j]>=d[i][k]+d[k][j])dame=true;
    }
    if(!dame)res+=d[i][j];
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1920
n = int(input())
ans = ""

while True:
  n -= 1
  x = divmod(n,26)
  ans = ans + chr(ord('a')+x[1])
  
  n = n - x[1]
  n = n // 26
  if n == 0:
    break
    
ans = ans[::-1]
print(ans)

Measured memory_bytes: 61844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
//#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define rep3(i, s, n) for (int i = (s); i <=(int) (n); i++)
//#define chmax(x,y) x = max(x,y)

	int a[3005][3005];
	long long dp[3005][3005][4];


int main() {
	int R,C,n;
	cin >> R >> C >> n;

	rep(i, n) {
	int r,c,v;
		cin >> r >> c >> v;
		a[r][c]=v;
	}

	rep3(i,1,R){
 		rep3(j,1,C) {
			dp[i][j][3]=max(dp[i][j][3],dp[i][j][2]+a[i][j]);
			dp[i][j][2]=max(dp[i][j][2],dp[i][j][1]+a[i][j]);
			dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]+a[i][j]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][2]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][3]);
			dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][0]);
			dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][1]);
			dp[i][j+1][2]=max(dp[i][j+1][2],dp[i][j][2]);
			dp[i][j+1][3]=max(dp[i][j+1][3],dp[i][j][3]);
		}
	}
	long long ans =0;
	ans=max(dp[R][C][0],dp[R][C][1]);
	ans=max(ans,dp[R][C][0]);
	ans=max(ans,dp[R][C][1]);
	ans=max(ans,dp[R][C][2]);
	ans=max(ans,dp[R][C][3]);

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


Measured memory_bytes: 320560
#include<stdio.h>


	int hen[3];

void Sort(void){

	int work;

	if(hen[0] > hen[1]){
		work = hen[0];
		hen[0] = hen[1];
		hen[1] = work;
	}
	if(hen[1] > hen[2]){
		work = hen[1];
		hen[1] = hen[2];
		hen[2] = work;
	}


}

int main(void){

	int i;
	int n;


	scanf("%d",&n);

	for(i=0;i<n;i++){

		scanf("%d %d %d",&hen[0],&hen[1],&hen[2]);
		Sort();
		if( (hen[2]*hen[2]) == (hen[0]*hen[0])+(hen[1]*hen[1]))
			printf("YES\n");
		else
			printf("NO\n");

	}



	return 0;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  vector<int> x(5);
  int ans;

  for(int i = 0; i < 5; i++) {
    cin >> x[i];
    if(x[i] == 0)
      ans = i+1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3472