akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

A = "abcdefghij"
N = 0
def dfs(s, lim):
    global N
    if len(s) == N:
        print("".join(s))
        # s = []
        return
    for i in range(lim): # abacなどが入らない
        s.append(A[i])
        dfs(s, len(set(s)) + 1)
        s.pop()
    # print(s)
    # dfs(s, prev)
    # s[-1] = A[prev + 1]
    # dfs(s, n+1, prev+1)

def main():
    global N
    N = int(input().strip())
    dfs([], 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59096
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define Int long long int

int main() {
  string org, memo;
  cin >>org >>memo;
  int orglen = org.length(), memolen = memo.length();
  bool ans = false;
  REP(i, orglen - memolen + 1){
    string tmp = org.substr(i, memolen);
    bool isOK = true;
    REP(j, memolen) if(tmp[j] != memo[j] && memo[j] != '_') isOK = false;
    if(isOK){
      ans = true;
      break;
    }
  }
  cout <<(ans ? "Yes" : "No") <<endl;
  return 0;
}


Measured memory_bytes: 1192
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = String.valueOf(n);
        s = s.replaceAll("1","a");
        s = s.replaceAll("9","b");
        s = s.replaceAll("a","9");
        s = s.replaceAll("b","1");
        System.out.println(s);
    }
}


Measured memory_bytes: 21460
N = int(input())
t, x, y = 0, 0, 0
ans = "Yes"

for i in range(N):
  nt, nx, ny = map(int,input().split())
  if ((nt - t) - abs(nx - x) - abs(ny - y))%2 != 0 or abs(nx - x) + abs(ny - y) > (nt - t):
    ans = "No"
    break
  else:
    t = nt
    x = nx
    y = ny

print(ans)

Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main() {
    ll H, W, N; cin >> H >> W >> N;
    map<PII, vector<vector<int>>> M;
    
    for(int i=0; i<N; i++){
        int a, b; cin >> a >> b;
        a--;
        b--;
        for(int y=-2; y<=0; y++){
            for(int x=-2; x<=0; x++){
                int ny = a + y;
                int nx = b + x;
                
                bool f = false;
                for(int j=0; j<3; j+=2){
                    for(int k=0; k<3; k+=2){
                        if(ny+j<0 || ny+j>=H || nx<0 || nx+k>=W) f = true;
                    }
                }
                if(f) continue;


                if(M.find({ny, nx})==M.end()){
                    vector<vector<int>> T(3, vector<int>(3));
                    M[{ny, nx}] = T;
                }

                M[{ny, nx}][2-(a-ny)][2-(b-nx)] = 1;
            }
        }
    }
    
    
    
    vector<ll> ret(10);
    ret[0] = (H-2)*(W-2) - M.size();
    
    for(auto V:M){
        int cnt = 0;
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(V.sc[i][j]==1) cnt++;
            }
        }
        
        ret[cnt]++;
    }
    
    
    for(int i=0; i<10; i++){
        cout << ret[i] << endl;
    }
    
    return 0;
    
}





Measured memory_bytes: 225280
n= int(input())
a = list(int(i) for i in input().split())
ct = 0
flag = 0
while flag == 0:
 for i in range(n):
  if a[i]%2 == 0:
   a[i] = a[i]//2
   ct+= 1
  else:
   flag = 1
   break
