akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<bool> A(1000000001, false);
    ll count = 0;
    for(size_t i=0;i<N; i++)
    {
        ll a;
        cin >> a;
        A[a] = !A[a];
        if(A[a]) count++;
        else count--;
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 125420
n = gets.chop.to_i
b = gets.chop.split.map(&:to_i)

a = []

a << b[0]

for i in 1..n-2 do
  a << [b[i-1], b[i]].min
end

a << b[n-2]




ans = 0
for elm in a do
  ans += elm
end

p ans

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}


const int inf = 1e9 + 7;
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string str;
    cin >> str;
    int cnt = 0;
    string rev = str;
    reverse(rev.begin() , rev.end());
    int n = str.length();
    str = str.substr(0 , n/2);
    rev = rev.substr(0 , n/2);
    for(int i = 0; i < rev.length(); i++){
        cnt += (rev[i] != str[i]);
    }
    cout << cnt << '\n';
}

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

using namespace std;

void solve() {
    long long N, K;
    cin >> N >> K;
    vector<pair<int, int>> p(N);
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p.begin(), p.end());

    for (int i = 0; i < N; i++)
    {
        if (K <= p[i].second)
        {
            cout << p[i].first << endl;
            return;
        }
        K -= p[i].second;
    }
}

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

Measured memory_bytes: 4016
from collections import deque


class Node:
    def __init__(self, id, w):
        self.id = id
        self.w = w


N = int(input())
uvw = [list(map(int, input().split())) for _ in range(N - 1)]
pairs = [[] for _ in range(N + 1)]
for u, v, w in uvw:
    pairs[u].append([v, w])
    pairs[v].append([u, w])

nodes = {1: Node(1, 0)}
q = deque([nodes[1]])
while len(q) > 0:
    node = q.pop()
    for v, w in pairs[node.id]:
        if v not in nodes:
            nodes[v] = Node(v, node.w + w)
            q.append(nodes[v])

for i in range(1, N + 1):
    print(nodes[i].w % 2)


Measured memory_bytes: 85564
IN = list(map(int, input().split()))
N, K = IN[0], IN[1]
P = [None] + list(map(int, input().split()))
C = [None] + list(map(int, input().split()))
MAX_N = 45000
#N = 1000
#K = 10**7
#P = [None] + [random.choice(list(itertools.chain(range(1,i), range(i+1,N)))) for i in range(1, N+1)]
#C = [None] + random.choices(range(-10**9, 10**9), k=N)

verbose = False

def cumsum(a):
    tmp = [0]*(len(a)+1)
    for i in range(1, len(a)+1): tmp[i] = a[i-1] + tmp[i-1]
    return tmp[1:]

def find_cycle(p, pos):
    cnt = 0
    steps = [0] * (MAX_N+1)
    path = [False] * (MAX_N+1)
    while True:
        steps[cnt] = pos
        path[pos] = True
        cnt += 1
        pos = p[pos]
        if path[pos]: break # found closure
    st = steps.index(pos) # start of closure
    return [steps[:st], steps[st:cnt]]


def score(steps, c):
    ret = [0]*len(steps)
    for i in range(len(steps)): ret[i] = c[steps[i]]
    return ret

maxsc = -10**9-1
done = [False] * (N+1)
for i in range(1, N+1):
    if verbose: print('entering', i)
    if done[i]: continue
    [preclosure_path, closure_path] = find_cycle(P, i)
    if verbose: print('closure found:', closure_path)
    closure_scores = score(closure_path, C)
    preclosure_scores = score(preclosure_path, C)
    closure_score = sum(closure_scores)
    preclosure_len, closure_len = len(preclosure_path), len(closure_path)

    cycles = (K-preclosure_len)//closure_len
    resid = (K-preclosure_len)%closure_len
    if cycles>=1: cycles -= 1
    abbrev = closure_score * cycles
   
    trail = preclosure_scores + closure_scores * 3
    path = preclosure_path + closure_path*3
    if verbose: print('score trail:', trail)
    if verbose: print('path:', preclosure_path + closure_path*3)
    if verbose: print('mark:', mark)
    mark = min(K, len(preclosure_path+closure_path)+resid)
    localmax = max(cumsum(trail[0:mark])) + max(0, closure_score*cycles)
    if verbose: print('localmax:', localmax, 'cycles:', cycles)
    maxsc = max(localmax, maxsc)

    if verbose: print('going greedy')
    for j in range(1, closure_len):
        if K<=mark+j: break
        target = path[j]
        if done[target]: continue
        localmax = max(cumsum(trail[j:mark+j])) + max(0, closure_score*cycles)
        maxsc = max(localmax, maxsc)
        done[target] = True
        if verbose: print('done:', target, 'with', localmax)

