akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





string T, B;
int NT, NB;
mint dp[1010][1010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> T >> B;
    NT = T.length(), NB = B.length();

    dp[0][0] = 1;
    rep(t, 0, NT) rep(b, 0, NB) {
         if (T[t] == B[b]) dp[t + 1][b + 1] += dp[t][b];
         dp[t + 1][b] += dp[t][b];
    }

    mint ans = 0;
    rep(t, 0, NT + 1) ans += dp[t][NB];
    cout << ans << endl;
}


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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  while(true){
    int n;
    cin >> n;
    if(n == 0) return 0;
    ll ans = INF;
    REP(i, (int)pow(n, 0.335)+1){
      if(n < i*i*i) break;
      int j = (int)pow(n-i*i*i, 0.5);
      if(ans > i+j+(n-i*i*i-j*j)){
        ans = i+j+(n-i*i*i-j*j);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3352
using System;
using System.Collections;
using System.Linq;
class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = new string[n];
        for (int i = 0; i < n; i++)
            s[i] = Console.ReadLine();
        int m = int.Parse(Console.ReadLine());
        string[] t = new string[m];
        for (int i = 0; i < m; i++)
            t[i] = Console.ReadLine();

        Array.Sort(s);
        int[] num = new int[n];
        for (int i = 0; i < n; i++)
        {
            if (i > 0)
            {
                if (s[i] == s[i - 1])
                {
                    num[i] = 0;
                    continue;
                }
            }
            int n1 = s.Count(p => p == s[i]);
            int n2 = t.Count(p => p == s[i]);
            num[i] = Math.Max(0, n1 - n2);
        }
        Console.WriteLine(num.Max());
    }
}

Measured memory_bytes: 13536
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef set <int> se;
#define endl "\n"
#define for(i,a,b) for(int i = a;i<b;i++)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


void solve(){

string n;
cin>>n;

int sum = 0;

for(i,0,n.size()) sum = sum + (int)(n[i]-'0');


if(sum%9==0) cout<<"Yes";
else
{
    cout<<"No";
}

}
 
 
int main()
{

solve();
 
return 0;
}

Measured memory_bytes: 3716
def f():
    s = list(input())
    for i in range(len(s)):
        s.pop(-1)
        s.pop(-1)
        c = 0
        for j in range(len(s)//2):
            if s[j] == s[len(s)//2 + j]:
                c += 1
                if c == len(s)//2:
                    return len(s)
            else:
                break
print(f())

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

long long n, a[200010];
long long rui[200010];
map<long long, long long> memo;

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


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

  long long ans = 0;
  for(int i = 0;i <= n;i++){
    memo[rui[i]]++;
    if(memo[rui[i]] > 1){
      ans += memo[rui[i]]-1;
    }
  }

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


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n);
    REP(i,n) cin >> v[i];
    sort(ALL(v));
    vector<ll> v1, v2;
    ll ans1 = 0,ans2 = 0;
    if (n == 2) ans1 = v[1] - v[0];
    else {
        int r = v.size() -1, l = 0;
        ans1 = v[r] - v[l];
        v1.push_back(v[r]);
        r--;
        ans1 += v[r] - v[l];
        v1.push_back(v[r]);
        r--;
        l++;
        int cnt = 0;
        while(l <= r) {
            int t = cnt % 4;
            if (t < 2) {
                ans1 += abs(v1[v1.size() -2] - v[l]);
                v1.push_back(v[l]);
                l++;
            } else {
                ans1 += abs(v1[v1.size() -2] - v[r]);
                v1.push_back(v[r]);
                r--;
            }
            cnt++;
        }

        r = v.size() -1, l = 0;
        ans2 = v[r] - v[l];
        v2.push_back(v[l]);
        l++;
        ans2 += v[r] - v[l];
        v2.push_back(v[l]);
        l++;
        r--;
        cnt = 0;
        while(l <= r) {
            int t = cnt % 4;
            if (t < 2) {
                ans2 += abs(v2[v2.size() -2] - v[r]);
                v2.push_back(v[r]);
                r--;
            } else {
                ans2 += abs(v2[v2.size() -2] - v[l]);
                v2.push_back(v[l]);
                l++;
            }
            cnt++;
        }

    }
    cout << max(ans1,ans2) << '\n';

    return 0;
}

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

int main(void){
    int n;
    int a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    int ans=1000000;
    for (int i = 1; i <= n; ++i) {
        int dab,dcd;
        int ax=a%i==0?i:a%i;
        int bx=b%i==0?i:b%i;
        int cx=c%i==0?i:c%i;
        int dx=d%i==0?i:d%i;

        int ay=a%i==0?a/i-1:a/i;
        int by=b%i==0?b/i-1:b/i;
        int cy=c%i==0?c/i-1:c/i;
        int dy=d%i==0?d/i-1:d/i;
        dab=abs(ax-bx)+abs(ay-by);
        dcd=abs(cx-dx)+abs(cy-dy);
        ans=min(ans,dab+dcd);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3096
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())
#define TEST(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }

struct hackenbush {
  int n;
  vector<vector<int>> adj;

  hackenbush(int n) : n(n), adj(n) { }
  void add_edge(int u, int v) {
    adj[u].push_back(v);
    if (u != v) adj[v].push_back(u);
  }

  // r is the only root connecting to the ground
  int grundy(int r) {
    vector<int> num(n), low(n);
    int t = 0;
    function<int(int,int)> dfs = [&](int p, int u) { 
      num[u] = low[u] = ++t;
      int ans = 0;
      for (int v: adj[u]) {
        if (v == p) { p += 2*n; continue; } 
        if (num[v] == 0) {
          int res = dfs(u, v);
          low[u] = min(low[u], low[v]);
          if (low[v] > num[u]) ans ^= (1 + res) ^ 1; // bridge
          else                 ans ^= res;           // non bridge
        } else low[u] = min(low[u], num[v]);
      }
      if (p > n) p -= 2*n;
      for (int v: adj[u]) 
        if (v != p && num[u] <= num[v]) ans ^= 1;
      return ans;
    };
    return dfs(-1, r);
  }
};

int main(){
    iostream_init();

    int n;
    cin >> n;
    int ans = 0;
    hackenbush g(n);
    for (int i = 0; i < n-1; ++i) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      g.add_edge(u, v);
    }
    cout << (g.grundy(0) ? "Alice" : "Bob") << endl;

    return 0;
}




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

int main(){
	int N,M,X,Y;
	std::vector<int> x, y;

	std::cin >> N >> M >>X >> Y;
	for( int _,i= 0; i<N; ++i ){
		std::cin >> _; x.push_back( _ );
	}
	for( int _,i=0; i<M; ++i ){
		std::cin >>_; y.push_back( _ );
	}
	x.push_back( X );
	y.push_back( Y );

	if( *std::max_element( x.begin(), x.end() ) >= *std::min_element( y.begin(), y.end() ) ){
		std::cout << "War" << std::endl;
		return 0;
	}
	std::cout << "No War" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INFTY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int prim();


int n,M[MAX][MAX];

int main(){
  int a,e,i,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  printf("%d\n",prim());

  return 0;
}

int prim(){
  int i,u,v,minv;
  int sum=0;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
      for(v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum += M[i][p[i]];
  }
  return sum;
}


Measured memory_bytes: 2104
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::{HashSet,HashMap};
#[allow(unused_imports)]
use std::cmp::{min,max};

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

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

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin 
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input!(s:String);
    let mut t = String::new();
    let s = s.chars();
    let mut i = 0;
    for c in s {
        i += 1;
        if i % 2 == 1 {
            t.push(c);
        }
    }
    println!("{}", t);
}


Measured memory_bytes: 4352
n = int(input())
b = [int(i) for i in input().split()]

a = [b[0]]
for i in range(n-1):
    if i < n-2:
        a.append(min(b[i], b[i+1]))
    else:
        a.append(b[len(a)-1])
print(sum(a))


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			String data = sc.next();
			char[] card = data.toCharArray();

			if(data.equals("-")) break;

			char[] temp = new char[data.length()];

			int n = sc.nextInt();
		
			for(int i = 0;i < n;i++){
				int num = sc.nextInt();

				for(int m = 0;m < num;m++){
					temp[data.length() - num + m] = card[m];
				}
				
				for(int m = num;m < data.length();m++){
					temp[m - num] = card[m];
				}

				for(int m = 0;m < data.length();m++){
					card[m] = temp[m];
				}			
			}
			System.out.println(card);
		}

	}
}