print(ct//n)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<string>
#include<stack>
#include<cmath>
#include<map>
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define per(i,l,r) for(int i=(r-1);i>=l;i--)
#define P pair<int,int>
#define ll long long
using namespace std;

int main ()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
	{
		int t=a;
		a=b;
		b=t;
	}
	rep(i,a,b+1)
	{
		if(i-a==b-i)
		{
			cout<<i;
		//	while(1);
			return 0;
		 } 
	} 
	cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl "\n"
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define PRIME 1000000007
#define max 200006
// bool a[max];
using namespace std;
typedef vector<vector<ll>> matrix;
// ll e[max], f[max];
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    // int t;
    // cin >> t;
    // while (t--)
    // {
 
        
    // }
    int n;
    cin>>n;
   int temp = n%10;
   if(temp==3)
   cout<<"bon";
   else if(temp == 0 || temp == 1 || temp == 6 || temp== 8)
   cout<<"pon";
   else{
       cout<<"hon";
   }

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;
const int nax = 200005;
int a[nax],n,k;
void solve()
  {
   cin>>k>>n;
   int mx = 0;
   loop(i,0,n)
    cin>>a[i];
   loop(i,1,n)
    mx = max(mx,a[i]-a[i-1]);
   mx = max(a[0]+k-a[n-1],mx);
   cout<<k-mx;
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

const int MAX_N = 100010;
vector<vector<pii>> g;
bool visited[MAX_N];
int dist[MAX_N];
int maxDist = 0;
int maxDistNode = 0;

void dfs(int u) {
    visited[u] = true;
    if (chmax(maxDist, dist[u])) {
        maxDistNode = u;
    }

    for (pii edge: g[u]) {
        int w = edge.first;
        int v = edge.second;
        if (!visited[v]) {
            dist[v] = dist[u] + w;
            dfs(v);
        }
    }
}

int main() {
    int n; cin >> n;
    g.resize(n);
    rep(i, n-1) {
        int s, t, w; cin >> s >> t >> w;
        g[s].pb(mp(w, t));
        g[t].pb(mp(w, s));
    }

    dfs(maxDistNode);
    rep(i, n) {
        visited[i] = false;
        dist[i] = 0;
    }
    dfs(maxDistNode);
    cout << maxDist << endl;
}



Measured memory_bytes: 11848
N,M=map(int,input().split())
s=[list(map(int,input().split()))[1:] for i in range(M)]
p=list(map(int,input().split()))

cnt=0

for i in range(2**N):
    for k in range(M):
        tmp=0
        for j in range(N):
            if ((i >> j) & 1) and j+1 in s[k]:
                tmp+=1
        if tmp%2!=p[k]:
            break
    else:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
N=gets.to_i
r=1.step(N-2,2).flat_map{|i|[[0,i],[i,0]]}
r+=(N%2).step(N-1,2).flat_map{|i|[[N-1,i],[i,N-1]]}
1.step(N-2,3){|j|
	(1+j%2).step(N-2,2){|i|
		r<<[i,j]
	}
}
p r.size
puts r.map{|e|e*' '}

Measured memory_bytes: 52604
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
using namespace std;
using ull = unsigned long long;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];
    int max_l = 0;
    int sum = 0;
    for(int i = 0; i < N; i++){
        max_l = max(L[i], max_l);
        sum += L[i];
    }
    if(sum - max_l > max_l) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin>>n;
  
  cout<<2*n/gcd(2,n)<<endl;
  
  return 0;
}

Measured memory_bytes: 3604
from collections import Counter

n = int(input())
vs = input().split()

xs = [v for v in vs[::2]]
x = Counter(xs).most_common()

ys = [v for v in vs[1::2]]
y = Counter(ys).most_common()

if x[0][0] != y[0][0]:
    d = n - x[0][1] - y[0][1]
    print(d)
