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

int main() {
	int N,Y;
	cin>>N>>Y;
	int x,y,z;
	int p10=-1,p5=-1,p=-1;
	for(x=0;x<N+1;x++){
		for(y=0;y<N-x+1;y++){
			for(z=0;z<N-x-y+1;z++){
				if((10000*x+5000*y+1000*z==Y)&&(x+y+z)==N){
					p10=x;
					p5=y;
					p=z;
				}
			}
		}
		
	}
	cout<<p10<<' '<<p5<<' '<<p<<endl;
	return 0;
}

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

x = 0
for a in A:
    x = (a - x//2) * 2

x //= 2
ans = []
for a in A:
    ans.append(x)
    x = (a - x//2) * 2
print(*ans)

Measured memory_bytes: 14100
#include<iostream>

using namespace std;

int main()
{
	int ss[8],i,j;
	int ans[2];
	
	for(;cin >> ss[0];)
	{
		ans[0]=ans[1]=0;
		
		for(i=1;i<8;i++)
		{
			cin >> ss[i] ;
		}
		
		for(i=0;i<4;i++)
		{
			if(ss[i]==ss[i+4])
			{
				ans[0]++;
				ss[i+4]=-1;
			}
		}
		for(i=0;i<4;i++)
		{
			for(j=4;j<8;j++)
			{
				if(ss[i]==ss[j])
				{
					ans[1]++;
				}
			}
		}
		cout << ans[0] << " " << ans[1] << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
g = [[] for _ in range(N+1)]

for _ in range(N-1):
        a,b = map(int,input().split())
        g[a].append(b)
        g[b].append(a)

def BFS(v):
        d = [N]*(N+1)
        d[v] = 0
        q = [v]

        while q:
                u = q.pop()
                for i in g[u]:
                        if d[i] == N:
                                d[i] = d[u] + 1
                                q.append(i)

        return d

db = BFS(1)
dw = BFS(N)

if sum([db[i] > dw[i] for i in range(1,N+1)]) >= N/2:
        print("Snuke")
else:
        print("Fennec")

Measured memory_bytes: 29936
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int[] l = new int[]{scanner.nextInt(), scanner.nextInt()};
            list.add(l);
        }

        list.sort((l1, l2) -> (l1[1] - l2[1]));
        int cnt = 1;
        int tmp = list.get(0)[1];
        for (int i = 1; i < m; i++) {
            int right = list.get(i)[0];
            int left = list.get(i)[1];
            if (right >= tmp) {
                tmp = left;
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 90684
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
ll nCr(ll n, ll r){
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
  ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
  return ret;
}

int p[1100];
int find(int a){
  if(p[a] == a){
    return a;
  }else{
    return p[a] = find(p[a]);
  }
}
void unite(int a, int b){
  int pa = find(a);
  int pb = find(b);
  p[pa] = pb;
}

struct edge{ll cost,a,b;};
int n,m;
vector<edge> E;

ll prim(int ei){
  ll ret = 0;
  rep(i,n){
    p[i] = i;
  }
  ret += E[ei].cost;
  unite(E[ei].a, E[ei].b);
  rep(i,E.size()){
    edge e = E[i];
    ll cost = e.cost;
    ll a = e.a;
    ll b = e.b;
    if(find(a) != find(b)){
      unite(a,b);
      ret += cost;
    }
  }
  return ret;
}

int main(void){
  cin>>n>>m;
  ll x;cin>>x;
  rep(i,m){
    ll u,v,w;
    cin>>u>>v>>w;u--;v--;
    E.push_back({w,u,v});
  }
  sort(all(E),[](const edge& x, const edge& y){return x.cost < y.cost;});
  ll equal=0,over=0,under=0;
  rep(i,E.size()){
    ll ret = prim(i);
    if(ret == x){
      equal++;
    }else if(ret < x){
      under++;
    }else{
      over++;
    }
  }
  //over どっちでもいい
  //equal どれかは黒
  //under 必ず白
  cerr<<under<<" "<<equal<<" "<<over<<endl;
  ll ans = (under==0?1:2) * max((ll)0,(mpow(2,equal) - 1 - (under==0?1:0))) % MOD * mpow(2,over) % MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL n, p;
    cin >> n >> p;
    LL a[n];
    bool flg = true;
    for( int i = 0; i < n; ++i ) {
        cin >> a[i];
        if( a[i] % 2 ) flg = false;
    
    }

    if( flg && p ) cout << 0;
    else if( flg ) {
        LL ans = 1;
        for( int i = 0; i < n; ++i ) ans *= 2;
        cout << ans;
    } else {
        LL ans = 1;
        for( int i = 0; i < n - 1; ++i ) ans *= 2;
        cout << ans;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		int cnt = 0;
		int n = s.length();
		for (int i = 0; i < n; ++i) {
			if (s.charAt(i) == '1')
				++cnt;
		}

		System.out.println(cnt);
	}

}


Measured memory_bytes: 20820
from heapq import heappop, heappush

INF = 10 ** 20

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
  s, t, w = map(int, input().split())
  edges[s].append((w, t))
  edges[t].append((w, s))

cost = [INF] * n
que = [(0, 0)]
cost[0] = 0

while que:
  acc, num = heappop(que)
  for weight, to in edges[num]:
    if weight + acc < cost[to]:
      cost[to] = weight + acc
      heappush(que, (weight + acc, to))

max_ind = cost.index(max(cost))
cost = [INF] * n
que = [(0, max_ind)]
cost[max_ind] = 0
while que:
  acc, num = heappop(que)
  for weight, to in edges[num]:
    if weight + acc < cost[to]:
      cost[to] = weight + acc
      heappush(que, (weight + acc, to))

print(max(cost))


Measured memory_bytes: 43244
import sys

day = input()

if day == "SUN":
  ans=7
elif day =="SAT":
  ans=1
elif day =="FRI":
  ans=2
elif day =="THU":
  ans=3
elif day =="WED":
  ans=4
elif day =="TUE":
  ans=5
elif day =="MON":
  ans=6

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> h(n);
  REP(i, n) { cin >> h[i]; }
  ll ans = 0;
  ll m = 0;
  for (ll i = 0; i < n - 1; i++) {
    // DEBUG(m);
    if (h[i] >= h[i + 1]) m++;
    ans = max(ans, m);
    if (h[i] < h[i + 1]) m = 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければ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;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;
const int M = 1000000007;


typedef long long int ll;
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算、a,b<=300000でないと使えない
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}



int main(){
  int n,k;
  cin >> n >> k;
  int h[n];

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

  sort(h,h+n);

  long long int ans=0;
  for(i=0;i<n-k;i++){
    ans += h[i];
  }

  cout << ans << endl;



}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
struct edge {
    int to;
    int cost;
};

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    vector<vector<edge>> g(k);
    for(int i = 0; i < k; i++) {
        g[i].emplace_back(edge{(i + 1) % k, 1});
        if(i * 10 % k != i) {
            g[i].emplace_back(edge{i * 10 % k, 0});
        }
    }
    // for(int i = 0; i < k; i++) {
    //     cout << i << ":";
    //     for(auto j : g[i]) {
    //         cout << j.to << ' ';
    //     }
    //     cout << endl;
    // }
    vector<int> d(k, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    d[1] = 0;
    que.push(P(0, 1));
    while(que.size()) {
        auto now = que.top();
        que.pop();
        if(d[now.second] < now.first) {
            continue;
        }
        for(auto next : g[now.second]) {
            if(d[next.to] > d[now.second] + next.cost) {
                d[next.to] = d[now.second] + next.cost;
                que.push(P(d[next.to], next.to));
            }
        }
    }
    cout << d[0] + 1 << endl;
}

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

using namespace std;

int main()

{

    int k,a,b,flag=0;

    cin>>k>>a>>b;

    for(int i=a;i<=b;i++)

    {

        if(i%k==0)

        {

            flag=1;

            break;

        }



    }

    if(flag)

        cout<<"OK";

    else

        cout<<"NG";

    return 0;

}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    printf("%d %d %d\n", c, a, b);
}

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

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(n == i * j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,s,n)for(int i=s;i<n;i++)
using namespace std;
using ll=long long;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,i;
  ll sum;
  cin >> n;
  sum=1;
  rep(i,1,n+1)sum*=i;
  cout << sum <<endl;
  return 0;
}



Measured memory_bytes: 3032
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <stdlib.h>


int main(){

    int x1,y1,x2,y2;

    cin >> x1 >> y1 >> x2 >> y2;

    int a = x2 - x1;
    int b = y2 - y1;

    int x3 = x2 - b;
    int y3 = y2 + a;
    int x4 = x3 - a;
    int y4 = y3 - b;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;


    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int d;
  cin >> d;
  
  if(d == 25)
    cout << "Christmas" << endl;
  
  if(d == 24)
    cout << "Christmas Eve" << endl;
  
  if(d == 23)
    cout << "Christmas Eve Eve" << endl;
  
  if(d == 22)
    cout << "Christmas Eve Eve Eve" << endl;
}                 

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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    if(n % 1000 == 0) ans = 0;
    else ans = 1000 - (n % 1000);
    cout << ans << endl;
}

int32_t main()
{
    DESYNC
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <vector>
#include <string>

int main(int argc, char* argv[]){
    int n;
    scanf("%d", &n);
    std::vector<int> list = {};
    list.resize(n);
    for(int i = n - 1; 0 <= i; --i){
        int input;
        scanf("%d", &input);
        list[i] = input;
    }
    for(int i = 0; i < list.size(); ++i){
        printf("%d", list[i]);
        if (i + 1 == list.size()){
            printf("\n");
        }else{
            printf(" ");
        }
    }
}


Measured memory_bytes: 2700
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
X = [tuple(MI()) for _ in range(N)]
X.sort()
print(sum(X[-1]))


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

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let n: usize = read();
    let mut h: i64 = read();
    let mut av: Vec<i64> = vec![];
    let mut bv: Vec<i64> = vec![];

    for _ in 0..n {
        let a = read();
        let b = read();
        av.push(a);
        bv.push(b);
    }

    av.sort();
    bv.sort();
    bv.reverse();
    let maxa = av[av.len() - 1];
    let mut ans = 0;

    for i in 0..bv.len() {
        let bi = bv[i];
        if bi < maxa {
            continue;
        }

        if bi < h {
            h -= bi;
            ans += 1;
        } else {
            println!("{}", ans + 1);
            return;
        }
    }

    println!("{}", (h - 1) / maxa + 1 + ans);
}


Measured memory_bytes: 8444
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int NMAX = 310;
const int MMAX = 1010;
const int INF = MMAX * 6;

struct edge { 
  int to, cap, rev, id;
  bool reversal;
};

vector<edge> G[NMAX];
bool used[NMAX];

void add_edge(int from, int to, int cap, int id, bool reversal) {
  G[from].push_back((edge){to, cap, G[to].size(), id, reversal});
  G[to].push_back((edge){from, 0, G[from].size() - 1, 0, false});
}

int dfs(int v, int t, int f) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (!used[e.to] and e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while (true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0) return flow;
    flow += f;
  }
}

int main() {
  int n, m, s, t;
  cin >> n >> m;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    add_edge(x, y, 1, i + 1, false);
    add_edge(y, x, 1, i + 1, true);
  }
  cin >> s >> t;
  cout << max_flow(s, t) << endl;

  vector<int> reverse_roads;
/*  REP(v, n + 1) {
    REP(i, G[v].size()) {
      edge e = G[v][i];
      cout << "G[" << v << "][" << i << "]";
      cout << "to=" << e.to;
      cout << "cap=" << e.cap;
      cout << "rev=" << e.rev;
      cout << "id=" << e.id;
      cout << "reversal=" << e.reversal << endl;
    }
  }*/
  REP(v, n + 1) {
    REP(e, G[v].size()) {
      if (G[v][e].reversal and G[v][e].cap == 0) {
        reverse_roads.push_back(G[v][e].id);
      }
    }
  }
  sort(reverse_roads.begin(), reverse_roads.end());
  int len = reverse_roads.size();
  cout << len << endl;
  REP(i, len) {
    cout << reverse_roads[i] << endl;
  }
}

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    char b[7][7];
    char a[7][7];
    int n,m,k;
    void copy_matrix(){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
                b[i][j]=a[i][j];
        }
        return;
    }
    void color(int i,int j){
        for(int x=0;x<n;x++){
            if(i&(1<<x)){
                for(int y=0;y<m;y++)
                    b[x][y]='$';
            }
        }
        for(int x=0;x<m;x++){
            if(j&(1<<x)){
                for(int y=0;y<n;y++)
                    b[y][x]='$';
            }
        }
        return;
    }

    bool check(){
        int total=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(b[i][j]=='#')
                    total++;
            }
        }
        if(total==k)
            return true;
        else
            return false;
    }

    void solve(){
        cin>>n>>m>>k;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
                cin>>a[i][j];
        }
        int total=0;
        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<(1<<m);j++){
                copy_matrix();
                color(i,j);
                if(check())
                    total++;
            }
        }
        cout<<total;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3532
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    long long int N,dig,sum1=0,sum2=0,i;
    cin>>N;
    if((N/10)==0){
     cout<<N<<endl;
     return 0;
    }
    while((N/10)>0){
     dig=N%10;
     N=N/10;
     if(dig!=9) {dig = 9;
                   N--;
                  }
     sum1+=dig;
    }
    sum1+=N;
    cout<<sum1<<endl;
    return 0;
    }

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

