akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

long long N;

int main(){
  cin >> N;
  unsigned long long ans = 0;
  if(N % 2 == 1){
    cout << 0 << endl;
    return 0;
  }else{ 
    long long div = 10;
    while(div <= N){
      ans += N / div;
      div *= 5;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using static System.Console;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        var ue = ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var shita = ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var list = new List<int>();
        int c = 0;
        for (int i = 0; i < N; i++)
        {
            var u = 0;
            var s = 0;
            for (int k = 0; k <= c; k++) u += ue[k];
            for (int j = c; j < N; j++) s += shita[j];

            list.Add(u + s);
            c++;
        }
        WriteLine(list.Max());
    }
}

Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int n,h[2001],ans;
bool check(int x)
{
    for(int i=x-1;i>=1;i--)
    {
        if(h[i]>h[x])return 0;
    }
    return 1;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];
    for(int i=1;i<=n;i++)ans+=check(i);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    char[] w = scanner.next().toCharArray();
    int[] freq = new int[26];
    for (char ch : w) freq[ch - 'a']++;
    if (Arrays.stream(freq).allMatch(i -> i % 2 == 0)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 27092
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>

using namespace std;

int main() {
	double r;
	cin >> r;
	cout <<fixed<<setprecision(15)<< r*r*M_PI<< " " <<fixed<<setprecision(15)<< 2 * r*M_PI << endl;
}

Measured memory_bytes: 1288
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    in >> n;
    ll ans = 1;
    REP(i, 8){
        if (pow(2, i) <= n){
            ans = pow(2, i);
        }
    }
    out << ans << endl;
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace agc26_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int cnt=0;

            for(int i=1; i<n; i++){
                if(input[i] == input[i-1]){
                    cnt++;
                    input[i] = i*-1;
                }
            }

            WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner

object Main {

  def solve(A: Int, B: Int) = {
    if (A > B) paint(B, '#', A, '.')
    else paint(A, '.', B, '#')
  }

  def paint(base: Int, baseC: Char, dot: Int, dotC: Char): Unit = {
    val panel = Array.fill[Char](100, 100)(baseC)
    val walls = Array((0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (1, 2), (0, 2), (0, 1))

    (0 until dot) foreach { i =>
      val w = (i  % 24) * 4 + 1
      val h = (i / 24) * 4 + 1
      panel(w)(h) = dotC
    }

    (0 until base - 1) foreach { i =>
      val w = (i  % 24) * 4 + 1
      val h = (i / 24) * 4 + 1
      walls.indices foreach { j =>
        val (dw, dh) = walls(j)
        panel(w + dw)(h + dh) = dotC
      }
    }

    println(s"100 100")

    (0 until 100) foreach { h =>
      (0 until 100) foreach { w =>
        print(panel(w)(h))
      }
      println()
    }
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val A = sc.nextInt()
    val B = sc.nextInt()
    solve(A, B)
  }
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<char> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int cnt=0;
	for (int i=1;i<n;i++)
	{
		cnt+=(a[i]!=a[i-1]);
	}
	cout<<min(n-1,n-1-cnt+2*k);
	return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline #高速化期待
from collections import deque

def main():
    N = int(input())
    A = [deque()] + [deque( map( int, input().split())) for _ in range(N)]
    NOW = [0]*(N+1)
    Days = [0]*(N+1)
    q = deque( [ i+1 for i in range(N)])
    while q:
      i = q.popleft()
      if not A[i]:
        continue
      
      a = A[i].popleft()
      
      if NOW[a] == i:
        NOW[a] = 0
        Days[a] = Days[i] = max((Days[i], Days[a])) + 1
        q.append(i)
        q.append(a)
      else:
        NOW[i] = a
    for i in range(N+1):
      if A[i]:
        print(-1)
        return
    print(max(Days))
if __name__ == '__main__':
    main()

Measured memory_bytes: 38140
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

string s[100];
long long int t[100];

int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> s[i] >> t[i];
	}
	string X;
	cin >> X;
	long long int ans = 0;
	bool flag = false;
	for(int i = 0; i < N; i++){
		if(flag){
			ans += t[i];
		}
		if(s[i] == X){
			flag = true;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    vector<int> L(N);
    for(auto &l:L) cin>>l;
    sort(L.begin(), L.end());
    int s=0;
    for(int i=0;i<N-1;i++) s+=L[i];
    if(s>L[N-1]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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


int main(){
    int n;
    cin >> n;
    vector<vector<int>>a(4, vector<int>(13));
    char m;
    int b;
    for(int i=0; i<n; i++){
        cin >> m >> b;
        if(m=='S'){
            a[0][b-1]=b;
        }
        else if(m=='H'){
            a[1][b-1]=b;
        }
        else if(m=='C'){
            a[2][b-1]=b;
        }
        else{
            a[3][b-1]=b;
        }        
    }

    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            if(a[i][j]==0){
                if(i==0){
                    cout << 'S' << " " << j+1 << endl;
                }
                else if(i==1){
                    cout << 'H' << " " << j+1 << endl;
                }
                else if(i==2){
                    cout << 'C' << " " << j+1 << endl;
                }  
                else{
                    cout << 'D' << " " << j+1 << endl;
                }                              
            }

        }
    }

}
	


Measured memory_bytes: 3156
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int L;
i64 A[202020];

i64 dp[202020][4][3];

i64 myabs(i64 x) { return max(x, -x); }

int main()
{
	scanf("%d", &L);
	for (int i = 0; i < L; ++i) scanf("%lld", A + i);

	for (int t = 0; t <= L; ++t) for (int i = 0; i < 4; ++i) for (int j = 0; j < 3; ++j) dp[t][i][j] = 1LL << 60LL;

	dp[0][2][0] = 0;

	for (int i = 0; i < L; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (dp[i][j][k] >= (1LL << 50LL)) continue;
			//	printf("%d %d %d %lld\n", i, j, k, dp[i][j][k]);
				i64 cand[] = { 0, A[i], A[i] + 1, A[i] + 2 };
				for (int l = 0; l < 4; ++l) {
					i64 c = cand[l];
					
					int j2;
					if (j == 3 && c != 0) continue;
					else if (j <= 1 && c == 0) j2 = 3;
					else if (j <= 1 || (j == 2 && c != 0)) j2 = c % 2;
					else j2 = j;

					int k2 = k;
					if (j != 3 && j % 2 != c % 2) ++k2;
					if (k2 >= 3) continue;

					dp[i + 1][j2][k2] = min(dp[i + 1][j2][k2], dp[i][j][k] + myabs(c - A[i]));
				}
			}
		}
	}

	i64 ret = 1LL << 60LL;
	for (int i = 0; i <= 3; ++i) {
		for (int j = 0; j <= 2; ++j) {
			int j2 = (i == 1 ? 1 : 0) + j;
			//printf("%d %d %lld\n", i, j2, dp[L][i][j]);
			ret = min(ret, dp[L][i][j]);
		}
	}
	printf("%lld\n", ret);
	return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;


int solve(){
    cin>>n>>m;
    if(n==m) cout<<"Yes";
    else cout<<"No";    
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 256
def aux(x,ans,b):
    if x == 0:
        return(' '.join(map(str,ans)))
    elif x % 2 == 1:
        return(aux(x//2, ans+[b],b*2))
    else:
        return(aux(x//2, ans, b*2))

while True:
    try:
        x = int(input())
        print(aux(x,[],1))
    except EOFError:
        break

Measured memory_bytes: 7644
import java.util.*;

class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    
    int K = sc.nextInt();
    String S = sc.next();
    
    if(S.length() > K){
      System.out.println(S.substring(0,K) + "...");
    }else{
      System.out.println(S);
    }
  }
}

Measured memory_bytes: 38656
from collections import deque

h, w = map(int, input().split())
a = [input() for _ in range(h)]
r = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == '.':
      b = list(map(list, a))
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        for di in range(-1, 2):
          i1 = i + di
          if 0 <= i1 < h:
            for dj in range(di % 2 - 1, 2, 2):                
              j1 = j + dj
              if 0 <= j1 < w and b[i1][j1] == '.':
                b[i1][j1] = b[i][j] + 1
                q.append((i1, j1))
print(r)


Measured memory_bytes: 3444
from itertools import accumulate

def run_length(data, init):
    tmp = init
    cnt = 0
    length = []
    for c in data:
        if tmp != c:
            length.append(cnt)
            cnt = 0
        tmp = c
        cnt += 1
    length.append(cnt)
    return length

n,k = map(int, input().split())
s = input()
length = run_length(s, '')
if s[0] == '0':
    acc = [0] + list(accumulate(length))
else :
    acc = list(accumulate(length))
acc.append(acc[-1])

ans = acc[0]
if k * 2 + 1 > len(acc)-2:
    k = (len(acc)-2) // 2
# print(k)
for i in range(0, n, 2):
    # print(i)
    if i + k * 2 + 1 >= len(acc):
        break
    if ans < acc[i + k * 2 + 1] - acc[i]:
        ans = acc[i + k * 2 + 1] - acc[i]
print(ans)
# print(acc)


Measured memory_bytes: 8820
use std::vec::Vec;
use std::cmp::*;
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let s: HashSet<char> = read::<String>().chars().collect();
  let a: Vec<char> = "abcdefghijklmnopqrstuvwxyz".chars().collect();

  for x in &a {
    if !s.contains(x) {
      println!("{}", x);
      return;
    }
  }
  println!("None");
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, l; cin >> n >> l;
  int su = 0;
  for(int i=1;i<=n;++i) {
    su += l + i - 1;
  }
  if(l > 0) {
    su -= l;
  } else if(l + n - 1 < 0) {
    su -= l + n - 1;
  }
  cout << su << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int x, t;
  cin >> x;
  if(x/10==9 || x%10==9) co("Yes");
  else co("No");
  
  return 0;
}


Measured memory_bytes: 256
#ABC127C-Prison.py

from sys import stdin

input = stdin.readline

N, M = list(map(int, input().split()))

L = []
R = []

for i in range(M):
    l, r = input().split()
    L.append(int(l))
    R.append(int(r))

maxL = max(L)
minR = min(R)


if maxL <= N and maxL <= minR:
    if N >= minR:
        print(minR-maxL+1)
    else:
        print(N-maxL+1)
else:
    print(0)


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

int main()
{
   int n;
   string s;
   set<int>s1;
   vector<string>v;
   set<int>::iterator it;
   set<string>s2;
   set<string>::iterator i1;
   map<string,int>mp;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>s;
       v.push_back(s);
       s1.insert(mp[s]);
       mp[s]++;
   }
   mp.clear();
   it=s1.end();
   it--;
   for(int i=0;i<n;i++)
   {
       if(mp[v[i]]==*it)
        s2.insert(v[i]);
       mp[v[i]]++;
   }
   for(i1=s2.begin();i1!=s2.end();i1++)
    cout<<*i1<<endl;
}


Measured memory_bytes: 40696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

double d;

int main() {
	cin >> d;
	int num = d;
	printf("%.10lf\n", max(d*sqrt(2), (double)num + 1));
}

Measured memory_bytes: 3284
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l.at(i);
    }
    int sum = 0;
    int count = 0;
    for (int i = 0; i < n; i++) {
        sum += l.at(i);
        count++;
        if (sum > x) goto last;
        if ( i == n - 1) count++;
    }
    last:
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    for(int i=0;i<5;i++)
    {
        cin>>x;
        if(!x)
        {
            y=i+1;
        }
    }
    cout<<y<<endl;


}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  vector<int>v;
  int s1,s2,ans;
  ans=999999999;
  cin >> n;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  s1=accumulate(v.cbegin(),v.cend(),0);
  s2=0;
  for(auto z:v){
    if(s1>s2){
      if(ans>s1-s2)
        ans=s1-s2;
    }
    else{
      if(ans>s2-s1)
        ans=s2-s1;
    }
    s2+=z;
    s1-=z;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
const int mod = INF;
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define f first
#define s second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
#define int long long
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

const int mx = 100000;



int32_t main()
{
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)cin >>v[i];
    int res = 0;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        res^=v[i];

    }
   cout<<((!res)?"Yes":"No");

   
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
  
int main()
{
	int m, n, l;
	long c;
	cin >> n >> m >> l;
	int *a = new int[n * m];
	int *b = new int[m * l];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i * m + j];
	for (int i = 0; i < m; i++)
		for (int j = 0; j < l; j++)
			cin >> b[i * l + j];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < l; j++) {
			c = 0; 
			for ( int k = 0; k < m; k ++) 
				c += a[i * m + k] * b[l * k + j];
			cout << c;
			if (j < l -1)
				cout << ' ';
			else
				cout << endl;		
		}
	delete [] a;
	delete [] b;
    return 0;
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::vector<ll> x) {
  int i = 0;
  while (true) {
    if (x.at(i) == 0) break;
    i++;
  }
  cout << i + 1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::vector<ll> x(5);
  for (int i = 0; i < 5; i++) {
    scanf("%lld", &x[i]);
  }
  solve(std::move(x));
  return 0;
}