else:
    if len(x) == 1:
        print(n // 2)
    else:
        d1 = n - x[0][1] - y[1][1]
        d2 = n - x[1][1] - y[0][1]
        if d1 > d2:
            print(d2)
        else:
            print(d1)


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

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, y;
  int a = -1, b = -1, c = -1;
  cin >> n >> y;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; i + j <= n; ++j) {
      if (10000*i + 5000*j + (n-i-j)*1000 == y) {
        a = i; b = j; c = (n-i-j);
        break;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    std::string s;
    cin >> s;
    if((s[2]==s[3])&&(s[4]==s[5])){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int a; int b; int c; int i; int n; int st; int sa;
	cin >> n;
	for (i = 1; i <= n; i++){
		cin >> a >> b >> c;
		a = a*a;
		b = b*b;
		c = c*c;
		if (a < b){
			if (b < c){
				st = c;
			}
			else{
				st = b;
				b = c;
			}
		}
		else{
			if (a < c){
				st = c;
			}
			else{
				st = a;
				a = c;
			}
		}
		sa = st - a - b;
		if (sa == 0){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return  0;
}

Measured memory_bytes: 1152
n = int(input())
x = list(map(int,input().split()))
a = x[:]
a.sort()
kijun = a[n//2]
a1 = a[n//2]
a2 = a[n//2-1]
for i in x:
	if i < kijun:
		print(a1)
	else:
		print(a2)

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

using namespace std;

const int INF = 1 << 30;

struct edge
{
  int to, cost;
};

int main()
{
  int N, M, D[50], E[50];
  int dp[50][50][1 << 10];

  while(scanf("%d %d", &N, &M), N) {
    vector< edge > gg[50], rg[50];
    D[0] = E[0] = D[N - 1] = 0, E[N - 1] = 1000;
    int comp[1001] = {}, rev[50];
    for(int i = 1; i < N - 1; i++) {
      scanf("%d %d", &D[i], &E[i]);
    }
    for(int i = 0; i < N; i++) {
      rev[i] = comp[E[i]]++;
    }

    for(int i = 0; i < M; i++) {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      --a, --b;
      gg[a].emplace_back((edge) {b, c});
      rg[b].emplace_back((edge) {a, c});
    }

    using T = tuple< int, int, int, int >;
    priority_queue< T, vector< T >, greater< >> que;
    fill_n(**dp, 50 * 50 * (1 << 10), INF);
    dp[0][0][0] = 0;
    que.emplace(0, 0, 0, 0);

    auto push = [&](int latte, int malta, int beet, int cost)
    {
      if(cost < dp[latte][malta][beet]) {
        dp[latte][malta][beet] = cost;
        que.emplace(cost, latte, malta, beet);
      }
    };

    bool reach = false;

    while(!que.empty()) {
      int latte, malta, beet, cost;
      tie(cost, latte, malta, beet) = que.top();
      que.pop();
      if(latte == N - 1 && malta == N - 1) {
        cout << cost << endl;
        reach = true;
        break;
      }
      for(auto &e : gg[latte]) {
        if(E[latte] <= E[e.to]) {
          if(E[e.to] < E[malta]) {
            push(e.to, malta, beet, cost + e.cost + D[e.to]);
          } else if(E[e.to] == E[malta] || E[latte] == E[e.to]) {
            if((beet >> rev[e.to]) & 1) push(e.to, malta, beet, cost + e.cost);
            else push(e.to, malta, beet | (1 << rev[e.to]), cost + e.cost + D[e.to]);
          } else {
            push(e.to, malta, 1 << rev[e.to], cost + e.cost + D[e.to]);
          }
        }
      }


      for(auto &e : rg[malta]) {
        if(E[malta] <= E[e.to]) {
          if(E[e.to] < E[latte]) {
            push(latte, e.to, beet, cost + e.cost + D[e.to]);
          } else if(E[e.to] == E[latte] || E[malta] == E[e.to]) {
            if((beet >> rev[e.to]) & 1) push(latte, e.to, beet, cost + e.cost);
            else push(latte, e.to, beet | (1 << rev[e.to]), cost + e.cost + D[e.to]);
          } else {
            push(latte, e.to, 1 << rev[e.to], cost + e.cost + D[e.to]);
          }
        }
      }


    }


    if(!reach) puts("-1");
  }

}

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


int main(){
	LL N;
	cin >> N;
	LL A, B;
	cin >> A >> B;
	LL ans = 0;
	LL tmp = 0;
	tmp = N / (A + B);
	ans += tmp * A;
	tmp = N - tmp * (A + B);
	if(tmp >= A) ans += A;
	else ans += tmp;
	cout << ans << endl;

}












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

using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n;
vector<int> height;
void in(){
	cin >> n;
	for(int i = 0; i < n; i ++) {
		int h; cin >> h;
		height.push_back(h);
	}
}

int dp[100010];

int dfs(int i) { //カエルのいる場所
	if(i == n - 1) return 0;

	if(dp[i] > -1) return dp[i];

	int ans = inf;

	chmin(ans, abs(height[i] - height[i + 1]) + dfs(i + 1)); //1つ先

	if(i + 2 <= n - 1) {
		chmin(ans, abs(height[i] - height[i + 2]) + dfs(i + 2));
	}

	return dp[i] = ans;
}

void solve(){
	memset(dp, -1, sizeof(dp));
	print(dfs(0));


}

signed main(){

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

}

Measured memory_bytes: 9492
s = input().split()

a = s[0]
b = s[1]
c = s[2]

five_count = 0
seven_count = 0

if a == '5':
    five_count += 1
elif a == '7':
    seven_count += 1

if b == '5':
    five_count += 1
elif b == '7':
    seven_count += 1

if c == '5':
    five_count += 1
elif c == '7':
    seven_count += 1

if five_count == 2 and seven_count == 1:
    answer = 'YES'
else:
    answer = 'NO'

print(answer)


Measured memory_bytes: 8980
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 1;
  // ll n;
  // cin >> n;
  ll a, b, c;
  cin >> a >> b;
  // ll n, m, k;
  // cin >> n >> m >> k;
  c = gcd(a, b);

  int found = 0;
  while(c % 2 == 0) {
    found = 1;
    c /= 2;
  }
  if(found) ans++;
  for(int i = 3; i <= sqrt(c); i += 2) {
    found = 0;
    while(c % i == 0) {
      found = 1;
      c /= i;
    }
    if(found) ans++;
  }
  if(c > 2) ans++;
  cout << ans << endl;
  return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;

  for (int i = 1; i <= 1250; ++i) {
    int e = i * 0.08;
    int t = i * 0.10;
    if (e == a && b == t) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

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

using namespace std;
using ll = long long;
const ll INF = 100000000;

int main() {
    int n;
    int tmp;
    int res = 0;
    cin >> n;
    rep(i, n) {
        cin >> tmp;
        if ((i+1) % 2 == 1 && tmp % 2 == 1) {
            res++;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int vmax, vmin;
    if(A+B<N){
        vmax = min(A, B);
        vmin = 0;
    }else{
        vmax = min(A, B);
        vmin = A + B - N;
    }

    cout << vmax << ' ' << vmin << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n, m;
	cin >> n >> m;

	vector<int> a(m), b(m), c(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}

	vector<vector<int>> dist(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dist[i][j] = i == j ? 0 : INF;
		}
	}

	for (int i = 0; i < m; i++) {
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	int ans = m;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (dist[j][a[i]] + c[i] == dist[j][b[i]]) {
				ans--;
				break;
			}
		}
	}

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


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;
int main() {

    int x,y,i,j,k,l,number_of_coloring;
    int left_coloring_x = 0;
    int right_coloring_x = 0;
    int upper_coloring_y = 0;
    int lower_coloring_y = 0;

    cin >> x >> y >> number_of_coloring;
  
    for(i = 0; i < number_of_coloring;i++){
        cin >> j >> k >> l;

        switch(l){
            case 1:
                if(left_coloring_x < j){
                    left_coloring_x = j;
                }
                break;
            case 2:
                if(right_coloring_x < abs(x - j)){
                    right_coloring_x = abs(x - j);
                }
                break;
            case 3:
                if(lower_coloring_y < k){
                    lower_coloring_y = k;
                }
                break;
            case 4:
                if(upper_coloring_y < abs(y - k)){
                    upper_coloring_y = abs(y - k);
                }
                
                break;
        }
    }
 
    x = x - left_coloring_x - right_coloring_x;
    y = y - lower_coloring_y - upper_coloring_y;

    if(x <= 0 || y <= 0) {
        cout << 0 << endl;
    } else {
        cout << x * y << endl;
    }
    return 0;
}

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

vector<int> v(300000), ans, ans2,ans3;
int vis[300000], vis2[300000];

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,b;
	cin>>a>>b;
	forr(i,1,a+1)
	{
		long long int x;
		cin>>x;
		v[i]=x;
	}
	if(b<=a)
	{
		long long int x=1;
		forr(i,0,b)
			x=v[x];
		cout<<x;
		return 0;
	}
	
	int k=1,flag=0;
	ans.push_back(1);
	vis[1]++;
	while(1)
	{
		
		if(flag)
			vis[k]++;
		if(vis[k]==3)
			break;
		ans.push_back(v[k]);
		k=v[k];
		flag=1;
	}
	forr(i,0,ans.size())
	{
		if((vis[ans[i]]==2 or vis[ans[i]]==3) and !vis2[ans[i]])
			ans3.push_back(ans[i]), vis2[ans[i]]=1;
		else if(vis[ans[i]]==1 and !vis2[ans[i]])
			ans2.push_back(ans[i]), vis2[ans[i]]=1;
	}
	long long int x=(b-ans2.size())%ans3.size();
	cout<<ans3[x];

	return 0;
}

Measured memory_bytes: 8056
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) const { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

using mint = modint<1000000007>;

mint dp[101][5][5][5];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  dp[0][0][0][0] = 1;
  int n;
  cin >> n;
  rep(i, n) rep(j, 5) rep(k, 5) rep(l, 5) reps(m, 4) {
    if (k == 1 && l == 2 && m == 3) continue;
    if (k == 1 && l == 3 && m == 2) continue;
    if (k == 3 && l == 1 && m == 2) continue;
    if (j == 1 && k == 3 && m == 2) continue;
    if (j == 1 && l == 3 && m == 2) continue;
    dp[i + 1][k][l][m] += dp[i][j][k][l];
  }
  mint ans = 0;
  rep(j, 5) rep(k, 5) rep(l, 5) {
    ans += dp[n][j][k][l];
  }
  cout << ans << endl;
  return 0;
}


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


int main() {
	
	string s;
	cin >> s;
	for(int i='a'; i<='z'; i++){
		bool flag = 0;
		for(auto j : s){
			if(j==i) flag = 1;
			continue;
		}
		if (flag == 0) {
			cout << (char)i << endl;
			break;
		}
		if (i=='z') cout << "None" << endl; 
	}
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
int aa(string s,int i,int n){
    int alpha[26],alpha2[26];
    for(int i=0;i<26;i++){
        alpha[i]=0;
        alpha2[i]=0;
    }
    for(int j=0;j<=i;j++){
        int a=s[j]-'a';
        alpha[a]++;
    }
    for(int j=i+1;j<n;j++){
        int a=s[j]-'a';
        alpha2[a]++;
    }
    int a=0;
    for(int i=0;i<26;i++){
        if(alpha[i]!=0&&alpha2[i]!=0){
            a++;
        }
    }
        return a;
    
    
}

int main(){
    int n;
    string s;
    cin>>n>>s;
    
    int max=0;
    int premax=0;
    for(int i=0;i<=n;i++){
        
            int max=aa(s,i,n);
            
        if(premax<=max){
            premax=max;
        }
        
        
    }
    cout<<premax;


return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int X,N,min = 99999,minn = 0,a = 0,sw = 0;
 cin >> X >> N;
	vector<int> num;
  vector<int> check;
    froop1(1,101){
    cin >> a;
    num.push_back(a);
  }
  int i = X;
  for(int j = -100;j < 200;j++){
    sw = 0;
    for(int k = 0;k < num.size();k++){
      if(j == num.at(k)){
        sw = 1;
      }
    }
    if(sw == 0){
		check.push_back(j);
    }
  }
  
  for(int j = 0;j < check.size();j++){
    if(min > abs(check.at(j) - X)){
      min = abs(check.at(j) - X);
      minn = check.at(j);
    }else if(min == abs(check.at(j) - X)){
      if(minn > check.at(j)){
        minn = check.at(j);
      }
    }
  }
  cout << minn << endl;
return 0;
}

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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main() {
    int X; cin >> X;
    int n; 
    n = X / 500;
    ll cnt = 0;
    cnt += 1000 * n;
    X -= 500 * n;
    n = X / 5;
    cnt += 5 * n;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
  ll n; cin>>n;
  vector <ll> a (n);
  for (auto &i : a) cin>>i;
  ll dp[n]; dp[0]=0; dp[1]=abs(a[1]-a[0]);
  for (ll i=2;i<n;++i) {
    dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1])); 
  }
  cout<<dp[n-1];
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end(), greater<int>());

  int x = 0;  
  
  for(int i = 0; i < N; i++){
    if (i%2==0){
      x += a.at(i);
    }
    else{
      x -= a.at(i);
    }
  }
  cout << x << endl;  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n, f1[100100], f2[100100], f3[100100];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        long long a, b, c;
        cin >> a >> b >> c;
        f1[i] = max(f2[i - 1], f3[i - 1]) + a;
        f2[i] = max(f3[i - 1], f1[i - 1]) + b;
        f3[i] = max(f1[i - 1], f2[i - 1]) + c;
        //cout << f1[i] << " " << f2[i] << " " << f3[i] << "\n";
    }
    cout << max(f1[n], max(f2[n], f3[n]));
}


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

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

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

    sort(a.begin(), a.end());
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }

    for (int i = 0; i < n; ++i) {
        if ((sum - a[i]) % 10 != 0) {
            cout << sum - a[i] << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,K,Z[41],T[41],ARR[41],ans,KB[41],sum;
int main(){
    cin>>N>>K;
    ll d=ll(log2(K));
    ll temp=K;
    for(int i=0 ; i<41; i++){
        KB[i]=temp%2;
        temp/=2;
    }
    for(int i=0 ; i<N ; i++){
        ll a;
        cin>>a;
        sum+=a;
        int ind=0;
        for(int j=0 ; j<41 ; j++){
            if(a%2)T[ind]++;
            else Z[ind]++;
            a/=2;
            ind++;
        }
    }
    for(int i=0 ; i<=d ; i++){
        for(int j=0 ; j<41 ; j++)ARR[j]=0;
        if(KB[i]==1){
            for(int j=40 ; j>=0 ; j--){
                if(j>d)ARR[j]=T[j];
                else if(j<=d&&j>i){
                    if(KB[j]==1)ARR[j]=Z[j];
                    else ARR[j]=T[j];
                }
                else if(i==j)ARR[j]=T[j];
                else{
                    ARR[j]=max(T[j],Z[j]);
                }
            }
        }
        //for(int j=0 ; j<41 ; j++)cout<<ARR[j];
        //cout<<"\n";
        ll a=0;
        for(int j=0 ; j<41 ; j++){
            a+=ARR[j]<<j;
        }
        ans=max(a,ans);
        //cout<<a<<"\n";
    }
    for(int j=0 ; j<41 ; j++)ARR[j]=0;
        for(int j=40 ; j>=0 ; j--){
            if(j>d)ARR[j]=T[j];
            else if(j<=d){
                if(KB[j]==1)ARR[j]=Z[j];
                else ARR[j]=T[j];
            }
        }
    //for(int j=0 ; j<41 ; j++)cout<<ARR[j];
    //cout<<"\n";
    ll a=0;
    for(int j=0 ; j<41 ; j++){
        a+=ARR[j]<<j;
    }
    ans=max(a,ans);
    //cout<<a<<"\n";
    if(K==0){
        cout<<sum;
        return 0;
    }
    cout<<ans;
}


Measured memory_bytes: 640
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ans=[0]*h*w
k=0
for i in range(n):
  for j in range(a[i]):
    ans[k]=i+1
    k+=1
for i in range(h):
  if i%2==0:
    print(*ans[i*w:(i+1)*w])
  else:
    print(*ans[i*w:(i+1)*w][::-1])

Measured memory_bytes: 3828
#include <stdio.h>

int main(void)
{
	int a, b, c, sum;
	float hei, hei_su;
	
	sum = 0;
	hei_su = 0;
	while (scanf("%d,%d", &a, &b) != EOF){
		sum += a * b;
		hei += b;
		hei_su++;
	}
	
	hei = hei / hei_su;
	
	hei += 0.5;
	
	printf("%d\n%.0f\n", sum, hei);
	
	return (0);
}

Measured memory_bytes: 628
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,k;
long long a[202020],ans,al;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=k;i++)
	{
		ans+=a[i];
	}
	int l=1,r=k;
	while(r<n)
	{
		al=max(al,ans);
		ans-=a[l];
		ans+=a[r+1];
		l++;
		r++;
	}
	al=max(al,ans);
	al+=k;
	if(al%2==0)
	{
		cout<<al/2<<endl;
	}
	else
	{
		cout<<al/2<<".5"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
import sys
N,K=map(int,input().split())
s=input()

x=[]
tmp=0
for i in range(N):
    if s[i]=="1":
        if tmp!=0: x.append([tmp,i-1]) 
        tmp=0
    
    else: tmp+=1
if tmp!=0: x.append([tmp,i]) 

l=len(x)
if l<=K: print(N),sys.exit()

y=[ [0, x[1][1]-x[1][0] ] ]
for i in range(1,l-1):
    y.append([x[i-1][1]+1, x[i+1][1]-x[i+1][0] ])

y.append([x[l-2][1]+1 ,N-1])
ans=0
for i in range(l-K+1):
    ans=max(ans,y[i+K-1][1]-y[i][0]+1 )
print(ans)

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

int main() {
  string s; cin >> s;
  string f, b;
  int n = s.length();
  
  
  f = s.substr(0,((n-1)/2));
  b = s.substr((n+3)/2-1);
  
   
  string f_a = f, b_a = b;
  reverse(f.begin(), f.end());
  reverse(b.begin(), b.end());
  
  if ((f == f_a) && (b == b_a) && f == b) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;

	int arr[n+1];

	for(int i=1;i<n+1;i++)
		cin>>arr[i];

	int dp[n+1];
	 dp[1]=0;
	 dp[2]=abs(arr[2]-arr[1]);

	for(int i=3;i<n+1;i++)
	{
		dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
	}
	cout<<dp[n]<<endl;
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x ,int y){return (x%mod + y%mod)%mod;}
inline int submod(int x ,int y){return (x%mod - y%mod + mod)%mod;}
inline int mulmod(int x ,int y){return (x%mod *1LL* y%mod)%mod;}
inline int nextSubMask(int i , int mask) {return (i-1)&mask;} /// returns next smallest submask

void we_r_done(){cout<<"NO"; exit(0);}

void debug(bool ok , string mssg)
{
    if(ok)return;
    cout<<mssg;
    exit(0);
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    FastIO;

    string s,t;
    cin>>s>>t;

    vector<int>pos[30];

    for(int i=0; i<s.size(); i++){
        int now = s[i]-'a';

        pos[now].pb(i);
        pos[now].pb(i+s.size());
    }

    for(int i=0; i<26; i++) sort(atoz(pos[i]));


    lli ans = 0;

    for(int i=0 , is = 0; i<t.size(); i++){

        int now = t[i]-'a';

        int idx = lower_bound(atoz(pos[now]) ,is) - pos[now].begin();

        if(idx == pos[now].size()){
            ans = -1;
            break;
        }

        idx = pos[now][idx];

        if(idx>=s.size()){
            ans += s.size()-is;
            idx -= s.size();
            ans += idx+1;
            is = idx+1;
        }
        else{
            ans += idx-is+1;
            is = idx+1;
        }
        is %= s.size();
    }

    cout<<ans;

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 1736
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

const int MAX_N = 1e5;
ll N, M;
set<int> edge[MAX_N];
bool used[MAX_N];
int color[MAX_N];

// 2部グラフかどうか
// 黒と白の2色で塗っていく
// u: 頂点，c:色
bool dfs(int u, int c) {
    used[u] = true;
    color[u] = c;
    for (auto v: edge[u]) {
        // (訪問済み and 色が違う) or (訪問してない and dfs(この頂点，違う色))
        if ((used[v] && 1 - c != color[v]) || (!used[v] && !dfs(v, 1-c))) {
            return false;
        }
    }

    return true;
}

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

    cin >> N >> M;
     REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].insert(b);
        edge[b].insert(a);
    }

    if (!dfs(0, 0)) {
        // 2部グラフでない→奇数サイクルが存在（同じ色同士でのパスがあるから），
        // 任意の2頂点間に奇数長のパスを作成できる
        // よって，2頂点の組み合わせ - すでにある辺の数
        cout << N * (N - 1) / 2 - M << endl;
    } else {
        // 違う色同士の頂点間には必ず辺を貼ることができる，
        // 黒＊白 - すでにある辺
        int count = 0;
        REP(i, N) {
            count += color[i];
        }
        cout << count * (N - count) - M << endl;
    }

    return 0;
}


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

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

  vector<int> C(26);
  for (int i = 0; i < 26; i++) cin >> C.at(i);

  vector<vector<int>> S(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) cin >> S.at(i).at(j);
  }

  vector<int> T(D);
  for (int i = 0; i < D; i++) {
    cin >> T.at(i);
    T.at(i)--;
  }

  vector<int> L(26);
  long long v = 0;

  for (int d = 0; d < D; d++) {
    v += S.at(d).at(T.at(d));
    L.at(T.at(d)) = d+1;
    for (int i = 0; i < 26; i++) {
      v -= C.at(i) * (d+1 - L.at(i));
    }
    cout << v << endl;
  }
}

