akhauriyash/Code-Regression huggingface dataset:
# 最初にでてきたSでフラグ 備蓄がなくなるまでTとペアにしてなくなったらフラグしなおし
ST = input()
flag = False
pool_s = 0
pair = 0
flag = 0
for v in ST:
    if flag == False and v == "S":
        flag = True
        pool_s = 1
    elif flag and v == "T":
        if pool_s > 0:
            pair += 1
            pool_s -= 1
        else:
            pool_s = 0
            flag = False
    elif flag and v == "S":
        pool_s += 1
print(len(ST) - pair * 2)


Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main(void) {
	int H,W;
	cin >> H >> W;
	map<char,int> alpha;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			char c;
			cin >> c;
			++alpha[c];
		}
	}

	bool pali = true;
	if (H%2 == 0 && W%2 == 0) {
		for (int i = 'a'; pali && i <= 'z'; ++i) {
			if (alpha[(char)i]%4 != 0) {
				pali = false;
			}
		}
	}
	else if (H%2 == 0 || W%2 == 0) {
		int lim;
		if (H%2 == 0) {
			lim = H/2;
		}
		else {
			lim = W/2;
		}
		int noft = 0;
		for (int i = 'a'; pali && i <= 'z'; ++i) {
			if (alpha[(char)i]%2 != 0) {
				pali = false;
			}
			else if (alpha[(char)i]%4 != 0) {
				++noft;
				if (noft > lim) {
					pali = false;
				}
			}
		}
	}
	else {
		int noft = 0;
		int lim = (H/2) + (W/2);
		bool odd = false;
		for (int i = 'a'; pali && i <= 'z'; ++i) {
			if (alpha[(char)i]%2 != 0) {
				if (!odd) {
					odd = true;
				}
				else {
					pali = false;
				}
			}
			else if (alpha[(char)i]%4 != 0) {
				++noft;
				if (noft > lim) {
					pali = false;
				}
			}
		}
		if (!odd) {
			pali = false;
		}
	}

	if (pali) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

x = inp()
serach_number = 100003
 
def sieve_of_eratosthenes(target):
    dest = int(math.sqrt(target))
    target_list = list(range(2, target + 1))
    prime_list = []
 
    while True:
        num_min = min(target_list)
        if num_min >= dest:
            prime_list.extend(target_list)
            break
        prime_list.append(num_min)
 
        i = 0
        while True:
            if i >= len(target_list):
                break
            elif target_list[i] % num_min == 0:
                target_list.pop(i)
            i += 1
    return prime_list

data = sieve_of_eratosthenes(serach_number)

for i in data:
    if i >= x:
        print(i)
        break



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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int ans = 0;
	for(int i = 0; i < n - 1; i++){
		if(s.at(i) == s.at(i + 1)) ans++;
	}
	ans = min(ans + 2 * k, n - 1);
	cout << ans << endl;
} 

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n,l;
	cin >> n >> l;
	string x;
	vector<string> v;
	rep(i,1,n)
	{
		cin >> x;
		v.pb(x);
	}
	sort(all(v));
	repp(i,0,n)
	{
		cout << v[i];
	}
	cout << endl;
}


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

#define ul unsigned long long
#define ll long long

