akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

V<V<char>> ac = { { 'A','T' }, {'G','C'} };

int main() {
	
	char b;
	cin >> b;
	rep(i, 2)rep(j, 2)if (ac[i][j] == b) {
		b = ac[i][(j + 1) % 2];
		break;
	}
	cout << b << endl;

}

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

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

	for (i = 0; a > 0; a -= c,i++);
	for (j = 0; b > 0; b -= d,j++);
	if (i > j) cout << k - i << endl;
	else cout << k - j << endl;
	return 0;
}

Measured memory_bytes: 1160
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type UnionFind struct {
	Par  []int
	Rank []int
}

func NewUnionFind(n int) *UnionFind {
	uf := &UnionFind{
		Par:  make([]int, n),
		Rank: make([]int, n),
	}
	uf.Init(n)
	return uf
}

func (uf *UnionFind) Init(n int) {
	for i := 0; i < n; i++ {
		uf.Par[i] = i
		uf.Rank[i] = 0
	}
}

func (uf *UnionFind) Find(x int) int {
	for uf.Par[x] != x {
		x, uf.Par[x] = uf.Par[x], uf.Par[uf.Par[x]]
	}
	return x
}

func (uf *UnionFind) Unite(x, y int) {
	x = uf.Find(x)
	y = uf.Find(y)
	if x == y {
		return
	}

	if uf.Rank[x] < uf.Rank[y] {
		uf.Par[x] = y
	} else {
		uf.Par[y] = x
		if uf.Rank[x] == uf.Rank[y] {
			uf.Rank[x]++
		}
	}
}

func (uf *UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	p := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = nextInt() - 1
		x[p[i]] = i
	}

	uf := NewUnionFind(n)
	for i := 0; i < m; i++ {
		x, y := nextInt()-1, nextInt()-1
		uf.Unite(x, y)
	}

	ans := 0
	for i := 0; i < n; i++ {
		if uf.Same(i, x[i]) {
			ans++
		}
	}

	puts(ans)
}