Measured memory_bytes: 3672
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {1,0,-1,0};

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;

		vector<int> score;
		for(int i=0;i<n;i++){
			int s;
			scanf("%d",&s);
			score.push_back(s);
		}

		sort(score.begin(),score.end());

		int sum=0;
		for(int i=1;i<score.size()-1;i++){
			sum += score[i];
		}

		printf("%d\n",sum/(score.size()-2));
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int W,a,b;
    while(cin>>W>>a>>b)
    {
        int k=a+W;
        if(b<=k&&b>=a)
            cout<<0<<endl;
        else
            cout<<min(abs(a-(b+W)),abs(b-(a+W)))<<endl;
    }
    return 0;
}


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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N;
  cin >> N;
  VI A(N);
  REP(i, N) cin >> A.at(i);

  int dp[N+10][3];

  dp[0][0]=0;
  dp[0][1]=0;
  dp[1][0]=A.at(0)+A.at(1);
  dp[1][1]=A.at(0)*(-1)-A.at(1);

  FOR(i, 2, N){
    dp[i][0]=max(dp[i-1][1]+A.at(i), dp[i-1][0]+A.at(i));
    dp[i][1]=max(dp[i-1][1]+2*A.at(i-1)-A.at(i), dp[i-1][0]-2*A.at(i-1)-A.at(i));
  }

  cout << max(dp[N-1][0],dp[N-1][1])<< endl;
  return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int calc(string ex)
{
	if(ex[0]=='(')	ex=ex.substr(1,ex.length()-2);

	for(int i=0,depth=0;i<ex.length();i++){
		if     (ex[i]=='(')	depth++;
		else if(ex[i]==')')	depth--;
		else{
			if(depth==0 && (ex[i]=='+'||ex[i]=='-'||ex[i]=='*')){
				switch(ex[i]){
					case '+':	return calc(ex.substr(0,i-1))+calc(ex.substr(i+2));
					case '-':	return calc(ex.substr(0,i-1))-calc(ex.substr(i+2));
					case '*':	return calc(ex.substr(0,i-1))*calc(ex.substr(i+2));
				}
			}
		}
	}

	return ex[0]-'0';
}