print(maxsc)


Measured memory_bytes: 220776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a+b>=c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <memory>
using namespace std; 

typedef long long ll; 
typedef unsigned long long ull;
typedef unsigned uint; 
typedef long double l_double;

#define vtr vector
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define type(var) static_cast<type>(var)
#define TEST uint _ {}; cin >> _; while (_--)
#define PI (3.1415926535897932384626433832795)
#define MOD 1'00'00'00'007
#define EPS 1e-9
#define deb(x) cout<< #x << " --> " << x << endl;

template<typename T>
void vtrS(const vector<T> &ARR) 
{ for (T const &val: ARR) cout<<val<<" "; cout<<endl; }

template<typename T>
void vtrV(const vector<T> &ARR) 
{ for (T const &val: ARR) cout<<val<<endl; }

template<typename T>
void read_vvtr(vector<vector<T>> &ARR) 
{ for (vector<T> &i: ARR) for (T &j: i) cin >> j; }

template<typename T>
void vvtrS(const vector<vector<T>> &ARR) 
{ for (vector<T> const &i: ARR) { for (T const &j: i) cout<<j<<" "; cout<<endl; } }

template<typename T>
void vvtrNS(const vector<vector<T>> &ARR) 
{ for (vector<T> const &i: ARR) { for (T const &j: i) cout<<j; cout<<endl; } }

template<typename T>
T cntDigits(const T &N) { return (floor(log10(N)) + 1); }

template<typename T>
bool isPowOfTwo(const T &N) { return (N && (!(N&(N-1)))); }

