akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;

struct state { int y, x, step; };
static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
        int w, h;
        while (scanf("%d%d", &w, &h), w) {
                vector<string> s(h);
                for (int i = 0; i < h; i ++) cin >> s[i];
                int sy, sx;
                for (int i = 0; i < h; i ++) {
                        for (int j = 0; j < w; j ++) {
                                if (s[i][j] == '@') {
                                        sy = i, sx = j;
                                }
                        }
                }
                vector<vector<bool>> used(h, vector<bool>(w, false));
                queue<state> q;
                q.push({sy, sx, 0});
                used[sy][sx] = true;
                while (!q.empty()) {
                        state p = q.front(); q.pop();
                        for (int d = 0; d < 4; d ++) {
                                int xx = p.x + dx[d], yy = p.y + dy[d];
                                if (xx < 0 || xx >= w || yy < 0 || yy >= h) continue;
                                if (used[yy][xx] || s[yy][xx] == '#') continue;
                                used[yy][xx] = true;
                                q.push({yy, xx, p.step + 1});
                        }
                }
                int ans = 0;
                for (int i = 0; i < h; i ++) {
                        for (int j = 0; j < w; j ++) {
                                ans += used[i][j];
                        }
                }
                printf("%d\n", ans);
        }
        return 0;
}

Measured memory_bytes: 3308
/*
ЗАПУСКАЕМ ВЫСОКОГО
░ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>

using std::cerr;
using std::cin;
using std::cout;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ff first
#define ss second
#define pb emplace_back
template<typename T> 
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h <<"\n"; 
}
template<typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
    int _b = 0;
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++; 
    cerr << " = " << _h << ","; 
    _dbg(_s+1, _t...);
}
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) 
#endif

struct init {
    init() {
        cin.tie(0);
        std::iostream::sync_with_stdio(0);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        #ifdef LOCAL
        srand(300); 
        #else
        using namespace std::chrono;
        srand(duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count()); 
        #endif
    }
    ~init() {
        #ifdef LOCAL
        cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
        #endif
    }
} init;

const int MAXN = 228;
int a[3][MAXN];
int dp[3][MAXN];

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

    dp[0][0] = a[0][0];
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < n; ++j)
        {
            {
                int pot = dp[i][j] + a[i + 1][j];
                if (dp[i + 1][j] < pot)
                    dp[i + 1][j] = pot;
            }
            {
                int pot = dp[i][j] + a[i][j + 1];
                if (dp[i][j + 1] < pot)
                    dp[i][j + 1] = pot;

            }
        }

    cout << dp[1][n - 1] << '\n';
    
    return 0;
}


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

#define MAX_N 105
int a[MAX_N];
int n;

int main(){
	//freopen("in.txt", "r", stdin);
	for(int i = 1; i <= 9; ++i) a[i] = i*111;
	a[10] = 1111;
	while(cin >> n){
        for(int i = 1; i <= 10; ++i) {
            if(a[i] >= n) {
                cout << a[i] << endl; break;
            }
        }
	}
	return 0;
}


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

int p,q,a,n;

int dfs(int pp, int qq, int count, int dis){
   if(q*pp==p*qq) return 1;
   if(count==n) return 0;
   if(q*pp>p*qq) return 0;

   int ans = 0;
   for(int i=dis; qq*i<=a; i++){
      ans += dfs(pp*i+qq,qq*i,count+1,i);
   }
   return ans;
}

int main(){
   cin>>p>>q>>a>>n;
   while(p||q||a||n){
      cout << dfs(0,1,0,1)<<endl;
      cin>>p>>q>>a>>n;
   }
}



Measured memory_bytes: 2992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc129/tasks/abc129_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 小さいコスト二つの和
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll a,b,c; cin >> a >> b >> c;
    res = a+b+c - max({a,b,c});
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;

int main() {
	string s;
	int count = 0;
	cin >> s;
	if (s[0] == 'o') {
		count++;
	}
	if (s[1] == 'o') {
		count++;
	}
	if (s[2] == 'o') {
		count++;
	}
	cout << 700 + count * 100 << endl;
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S=in<string>(),T=in<string>();
	for(int i=0,ei=S.size();i<ei;i++){
		if(S==T){
			cout << "Yes" << endl;
			return 0;
		}
		rotate(S.begin(),S.begin()+1,S.end());
	}
	
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = int(input())
print(180*(n-2))


Measured memory_bytes: 67052
#include<stdio.h>
int main(void)
{
	int x[10000];
	int i = 0;
	while(1){
		scanf("%d",&x[i]);
		if(x[i]==0){
			break;
		}
		i++;
	}
	for(int j = 0;j < i;j++)
	{
		printf("Case %d: %d\n",j+1,x[j]);
	}
	return 0;
}



Measured memory_bytes: 2060
#<C>
N = int(input())
B = list(map(int,input().split()))
A = [None] * N
A[0] = B[0]
for i in range(N - 2):
    if B[i] <= B[i + 1]:
        A[i + 1] = B[i]
    else:
        A[i + 1] = B[i + 1]
A[N - 1] = B[N -2]
print(sum(A))
        

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll a[N];
ll s[N];
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	for(int i = 0; i <= n; i++) cin >> a[i];
	s[n] = a[n];
	for(int i = n - 1; i >= 0; i--) s[i] = a[i] + s[i + 1];

	ll ans = 1;
	ll c = 1;
	for(int i = 0; i < n; i++){
		c -= a[i];
		if(c <= 0) return cout << -1, 0;
		if(s[i + 1] < c) return cout << -1, 0;
		c = min(c + c, s[i + 1]);
		ans += c;
	}
	cout << (c == a[n] ? ans : -1);
	return 0;
}


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

int main()
{
	string s;
	cin >> s;
	int y_i = s.find_first_of('/');
	int m_i = s.find_last_of('/');
	int year = stoi(s.substr(0, y_i));
	int month = stoi(s.substr(y_i + 1, m_i - y_i - 1));
		
	if (year<2019)
	{
		cout << "Heisei" << endl;
		return 0;
	}
	else if (year>2019)
	{
		cout << "TBD" << endl;
		return 0;
	}
	else if (month <= 4)
	{
		cout << "Heisei" << endl;
		return 0;
	}
	else
	{
		cout << "TBD" << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> 
#include <cstdlib>
#include <cmath>
#include<map>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h> 
#include<vector>
using namespace std;
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
//#define viadj[n+1] vector<int>adj[n+1] 
#define sortA(arr)   sort(arr.begin(),arr.end())
#define sortC(arr,n)   sort(arr,arr+n,comparefunc())
#define search(arr,c)  binary_search(arr.begin(),arr,end(),c)
#define pb   push_back
#define ll long long
 
/*struct node{
     int b;long sum;
     string name;
}
 
 
bool comparefunction(node c,node d){
   if(c.b!=d.b)
   return c.b>d.b;
     
}*/
 
 // 
 
  /* void dfs(int v) {
    visited[v] = true;
 
    
    for (int u : adj[v]) {
       if (!visited[u])
            dfs(u);
    }
   
    
}*/
 
 int  gcd(int a,int b)
 {
       // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a%b, b); 
    return gcd(a, b%a); 
 }
   
 
     
 
 
 
 