int main()
{
	char op[]={'+','-','*'};
	char *fmt[]={"(((%d %c %d) %c %d) %c %d)",
				 "((%d %c (%d %c %d)) %c %d)",
				 "((%d %c %d) %c (%d %c %d))",
				 "(%d %c ((%d %c %d) %c %d))",
				 "(%d %c (%d %c (%d %c %d)))"};

	 for(int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d),a|b|c|d;){
		int n[]={a,b,c,d};
		sort(n,n+4);
		do{
			for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++){
				for(int l=0;l<5;l++){
					char ex[20];
					sprintf(ex,fmt[l],n[0],op[i],n[1],op[j],n[2],op[k],n[3]);
					if(calc(ex)==10){
						puts(ex);
						goto FOUND;
					}
				}
			}
		}while(next_permutation(n,n+4));
		puts("0");
		FOUND:;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::unordered_set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }


void solve(void)
{
  ui N{}; cin >> N;

  using MSet = std::multiset<ll>;
  MSet S{};
  for(ui tmp = 0; tmp < 1U << N; ++tmp)
  {
    ll s; cin >> s;
    S.emplace(s);
  }

  MSet Tree{};
  auto last = S.end(); --last;

  Tree.emplace(*last);
  S.erase(last);

  while(!S.empty())
  {
    MSet work{};
    while(!Tree.empty())
    {
      auto max = Tree.end();
      --max;
      auto it = S.lower_bound(*max);
      if(it == S.begin())
      {
        cout << "No" << CRLF;
        return;
      }
      else
      {
        --it;
        work.emplace(*max);
        work.emplace(*it);
        Tree.erase(max);
        S.erase(it);
      }
    }

    Tree = std::move(work);
  }
  cout << "Yes" << CRLF;

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 12544
N = int(input())
P = list(map(int,input().split()))
Q = sorted(P)

counter = 0

for i in range(N):		#rangeは範囲（長さ）を表すからNでよい
	if P[i] != Q[i]:
		counter = counter + 1

if counter>2:
	print('NO')
else:
	print('YES')

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int n,i,c,f=0,a[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            c++;
        if(a[i]%3==0||a[i]%5==0)
        {
            f++;
        }
        }
    }
    if(f==c)
    {
        printf("APPROVED\n");
    }
    else
        printf("DENIED\n");
    return 0;
}


Measured memory_bytes: 128