akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n;
	while (cin >> n, n)
	{
		vector<pair<string, string>> v;
		REP(i, n)
		{
			string s, t;
			cin >> s >> t;
			v.emplace_back(s, t);
		}
		string from, to; cin >> from >> to;
		queue<pair<string, int>> que;
		que.push(make_pair(from, 0));
		set<string> st;
		st.insert(from);
		bool f = true;
		while (que.size())
		{
			string tmp = que.front().first;
			int cnt = que.front().second;
			que.pop();
			if (tmp == to)
			{
				f = false;
				cout << cnt << endl;
				break;
			}
			REP(i, n)
			{
				string t;
				REP(j, tmp.size())
				{
					if (j< tmp.size() - v[i].first.size() + 1 &&
						tmp.substr(j, v[i].first.size()) == v[i].first)
					{
						j += v[i].first.size() - 1;
						t += v[i].second;
					}
					else t += tmp[j];
				}
				if (t.size()>to.size()||st.count(t)) continue;
				st.insert(t);
				que.push(make_pair(t, cnt + 1));
			}
		}
		if (f) puts("-1");
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> bit(60);
	REP(i, N) {
		ll a;
		cin >> a;
		REP(j, 60) {
			bit[j] += (a & 1);
			a >>= 1;
		}
	}

	ll X = 0;
	ll res = 0;
	for (ll j = 50; j >= 0; j--) {
		ll tmp = (1ll << j);
		if (bit[j] < N - bit[j] && X + tmp <= K) {
			X += tmp;
			res += (N - bit[j])*tmp;
		}
		else {
			res += bit[j] * tmp;
		}
	}
	cout << res << endl;

	return 0;
}


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

using namespace std;