Measured memory_bytes: 4608
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    beforeLen = len(num_list)

    num_list = set(num_list)

    afterLen = len(num_list)

    print('YES' if beforeLen == afterLen else 'NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 100436
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
int main()
{
  string s;
  cin >> s;

  string t = "";
  re(i, s.size()) {
    if (i % 2 == 0) t += s[i];
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

char s[1234][1234];

int main(){
  for(int n;cin>>n,n;){
    for(int i=0;i<n;i++){
      cin>>s[i];
      if(i){
	for(int j=0;;j++){
	  if(s[i][j]=='.'){
	    s[i][j]=' ';
	  }else{
	    s[i][j-1]='+';
	    for(int k=i-1;s[k][j-1]==' ';k--){
	      s[k][j-1]='|';
	    }
	    break;
	  }
	}
      }
    }
    for(int i=0;i<n;i++){
      cout<<s[i]<<endl;
    }
  }
}

  

Measured memory_bytes: 2372
#include <bits/stdc++.h>
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N, K; cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int h; cin >> h;
		if (h >= K) ans++;
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

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

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define memset(a,first,last,val) fs(i,first,last,1) a[i]=val
#define nl cout<<"\n";
#define chk(x) cout<<#x<<x<<" ", nl
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define mid(a,b) ((a+b)/2)
#define pb push_back
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

vl vb;
int N;

class triplet{
    public:
    ll f, s, t;};

vl in(ll n){
    vl ar;
    ll x;
    f(i,n)
    cin>>ar[i];
    return ar;
}
vll in_pr(ll n){
    vll ar;
    ll x,y;
    f(i,n)
    {cin>>x>>y;
    ar[i]={x,y};
    }return ar;
}
void out(vl v, char ch='\0'){
    fl(i,v)
    cout<<i<<ch;
}

void printArray(vector<int> arr, int n) 
{ 
    ll num=0;
    for (int i = 0; i < n; i++) 
    num*=10, num+=i;

    if(n==N)
    vb.pb(num);
        
} 

int printfactorialof(int n){
    if(n<=1)
        return 1;
    
    return n*printfactorialof(n-1);
}

void solve(){
ll N,K,x,i=0;
cin>>N>>K;
vl v;
ll m=N;
f(i,N)
cin>>x, v.pb(x);
i=1;
N-=K;
while(N>0)
{
    i++;
    N-=(K-1);
}
cout<<i,nl
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0;
ll s2l(string st){
  stringstream ss(st);
  ll x;ss>>x;
  return x;
}
void calc(ll x,string st){
  if(st=="") ans+=x;
  else{
    for(ll i=1;i<=st.size();i++){
      calc(x+s2l(st.substr(0,i)),st.substr(i));
    }
  }
}
int main(){
  string st;cin>>st;
  calc(0,st);
  cout <<  ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
#define PI 3.1415926535897932384626433832795
#define coutfix(i) cout << fixed << setprecision(i)
using namespace std;

int main()
{
	string ss;
	cin >> ss;
	int64 aa = 0, bb = 0;
	for(int64 ii = 0;ii < ss.length();ii++)
	{
		if((ss[ii] - '0') == ii % 2)
		{
			aa++;
		}
		else
		{
			bb++;
		}
	}
	cout << min(aa, bb) << endl;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,s,b,ans;
int main() {
	scanf("%lld %lld",&n,&s);
	ans=-1;
	for (b=2;b*b<=n;b++) {
		ll m=n,c=0;
		while (m>0) {
			c+=m%b;
			m/=b;
		}
		if (c==s) {
			ans=b; break;
		}
	}
	if (ans==-1) {
		for (b=1;b*b<=(n-s);b++) {
			if ((n-s)%b==0) {
				ll t=(n-s)/b+1,m=b;
				if (t>=2&&m<t&&(s-m)<t&&m<=s&&(ans>t||ans==-1)) {
					//printf("%lld %lld\n",t,m);
					ans=t;
				}
			}
		}
	}
	if (n==s) ans=n+1;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int n;
  scanf("%d",&n);
  int a[n];
  int i;
  int total = 0;
  for(i=0;i<n;i++) {
    scanf("%d",&a[i]);
    total += a[i];
  }
  //printf("%d\n",total);
  int min = 100000;
  int minid = 1000;
  for(i=n-1;i>-1;i--) {
    int dif = abs(a[i] * n - total);
    //printf("%d %d %d\n",dif,min,a[i]);
    if(dif <= min) {
      minid = i;
      min = dif;
    }
  }
  printf("%d\n",minid);
  return 0;
}


Measured memory_bytes: 128
N,A,B=map(int,input().split())
ans=0
for i in range(1,N+1):
    i=str(i)
    l=len(i)
    s=0
    for j in range(l):
        s+=int(i[j])
    if A<=s<=B:
        ans+=int(i)
        
print(ans)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Pip; 
const int INF = (1<<30);

int main(){

  int w, h;
  int data[102][102] = {{0}};

  cin >> w >> h;

  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      cin >> data[i][j];
    }
  }

  queue<Pii> q;
  bool flag[102][102][6];
  int cnt = 0;

  fill_n(**flag, sizeof(flag), false);
  q.push(Pii(0, 0));
  
  while( !q.empty() ) {
    Pii p = q.front(); q.pop();
    int y = p.fr, x = p.sc;
    if( y % 2 == 0 ) {
      int dx[] = {-1, 0, 1, 0, -1, -1}, dy[] = {-1, -1, 0, 1, 1, 0};
      for(int i=0; i<6; i++) {
	int nx = x + dx[i], ny = y + dy[i];
	if( nx >= 0 && ny >= 0 && nx <= w+1 && ny <= h+1 ) {
	  if( !flag[ny][nx][i + 3 % 6] ) {
	    flag[ny][nx][i + 3 % 6] = true;
	    if( ny != 0 && nx != 0 && ny != h+1 && nx != w+1 && data[ny][nx] ) {
	      cnt++;
	    }
	    if( !data[ny][nx] ) {
	      q.push(Pii(ny, nx));
	    }
	  }
	}
      }
    }
  
    else {
      int dx[] = {0, 1, 1, 1, 0, -1}, dy[] = {-1, -1, 0, 1, 1, 0};
      for(int i=0; i<6; i++) {
	int nx = x + dx[i], ny = y + dy[i];
	if( nx >= 0 && ny >= 0 && nx <= w+1 && ny <= h+1 ) {
	  if( !flag[ny][nx][i + 3 % 6] ) {
	    flag[ny][nx][i + 3 % 6] = true;
	    if( ny != 0 && nx != 0 && ny != h+1 && nx != w+1 && data[ny][nx] ) {
	      cnt++;
	    }
	    if( !data[ny][nx] ) {
	      q.push(Pii(ny, nx));
	    }
	  }
	}
      }
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1332
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        long w = 0;
        long c = 0;
        for (int i = 0;i < s.length;++i){
            if(s[i] == 'W'){
                c += i - w;
                ++w;
            }
        }
        System.out.println(c);
    }

}




Measured memory_bytes: 27428
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    int n;
    cin >> n;
    vector<long long> A(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<long long>());

    int rem = n - 2;
    long long res = A[0];
    for (int i = 1; i < n; ++i) {
        if (rem-- > 0) {
            res += A[i];
        }
        if (rem-- > 0) {
            res += A[i];
        }
        // cout << rem << " " << A[i] << " " << res << endl;
    }

    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans = 0;
    for (auto &p: mp) {
        int sc = p.second;
        ans += (ll)sc*(sc-1)/2;
    }
    cout << ans << endl;

    return 0;

}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) cout << 1; // 三色とも同じ
	else if ((a - b) * (a - c) * (b - c) == 0) cout << 2; // 二色が同じ
	else cout << 3;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

普通に3C3+3C2の式を書けば終わるね
……上のコードでやってる方法は流石に荒業だけど、2つが同値ならば、かつその時のみ値が0になり、
しかも総積が0になる時は、0は掛け算の単位元だからどれかの項に0があることを利用しているのね
*/

Measured memory_bytes: 256
#!/usr/env perl

while(<>){
  ($a, $b, $c, $d) = split /\s+/;
  print "Left" if($a + $b > $c + $d);
  print "Right" if($a + $b < $c + $d);
  print "Balanced" if($a + $b == $c + $d);
  exit;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
int ans,x,n;
int f[20][20][2][2],B[40];
int M(int x)
{
    return x<0?x+10:x;
}
void dp(int p,int n,int a,int b)
{
    if(f[p][n][a][b]!=-1){ans+=f[p][n][a][b];return ;}
    int u=ans;
    if(p+p-1==n)
    {
        if(a==0&&b==0)ans+=10*(B[p]==0);
        else if(a==1&&b==1)ans+=10*(B[p]==9);
        return ;
    }
    if(p+p-1>n)
    {
        ans+=a==b;
        return ;
    }
     for (int i=p==1;i<=9;i++)
    for (int j=0;j<=9;j++)
    if (M(i-j-b)==B[p]&&(a==(j<i)||j==i)&&(M(j-i)==B[n+1-p]||M(j-1-i)==B[n+1-p])){
        if (a){
            if (j==i&&B[n+1-p]==0) continue;
            dp(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
        }else{
            if (j==i&&B[n+1-p]==9) continue;
            dp(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
        }
    }
    /*
    for(int i=p==1;i<=9;i++)
    {
        for(int j=0;j<=9;j++)
        {
           if (M(i-j-b)==B[p]&&(a==(j<i)||j==i)&&(M(j-i)==B[n+1-p]||M(j-1-i)==B[n+1-p])) {
            if(a)
            {
                if(j==i&&B[n+1-p]==0)continue;
                dp(p+1,n,M(j-1-i)==B[n+1-p],i+b-j<0);
            }
            else
            {
                if (j==i&&B[n+1-p]==9) continue;
                dp(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
            }
            }
        }
    }*/
    f[p][n][a][b]=ans-u;
}
signed main()
{
    scanf("%lld",&n);x=n;int k;
    if(n%9)return puts("0"),0;
    for(k=1;k<=10&&x;k++)B[k]=x%10,x/=10;k--;
    for(int i=k;i<=18;i++)memset(f,-1,sizeof(f)),dp(1,i,0,0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		sc.close();
		boolean b = true; 
		
		for(int i=0; i<s.length()-1; i++) {
			char c = s.charAt(i);
			for(int j=i+1; j<s.length(); j++) {
				if(c==s.charAt(j)) {
					b = false;
					break;
				}
			}
		}
		
		if(b) {
			System.out.println("yes");
		}else {
			System.out.println("no");
		}

	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for(ll i=1;i*i<=n;i++) {
    if(n%i==0) {
      res.push_back(i);
      if(i!=n/i) {
        res.push_back(n/i);
      }
    }
  }
  return res;
}

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  ll x;
  cin >> x;
  vec div=divisor(x);
  for(auto p:div) {
    ll tx=x/p;
    for(ll i=0;i*i*i*i<=tx;i++) {
      ll a=i;
      ll b=a-p;
      if(a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b==tx) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3600
require 'pp'

def gets; ARGF.gets; end

class Solver

  def main
    a, b = gets.chomp.split
    # puts a
    # puts b

    if a == 'H' && b == 'H'
      puts "H"
    elsif a == 'H' && b == 'D'
      puts "D"
    elsif a == 'D' && b == 'H'
      puts "D"
    else
      puts "H"
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
n,y = map(int,input().split())

total = 0
X = -1
Y = -1
Z = -1


for i in range(n + 1):
      for j in range(n - i + 1):
              k = n - i - j
              if k < 0:
                      break
              total = 10000 * i + 5000 * j + 1000 * k
              if total == y:
                      X = i
                      Y = j
                      Z = k
                      break
print(str(X) + " " + str(Y) + " " + str(Z))

Measured memory_bytes: 3064
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()

	active := 0
	ans := 0
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		if active > tmp {
			active = tmp
		} else {
			ans += tmp - active
			active = tmp
		}
	}
	fmt.Printf("%v\n", ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int gcd(int i, int j) {
  if(i % j == 0) {
    return(j);
  } else {
    return(gcd(j, i % j));
  }
}

int main() {

  int k;
  cin >> k;
  ll ans = 0;
  for(int i = 1; i <= k; i++) {
    for(int j = 1; j <= k; j++) {
      for(int l = 1; l <= k; l++) {
        int b = gcd(i,j);
        ll t = gcd(b,l);
        ans = ans + t;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll gcd(ll a, ll b) {
    if (a < b)
        swap(a, b);
    ll c = a % b;
    if (c == 0)
        return b;
    return gcd(b, c);
}

ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = gcdex(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);

    ll x, y;
    gcdex(a, b, x, y);
    cout << x << " " << y << endl;
    return 0;
}


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

int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    int a;
    if(s==1) a=2;
    else a=s-1;
    for(int i=0;i<k;i++) cout<<s<<" ";
    for(int i=0;i<n-k;i++) cout<<a<<" ";
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using P = pair<long long, long long>;

struct data {
  int to, n;
};

long long n, m;
vector<long long> dp;
vector<vector<data>> edge;
vector<P> v;
vector<vector<long long>> memo;

long long twopow(long long x) {
  long long res = 1, now = 2;
  while(x) {
    if(x & 1) res *= now;
    now *= now;
    x >>= 1;
  }
  return res;
}

unsigned long long popcount(unsigned long long x) {
  x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) +
      (x & 0x5555555555555555UL);
  x = ((x & 0xccccccccccccccccUL) >> 2) +
      (x & 0x3333333333333333UL);
  x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) +
      (x & 0x0f0f0f0f0f0f0f0fUL);
  x = ((x & 0xff00ff00ff00ff00UL) >> 8) +
      (x & 0x00ff00ff00ff00ffUL);
  x = ((x & 0xffff0000ffff0000UL) >> 16) +
      (x & 0x0000ffff0000ffffUL);
  x = ((x & 0xffffffff00000000UL) >> 32) +
      (x & 0x00000000ffffffffUL);
  return x;
}

long long solve();

int main() {
  cin >> n;
  edge.resize(n);
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].push_back({b, i});
    edge[b].push_back({a, i});
  }
  cin >> m;
  v.resize(m);
  for(int i = 0; i < m; ++i) {
    cin >> v[i].fi >> v[i].se;
    --v[i].fi, --v[i].se;
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  memo.assign(n, vector<long long>(n, 0));
  for(int i = 0; i < n; ++i) {
    queue<int> qu;
    vector<bool> used(n, 0);
    qu.push(i);
    used[i] = 1;
    while(qu.size()) {
      int now = qu.front();
      qu.pop();
      for(auto e : edge[now]) {
        int nextp = e.to;
        if(!used[nextp]) {
          memo[i][nextp] = memo[i][now];
          memo[i][nextp] += (1LL << e.n);
          used[nextp] = 1;
          qu.push(nextp);
        }
      }
    }
  }
  for(long long i = 0; i < (1LL << m); ++i) {
    long long now = 0, nowb = 0;
    set<int> st;
    for(int j = 0; j < m; ++j)
      if(i >> j & 1) nowb |= memo[v[j].fi][v[j].se];
    now = twopow(n - 1 - (long long)popcount(nowb));
    if(popcount(i) % 2)
      res -= now;
    else
      res += now;
  }
  return res;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var amari = n % 1000;
            WriteLine(amari == 0 ? 0 : 1000 - amari);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17624
#include<stdio.h>
long long a[11][1001];
int main(void){
  int i,j,k,n,m;
  a[0][0]=1;
  for(i=0;i<=100;i++){        //0~100までの数字について見ていく
    for(j=1000;j-i>=0;j--){   //sの制限値 0~1000
      for(k=9;k>0;k--){      //nの制限値 0~9
        a[k][j]+=a[k-1][j-i];
      }
    }
  }
  while(1){
    scanf("%d %d",&n,&m);
    if(n==0 && m==0)break;
    printf("%lld\n",a[n][m]);
  }
  return 0;
}

Measured memory_bytes: 672
//
//  main.cpp
//  OddString
//
//  Created by wenhan on 2017/9/2.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
        if(i%2==0)
            cout<<s[i];
    cout<<endl;
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
const int MAXN = 100050;
const int MAXM = 400500;
bool vis[MAXN];
int h[MAXN],nx[MAXM],to[MAXM],tot,rk[MAXN];
int color[MAXN],n,m;
void add_edge(int x,int y){to[++tot]=y;nx[tot]=h[x];h[x]=tot;rk[x]++;}
void link(int x,int y){add_edge(x,y);add_edge(y,x);}
bool dfs(int x,int y){
	if(color[x]&&3-color[x]!=y)return 0;
	if(vis[x])return 1;
	vis[x]=1;
	color[x]=3-y;
	bool tmp=true;
	for(int i=h[x];i;i=nx[i]){
	//	if(vis[to[i]])continue;
		tmp&=dfs(to[i],color[x]);
	}
	return tmp;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,1,m){
		int a,b;
		cin>>a>>b;
		link(a,b);
	}
	ll cnt1=0,cnt2=0,cnt3=0;
	rep(i,1,n){
		if(!rk[i])cnt1++;
		else if(!color[i]){
			int ret = dfs(i,1);
			if(ret == 0)
				cnt3++;
			else 
				cnt2++;
		}
	
	}
//	cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;
	cout<<cnt1*cnt1+2LL*cnt1*(n-cnt1)+cnt2*cnt2*2+cnt2*cnt3*2+cnt3*cnt3;
	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define inf mod1
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
	fast;
	ll h = 1;
	//scanf("%lld", &h);
    while(h--){ 
            ll n, m;
            cin >> n >> m;
            if(n == m){cout << "Yes";}
            else{cout << "No";}     
        }   
    }       

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


def solve(W: int, H: int, x: int, y: int):
    if x * 2 == W and y * 2 == H:
        p = 1
    else:
        p = 0
    print(W * H / 2, p)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(W, H, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
vvl v;
//vl vis,d;
ll dp[1<<21];ll c[21][21];

int main() {
    IOS;
    cin>>n;
    fo(i,n)fo(j,n)cin>>c[i][j];
    dp[0]=1;
    for(int mask=1;mask<(1<<n);mask++){
        h=-1;fo(i,n)h+=(mask&(1<<i))>0;
        fo(i,n)if(c[h][i]&&(mask&(1<<i))!=0)dp[mask]+=dp[mask^(1<<i)]; 
        dp[mask]%=mod;//cout<<dp[mask]<<el;
    }
    cout<<dp[(1<<n)-1];
    return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
int s[100004],m[100004];
int main(){
	long long t,ans=0;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>s[i];
		m[s[i]]++;
		ans+=s[i];
	}
	long long r;
	cin>>r;
	for(int i=0;i<r;i++){
		long long a,b;
		cin>>a>>b;
		long long q=b-a;
		ans+=m[a]*q;
		m[b]+=m[a];
		m[a]=0;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 4412
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,ans=0;
  cin>>a>>b>>c;
  for(int i=0;i<c;i++)
  {
    if(b-a>=0)
    {
      ans++;
      b-=a;
    }
    else break;
  }
  cout<<ans;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int scoring(int score , int choose, int day, vector<int> &c,vector<vector<int>> &s,vector<int> last){
    //--choose;
    score += s[day][choose];
    int hiku = 0;
    rep(i,26){
        hiku += c[i]*(day - last[i]);
    }
    score -= hiku;
    return score;
}

//ミョ(-ω- ?)
int main() {
    int d;
    cin >> d;
    const int n = 26;
    vector<int> c(n,0);
    rep(i,n)cin >> c[i];
    vector<vector<int>> s(365,vector<int>(n,0));
    rep(i,d)rep(j,n)cin >> s[i][j];
    vector<int> last(n,0);
    int score = 0;
    rep(i,d){
        int res = 0;
        ll max_score = LONG_LONG_MIN;
        rep(j,n){
            int ch = scoring(score,j,i,c,s,last);
            if(max_score < ch){
                res = j;
                max_score = ch;
            }
            if(i > 52)cerr << ch << " " << i << "日" << j << "選択" << endl;
        }
        cout << res + 1 << endl;
        last[res] = i+1;
        score = max_score;
    }
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long n;
  cin >> n;
  for (long i = sqrt(n) + 1; i > 0; i--) {
    if (!(n % i)) {
      cout << to_string(n / i).length() << '\n';
      return 0;
    }
  }
}


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

#define REP(i, n) for(int i=0; i<n; i++)
#define REPA(i, a, n) for(int i=a; i<n; i++)
#define REPE(i, a, n) for(int i=a; i<=n; i++)
#define SetArray(a, n) for(int array_i=0; array_i<n; array_i++) cin >> a[array_i]
#define print(x) cout << x
#define printw(x) cout << x << " "
#define println(x) cout << x << endl
#define printl() cout << endl
#define sqr(x) (x)*(x)
#define cube(x) (x)*(x)*(x)
typedef long long ll;
typedef unsigned int uint;
typedef vector<int> vi;

int main(){
    char a;
    cin >> a;

    if(a >= 'a' && a <= 'z')
        println('a');
    else
        println('A');

    return 0;
}




Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;


signed main(){
    
    while(1){
    vector<pair<int, char>> vp(5);
    vp[0].second = 'A';   
    vp[1].second = 'B';   
    vp[2].second = 'C';   
    vp[3].second = 'D';   
    vp[4].second = 'E';
    bool flag = true;
    for(int i = 0; i < 5; i++){
        int a, b; cin >> a >> b;
        if(a == 0 and b == 0){
            flag = false;
            break;
        }
        vp[i].first = a + b;
    }

    if(flag == false) break;

    sort(vp.rbegin(), vp.rend());
    cout << vp[0].second << " " << vp[0].first << endl;
    }
    return 0;
}




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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

int main() {
  string s; cin >> s;
  int n = s.size();
  int k = s.size();
  FOR(i, 1, n) {
    if (s[i] != s[i-1]) {
      chmin(k, max(i, n-i));
    }
  }
  cout << k << endl;
  return 0;
}

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

#define endl "\n"

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

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

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

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int X, A, B; cin >> X >> A >> B;

    if (B <= A) cout << "delicious" << endl;
    else if (B > A+X) cout << "dangerous" << endl;
    else cout << "safe" << endl;
  
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(){
    long long sum;
    long long N;
    cin >> N;
    long long tmp = N/15;
    
    sum = N*(1+N)/2;
    sum -= tmp*(60+60+105*(tmp-1))/2;

    for(int i=N/15*15+1; i<=N; ++i){
        if(i%3==0||i%5==0){
            sum -= i;
        }
    }
    cout <<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define vi vector<long long>
#define vvi vector<vector<long long>>
int main(void){
  int H, A;
  cin >> H;
  cin >> A;
  int q = H/A;
  int r = (H%A == 0)?(0):(1);
  cout << q+r;
  return 0;
}

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

int main() {
  int x,y,z,count = 1;
  cin >> x >> y >> z;
  x -= y + z + z;
  while(x >= 0){
    x -= y + z;
    count++;
  }
  cout << count - 1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

#define SIZE 300000
#define INF 1000000000

int blockState[SIZE];
int blockL[SIZE], blockR[SIZE];
int item[SIZE];
int rN;

void applyBlock(int id, int x) {
  if (blockState[id] == 0) {
    blockL[id] = blockR[id] = x;
    blockState[id] = 1;
  }
  else if (blockState[id] == 1) {
    if (blockR[id] + 1 == x)
      blockR[id] = x;
    else
      blockState[id] = 2;
  }
}

void applyNode(int pos, int x) {
  int id = pos / rN;
  int l = id * rN;
  int r = (id + 1) * rN;

  if (blockState[id] == 1) {
    for (int i=l; i<r; i++) {
      if (item[i] + 1 == blockL[id])
        item[i] = blockR[id];
      else
        item[i] = INF;
    }
    blockState[id] = 0;
  }

  if (blockState[id] == 2) {
    for (int i=l; i<r; i++)
      item[i] = INF;
    blockState[id] = 0;
  }

  if (x == -1) return;

  if (item[pos] + 1 == x) {
    item[pos] = x;
  } else {
    item[pos] = INF;
  }
}

int main() {
  int N, K, T;

  scanf("%d%d%d", &N, &K, &T);

  rN = sqrt(N);

  int blockSize = (N + rN-1) / rN;

  for (int i=0; i<blockSize; i++) {
    blockL[i] = -1;
    blockR[i] = -1;
  }

  for (int i=0; i<T; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    l--;

    //[l, r)
    for (int i=l; i<(l/rN+1)*rN; i++)
      if (i < r)
        applyNode(i, x);

    for (int i=r/rN*rN; i<r; i++)
      if (i >= (l/rN+1)*rN)
        applyNode(i, x);

    for (int i=l/rN+1; i<r/rN; i++)
      applyBlock(i, x);
  }

  for (int i=0; i<blockSize; i++)
    applyNode(i*rN, -1);

  int ans = 0;

  for (int i=0; i<N; i++)
    ans += item[i] == K;

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

  return 0;
}



Measured memory_bytes: 4008
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

vector<int> a(3);


int main (){
    cin >> a[0] >> a[1] >> a[2];
    sort(All(a));
    int sa = a[2]-(a[0]+a[2]-a[1]);
    int ans = a[2]-a[1]+sa/2;
    if(sa%2 == 1) ans += 2;
    cout << ans << "\n";
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Many Kinds of Apples
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N = parseInt(br.readLine());
		int[] c = new int[N + 1];
		int[] a = new int[N + 1];

		StringTokenizer st = new StringTokenizer(br.readLine());

		for (int i = 1; i <= N; i++) {
			c[i] = parseInt(st.nextToken());
		}

		int Q = parseInt(br.readLine());
		int ans = 0;
		for (int i = 0; i < Q; i++) {
			st = new StringTokenizer(br.readLine());

			int t = parseInt(st.nextToken());
			int x = parseInt(st.nextToken());
			int d = parseInt(st.nextToken());

			if (t == 1) {
				a[x] += d;
			} else {
				a[x] -= d;
			}

			if (a[x] < 0 || a[x] > c[x]) {
				ans = x;
				break;
			}
		}

		System.out.println(ans);
	}
}



Measured memory_bytes: 55812
// I saw tourist's code.

#include<bits/stdc++.h>

using namespace std;

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

    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(x[i] > y[i]){
            ans += 2 * (x[i] - y[i]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1412
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<functional>

using namespace std;

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

	int a,b,c,k;
	cin >> a >> b >> c >> k;
	
	long long m = max(max(a,b),c);
	int rest = a+b+c-m;

	for(int i=0;i<k;i++){
		m *= 2;
	}
	cout << m+rest << "\n";

	return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
degree = 0
degree += 30 * h
degree -= 6 * m
degree += 0.5 * m
degree = math.radians(degree)
ans = a**2 + b**2 - 2 * a * b * math.cos(degree)
print(math.sqrt(ans))

Measured memory_bytes: 9448
# -*- coding: utf-8 -*-
N, M, C = map(int, input().split())
B_list = list(map(int, input().split()))

number = 0
for i in range(N):
    source_list = list(map(int, input().split()))
    judge = 0
    for i in range(M):
        judge += source_list[i] * B_list[i]
    judge += C
    if judge > 0:
        number += 1
print(number)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    char b, c;
    scanf("%c", &b);

    if (b == 'A'){
        c = 'T';
    }else if(b == 'C'){
        c = 'G';
    }else if(b == 'G'){
        c = 'C';
    }else if(b == 'T'){
        c = 'A';
    }

    // 出力
    printf("%c\n", c);
    return 0;
}

Measured memory_bytes: 128
/*
 * main.c
 *
 *  Created on: 2019/03/09
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// unsigned long long int A[100001] = {0}; // price
// unsigned long long int B[100001] = {0}; // limit

typedef struct {
	unsigned long long int A;
	int B;
} DRINKDT_t;

DRINKDT_t a[100001] = {0};

int sort_inc(const void *a, const void *b)
{
	DRINKDT_t *pa = (DRINKDT_t*)a;
	DRINKDT_t *pb = (DRINKDT_t*)b;
	unsigned long long int da = pa->A;
	unsigned long long int db = pb->A;

	return (int)(da -db);
}

int main()
{
	int N, M;
	unsigned long long int tempa;
	int tempb;
	int i = 0;
	unsigned long long int min = 0;
	int remain = 0;

	scanf("%d %d", &N, &M);
	for(i = 0; i < N; i++) {
		scanf("%llu %d", &tempa, &tempb);
		a[i].A = tempa;
		a[i].B = tempb;
	}
	qsort(a, N, sizeof(DRINKDT_t), sort_inc);
	remain = M;
	for(i = 0; i < N; i++) {
		if(remain > a[i].B) {
			min += a[i].A * a[i].B;
			remain -= a[i].B;
		} else {
			min += a[i].A * remain;
			break;
		}
	}

    printf("%llu\n",min);
	return 0;
}


Measured memory_bytes: 3324
// atcoder/abc153/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "("; each (i, s) os << i << ","; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "("; each (i, m) os << i << ","; os << ")"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> swap(pair<P, Q> p) { return make_pair(p.second, p.first); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  lli d, a;
  while (cin >> n >> d >> a) {
    vector<pair<lli, lli>> v(n);
    cin >> v;

    const int D = 0;
    const int E = 1;
    priority_queue<vector<lli>> q; // (position, type, paramater)
    each (i, v) {
      q.push(vector<lli>({-i.first, E, i.second}));
    }

    lli cnt = 0;
    lli sum = 0;
    while (q.size()) {
      vector<lli> u = q.top();
      q.pop();
      if (u[1] == E) {
        if (sum < u[2]) {
          lli req = u[2] - sum;
          lli x = (req / a) + bool(req % a);
          cnt += x;
          sum += a * x;
          q.push(vector<lli>({u[0] - d * 2, D, -(x * a)}));
        }
      }
      if (u[1] == D) {
        sum += u[2];
      }
    }
    cout << cnt << endl;
  }

  return 0;
}


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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<int> a(N);
    int div2 = 0, div4 = 0, div = 0;

    REP (i, 0, N) {
        cin >> a[i];
        if (a[i] % 4 == 0) {
            div4++;
        } else if(a[i] % 2 == 0) {
            div2++;
        } else {
            div++;
        }
    }
    if (div2 >= 1) {
        cout << (div <= div4 ? "Yes" : "No") << endl;
    } else {
        cout << (div - 1 <= div4 ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 640