string S[ 110 ];

int main( int argc, char *argv[] )
{
int i;
int N;
int L;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> L;
	for( i = 0; i < N; i++ ) cin >> S[ i ];

	sort( S, S + N );
	for( i = 0; i < N; i++ ) cout << S[ i ];

	cout << endl;

	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)

const int INF = 0x3f3f3f3f;

typedef long long ll;

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

int main() {
	ll a = read() - 1, b = read(), c = read(), d = read();
	ll lcm = (c / gcd(c, d)) * d;
	ll resA = a / c + a / d - a / lcm;
	ll resB = b / c + b / d - b / lcm;
	printf("%lld\n", b - a - (resB - resA));
  return 0;
}

long long read() {
  long long a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

const int N = 2020;
int n,mo,f[N*3][N];
inline void add(int &x, int y){x=x+y<mo?x+y:x+y-mo;}
int main() {
	read(n);read(mo);
	f[1][0]=1;
	rep(i,2,3*n+1)rep(j,1,min(3,i)){
		int xs=1;rep(k,i-j+1,i-1)xs=1ll*xs*(k-1)%mo;
		rep(k,0,n)if(f[i-j][k]){
			add(f[i][k+(j>=2)],1ll*f[i-j][k]*xs%mo);
		}
	}
	int res=0;rep(i,0,n)add(res,f[3*n+1][i]);
	cout<<res;
	return 0;
}


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

int main(){  
    int H, N;  cin >> H >> N;
    int A = 0;
    for(int i=0; i<N; i++){
        int a;  cin >> a;
        A += a;
    }
    if(A >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int n,A[50],q,m;

int check(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int res=check(i+1,m)||check(i+1,m-A[i]);
  //printf("res;%d\n",res );
  return res;
}

int main(){
scanf("%d", &n);
for(int i=0;i<n;i++){
scanf("%d", &A[i]);
}
scanf("%d\n", &q);
for(int j=0;j<q;j++){
  scanf("%d",&m);
  if(check(0,m)){printf("yes\n");}
  else{printf("no\n");}
}



  return 0;
}



Measured memory_bytes: 2148
def main():
    n, k = map(int, input().split(" "))
    line = [int(s) for s in input().split(" ")]
    max_num = 0
    start = 0
    total = 0
    for i in range(k):
        total += line[i]
        if max_num < line[i]:
            max_num = line[i]
    max_sum = total
    for i in range(k, n):
        total = total + line[i] - line[i - k]
        if max_num < line[i]:
            max_num = line[i]
        if max_sum < total:
            max_sum = total
            start = i - k + 1
    kitai = [0.0 for _ in range(max_num + 1)]
    total = 0
    for i in range(1, max_num + 1):
        total += i
        kitai[i] = total / i
    total = 0
    for i in range(start, start + k):
        total += kitai[line[i]]
    print(total)


if __name__ == '__main__':
    main()


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

int zettaiti(int x){
    if(x>0){
        return x;
    }else{
        return -x;
    }
}

int main(){
    int n,k,key;
    int x;
    int distance = 0;
    cin >> n >> k;
    key = k/2;
    for(int i = 0;i<n;i++){
        cin >> x;
        if(x<=key){
            distance += zettaiti(2*x);
        }else{
            distance += zettaiti(2*(x-k));
        }
    }
    cout << distance << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    u_map m;
    ll N;
    input(N);

    rep(i, 0, N)
    {
        string s;
        input(s);
        m[s] += 1;
    }

    ll M;
    input(M);
    rep(i, 0, M)
    {
        string s;
        input(s);
        m[s] -= 1;
    }

    ll res = -1000000;
    for_each(m.begin(), m.end(), [&](auto &p) {
        res = max(res, p.second);
    });

    cout << (res < 0 ? 0 : res) << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 303;
const int MOD = 1e9+7;

int N, M;
ll dp[MAX][MAX][MAX];
viii constraints;

inline int count_color(int r, int g, int b, int l) {
    return (r >= l) + (g >= l) + (b >= l);
}

int solve() {
    dp[0][0][0] = 1;

    FORE (c, constraints) {
        int left, right, x;
        left = get<0>(c);
        right = get<1>(c);
        x = get<2>(c);
        REP (a, right) REP (b, right) if (count_color(right, a, b, left) != x) {
            dp[right][a][b] = -1;
            dp[a][right][b] = -1;
            dp[a][b][right] = -1;
        }
    }

    REP (r, N) REP (g, N) REP (b, N) {
        if (dp[r][g][b] < 0) continue;
        int next = max(r, max(g, b));
        bool r_ok = true, g_ok = true, b_ok = true;
        if (dp[next+1][g][b] >= 0)
            (dp[next+1][g][b] += dp[r][g][b]) %= MOD;
        if (dp[r][next+1][b] >= 0)
            (dp[r][next+1][b] += dp[r][g][b]) %= MOD;
        if (dp[r][g][next+1] >= 0)
            (dp[r][g][next+1] += dp[r][g][b]) %= MOD;
    }
    ll ans = 0;
    REP (a, N) REP (b, N) {
        ans += max(0ll, dp[N][a][b]);
        ans += max(0ll, dp[a][N][b]);
        ans += max(0ll, dp[a][b][N]);
    }
    return ans % MOD;
}

int main() {
    cin >> N >> M;
    REP (i, M) {
        int l, r, x;
        cin >> l >> r >> x;
        constraints.push_back(make_tuple(l, r, x));
    }
    cout << solve() << endl;
}

Measured memory_bytes: 217344
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 2e5 + 2;
const int M = 1e5 + 2;
const int mod = 998244353;
const int inf = 1e9;
const ll INF = 1e16;

void data() {
	#ifdef PC
		freopen("main.in", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
}

float n;

int main() {
	data();
	scanf("%f", &n);
	printf("%f", (n * n * n) / 27.0);
}

/*
	Timus: 288481RF
	CodeForces: fractal
*/


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = input()
    b = input()
    c = input()
    ans = 0

    for i in range(n):
        s = set()
        s.add(a[i])
        s.add(b[i])
        s.add(c[i])

        if len(s) == 2:
            ans += 1
        elif len(s) == 3:
            ans += 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a[100],i,s=0,c=0;
    double x=0,t;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    x=1.0/(4*m);
    t=(s*x);
    for(i=0;i<n;i++){
        if(a[i]>=t)
            c++;
    }
    if(c<m)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

int main() {
	int n, a, cnt = 0, ans = 10e9;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		while (1) {
			if (a % 2) {
				break;
			}
			cnt++;
			a /= 2;
		}
		ans = min(ans, cnt);
		cnt = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n; cin >> n;
	if (n / 100 > 0 && n / 100 <= 12 && n % 100 > 0 && n % 100 <= 12) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (n / 100 > 0 && n / 100 <= 12) {
		cout << "MMYY" << endl;
	}
	else if (n % 100 > 0 && n % 100 <= 12) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
a = input()
la = list(map(int,a.split())) #街にいるモンスター数
b = input()
lb = list(map(int,b.split())) #ダメージ

damagecost = 0
killmonster = 0
for i in range(n):
    if lb[i] <= la[i]:
        killmonster += lb[i]
    else:
        killmonster += la[i]
        damagecost = lb[i] - la[i]
        if damagecost >= la[i + 1]:
            killmonster += la[i + 1]
            la[i + 1] = 0
        else:
            killmonster += damagecost
            la[i + 1] = la[i + 1] - damagecost
print(killmonster)


Measured memory_bytes: 20800
def main():
  s = input().split()
  n = int(s[0])
  a = int(s[1])
  b = int(s[2])
  
  if (b - a) % 2 == 0:
    print((b - a) // 2)
    return
  
  if a - 1 <= n - b:
    print(a + (b - a - 1) // 2)
    return
  
  print(n - b + 1 + (b - a - 1) // 2)
  
main()

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    string s;
    cin >> s;
    int ans = 0;
    char cur = s[0];
    rep(i,1,s.size()){
        if(s[i] != cur){
            cur = s[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
def N(x,y,n): # no of x...y < n
    r=0
    for i in range(1,n+1):
        if str(i)[0]==str(x) and str(i)[-1]==str(y):
            r+=1
    return r

ans=0
n=int(input())
for x in range(1,10):
    ans+=N(x,x,n)*N(x,x,n)
    for y in range(x+1,10):
        ans+=N(x,y,n)*N(y,x,n)*2
        
print(ans)


Measured memory_bytes: 44816
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=410,M=100010;
struct Edge{
	int u,v;
}e[M];
int n,m;
inline bool gs(bool s[]){
	for(int i=m;i>=1;i--){
		if(s[e[i].u]&&s[e[i].v])return false;
		if(s[e[i].u]||s[e[i].v]){
			s[e[i].u]=s[e[i].v]=true;
		}
	}
	return true;
}
bool live[N];
bool s[N][N];
inline int Main(){
	n=ni,m=ni;
	for(int i=1;i<=m;i++){
		e[i]=(Edge){ni,ni};
	}
	memset(s,0,sizeof(s));
	for(int i=1;i<=n;i++){
		s[i][i]=true;
		live[i]=gs(s[i]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!live[i])continue;
		for(int j=1;j<i;j++){
			if(!live[j])continue;
			ans++;
			for(int k=1;k<=n;k++){
				if(s[i][k]&&s[j][k]){
					ans--;
					break;
				}
			}
		}
	}
	return ans;
}
int main(){
	printf("%d\n",Main());
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvii;
typedef pair<int, int> ii;
typedef vector<ii> vii;

////////////////////////////////

void solve() {
	
}

const int INF = 1e9 + 1;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<vector<int>> a(3, vector<int>(n, 0));
	for (int i = 0; i < n; ++i) cin >> a[0][i] >> a[1][i] >> a[2][i];
	vector<vector<int>> dp(n, vector<int>(3, 0));
	dp[0][0] = a[0][0];
	dp[0][1] = a[1][0];
	dp[0][2] = a[2][0];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int z = 0; z < 3; ++z) {
				if (j == z) continue;
				dp[i][z] = max(dp[i][z], dp[i - 1][j] + a[z][i]);
			}
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
	return 0;
}


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

int main() {
    int A, B;
    char op;
    
    cin >> A >> op >> B;

    int result = 0;
    if (op == '+') {
        result = A + B;
    } else if (op == '-') {
        result = A - B;
    }

    cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n;cin>>n;
    ll a[n][3];
    repn(i,n){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll dp[n][3];
    repn(i,n){
        repn(j,3ll){
            dp[i][j]=0;
        }
    }
    dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
    rep(i,1,n-1){
        repn(j,3ll){
            dp[i][j]=max(dp[i-1][(j+1)%3]+a[i][j],dp[i-1][(j+2)%3]+a[i][j]);
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<( (a+c==b<<1)?"YES":"NO" )<< endl;
    return 0;
}

Measured memory_bytes: 256
//abc132_b.cpp
//Sat Jun 29 20:41:36 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	int ans = 0;
	for (int i=1;i<n-1;i++){
		if (p[i-1]>p[i] &&
			p[i]>p[i+1]){
			ans++;
		}else if (p[i-1] < p[i] &&
			p[i] < p[i+1]){
			ans++;
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
from sys import stdin
import numpy as np

def bit_search(a, n, m, x):
    res = []
    for i in range(2 ** n):
        price = 0
        skill = np.zeros((n, m))
        for j in range(n):
            if (i >> j) & 1:
                price += a[j][0]
                skill[j] = a[j][1:]
        skill_sum = np.sum(skill, axis=0)\
                        if skill.shape[0] > 1 else skill
        if (skill_sum >= x).all(): res.append(price)
    return res

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = bit_search(a, n, m, x)
    print('-1' if not res else min(res))
    return

if __name__ == '__main__':
    main()


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

vector<ll> a;
vector<ll> f;
ll n, k, sum=0;


int judge(ll x){

    ll after_training = 0;

    for(int i=0; i<n; i++){
        after_training += min((x)/f[n-i-1], a[i]);
    }

    if(sum - after_training <= k){
        // x以下にできる時
        return 0;
    }
    else{
        // x以下にできない時
        return 1;
    }
}


int main(void){

    cin >> n >> k;

    for(int i=0; i<n; i++){
        ll tmp_a;
        cin >> tmp_a;
        a.push_back(tmp_a);
    }
    sort(a.begin(), a.end());

    for(int i=0; i<n; i++){
        ll tmp_f;
        cin >> tmp_f;
        f.push_back(tmp_f);
    }
    sort(f.begin(), f.end());


    for(int i=0; i<n; i++){
        sum += a[i];
    }

    // 二分探索
    ll ok = 1000000000000;
    ll ng = -1;
    ll ans;
    while(ok - ng > 1){
        ll mid = (ok + ng ) / 2;
        // mid以下にできるとき0
        if(judge(mid)==0){
            ok = mid;
        }
        else{
            ng = mid;
        }
        ans = ok;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 4848
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	int c;
	int a,b;
	int tokuten1 = 0;
	int tokuten2 = 0;
	
	while (cin >> c) {
		tokuten1 = 0;
		tokuten2 = 0;
		if (c == 0) {
			break;
		}
		for (int i = 0; i < c; i++) {
			cin >> a >> b;
			if (a > b) {
				tokuten1 += (a + b);
			} else if (a < b) {
				tokuten2 += (a + b);
			} else {
				tokuten1 += a;
				tokuten2 += b;
			}
		}
		cout << tokuten1 << " " << tokuten2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n;

int main() {
    cin >> n;
    vector<int> h(n);
    REP(i, n){
        cin >> h[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    FOR(i,2,n){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    put(dp[n-1]);
    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N, A;
    cin >> N >> A;
    vector<int> x(N+1);
    for (int i = 1; i < N+1; i++) {
        cin >> x[i];
        x[i] -= A;
    }

    vector<vector<ll>> dp(N+1, vector<ll> (6000));

    for (int i = 0; i < 6000; i++) {
        dp[0][i] = 0;
    }
    dp[0][3000] = 1;

    for (int n = 1; n < N+1; n++) {
        for (int i = 0; i < 6000; i++) {
            if(i - x[n] < 6000 && i - x[n] >= 0){
                dp[n][i] = dp[n-1][i] + dp[n-1][i-x[n]];
            }
            else{
                dp[n][i] = dp[n-1][i];
            }
        }
    }

    printf("%lld\n", dp[N][3000] - 1);

}

Measured memory_bytes: 5552
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, m;

int main()
{
    scanf("%lld%lld", &n, &m);
    ll i = 1, j = n;
    for(; m > 0; i++, j--)
    {
        if((i - 1) - (j + 1) + i - j == -n - 2) j--;
        else if((i - 2) - (j + 2) + i - j == -n - 2) j--;
        printf("%lld %lld\n", i, j);
        m--;
    }
    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

int f(int n) {
  int ans = 1;
  rep(i, n) ans *= i + 1;
  return ans;
}

void Main() {
  Cin(int, n);
  using pii = pair<int, int>;
  vector<pii> v(n);
  rep(i, n) cin >> v[i].first >> v[i].second;
  sort(rng(v));

  double d = 0;
  do {
    rep(i, n - 1) {
      double tmp =
        hypot(v[i].first - v[i + 1].first, v[i].second - v[i + 1].second);
      d += tmp;
    }
  } while (next_permutation(rng(v)));

  d /= f(n);
  cout << d << endl;
}

Measured memory_bytes: 256