int main()
{
    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
   
    int check1=0,check2=0,check3=0;
    int counti=0;
    //int count=0;
    long double pi=3.141592653589793;
    ll sum=0,count=0,n,m,t,k,a,b,c,d;
  //  cin>>t;
  cin>>n>>m;
  vi adj[n+1];
 int res[n+1]={0};
  int h[n+1];
  rep(i,1,n+1)
  cin>>h[i];
  while(count!=m)
  {
      int u,v;
      cin>>u>>v;
      if(h[u]<=h[v])
      res[u]=1;
      if(h[v]<=h[u])
      res[v]=1;
      
      
      count++;
      
  }
  
  rep(i,1,n+1)
  {
      if(!res[i])
      counti++;
  }
  cout<<counti;
  
    }
 

 
 
 

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

int main(void){
	int n;
	cin >> n;
	int a[n+1];
	int i;
	long long ans=0,ans2=0;
	a[0] = 0;
	for(i=1;i<=n;i++)cin >> a[i];
	//1 3 5 7 9を+にする場合
	long long b = 0;//bはそれまでの合計値
	for(i=1;i<=n;i++){
		b += a[i];
		if(i%2==1){
			if(b>0){
			}else{
				ans += abs(1-b);
				b = 1;
			}
		}else{
			if(b<0){
			}else{
				ans += abs(-1-b);
				b = -1;
			}
		}
	}
	//1 3 5 7を-にする場合
	b = 0;
	for(i=1;i<=n;i++){
		b += a[i];
		if(i%2==0){
			if(b>0){
			}else{
				ans2 += abs(1-b);
				b = 1;
			}
		}else{
			if(b<0){
			}else{
				ans2 += abs(-1-b);
				b = -1;
			}
		}
	}
	cout << min(ans,ans2);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main(){
 ll a,b,c,k;
  cin>>a>>b>>c>>k;
  ll y=max(a,b);
  ll n=max(c,y);
  ll p=n;
  n*=pow(2,k);
  cout<<a+b+c-p+n<<endl;
}



Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if((a - b) < c)
    {
        cout << c - (a - b);
    }
    else
    {
        cout << "0";
    }
    
    return 0;
}