Measured memory_bytes: 3668
N,Q = map(int,input().split())
ans = (N-2)**2
H = [N for i in range(N+1)]
W = [N for i in range(N+1)]

last_ignored_H= N
last_ignored_W=N

ignoredH = [False for i in range(N+1)]
ignoredH[N] = True

ignoredW=[False for i in range(N+1)]
ignoredW[N] = True

for i in range(Q):
    command ,where = map(int,input().split())
    if command == 1:
        
        if ignoredH[where] == True:
            ans -=H[where] - 2
            continue
            
        elif ignoredH[where] == False:
            H[where] = last_ignored_W
            ans -=H[where] - 2
            for j in range(where,last_ignored_H):
                ignoredH[j] = True
                H[j] = H[where]
            last_ignored_H = where
  
  
    else:
        
        if ignoredW[where] == True:
            ans -=W[where] - 2
            continue
        elif ignoredW[where] == False:   
            W[where] = last_ignored_H
            ans -=W[where] -2
            for j in range(where,last_ignored_W):
                ignoredW[j] = True
                W[j] = W[where]
            last_ignored_W = where
            
print(ans)


Measured memory_bytes: 101756
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
const long long INF = 1e9+7;

int main()
{
	int N, W; cin >> N >> W;
	const int MAX_V = 100100;
	vector<int> weight(N), value(N);
	for(int i = 0; i < N; i++){
		cin >> weight[i] >> value[i];
	}
  
	vector<vector<ll>> dp(N+1, vector<ll>(MAX_V, INF));
	dp[0][0] = 0;
	for(int i = 0; i < N; i++){
		//dp[i][sum_v]...i-1番目までから価値がsum_vを超えないように選んだ重さの最小値
		for(int sum_v = 0; sum_v < MAX_V; sum_v++){
			if(sum_v - value[i] >= 0){ //i番目を選ぶとき
				chmin(dp[i+1][sum_v], dp[i][sum_v-value[i]] + weight[i]);
			}

			//選ばないとき
			chmin(dp[i+1][sum_v], dp[i][sum_v]);
		}
	}		

	ll ans = 0;
	for(int i = 0; i < MAX_V; i++){
		if(dp[N][i] <= W) ans = i; //N個までの重さがWを超えない価値の最大値を取りたい
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 80256
n, a, b = map(int, input().split())
mod = 1000000007
def inv(y, mod):
    return pow(y, mod - 2, mod)

def comb(n, a, mod):
    x = 1
    y = 1
    for i in range(a):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    return (x * inv(y, mod)) % mod
    
print((pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)


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

template<typename NodeIdx,typename Cost>
vector<Cost> bellman_ford(vector<tuple<NodeIdx,NodeIdx,Cost>> &graph, NodeIdx n_node , NodeIdx start_idx){
    using Edge = tuple<NodeIdx,NodeIdx,Cost> ;
    const Cost INF = numeric_limits<Cost>::max();
    vector<Cost> d(n_node,INF);
    d[start_idx] = 0;
    while(true){
        bool update =false;
        for (const Edge &e : graph){
            if (d[get<0>(e)] != INF && d[get<1>(e)] > d[get<0>(e)] + get<2>(e) ){
                d[get<1>(e)] = d[get<0>(e)] + get<2>(e);
                update =true;
            }
        }
        if (!update) break;
    }
    return d;
    
}


int main(){
    ll V,E,r ;
    cin >> V>> E >> r;
    vector<tuple<ll,ll,ll>> graph;
    for (ll i=0;i<E;i++){
        ll v1,v2,c;
        cin >> v1 >> v2 >> c;
        graph.push_back(make_tuple(v1,v2,c));
    }
    vector<ll> ret = bellman_ford<ll,ll>(graph,V,r);
    for (const auto &c:ret){
        if (c == numeric_limits<ll>::max()) printf("INF\n");
        else printf("%lld\n",c);
    }

}


Measured memory_bytes: 15072
#include <cstdio>

using namespace std;

long long a[50];

int main() {
    int n, i, j;
    long long ans = 0;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%lld", &a[i]);
    
    while (1) {
        int f = 0;
        
        for (i = 0; i < n; i++) {
            if (a[i] >= n) {
                long long x = a[i] / n;
                
                f = 1;
                ans += x;
                
                for (j = 0; j < n; j++) {
                    if (j == i) {
                        a[j] -= x * n;
                    } else {
                        a[j] += x;
                    }
                }
            }
        }
        
        if (f == 0) break;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int fibonacci(int);

int main(){
  int k;
  scanf("%d", &k);
  printf("%d\n", fibonacci(k));
  return 0;
}

int fibonacci(int n){
  int i;
  int F[n];
  F[0] = 1;
  F[1] = 1;
  for(i = 2; i <= n; i++) F[i] = F[i - 2] + F[i - 1];
  return F[n];
}



Measured memory_bytes: 2104
import java.util.*;

public class Main {
  static int n, m, q;
  static int[] a;
  static int score[][];
  static int res;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    m = sc.nextInt();
    q = sc.nextInt();
    a = new int[n];
    score = new int[q][4];
    res = 0;

    for (int i = 0; i < q; i++) {
      for (int j = 0; j <= 3; j++){
        score[i][j] = sc.nextInt();
      }
    }

    for (int i = 1; i <= m; i++) {
      cal(0, i);
    }

    System.out.println(res);
  }

  static void cal(int ind, int num) {
    if (ind == n) {
      int pt = 0;
      for (int i = 0; i < q; i++) {
        if (a[score[i][1] - 1] - a[score[i][0] - 1] == score[i][2]) pt += score[i][3];
      }
      res = Math.max(res, pt);
      return;
    }

    a[ind] = num;

    for (int i = num; i <= m; i++) {
      cal(ind+1, i);
    }
  }
}

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

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

int main() {
  long long  a,b;
  cin >> a >> b;
  long long ans = 1;
  ll g = gcd(a,b);
  for(int i=2;i <= sqrt(g);i++){
    if(g%i == 0){
      ans++;
      while(g%i == 0){
        g /= i;
      }
    }
  }
  
  if(g>1){
    ans++;
  }

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


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

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::vector<int> num(n, 0);

    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;

        a--;
        b--;

        num[a]++;
        num[b]++;
    }

    for (auto elem : num) {
        std::cout << elem << std::endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    string s, t; cin >> s >> t;

    int ans = 2 * N;
    for (int i = 0; i < N; ++i) {
        string s_right {s.substr(i)};
        string t_left {t.substr(0, N-i)};
        if ( s_right == t_left ){
            ans = i + N;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
int i;
int R;
int D;
int X;

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

	cin >> R;
	cin >> D;
	cin >> X;

	for( i = 1; i <= 10; i++ )
	{
		X = R * X - D;

		cout << X << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],ans=n,num=0,idx=0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
    	while((num^a[i])!=num+a[i]){
    		num-=a[idx];
    		idx++;
    	}
    	ans+=i-idx;
    	num+=a[i];
    }
    cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(void) {
    int a, b, c, x, ans, t;
    cin >> a >> b >> c >> x;
    ans = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                t = 500 * i + 100 * j + 50 * k;
                if(t == x){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()[::-1]
 
cnt = [0] * 2019
cnt[0] = 1
total = 0
x = 1
ans = 0
 
for a in S:
    total += int(a) * x
    total %= 2019
    cnt[total] += 1
    x = x*10
    x %= 2019
 
for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2
 
print(ans)

Measured memory_bytes: 9372
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll INF = 1e9 + 10 ;
int main(){
    fastio 
    ll n , k ; 
    cin >> n >> k ; 
    vector<ll> v(n);
    ll sum = 0 ; 
    vector<ll> cnt(41) ; 
    for(ll i = 0; i < n; i++){
        cin >> v[i] ; 
        for(ll j = 0; j < 41; j++){
            if ( v[i] & (1LL << j) ) cnt[j]++;
        }
        sum += v[i] ; 
    }
    debug() << imie(cnt) ; 
    ll t = 0 ; 
    for(ll i = 40; i >= 0; i--){
        ll x = (1LL << i) ; 
        if ( x <= k ){
            if ( cnt[i] == 0 || n - cnt[i] > cnt[i] ){
                t += x;
                k -= x;
            }
        }
    }
    ll ans = 0 ; 
    for(ll i = 0; i < n; i++){
        ans += t ^ v[i] ; 
    }
    cout << max(sum, ans) << endl ; 
    return 0 ;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <cmath>
#define LL long long
#define INF 100000000000000000

using namespace std;

int main(void){
  LL N;
  cin >> N;

  //N = p*qとなるp, qのうち，p+qが最小になるようなものを求めればよい
  LL min = INF;
  LL p, q;
  for(LL i=1; i<=sqrt(N); i++){
    if(N%i == 0){
      //p*q = Nとなるp, qの定義
      p = i;
      q = N/i;
      //p+qの最小値を更新していく
      if( p + q < min)
	min = p + q;
    }
  }

  //(1, 1)が初期値なので2を引いて出力
  cout << min - 2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#sequence
n=int(input())
lists=list(map(int,input().split()))
a=0
sum1=0
#奇数番目の項が-,偶数番目の項が＋の場合の最小値
for i in range(n):
    sum1+=lists[i]
    if i%2==0:
        if sum1>=0:
            a+=(sum1+1)
            sum1=-1
        elif sum1<0:
            pass
    elif  i%2!=0:
        if sum1<=0:
            a+=(1-sum1)
            sum1=1
        elif sum1>0:
            pass

b=0
#奇数番目の項が＋、偶数番目の項が−の場合の最小値
sum2=0
for i in range(n):
    sum2+=lists[i]
    if i%2!=0:
        if sum2>=0:
            b+=(sum2+1)
            sum2=-1
        elif sum2<0:
            pass
    elif  i%2==0:
        if sum2<=0:
            b+=(1-sum2)
            sum2=1
        elif sum2>0:
            pass
print(min(a,b))

Measured memory_bytes: 14468
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
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;}

int main() {
    string s, t;
    cin >> s >> t;
    ll ls = s.size(), lt = t.size();
    ll MAX = 3100;
    ll dp[MAX][MAX] = {0};
    rep(i, ls) {
        rep(j, lt) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else {
                chmax(dp[i+1][j+1], dp[i][j+1]);
                chmax(dp[i+1][j+1], dp[i+1][j]);
            }
        }
    }

    string ans = "";
    ll i = (ll)s.size(), j = (ll)t.size();
    while(i > 0 && j > 0) {
        if (dp[i][j] == dp[i-1][j]) i--;
        else if (dp[i][j] == dp[i][j-1]) j--;
        else {
            ans = s[i-1] + ans;
            i--;
            j--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 75264
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let n: usize = s.len();

    for i in (2..n) {
      if i % 2 == 0 && check(&s, n, i) {
        println!("{}", n - i);
        return
      }
    }
}


fn check(v: &Vec<char>, n: usize, i: usize) -> bool {
  let n: usize = (n - i) / 2;

  for j in 0..n {
    if v[j] != v[j + n] {
      return false;
    }
  }

  return true;
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    SS = raw_input()
    T = raw_input()
    S = ""
    start_index = -1
    end_index = -1
    t_index = 0
    state = 0
    if len(T) > len(SS):
        S = 'UNRESTORABLE'
    else:
        for index in range(len(SS) - len(T), -1, -1):
            for current_index in range(index, index + len(T)):
                if SS[current_index] == '?' or SS[current_index] == T[t_index]:
                    t_index += 1
                    if t_index == len(T):
                        start_index = index
                        end_index = current_index
                        state = 1
                        break
                else:
                    t_index = 0
                    break
            if state == 1:
                break
        if start_index == -1:
            S = 'UNRESTORABLE'
        else:
            for index, s in enumerate(SS):
                if index >= start_index and index <= end_index:
                    S += T[index - start_index]
                elif s == '?':
                    S += 'a'
                else:
                    S += s
    print S


Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int N;

int main(){
	while(cin >> N){
		int d = N%10; N /= 10;
		int c = N%10; N /= 10;
		int b = N%10; N /= 10;
		int a = N%10;
		if(a+b+c+d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
		else if(a+b+c-d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
		else if(a+b-c+d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
		else if(a-b+c+d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
		else if(a+b-c-d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
		else if(a-b-c+d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
		else if(a-b+c-d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
		else if(a-b-c-d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        int N = S.Length;
        int minCount = int.MaxValue;
        for(int i = 0; i < 2; i++)
        {
            int digitValue = i;
            int count = 0;
            foreach(var ch in S)
            {
                if(digitValue.ToString() != ch.ToString())
                {
                    count++;
                }
                digitValue = (digitValue + 1) % 2;
            }
            minCount = Math.Min(count, minCount);
        }

        Console.WriteLine(minCount);
    }

}



Measured memory_bytes: 15328
#include<stdio.h>

int main(){
  int i,a[200001]={},n,p,cnt=1,max=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&p);
    a[p]=i;
  }
  for(i=1;i<n;i++){
    if(a[i]<a[i+1])
      cnt++;
    else{
      if(max<cnt)
        max=cnt;
      cnt=1;
    }
  }
  if(max<cnt)
    max=cnt;
  printf("%d\n",n-max);
}

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

int main(){
    FILE*fi,*fout;
    long long n,a,b;
    //fi=fopen("A.in" ,"r");
    //fout=fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%lld%lld%lld" ,&n,&a,&b);
    if((n-1)*b+a-((n-1)*a+b)+1<=0)
      fprintf(fout,"0\n");
    else
      fprintf(fout,"%lld\n" ,(n-1)*b+a-((n-1)*a+b)+1);
    //fclose(fi);
    //fclose(fout);
}


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

int main() {
  int c[4][4];
  for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) cin >> c[i][j];

  int a1, a2, a3;
  int correct = 0;
  for (a1 = 0; a1 <= 100; a1++) {
    for (a2 = 0; a2 <= 100; a2++) {
      for (a3 = 0; a3 <= 100; a3++) {
        int b1_1 = c[1][1] - a1; int b1_2 = c[2][1] - a2; int b1_3 = c[3][1] - a3;
        int b2_1 = c[1][2] - a1; int b2_2 = c[2][2] - a2; int b2_3 = c[3][2] - a3;
        int b3_1 = c[1][3] - a1; int b3_2 = c[2][3] - a2; int b3_3 = c[3][3] - a3;

        if (b1_1 == b1_2 && b1_2 == b1_3 &&
          b2_1 == b2_2 && b2_2 == b2_3 &&
          b3_1 == b3_2 && b3_2 == b3_3) correct = 1;
      }
    }
  }

  if (correct) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			Map<String, Integer>[] supers = new Map[n];
			for (int i = 0; i < n; i++)
				supers[i] = new HashMap<String, Integer>();
			Map<String, Integer> min = new HashMap<String, Integer>();
			for (int i = 0; i < n; i++) {
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					String name = scanner.next();
					int value = scanner.nextInt();
					supers[i].put(name, value);
					if (!min.containsKey(name) || min.get(name) > value)
						min.put(name, value);
				}
			}
			int q = scanner.nextInt();
			String[] name = new String[q];
			for (int i = 0; i < q; i++)
				name[i] = scanner.next();
			int m = scanner.nextInt();
			List<Point>[] lists = new List[n + 1];
			for (int i = 0; i <= n; i++)
				lists[i] = new ArrayList<Main.Point>();

			while (m-- > 0) {
				int s = scanner.nextInt();
				int t = scanner.nextInt();
				int d = scanner.nextInt();
				lists[s].add(new Point(t, d));
				lists[t].add(new Point(s, d));
			}
			int sum = 0;
			for (int i = 0; i < q; i++) {
				if (!min.containsKey(name[i])) {
					System.out.println("impossible");
					continue loop;
				}
				sum += min.get(name[i]);
			}
			int[][] dp = new int[n + 1][1 << q];
			for (int[] dp1 : dp)
				Arrays.fill(dp1, 1 << 20);
			PriorityQueue<Point> pq = new PriorityQueue<Point>();
			pq.offer(new Point(0, 0, 0));
			int ans = 0;
			while (!pq.isEmpty()) {
				Point p = pq.poll();
				int t = p.t;
				int cost = p.cost;
				int bit = p.bit;
				if (t == 0 && bit == (1 << q) - 1) {
					ans = cost;
					break;
				}
				if (dp[t][bit] < cost)
					continue;
				dp[t][bit] = cost;
				if (t > 0)
					for (int i = 0; i < q; i++)
						if (supers[t - 1].containsKey(name[i])
								&& supers[t - 1].get(name[i]).equals(
										min.get(name[i])))
							bit |= 1 << i;
				for (Point point : lists[t])
					pq.offer(new Point(point.t, cost + point.cost, bit));

			}
			System.out.println(sum + " " + ans);
		}
	}

	class Point implements Comparable<Point> {
		int t, cost, bit;

		@Override
		public String toString() {
			return "Point [t=" + t + ", cost=" + cost + ", bit=" + bit + "]";
		}

		public Point(int t, int cost, int bit) {
			super();
			this.t = t;
			this.cost = cost;
			this.bit = bit;
		}

		public Point(int t, int cost) {
			super();
			this.t = t;
			this.cost = cost;
		}

		@Override
		public int compareTo(Point o) {
			if (cost == o.cost)
				return o.bit - bit;
			return cost - o.cost;
		}
	}
}

Measured memory_bytes: 25604
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<pii> tre(n);
	vi x(n);
	vi y(n);
	REP(i, n) {
		cin >> tre[i].first >> tre[i].second;
		x[i] = tre[i].first;
		y[i] = tre[i].second;
	}
	SORT(x);
	x.erase(unique(x.begin(), x.end()), x.end());
	SORT(y);
	y.erase(unique(y.begin(), y.end()), y.end());
	map<int, int> zipx;
	map<int, int> zipy;
	REP(i, x.size())
		zipx[x[i]] = i;
	REP(i, y.size())
		zipy[y[i]] = i;

	vvi cell(y.size(), vi(x.size(), 0));
	REP(i, tre.size()) {
		cell[zipy[tre[i].second]][zipx[tre[i].first]]++;
	}
	REP(i, y.size()) {
		REP(j, x.size()) {
			if (i != 0)
				cell[i][j] += cell[i - 1][j];
			if (j != 0)
				cell[i][j] += cell[i][j - 1];
			if (i != 0 && j != 0)
				cell[i][j] -= cell[i - 1][j - 1];
		}
	}
	int minx,miny, maxx, maxy;
	minx = x[0];
	miny = y[0];
	maxx = x[x.size()-1];
	maxy = y[y.size() - 1];
	REP(i, m) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (x1>maxx||y1>maxy||x2<minx||y2<miny) {
			cout << 0 << endl;
			continue;
		}
		x1 = zipx[*lower_bound(ALL(x), x1)];
		y1 = zipy[*lower_bound(ALL(y), y1)];
		x2 = zipx[*(upper_bound(ALL(x), x2) - 1)];
		y2 = zipy[*(upper_bound(ALL(y), y2) - 1)];
		int ans = cell[y2][x2];
		if (y1 != 0)
			ans -= cell[y1 - 1][x2];
		if (x1 != 0)
			ans -= cell[y2][x1 - 1];
		if (y1 != 0 && x1 != 0)
			ans += cell[y1 - 1][x1 - 1];
		cout << ans << endl;
	}
}

Measured memory_bytes: 101340
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

		int R;
		cin >> R;
		string s = "AGC";
		if (R < 1200) {
			s = "ABC";
		}
		else if (R < 2800) {
			s = "ARC";
		}
		cout << s << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using lP = pair<ll, ll>;
using iP = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;

vector<vector<int>> edge;
vector<int> r;

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号

	UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
		for (int i = 0; i < N; ++i) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る
		if (par[x] == x) return x;
		return par[x] = root(par[x]); // 経路圧縮
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y) { // 2つのデータx,yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main()
{
	// ABC075-C, UnionFindでも解いてみる
	int n, m; cin >> n >> m;
	vector<iP> edge(m);
	rep(i, m) {
		cin >> edge[i].first >> edge[i].second;
		edge[i].first--; edge[i].second--;
	}
	int ans = 0;
	rep(i, m) {
		UnionFind tree(n);
		rep(j, m) {
			if (i != j) tree.unite(edge[j].first, edge[j].second);
		}

		int parent = tree.root(0);
		bool ok = false;
		rep(j, n) {
			if (parent != tree.root(j)) ok = true;
		}
		if (ok) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612