Measured memory_bytes: 26232
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=100005;
long long int a[MAX*3];
int main()
{
	long long int ans=0;
	int n;
	cin>>n;
	for(int i=1;i<=3*n;++i){
		cin>>a[i];
	}
	sort(a+1,a+3*n+1);
	for(int i=1;i<=n;++i) ans+=a[3*n-i*2+1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
def transpose(A):
    B = []
    for j in range(len(A[0])):
        C = [A[i][j] for i in range(len(A))]
        B.append(C)
    return B

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

for i in reversed(range(H)):
    if A[i] == ['.']*W:
        A.pop(i)
        
H = len(A)        
A = transpose(A)
for j in reversed(range(W)):
    if A[j] == ['.']*H:
        A.pop(j)

A = transpose(A)
for i in range(len(A)):
 	print(*A[i], sep='')

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

using namespace std;
using ll = long long;


int main()
{
	int n; cin >> n;
	vector<ll> a(n);
	map<ll,ll> mp;
	for(int i = 0; i < n; i++)cin >> a[i];
	mp[0]++, mp[a[0]]++;
	for(int i = 1; i < n; i++) {
		a[i] += a[i - 1];
		mp[a[i]]++;
	}

	ll ans = 0;
	for(auto i : mp) {
		ans += (i.second - 1) * i.second / 2;
	}
	cout << ans << endl;	
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n;
  cin>>n;
  ll ans=0;
  rep(i,n){
    int a;
    cin>>a;
    ans=ans^a;
  }
  if(ans==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
const ll mod = 1e9 + 7 ;
ll h , w ;
char grid[1005][1005];
ll dp[1005][1005];
int main()
{
    ios;
    cin >> h >> w;
    forn(i , 1 , h){
       forn(j , 1 , w){
          cin >> grid[i][j] ;
       }
    }
    if(grid[1][1] == '#' or grid[h][w] == '#'){
        cout << 0 << el ;
        ro;
    }
    forn(i , 1 , h){
      forn(j , 1 , w){
         if(i == j  and i == 1){
            dp[1][1] = 1;
         }
         else {
            if(grid[i][j] == '#'){
                dp[i][j] = 0 ;
            }
            else if(grid[i][j]!='#'){
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j]%=mod;
            }
         }
      }
    }
    cout << dp[h][w] % mod << el ;
    ro ;
}



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

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> dp(n);
    dp[1] = abs(h[0] - h[1]);
    for (int i=2; i<n; ++i) {
        dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), dp[i-2] + abs(h[i-2]-h[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxN = 19;
const int MaxM = 20;
const int M = 1000000007;

int n, m, nK;
int rest[MaxM + 1][MaxN];

int f[1 << MaxN];

int main()
{
	cin >> n >> m >> nK, --n;

	for (int i = 1; i <= m; ++i)
		for (int j = 0; j < n; ++j)
			rest[i][j] = -1;

	for (int i = 0; i < nK; ++i)
	{
		int u, v, w;
		cin >> u >> v >> w, --v;

		rest[u][v] = w;
	}

	f[0] = 1;
	for (int i = 1; i <= m; ++i)
		for (int j = 0; j < n; ++j)
			for (int s = 0; s < 1 << n; ++s)
			{
				if (f[s] == 0)
					continue;

				int cur = f[s];

				if (rest[i][j] == 1 || s >> j & 1)
					f[s] = 0;

				if (rest[i][j])
				{
					int p = s >> j;
					int t = s ^ (((p & -p) ^ 1) << j);
					f[t] = (f[t] + cur) % M;
				}
			}

	int res = 0;
	for (int s = 0; s < 1 << n; ++s)
		res = (res + f[s]) % M;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>

int binarySearch(int,int);
    
int S[100000];

int main()
{
    int n, q, i, count = 0, flag;
    int T[100000];

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    for (i = 0; i < q; i++)
    {
        scanf("%d", &T[i]);
        flag = binarySearch(n, T[i]);
        if (flag == 0)
            count++;
    }
    printf("%d\n", count);
    return 0;
}

int binarySearch(int n,int key)
{
    int l=0,mid,r=n;
    while(l<r)
    {
        mid = (l+r)/2;
        if(S[mid]==key)return 0;
        else if(key<S[mid]) r = mid;
        else l = mid+1;
    }
    return 1;
}



Measured memory_bytes: 2296
s = input()

ans = 0
l = 0
r = 0
p = 0
for i in range(len(s)):
    if s[i] == ">":
        l += 1
    else:
        r += 1

    if i == len(s) - 1:
        break
        
    if s[i] == ">" and s[i+1] == "<":
        x = max(l, r)
        y = min(l, r)
        ans += x * (x+1) / 2
        if y == 0:
            ans += 0
        else:
            ans += y * (y-1) / 2
        l = 0
        r = 0
        p = i+1

if p != len(s) + 1:
    x = max(l, r)
    y = min(l, r)
    ans += x * (x+1) / 2
    if y == 0:
        ans += 0
    else:
        ans += y * (y-1) / 2


print(int(ans))

    




        


    







        



Measured memory_bytes: 4212
import math

N,D =[int(x) for x in input().split()]

X = []
Y = []

for i in range(N):
    x,y = [int(x) for x in input().split()]
    X.append(x)
    Y.append(y)

ans = 0

for i in range(N):
    r = math.sqrt(X[i] ** 2 + Y[i] ** 2)
    if r <= D:
        ans += 1

print(ans)

Measured memory_bytes: 24580
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n;
	while(cin>>n and n>0){
		int w,h; cin>>w>>h;
		int tree[w][h]={};
		rep(i,n){
			int a,b; cin>>a>>b;
			tree[a-1][b-1]++;
		}
		int s,t; cin>>s>>t;

		int ans=0;
		rep(i,w-s+1){
			rep(j,h-t+1){
				int cnt=0;
				rep(dx,s){
					rep(dy,t){
						if(tree[i+dx][j+dy]) cnt++;
					}
				}
				if(ans<cnt) ans=cnt;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    char O[55],E[55];
	char x[150];
	int i,k,m,l1,l2;
	while (scanf("%s",O)!=EOF&&scanf("%s",E)!=EOF)
	{
   k=0;m=0;
	 l1=strlen(O);
	l2=strlen(E);
	for (i=0;i<l1+l2;i++)
	{	
		x[i]=O[k];
	  i++,k++;
	  x[i]=E[m];
    	m++;
	}	
	for (i=0;i<l1+l2;i++)
		cout << x[i] ;
	cout << endl;
	}
	return 0;
}

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

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;

    int length = S.size();
    bool hitachi = true;

    if (S.at(length - 1) != 'i')
    {
        cout << "No" << endl;
        return (0);
    }

    for (int i = 0; i < length; i++)
    {
        if (i % 2 == 0)
        {
            if (S.at(i) != 'h')
            {
                hitachi = false;
            }
        }
        if (i % 2 == 1)
        {
            if (S.at(i) != 'i')
            {
                hitachi = false;
            }
        }
    }

    if (hitachi == false)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int m[]={5,1,2,4,1,3,1,0,0,2,3,2,2,4,5,1,4,0,4,3,3,5,0,5},a,b,c,d,r;char s[99];int main(){for(s[87]=1,s[78]=4,s[69]=3,s[83]=2;~scanf("%s",s);*s<60?printf(r?"%d\n":0,r),a=c=0,b=r=1:(d=s[*s],d?d=d+c&3,a=m[4*a+d],b=m[4*b+d]:c+=*s-76?1:3,r+=a%3?b%3?(b+6-a)%6<3?2:5:3+!b:a?6:1));}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	int b, c;
	for (int i = 0; i < 9; i++) {
		cin >> a >> b >> c;
		int sum = (200 * b + 300 * c), man = b + c;
		cout << a << " " << man <<" "<< sum << endl;
	}
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
   
 
   cin >> n;
  
  
   if (n < 1000){
     
      cout << "ABC" << endl;
   }else{
     
      cout << "ABD" << endl;
   }
  
  
  
  return 0;
}

Measured memory_bytes: 256
/**
 *  author:   TakeruOkuyama
 *  created:  
**/
#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>;

const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> L(2*N);
    rep(i, 2*N){
        cin >> L[i];
    }
    sort(L.begin(), L.end());
    int ans = 0;
    rep(i, 2*N){
        //cout << L[i];
        if(i % 2 == 0){
            ans += L[i];
        }
    }
    cout << ans << endl;
return 0;}

/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (W >= x + r && 0 <= x - r) {
		if (H >= y + r && 0 <= y - r) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	set<int> s;
	int a, b, c;
	cin >> a >> b >> c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	if (s.size() == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

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

    string s;
    cin >> s;
    string res;
    if (s == "Sunny") res = "Cloudy";
    else if (s == "Cloudy") res = "Rainy";
    else res = "Sunny";
    cout << res << endl;
}

Measured memory_bytes: 3596
#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;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 2*10E3+7;
const ll INF = 10E17;

int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    set<string> S;
    cin>>n;
    forn(i,n){
        string s;
        cin>>s;
        S.insert(s);
    }
    cout<<S.size()<<endl;
    return 0;
}


Measured memory_bytes: 19184
import java.util.*;

class Main{

    int n,m;
    int[][] cost;
    int[] p;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            cost = new int[m][3];
            for(int i=0; i<m; i++)for(int j=0; j<3; j++) cost[i][j] = sc.nextInt();

            init();

            Arrays.sort(cost, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[2] - b[2];
                    }
                });

            int ans = 0;
            for(int i=0; i<m; i++){
                int a = cost[i][0], b = cost[i][1];
                a = root(a); b = root(b);
                if(a==b) continue;
                merge(a,b);
                ans += cost[i][2];
            }

            System.out.println(ans);
        }
    }

    void init(){
        p = new int[n];
        for(int i=0; i<n; i++) p[i] = i;
    }

    int root(int a){
        if(a==p[a]) return a;
        else return p[a] = root(p[a]);
    }

    void merge(int a, int b){
        a = root(a); b = root(b);
        p[a] = b;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 23260
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(int argc, char *argv[]) {
	int sr;
	int a, b;
	int i, j;
	int apb, amb, ab;

	sr=scanf("%d %d", &a, &b);
	apb = a+b;
	amb = a-b;
	ab = a*b;

	if (apb>amb) {
		if (apb>ab) {
			printf("%d",apb);
		} else {
			printf("%d",ab);
		}
	} else {
		if (amb>ab) {
			printf("%d",amb);
		} else {
			printf("%d",ab);
		}
	}
	printf("\n");
	fflush(stdout);

	return 0;

}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

void unique_count(vector<int> &a, vector<vector<int>> &b) {
	// erase(b.begin(), b.end());
	for (int i=0; i<a.size(); i++)
		if ((i>0)&&(a.at(i)==a.at(i-1)))
			b.back().at(1)++;
		else
			b.push_back({a.at(i), 1});
	return;
}

int	main() {
	int N;
	cin >>N;
	vector<int> a(N, 0);
	for (int i=0; i<N; i++)
		cin >>a.at(i);
	sort(a.begin(), a.end());
	vector<vector<int>> b;
	unique_count(a, b);
	if (2<b.size()) {
		cout <<"No" <<endl;
		return 0;
	} else if (1==b.size()) {
		int C=b.at(0).at(0);
		if (C==N-1) {
			cout <<"Yes" <<endl;
			return 0;
		} else if ((C>=1)&&(N/2>=C)) {
			cout <<"Yes" <<endl;
		} else {
			cout <<"No" <<endl;
			return 0;
		}
	} else {
		int b01=b.at(0).at(1);
		int b11=b.at(1).at(1);
		int b00=b.at(0).at(0);
		int b10=b.at(1).at(0);
		if (1!=b10-b00) {
			cout <<"No" <<endl;
			return 0;
		}
		if ((b11/2>=b10-b01)&&(b10>=b01+1)) {
			cout <<"Yes" <<endl;
			return 0;
		}
		cout <<"No" <<endl;
		return 0;
	}
	return 0;
}



Measured memory_bytes: 6064
n,m,*a=map(int,open(0).read().split())
c=[bin(i)[::-1].index("1") for i in a]
if sum(c)!=c[0]*n:
    print(0)
    exit()
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
a=list(set(a))
b=a[0]
for i in a:
    b=lcm(i,b)
    if b>2*m:
        print(0)
        exit()
print((m-b//2)//b+1)  

Measured memory_bytes: 14092
from itertools import accumulate
import math
import fractions

N = int(input())
A = [int(i) for i in input().split()]

#最大公約数で累積和作る
B = [0] * (N+1)
R = [0] * (N+1)
for i in range(N):
    B[i+1] = (fractions.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (fractions.gcd(R[N-i], A[N-1 -i]))
 
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(B[i], R[i+1]))
print(ans)

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

using namespace std;
using T = long long;

//RMQに答えるSegmentTree
//必要に応じて書き換える．
struct SegmentTree {
private:
    int n;
    vector<T> node;
public:
    SegmentTree(vector<T> vect){
        int sz = vect.size();
        n = 1; for(;n<sz;) n*= 2;
        node.resize(2*n-1,0);

        for(int i=0; i<sz ; i++) node[i+n-1] = vect[i];
        for(int i=n-2; i>=0 ; i--) node[i] = max(node[2*i+1], node[2*i+2]);//ここをうまく書き換える
    }

    void update(int x, T val){
        x += (n-1);

        node[x] = val;
        while(x > 0){
            x = (x-1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }
    T getmax(int a, int b, int k=0, int l=0, int r= -1) {
        if(r<0) r=n;
        if(r <= a || b <= l) return 0;
        if(a<=l && r<=b ) return node[k];

        T vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        T vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl,vr);
    }
};


int main() {
    int n;
    long long sum = 0;
    cin >> n;
    vector<T> vect(n);
    for(int i= 0; i< n; i++){
        cin >> vect[i];
        sum += vect[i];
    }
    SegmentTree dp((vector<T>(n)));
    T now;
    for(int i=0; i<n ;i++){
        now = vect[i];
        dp.update(now-1, dp.getmax(0,now)+now);
    }
    long long ans=dp.getmax(0,n);
    cout << sum - ans << endl;
    return 0;
}



Measured memory_bytes: 6516
=begin
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
=end
n = gets.chomp.to_i 
a = [0]
for i in (0...n)
    x = gets.chomp.to_i
    a << x
end
d = [[0,-1e9.to_i]]
(n+1).times do 
    d << [-1e9.to_i,-1e9.to_i]
end
for i in (0...n)
    for x in (0..1)
        for y in (0..1)
            z = a[i + 1] - x - y
            d[i + 1][y] = [d[i + 1][y], d[i][x] + x + z / 2].max if z >= 0
        end
    end
end
puts [d[n][0], d[n][1]].max

Measured memory_bytes: 10748
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <set>
#include <map>
using namespace std;
#define LL long long

int n,k;
LL dp[55][55][105];
bool mark[55][55][105];
LL a[55];

LL rek( int l, int r, int k ){
	if ( l > r ) return 0;
	if ( k == 0 ) return 0;
	LL &ans = dp[l][r][k];
	if ( mark[l][r][k] ) return ans;
	ans = -1e18;
	mark[l][r][k] = true;
	ans = max( ans, rek(l+1,r,k-1) + a[l]);
	ans = max( ans, rek(l,r-1,k-1) + a[r]);
	if ( k >= 2 ) {
		ans = max( ans, rek(l+1,r,k-2) );
		ans = max( ans, rek(l,r-1,k-2) );
	}
	return ans;
} 

int main(){

	memset(dp,-1,sizeof(dp));

	scanf("%d%d",&n,&k);
	for ( int i = 0; i < n; i++ ) scanf("%lld",&a[i]);

	LL ans = 0;
	for ( int i = 1; i <= k; i++ ){
		ans = max( ans, rek(0,n-1,i) );
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main
{

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

		int n = Integer.parseInt(sc.next());
		String s = sc.next();
		int k = Integer.parseInt(sc.next());

		StringBuilder sb = new StringBuilder(s);

		char c = s.charAt(k - 1);

		for (int i = 0; i < n; i++) {
			if (s.charAt(i) != c) {
				sb.setCharAt(i, '*');
			}
		}

		System.out.println(sb.toString());

		sc.close();
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int b,r,n,c=0;
  cin>>n>>b>>r;
  c+=(n/(b+r))*b;
  c+= (b < n%(b+r)) ? b : (n%(b+r));
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
/*
int main(){
    int N;
    cin >> N;
    int L[N];
    for(int i=0;i<N;i++) cin >> L[i];
    int count=0;
    sort(L, L+N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N/2;j++){
            if(i==j) continue;
            for(int k=N-1;k>N/2;k--){
                if(j>k) break;
                if(k==i) continue;
                
                if(L[i]<L[j]+L[k] && L[j]<L[k]+L[i] && L[k]<L[i]+L[j]){
                    count++;
                }
            }
            
        }
    }
    cout << count << endl;
    return 0;
}*/

int main(){
    int N;
    cin >> N;
    int L[N];
    for(int i=0;i<N;i++)cin >> L[i];
    sort(L,L+N);
    int count=0;
    for(int i=N-3; i>=0; i--){//3rd length
        for(int j=N-2;j>i;j--){//2nd length
            for(int k=N-1;k>j;k--){//1st length
                if(L[k]<L[i]+L[j]) count ++;
            }
        }
    }
    cout << count <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    
    string s = to_string(N);
    int mod = 0;
    for(int i = 0; i < s.size(); ++i) mod += s[i] - '0';
    printf("%s\n", (N % mod) ? "No" : "Yes");
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int n, h, ans;
P p[100005];
vector<int>vec;
signed main() {
	cin >> n >> h;
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n);
	reverse(p, p + n);
	rep(i, n) {
		if (p[i].second >= p[0].first) {
			vec.push_back(p[i].second);
		}
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	rep(i, vec.size()) {
		h -= vec[i];
		ans++;
		if (h <= 0) {
			cout << ans << endl;
			endre;
		}
	}
	if (h%p[0].first) {
		cout << ans + h / p[0].first + 1 << endl;
	}
	else {
		cout << ans + h / p[0].first << endl;
	}
	endre;
}

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

int main() {
	int n; cin >> n;
	vector<int>x(n),l(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> l[i];
	}
	vector<pair<int, int>>sg(n);
	for (int i = 0; i < n; i++) {
		sg[i] = { x[i] + l[i],x[i] - l[i] };
	}
	sort(sg.begin(), sg.end());

	int ans = 0, now = -1e9;
	for (int i = 0; i < n; i++) {
		if (now <= sg[i].second) {
			ans++; now = sg[i].first;			
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024 * 256;

int n, ile[3];
VI A[2];
VI V[M];
int R[M];

void DFS(int v, int pr, int val)
{
	A[val].PB(v);
	for (auto x : V[v])
	{
		if (x != pr)
		{
			DFS(x, v, 1 - val);
		}
	}
}

void add(int i, int ind)
{
	//R[i] = A[ind].back();
	R[A[ind].back()] = i;
	A[ind].pb();
}

int32_t main()
{
	scanf("%d", &n);
	FOR(i, 2, n)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		V[a].PB(b);
		V[b].PB(a);
	}
	DFS(1, 0, 0);
	FOR(i, 1, n)
	{
		ile[i % 3]++;
	}
	if (SIZ(A[0]) < SIZ(A[1]))
	{
		swap(A[0], A[1]);
	}
	debug(ile[1], ile[2], ile[0], A[0], A[1]);
	if (ile[1] + ile[2] <= SIZ(A[0]))
	{
		FOR(i, 1, n)
		{
			if (i % 3 == 0)
			{
				if (!A[1].empty())
				{
					add(i, 1);
				}
				else
				{
					add(i, 0);
				}
			}
			else
			{
				add(i, 0);
			}
		}
	}
	else
	{
		assert(SIZ(A[0]) >= ile[1]);
		assert(SIZ(A[1]) >= ile[2]);
		FOR(i, 1, n)
		{
			if (i % 3 == 1)
			{
				add(i, 0);
			}
			else if (i % 3 == 2)
			{
				add(i, 1);
			}
		}
		FOR(i, 1, n)
		{
			if (i % 3 == 0)
			{
				if (A[1].empty())
				{
					add(i, 0);
				}
				else
				{
					add(i, 1);
				}
			}
		}
	}
	
	FOR(i, 1, n)
	{
		printf("%d ", R[i]);
	}
	printf("\n");
}














Measured memory_bytes: 23028
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int a,b,h,m;
  double lhand,shand,x,y,ans;

  scanf("%d %d %d %d",&a,&b,&h,&m);

  lhand = m*M_PI/30;
  shand = (60*h+m)*M_PI/360;

  x = a*sin(lhand)-b*sin(shand);
  y = a*cos(lhand)-b*cos(shand);

  ans = sqrt(x*x+y*y);

  printf("%.20lf\n",ans);

  return 0;
}

Measured memory_bytes: 2504
A,B,C = map(int,input().split())

s = [A,B,C]
s.sort()

count = 0
a = s[2] - s[1]
count = count + a

s[0] = s[0] + a
#print(s[0],count)
b = s[2] - s[0]

if b % 2 == 0:
    count = count + (b // 2)
    print(count)

else:
    count = count + (b // 2) + 2
    print(count)

Measured memory_bytes: 3064
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#li=input().split()
#import fractions
#n=int(input())

lis=list(map(int,input().split()))
S=input()

if S[lis[1]-1]=="A":
    ans=S[:lis[1]-1]+"a"+S[lis[1]:]
elif S[lis[1]-1]=="B":
    ans=S[:lis[1]-1]+"b"+S[lis[1]:]
elif S[lis[1]-1]=="C":
    ans=S[:lis[1]-1]+"c"+S[lis[1]:]

print(ans)


Measured memory_bytes: 3060
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    is_first = True
    ls = [[0] * 13 for _ in range(len(s))]
    mod = 10 ** 9 + 7
    for i in range(len(s)):
        if is_first:
            is_first = False
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                t = int(s[-i-1])
                ls[i][t] += 1
        else:
            mlt = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        r = (j + mlt * k) % 13
                        ls[i][r] += ls[i-1][j]
                        ls[i][r] %= mod
            else:
                t = int(s[-i-1])
                for j in range(13):
                    r = (j + mlt * t) % 13
                    ls[i][r] += ls[i-1][j]
                    ls[i][r] %= mod
    print(ls[-1][5])


if __name__ == '__main__':
    slove()


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


const int mod=1e9+7;

vector<int> A,B;

int main(){
	int n,a;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a;
		A.push_back(a);
		B.push_back( abs( i-((n-1)-i) ) );
	}
	
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	
	if(A!=B){
		cout << 0 << endl;
		return 0;
	}
	
	long long sum=1;
	for(int i=0;i<n/2;i++){
		sum=(sum*2)%mod;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1276
#include <cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 100000; i++) {
		if ((i * 8) / 100 == a && (i * 10) / 100 == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


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

  cout << (N*(N-1))/2+(M * (M-1))/2 << endl;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}

// 連想配列の中身を全部出力
// void printM(vector<int> &v) {
//   cout << "  [ ";
//   for(int i = 0; i < (int)v.size(); i++) {
//     cout << v.at(i) << " ";
//   }
//   cout << "]" << endl;
// }
//
// void printMM(vector<vector<int>> &vv) {
//   cout << "{" << endl;
//   for(int i = 0; i < (int)vv.size(); i++) {
//     cout << "  [ ";
//     for(int j = 0; j < (int)vv.at(i).size(); j++) {
//       cout << vv.at(i).at(j) << " ";
//     }
//     cout << "]," << endl;
//   }
//   cout << "}" << endl;
// }


Measured memory_bytes: 256
N, X = gets.split.map(&:to_i)

L = gets.split(" ")
cnt = 0
len = 0
L.each do |data|
    if len <= X then
        cnt += 1
    else
        break
    end
    len += data.to_i
end
if len <= X then
    cnt += 1
end
puts cnt

Measured memory_bytes: 1788
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(returnWheather(s))
}

func returnWheather(s string) string {
	const (
		sun   = "Sunny"
		rain  = "Rainy"
		cloud = "Cloudy"
	)

	if s == sun {
		return cloud
	}
	if s == cloud {
		return rain
	}
	return sun
}


Measured memory_bytes: 512
import Data.Char (chr, ord)

toggleChar :: Char -> Char
toggleChar ch
  | 65 <= chi && chi <= 90  = chr $ chi + 32
  | 97 <= chi && chi <= 122 = chr $ chi - 32
  | otherwise               = ch
  where
    chi = ord ch

main :: IO ()
main = getLine >>= putStrLn.(map toggleChar)



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

const double pi = acos(-1);
int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	double a,b,x; cin >> a >> b >> x;
	double r1 = (x * 2 / a - b * a) / a;
	if(r1 > 0){
		double ans = atan((b - r1) / a)  * 180 / pi;
		printf("%.6f",ans);
		return 0;
	} 	
	r1 = 2 * x / b / a;
	double ans = atan(b / r1) * 180 / pi;
	printf("%.6f",ans);
	return 0;
}

Measured memory_bytes: 512
S = input()
s1 = "hi"
s2 = "hihi"
s3 = "hihihi"
s4 = "hihihihi"
s5 = "hihihihihi"
result = "No"

if S == s1:
    result = "Yes"
elif S == s2:
    result = "Yes"
elif S == s3:
    result = "Yes"
elif S == s4:
    result = "Yes"
elif S == s5:
    result = "Yes"
print(result)

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int n[100],x[100];
	int i,j,k;
	int a = 0;
	int ans;
	int cnt[100] = {0};
	
	do 	{
		scanf("%d %d",&n[a],&x[a]);
		
		for (i=1;i<=n[a];i++) {
			for (j=1;j<=n[a];j++) {
				for (k=1;k<=n[a];k++) {
					ans = i + j + k;
				
					if (ans == x[a] && i < j && j < k) {
						cnt[a] = cnt[a] + 1;
					}
				}
			}
		}
		
		a = a + 1;
	} while (n[a-1] != 0 || x[a-1] != 0);

	
	for (i=0;i<a-1;i++) {
		printf("%d\n",cnt[i]);
	}
	
return 0;
}


Measured memory_bytes: 2136