int main() {
    while (true) {
        int a, b;
        char op;
        cin >> a >> op >> b;
        if (op == '?') {
            break;
        }
        if (op == '+') {
            cout << a + b << '\n';
        }
        else if (op == '-') {
            cout << a - b << '\n';
        }
        else if (op == '*') {
            cout << a * b << '\n';
        }
        else {
            cout << a / b << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    vector<string> v{"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin>>s;
    int index;
    for(int i=0;i<7;i++){
        if(v[i]==s){
            index=i;
        }
    }
    cout<<7-index<<endl;
    return 0;
}

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

ll N, M, W[100000], cnt[100000];
vector<ll> E[100000], candidate;
bool visited[100000], check[100000];

void dfs_candidate(ll v) {
  visited[v] = true;
  for(ll u : E[v]) if(!visited[u]) {
    if(!check[v] && check[u]) candidate.push_back(u);
    else dfs_candidate(u);
  }
}

ll dfs(ll v) {
  ll ret = 0;
  visited[v] = true;
  for(ll u : E[v]) if(!visited[u]) ret = max(ret, dfs(u));
  return ret + W[v];
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, N) cin >> W[i];
  REP(i, 0, M) {
    ll U, V; cin >> U >> V; U--; V--;
    E[U].push_back(V);
    E[V].push_back(U);
  }

  queue<ll> q;
  REP(i, 0, N) cnt[i] = E[i].size();
  REP(i, 1, N) if(cnt[i] == 1) q.push(i);
  REP(i, 0, N) check[i] = false;
  while(q.size()) {
    ll v = q.front();
    q.pop();
    if(v == 0) continue;
    check[v] = true;
    for(ll u : E[v]) if(--cnt[u] == 1) q.push(u);
  }

  REP(i, 0, N) visited[i] = false;
  dfs_candidate(0);

  ll ans = 0;
  REP(i, 0, N) visited[i] = false;
  REP(i, 0, N) if(!check[i]) visited[i] = true;
  for(ll v : candidate) ans = max(ans, dfs(v));
  REP(i, 0, N) if(!check[i]) ans += W[i];
  cout << ans << endl;
}


Measured memory_bytes: 15048
#include <iostream>
using namespace std;
int main(void){
    long n;
    long sum=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        if(i%3!=0){
            if(i%5!=0){
                sum+=i;
            }
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3620
n,m,x=map(int, input().split())
c=[0]*n
for i in range(n):
    c[i]=list(map(int, input().split()))

ans=10**7
for i in range(2**n):
    cost=0
    res=[0]*m
    for j in range(n):
        if ((i >> j) & 1):
            for k in range(m):
                res[k]+=c[j][k+1]
            cost+=c[j][0]
    for j in range(m):
        if res[j]<x:
            break
        if res[j]>=x and j==m-1:
            if cost<ans:
                ans=cost
if ans==10**7:
    print('-1')
else:
    print(ans)

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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  int p;
  int count = 0;
  int min = 2 * 1e5;
  for (int i = 0; i < n; ++i) {
    std::cin >> p;
    min = std::min(min, p);
    if (p <= min)
      ++count;
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int cnt1[5],cnt2[5];
int n;
const double eps=1e-8; 
int be[5],ed[5]; 
int change(int h,int m){
	if (h*60+m<120) return h*60+m+24*60;
	else return h*60+m; 
}
void init(){
	be[0]=11*60;ed[0]=14*60+59;
	be[1]=18*60;ed[1]=20*60+59;
	be[2]=21*60;ed[2]=60+59+24*60; 
} 
int main()
{
	init();	
	int h,m1,m2; 
	while (~scanf("%d",&n),n)
	{
		memset(cnt1,0,sizeof(cnt1));
		memset(cnt2,0,sizeof(cnt2)); 
		for (int i=0;i<n;i++){
			scanf("%d:%d%d",&h,&m1,&m2);
			int t=change(h,m1); 
			for (int j=0;j<3;j++){
				if (be[j]<=t && t<=ed[j]) 
				{
					cnt1[j]++;
					if (m1>m2) m2+=60;
					if (m2-m1<=8) cnt2[j]++; 
					break; 
				} 
			} 	
		} 
		if (cnt1[0]) 
		printf("lunch %d\n",(int)((cnt2[0]*1.0/cnt1[0]+eps)*100));
		else printf("lunch no guest\n");
 		if (cnt1[1]) 
		printf("dinner %d\n",(int)((cnt2[1]*1.0/cnt1[1]+eps)*100));
		else printf("dinner no guest\n");
		if (cnt1[2]) 
		printf("midnight %d\n",(int)((cnt2[2]*1.0/cnt1[2]+eps)*100));
		else printf("midnight no guest\n");
	}				
	return 0; 
} 

Measured memory_bytes: 1196
#D
n = int(input())
a = list(map(int,input().split()))

box = [0 for _ in range(n)]
result = []
def baisu(n,max_n):
    ans = []
    cnt = 1
    while n*cnt <= max_n:
        ans.append(n*cnt)
        cnt += 1  
    return ans

for i in range(n-1,-1,-1):
    if i+1 > n//2:
        box[i] = a[i]
        
    else:
        num = baisu(i+1,n)
        tmp = 0
        for j in num:
            tmp += box[j-1]
        if tmp % 2 == a[i]:
            box[i] = 0
            
        else:
            box[i] = 1
            
for i,j in enumerate(box):
    if j == 1:
        result.append(i+1)
        
if result == []:
    print(0)
else:
    print(len(result))
    print(*result)

Measured memory_bytes: 21684
n = int(input())
a,b,c = list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
ans = sum(b)
for i in range(n-1):
  if a[i] == a[i+1]-1:
    ans += c[a[i]-1]
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
	int a, b, d, r;
	double p, q, f;
	scanf("%d %d", &a, &b);
	d=a/b;
	r=a%b;
	p=a;
	q=b;
	f=p/q;
	printf("%d %d %f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 636
//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
#define debug(x) cerr << #x << " : " << x;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
ll a[MAXN], n, b[MAXN];
unordered_map<ll, ll> M;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	for (int i = 0; i < n; i++)
		M[b[i]] = i;
	ll ans = 0;
	for (int i = 0; i < n; i++)
		if(i % 2 != M[a[i]] % 2)
			ans++;
	cout << ans / 2;
}

Measured memory_bytes: 5924
#include<stdio.h>
#include<string.h>
#include<list>
int F(int x,int y)
{
	if(!y)return x;
	return F(y,x%y);
}
typedef std::list<int>L;
L e[1002];
int m,n;
bool f[1002];
int G(int s,int d)
{
	if(s==d)return 1;
	if(f[s])return 0;
	f[s]=1;
	for(L::iterator i=e[s].begin();i!=e[s].end();++i)
	{
		if(G(*i,d))
		{
			e[*i].push_back(s);
			e[s].erase(i);
			return 1;
		}
	}
	return 0;
}
int main()
{
	int a[500],i,j,x;
	while(scanf("%d%d",&m,&n),m)
	{
		for(i=0;i<m+n+2;++i)e[i].clear();
		for(i=0;i<m;++i)scanf("%d",&a[i]),e[m+n].push_back(i);
		for(j=0;j<n;++j)
		{
			scanf("%d",&x);
			for(i=0;i<m;++i)if(F(a[i],x)>1)e[i].push_back(m+j);
			e[m+j].push_back(m+n+1);
		}
		for(x=0;memset(f,0,sizeof(f)),G(m+n,m+n+1);)++x;
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 2672
#include <iostream>

int n, a[4][13] = {};

void plus(char c, int m) {
  switch(c) {
  case 'S':
    a[0][m]++;
    break;
  case 'H':
    a[1][m]++;
    break;
  case 'C':
    a[2][m]++;
    break;
  case 'D':
    a[3][m]++;
  }
}

int main() {
  char b[4] = {'S', 'H', 'C', 'D'};
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    char c;
    int m;
    std::cin >> c >> m;
    plus(c, m - 1);
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if (a[i][j] == 0) std::cout << b[i] << " " << j + 1 << std::endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[n-1] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << "+" << endl;
	}
	else if (a*b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}
	return 0;
}

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



int main(){
    ll N, M; cin >> N >> M;
    ll ans = 0;
    vector<ll> E(N+1);
    for(int i = 0; i < M; i++){
        ll a, b; cin >> a >> b;
        if(a == 1) E[b]++;
        else if(b == 1) E[a]++;
        else {E[a]++; E[b]++;}
    }

    for(int i = 2; i < N+1; i++){
        if(E[i]%2 != 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String S = scan.next();
        char[] d = S.toCharArray();
        int[] a = new int[26];
        for (int i = 0; i < N; i++) {
            a[d[i]-'a'] += 1;
        }
        long answer = 1;
        for (int i = 0; i < 26; i++) {
            if (a[i] == 0) {
                continue;
            }
            answer = answer * (a[i] + 1) % 1000000007;
        }
        System.out.println(answer - 1);
    }
}


Measured memory_bytes: 28208
A, B, C = map(int,input().split())
AB_C = A*10+B+C
A_BC = A+B*10+C
A_CB = A+C*10+B
B_AC = B+A*10+C
B_CA = B+C*10+A
C_BA = C+B*10+A
max = 0
S = []
S.append(AB_C)
S.append(A_BC)
S.append(A_CB)
S.append(B_AC)
S.append(B_CA)
S.append(C_BA)
for i in range(len(S)):
    if S[i] > max:
        max = S[i]
print(max)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

int c[10][10005];

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vs s(h);
    rep(i,0,h) cin >> s[i];
    int ans = inf;
    rep(div,0,1<<(h-1)){
        int g = 0;
        vi id(h);
        rep(i,0,h){
            id[i] = g;
            if(1 & div >> i)g++;
        }g++;
        rep(i,0,g)rep(j,0,w) c[i][j] = 0;
        rep(i,0,h)rep(j,0,w) c[id[i]][j] += (s[i][j]-'0');

        int num = g-1;
        vector<int> now(g);
        auto add = [&](int j){
            rep(i,0,g) now[i] += c[i][j];
            bool ok = true;
            rep(i,0,g) if(now[i] > k) ok = false;
            return ok;
        };
        rep(j,0,w){
            if(!add(j)){
                num++;
                now = vector<int>(g);
                if(!add(j)){
                    num = inf;
                    break;
                }
            }
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
from operator import itemgetter

n = int(input())
xl = []

for i in range(n):
    x, l = map(int, input().split())
    xl.append([x - l, x + l])

xl = sorted(xl, key=itemgetter(1))

ans = 0
m = -float("inf")
for left, right in xl:
    if left < m:
        ans += 1
    else:
        m = max(m, right)

print(n - ans)

Measured memory_bytes: 22180
n,k=map(int,input().split(" "))
if n<k:
    print(0)
else:
    a=[1,0]
    for i in range(n):
        a=[0]+[a[i-1]+i*a[i] for i in range(1,len(a))]+[0]
    for i in range(1,k+1):
        a[k]*=i
    print(a[k]%(10**9+7))


Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()


const int mod = 1e9 + 7;
const int N = 2e5 + 6;
int arr[N];

void solve()
{
	int n;
	cin >> n;
	double odd = 0;
	double even = 0;
	if(n & 1) n--, odd = 1;
	odd += n / 2;
	even += n / 2;
	cout << odd / (even + odd);
}

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif*/
	solve();
	return 0;
}          

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,K,L;
	int p[100001],q[100001],r[100001],s[100001];
	scan(N);scan(K);scan(L);
	UnionFind miti(N);
	UnionFind tetu(N);
	rep(i,K){
		scan(p[i]);scan(q[i]);
		int sm=min(p[i]-1,q[i]-1),bi=max(p[i]-1,q[i]-1);
		miti.unite(sm,bi);

	}
	rep(i,L){
		scan(r[i]);scan(s[i]);
		int sm=min(r[i]-1,s[i]-1),bi=max(r[i]-1,s[i]-1);
		tetu.unite(sm,bi);
	}
	map<pint,int> bothpar;
	rep(i,N) bothpar[mp(miti.root(i),tetu.root(i))]++;
	rep(i,N) printf("%d ",bothpar[mp(miti.root(i),tetu.root(i))]);
	kaigyo;
	return 0;
}


Measured memory_bytes: 16640
N = int(input())
w = str(input())
x = 0
List = []
for i in range(N):
  if w[i] == 'I':
    x += 1
    List.append(x)
  else:
    x -= 1
    List.append(x)
if max(List) <=0:
  print(0)
else:
  print(max(List))

Measured memory_bytes: 38256
x, n=map(int, input().split())
try:
  l=list(map(int, input().split()))
except EOFError:
  print(x)
  exit()
for i in range(101):
  if x+i in l and x-i in l:
    continue
  elif x+i in l:
    print(x-i)
    exit()
  elif x-i in l:
    print(x+i)
    exit()
  else:
    print(x-i)
    exit()

Measured memory_bytes: 9204
//58
#include<iostream>

using namespace std;

int g[12][12];

void ff(int y,int x){
  if(g[y][x]){
    g[y][x]=0;
    int dy[]={0,1,0,-1};
    int dx[]={1,0,-1,0};
    for(int i=0;i<4;i++){
      int ny=y+dy[i];
      int nx=x+dx[i];
      if(0<=nx&&nx<12&&0<=ny&&ny<12){
	ff(ny,nx);
      }
    }
  }
}

int main(){
  for(;;){
    for(int y=0;y<12;y++){
      for(int x=0;x<12;x++){
	char c;
	if(!(cin>>c))return 0;
	g[y][x]=c=='1';
      }
    }
    int ans=0;
    for(int y=0;y<12;y++){
      for(int x=0;x<12;x++){
	if(g[y][x]){
	  ans++;
	  ff(y,x);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
    int x,y,w,h;

    scanf("%d %d %d %d",&w,&h,&x,&y);

    if( 2 * x == w && 2 * y == h){
        printf("%lf 1\0",(double)w * (double)h /2);
    }else{
        printf("%lf 0\0",(double)w * (double)h /2);
    }

    return 0;
    
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct f_t
{
	ll v_sum[4];
	f_t add_h(int v)
	{
		if(v==0) return *this;
		auto&ret=*this;
		for(int i=3;i>0;i--)
		{
			max_u(ret.v_sum[i], ret.v_sum[i-1]+v);
		}
	}
	f_t add_v(int v)
	{
		if(v==0) return *this;
		auto&ret=*this;
		for(int i=3;i>0;i--)
		{
			max_u(ret.v_sum[i], ret.v_sum[i-1]+v);
		}
	}
	ll get(void)
	{
		ll ret=0;
		for(int i=0;i<=3;i++) max_u(ret, v_sum[i]);
		return ret;
	}
};


void dp_update(f_t&t, f_t&u, f_t&l, int v)
{
	for(int i=0;i<=3;i++)
	{
		max_u(t.v_sum[0], l.v_sum[i]);
	}
	for(int i=0;i<=3;i++)
	{
		max_u(t.v_sum[i], u.v_sum[i]);
	}
	if(v)
	{
		for(int i=0;i<=3;i++)
		{
			max_u(t.v_sum[1], l.v_sum[i]+v);
		}
		for(int i=1;i<=3;i++)
		{
			max_u(t.v_sum[i], u.v_sum[i-1]+v);
		}
	}
};


struct solve
{
	ll operator()(int r, int c, vvi&f) {
		vector<vector<f_t>> dp(c+1);
		for(auto&m:dp) m.resize(r+1);

		for(int y=1;y<=c;y++)
		{
			for(int x=1;x<=r;x++)
			{
				dp_update(dp[y][x], dp[y-1][x], dp[y][x-1], f[y][x]);
			}
		}
/*
		for(int y=1;y<=c;y++)
		{
			for(int x=1;x<=r;x++)
			{
				cout << f[y][x] << " ";
			}
			cout << "\n";
		}
		cout << "\n";
		for(int y=1;y<=c;y++)
		{
			for(int x=1;x<=r;x++)
			{
				cout << dp[y][x].get() << " ";
			}
			cout << "\n";
		}
*/
		ll ans=dp[c][r].get();

		return ans;
	}
};


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

	for(;;)
	{
		int r, c, k;
		cin >> r >> c >> k;
		if(cin.fail()) break;
		vvi f(c+1);
		for(auto&m:f) m.resize(r+1);

		for(int i=0;i<k;i++)
		{
			int x, y, v;
			cin >> x >> y >> v;
			f[y][x]=v;
		}
		cout << solve()(r, c, f) << "\n";
	}
	return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;

	int cnt = 0, tmp = 1;
	while (cnt < n) {
		tmp = a[tmp - 1];
		cnt++;
		if (tmp == 2) { cout << cnt << endl; return 0; }
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 640
n = int(raw_input())

d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
G = [0 for i in range(n)]


def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
    
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]

def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        a[G[0]-1][G[2+j]-1] = 1

main()
   


       

Measured memory_bytes: 6484
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};
ll modfact[100010];

const int MAX = 100001;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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


long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

    vector<int> layer(N,-1);

    vector<int> tonari[100001];
    modfact[0]=1LL;
    for(ll i=1LL;i<=100010;i++){
        modfact[i]=(i*modfact[i-1])%mod;
    }

    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        tonari[a-1].push_back(b-1);
        tonari[b-1].push_back(a-1);
    }

    ll ans=K;
    layer[0]=0;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int tmp=q.front();
        q.pop();
        int sums=tonari[tmp].size()-1;
        if(layer[tmp]==0){
            //ans*=modfact[K-1]/modinv(modfact[K-sums-1],mod);
            ans*=COM(K-1,sums+1);
            ans%=mod;
        }else{
            //ans*=modfact[K-2]/modinv(modfact[K-2-sums],mod);
            ans*=COM(K-2,sums);
            ans%=mod;
        }
        for(int i=0;i<tonari[tmp].size();i++){
            int pos=tonari[tmp][i];
            if(layer[pos]>=0) continue;
            layer[pos]=layer[tmp]+1;
            q.push(tonari[tmp][i]);
        }
    }

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



Measured memory_bytes: 9976
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var b = int.Parse(line[2]);
        var ans1 = Min(a, b);
        var ans2 = Max(0, a + b - n);
        Console.WriteLine("{0} {1}", ans1, ans2);
    }
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
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 # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = readInts()
    # 全体の合計 その差が答え 全部で最小値を取る
    total = sum(A)
    mi_ = float("inf")
    left = 0
    for i in range(n):
        left += A[i]
        total -= A[i]
        mi_ = min(mi_,abs(left - total))
    print(mi_)
if __name__ == '__main__':
  main()


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

using namespace std;

int main()
{
  int i,j,k;
  int H,W,K;
  int ans;
  int black;
  scanf("%d %d %d",&H,&W,&K);
  char S[H+1][W+1];
  for(i=0;i<H;i++){
    scanf("%s",S[i]);
  }

  ans = 0;
  black = 0;
  for(int temp=0;temp<(1<<H);temp++){
    for(int temp2=0;temp2<(1<<W);temp2++){
      for(i=0;i<H;i++){
        for(j=0;j<W;j++){
          if( !(temp2&(1<<j)) && !(temp&(1<<i)) && S[i][j]=='#' ){
            black += 1;
          }
        }
      }
        if( black == K ){
          ans++;
        }
        black = 0;
    }
  }

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


Measured memory_bytes: 3772
#include<iostream>
using namespace std;
int main()
{
    int a=0,b=0;
    cin>>a>>b;
    if((a==1 && b==2) ||( a==2 && b==1))
    cout<<"3"<<endl;
    else if((a==2 && b==3) || (a==3 && b==2))
    cout<<"1"<<endl;
    else if((a==1 && b==3) || (a==3 && b==1))
    cout<<"2"<<endl;

  
    return 0;
}

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

int main(){
    string n; cin >> n;
    
    if((n[0]==n[1]&&n[1]==n[2]) || (n[1]==n[2]&&n[2]==n[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;   
    int i = 1;
    while (1){
        if (i % 2 == 0){
            a -= d;
            if (a <= 0){
            cout << "No" << endl;
            break;
        }
        }
        else{
            c -= b;
            if (c <= 0){
            cout << "Yes" << endl;
            break;
        }
        }
        
        
        i ++;

    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	cin>>a;
	if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u')
	{
		cout<<"vowel";
	}
	else
	{
		cout<<"consonant";
	}
	return 0;
 }

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

const long long MOD = 1'000'000'007;
long long dp[100010];
bool check[100010];
int main(){
	int n, m;
	cin >> n >> m;
	for (auto &x : check) x = true;
	for (int i = 0; i < m; i++){
		int a;
		cin >> a;
		check[a] = false;
	}
	dp[0] = 1;
	dp[1] = check[1] ? 1 : 0;
	for (int i = 2; i < n+1; i++){
		if (check[i]){
			dp[i] = dp[i-1] + dp[i-2];
			dp[i] %= MOD;
		}
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 1152
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int g[4][4];

#define POS(x) cout<<((x)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define Pos(x) cout<<((x)?"Possible":"Impossible")<<endl;
#define YES(x) cout<<((x)?"YES":"NO")<<endl;
#define Yes(x) cout<<((x)?"Yes":"No")<<endl;
#define yes(x) cout<<((x)?"yes":"no")<<endl;


int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int a, b;
  for(int i = 0; i < 3; i++) {
    cin >> a >> b;
    a--; b--;
    g[a][b] = g[b][a] = 1;
  }
  vector<int> v{0, 1, 2, 3};
  int r = 0;
  do {
    int x = 1;
    for(int i = 1; i < 4; i++) {
      x &= g[v[i]][v[i-1]];
    }
    r |= x;
  } while(next_permutation((v).begin(), (v).end()));
  YES(r);
  return 0;
}


Measured memory_bytes: 384
using System;

public class Program{
    public static void Main(){
        string[] input=Console.ReadLine().Split(' ');
        ulong L=ulong.Parse(input[0]);
        ulong R=ulong.Parse(input[1]);
        ulong ans=2018;
        if(R-L>=2019){
            ans=0;
        }else{
            for(ulong i=L;i<R;i++){
                for(ulong j=i+1;j<=R;j++){
                    ulong result=i*j%2019;
                    if(result<ans){
                        ans=result;
                    }
                }
            }
        }
        
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.07.14 20:51:51
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int n, a[100010];
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);

    int sum = 0;
    rep(i, n) {
        sum ^= a[i];
    }

    if (sum == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

class DisjointSet:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1] * n
        self.rank = [0] * n

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def has_same_root(self, x, y):
        return self.root(x) == self.root(y)

    def get_size(self, x):
        return self.size[self.root(x)]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x] 
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


n, m = map(int, input().split())
DS = DisjointSet(n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    DS.unite(a, b)
seen = set()
ans = 0
for i in range(n):
    r = DS.root(i)
    if r in seen:
        continue
    else:
        seen.add(r)
        ans += 1
print(ans - 1)

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, k; read(n, k);
  vector<ll> a(n), b;
  rep(i, 0, n) read(a[i]);
  rep(l, 0, n) rep(r, l, n) {
    ll m = 0;
    rep(i, l, r + 1) m += a[i];
    b.push_back(m);
  }
 
  ll ans = 0;
  for (int i = 60; i >= 0; i--) {
    vector<ll> c;
    for (ll v : b) if (v & (1ll << i)) c.push_back(v);
    if (c.size() >= k) (ans |= 1ll << i), (b = c);
  }

  write(ans);
}


Measured memory_bytes: 8876
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

int main() {
  char a,b;
  cin>>a>>b;
  if(a=='D'){
      if(b=='D'){
          cout<<'H'<<endl;
      }
      else{
          cout<<'D'<<endl;
      }
  }
  if(a=='H'){
      cout<<b<<endl;
  }

}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class BCountBalls {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll N, A, B;
	    in >> N >> A >> B;
	    out << N / (A + B) * A + min(N % (A + B), A) << '\n';
	}
};


int main() {
	BCountBalls solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll a[5];
int dxy[5] = {-1, 0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);

    int H, W;
    vector<string> field;
    cin >> H >> W;
    for (int i = 0; i < H; ++i)
    {
        string s;
        cin >> s;
        field.push_back(s);
    }

    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            if (field[i][j] == '#')
            {
                int sum = 0;
                for (int k = 0; k < 4; ++k)
                {
                    int nx = j + dxy[k], ny = i + dxy[k + 1];
                    if (nx < 0 || ny < 0 || nx >= W || ny >= H)
                        continue;

                    if (field[ny][nx] == '#')
                        sum++;
                }
                if (!sum)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import collections
Sa = collections.deque([ i for i in input()])
Sb = collections.deque([ i for i in input()])
Sc = collections.deque([ i for i in input()])
prv = Sa.popleft()
win = 0
flag = True
while flag:
    if prv == 'a':
        if not Sa:
            flag = False
            win = 'A'
        else:
            prv = Sa.popleft()
    elif prv == 'b':
        if not Sb:
            flag = False
            win = 'B'
        else:
            prv = Sb.popleft()
            
    elif prv == 'c':
        if not Sc:
            flag = False
            win = 'C'
        else:
            prv = Sc.popleft()
            
print(win)

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

using namespace std;

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

vector<string> s(10, string(10, '.'));
int dx[8] = { 1,0,-1,0,-1,-1,1,1 };
int dy[8] = { 0,1,0,-1,-1,1,-1,1 };

typedef pair<int, int> P;
map<char, char> rv;

int count(vector<string> v, char c) {
	int cnt = 0;
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			if (v[i][j] == c) {
				cnt++;
			}
		}
	}
	return cnt;
}

vector<string> put(int y, int x, char c) {
	auto ts = s;
	ts[y][x] = c;
	rep(i, 8) {
		int ty = y + dy[i], tx = x + dx[i];
		int cnt = 0;
		vector<P> ch;
		while (1) {
			if (rv[ts[ty][tx]] != c) {
				break;
			}
			ch.push_back(P(ty, tx));
			ty += dy[i]; tx += dx[i];
		}
		if (ts[ty][tx] == c) {
			each(p, ch) {
				ts[p.first][p.second] = c;
			}
		}
	}
	return ts;
}

P maxPoint(char c) {
	int ma = 0, now = count(s, c);
	P p(-1, -1);

	if (c == 'o') {
		for (int y = 1; y <= 8; y++) {
			for (int x = 1; x <= 8; x++) {
				if (s[y][x] == '.') {
					int next = count(put(y, x, c), c);
					if (ma < next && next > now + 1) {
						ma = next;
						p = P(y, x);
					}
				}
			}
		}
	}
	else {
		for (int y = 8; y >= 1; y--) {
			for (int x = 8; x >= 1; x--) {
				if (s[y][x] == '.') {
					int next = count(put(y, x, c), c);
					if (ma < next && next > now + 1) {
						ma = next;
						p = P(y, x);
					}
				}
			}
		}
	}
	
	return p;
}

int main() {
	for (int y = 1; y <= 8; y++) {
		cin >> s[y];
		s[y] = "." + s[y] + ".";
	}
	rv['o'] = 'x';
	rv['x'] = 'o';
	rv['.'] = '.';

	string tb = "ox";

	int wait = 0;
	for (int i = 0;; i++) {
		char c = tb[i % 2];
		auto p = maxPoint(c);
		if (p.first == -1) {
			wait++;
			if (wait == 2)break;
			continue;
		}
		wait = 0;
		s = put(p.first, p.second, c);
	}

	for (int y = 1; y <= 8; y++) {
		for (int x = 1; x <= 8; x++) {
			cout << s[y][x];
		}
		cout << endl;
	}	

	return 0;
}

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

int main(){
    int n;

    int max;

    cin >> n >> max;

    int ans = max;

    int p;

    for(int i = 0; i < n - 1; ++i){
        cin >> p;
        ans += p;

        if(max < p) max = p;
    }

    cout << ans - max + max/2 << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 998244353;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}


int a[4000];
int dp[4000][4000];
signed main(){
    int ans = 0;
    int n,s;
    cin >> n >> s;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=s;j++){
            if(j==a[i]){
                dp[i][j] = dp[i-1][j] + i;
            }
            else if(j-a[i] < 0){
                dp[i][j]= dp[i-1][j];
            }
            else{
                dp[i][j]= dp[i-1][j]+ dp[i-1][j-a[i]];

            }
            dp[i][j] %= MOD;
            ans += dp[i][s];
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 94208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())


void solve(void){
    string N;
    cin >> N;
    int ans = N[0]-'1' + (N.length()-1)*9;
    int tmp = 0;
    if (count(all(N), '9') == (int)N.length()) ans = N.length()*9;
    else {
        rep((int)N.length(), d) tmp += N[d]-'0';
        ans = max(ans, tmp);
    }
    cout << ans << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

bool comp(const pair<int, int> &a, const pair<int, int> &b){
    return a.second < b.second;
}

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

    vector<pair<int, int>> red(n);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        red[i] = pair<int, int>(a, b);
    }
    sort(all(red), comp); reverse(all(red));

    vector<pair<int, int>> blue(n);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        blue[i] = pair<int, int>(a, b);
    }
    sort(all(blue));

    int cnt = 0;
    rep(i, n){
        rep(j, n){
            if(blue[i].first > red[j].first && blue[i].second > red[j].second){
                cnt ++;
                blue[i].first = 999; blue[i].second = 999;
                red[j].first = 1000; red[j].second = 1000;
                break;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
lis = [[] for _ in range(m + 1)]

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


const i64 inf = 1e18;

void solve(long long N, long long x, std::vector<long long> a){
    vector<vector<i64>> table(N, vector<i64>(N, inf));
    rep(i, N){
        rep(j, N){
            if(j != 0) table[i][j] = min(table[i][j - 1], a[(i - j + N) % N]);
            else table[i][j] = a[i];
        }
    }
    i64 ans = inf;
    rep(i, N){
        i64 tmp = x * i;
        rep(j, N) tmp += table[j][i];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    long long x;
    scanf("%lld",&x);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, x, std::move(a));
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);

  bool flag = false;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
    if (v.at(i) == 0) {
      flag = true;
    }
    if (v.at(i) < 0) {
      cnt++;
      v.at(i) *= -1;
    }
  }

  ll ans = accumulate(v.begin(), v.end(), 0LL);

  if (flag) {
    cout << ans << endl;
    return 0;
  }

  if (cnt % 2 == 0) {
    cout << ans << endl;
    return 0;
  } else {
    sort(v.begin(), v.end());
    cout << ans - v.at(0) * 2 << endl;
    return 0;
  }
}


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

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

	vector<int> wV(n);
	int rSum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> wV[i];
		rSum += wV[i];
	}

	int lSum = wV[0];
	rSum -= wV[0];

	int prev = 10000;
	int t = 1;
	while (lSum - rSum < 0) {
		prev = lSum - rSum;
		if (n == t) {
			break;
		}
		lSum += wV[t];
		rSum -= wV[t];
		++t;
	}

	int ret = -prev;
	if (lSum - rSum < ret) {
		ret = lSum - rSum;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char** argv)
{
    int A, B;
    std::cin >> A;
    std::cin >> B;

    int p = A + B;
    int m = A - B;
    int t = A * B;

    int m1 = (p > m) ? p : m;
    int m2 = (m1 > t) ? m1 : t;

    std::cout << m2 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> f(n, vector<int> (10));
        for (int i = 0; i < n; i ++) for (int j = 0; j < 10; j ++) scanf("%d", &f[i][j]);
        vector<vector<int>> p(n, vector<int> (11));
        for (int i = 0; i < n; i ++) for (int j = 0; j <= 10; j ++) scanf("%d", &p[i][j]);
        long long ans = - (1LL << 60);
        for (int use = 1; use < (1 << 10); use ++) {
                long long res = 0;
                for (int i = 0; i < n; i ++) {
                        int cnt = 0;
                        for (int j = 0; j < 10; j ++) cnt += f[i][j] && use & (1 << j);
                        res += p[i][cnt];
                }                   
                ans = max(ans, res);
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 256