Measured memory_bytes: 256
abc = list(map(int,input().split()))

count = 0
abc.sort(reverse=True)

# 偶奇が一致
if abc[0] % 2 == abc[1] % 2 and abc[0] % 2 == abc[2] % 2:
    count += (abc[0] - abc[1]) / 2
    count += (abc[0] - abc[2]) / 2

# 偶奇が両方違う
elif abc[0] % 2 != abc[1] % 2 and abc[0] % 2 != abc[2] % 2:
    abc[1] += 1
    abc[2] += 1
    count += 1

    count += (abc[0] - abc[1]) / 2
    count += (abc[0] - abc[2]) / 2

# 偶奇が片方違う
else:
    if abc[0] % 2 == abc[1] % 2:
        abc[0] += 1
        abc[1] += 1
        count += 1

        count += (abc[0] - abc[1]) / 2
        count += (abc[0] - abc[2]) / 2

    else:
        abc[0] += 1
        abc[2] += 1
        count += 1

        count += (abc[0] - abc[1]) / 2
        count += (abc[0] - abc[2]) / 2

print(int(count))

Measured memory_bytes: 3064
N, M = map(int, input().split())
a_list = list(map(int, input().split()))

items = {
    1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6
}

dp = [-float("inf")] * (N + 1)
b_list = []
for a in a_list:
    need = items[a]
    if need <= N:
        dp[need] = 1
        b_list.append(a)

M = len(b_list)
dp[0] = 0
for i in range(N + 1):
    for b in b_list:
        if i - items[b] >= 0:
            if dp[i - items[b]] != -float("inf"):
                dp[i] = max(dp[i], dp[i - items[b]] + 1)

b_list.sort(reverse=True)
ans = ""

for i in range(dp[N]):
    for b in b_list:
        if dp[N - items[b]] == dp[N] - 1:
            ans += str(b)
            N -= items[b]
            break
print(ans)


Measured memory_bytes: 3396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n){
        cin >> h[i];
    }

    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    ll ans = 0;
    rep(i, n){
        if(k == 0){
            ans += h[i];
        }
        else{
            k--;
        }
    }

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

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <cmath>

int n;
bool prime[55560];
int main() {
	std::cin >> n;

	std::fill(prime, prime + 55555 + 1, true);
	for (int i = 2, end = std::sqrt(55555); i <= end; i++) {
		if (prime[i]) {
			for (int j = 0; i * (j + 2) <= 55555; j++) {
				prime[i *(j + 2)] = false;
			}
		}
	}
	prime[0] = prime[1] = false;

	int ans[60];
	int cnt = 0;
	for (int i = 6; cnt < n; i += 5)
		if (prime[i])
			ans[cnt++] = i;

	for (int i = 0; i < n; ++i)
		std::cout << ans[i] << std::endl;
	return 0;
}


Measured memory_bytes: 256
/*
拼图最终一定被分成了若干个连续的部分，这里连续的定义是相邻的2个拼图拼在一起。对于一个连续的部分1 ~ N，需要满足的条件是：
C[1] = 0   D[N] = 0   对于相邻的两个拼图i和i + 1，D[i] = A[i + 1]且C[i + 1] = 0 或 B[i] = C[i + 1]且D[i] = 0
定义一个拼图的两个属性P和Q：
当C[i] = 0时，P[i] = A[i]；当C[i] > 0时，P[i] = -C[i]
当D[i] = 0时，Q[i] = -B[i]；当D[i] > 0时，Q[i] = D[i]
可以观察到这么几个性质：
(1)因为A[i] > 0且B[i] > 0，所以C[i] != 0且D[i] != 0
(2)两个拼图i和i + 1能拼接起来的条件等价于Q[i] = P[i + 1]
(3)C[1] = 0等价于P[1] > 0，D[N] = 0等价于Q[N] < 0
根据此可以建图，把每个权值当成一个点，一个拼图是一条P[i] -> Q[i]的有向边，所有> 0的点可以作为路径起点，所有< 0的点可以作为路径终点
一个合法的方案对应的是：若干条合法的路径，满足每条边被覆盖了恰好一次
可以考虑把所有路径分成若干组，每组的路径顺次排列成一个环，每条路径的终点往下一条路径的起点连一条边。那么这个方案对应了新图的若干条欧拉回路
只要能构造出存在这样欧拉回路的图，就能构造出合法的方案。直接根据度数判断能否令每个点满足入度 = 出度且对于每个联通块都能在构造的环上即可 
*/