int main()
{
  int a,b;//1=min,2=max
  cin>>a>>b;

  int ca,cb,ans=-1;
  for (int i=0;i<=1000;i++) {
    ca=i*8/100;
    cb=i*10/100;
    if (ca==a&&cb==b) {
      ans=i;
      break;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll res = 0;
    repr(i,1,n+1) {
        if (i%3!=0 && i%5!=0) {
            res += i;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3640
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const int MX = 100 * 1000 + 7;

ll dp[MX];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n, w;
    cin >> n >> w;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = w; j >= a; j--) {
            dp[j] = max(dp[j], dp[j - a] + b);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= w; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int K = in.nextInt();
      	int N = in.nextInt();
       	int[] A = new int[N];
       	int max = 0;
       	int remainder = 0;
       	int actualMax = 0;
       	
       	for(int i = 0; i<N; i++) {
       		A[i] = in.nextInt();
       		if (i > 0) {
           		max = Math.max(A[i]-A[i-1], max);
       		}
       	}
   		remainder = K-A[N-1]+A[0];
       	actualMax = Math.max(max, remainder);
       	
       	System.out.println(K-actualMax);
       	
	}
}


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

int main() {
    int r, c;
    int excel[101][101];
    for (int i=0; i<101;i++)
        for (int j=0; j<101; j++) excel[i][j] = 0;

    cin >> r >> c;
    for (int i=0; i<r; i++) {
        for (int j=0; j<c; j++) {
            cin >> excel[i][j];
            int point = excel[i][j];
            excel[i][c] += point;
            excel[r][j] += point;
            excel[r][c] += point;
        }
    }

    for (int i=0; i<=r; i++) {
        for (int j=0; j<=c; j++) {
            cout << excel[i][j];
            if ( j != c ) cout << " ";
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 1200
N = int(input())
c = input()

right = N-1
left = 0
cnt = 0
for i in range(N):
    if right <= left:
        break
        
    if c[right] == "W":
        right -= 1
    else:
        if c[left] == "R":
            left += 1
        # 交換
        else:
            cnt += 1
            left += 1
            right -= 1

print(cnt)

Measured memory_bytes: 9416
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b, c;
		cin >> a >> b >> c;
		if (a + b < a + c && a + b < b + c) {
			cout << a + b;
	}
		else if (a + c < a + b && a + c < b + c) {
			cout << a + c;
		}
		else {
			cout << b + c;
		}
}

Measured memory_bytes: 256
#include <list>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

int pos;

bool parse(string s) {
	switch(s[pos]) {
	case 'T':
		++pos;
		return true;
	case 'F':
		++pos;
		return false;
	case '-':
		++pos;
		return !parse(s);
	case '(':
		++pos;
		bool a = parse(s);
		char op = s[pos];
		++pos;
		if(op == '-')
			++pos;
		bool b = parse(s);
		++pos;
		switch (op) {
		case '*':
			return a&&b;
		case '+':
			return a||b;
		case '-':
			return !a||b;
		}
	}
}

int main() {
	string str;
	while(cin >> str, str != "#") {
		set<char> cha;
		REP(i, str.size()) {
			if(islower(str[i]))
				cha.insert(str[i]);
		}
		int size = cha.size();

		map<int, char> m;
		int count = 0;
		set<char>::iterator it = cha.begin();
		while(it != cha.end()) {
			m[count] = *it;
			++count;
			++it;
		}

		REP(i, 1<<size) {
			string s = str;
			REP(j, size) {
				if(i&(1<<j)) {
					REP(k, s.size()) {
						if(s[k] == m[j]) {
							s[k] = 'T';
						}
					}
				} else {
					REP(k, s.size()) {
						if(s[k] == m[j]) {
							s[k] = 'F';
						}
					}
				}
			}
					
			string left = s.substr(0, s.find("="));
			string right = s.substr(s.find("=")+1, s.size()-1);
			
			pos = 0;
			bool l = parse(left);
			pos = 0;
			bool r = parse(right);
			if(l != r) {
				cout << "NO" << endl;
				goto next;
			}
		}

		cout << "YES" << endl;
next:
		;
	}

	return 0;
}

Measured memory_bytes: 2292
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <ctime>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define bug cout<<88888888<<endl;
#define MIN(x,y) (x<y?x:y)
#define MAX(x,y) (x>y?x:y)

int N;
struct Edge{
    int u,v;
    int next;
}edge[MaxM];
int cont;
int head[MaxN];
void init()
{
    cont = 0;
    MST(head,-1);
}
void add(int u, int v)
{
    edge[cont].u = u;
    edge[cont].v = v;
    edge[cont].next = head[u];
    head[u] = cont++;
}

int DFS(int u)
{
    vector<int> V;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        int v = edge[i].v;
        V.push_back(DFS(v));
    }
    int ans;
    if(V.size()==0) ans = 0;
    else
    {
        sort(V.begin(), V.end());
        int Max = 0;
        for(int i=0;i<V.size();i++)
        {
            //cout << i << ":" << V[i] << endl;
            V[i]+=(V.size()-i);
            Max = MAX(Max, V[i]);
        }
        ans = Max;
    }
    V.clear();
    return ans;
}
int main()
{
    while(~scanf("%d", &N))
    {
        init();
        for(int i=2;i<=N;i++)
        {
            int x;
            scanf("%d", &x);
            add(x,i);
        }
        int ans = DFS(1);
        printf("%d\n", ans);
    }
    //system("pause");
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 2e5 + 10;
const int maxK = 1e4+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1e9+7;

pii a[maxN];
vector<int> to[10];
int main()
{
	int n;
	cin>>n;
	if(n >= 30)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++) cin>>a.at(i);
  sort(a.begin(),a.end());
  cout<<a.at(0)+a.at(1)+a.at(2)*10<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String ans = "No";
        if(n%10==9||n/10==9)ans = "Yes";
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
use std::collections::HashSet;

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let s: HashSet<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let r: HashSet<i32> = [1, 9, 7, 4].iter().cloned().collect();
    println!("{}", if s == r { "YES" } else { "NO" })
}


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


int main() {
  int group[] = {1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin >> x >> y;
  if(group[x-1]==group[y-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

constexpr int inf = 1e9;

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

    vector<int> dp(h + 1, inf);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < h; ++j) {
            const int nxt = min(h, j + a[i]);
            dp[nxt] = min(dp[nxt], dp[j] + b[i]);
        }
    }

    cout << dp.back() << endl;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A = A.reshape((int(N/2), 2))[:,0] if N % 2 == 0 else np.append(A, 2, 100).reshape((int((N+1)/2), 2))[:, 0]
print((A % 2 == 1).sum())

Measured memory_bytes: 27172
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

n = int(input())
A = inpl()
mod = 10**9 + 7

fct = [1]
inv = [1]

for i in range(1, n+2):
    fct.append((fct[-1]*i)%mod)
    inv.append((pow(fct[i], mod-2, mod)))

def comb(n, k):
    if k < 0 or k > n:
        return 0
    return (fct[n] * inv[n - k] * inv[k]) % mod    

C = ["" for i in range(n+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
        break
    else:
        C[a] = l

print(n)

for k in range(2, n+2):
    total = comb(n+1, k)
    b = comb(n+i-j, k-1)
    res = (total-b)%(mod)
    print(res)

Measured memory_bytes: 21024
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>

#define mii map<int,int>
#define int long long
#define inf 2000000000000000000
#define re(i,x,n) for(i=x;i<=n;i++)
typedef long long ll;
using namespace std;
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
struct edge
{
	int a;
	int b;
	int w;
};
edge ar[100000];
int par[10001];
bool comp(edge a, edge b)
{
	if (a.w < b.w)
		return true;
	else
		return false;
}
int find(int a)
{
	if (par[a] == -1)
		return a;
	else
		return par[a] = find(par[a]);
}
void merge(int a, int b)
{
	par[a] = b;
}
void Sieve(int  n)
{
	int i;
	bool primes[n + 1];
	memset(primes, true, sizeof(primes));
	int j;
	for (i = 2; i * i <= n; i++)
	{
		if (primes[i])
		{
			for (j = i * i; j <= n; j += i)
				primes[j] = false;
		}
	}
	int a[n + 1];
	int k = -1;
	for (i = 2; i <= n; i++)
		if (primes[i]) {
			//cout << i << " ";
			a[++k] = i;
		}
//	cout << endl;
	int count = 0;


	int r = 0;
	bool be = false;
	for (i = 6; i <= n; i++)
	{
		for (j = 0; j <= k; j++)
		{
			if (i % a[j] == 0)
				count++;
			if (count == 2) {

				be = true;
				break;
			}
		}
		if (be) {
			r++;

			be = false;
		}
		count = 0;
	}
	// cout << endl;
	cout << r << endl;

}

int32_t main()
{

	//c_p_c();
	string s, t;
	cin >> s >> t;
	int count = 0;
	int i;
	for (i = 0; i < s.length(); i++)
	{
		if (s[i] != t[i])
			count++;
	}
	cout << count << endl;

}

Measured memory_bytes: 3924
#include<stdio.h>
long long int gcd(long long int a, long long int b)
{
	long long int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main()
{
	long long int a, b;
	scanf("%lld %lld", &a, &b);
	printf("%lld\n", a / gcd(a, b) * b);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

int main()
{
  int N, K; cin >> N >> K;
  ++N;
  ll ans = 0;
  ll s = K;

  repe(i, K, N){
    ans += (N - (s - 1)) * s - (s - 1);
    ans %= MOD;
    ++s;
  }

  cout << ans << endl;

}



Measured memory_bytes: 3604
N,H = map(int,input().split())
ab = [tuple(map(int,input().split())) for i in range(N)]

maxa = max(ab)[0]
ans = 0
for a,b in sorted(ab, key=lambda x:x[1], reverse=True):
    if b <= maxa:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

ans += (H-1)//maxa + 1
print(ans)


Measured memory_bytes: 18840
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
    cin >> n >> s;
    char tar = s.at(0);
    s += "!";
    int cnt = 1;
    for(int i = 1; i < n; ++i) {
        if(tar != s.at(i)) {
            cnt++;
            tar = s.at(i);
        }
    }
    cout << cnt << endl;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N,M;
    cin >> N >> M;

    vector<i64> x(N),y(N),z(N);
    vector<int> idx;
    rep(i,0,N){
        cin >> x[i] >> y[i] >> z[i];
        idx.push_back(i);
    }

    i64 ans=0;
    rep(i,0,1<<3){
        i64 p=(i&1)?-1:1,q=(i&2)?-1:1,r=(i&4)?-1:1;
        sort(rbegin(idx),rend(idx),[&](int a,int b){ return p*x[a]+q*y[a]+r*z[a]<p*x[b]+q*y[b]+r*z[b]; });

        i64 s=0,t=0,u=0;
        rep(j_,0,M){
            int j=idx[j_];
            s+=x[j];
            t+=y[j];
            u+=z[j];
        }
        ans=max(ans,abs(s)+abs(t)+abs(u));
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000009
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    { 
      int n;
      cin>>n;
      int x=n/500;
     // cout<<x<<" ";
      int ans=0;
      ans+=x*1000;
      
      int xx=n-(x*500);
    //  cout<<xx<<" ";
      xx=xx/5;
      
      ans+=xx*5;
      cout<<ans;
       
    }
}

    
// 🍪 🍪 🍪


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

constexpr long long INF = 0xffffffffffff;

class union_find {
private:
	vector<int> uf;
	vector<long long> pd;

public:
	union_find(int n):uf(n, -1), pd(n, 0) {}
	
	inline int find(int x) {
		if(uf[x] < 0)
			return x;

		const int tmp = uf[x];
		uf[x] = find(uf[x]);
		pd[x] += pd[tmp];
		return uf[x];
	}

	inline void unite(int xx, int yy, int d) {
		int x = find(xx), y = find(yy);
		if(x == y)
			return;
		
		d += pd[yy] - pd[xx];
		if(uf[x] < uf[y]) {
			swap(x, y);
			d = -d;
		}

		else if(uf[x] == uf[y])
			--uf[y];
		
		uf[x] = y;
		pd[x] = d;
	}
	
	inline bool same(int x, int y) {
		return find(x) == find(y);
	}

	inline long long get_dist(int x, int y) {
		return same(x, y) ? pd[x] - pd[y] : INF;
	}
};


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

	for(int n, m; cin >> n >> m && n;) {
		union_find uf(n);
		for(int i = 0; i < m; ++i) {
			char q;
			int a, b;
			cin >> q >> a >> b;

			if(q == '!') {
				int d;
				cin >> d;
				uf.unite(a - 1, b - 1, d);
			}
			else {
				const long long ans = uf.get_dist(a - 1, b - 1);
				if(ans == INF)
					cout << "UNKNOWN" << endl;
				else
					cout << ans << endl;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2380
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

struct State {
  int from;
  int to;
  State(int f,int t)
    : from(f),to(t) {}
};

void matrix_pow(const bool A[101][101],const bool B[101][101],
                bool C[101][101],int length){
  bool tmp[101][101] = {};
  for(int i = 0; i < length; i++){
    for(int j = 0; j < length; j++){
      bool sum = false;
      for(int k = 0; k < length; k++){
        sum |= (A[i][k] && B[k][j]);
      }
      tmp[i][j] = sum;
    }
  }
  memcpy(C,tmp,sizeof(bool)*101*101);
}

void fast_pow(int n,int length,bool A[101][101],bool C[101][101]) {
  for(int i = 0; i < length; i++){
    C[i][i] = 1;
  }
  while(n > 0) {
    if (n & 1){
      matrix_pow(C,A,C,length);
    }
    matrix_pow(A,A,A,length);
    n >>= 1;
  }
}

void disp(bool matrix[101][101]){
  for(int y = 0; y < 10; y++){
    for(int x = 0; x < 10; x++){
      printf("%d ",matrix[y][x]);
    }
    printf("\n");
  }
  printf("\n");
}

int main(){
  int total_stations;
  int total_sections;
  int total_steps;
  while(~scanf("%d %d %d",
               &total_stations,
               &total_sections,
               &total_steps)){
    if(total_stations == 0 && total_sections == 0 && total_steps == 0) break;
    vector<int> edge[101];
    for(int section_i = 0; section_i < total_sections; section_i++){
      int src,dst;
      scanf("%d %d",&src,&dst);
      src--; dst--;
      edge[src].push_back(dst);
      edge[dst].push_back(src);
    }

    vector<State> states;
    states.push_back(State(-1,0));
    for(int from = 0; from < total_stations; from++){
      for(int i = 0; i < edge[from].size(); i++){
        int to = edge[from][i];
        states.push_back(State(from,to));
      }
    }

    bool init_matrix[101][101] = {};
    for(int y = 0; y < states.size(); y++){
      for(int x = 0; x < states.size(); x++){
        if(states[y].to == states[x].from
           && states[y].from != states[x].to){
          init_matrix[y][x] = true;
        }
      }
    }

    bool result_matrix[101][101] = {};
    fast_pow(total_steps,states.size(),init_matrix,result_matrix);

    bool isok = false;
    for(int i = 0; i < states.size(); i++){
      if(states[i].to == total_stations - 1 && result_matrix[0][i]){
        isok = true;
        break;
      }
    }
    // disp(result_matrix);
    printf("%s\n",isok ? "yes" : "no");
  }
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll inf=1LL<<50;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,Ans=INF;
	cin>>N;
	vector<int> w(N);
	for(int i=0;i<N;i++) cin>>w[i];
	for(int i=1;i<N;i++){
		int a=0,b=0;
		for(int j=0;j<i;j++) a+=w[j];
		for(int j=i;j<N;j++) b+=w[j];
		Ans=min(Ans,abs(a-b));
	}
	cout<<Ans<<endl;
	return 0;
}

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

int main() {
  int a;
  string b;
  cin>>a>>b;
  int c=0;
  for(int i=0;i<a-2;i++){
    if(b.at(i)=='A'&&b.at(i+1)=='B'&&b.at(i+2)=='C'){
      c++;
    }
  }
  cout<<c<<endl;
}

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

void solve(long long N){
	map<int,int> mp;
	for(int i = 2; i * (i - 1) / 2 <= N; ++i) {
		if(i * (i - 1) / 2 == N) {
			vector<vector<int>> a(i);
			int cnt = 1;
			for(int j = 0; j < i; ++j) {
				for(int k = j + 1; k < i; ++k) {
					a[j].push_back(cnt);
					a[k].push_back(cnt);
					++cnt;
				}
			}
			cout << "Yes" << endl;
			cout << i << endl;
			for(int j = 0; j < i; ++j) {
				cout << a[j].size();
				for(auto k: a[j]) {
					cout << " " << k;
				}
				cout << endl;
			}
			return;
		}
	}
	cout << "No" << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
// #include<string.h>
int main(){
    ll n;
    string s;
    cin>>n>>s;
    ll ans = 1;
    ll idx = 0;
    repl(i,1,n) if(s[idx]!=s[i]){
        idx = i;
        ans++;
    } 
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var centerIndex = s.Length / 2;

            var s1 = s.Substring(0, centerIndex);
            var s2 = s.Substring(centerIndex);

            Console.WriteLine(s1 == s2 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <bitset>
#include <queue>
using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> p(n);
    int count[3] = {0, 0, 0};
    for (int i=0; i<n; ++i){
        cin >> p[i];
    }
    for (int i=0; i<n; ++i){
        if(p[i] <= a){
            count[0]++;
        }
        else if(p[i] <= b){
            count[1]++;
        }
        else {
            count[2]++;
        }
    }
    int ans = min(min(count[0], count[1]), count[2]);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,h;
	cin >> h >> n;
	vector<int> dp(h + 1,1e9);
	dp[0] = 0;
	for (int i = 0;i < n;++i) {
		int a,b;
		cin >> a >> b;
		for (int j = 0;j <= h;++j) {
			dp[min(a + j,h)] = min(dp[min(a + j,h)],dp[j] + b);
		}
	}
	cout << dp[h];
}

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

int node;

string S;
vector<int> G[100005];

void solve(int root, int pos)
{
    if(pos < 0)
        return;
    
    if(pos == 0)
    {
        while(node < S.size() + 1) {
            node++;
            G[root].push_back(node);
        }
        return;
    }
    
    int indx = pos - 1;
    
    while(S[indx] == '0')
        indx--;
    
    while(S.size() + 1 - node > indx + 1)
    {
        node++;
        G[root].push_back(node);
    }
    
    node++;
    G[root].push_back(node);
    solve(node, indx);
}

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    cin >> S;
    
    if(S.back() == '1' || S[0] == '0')
    {
        cout << -1 << "\n";
        return 0;
    }
    
    S.pop_back();
    
    for(int i=0, j=S.size()-1; i <= j; i++, j--)
    {
        if(S[i] != S[j])
        {
            cout << -1 << "\n";
            return 0;
        }
    }
    
    node = 1;
    solve(1, S.size()-1);
    
    for(int i=1; i<=node; i++)
        for(auto x : G[i])
            cout << i << " " << x << "\n";
    
    return 0;
}

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

int main()
{
	int x1,x2,x3=0,x4=0; 
	int y1,y2,y3=0,y4=0; 
	cin>>x1>>y1>>x2>>y2;

	int x = x2-x1, y= y2-y1;

	cout<<x2-y<<" "<<y2+x<<" "<<x1-y<<" "<<y1+x;
	

	




	 
}		

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


int main(){
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		v.pb(temp);
	}
	sort(v.begin(),v.end());
	cout<<v[n/2] -v[n/2-1];
    
    return 0;
}


Measured memory_bytes: 892
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
D,X = readInts()
ans = 0
for i in range(n):
    a = I()
    ans += (D//a)+1 if D%a else D//a
print(X+ans)


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

int main(){
    int N;
    int64_t ans = 1;
    cin >> N;
    for (int i = 1; i <= N; i++){
        ans *= i;
        ans %= 1000000007;
    }
    
    cout << ans << endl;
    
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    PRINT(a[K - 1]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using LL = long long;
using namespace std;
#define DBG(x) cerr<<#x<<" = "<<x<<endl
#define rep(i,n) for(int i=0;i<(n);++i)

int a[9];

int main() {
	rep(i, 9) cin >> a[i];
	
	vector<int>p;
	int ans = 0;
	rep(i, 9) p.push_back(i + 1);
	do
	{
		int num1, num2, num3, num4;
		num1 = p[0];
		num2 = p[1] * 10 + p[2];
		num3 = p[3] * 100 + p[4] * 10 + p[5];
		num4 = p[6] * 100 + p[7] * 10 + p[8];
		if (num1 + num2 + num3 == num4)
		{
			bool flag = true;
			rep(i, 9)
			{
				if (a[i] != -1 && a[i] != p[i])
				{
					flag = false;
					break;
				}
			}
			if (flag) ++ans;
		}
	} while(next_permutation(p.begin(), p.end()));
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,tmp;
    cin>>n;
    vector<int> f(n,0);
    vector<vector<int>> p(n,vector<int>(11,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>tmp;
            f[i]=f[i]*2+tmp;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>p[i][j];
        }
    }
    int count=0;
    int max=-1000000000;
    for(int i=1;i<1024;i++){
        for(int j=0;j<n;j++){
            tmp=__builtin_popcount(f[j]&i);
            count+=p[j][tmp];
        }
        if(count>max){
            max=count;
        }
        count=0;
    }
    cout<<max<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

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;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int x[10][10];

int main() {

    string s;
    cin >> s;
    rep(i, s.size()) {
        if (i % 2 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        } else if (i % 2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 20000
#define N 40005
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef long long ll;
const int DAT_SIZE=(1<<18)-1;
int X=N;
ll data[DAT_SIZE],datb[DAT_SIZE];

void add(int a,int b,int x,int k,int l,int r){
  if(a<=l&&r<=b)data[k]+=x;
  else if(l<b&&a<r){
    datb[k]+=(min(b,r)-max(a,l))*x;
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
}

ll sum(int a,int b,int k,int l,int r){
  if(b<=l||r<=a)return 0;
  else if(a<=l&&r<=b)
    return data[k]*(r-l)+datb[k];
  else{
    ll res=(min(b,r)-max(a,l))*data[k];
    res+=sum(a,b,k*2+1,l,(l+r)/2);
    res+=sum(a,b,k*2+2,(l+r)/2,r);
    return res;
  }
}

int n,x[N],y[N],a,b,xmax,xmin,ymax,ymin;
vector<P1> L[N];
set<int> Y;

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
      x[i]+=M;
      y[i]+=M;
      Y.insert(y[i]);
    }
    for(int i=0;i<n;i++){
      if(y[i]!=y[(i+1)%n])continue;
      if(x[i]<x[(i+1)%n])
	L[y[i]].push_back(P1(P(x[i],x[(i+1)%n]),1));
      else
	L[y[i]].push_back(P1(P(x[(i+1)%n],x[i]),-1));
    }
    xmax=ymax=0;
    xmin=ymin=(1e9);
    for(int i=0;i<4;i++){
      cin>>a>>b;
      a+=M;
      b+=M;
      xmax=max(xmax,a);
      xmin=min(xmin,a);
      ymax=max(ymax,b);
      ymin=min(ymin,b);
      Y.insert(b);
    }
    for(int i=0;i<X;i++)
      add(i,i+1,0,0,0,X);
    set<int>::iterator ite=Y.begin();
    int ans=0,py=(*ite),S=0;
    while(ite!=Y.end()){
      ans+=S*((*ite)-py);
      py=(*ite);
      for(int i=0;i<L[(*ite)].size();i++){
	int s=L[(*ite)][i].first.first;
	int g=L[(*ite)][i].first.second;
	add(s,g,L[(*ite)][i].second,0,0,X);
      }
      if(ymin<=(*ite)&&(*ite)<ymax)
	S=sum(0,xmin,0,0,X)+sum(xmax,X,0,0,X);
      else S=sum(0,X,0,0,X);
      ite++;
    }
    cout<<ans<<endl;
    for(int i=0;i<DAT_SIZE;i++)
      data[i]=datb[i]=0;
    for(int i=0;i<N;i++)L[i].clear();
    Y.clear();
  }
  return 0;
}

Measured memory_bytes: 8148
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main (){
    ll N, L[2]{};
    cin >> N;
    set <int> S;
    while (cin >> N) {
        if (!S.insert(N).second) {
            S.erase(N);
            if (N > L[0]){
                L[1] = L[0], L[0] = N;
            }
            else if(N > L[1]){
                L[1] = N;
            }
        }
    }
    cout << L[0] * L[1] << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {

    ll N; 
    cin >> N;

    vector<pi > ab;
    vector<pi > cd;

    for(ll i = 0; i < N; i++){
        ll a, b; cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }

    for(ll i = 0; i < N; i++){
        ll a, b; cin >> a >> b;
        cd.push_back(make_pair(a, b));
    }

    //sort(ab.begin(), ab.end());
    sort(cd.begin(), cd.end());

    ll ans = 0;
    pi t_pair = make_pair(-1, -1);

    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < N; j++){
            if(cd[i].first > ab[j].first && ab[j].first >= 0){
                if(cd[i].second > ab[j].second){
                    if(t_pair.first < ab[j].second){
                        t_pair = make_pair(ab[j].second, j);
                    }
                }
            }
        }

        //ペア決定
        if(!(t_pair.first == -1)){
            ans++;
            //ペアにしたやつはもうペアにしない
            ab[t_pair.second].first = -1;
            ab[t_pair.second].second = -1;
            t_pair = make_pair(-1, -1);
        }

    }



    cout << ans<< endl;

}

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

// 頂点s+1から出発する場合の幅優先探索
void bfs(int s, int n, vector<vector<int> >& M, vector<int>& d) {
    static const int INFTY = (1 << 21);

    // 今回は標準ライブラリのキューを使う
    queue<int> q;

    // 各種初期化処理
    // 出発する頂点をpush
    q.push(s);
    // 距離格納配列の初期化
    for (int i = 0; i < n; ++i) {
        d[i] = INFTY;
    }
    // 出発点の距離は0
    d[s] = 0;

    // 探索開始
    int u;
    while (!q.empty()) {
        // 先頭を取り出してpopする(訪問)
        u = q.front();
        q.pop();

        // 隣接する訪問可能な頂点をpushする
        for (int v = 0; v < n; ++v) {
            if (M[u][v] == 0) continue;   //訪問不可
            if (d[v] != INFTY) continue;  //訪問済み

            d[v] = d[u] + 1;  //今回リンクのコストは1固定
            q.push(v);
        }
    }

    // 頂点1から各頂点までの距離を出力
    // INFTYが入っていた場合は到達不可能なので-1を出力
    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    static const int N = 110;
    // n : グラフの頂点数
    // M : 隣接行列(グラフを表現)
    // d : 任意の頂点から各頂点への距離格納配列(INFTYで初期化)
    int n, u, k, v;
    vector<int> d(N);
    vector<vector<int> > M(N, vector<int>(N));

    cin >> n;

    // グラフの初期化
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            M[i][j] = 0;
        }
    }
    // グラフの入力
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        --u;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            --v;
            M[u][v] = 1;
        }
    }

    bfs(0, n, M, d);

    return 0;
}


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

 const long long int mod=1e9+7;


 long long int dfs(int K,const vector<vector<int>>&graph, int now,int from) {

 int can_use_color_num;
 if (from==-1) {
 can_use_color_num=K-1;
 }
 else {
 can_use_color_num=K-2;
 }
 if (K<graph[now].size()) {
 return 0;
 }
 else {
 long long int case_num=1;
 for (auto e : graph[now]) {
 if(e==from)continue;

 case_num*=can_use_color_num;
 can_use_color_num--;
 case_num%=mod;
 }
 for (auto e : graph[now]) {
 if(e==from)continue;
 case_num *=dfs(K,graph,e,now);
 case_num %= mod;
 }
 return case_num;
 }
 }



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

 vector<vector<int>>graph(N);
 for (int i = 0; i < N - 1; ++i) {
 int a,b;cin>>a>>b;a--;b--;

 graph[a].push_back(b);
 graph[b].push_back(a);
 }

 long long int answer=K*dfs(K,graph,0,-1);
 answer%=mod;
 cout<<answer<<endl;
 return 0;
 }

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

struct UnionFind {
    vector<ll> par;  // par[i]: parent of i
    vector<ll> siz;

    UnionFind(ll N) : par(N + 1), siz(N + 1, 1ll) {  // initialize by making every node a root node
        for (int i = 0; i <= N; i++) par[i] = i;
    }

    ll root(ll x) {  // find the root of a given node
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return;
    }

    bool issame(ll x, ll y) {  // return true if x and y belong to the same tree
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};


unordered_set<int> friends_adj[100100];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uftree(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uftree.unite(a, b);
        friends_adj[a].insert(b);
        friends_adj[b].insert(a);
    }
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        if (uftree.issame(c, d)) {
            friends_adj[c].insert(d);
            friends_adj[d].insert(c);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << uftree.size(i) - friends_adj[i].size() - 1 << " ";
    }
    cout << endl;
}


Measured memory_bytes: 26752
#include <iostream>

using namespace std;

int main(){

  int command_count = 0;
  int plus_num = 0;
  
  cin >> command_count >> plus_num;
  
  int now_number = 1;
  
  for(int i = 0;i < command_count;i++){
  
    if(now_number * 2 < now_number + plus_num){
    
      now_number *= 2;
      
    }else{
    
      now_number += plus_num;
    
    }
    
  }
  
  cout << now_number << endl;
  
  
  return 0;

}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }else{
        cout << "a > b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#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;

/*
<url:https://agc003.contest.atcoder.jp/tasks/agc003_b>
問題文============================================================
 高橋君は 1 から N までの整数のうちのどれかが書かれたカードをたくさん持っています。
 高橋君は整数 i が書かれたカードを Ai 枚持っています。
 
 2 枚のカードについて、それらに書かれた整数の差の絶対値が 1 以下のとき、これらをペアにすることができます。
 
 高橋君は、同じカードが複数のペアに使われないように、できるだけ多くのペアを作りたいです。
 高橋君が作れるペアの個数の最大値を求めてください。
 
=================================================================

解説=============================================================
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N);
    for(auto&in:A) cin >> in;
    vector<ll> tA(A);
    
    ll cntl = 0;
    for(int i = 0; i < N - 1;i++){
        cntl += A[i]/2;
        A[i] -= A[i]/2 * 2;
        ll minv = min(A[i],A[i+1]);
        cntl += minv;
        A[i] -= minv; A[i+1] -= minv;
    }
    cntl += A[N-1]/2;
    
    A = tA;
    
    ll cntr = 0;
//    for(int i = N - 1; i > 0; i--){
//        cntr += A[i]/2;
//        A[i] -= A[i]/2 * 2;
//        ll minv = min(A[i],A[i-1]);
//        cntr += minv;
//        A[i] -= minv; A[i-1] -= minv;
//    }
//    cntr += A[0]/2;
    cout << max(cntl,cntr) << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main(){
 long long x,k,d;
 cin >> x >> k >> d;
  x = abs(x);
  long long straight = min(k,x/d);
  k -= straight;
  x -= straight*d;
  if(k%2==0){
     cout << x << endl;
  }else{
     cout << d-x << endl;
  }
  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  bitset<8>bs;
  int fr = 0;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
    x /= 400;
    if(x >= 8)fr++;
    else bs[x] = 1;
  }
  int sum = 0;
  for(int i = 0; i < 8; ++i)sum += bs[i];
  if(fr == 0){
    cout << sum << ' ' << sum << endl;
  } else {
    cout << max(sum,1) << ' ' << sum + fr << endl;
  }
}



Measured memory_bytes: 3656