template<typename T>
T lcm(T a, T b) { return ((a*b)/gcd(a, b)); }
// --------------------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<boolalpha;
    cout<<fixed<<setprecision(3); 
    // --------------------------------------
    
    int n {};
    ll x {};
    cin >> n >> x;
    vtr<ll> D {0};

    ll d {};
    while (n--) {
    	ll num {};
    	cin >> num;

    	d = d + num;
    	D.EB(d);
    }

    int ans {};
    for (auto const &val: D) {
    	if (val <= x) ++ans;
    	else break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll N;
    cin >> N;

    string a[] = {"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"};
    string name;
    while(N){
        N--;
        name += a[N%26];
        N /= 26;
    }

    rvs(name);
    cout << name << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG



int main(){
    int s;
    cin>>s;
    vector<ll> sum(2010,1);
    sum[1]=0;
    sum[2]=0;
    for(int i=6; i<=2000; i++){
        for(int j=3; j<=i-3;j++){
            sum[i]+=sum[j];
            sum[i]%=mod;
        }
    }

    cout<<sum[s]<<endl;

}

Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
#define INF (2147483647)
#define mod (1000000007)

int main(void){
  int N;
  cin >> N;
  cout << N*800-N/15*200 << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}





fn main() {
    input! {
        w: i64,
        h: i64,
        x: i64,
        y: i64,
    }

    let half_area: f64 = ((w * h) as f64) / 2.0;
    let is_center = if (2 * x == w) && (2 * y == h) { 1 } else { 0 };

    println!("{:.6} {}", half_area, is_center);
}


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

#define ll long long
#define endl '\n'

void max_self(int &a, int b){ a = max(a, b);}
void min_self(int &a, int b){ a = min(a, b);}

void solve(){
	int n; cin>>n;
	cout<<(n + 1) / 2<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	var N, M, a, b int
	fmt.Scan(&N, &M)
	c := make([]int, N)
	for i := 0; i < M; i++ {
		fmt.Scan(&a, &b)
		c[a-1]++
		c[b-1]++
	}
	for i := 0; i < N; i++ {
		fmt.Println(c[i])
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;

void solve()
  {
   int x;
   int ans = 0;
   cin>>x;
   int cnt = x/500;
   ans += 1000*cnt;
   x -= cnt*500;
   ans += 5*(x/5);
   cout<<ans;
  }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
  /* int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3648
# 文字列の入力
s = str(input())
min=999999

for i in range(len(s)-2):
  number=int(s[i])*100+int(s[i+1])*10+int(s[i+2])
  if abs(number - 753) < min:
    min = abs(number - 753)
    
print(min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll f(ll b, ll n) {
  if(n<b) return n;
  return f(b,n/b)+n%b;
}

bool check(ll b, ll n, ll s) {
  return f(b,n)==s;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n,s;
  cin>>n>>s;
  if(n==s) {
    cout << n+1 << endl;
    return 0;
  }
  for(ll b=2; b*b<=n; b++) {
    if(check(b,n,s)) {
      cout << b << endl;
      return 0;
    }
  }
  const ll big=numeric_limits<ll>::max();
  ll ans=big;
  for(ll a=1; a*a<=n; a++) {
    ll b = (a+n-s)/a;
    //cout << b << endl;
    if(b<2) continue;
    if(check(b,n,s)) {
      ans=min(ans,b);
    }
  }
  if(ans==big) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const float eps=1e-6;
const ll mod=1e8;
int main()
{
    int n,i;
    cin>>n;
    ll a1[n+1]={0},a2[n+1]={0},a3[n+1]={0},dp[n+1][3]={0};
    for(i=1;i<=n;i++)
    {
        cin>>a1[i]>>a2[i]>>a3[i];
    }
    for(i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a1[i];
        dp[i][1]=max(dp[i-1][2],dp[i-1][0])+a2[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a3[i];
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 4992
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  public static void main(String[] arg) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    sc.close();
    System.out.println(compute(line));
  }

  private static int compute(String line) {
    String[] elements = line.split(" ");
    LinkedList<String> stack = new LinkedList<>();
    for (String element : elements) {
      if (element.matches("[0-9]+")) {
        stack.push(element);
      } else if (element.equals("+")) {
        int a = Integer.valueOf(stack.poll());
        int b = Integer.valueOf(stack.poll());
        stack.push(String.valueOf(b + a));
      } else if (element.equals("-")) {
        int a = Integer.valueOf(stack.poll());
        int b = Integer.valueOf(stack.poll());
        stack.push(String.valueOf(b - a));
      } else if (element.equals("*")) {
        int a = Integer.valueOf(stack.poll());
        int b = Integer.valueOf(stack.poll());
        stack.push(String.valueOf(b * a));
      }
    }
    return Integer.valueOf(stack.poll());
  }
}


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

string t;

bool is_palindrome(string s)
{
	int i;

	for (i = 0; i < s.size() / 2; i++)
		if (s[i] != s[s.size() - i - 1])
			return false;
	return true;
}

int main(void)
{
	cin >> t;

	if (is_palindrome(t) && is_palindrome(t.substr(0, (t.size() - 1) / 2)) && is_palindrome(t.substr(t.size() / 2 + 1, (t.size() - 1) / 2)))
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
      //整数の入力
      Scanner sc = new Scanner(System.in);
      double Hankei = Double.parseDouble(sc.next());
      double Syutyo = 0;
      double pai = Math.PI;

      Syutyo = 2.0 * Hankei * pai;
      System.out.println(Syutyo);
    }
    
}


Measured memory_bytes: 35856
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
struct Edge {
	int to, id;
	Edge(int to, int id) :to(to), id(id) {}
};

vector<Edge> g[55];
vector<int> es;

bool dfs(int v, int tv, int p = -1) {
	if (v == tv) {//目的地
		es = vector<int>();//初期化
		return true;
	}
	for (Edge e : g[v] ) {
		if (e.to == p) continue;//親にはいかない
		if (dfs(e.to, tv, v)) {
			es.push_back(e.id);//辺のidを記録
			return true;
		}
	}
	return false;
}

long long  bitcount64(long long bits)
{
	bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
	bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
	bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
	bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
	bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
	return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}

void solve() {
	LL N, M;
	cin >> N;
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		//iは辺番号として決めておく。
		g[a].emplace_back(b, i);
		g[b].emplace_back(a, i);
	}

	cin >> M;
	vector<LL> eset(M,0);//辺の集合を表現bit
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		dfs(a, b);//esの中に辺番号
		for (int e : es) {
			eset[i] |= 1ll << e;
		}
	}

	LL ans = 0;
	//砲除原理やってく
	//条件の集合をbitで管理
	for (LL i = 0; i < (1ll << M); ++i) {
		//白にする辺を列挙
		LL mask = 0;
		for (LL j = 0; j < M;++j) {
			if ((i >> j) & 1) {
				mask |= eset[j];
			}
		}
		int white = bitcount64(mask);
		LL now = 1ll<<(N-1-white);//2^(n-1-while)
		if (bitcount64(i) % 2 == 0) {
			ans += now;//偶数個
		}
		else {
			ans -= now;//奇数個
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
typedef long long ll;
typedef pair<ll, ll> P;
map<long long, long long> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
signed main() {
    ll n;
    cin >> n;
    ll ini = n;
    ll length = 0;
    REP(i, 30) {
        n = n - modpow(26, i + 1);
        if (n <= 0) {
            length = i + 1;
            n = n + modpow(26, i + 1);
            break;
        }
    }
    string s;
    n--;
    while (n > 0) {
        s += 'a' + n % 26;
        n /= 26;
    }
    s += string(length - s.size(), 'a');
    reverse(s.begin(), s.end());
    cout << s << endl;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(K)]
dp = [0] * (H * W * 4)
table = [0] * (H * W)
for i, j, v in a: table[(i - 1) * W + j - 1] = v
for i in range(H):
  for j in range(W):
    x = i * W + j
    for k in range(4):
      if i + 1 < H:
        y = (i + 1) * W + j
        dp[y * 4 + 0] = max(dp[y * 4 + 0], dp[x * 4 + k])
      if j + 1 < W:
        y = i * W + j + 1
        dp[y * 4 + k] = max(dp[y * 4 + k], dp[x * 4 + k])
      if k + 1 <= 3 and table[x]:
        if i + 1 < H:
          y = (i + 1) * W + j
          dp[y * 4 + 0] = max(dp[y * 4 + 0], dp[x * 4 + k] + table[x])
        if j + 1 < W:
          y = i * W + j + 1
          dp[y * 4 + k + 1] = max(dp[y * 4 + k + 1], dp[x * 4 + k] + table[x])
for k in range(3): dp[(H * W - 1) * 4 + k] += table[-1]
print(max(dp[-4: ]))


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
ll a[5005];

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  ll res=0;
  rep(i,n)res+=a[i]-1;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<cstring>
using namespace std;
int main(){
	int n;
	 cin >> n; 
	 string s;
	 cin >> s;
	 int r = 0, w = 0;
	 for(int i = 0; i<s.length(); i++){
	 	if(s[i] == 'R'){
	 		r++;
		 }
		 else{
		 	w++;
		 }
	 }
	 int ans = 0;
	 for(int i = 0; i<r; i++){
	 	if(s[i] == 'W'){
	 		ans++;
		 }
	 }
	 cout << ans;
	 return 0;
}

Measured memory_bytes: 3732
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"math"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dd := make([][]int, 1000)
	for i := range dd {
		dd[i] = make([]int, 1000)
	}
	num := make([]int,1000)
	inv := make([]int, 1001)
	x := make([]int, 1000)
	y := make([]int, 1000)
	vv := make([]int, 1000)
	nowt := make([]float64, 1000)
	rev := make([]int, 1000)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf1 := strings.Split(scanner.Text(), " ")
			num[i], _ = strconv.Atoi(buf1[0])
			x[i], _ = strconv.Atoi(buf1[1])
			y[i], _ = strconv.Atoi(buf1[2])
			inv[num[i]] = i
		}
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				dd[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])
			}
		}
		scanner.Scan()
		m, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf2 := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(buf2[0])
			d, _ := strconv.Atoi(buf2[1])
			c = inv[c]
			d = inv[d]
			for j := 0; j < n; j++ {
				vv[j] = 0
				nowt[j]=999999999
				rev[j]=-1
			}
			nowt[c]=0
			for j := 0; j < n; j++ {
				M := 99999999
				at := 0
				for k := 0; k < n; k++ {
					if vv[k] == 0 && float64(M) > nowt[k] {
						M=int(nowt[k])
						at = k
					}
				}
				if M > 90000000 {
					break
				}
				vv[at]=1
				for k := 0; k < n; k++ {
					if vv[k] == 0 && dd[at][k]<=2500&&nowt[k]>nowt[at]+math.Sqrt(float64(dd[at][k])) {
						nowt[k]=nowt[at]+math.Sqrt(float64(dd[at][k]))
						rev[k] = at
					}
				}
			}
			if vv[d] == 0 {
				fmt.Println("NA")
			} else {
				stack := make([]int, 0)
				V := d
				for V != c {
					stack = append(stack, V)
					V = rev[V]
				}
				fmt.Print(num[c])
				for len(stack) > 0 {
					fmt.Printf(" %d", num[stack[len(stack)-1]])
					stack = stack[:len(stack)-1]
				}
				fmt.Println()
			}
		}
	}
}


Measured memory_bytes: 2376
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9 + 5;

int n;
vector<int> a, ans;
vector<vector<int>> G;

void dfs(int v, int p, vector<int> &vec){
	for(auto nv : G[v]){
		if(nv == p) continue;
		auto idx = lower_bound(vec.begin(), vec.end(), a[nv]);
		int origin = *idx;
		*idx = a[nv];
		ans[nv] = lower_bound(vec.begin(), vec.end(), INF) - vec.begin();
		dfs(nv, v, vec);
		*idx = origin;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	rep(i,n) cin >> a[i];
	G.resize(n);
	rep(i,n-1){
		int u, v;
		cin >> u >> v;
		--u; --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ans.resize(n, -1);
	ans[0] = 1;
	vector<int> v(n+1, INF);
	v[0] = a[0];
	dfs(0, -1, v);
	rep(i,n) cout << ans[i] << endl;
	return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  ll sum = 0;
  rep(i, k) { ll add;
    cin >> add;
    sum += add;
  }

  string ans = (sum >= n) ? "Yes" : "No";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
long long N, M, K;
int c[3][3];
int main() {
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}
	int a1, b1, b2, b3;
	bool flag = false;
	for (int i = 0; i <= c[0][0]; ++i) {
		a1 = i; 
		b1 = c[0][0] - a1; 
		b2 = c[0][1] - a1;
		b3 = c[0][2] - a1;
		for (int j = 0; j <= c[1][0]; ++j) {
			if (j + b1 == c[1][0] && j + b2 == c[1][1] && j + b3 == c[1][2]) {
				for (int k = 0; k <= c[2][0]; ++k) {
					if (k + b1 == c[2][0] && k + b2 == c[2][1] && k + b3 == c[2][2]) {
						flag = true;
					}
				}
			}
		}
        
		if (flag) break;
 	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

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

	if (0 > x - r || x + r > W)
		puts("No");
	else if (0 > y - r || y + r > H)
		puts("No");
	else
		puts("Yes");

	return 0;
}

Measured memory_bytes: 584
n,a,b = map(int,input().split())

if a == b:
  ans = 0
elif abs(a-b)%2 == 0:
  ans = abs(a-b)//2
elif abs(a-b)%2 == 1:
  if a > b:
    if (a-1) > (n-b):
      ans = (n-a) + (a-b-1)//2 + 1
    else:
      ans = (b-1) + (a-b-1)//2 + 1
  if b > a:
    if (b-1) > (n-a):
      ans = (n-b) + (b-a-1)//2 + 1
    else:
      ans = (a-1) + (b-a-1)//2 + 1
      
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cctype>
#include <string>

 
using namespace std;
     
int main() {
  int n,b;
  cin >> n >> b;
  std::string s;
  cin >> s;
      
  for (int i=0;i<n;i++){
    if (i == b-1) {
      if (s[i] == 'A') {
        s[i] = 'a';
      }
      if (s[i] == 'B') {
        s[i] = 'b';
      }
      if (s[i] == 'C') {
        s[i] = 'c';
      }
    }
  }
  cout << s <<endl;   
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int max = -1000 * 1000;
  if (a + b > max) { max = a + b; }
  if (a - b > max) { max = a - b; }
  if (a * b > max) { max = a * b; }
  cout << max << endl;
}

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

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

  int n;
  vector<int> s;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    s.push_back(p);
  }

  int q;
  vector<int> t;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int p;
    cin >> p;
    t.push_back(p);
  }

  int c = 0;
  for (int i = 0; i < q; ++i) {
    int p = t[i];

    int l = 0;
    int r = n;
    while (l < r) {
      int m = (l + r) / 2;
      if (p == s[m]) {
        ++c;
        break;
      } else if (p < s[m]) {
        r = m;
      } else {
        l = m + 1;
      }
    }
  }
  cout << c << endl;

  return 0;
}



Measured memory_bytes: 3428
"use strict"

function main(input) {
  //一部の正解がjsで扱う最大値を越えるため、文字列として扱う。
  //計算は配列を使った筆算（上の配列と下の配列を計算、桁上がりも対応）にて行う

  const cal = (a, b) => {
    //左詰の配列だと計算しづらいのでreverse
    let aa = a
      .split("")
      .map(v => ~~v)
      .reverse()
    let bb = b
      .split("")
      .map(v => ~~v)
      .reverse()

    let cc = []
    let digit = 0
    //各配列の値についてaa[i] + bb[i]する=筆算 桁数の大きい方の回数
    for (let i = 0; i < bb.length; i++) {
      let tmp = Number(aa[i])
        ? Number(aa[i]) + Number(bb[i]) + digit
        : Number(bb[i]) + digit //
      digit = 0

      if (tmp >= 10) {
        digit = Math.floor(tmp / 10)
        tmp = tmp % 10
      } else {
        digit = 0
      }
      cc.push(tmp)
    }
    if (digit > 0) cc.push(digit)

    return cc.reverse().join("") //array -> recerse -> string
  } //end cal

  input = Number(input)

  let numbers = ["2", "1"]

  for (let i = 2; i <= input; i++) {
    let tmp = cal(numbers[i - 2], numbers[i - 1])
    numbers.push(tmp)
  }
  console.log(numbers.pop()) //string
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

const int MAX = 1e5 + 1;

int N, M;

struct uf {
  int cmps; vi s;
  uf (int n) : cmps(n), s(n, -1) {}
  bool conn(int i, int j) {
    return find(i) == find(j);
  }
  int find(int i) {
    return s[i] < 0 ? i : (s[i] = find(s[i]));
  }
  void join(int i, int j) {
    i = find(i), j = find(j);
    if (i == j) return;
    cmps--;
    if (s[i] > s[j]) swap(i, j);
    s[i] += s[j]; s[j] = i; 
  }
};

// aaaaaaaaaaaaaaaa
void solve() {
  scanf("%d%d", &N, &M);

  uf pd(N);
  int x, y, z;
  rep(i, 0, M) {
    scanf("%d%d%d", &x, &y, &z);
    --x; --y; z &= 1;
    pd.join(x, y);
  }
  
  printf("%d\n", pd.cmps);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  solve();
	return 0;
}

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

void Main() {
  int n, m;
  cin >> n >> m;
  vector<int> yakusu;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      yakusu.push_back(i);
      yakusu.push_back(m / i);
    }
  }

  sort(yakusu.rbegin(), yakusu.rend());

  for (int i = 0; i < yakusu.size(); i++) {
    if (yakusu[i] <= (m / n)) {
      cout << yakusu[i] << endl;
      break;
    }
  }
}

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



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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  string s; cin >> s;
  rep(i,s.size()/2) cout << s[2*i];
  if(s.size()%2) cout << s[s.size()-1];
  cout << endl;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
int main(){
  ll N;
  cin >> N;
  llvec A(N+1);
  llvec cand1(N+1);
  llvec cand2(N+1);
  rep(i, N+1)cin >> A[i];
  
  //ll tmp = accumulate(ALL(A), 0LL);
  cand1[N]=0;
  rrep(i, N){
    cand1[i] = cand1[i+1] + A[i+1];
  }
  
  
  
  bool chk = true;
  if(A[0]>0 and N!=0)chk=false;
  if(A[0]!=1 and N==0)chk=false;
  cand2[0]=1;
  ll ans = 1;
  FOR(i, 1, N+1){
    cand2[i] = cand2[i-1]*2 - A[i];
    if(cand2[i]<=0 and i!=N){
      chk =false;
      break;
    }
    if(cand2[i]<0){
      chk =false;
      break;
    }
    if(cand2[i]>=cand1[i]){
      cand2[i]=cand1[i];
    }
    //cerr << i <<" "<< A[i] <<" "<<cand1[i] << " " << cand2[i] << endl;
    ans += cand2[i]+A[i];
  }
  
  if(!chk)cout << -1;
  else cout << ans;
  return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    int H,A;
    cin >> H >> A;
    int cnt = 0;
    while(H > 0){
        H -= A;
        cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

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

int dp[2][1 << 20];
char s[21][21];
int main() {
	int m, n; scanf("%d%d", &m, &n);
	int cnt = 1;
	rep(i, m)scanf("%s", s[i]);
	rep(i, m)rep(j, n) {
		if (s[i][j] == '?')cnt = (cnt * 3) % MOD;
	}
	int*now = dp[0], *nxt = dp[1];
	now[0] = 1;
	rep(i, m)rep(j, n) {
		fill(nxt, nxt + (1 << n), 0);
		rep(k, 1 << n) {
			if (now[k] == 0)continue;
			int a = k&~(1 << (j - 1));
			if (s[i][j] == 'J' || s[i][j] == '?') {
				if (j < n - 1)(nxt[a | 1 << j] += now[k]) %= MOD;
				else(nxt[a&~(1 << j)] += now[k]) %= MOD;
			}
			if (s[i][j] == 'O' || s[i][j] == '?')
				(nxt[k&~(1 << j)] += now[k]) %= MOD;
			if (s[i][j] == 'I' || s[i][j] == '?') {
				if (!(k >> j & 1))(nxt[a&~(1 << j)] += now[k]) %= MOD;
			}
		}
		swap(now, nxt);
	}
	rep(i, 1 << n)cnt = (cnt + MOD - now[i]) % MOD;
	printf("%d\n", cnt);
}

Measured memory_bytes: 11384
#include <cstdio>
#define ll long long

struct data{ int from, to; ll dist; };
int n, m;
int visit[1010], neg[1010];
ll darr[1010];
data arr[2010];

int main(){
	int i, j, a, s;
	ll d;
	scanf("%d %d", &n, &m);
	for(i = 0; i < m; i++) scanf("%d %d %lld", &a, &s, &d), arr[i] = (data){a, s, -d}; visit[1] = 1;
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			a = arr[j].from; s = arr[j].to; d = arr[j].dist;
			if(visit[a]){
				if(!visit[s]) darr[s] = darr[a] + d, visit[s] = 1;
				else if(darr[s] > darr[a] + d) darr[s] = darr[a] + d;
			}
		}
	}
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			a = arr[j].from; s = arr[j].to; d = arr[j].dist;
			if(visit[a]){
				if(darr[s] > darr[a] + d) darr[s] = darr[a] + d, neg[s] = 1;
				if(neg[a]) neg[s] = 1;
			}
		}
	}
	if(neg[n]) printf("inf");
	else printf("%lld", -darr[n]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,m; cin >> n >> m;
	vl ac(101010,0);
	vl wa(101010,0);
	rep(i,m){
		ll t; string s; cin >> t >> s;
		if(s=="WA"){
			if(!ac[t]) wa[t]++;
		}else{
			ac[t] = 1;
		}
	}
	ll a=0,w=0;
	rep(i,101010){
		if(ac[i]){
			a++; w+=wa[i];
		}
	}
	print2(a,w);
}

Measured memory_bytes: 1920
import java.util.Scanner;

class Main {

	int max = -1000000,min = 1000000;

	public void min() {

		Scanner sc = new Scanner(System.in);

		long sum = 0;

		int n = sc.nextInt();

		if(n == 0) {

			max = 0;

			min = 0;

		} else if (n == 1) {

			int ai = sc.nextInt();

				max = ai;

				min = ai;

				sum += ai;

		} else {

			for(int I = 1; I <= n; I++) {

				int ai = sc.nextInt();

				if(ai > max) {

					max = ai;

					if(ai < min) {

						min = ai;

					}

				} else if(ai < min) {

					min = ai;

					if(ai > max) {

						max = ai;

					}

				}

				sum += ai;

			}
		}

		System.out.println(min + " " + max + " " + sum);

	}

	public static void main(String[] args) {

		new Main().min();

	}

}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N >> S;
    string S_tmp = S;
    string S_tmp1 = S;
    ll S_count = 1;

    sort(S_tmp1.begin(), S_tmp1.end());
    //cout << "test" << endl;

    REP(i,S_tmp1.size()-1){
        if(!(S_tmp1.at(i)==S_tmp1.at(i+1))){
            S_count++;
        }
    }
    //cout << "test" << endl;

    ll ans = 0;

    REPS(i, N - 1)
    {

        string X, Y;
        X = S.substr(i);
        S = S_tmp;
        Y = S.erase(i);
        S = S_tmp;
        sort(X.begin(), X.end());
        sort(Y.begin(), Y.end());
        //cout << "test1" << endl;

        ll X_count = 1;
        ll Y_count = 1;

        REP(j,X.size()-1){
            if (!(X.at(j) == X.at(j + 1))){
                X_count++;
            }
        }
        //cout << "test2" << endl;

        REP(j, Y.size() - 1)
        {
            if (!(Y.at(j) == Y.at(j + 1)))
            {
                Y_count++;
            }
        }
        //cout << "test3" << endl;

        ans = max(ans, X_count + Y_count - S_count);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define VM 10000 
#define M 2000001

int main()
{
  unsigned short *P,*Q;

  int S[VM+1];
  int n,i,j;

  scanf("%d",&n);

  P = malloc(sizeof(short)*n+1);
  Q = malloc(sizeof(short)*n+1);

  for(i=0;i <=VM;i++)
    {
      S[i]=0;
    }

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

  for(i=1;i<=VM;i++)S[i]=S[i]+S[i-1];
 
  for(j=1;j<=n;j++){
    Q[S[P[j]]] = P[j];
    S[P[j]]--;
  }
 
  
  for(i=1;i<=n;i++)
    {
      if(i>1)printf(" ");
      printf("%d",Q[i]);
    }
        printf("\n");
      return 0;
}
  
      

Measured memory_bytes: 8460
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
 
const int maxn = 2010;
vector<int> g[maxn];
int cnt[maxn];

int cursz = 0;

void dfs(int v, int k, int p = 0, int d = 0) {
	if(k & 1 and d == k / 2 + 1) {
		cnt[v]++;
		return;
	}
	cursz++;
	if(!(k & 1) and d == k / 2) return;
	for(int x : g[v]) {
		if(x == p) continue;
		dfs(x, k, v, d + 1);
		cnt[v] += cnt[x];
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	if(k == 1) {
		cout << n - 2 << endl;
		return 0;
	}
	if(k >= n - 1) {
		cout << 0 << endl;
		return 0;
	}
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans = n;
	for(int i = 1; i <= n; i++) {
		if(g[i].size() == 1) continue;
		cursz = 0;
		fill(cnt, cnt + maxn, 0);
		dfs(i, k);
		if(k & 1) {
			int maxpos = 0;
			for(int x : g[i]) {
				maxpos = max(maxpos, cnt[x]);
			}
			cursz += maxpos;
		}
		ans = min(ans, n - cursz);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3712
import re
a = [chr(i) for i in range(ord('a'), ord('z')+1)]
l = [0] * len(a)
while True:
  try:
    s = str(input())
  except:
    break
  for c in s:
    p = 0
    if re.match(r'^[a-zA-Z]$', c):
      p = a.index(c.lower())
      l[p] += 1

for i in range(len(a)):
  print("{0} : {1}".format(a[i], l[i]))


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    int N, M;
    cin >> N >> M;
    int sum = 0;
    rep(i, 0, M) {
        int a;
        cin >> a;
        sum += a;
    }
    int ans = N - sum;
    chmax(ans, -1);
    cout << ans << "\n";
}


Measured memory_bytes: 3616
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	int H,W;
	while(true)
	    {
		H=scan.nextInt();
		W=scan.nextInt();
		if((H==0) && (W==0))break;
		for(int i=0;i<H;i++)
		    {
			
			if(H==0 && W==0)break;
			for(int j=0;j<W;j++)
			    {
				System.out.print("#");
			    }
			System.out.println();
		    }
		System.out.println();
	    }
    }
}

Measured memory_bytes: 26972