#include <map>
#include <cstdio>

using namespace std;
const int Max_N(100050);
const int Max_H(205);

int N, H, P, Q, Sum1, Sum2, Fa[Max_H << 1], *Father = Fa + Max_H;
bool Ha[Max_H << 1], *Have = Ha + Max_H;
map<int, int> In, Out;

int Get_Father(int x)
{
	return Father[x] == x ? x : Father[x] = Get_Father(Father[x]);
}

int main()
{
	scanf("%d%d", &N, &H);
	for (int x = -H;x <= +H;++x)
		Father[x] = x;
	for (int i = 1, A, B, C, D, P, Q;i <= N;++i)
	{
		scanf("%d%d%d%d", &A, &B, &C, &D);
		if (C == 0)
			P = A;
		else
			P = -C;
		if (D == 0)
			Q = -B;
		else
			Q = D;
		//P -> Q
		++In[Q], ++Out[P], Father[Get_Father(P)] = Get_Father(Q);
	}
	for (int x = -H;x <= -1;++x)
	{
		if (Out[x] > In[x])
		{
			puts("NO");
			return 0;
		}
		if (In[x] - Out[x])
			Sum1 += In[x] - Out[x], Have[Get_Father(x)] = true;
	}
	for (int x = +1;x <= +H;++x)
	{
		if (In[x] > Out[x])
		{
			puts("NO");
			return 0;
		}
		if (Out[x] - In[x])
			Sum2 += Out[x] - In[x], Have[Get_Father(x)] = true;
	}
	if (Sum1 == Sum2)
	{
		for (int x = -H;x <= +H;++x)
			if ((In[x] || Out[x]) && Have[Get_Father(x)] == false)
			{
				puts("NO");
				return 0;
			}
		puts("YES");
	}
	else
		puts("NO");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		while (true) {
			String str = sc.nextLine();

			if (str.equals("0"))
				break;
			char[] sen = str.toCharArray();
			int sum = 0;

			for (int i = 0; i<sen.length; i++) {
				sum += Character.getNumericValue(sen[i]);
			}
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 26624
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
import numpy as np


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    N = I()
    h = LI()
    h = np.array(h)
    #  print(N, h)
    # 0以上の塊をみつける
    # その塊に水をやる
    # 以上を繰り返す
    count = 0
    while True:
        #  print(h)
        first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0]
        if len(first_non_zero_idx) == 0:
            # 終了
            print(count)
            return
        else:
            first_non_zero_idx = first_non_zero_idx[0]

        first_zero_idx = [idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0]
        if len(first_zero_idx) == 0:
            # 0がないので最後まで水をやる
            first_zero_idx = len(h)
        else:
            first_zero_idx = first_zero_idx[0]

        # 水をやる
        h[first_non_zero_idx:first_zero_idx] -= 1
        count += 1





main()


Measured memory_bytes: 13636
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(2000).
       01 A-REC.
      	02 A-DATA OCCURS 200 .
      		03 A PIC 999999999 .
       01 temp1 PIC 9999.
       01 temp2 PIC 9999.
       01 temp3 PIC 99999.
       01 N PIC 999.
       01 REN PIC ZZZZ9.
       01 RE PIC 99999.
       01 MOD PIC 9.
       01 R PIC 999999999.
       01 S PIC 999.
       01 NOW PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
      	MOVE 10000 TO RE.
      	ACCEPT N.
      	MOVE 1 TO NOW.
      	ADD 1 TO N.
      	ACCEPT INP.
      	PERFORM VARYING S FROM 1 BY 1 UNTIL S = N
      		PERFORM VARYING temp1 FROM NOW BY 1 UNTIL INP(temp1:1)=SPACE
      		END-PERFORM
      		COMPUTE temp2 = temp1 - NOW
      		MOVE INP(NOW:temp2) TO A(S)
      		COMPUTE NOW = temp1 + 1
      	END-PERFORM.
      	PERFORM VARYING S FROM 1 BY 1 UNTIL S = N
      		COMPUTE R = A(S) / 2
      		COMPUTE MOD = A(S) - R*2
      		PERFORM VARYING temp3 FROM 0 BY 1 UNTIL MOD = 1
      			COMPUTE R = A(S) / 2
      			COMPUTE MOD = A(S) - R*2
      			COMPUTE A(S) = R
      		END-PERFORM
      		IF temp3 > 0 THEN
      			SUBTRACT 1 FROM temp3
      		END-IF
      		IF temp3 < RE THEN
      			MOVE temp3 TO RE
      		END-IF
      	END-PERFORM.
      	MOVE RE TO REN.
      	DISPLAY REN.
        STOP RUN.




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

using namespace std;

int main()
{
    char a, b;
    cin >> a >> b;
    string result = "";
    if (a > b)
    {
        while (a > '0')
        {
            result += to_string(b - '0');
            a--;
        }
    }
    else
    {
        while (b > '0')
        {
            result += to_string(a - '0');
            b--;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<pair<long, long>> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  sort(data.begin(), data.end());
  long count = 0, sub, a, b;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(i == j)continue;
      sub = 1;
      a = data.at(j).first - data.at(i).first;
      b = data.at(j).second - data.at(i).second;
      for(int k = 0; k < N; k++){
        if(k == i)continue;
        for(int l = 0; l < N; l++){
          if(l == j || k == l)continue;
         if(data.at(l).first - data.at(k).first == a && data.at(l).second - data.at(k).second == b){
           sub++;
         }
        } 
      }
      count = max(count, sub);
    }
  }
  
  cout << N - count << endl;
  return 0;
}


Measured memory_bytes: 256
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll a,b,c,d,n=0;
    cin >> a >> b >> c >> d;

    while(a>0 && c>0)
    {
        if(n%2==0)
        {
            c-=b;
        }
        else
        {
            a-=d;
        }
        n++;
    }

    if(n%2==0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" <<endl;
    }
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;


int W,H;
int _black_cnt;
char sima[21][21];
bool is_visit[21][21];
int dw[4] = {1,0,-1,0};
int dh[4] = {0,1,0,-1};

void saiki(int w, int h) {
	int aw,ah;
	rep(i,4) {
		aw = w+dw[i];
		ah = h+dh[i];
		if ((0 <= aw && aw <= W) || (0 <= ah && ah <= H)) { 
			if (sima[aw][ah] == '.' && !is_visit[aw][ah]) {
				is_visit[aw][ah] = true;
				_black_cnt++;
				saiki(aw,ah);
			}
			else {
				is_visit[aw][ah] = true;
			}
		}
	}

	return;
}

int main() {
	string a_str;
	while(cin >> W >> H) {
		if (W==0 && H==0) { break; }

		_black_cnt=0;
		//初期化
		rep(h,21) {
			rep(w,21) {
				sima[w][h] = 0;
				is_visit[w][h] = 0;
			}
		}
		
		//値挿入
		int fw=0,fh=0;
		rep(h,H) {
			cin >> a_str;
			rep(w,W) {
				if (a_str[w]=='@') { fw=w; fh=h; }
				sima[w][h] = a_str[w];
			}
		}

		is_visit[fw][fh] = true;
		_black_cnt=1;
		saiki(fw,fh);
		cout << _black_cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
# dfs

def dfs(lst, char_n, i, tmp_sum):
    if i == len(lst):
        return tmp_sum + int(char_n)
    return dfs(lst, lst[i], i + 1, int(char_n) + tmp_sum) + dfs(lst, char_n + lst[i], i + 1, tmp_sum)


lst = [x for x in input()]
print(dfs(lst, lst[0], 1, 0))

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

typedef long long int llint;

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

  int cnt = 1;
  n -= k;

  cnt += n / (k - 1);
  if(n % (k - 1) > 0) cnt++;

  cout<< cnt <<endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


int N, M; 
int ans = 0;
vector<vector<int>> graph;
vector<bool> visited;

void dfs(int c, int depth){
  if(depth == N-1){
    ans++;
    return;
  }

  for(auto v : graph[c]){
    if(visited[v]) continue;
    visited[v] = true;
    dfs(v, depth+1);
    visited[v] = false;
  }
}
signed main() {
  cin >> N >> M;

  graph.resize(N);
  REP(i, M){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }

  visited.resize(N, false);
  visited[0] = true;

  dfs(0, 0);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#define ll long long
#define linf (1ll<<60)
#define iinf 0x3f3f3f3f
#define dinf 1e100
#define eps 1e-8
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
int f[1000];
int main()
{
	int i, j, N;
	for(i=1;i<=200;i+=2)
	{
		for(j=1;j<=i;j++)if(i%j==0)f[i]++;
		f[i]=f[i]==8;
	}
	for(i=1;i<=200;i++)f[i]+=f[i-1];
	scanf("%d",&N);
	printf("%d",f[N]);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)
	result := make([]rune, len(s))
	for i, c := range s {
		result[i] = rune((int(c)-65+n)%26 + 65)
	}

	fmt.Printf("%s\n", string(result))
}


Measured memory_bytes: 768
n = int(input())
ans = [0]*4
for i in range(n):
    s = input()
    if s=='AC':
        ans[0]+=1
    elif s=='WA':
        ans[1]+=1
    elif s=='TLE':
        ans[2]+=1
    elif s=='RE':
        ans[3]+=1
print('AC x {}'.format(ans[0]))
print('WA x {}'.format(ans[1]))
print('TLE x {}'.format(ans[2]))
print('RE x {}'.format(ans[3]))

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

const int maxn = 3e3 + 10;
int N;
double p[maxn];
double DP[maxn][maxn * 2];


int main(){
    scanf("%d" , &N);
    for(int i = 1; i <= N; ++i){
        scanf("%lf" , &p[i]);
    }
    DP[0][3000] = 1.0;
    for(int i = 1; i <= N; ++i){
        for(int j = 3000 - N; j <= 3000 + N; ++j){
            DP[i][j] = p[i] * DP[i - 1][j - 1] + (1.0 - p[i]) * DP[i - 1][j + 1];
        }
    }
    double ret = 0;
    for(int i = 1; i <= N; ++i){
        ret += DP[N][3000 + i];
    }
    printf("%.12lf\n" , ret);
}


Measured memory_bytes: 141696
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  map<string,int>mp;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
  }
  for(string s:{"AC","WA","TLE","RE"}){
    cout << s << " x " << mp[s] << endl;
  }
  return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll MOD = 1e9+7;

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

	int max = 1000000;
	bitset<1000000> vis;
	vis.set();
	vis[0] = vis[1] = 0;
	for(int i = 2; i*i <= max; i++){
		if(vis[i] == 1){
			for(int j = i*i; j <= max; j+=i)
				vis[j] = 0;
		}
	}

	int n; cin >> n;

	while(vis[n] == 0) n++;
	cout << n << '\n';

	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<vector>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
const int mx=90+10,mo=1000000007;
const ll inf=1000000000000000000;
ll fib[mx];
vector<pi> a[mx];
vector<pi>::iterator it;
ll x,y,n,m,num;
int i,j,k,l,t,tot,ca,ans;
int main(){
    fib[0]=fib[1]=1;
    tot=1;
    while (1){
        fib[tot+1]=fib[tot]+fib[tot-1];
        if (fib[tot+1]>inf) break;
        tot++;
    }
    a[1].pb(mp(1,2));a[1].pb(mp(1,3));a[1].pb(mp(1,4));
    fo(i,1,tot-3){
        it=a[i].begin();
        while (it!=a[i].end()){
            x=(*it).xx;y=(*it).yy;
            x+=y;
            while (x<=fib[i+3]){
                a[i+1].pb(mp(y,x));
                x+=y;
            }
            it++;
        }
    }
    scanf("%d",&ca);
    while (ca--){
        scanf("%lld%lld",&n,&m);
        if (n>m) swap(n,m);
        ans=1;
        while (fib[ans+1]<=n&&fib[ans+2]<=m) ans++;
        printf("%d ",ans);
        if (ans==1){
            printf("%lld\n",n*m%mo);
            continue;
        }
        else{
            num=0;
            it=a[ans-1].begin();
            while (it!=a[ans-1].end()){
                x=(*it).xx;y=(*it).yy;
                if (y<=n) (num+=(m-x)/y)%=mo;
                if (y<=m) (num+=(n-x)/y)%=mo;
                it++;
            }
            printf("%d\n",num);
        }
    }
}

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

int main(){
  string str;
  cin >> str;
  int count;
  for(int i=0; i<str.length(); i++){
    if(str[i] == '1'){
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, ans = 0;
    in >> N;
    vector<ll> X;
    REP(i, 5){
        ll a;
        in >> a;
        X.push_back(a);
    }
    SORT(X);
    ans = ceil(double(N) / X[0]) + 4;
    out << ans << endl;

}

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

#define debug(x) cerr << #x << ": " << x << endl

long long lcm(long long a, long long b) {
  long long g = __gcd(a, b);
  return a / g * b;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  long long res = 1;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    res = lcm(res, x);
  } 
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn gcd(a: u8, b: u8) -> u8 {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input! {
        k: u8,
    }

    let mut ans: u32 = 0;
    for a in 1..k + 1 {
        for b in a..k + 1 {
            for c in b..k + 1 {
                if a == b && b == c {
                    ans += gcd(gcd(a, b), c) as u32;
                } else if a == b || b == c {
                    ans += 3 * gcd(gcd(a, b), c) as u32;
                } else {
                    ans += 6 * gcd(gcd(a, b), c) as u32;
                }
                // println!("{}, {}, {}: {}", a, b, c, gcd(gcd(a, b), c));
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2096
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x[] = new int[n];
    int total[] = new int[101];
    for(int i=0 ; i<n ; i++){
      x[i] = sc.nextInt();
    }
    for(int j=0 ; j<=100 ; j++){
      for(int i=0 ; i<n ; i++){
        total[j] = total[j] + (x[i]-j)*(x[i]-j);
      }
    }
    Arrays.sort(total);
    // for(int i=0 ; )
    System.out.println(total[0]);
  }
}


Measured memory_bytes: 21844
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
  
int main(){
	vector<pair<int,pair<int,int>>> vx,vy;
	int i=0,r=0,n,x1,y1,x2,y2;
	for(scanf("%d",&n);i<n;i++){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(x1>x2)swap(x1,x2);
		if(y1>y2)swap(y1,y2);
		if(x1==x2)vy.emplace_back(make_pair(x1,make_pair(y1,y2)));
		else vx.emplace_back(make_pair(y1,make_pair(x1,x2)));
	}
	//sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());
	for(auto &e:vx){
		auto it1=lower_bound(vy.begin(),vy.end(),make_pair(e.second.first,make_pair(-2000000000,-2000000000)));
		auto it2=lower_bound(vy.begin(),vy.end(),make_pair(e.second.second+1,make_pair(-2000000000,-2000000000)));
		
		for(;it1!=it2;++it1){
			auto &f=*it1;
			if(f.second.first<=e.first&&e.first<=f.second.second)r++;
		}
	}
	printf("%d\n",r);
}

Measured memory_bytes: 4012
#pragma GCC optimization_level 3
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    int count = 0;
    int min_p = 10000000;

    for (size_t i = 0; i < n; i++)
    {
        cin>>p.at(i);
    }
    

    for (size_t i = 0; i < n; i++)
    {
        min_p = min(min_p,p.at(i));
        if(p.at(i)==min_p){
            count++;
        }


    }

    cout << count;
}

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


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

    long int n;
    cin>>n;
    long int a[n];
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
    } 
    long int count=0;
    for(long int i=1;i<n-1;i++)
    {
        if(a[i]==a[i-1] && a[i]==a[i+1])
        {
            continue;
        }
        if(a[i]>=a[i-1])
        {
            if(a[i]<=a[i+1])
            {
                count++;
            }
        }
        else if(a[i]<=a[i-1])
        {
            if(a[i]>=a[i+1])
                count++;
        }

    }
    cout<<count<<endl;


}


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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, A);
    CIN(int, P);

    int ans = (3*A+P)/2;

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
struct Point{int x, y;};

class Cube{
    public:
    char C[3];
    Cube(){ C[0] = 'W'; C[1] = 'R'; C[2] = 'B';}
    void setEmpty(){ C[0] = 'E';}
    void rotate(int d){
        if ( d % 2 == 0 ) swap(C[0], C[2]);
        else swap(C[0], C[1]);
    }
};

char target[3][3];

class Puzzle{
    public:
    Cube cubes[3][3];
    Point empty;
    int manhattanDist;
     
    Puzzle(){
	rep(y, 3) rep(x, 3) cubes[y][x] = Cube();
    }

    void setEmpty( int y, int x ){
        empty.x = x; empty.y = y;
        cubes[y][x].setEmpty();
    }

    void setmanhattanDist(){
        manhattanDist = 0;
	rep(y, 3) rep(x, 3) if ( cubes[y][x].C[0] != target[y][x] ) manhattanDist++;
    }

    void upDate( int y, int x, int d ){
        if ( target[y][x] != cubes[y][x].C[0] ) manhattanDist += d;
    }
};

int ix, iy, tx, ty, limit;
Puzzle u;
static const int dy[4] = {0, -1, 0, 1};
static const int dx[4] = {1, 0, -1, 0};

bool dfs( int depth, int pre, int seq ){
    if ( depth + u.manhattanDist-1 > limit ) return false;
    if ( u.manhattanDist == 0 ) return true;

    int x, y, nx, ny;

    y = u.empty.y;
    x = u.empty.x;

    Puzzle tmp = u;

    for ( int d = 0; d < 4; d++ ){
        if ( pre != -1 && d == (pre+2)%4 ) continue;
        ny = y + dy[d];
        nx = x + dx[d];
        if ( ny < 0 || nx < 0 || 3 <= nx || 3 <= ny ) continue;
        u = tmp;
        u.upDate(ny, nx, -1);
        u.upDate(y, x, -1);
        u.cubes[ny][nx].rotate(d);
        u.cubes[y][x] = u.cubes[ny][nx];
        u.setEmpty(ny, nx);
        u.upDate(ny, nx, 1);
        u.upDate(y, x, 1);

        if ( dfs( depth+1, d, seq) ) return true;
    }

    return false;
}

int compute(){
    Puzzle initial = Puzzle();
    initial.setEmpty(iy, ix);
    initial.setmanhattanDist();
    int start = initial.manhattanDist -1;
    while( start % 3 != 0 ) start--;
    for ( limit = start; limit <= 30; limit+=3 ){
        u = initial;
        if ( dfs(  0, -1, 0 ) ) {
            if ( limit == 0 ) return 0;
            limit -= 2;
            u = initial;
            if ( dfs(0, -1, 0 ) ) {
		return limit;
            } else {
		limit++;
                u = initial;
                if ( dfs(0, -1, 0) ) return limit;
                else return limit+1;
            }
            return 0;
        }
    }
    return -1;
}

main(){
    while(1){
	cin >> ix >> iy;
	if ( ix == 0 && iy == 0 ) return false;
	ix--; iy--;
	rep(y, 3) rep(x, 3){
	    cin >> target[y][x];
	    if ( target[y][x] == 'E' ){ tx = x; ty = y; }
	}
	cout << compute() << endl;
    }
}

Measured memory_bytes: 868
N = int(input())
a = list(map(int, input().split()))

A = 0
B = 0

n = round(N/2+0.1)

while True:
  try:
    A = A + max(a)
    a.pop(a.index(max(a)))
    B = B + max(a)
    a.pop(a.index(max(a)))
  except:
    break

print(A-B)

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

int main()
{
  int64_t N, a, ans = 0;
  cin >> N;
  map<int64_t, int64_t> mp;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    mp[a + i]++;
    ans += mp[i - a];
  }
  cout << ans << endl;
}


Measured memory_bytes: 26220
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
c=gets.split.map(&:to_i)
ans = b.inject(:+)

n.times do |i|
  ans += c[a[i]-1] if a[i]+1 == a[i+1]
end
puts ans


Measured memory_bytes: 1788
def resolve():
    N, T = map(int, input().split())
    c = []
    t = []
    for _ in range(N):
        ca, ta = map(int, input().split())
        c.append(ca)
        t.append(ta)
    ans = []
    for i in range(N):
        if t[i] <= T:
            ans.append(c[i])
    if len(ans) != 0:
        print(c[c.index(min(ans))])
    else:
        print("TLE")
resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int aa;
    string a;
    cin>>a;
    aa=a.length();
    if(aa&1){cout<<"No"<<endl;return 0;}
    for(int i=0;i<aa/2;i++){
        if(a[i]=='p'&&a[aa-i-1]!='q'){
            cout<<"No"<<endl;
            return 0;
        }else
        if(a[i]=='q'&&a[aa-i-1]!='p'){
            cout<<"No"<<endl;
            return 0;
        }else
        if(a[i]=='b'&&a[aa-i-1]!='d'){
            cout<<"No"<<endl;
            return 0;
        }else
        if(a[i]=='d'&&a[aa-i-1]!='b'){
            cout<<"No"<<endl;
            return 0;
        }
    }cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int A,B;
	cin >> A >> B;
	if(B%A == 0) cout << A+B << endl;
	else cout << B-A << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    bool check = true;
    loop(i, n) if (s[i] != t[i]) check = false;
    if (check)
        putout("Yes");
    else
        putout("No");
    return 0;
}


Measured memory_bytes: 3624