akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn rec(u: usize, parent: &Vec<usize>, weight: &Vec<usize>, result: &mut Vec<Option<usize>>) -> usize {
    if u == 0 {
        return weight[0];
    }
    if let Some(value) = result[u] {
        return value;
    }
    result[u] = Some(weight[u] + rec(parent[u], parent, weight, result));
    result[u].unwrap()
}

fn main() {
    input! {
        n: usize,
        q: usize,
        ab: [(usize, usize); n - 1],
        px: [(usize, usize); q],
    }
    let mut parent = vec![0; n];
    for (a, b) in ab {
        parent[b - 1] = a - 1;
    }
    let mut weight = vec![0; n];
    for (p, x) in px {
        weight[p - 1] += x;
    }
    let mut result = vec![None; n];

    result[0] = Some(weight[0]);
    for u in 1..n {
        rec(u, &parent, &weight, &mut result);
    }
    for u in 0..n {
        println!("{}", result[u].unwrap());
    }
}


Measured memory_bytes: 15140
using System;

namespace Atcoder2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Akun = Console.ReadLine().Split(' ');
            double Astart = double.Parse(Akun[0]);
            double Aspeed = double.Parse(Akun[1]);
            string[] Bkun = Console.ReadLine().Split(' ');
            double Bstart = double.Parse(Bkun[0]);
            double Bspeed = double.Parse(Bkun[1]);
            double time = double.Parse(Console.ReadLine());

            double distance = Math.Abs(Bstart - Astart);
            if (Bstart < Astart)
            {
                Bstart = Astart + distance;
            }

            bool flag = false;

            double maibyou = Aspeed - Bspeed;
            if(maibyou <= 0)
            {
                flag = false;
            }else if(distance / maibyou <= time)
            {
                flag = true;
            } else
            {
                flag = false;
            }

            if(flag)
            {
                    Console.WriteLine("YES");
            }
            else
            {
                    Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 27548
[A,B,K] = [int(i) for i in input().split()]
def make_gcd(a,b):
    while b:
        a,b = b,a%b
    return a
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors = sorted(divisors,reverse=True)
    return divisors
gcd = make_gcd(A,B)
print(make_divisors(gcd)[K-1])

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int nn = n;
    int cnt = 0;
    while (n) {
        cnt += n % 10;
        n /= 10;
    }
    //cout << nn << " " << n << endl;
    if (nn % cnt == 0) {
        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;
  vector<string> data(N);
  int max = 0;
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  int count = 0;
  for(int i = 0; i < N; i++) {
    if(i == 0) {
      count = 1;
    }
    else if(data.at(i) == data.at(i - 1)) {
      count++;
    }
    else {
      count = 1;
    }
    if(count > max) {
      max = count;
    }
  }
  vector<string> ans;
  int count2 = 0;
  for(int i = 0; i < N; i++) {
    if(i == 0) {
      count2++;
    }
    else if(data.at(i) == data.at(i - 1)) {
      count2++;
    }
    else {
      count2 = 1;
    }
    if(count2 == max) {
      ans.push_back(data.at(i));
    }
  }
  for(int i = 0; i < ans.size(); i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 15988
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;
typedef long long ll;

// AtCoder Beginner Contest 142
int main(){

    int n, k;
    cin >> n >> k;
    int ans = 0;
    rep(i, n){
        int a;
        cin >> a;
        if(a >= k)ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,k,s=0,l=0,sum1=0,sum2=0,start=0,m=0;
    cin>>n>>k;
    int A[n];

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

    for(int i=0;i<n;i++){
        if(0<=A[0]){
            l=0;
            m=2*A[n-1];
            break;
        }else if(0>=A[n-1]){
                 l=n;
                 m=-2*A[0];
                 break;
                 }
         else if(i!=0 && i!=n-1&& A[i-1]<0 && 0<A[i]){
            l=i;
            m=-2*A[0] + 2*A[n-1];
            break;
         }
        }

        for(int i=0;i<=l;i++){
                if(i>=l-k && i<l && i+k<=n){
                    sum1=A[i];
                    if(i+k==l){
                        sum2=0;
                    }else{
                        sum2=A[i+k-1];
                    }

                }else if(i==l && i+k<=n){
                    sum1=0;
                    sum2=A[i+k-1];
                    }
                if(m>-2*sum1+sum2){
                    m=-2*sum1+sum2;
                }
                if(m>-1*sum1+2*sum2){
                    m=-1*sum1+2*sum2;
                }

        }
        if(l==n){
            m=-1*A[n-k];
        }
        cout<<m;

}











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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    vector<pair<int,int>> A;
    for (int i = 0; i < N; i++) { 
        int ai; cin >> ai;
        A.push_back(make_pair(ai, i));
    }
    sort(begin(A), end(A));
    reverse(begin(A), end(A));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (A[j].second != i) {
                cout << A[j].first << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3312
s = input()
l = len(s)

for i in range(2**(l-1)):
    f = ""
    for j in range(l-1):
        f += s[j]
        if i & (1 << j):
            f += "+"
        else:
            f += "-"
        if j == l-2:
             f += s[l-1]
    if eval(f)==7:
        print(f+"=7")
        break

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

#define fori( tt,aa)      for(long long i= tt; i<aa; i++)
#define forj( yy,bb)      for(long long j=yy; j<bb; j++)
#define fork( uu,cc)      for(long long k=uu; k<cc; k++)
#define sz(v)    v.size()
#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define EPS 1e-7
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE; fast();

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string String;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast(){
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
}

ld pow (ll a, ll b);
ll numOfDigits(ll n);
ll BN (vecint &v, ll j, ll sum);

int main()
{
    THINK_TWICE_CODE_ONCE;
    //freopen("test cases\\be together.txt", "r", stdin);
    int n; cin>>n;
    int arr[n];
    fori(0,n ) cin>>arr[i];
    ll c = -100, mn = LLONG_MAX;
    fori(-100,101){
        ll cost = 0;
        forj(0,n){
            if(arr[j] != c){
                cost += pow(arr[j]-c,2);
            }
        }
        c++;
        mn = min(mn, cost);
    }
    cout<<mn;
    return 0;
}
ld pow (ll a, ll b){
    ld pow = 1;
    fori(0,b)
        pow *=a;
    return pow;
}
/*
ll BN (vecint &v, ll j, ll sum){
int low = j;
int up = n-1;
ll ans = -1;
while(low<=up){
    ll mid = ((ll)low+ up)/2;
    if(sum>v[mid]){
        ans = mid;
        low = mid+1;
    }else up = mid-1;
}
return ans;
}*/

ll numOfDigits(ll n){
    if(!n) return 1;
    return (ll)(log10(n)+1);
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
ave1 = sum(A)//n
ave2 = ave1+1
ans1 = 0
ans2 = 0
for a in A:
    ans1 += (a-ave1)**2
    ans2 += (a-ave2)**2
print(min(ans1,ans2))

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

int main() {
	long long N;
	string S;
	cin >> N >> S;
	if (N % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

v = [[0, 0] for _ in range(N)]
s = []
ans = 500

for i in range(1<<N):
    tmp = 0
    for j in range(N):
        if ((i>>j)&1): v[j] = [B[j], j]
        else:          v[j] = [A[j], j]
    for j in range(N):
        p = j
        while (p and v[p][0] < v[p-1][0]):
            v[p], v[p-1] = v[p-1], v[p]
            tmp += 1
            p -= 1
    for j in range(N):
        if (((i>>v[j][1])+v[j][1]-j)&1):
            s.append(v[j][0]*500+j)
    if (len(s)&1):
        tmp = 500
        s.pop()
    while s:
        p = s.pop()
        q = s.pop()
        if ((p-q)&1): tmp += p-q
        else:         tmp += 500
    ans = min(ans, tmp)

if ans < 500:
    print(ans)
else:
    print(-1)


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

int main() { 
    int n, m, ans = 0;
    cin >> n >> m;
    int red[n] = {0}, sum[n];
    red[0] = 1;
    for(int i = 0; i < n; ++i) sum[i] = 1;

    int x, y;
    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        x--, y--;
        if(red[x]) {
            red[y] = 1;
        }
        sum[x]--;
        sum[y]++;
        if(sum[x] == 0) {
            red[x] = 0;
        }
    }

    for(int i = 0; i < n; ++i) {
        if(red[i]) ans++;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;


int main(){
	long long A, B, C, K;
	cin >> A >> B >> C >> K;

	long long tmp = A - B;
	if(K % 2 == 1){
		tmp *= -1;
	}

	cout << tmp << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, s = LI()
a = LI()

dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 2**0
for i in range(1, n+1):
    x = a[i-1]
    for j in range(s+1):
        if dp[i-1][j]:
            dp[i][j] += dp[i-1][j] * 2
            dp[i][j] %= mod
        if j - x < 0:
            continue
        if dp[i-1][j-x]:
            dp[i][j] += dp[i-1][j-x]
            dp[i][j] %= mod
print(dp[-1][-1])


Measured memory_bytes: 139756
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int f=0;
  string s;
  cin >> s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
N = int(input() )
C = []
for i in range(N):
  A, B = map(int, input().split() )
  C.append([A, B])
C.sort(key=lambda s:s[1] )
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

Measured memory_bytes: 38044
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
double dp[301][301][301];

double ways(int x,int y,int z,int n)
{
    if(x<0 || y<0 || z<0)
    {
        return 0;
    }
    if(x==0 && y==0 && z==0)
    {
        return dp[x][y][z]=0;
    }
    else
    {
        if(dp[x][y][z]>-0.9)
        {
            return dp[x][y][z];
        }
        
        double temp;
        temp=( n+x*ways(x-1,y,z,n)+y*ways(x+1,y-1,z,n)+z*ways(x,y+1,z-1,n) );
        return dp[x][y][z]=(temp/(x+y+z));
        
    }
}


double solve(int x,int y,int z,int n)
{
    memset(dp,-1,sizeof(dp));
    return ways(x,y,z,n);
}

int main()
{
    int n;
    cin>>n;
    int one,two,three;
    one=two=three=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(x==1)
        {
            one++;
        }
        else if(x==2)
        {
            two++;
        }
        else if(x==3)
        {
            three++;
        }
    }
    //cout<<solve(one,two,three,n);
    cout<<fixed<<setprecision(12)<<solve(one,two,three,n);
    return 0;
}

Measured memory_bytes: 216896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(){
	std::string n;
	std::cin >> n;
	for(int i=0; i<3; i++){
		int m = (int)n[i] - '0';
		// std::cout << m;
		std::cout << (10 - m);
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 256
import * as fs from "fs";
namespace b {
  const input = fs.readFileSync("/dev/stdin", "utf8");

  // inputに入力データ全体が入る
  function main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    let tmp0 = input[0].split(" ");
    let tmp1 = input[1].split(" ");
    //文字列から10進数に変換するときはparseIntを使います
    const n = parseInt(tmp0[0], 10);
    const m = parseInt(tmp0[1], 10);

    let sumDay = 0;
    for (let i = 0; i < m; i++) {
      sumDay += parseInt(tmp1[i], 10);
    }

    if (sumDay <= n) {
      console.log("%d", n - sumDay);
      return;
    }

    console.log("-1");
    return;
  }

  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  main(input);
}


Measured memory_bytes: 30432
#include<iostream>
#include<string>
#include<stack>
using namespace std;

int main(){
	string S;
	int n=0;
	stack<int> T[92000];
	bool hantei=true;

	while (true){
		getline(cin,S);
		hantei=true;
		if(S=="."){
			break;
		}
		for(int i=0;i<S.size();i++){
			if(S[i]=='(' || S[i]=='['){
				T[n].push(S[i]);
			}
			if(S[i]==')' || S[i]==']'){
				if(T[n].empty()){
					hantei=false;
				}
				else{
					if((T[n].top()=='(' && S[i]==']')|| (T[n].top()=='[' && S[i]==')')){
						hantei=false;
					}
					T[n].pop();
				}
			}
		}
		if(T[n].empty()==false){
			hantei=false;
		}
		cout<<(hantei?"yes":"no")<<endl;
		n++;
	}
	return 0;
}

Measured memory_bytes: 62984
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long d,n,ans;
    scanf("%lld%lld",&d,&n);
    if(n==100){ans=pow(100,d)*(n+1);}else ans=pow(100,d)*n;
    
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

#define for1(n) for (int i = 0 ; i < n ; i++)
#define for2(n) for (int j = 0 ; j < n ; j++)
#define for1l(n) for (ll i = 0 ; i < n ; i++)
#define for2l(n) for (ll j = 0 ; j < n ; j++)

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1);
}

Measured memory_bytes: 3596
def main():
    from itertools import accumulate
    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10 ** 5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
	int n, a, b, c, d;
	string str;
	cin >> n >> a >> b >> c >> d;
	cin >> str;

	bool two_stone = false;
	bool three_blank = false;

	if(str[c-1]=='#' || str[d-1]=='#'){
		cout << "No" << endl;
		return 0;		
	}

	if(c > d){
		for(int i=b-1;i<=min(d-1, n-1);i++){
			if(str[i-1] == '.' && str[i] == '.' && str[i+1] == '.'){
				three_blank = true;
				break;
			}
		}
		if(!three_blank){
			cout << "No" << endl;
			return 0;
		}
	}

	for(int i=a-1;i<c-2;i++){
		if(str[i] == '#' && str[i+1] == '#'){
			cout << "No" << endl;
			return 0;
		}
	}

	for(int i=b-1;i<d-2;i++){
		if(str[i] == '#' && str[i+1] == '#'){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 888
using System;
class Program
 {
        static void Main(string[] args)
        {
          string[] str = Console.ReadLine().Split(' ');
          int r, D, x;
          int [] seq = new int[10];
          r = int.Parse(str[0]);  
          D = int.Parse(str[1]);
          x = int.Parse(str[2]);
          seq[0] = r * x - D;
          for(int i=0; i < seq.Length-1; ++i)
          {
            seq[i+1] = r * seq[i] - D;
          }
          
          foreach(int s in seq)
          {
            Console.WriteLine(s);
          }   
        }
 }

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<map>
#define ran(x) (x).begin(),(x).end()
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> b;
	for(int i = 0; i < n; ++i) {
		int s;
		cin >> s;
		++b[s];
		a[i] = s;
	}
	int ans = 0;
	for(int i = 0; i < n-2;++i) {
		for(int j = i + 1; j < n - 1;++j) {
			if(a[i]==a[j])
				continue;
			for(int k = j + 1; k < n;++k) {
				if(a[i]==a[k]||a[j]==a[k])
					continue;

				int sum = a[i]+a[j]+a[k];
				int ma = max(a[i], max(a[j], a[k]));
				int mi = min(a[i], min(a[j], a[k]));
				sum -= (ma + mi);
				if(mi + sum > ma){
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

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

	for (int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}

	solve();

	return 0;
}


Measured memory_bytes: 3120
line = raw_input()
odd_one = 0
even_one = 0
for i, val in enumerate(line):
    if val == '1':
        if (i + 1)% 2 == 0:
            even_one += 1
        else:
            odd_one += 1

odd_zero = (len(line)+1) / 2 - odd_one
even_zero = len(line) / 2 - even_one

result = 0
if odd_one + even_zero > even_one + odd_zero:
    result = even_one + odd_zero
else:
    result = odd_one + even_zero

print result



Measured memory_bytes: 32668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

void printArray(vector<int> a) {
  for (auto x : a) {
    cout << x << " ";
  }
  cout << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n);
  for (int i = 0; i < n; i++) {
    num[i] = i;
  }
  Graph G(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  // for (int i = 0; i < n; i++) {
  //   printArray(G[i]);
  // }
  int count = 0;

  do {
    if (num[0] != 0) {
      break;
    }

    for (int i = 0; i < n - 1; i++) {
      int temp = num[i];
      if (find(G[temp].begin(), G[temp].end(), num[i + 1]) != G[temp].end()) {
        // cout << i << endl;
        if (i == n - 2) {
          // printArray(num);
          count++;
        }
      } else {
        break;
      }
    }
  } while (next_permutation(num.begin(), num.end()));

  cout << count << endl;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a==b && a==c && b==c)
		cout << "No";
	
	else if(a!=b && a!=c && b!=c)
		cout << "No";
	
	else 
		cout << "Yes";
	
	return 0;
}

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

using ll = int64_t;
#define int ll

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

#define fi first
#define se second
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

const int MAX_W = 1e5 + 5;
int dp[MAX_W];

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

  int N, W;
  std::cin >> N >> W;
  rep(i, N) {
    int w, v;
    std::cin >> w >> v;
    ddrep(j, W) {
      if (j - w >= 0)
        dp[j] = max(dp[j], dp[j - w] + v);
    }
  }
  print(dp[W]);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)

typedef long long ll;

#define gc getchar()
inline int read(){char c,p=0;int w;
	while(!isdigit(c=gc))if(c=='-')p=1;w=c&15;
	while(isdigit(c=gc))w=w*10+(c&15);return p?-w:w;
}

template<typename T,typename U>inline bool smin(T&x,const U&y){return y<x?x=y,1:0;}
template<typename T,typename U>inline bool smax(T&x,const U&y){return x<y?x=y,1:0;}
const int N=2e5+5;
char s[N];
int n,a[N];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	REP(i,1,n)a[i]=s[i]=='B'?0:1,a[i]+=a[i-1];
	ll ans=0;
	REP(i,1,n)if(s[i]=='B')ans+=a[n]-a[i];
	std::cout<<ans;
	return 0;
}


Measured memory_bytes: 1280
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    s = input()
    ans = 0
    hoge = [ans]
    for i in s:
        if i == "I":
            ans += 1
        else:
            ans -= 1
        hoge.append(ans)
    print(max(hoge))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 10352
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	fmt.Println(choose(a, b, c))
}

func choose(a, b, c int) string {
	for i := 1; i <= 100; i++ {
		if i*a%b == c {
			return "YES"
		}
	}
	return "NO"
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
vector<ll> g[N];
ll n,m,a[N],b[N],c[N],d[N],len[N];
vector<ll> f[N];
bool us[N];
ll col[N];
void dfs(ll x,bool co){
    if(~col[x])return;
    col[x]=co;
    for(auto y:f[x]){
	dfs(y,co^1);
    }
}
int main(){
    cin>>n>>m;
    rep(i,n)cin>>d[i];
    rep(i,m){
	cin>>a[i]>>b[i];
	a[i]--,b[i]--;
	len[i]=max(d[a[i]],d[b[i]]);
	g[a[i]].push_back(i);
	g[b[i]].push_back(i);
    }
    bool ok=1;
    rep(i,n){
	ll mi=1e17,eid=0;
	for(auto e:g[i]){
	    if(mi>len[e]){
		eid=e;
		mi=len[e];
	    }
	}
	us[eid]=1;
	if(d[i]!=mi)ok=0;
    }
    if(ok==0){
	cout<<-1<<endl;
	return 0;
    }
    rep(i,m)if(us[i]){
	f[a[i]].push_back(b[i]);
	f[b[i]].push_back(a[i]);
    }
    rep(i,n)col[i]=-1;
    rep(i,n)dfs(i,0);
    rep(i,n)cout<<(col[i]?"B":"W"); cout<<endl;
    rep(i,m)cout<<len[i]<<endl;
}




Measured memory_bytes: 29696
#include<bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int maxn = 1001;
int dp[maxn][maxn];

int main()
{
    int H,W;
    cin >> H >> W;
    char grid[H+2][W+2];

    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            cin >> grid[i][j];
        }
    }
    //dp[1][1] = 1;
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
                if(i == 1 && j == 1)dp[i][j] = 1;
        else if(grid[i][j] == '.')
            dp[i][j] = (dp[i][j-1] + dp[i-1][j])%Mod;
            else
                dp[i][j] = 0;
        }
    }
    cout << dp[H][W]<<endl;
    return 0;
}


Measured memory_bytes: 5120
import math
from typing import List, Counter, Tuple
from collections import Counter
from itertools import permutations


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


INF = 10**18

def knapsack(A: List[int], B: List[int], C: List[int], N: int, M: int):
    dp = [[-INF]*(M+1) for _ in range(N+1)]
    dp[0][0] = 0
    # dp[i][k] = max(dp[i-1][k], dp[i-1][k-1]+A[i]+B[i]+C[i])
    # dp[0][0] = 0
    for i in range(1, N+1):
        dp[i][0] = 0
        for j in range(1, M+1):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]+A[i-1]+B[i-1]+C[i-1])
    return dp[N][M]


def solve() -> int:
    N, M = read_ints()
    A, B, C = [], [], []
    for _ in range(N):
        a, b, c = read_ints()
        A.append(a)
        B.append(b)
        C.append(c)
    max_score = -INF
    for a_sign in [-1, 1]:
        for b_sign in [-1, 1]:
            for c_sign in [-1, 1]:
                score = knapsack([a*a_sign for a in A],
                                 [b*b_sign for b in B],
                                 [c*c_sign for c in C],
                                 N, M)
                max_score = max(max_score, score)
    return max_score


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 107792
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in b:
        A = [[(a if a != i else 0) for a in l] for l in A]

    return [NO, YES][any([not any(l) for l in [*A, *[[A[i][j] for i in range(3)] for j in range(3)], [A[0][0], A[1][1], A[2][2]], [A[2][0], A[1][1], A[0][2]]]])]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)]
         for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(A, N, b)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75236
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    string s;
    vector<string> v;
    int K;
    cin>>s;
    cin>>K;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=K;j++){
            v.push_back(s.substr(i,j));
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end()); 
    cout<<v[K-1]<<endl;
    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool jjjjaa(int hhjajxxx)
{
    long double yyyyya = sqrt(hhjajxxx);
    return ((yyyyya - floor(yyyyya)) == 0);
}
int main()
{
    int n;
    cin>>n;
    int nn=n%10;
    if(nn==0 || nn ==1 || nn==6 || nn==8) cout<<"pon";
    else if(nn == 2 || nn==4 || nn ==5 || nn==7 || nn==9) cout<<"hon";
    else if(nn==3) cout<<"bon";
    else ;
    
    return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll A,B;
int main() {
    cin>>A>>B;
    p((A-1)*(B-1));
    return 0;
}

Measured memory_bytes: 384
//
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using ll = long long;

ll get_num(vector<int>& number, int begin, int end) {
  ll ret = 0;
  for (int i = end, pos = 0; i >= begin; --i, ++pos) {
    ret += number[i] * pow(10, pos);
  }
  return ret;
}

ll sum(vector<int>& number, int i, size_t size) {
  size_t b = 0;
  size_t e = 0;
  ll sum = 0;
  for (size_t k = 0; k < size; ++k) {
    size_t f = (i >> k) & 1;
    if (f) {
      int a = get_num(number, b, e);
      // cout << a << endl;
      sum += a;
      ++e;
      b = e;
    } else {
      ++e;
    }
  }
  // cout << get_num(number, b, e) << endl;
  return sum + get_num(number, b, e);
}

ll solve(string s, vector<int>& number) {
  int n = int(pow(2, s.length() - 1));
  ll ret{};
  for (int i = 0; i < n; ++i) {
    ret += sum(number, i, s.length() - 1);
    // cout << endl;
  }
  return ret;
}

int main() {
  string s;
  cin >> s;
  vector<int> number;
  for (auto e : s) {
    number.push_back(e - '0');
  }
  cout << solve(s, number) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

const int N = 2000000;
const int mo = 1e9 + 7;

int n;
int fac[N + 5], inv[N + 5];

int fpm(int x, int y) {
    int res = 1;
    for(; y > 0; y >>= 1) {
        if(y & 1)
            res = (ll) res * x % mo;
        x = (ll) x * x % mo;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for(int i = 1; i <= N; ++i) fac[i] = (ll) fac[i-1] * i % mo;
    inv[N] = fpm(fac[N], mo - 2);
    for(int i = N; i >= 1; --i) inv[i-1] = (ll) inv[i] * i % mo;
}

inline int binom(int x, int y) {
    if(x < 0 || y < 0 || x < y) return 0;
    return (ll) fac[x] * inv[y] % mo * inv[x - y] % mo;
}

int main() {
#ifdef Wearry 
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    init();
    scanf("%d", &n);

    int ans = (ll) fac[n-1] * (n-1) % mo;
    for(int k = 1; k < n; ++k) {
        ans = (ans - (ll) binom(n - 3 - k + 1, k) * fac[n - 1 - k] % mo * fac[k]) % mo; 
    }
    ans = (ans + mo) % mo;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> x(M);
	for (int i = 0; i < M; ++i) { cin >> x[i]; }
	sort(x.begin(), x.end());

	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	vector<ll> d;
	for (int i = 1; i < M; ++i) {
		d.push_back(abs(x[i] - x[i - 1]));
	}
	sort(d.begin(), d.end(), greater<ll>());

	ll res = 0;
	for (int i = N - 1; i < d.size(); ++i) {
		res += d[i];
	}
	cout << res << endl;

	return 0;
}


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

using namespace std;
using ll = long long;

using P = pair<ll, ll>;
using Pp = pair<P, ll>;

int main() {
	const ll INF = 1e18;
	int N, Q;
	cin >> N >> Q;
	vector<ll> s(N);
	vector<ll> t(N);
	vector<ll> x(N);
	for (int i = 0; i < N; ++i) {
		cin >> s[i] >> t[i] >> x[i];
	}
	vector<ll> D(Q);
	for (int i = 0; i < Q; ++i) { cin >> D[i]; }

	priority_queue<Pp, vector<Pp>, greater<Pp>> ev;
	for (int i = 0; i < N; ++i) {
		ev.push(Pp(P(s[i] - x[i], 1), x[i]));
		ev.push(Pp(P(t[i] - x[i], -1), x[i]));
	}
	ev.push(Pp(P(INF, 1), INF));

	vector<ll> res(Q);
	set<ll> pos;
	pos.insert(INF);
	for (int i = 0; i < Q; ++i) {
		while (true) {
			Pp p = ev.top();
			P pf = p.first;
			if (pf.first <= D[i]) {
				if (pf.second == 1) { pos.insert(p.second); }
				else { pos.erase(p.second); }
			} else {
				break;
			}
			ev.pop();
			if (ev.empty()) { break; }
		}
		auto it = pos.lower_bound(-INF);
		res[i] = (*it == INF ? -1 : *it);
	}

	for (int i = 0; i < Q; ++i) {
		cout << res[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 29800
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { //Write choose function for each k (0 <= k <= N-1)
		//Figure out why this even works to begin with (why no overcounting occurs)
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long M = input.nextLong();
		long K = input.nextLong();
		long[][] fact = new long[(int) (N+1)][2]; //[Factorial][Inverse]
		fact[1][0]=1;
		fact[1][1]=1;
		long mod = 998244353;
		long baseCase = M;
		baseCase*=FastExp(M-1,N-1,mod);
		baseCase%=mod; //K=0 case
		long ans = baseCase;
		for (long i = 2; i <= N; i++) { //Pre-computing factorial and inverses
			fact[(int) i][0] = fact[(int) (i-1)][0]*i;
			fact[(int) i][0]%=mod;
			long inverse = FastExp(fact[(int) i][0],mod-2,mod);
			fact[(int) i][1] = inverse;
		}
		for (long i = 1; i <= K; i++) {
			if (K==N-1) {
				ans = FastExp(M,N,mod); //Avoiding finding factorial of 0 (dubious case that is hard to code using choose function)
				break;
			}else {
				long curans = M; //M ways of making pairs same color
				long pairs = fact[(int) (N-1)][0];
				pairs*=fact[(int) i][1];
				pairs%=mod;
				pairs*=fact[(int)(N-i-1)][1]; //Choosing K pairs from N-1 adjacent pair slots
				pairs%=mod;
				curans*=pairs;
				curans%=mod; //Each pair has M possibilities
				//K pairs = K+1 slots used, therefore N-(K+1) = N-K-1 slots remain (1<=i<=K)
				long leftover = FastExp(M-1,N-i-1,mod);
				curans*=leftover;
				curans%=mod;
				ans+=curans;
				ans%=mod;
			}
		}
		System.out.println(ans);
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans = 1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			base*=base;
			base%=mod;
			ans%=mod;
			exp/=2;
		}
		return ans;
	}
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    double n, m;
    cin >> n >> m;
    double sum = 0;
    int ans = 0;
    vector<double> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end());
    for (int i = n - 1; i >= (n - m); --i)
    {
        if (a[i] >= sum / (4 * m))
        {
            ans++;
        }
    }
    if (ans == m)
    {
        cout << "Yes"
             << "\n";
    }
    else
    {
        cout << "No" << '\n';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(d >= ((max(a, c) - min(a, c))))
        cout << "Yes" << endl;
    else if((d >= ((max(a, b) - min(a, b)))) &&
            (d >= ((max(b, c) - min(b, c)))))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

string s;
string s2 = "KIHBR";
int main(){
  cin >> s;
  ll k = 0;
  ll cnt = 0;
  rep(i,s.size()){
    if(s[i] == 'A'){
      if(k == 0 || k == 3 || k == 4 || k == 5){
        if(cnt == 0){
          cnt++;
        }
        else{
          cout << "NO" << endl;
          return 0;
        }
      }
      else{
        cout << "NO" << endl;
        return 0;
      }
    }
    else{
      if(s[i] == s2[k]){
        k++;
        cnt = 0;
      }
      else{
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  if(k != 5){
    cout << "NO" << endl;
    return 0;
  }
 
  cout << "YES" << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int s[105];

int main()
{
	int a,b,x,n,m;
	while(~scanf("%d %d %d",&n,&m,&x))
	{
		s[0] = 0;
		a =  0;
		for(int i = 1;i <= m;i++)
		{
			scanf("%d",&s[i]);
			if(s[i] > x&& s[i-1] < x) a = i - 1;
		}
		b = min(m - a,a);
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
dic = {i:[] for i in range(1,N+1)}

for _ in range(N-1):
  u, v, w = map(int, input().split())
  dic[u].append((v,w))
  dic[v].append((u,w))
  
s1 = set([1])
s2 = set([])
h = deque([(1,0)])

while h:
  p = h.popleft()
  for t in dic[p[0]]:
    if t[0] == p[1]:
      continue
    if t[1]%2 == 0:
      if p[0] in s1:
        s1.add(t[0])
      else:
        s2.add(t[0])
    else:
      if p[0] in s1:
        s2.add(t[0])
      else:
        s1.add(t[0])
    h.append((t[0],p[0]))

for i in range(1,N+1):
  if i in s1:
    print(0)
  elif i in s2:
    print(1)

Measured memory_bytes: 110392
#include <cmath>
#include <iostream>
#include <cstdio>
#include <ctype.h>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iomanip>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <sstream>

using namespace std;

int main()
{
	int n;
	long ans;
	
	cin >> n;
	ans = n;
	for (int i=n-1; i>=2; i--)
	{
		ans *= i;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1164
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

s = input().strip()
c = "CODEFESTIVAL2016"
cnt = 0
for i in range(len(c)):
    if s[i] != c[i]: cnt += 1
print(cnt)


Measured memory_bytes: 5848
def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
        
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if (s == T_hint):
                ans_right = ''.join(S_part[:index_init]).replace('?', 'a')
                ans_middle = ''.join(s)
                tmp_ans = ans_right + ans_middle
                
                if (index_init + len(T_hint) < N):
                    ans_left = ''.join(S_part[index_init + len(T_hint):]).replace('?', 'a')
                    tmp_ans += ans_left
                
                ans.append(tmp_ans)
            

            elif ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                    
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')

                    if (index_init + len(T_hint) < N):
                        module = S_part[index_init + len(T_hint):]
                        module = ''.join(module)
                        module = module.replace('?', 'a')
                        
                        tmp_ans += module


                    ans.append(tmp_ans)

    ans.sort()

    if (S_part.count('?') == 0 and T_hint in S_part):
        print(''.join(S_part))
    
    elif (len(ans) > 0):
        print(ans[0])
    
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()


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

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int N, M;
	cin >> N >> M;
	vi co(N);
	rep(i,0,M) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		co[a] ^= 1;
		co[b] ^= 1;
	}
	rep(i,0,N) {
		if (co[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	exit(0);
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int N; cin >> N;
    vector<ll> A(N),B(N),C(N-1);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> B[i];
    for(int i = 0; i < N-1; ++i) cin >> C[i];
    ll ans = B[N-1];
    for(int i = 0; i < N-1; ++i) {
        ans += B[i];
        if(A[i]+1==A[i+1]) ans += C[A[i]-1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256