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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

vector<vector<ll>> c(1000000);
vector<ll> ans;
vector<ll> d;

void ki(ll i,ll j){
    if(i==1){
        for(ll k=0;k<c[1].size();k++){
            ki(c[i][k],1);
        }
    }else{
        ans[i]=ans[j]+d[i];
        for(ll k=0;k<c[i].size();k++){
            if(ans[c[i][k]]==-1){
                ki(c[i][k],i);
            }
        }
     }
    
}

int main(){
    ll n,q;cin>>n>>q;
    ll a[n+1],b[n+1];
    for(ll i=1;i<=n-1;i++){
        cin>>a[i]>>b[i];
        c[a[i]].push_back(b[i]);
        c[b[i]].push_back(a[i]);
    }
    ll p[q+1],x[q+1];
    for(ll i=0;i<=n;i++){
        ans.push_back(-1);
        d.push_back(0);
    }
    for(ll i=1;i<=q;i++){
        cin>>p[i]>>x[i];
        d[p[i]]=d[p[i]]+x[i];
    }
    ans[1]=d[1];
    ki(1,1);
    cout<<ans[1];
    for(ll i=2;i<=n;i++){
        cout<<' '<<ans[i];
    }
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 47972
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int s[n];
  rep(i,n) cin>>s[i];
  sort(s, s + n);
  int ans = 0;
  int mi = 10000;
  rep(i,n) {
    if(s[i] % 10 != 0) {
      mi = min(mi, s[i]);
    }
    ans += s[i];
  }
  if(ans % 10 == 0) {
    if(mi == 10000) {
      ans = 0;
    } else {
      ans = ans - mi;
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

    string S; cin >> S;
    
    if(N%2)
    {
        cout << "No";
        return 0;
    }

    for(int i = 0; i < N/2; i++)
    {
        if(S.at(i) != S.at(i+N/2))
        {
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  if (ll(s.size()) <= k)
    cout << s << endl;
  else
    cout << s.substr(0, k) << "..." << endl;


  return 0;
}


Measured memory_bytes: 3628
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = -float("inf")
for i in range(N):
    hoge = []
    p = i
    s = 0
    for j in range(K):
        p = P[p]-1
        s += C[p]
        hoge.append(s)
        ans = max(ans,s)
        if p == i:
            S1 = s*((K-1)//len(hoge))
            S1 += max(hoge[0:(K-1)%len(hoge)+1])
            S2 = ans
            if (K-1) // len(hoge) > 1:
                S2 = s*((K-1)//len(hoge)-1)
                S2 += max(hoge)
            ans = max(ans,S1,S2)
            break
print(ans)
        


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

int main(){
	int N;
	cin>>N;
	vector<double> v(N);
	for (int i=0;i<N;i++){
		cin>>v.at(i);
	}
	double sum = v.at(0);
	sort(v.begin(),v.end());
	for (int i=1;i<N;i++){
		if(i!=1){
			sum = (sum+v.at(i))/2;
		}
		else{
			sum = (v.at(0)+v.at(1))/2;
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 200100;

std::vector<int> g[maxn];
bool vis[maxn];

int val = 0;

void dfs(int v){
   for(auto i : g[v]){
      if(!vis[i]){
        vis[i] = true;
        val += 1;
        dfs(i);
      }
   }
}

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    while(t--){
      int n,m; cin >> n >> m;
      map <pii, int> mp;
      for(int i = 0; i < m; i++){
         int a,b; cin >> a >> b;
         if(a > b) swap(a, b);
         if(mp.find({a, b}) != mp.end()) continue;
         g[a].push_back(b);
         g[b].push_back(a);
         mp[{a, b}] += 1;
      }
      int ans = 0;
      for(int i = 1; i <= n; i++){
         if(!vis[i]){
            vis[i] = true;
            val = 1;
            dfs(i);
            ans = max(ans, val);
         }
      }
      cout << ans << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 33544
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int m[200001];
void make_set(int val)
{
    m[val]=val;
}
int find_set(int val)
{
    if(m[val]==val)
    return val;
    m[val]=find_set(m[val]);
    return m[val];
}
void union_set(int p,int q)
{
    m[q]=p;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,i;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    make_set(i);
    for(i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        int fu=find_set(u),fv=find_set(v);
        if(fu!=fv)
        union_set(fu,fv);
    }
    int ans[n+1]={0},an=0;
    for(i=1;i<=n;i++)
    {
        int x=find_set(i);
        ans[x]++;
        an=max(an,ans[x]);
    }
    cout<<an;
    return 0;
}

Measured memory_bytes: 6840
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  ll a,b;cin>>a>>b;
  if(a == 1 || b == 1){
    print(1);
    return 0;
  }
  print((a*b+1)/2);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	long long int n, a, x[55], dp[55][55][2550] = {}, ans = 0;
	cin >> n >> a;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	dp[1][1][x[1]] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= i;j++) {
			for (int k = 1; k <= 2550; k++) {
				dp[i][j][k] += dp[i - 1][j][k];
				dp[i][j][k + x[i]] += dp[i - 1][j - 1][k];
			}
		}
		dp[i][1][x[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		ans += dp[n][i][a*i];
	}
	cout << ans << endl;
	return 0;
}


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

// 最終チェック
long long N, K, A[1 << 18];

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> A[i];

	assert(2 <= N && N <= 200000);
	assert(1 <= K && K <= N - 1);
	for (int i = 1; i <= N; i++) assert(1 <= A[i] && A[i] <= 1000000000);
	for (int i = K + 1; i <= N; i++) {
		if (A[i - K] < A[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 5216
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int t = Integer.parseInt(str[2]);
    int sum = 0;
    for(int i = 1; a*i <= t; i++){
      sum += b;
  }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21204
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

a = [0]+a+[0]

d=[]

for i in range(n+1):
  d.append(abs(a[i+1]-a[i]))
sa = sum(d)
for i in range(1,n+1):
  print(sa+abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i+1]-a[i]))


Measured memory_bytes: 92684
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        int N, L;
        is >> N >> L;
        if(!is) return;
        vector<ll> A(N);
        for (auto &&a : A) {
            is >> a;
        } // end a
        int k = -1;
        for (int i = 0; i < N - 1; ++i) {
            if(A[i] + A[i+1] >= L){
                k = i;
            }
        } // end i
        if(k < 0){
            os << "Impossible\n";
            return;
        }
        os << "Possible\n";
        for (int i = 1; i <= k; ++i) {
            os << i << '\n';
        } // end i
        for (int j = N-1; j > k; --j) {
            os << j << '\n';
        } // end j

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_C.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

// 0:TOP 1:FRONT 2:RIGHT 3:LEFT 4:BACK 5:BOTTOM 

class Dice{
public:
	vector<int> dice;
	Dice(){
		dice.resize(6);
		dice[0] = 1;
		dice[1] = 2;
		dice[2] = 4;
		dice[3] = 3;
		dice[4] = 5;
		dice[5] = 6;
	}
	Dice(vector<int> from){ dice = from; }
	void right(){
		int to[] = {1,3,5,2,4,6};
		doRotate(to);
	}
	void west(){
		int to[] = {3,2,6,1,5,4};
		doRotate(to);
	}
	void north(){
		int to[] = {2,6,3,4,1,5};
		doRotate(to);
	}
	void doRotate(int to[6]){
		vector<int> tmp = dice;
		rep(i,6) tmp[i] = dice[to[i]-1];
		dice = tmp;
	}
	vector< vector<int> > generateAllPattern(){
		vector< vector<int> > ans;
		for(int i = 0 ; i < 4 ; i++){
			for(int j = 0 ; j < 4 ; j++){
				for(int k = 0 ; k < 4 ; k++){
					ans.push_back(dice);
					north();
				}
				west();
			}
			right();
		}
		sort(ans.begin(),ans.end());
		ans.erase(unique(ans.begin(),ans.end()),ans.end());
		return ans;
	}
};

int main(){
	int n;
	while(cin >> n , n){
		Dice d;
		int x = 0 , y = 0;
		for(int i = 0 ; i < n ; i++){
			string s; cin >> s;
			
			if(s == "north") 	  for(int p = 0 ; p < 3 ; p++) d.north();
			else if(s == "south") for(int p = 0 ; p < 1 ; p++) d.north();
			else if(s == "east")  for(int p = 0 ; p < 3 ; p++) d.west();
			else if(s == "west")  for(int p = 0 ; p < 1 ; p++) d.west();
		}
		cout << d.dice[0] << endl;
	}
}

Measured memory_bytes: 0
n,k,q = map(int,input().split())
a = []
for i in range(q):
    a.append(int(input()) -1)
a.sort()

d = [0] * n
for i in a:
    d[i] += 1
boad = q - k + 1
for j in range(n):
    if d[j] >= boad:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8608
#include <iostream>
using namespace std;
typedef long long ll;
ll n,s[1000],t[1000][1000],ok,go,ch[1000],day;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin>>t[i][j];
            t[i][j]--;
        }
    }
    while(ok!=n){
        ok=0;
        day++;
        //cout<<"DAY"<<endl;
        for(int i=0;i<n;i++)ch[i]=0;
        go=0;
        for(int i=0;i<n;i++){
            if(s[i]==n-1){continue;}
            if(ch[i]==0&&ch[t[i][s[i]]]==0&&t[t[i][s[i]]][s[t[i][s[i]]]]==i){
                //cout<<i<<t[i][s[i]]<<endl;
                ch[i]++;
                ch[t[i][s[i]]]++;
                s[t[i][s[i]]]++;
                s[i]++;
                go++;
            }
        }
        for(int i=0;i<n;i++){
            if(s[i]==n-1)ok++;
        }
        if(go==0){cout<<-1<<endl; return 0;}
    }
    cout<<day<<endl;
}


Measured memory_bytes: 8064
import math

def create_arr(n):
  prime = {i for i in range(2,n)}
  for i in range(2,n):
    if i in prime:
        for j in range(i*2,n,i):
            if j in prime:
                prime.remove(j)
  return prime

def search(x):
  root = math.floor(math.sqrt(float(x)))
  prime_arr = create_arr(root)
  
  for num in prime_arr:
    if int(x) % num == 0:
      return search(int(x)+1)
  print(x)

X = input()
search(X)

Measured memory_bytes: 3572
<?php

$inp = str_split(fgets(STDIN));
$astation = 0;
$bstation = 0;

for($i = 0; $i < 3; $i++) {
  if (strcmp($inp[$i], 'A') === 0) {
    ++$astation;
  } else {
    ++$bstation;
  }
}

if ($astation === 3 || $bstation === 3)  {
  echo 'No';
} else {
  echo 'Yes';
}
?>

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h1, h2;
    cin >> h1 >> h2;
    int k1, k2;
    cin >> k1 >> k2;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int hiroshi = h1 * a + (h1 / 10) * c + h2 * b + (h2 / 20) * d;
    int kenjiro = k1 * a + (k1 / 10) * c + k2 * b + (k2 / 20) * d;
    if (hiroshi > kenjiro) {
        cout << "hiroshi" << '\n';
    } else if (hiroshi < kenjiro) {
        cout << "kenjiro" << '\n';
    } else {
        cout << "even" << '\n';
    }
    return 0;
}


Measured memory_bytes: 3208
#include<stdio.h>
#include<math.h>

bool isprime(int x){
    if(x==2) return true;
    if(x<2 || x%2==0) return false;
    for(int i=2;i<sqrt(x)+1;i++){
        if(x%i==0) return false;
    }
    return true;
}

int  main(){
    int N;
    scanf("%d",&N);
    int X[N];
    int sum=0;
    int i;
    for(i=0; i<N;i++){
        scanf("%d",&X[i]);
        if(isprime(X[i]))sum++; 
    }
    printf("%d\n",sum);
    return 0;

}



Measured memory_bytes: 2700
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  const int N = 365, K = 26;
  vector<int> c(K);
  vector<vector<int>> s(N, vector<int>(K));
  cin >> c[0];
  for (int &x : c) cin >> x;
  for (auto &v : s) for (int &x : v) cin >> x;
  vector<int> ans(N);
  vector<int> last(K, -1);
  int score = (int) 1e6;
  for (int i = 0; i < N; ++i) {
    int dec = 0;
    for (int j = 0; j < K; ++j) {
      dec += c[j] * (i - last[j]);
    }
    int mx = -MOD, t = -1;
    for (int j = 0; j < K; ++j) {
      if (uax(mx, s[i][j] - dec + c[j] * (i - last[j]))) t = j;
    }
    score += mx;
    last[t] = i;
    ans[i] = t;
    cout << 1 + ans[i] << '\n';
  }
  error(score);
}


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

int main()
{
    int penalties[100001] = {}, rez_w = 0, rez_a = 0, n, m, p;
    char ch[3];
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        cin >> p >> ch;
        if (strcmp(ch, "WA") == 0 && penalties[p] != -1) penalties[p]++;
        else
        {
            if (penalties[p] != -1)
            {
                rez_w += penalties[p];
                rez_a++;
                penalties[p] = -1;
            }
        }
    }
    cout << rez_a << ' ' << rez_w;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;

int main(){
	LL n;
	cin>>n;
	LL v[n+1],c[n+1];
	for(LL i=1;i<=n;i++) cin>>v[i];
	for(LL i=1;i<=n;i++) cin>>c[i];
	LL x[n+1];
	for(LL i=1;i<=n;i++) x[i]=v[i]-c[i];
	LL sum=0;
	for(LL i=1;i<=n;i++) if (x[i]>0) sum+=x[i];
	cout<<sum<<endl;
}


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

using namespace std;

vector<int> par;
vector<int> r;

void init(int size) {
	par.resize(size);
	r.resize(size, 0);
	for (int i = 0; i < size; ++i) { par[i] = i; }
}

int find(int x) {
    if (par[x] == x) {
		return x;
    } else {
		return par[x] = find(par[x]);
    }
}
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) { return; }

    if (r[x] < r[y]) { par[x] = y; }
    else { 
		par[y] = x;
		if (r[x] == r[y]) { ++r[x]; }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> p(N + 1);
	for (int i = 1; i <= N; ++i) { cin >> p[i]; }
	vector<int> x(M);
	vector<int> y(M);
	for (int i = 0; i < M; ++i) {
		cin >> x[i] >> y[i];
	}

	init(N + 1);
	for (int i = 0; i < M; ++i) {
		unite(x[i], y[i]);
	}

	int res = 0;
	for (int i = 1; i <= N; ++i) {
		if (same(i, p[i])) { ++res; }
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    int N,M,a,b;
    cin>>N>>M;
    vector<ll> G[N];
    for(int i =0;i<M;i++){
        cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> prev(N, INF);
    queue<ll> que;
    prev[0]=0;
    que.push(0);

    while(!que.empty()){
        ll pos=que.front();
        que.pop();
        for(int i=0;i<G[pos].size();i++){
            if(prev[G[pos][i]]!= INF) continue;//探索済み
            prev[G[pos][i]]=pos+1;
            que.push(G[pos][i]);
        }
    }

    cout<<"Yes"<<endl;
    for(int i=1;i<N;i++){
        cout<<prev[i]<<endl;
    }

    
        return 0;
}

Measured memory_bytes: 12768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const ll mod = 1e9 + 7;

const ll inf = 1LL << 60;

struct mint{
    ll x;
    mint(ll x = 0): x((x % mod + mod)%mod){}

    
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod)  x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator+(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const{ //クラスのメンバを変更しない
        mint res(*this);
        return res*=a;
    }

    mint pow(ll n)const{
        if(n == 0)return 1;
        mint a = pow(n>>1);
        a *= a;
        if(n & 1)a *= (*this);
        return a;
    }

    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint a){
        return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
        mint res(*this);
        return res/=a;
    }
    
};

ostream& operator<<(ostream &os, const mint &m){
    os << m.x;
    return os;
}

struct Combination{
    vector<mint> fact,ifact;
    Combination(int n): fact(n+1),ifact(n+1){
        fact[0] = 1;
        for(int i = 1; i<=n; i++)fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i>= 1; i--){
            ifact[i-1] = ifact[i] * i;
        }
    }

    mint comb(int n, int k){
        if(k < 0 || n < k)return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,K; cin>>N>>K;
    Combination combi(N);
    vector<mint> ans(K,0);
    REP(i,K){
        ans[i] = combi.comb(K-1,i) * combi.comb(N-K+1, i+1);
    }

    REP(i,K){
        cout << ans[i] << endl;
    }
    
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
int a,b;
char op;
while(1){
cin>> a >> op >> b;
if(op=='?'){break;}
if(op == '+'){
cout<<a+b<<endl;
}else if(op=='-'){
cout<<a-b<<endl;
}else if(op=='*'){
cout<<a*b<<endl;
}else if(op=='/'){
cout<<a/b<<endl;
}else{
cout<<endl;
}
}
return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int func(string s, string t){
  int ans=0;
  for(char c='a'; c<='z'; c++){
    bool checks=false, checkt=false;
    rep(i,sz(s)){
      if(s[i]==c){
        checks = true;
        break;
      }
    }
    rep(i,sz(t)){
      if(t[i]==c){
        checkt = true;
        break;
      }
    }
    if(checks && checkt){
      ans ++;
    }
  }
  return ans;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans=0;
  srep(i,1,n-1){
    ans = max(ans, func(s.substr(0,i), s.substr(i)));
  }
  cout << ans << endl;
  return 0;
}

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;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;
int dp[5005][5005];
int main() {
    int n; string s;
    cin >> n >> s;
    for(int i = n-1; i>=0; i--) {
        for(int j = n-1; j>=0; j--) {
            if(s[i] == s[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            }
            else dp[i][j] = 0;
        }
    }
    int ans = 0;
    rep(i,n) rep(j,n) {
        if(i>=j) continue;
        int now = min(dp[i][j], j-i);
        ans = max(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 98048
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    ll n, w;
    cin>>n>>w;
    
    ll weights[101], values[101];
    for(ll i=0; i<n; i++)
    {
        cin>>weights[i]>>values[i];
    }
    
    ll dp[101][100001];
    for(ll i=0; i<=n; i++)
    {
        for(ll j=0; j<=w; j++)
        {
            if(i == 0 || j == 0)
            {
                dp[i][j] = 0;
            } else if(weights[i-1] > j)
            {
                dp[i][j] = dp[i-1][j];
            } else
            {
                dp[i][j] = max(values[i-1]+dp[i-1][j-weights[i-1]], dp[i-1][j]);
            }
        }
    }
    
    cout<<dp[n][w]<<endl;
    
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vector<int> s(n+1);
  rep(i,n) {
    s[i+1] = (s[i]+a[i])%k;
  }
  map<int,int> mp;
  ll ans = 0;
  queue<int> q;
  rep(j,n+1) {
    ans += mp[s[j]];
    mp[s[j]]++;
    q.push(s[j]);
    if (q.size() == k) {
      mp[q.front()]--;
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int a, b, i, small8, small10, big8, big10;
    cin >> a >> b;
    small8 = (a * 100)/8 + (a%2);
    small10 = b * 10;
    big8 = ((a+1) * 100)/8 + ((a+1)%2);
    big10 = (b+1) * 10;
    for(i = 10; i <= 1001; i++){
        if(small8<=i && small10<=i&& i < big8 &&i < big10) {
            cout << i << endl;
            break;
        }
        if(i==1001) cout << -1 << endl;
    }
}


Measured memory_bytes: 256
//
//AtCoder Beginner Contest 125
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { 
    if (y==0) return x;
    return (x % y)? gcd(y, x % y): y; 
}    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> la(n,0);
    vector<ll> ra(n,0);
    REP(i,n-1) la[i+1] = gcd(la[i], a[i]);
    FORD(i, n-1, 1) ra[i-1] = gcd(ra[i], a[i]);
    
    ll ans=0;
    REP(i,n) ans = max(ans, gcd(la[i], ra[i]));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  int n;
  cin >> n;
  
  vector<int> l(n);
  int m = 0;
  int s = 0;
  for (int i = 0; i < n;i++) {
    cin >> l[i];
    m = max(m, l[i]);
    s += l[i];
  }
  
  if (m < (s - m)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#define N 10000
int main(){
  int a[N] = {}, b,  c, worktime = 0;
  scanf("%d %d", &b, &c);
  for (size_t i = 0; i < c; i++) {
    scanf("%d", &a[i]);
    worktime += a[i];
  }
  if((b - worktime) >= 0)  printf("%d", b - worktime);
  else printf("-1");
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, T;

struct Food {
  int t, d;
};

vector<Food> F;

int main() {
  cin >> N >> T;
  F.resize(N);
  rep(i, N) cin >> F[i].t >> F[i].d;

  sort(all(F), [&](const Food& a, const Food& b) { return a.t < b.t; });
  assert(F[0].t <= F[N - 1].t);

  vector<vector<int>> dp(N + 1, vector<int>(T, 0));
  rep(i, N) rep(t, T) {
    dp[i + 1][t] = dp[i][t];
    if (t - F[i].t >= 0)
      dp[i + 1][t] = max(dp[i + 1][t], dp[i][t - F[i].t] + F[i].d);
  }

  int ans = 0;
  rep(i, N) rep(t, T) ans = max(ans, dp[i][t] + F[i].d);

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


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

using namespace std;

string S, T;
int N, M;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> S >> T;
	N = (int)S.size();
	M = (int)T.size();
	
	int ans = 1000000000;
	for (int i = 0; i + M <= N; i++) {
		int cnt = 0;
		for (int j = 0; j < M; j++)
			cnt += (int)(S[i + j] != T[j]);
		ans = min(ans, cnt);
	}
	
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

#define MAX_V 200010
struct edge { int to; int cost; };
int V; vector<edge> G[MAX_V]; ll d[MAX_V];
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	int m; cin >> V >> m;
	rep(i, 0, m) {
		int p1, p2; cin >> p1 >> p2;
		G[p1 - 1].push_back({ p2 - 1,1 });
	}
	dijkstra(0);
	if (d[V - 1] > 2) printf("IMPOSSIBLE");
	else printf("POSSIBLE");
	return 0;
}

Measured memory_bytes: 11892
use std::io::*;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let n: usize = read();

    let mut a = Vec::new();
    for _ in 0..n {
        a.push(read::<usize>());
    }

    a.sort_by(|a, b| b.cmp(a));

    let mut sum = 0;

    for i in a {
        sum += i;

        if sum >= h {
            println!("Yes");
            return;
        }
    }

    println!("No");
}

/// Example
/// ```
///
///  let n: i32 = read();
///
///  let mut xs = Vec::new();
///  for _ in 0..n {
///      xs.push(read::<i32>() + 1000);
///  }
/// ```
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn hoge() {
        assert_eq!(run(20, 15), 0);
        assert_eq!(run(20, 30), 0);
        assert_eq!(run(12, 4), 4);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
if (a <= b){
	if(b <= c)
		printf("%d %d %d\n", a, b, c);//a<b<c
    else if(b >= c && a <= c)
				printf("%d %d %d\n", a, c, b);//a<c<b
    else
    				printf("%d %d %d\n", c, a, b);//c<a<b
}
else if (b <= a){
	if(a <= c)
		printf("%d %d %d\n", b, a, c);//b<a<c
    else if(a >= c && b <= c)
				printf("%d %d %d\n", b, c, a);//b<c<a
    else
    				printf("%d %d %d\n", c, b, a);//c<b<a
}
	return 0;
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
  
namespace std{
  bool operator < (const P &a,const P &b){
    return (a.real()<b.real()||(a.real()==b.real() && a.imag()<b.imag()));
  }
}
double eps=1e-10;
double Sqrt(double x){
  return sqrt(max(0.0,x));
}
  
struct S{
  P p,q;
  S(P p,P q):p(p),q(q){}
};
  
struct C{
  P p;
  double r;
  C(P p,double r):p(p),r(r){}
  C(double x,double y,double r):p(P(x,y)),r(r){}
};
  
S getTangent(C a,P p){
  P base=a.p-p;
  double w=Sqrt(norm(base)-a.r*a.r);
  P s=p+base*P(w,a.r)/norm(base)*w;
  P t=p+base*P(w,-a.r)/norm(base)*w;
  return S(s,t);
}
  
int main(){
  double ax,ay,ar,bx,by;
  cin>>bx>>by>>ax>>ay>>ar;
  S ans=getTangent(C(ax,ay,ar),P(bx,by));
  if(ans.q<ans.p)swap(ans.q,ans.p);
  printf("%.10f %.10f\n",ans.p.real(),ans.p.imag());
  printf("%.10f %.10f\n",ans.q.real(),ans.q.imag());
  return 0;
}

Measured memory_bytes: 3344
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
using namespace std;

void add(int i, int x, vector<int>& node, int n) {
	i += n - 1;
	node[i] += x;
	while (i > 0) {
		i = (i - 1) / 2;
		node[i] = node[2 * i + 1] +node[2 * i + 2];
	}
}
int getSum(int a, int b, int k, int l, int r, vector<int>& node) {
	if (r <= a || b <= l) return 0;
	if (a <= l && r <= b) return node[k];
	return (getSum(a, b, 2*k+1 , l, (l + r)/2, node) + getSum(a, b, 2*k + 2 , (l + r)/2, r, node));
}


int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n_, q;  cin >> n_ >> q;
	int n = 1;
	while (n < n_) n *= 2;
	vector<int> node(2 * n - 1, 0);

	for (int i = 0; i < q; i++) {
		int com, x, y; cin >> com >> x >> y;
		if (com == 0) { add(x - 1, y, node, n); }
		else { cout << getSum(x - 1, y, 0, 0, n, node) << endl; }
	}
}

Measured memory_bytes: 3880
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

int main(int argc, char* argv[])
{
  int n, x;
  int sum = 0;
  std::vector< int > vm;

  std::cin >> n >> x;
  for (int i = 0; i < n; i++) {
    int tmp;
    std::cin >> tmp;
    sum += tmp;
    vm.push_back(tmp);
  }

  std::vector< int >::iterator it;
  it = std::min_element(vm.begin(), vm.end());
  std::cout << n + (int)((x - sum) / *it) << std::endl;

  return 0;
}


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

using namespace std;

int abs(int x){
    return x > 0 ? x : -x;
}
bool isranged(int x, int y, int z){
    if(y < x && z < y) return true;
    if(y < z && x < y) return true;
    return false;
}

int main(){
    int n, total = 0;
    cin >> n;
    vector<int> pos(n+2, 0);
    for(int i = 1; i < n+1; i++){
        cin >> pos[i];
        total += abs(pos[i] - pos[i-1]);
    }
    total += abs(pos[n+1] - pos[n]);

    for(int i = 1; i < n+1; i++){
        int ans = total;
        if(isranged(pos[i-1], pos[i], pos[i+1])){
        }
        else{
            ans -= 2 * min(abs(pos[i] - pos[i-1]), abs(pos[i] - pos[i+1]));
        }
        cout << ans << endl;
    }

	return 0;
}



Measured memory_bytes: 1664
#!/usr/bin/env python3
import sys
from bisect import bisect_left,bisect_right

def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    answer = 0
    A.sort()
    C.sort()
    for i in range(N):
        answer += bisect_left(A,B[i])*(N-bisect_right(C,B[i]))
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24188
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int flag=0;
  while(n>0){
    if(n%10==7)	flag=1;
    n/=10;
  }
  if(flag) cout<<"Yes"<<endl;
  else	cout<<"No"<<endl;
  return 0;
}


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

struct data
{
    int val,id,type;
};

typedef pair<int,int> ii;
int m,n,k;
vector<data> V;
stack<int> S;

bool cmp(data x1,data x2)
{
    return x1.val<x2.val;
}

int Check(int u,int v)
{
    if(v==n&&u<m)
        return u+1;
    if(u==m&&v>0)
        return m+n-v+1;
    if(v==0&&u>0)
        return m+n+m-u+1;
    if(u==0&&v<n)
        return m+n+m+v+1;
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>m>>n>>k;
    int u1,v1,u2,v2;
    for(int i=1;i<=k;i++)
    {
        cin>>u1>>v1>>u2>>v2;
        int t1=Check(u1,v1),t2=Check(u2,v2);
        if(t1!=0&&t2!=0)
        {
            if(t1>t2)
                swap(t1,t2);
            V.push_back({t1,i,1});
            V.push_back({t2,i,-1});
        }
    }
    sort(V.begin(),V.end(),cmp);
    for(int i=0;i<V.size();i++)
        if(V[i].type==1)
            S.push(V[i].id);
        else
        if(S.top()==V[i].id)
            S.pop();
    if(S.size()==0)
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 4980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void){
    int n;
    cin >> n;
    
    vector<int> l(2*n);
    
    for (int i = 0; i < 2*n; i++) cin >> l[i];
    
    sort(l.begin(), l.end());
    
    int ans = 0;
    
    for (int i = 0; i < 2*n; i+=2) ans += l[i];
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

class Coordinate
{
public:
	double x;
	double y;

	Coordinate(double _x, double _y):x(_x),y(_y){}
	Coordinate():Coordinate(0.0,0.0){}
	Coordinate(int _x, int _y):Coordinate((double)_x, (double)_y) {}

	bool isEnd(){
		return (100.0 == this->x && 0.0 == this->y) ? true : false;
	}
};

inline const Coordinate operator+(const Coordinate& lhs, const Coordinate& rhs) {
	return Coordinate(lhs.x + rhs.x, lhs.y + rhs.y);
}
inline const Coordinate operator-(const Coordinate& lhs, const Coordinate& rhs) {
	return Coordinate(lhs.x - rhs.x, lhs.y - rhs.y);
}

const double sin60 = sin(M_PI / 3);
const double cos60 = 0.5;

void makeKockCueve(const int n, vector<Coordinate>& coordList);

int main() {
	int n;
	vector<Coordinate> coordinateList{{0.0, 0.0}, {100.0, 0.0}};
	cin >> n;

	makeKockCueve(n, coordinateList);

	for(const auto& e : coordinateList) {
		cout << e.x << " " << e.y << endl;
	}
	return 0;
}

void makeKockCueve(const int n, vector<Coordinate>& coordList) {
	if(0 == n) { return; }

	Coordinate left, midLeft, mid, midRight, right, tmp;
	double _x, _y;
	auto it = coordList.begin();

	while(it < coordList.end()){
		left = coordList[distance(coordList.begin(), it)];
		if(left.isEnd()) { break; }

		right = coordList[distance(coordList.begin(), it) + 1];

		midLeft.x = left.x + (right.x - left.x) / 3;
		midLeft.y = left.y + (right.y - left.y) / 3;

		midRight.x = left.x + (right.x - left.x) / 3 * 2;
		midRight.y = left.y + (right.y - left.y) / 3 * 2;

		tmp = midRight - midLeft;

		mid.x = midLeft.x + cos60 * tmp.x - sin60 * tmp.y;
		mid.y = midLeft.y + sin60 * tmp.x + cos60 * tmp.y;

		it = coordList.insert(it + 1, {midLeft, mid, midRight});
		it += 3;
	}
	makeKockCueve(n - 1, coordList);
}


Measured memory_bytes: 3324
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;


int main(){
 
    string s;
    string ss[10]={"000","111","222","333","444","555","666","777","888","999"};

    cin>>s;
    REP(i,10){
        if(s.find(ss[i])!=string::npos){
            yes;
            return 0;
        }
    }

    no;
    




}


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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int,int>> p(N);
  for (int i = 0; i < N; i++) {
    string a;
    int b;
    cin >> a >> b;
    p.at(i) = make_tuple(a,-b,i);
  }
  sort(p.begin(),p.end());

  for (int i = 0; i < N; i++) {
    string a;
    int b,j;
  tie(a,b,j) = p.at(i);
    cout << j+1 << endl;
  }
}




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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

int simulate(vector<int> cnt,bool phase) {
  if( cnt[1] == 0 && cnt[2] == 0 ) return 1;
  int ret = cnt[0];
  int cur = 0;
  if( phase ) {
    if( !cnt[1] ) return ret;
    cur += 1, --cnt[1], ++ret;
  } else {
    if( !cnt[2] ) return ret;
    cur += 2, --cnt[2], ++ret;
  }
  while( cnt[1] || cnt[2] ) {
    if( cur == 1 ) {
      if( !cnt[1] ) break;
      ( cur += 1 ) %= 3, --cnt[1], ++ret;
    } else {
      if( !cnt[2] ) break;
      ( cur += 2 ) %= 3, --cnt[2], ++ret;
    }
  }
  if( cnt[1] || cnt[2] ) ++ret;
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n),cnt(3,0);

  rep(i,n) { 
    cin >> a[i];
    a[i] %= 3;
    ++cnt[a[i]];
  }
  cout << max(simulate(cnt,false),simulate(cnt,true)) << endl;
  return 0;
}

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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

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

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
	int x,n;
	cin>>x>>n;
	set<int> st;
	for(int i=0;i<n;i++){
		int it;
		cin>>it;
		st.insert(it);
	}

	for(int f=0;f<=1e8;f++){

		if(st.count(x-f)==0){
			cout<<x-f<<nl;
			return;
		}
		if(st.count(f+x)==0){
			cout<<f+x<<nl;
			return;
		}
	}
}

int main()
{
	FIO;

	int t = 1;
	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char s[100];
int main(){
	scanf(" %s",s);
	s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'?printf("Yes"):printf("No");
	return 0;
}

Measured memory_bytes: 256