akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> g[100010];
long long dp[100010][3]; // 0 - black, 1 - white
bool used[100010];

const long long mod = 1e9 + 7;

void dfs(int v)
{
  used[v] = true;
  for (auto to : g[v])
  {
    if (!used[to]) 
    {
      dfs(to);
      long long k = (dp[to][0] + dp[to][1]) % mod;
      dp[v][1] *= k;
      dp[v][1] %= mod;
      dp[v][0] *= dp[to][1];
      dp[v][0] %= mod;
    }
  }
}

int main()
{
  int n; cin >> n;
  for (int i = 0; i < n - 1; i++)
  {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
    dp[i + 1][1] = 1;
    dp[i + 1][0] = 1;
  }
  dp[n][1] = 1;
  dp[n][0] = 1;
  
  dfs(1);
  cout << (dp[1][0] + dp[1][1]) % mod << endl;
  return 0;
}

Measured memory_bytes: 12288
// hello {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 605;
int n, m;
VI adj[MAX_N];
vector<double> dp(MAX_N, 0);

void input() {
    RI(n, m);
    REP(i, m) {
        int a, b;
        RI(a, b);
        adj[a].PB(b);
    }
}

void solve() {
    for(int i = n - 1; i > 0; i--) {
        for(auto j:adj[i]) {
            dp[i] += dp[j];
        }
        dp[i] = dp[i] / adj[i].size() + 1;
    }
    // cout << dp[1] << endl;
    double ans = dp[1];
    for(int i = 1; i < n; i++) {
        double maxi = 0;
        if(adj[i].size() < 2) continue;

        int ni = adj[i].size();
        for(auto j:adj[i]) {
            maxi = max(maxi, dp[j]);
        }
        vector<double> tmp = dp;
        // cout << "i = " << i << endl;
        // cout << maxi << endl;
        // cout << dp[i] << endl;
        tmp[i] = ((dp[i]-1)*ni - maxi) / (ni - 1) + 1;
        // cout << tmp[i] << endl;
        for(int k = i-1; k > 0; k--) {
            tmp[k] = 0;
            for(auto j:adj[k]) {
                tmp[k] += tmp[j];
            }
            tmp[k] = tmp[k] / adj[k].size() + 1;
        }
        // cout << tmp[1] << endl;
        ans = min(ans, tmp[1]);
    }

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

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}


Measured memory_bytes: 1408
N, = [int(x) for x in input().split()]
DD = [[int(x) for x in input().split()] for i in range(N)]
isDoublet = [x == y for x, y in DD]
for i in range(N-2):
    if isDoublet[i] and isDoublet[i + 1] and isDoublet[i + 2]:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 62436
#include <iostream>
#include <cstdio>

using namespace std;

void printDirection(int d, char dir)
{
    for (int i = 0; i < d; i++)
    {
        printf("%c", dir);
    }
}

int main()
{
    int sx, sy, tx, ty;
    
    cin >> sx >> sy >> tx >> ty;
    
    int dx = tx - sx;
    int dy = ty - sy;
    
    // 1. t への移動
    printDirection(dy, 'U');
    printDirection(dx, 'R');
    
    // 2. s への移動
    printDirection(dy, 'D');
    printDirection(dx, 'L');
    
    // 3. t への移動
    printDirection(1, 'L');
    printDirection(dy + 1, 'U');
    printDirection(dx + 1, 'R');
    printDirection(1, 'D');
    
    // 4. s への移動
    printDirection(1, 'R');
    printDirection(dy + 1, 'D');
    printDirection(dx + 1, 'L');
    printDirection(1, 'U');
    
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
li = sorted(list(map(int, input().split())))

for i in range(n):
    x = x - li[i]
    if x < 0:
        print(i)
        break
else:
    if x == 0:
        print(n)
    else:
        print(n-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
    
#define par pair<pair<int,int>, int>
#define f first
#define s second

char s[10];

bool valid(int idx)
{
    int n;
    n = (s[idx]-'0') * 10 + (s[idx+1]-'0');
    return (n>0 && n < 13);
}

int main() {
    scanf("%s",s);
    if(valid(0) && valid(2)) printf("AMBIGUOUS");
    else if(valid(0)) printf("MMYY");
    else if(valid(2)) printf("YYMM");
    else printf("NA");
	return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::{input, marker::Chars};

fn main() {
    input! {
       s: Chars,
       t: Chars,
    }

    let mut min = t.len();

    for i in 0..=(s.len() - t.len()) {
        let mut count = 0;
        for j in 0..t.len() {
            if s[i+j] != t[j]{
                count += 1;
            };
        }
        if min > count {
            min = count
        }
    } 

    println!("{}",min);
}


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

using namespace std;

long long int n, m, d;

int main() {
  cin >> n >> m >> d;
  long long int cnt = 2 * (n - d);
  if (d == 0) cnt = n;

  printf("%.11f\n", (double)cnt * (m - 1) / (n * n));

  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	string s, t;
	cin >> s >> t;
	int index = -1;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	rep(i, s.size()) {
		bool isOK = true;
		rep(j, t.size()) {
			if (i + j >= s.size()) {
				isOK = false;
				break;
			}
			if (!(s[i + j] == t[j] || s[i + j] == '?')) {
				isOK = false;
				break;
			}
		}
		if (isOK) {
			index = i;
			break;
		}
	}
	if (index == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	string ans = "";
	rep(i, s.size()) {
		if (i >= index && i < index + t.size()) {
			ans += t[i - index];
			continue;
		}
		if (s[i] == '?') {
			ans += "a";
			continue;
		}
		ans += s[i];
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 3584
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const ll LINF = (ll)1 << 60;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int w,h,c;
  cin>>w>>h>>c;
  int g=__gcd(w,h);
  int sum=0;
  cout<<(w/g)*(h/g)*c<<'\n';
  return(0);
}


Measured memory_bytes: 3216
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
    if (b / a >= c) System.out.println(c);
    else System.out.println(b / a);
  }
}

Measured memory_bytes: 23764
N = int(input())
S = []
for i in range(N):
    S.append(input())
march = [0, 0, 0, 0, 0]

for i in range(N):
    if S[i][0] == "M":
        march[0] += 1
    if S[i][0] == "A":
        march[1] += 1
    if S[i][0] == "R":
        march[2] += 1
    if S[i][0] == "C":
        march[3] += 1
    if S[i][0] == "H":
        march[4] += 1
ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += march[i] * march[j] * march[k]
print(ans)


Measured memory_bytes: 9772
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define ll long long
int main()
{
	int sum=0,k,a,b,c,i;
	cin>>k;
	for(a=1;a<=k;a++)
		for(b=1;b<=k;b++)	
			for(c=1;c<=k;c++)
			{
				i=__gcd(a,b);
				sum+=__gcd(i,c);
			}			
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3604
from sys import stdin
from itertools import repeat
def main():
    n = int(stdin.readline())
    a = map(int, stdin.read().split(), repeat(10, n))
    s = p = 0
    for x in reversed(a):
        p -= 1
        if p < 0:
            p = 0
        if x < p:
            print -1
            return
        if x > p:
            s += x
            p = x
    if p:
        print -1
        return
    print s
main()

Measured memory_bytes: 20104
import math


def is_prime(n):
  if n in [2, 3, 5, 7]:
    return True
  elif 0 in [n%2, n%3, n%5, n%7]:
    return False
  else:
    check_max = math.ceil(math.sqrt(n))
    for i in range(2, check_max + 1):
      if n % i == 0:
        return False
    else:
      return True

def main():
  primes = set([])
  length = int(input())
  for _ in range(0, length):
    n = int(input())
    if is_prime(n):
      primes.add(n)

  print(len(primes))
  return 0


if __name__ == '__main__':
  main()

Measured memory_bytes: 7820
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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


int main(){
    cin>>r;
    out(3*r*r);
    
    
}


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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine()); //2 <= n
            var 現在最小 = int.Parse(Console.ReadLine());
            var 最大利益 = int.MinValue;
            for(var i = 0; i < n - 1; ++i)
            {
                var m = int.Parse(Console.ReadLine());
                var 利益 = m - 現在最小;
                if (利益 > 最大利益) 最大利益 = 利益;
                if (m < 現在最小) 現在最小 = m;
            }
            Console.WriteLine(最大利益);
        }
    }
}


Measured memory_bytes: 20068
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	string s1c = s1, s2c = s2;

	reverse(ALL(s1));
	reverse(ALL(s2));

	if (s1 == s2c && s2 == s1c) cout << "YES" << endl;
	else cout << "NO" << endl;
	
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    dic = collections.defaultdict(int)
    for i in a:
        for x in range(i-1,i+2):
            dic[x] += 1
    diclst = sorted(dic.items(), key=lambda x: x[1], reverse=True)
    ans = diclst[0][1]
    print(ans)
main()

Measured memory_bytes: 93300
#include <iostream>
#include <vector>
#include <queue>

#define fi first
#define se second
#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, q;
	cin >> n >> k >> q;
	vi diff (n + 5);
	diff[0] += k;
	while (q--) {
	  int foo;
	  cin >> foo;
	  foo--;
	  diff[0]--;
    diff[foo]++;
    diff[foo + 1]--;
  }
  int tot = 0;
  FOR (i, 0, n) {
    tot += diff[i];
    cout << (tot > 0 ? "Yes" : "No") << '\n';
  }
	return 0;
}

Measured memory_bytes: 1024
x = input()
y = input()
lx = len(x)
ly = len(y)

chars = [[''] * (ly + 1) for _ in range(lx + 1)]
length = [[0] * (ly + 1) for _ in range(lx + 1)]
prev = [[0b00] * (ly + 1) for _ in range(lx + 1)]

for i_x in range(lx):
    for i_y in range(ly):
        if x[i_x] == y[i_y]:
            length[i_x+1][i_y+1] = length[i_x][i_y] + 1
            chars[i_x+1][i_y+1] = x[i_x]
            prev[i_x+1][i_y+1] = 0b11
        elif length[i_x+1][i_y] > length[i_x][i_y+1]:
            length[i_x+1][i_y+1] = length[i_x+1][i_y]
            prev[i_x+1][i_y+1] = 0b01
        else:
            length[i_x+1][i_y+1] = length[i_x][i_y+1]
            prev[i_x+1][i_y+1] = 0b10

lcs = [''] * length[-1][-1]
i_x, i_y = lx, ly
i = 1
while i_x and i_y:
    if prev[i_x][i_y] == 0b11:
        lcs[-i] = chars[i_x][i_y]
        i += 1
    i_x, i_y = i_x - ((prev[i_x][i_y] & 0b10) >> 1), i_y - (prev[i_x][i_y] & 0b01)

print(''.join(lcs))


Measured memory_bytes: 518408
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)((v).size())
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 


#define M 100010


ll f(ll x){
	return x*x*x*x*x;
}
int main(){
    IOS;
    tihs;
    
    vll v;
    rep(i,-3000,3000)v.pb(i);
    ll x;cin>>x;
    bool ok=0;
    rep(i,0,sz(v)){
    	rep(j,0,sz(v)){
    		ll a=v[i],b=v[j];
	    	ll y=f(a)-f(b);
	    	if(y==x){
	    		cout<<a<<" "<<b;
	    		ok=1;
	    		break;
	    	}
    	}
    	if(ok)break;
	}
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

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

// UnionFind
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(){
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m){
		int a, b;
		cin >> a >> b;
		--a; --b;
		uf.unite(a, b);
	}

	int ans = 0;
	rep(i, n){
		ans = max(ans, uf.size(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 4028
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
long long bit(int l,int r,int po){
	if(l>r)
	return 0;
	long long cnt=0;
	for(int i=l;i<=r;i++)
	cnt+=(1<<i)*pow(10,po+l-i);
	return cnt;
}
int main(){
	string a;
	cin>>a;
	long long ans=0;
	for(int i=0;i<a.size();i++){
		ans+=((int)a[i]-'0')*((1<<i)*pow(10,a.size()-i-1)+bit(i,a.size()-2,a.size()-i-2));
	}
	cout<<ans;
}  

Measured memory_bytes: 256
package main

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

func main() {
	A, B := ReadInt(), ReadInt()
	ans := 0
	if A > B {
		ans += A
		A--
	} else {
		ans += B
		B--
	}
	if A > B {
		ans += A
		A--
	} else {
		ans += B
		B--
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
const int N=1e5+5;
int x,k;


int32_t main(){
	IOS;
	
	//code
	cin>>k>>x;
	if(500*k>=x)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	//code
	
	return 0;

}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    std::array<int, 100010> check{};
    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] < 100010) ++check[A[i]];
        else ++res;
    }
    for (int i = 0; i < check.size(); ++i) {
        if (check[i] != 0) {
            if (check[i] == i) continue;
            else if (check[i] > i) res += check[i] - i;
            else res += check[i];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4304
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	lli N, A, B; cin >> N >> A >> B;
	lli ans = 0;
	if (N == 1 && A == B)ans = 1;
	else if (N > 1 && A <= B)ans = 1 + (N - 2) * (B - A);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc076c()
}

fun abc076c() {
    val s = readLine()!!
    val t = readLine()!!
    if (s.contains(t)) {
        println(s.replace('?', 'a'))
        return
    }
    for (i in s.length - t.length downTo 0) {
        var isMatch = true
        for (j in 0 until t.length) {
            if (s[i+j] == '?') continue
            if (s[i+j] != t[j]) {
                isMatch = false
                break
            }
        }
        if (isMatch) {
            val r = s.substring(0, i) + t + s.substring(i + t.length, s.length)
            println(r.replace('?', 'a'))
            return
        }
    }
    println("UNRESTORABLE")
}

Measured memory_bytes: 33656
from math import factorial


def cntRank(S, n):
    used = set()
    cnt = 0

    for i, s in enumerate(S):
        s = int(s)
        j = 1
        while j < s:
            if j not in used:
                cnt += factorial(n - (i + 1))
            j += 1
        used.add(s)

    return cnt + 1


N = int(input())
P = map(int, input().split())
Q = map(int, input().split())

print(abs(cntRank(P, N) - cntRank(Q, N)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n;
int k;
int a[5];
long long ans=1;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>k;
		int qaq=0;
		for(int i=1;i<=3;i++) 
			if(a[i]==k&&qaq==0) a[i]++,qaq++;
			else if(a[i]==k&&qaq!=0) qaq++;
		if(qaq==0) {
			cout<<0;
			return 0;
		}
		ans*=qaq;
		ans%=1000000007;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
'''
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(' '))))
num_sum = 0
remove_array = np.array([], int)
for i in range(N):
    c1 = np.count_nonzero(A == i + 1)
    c2 = np.count_nonzero(A == A[i])
    if c2 <= 1:
        remove_array = np.append(remove_array, 0)
    else:
        remove_array = np.append(remove_array, c2 - 1)
    num_sum += int(c1 * (c1 - 1) / 2)
print(*(num_sum - remove_array), sep='\n')
'''
import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
total = 0
for key in cnt.keys():
    total += cnt[key] * (cnt[key] - 1) // 2
for i in range(N):
    tmp = total
    tmp -= cnt[A[i]] * (cnt[A[i]] - 1) // 2
    tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2
    print(tmp)

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

typedef long long int ll;

int main()
{
    ll n;
    string x;
    cin >> n;
    vector<string> s(n);
    vector<ll> t(n);
    for(ll i = 0;i < n;i++){
        cin >> s[i] >> t[i];
    }
    cin >> x;

    ll l = 0, ans = 0;
    for(ll i = 0;i < n;i++){
        if(x == s[i]){
            l = i;
        }
    }
    for(ll i = l + 1;i < n;i++){
        ans += t[i];
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

const int mod = INF+7;
int main(){
    map<char,int>mp;
    int n;cin>>n;
    string s;cin>>s;
    rep(i,n){
        mp[s[i]]++;
    }
    ll res = 1;
    for(auto m : mp){
        res = res*(m.second+1)%mod;
    }
    cout<<res-1<<endl;
}



Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
int n,a[105];
int main()
{
    int w=0,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0&&a[i]%3&&a[i]%5)w=1;
    }
    if(w)printf("DENIED\n");
    else printf("APPROVED\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, m; cin >> n >> m;

    // 入力
    vector<string> a(n);
    vector<string> b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    
    // 縦横それぞれ(n-m+1)の範囲を探索
    ll range = n-m+1;

    // 探索
    bool ans = false;
    rep(i, range){
        rep(j, range){
            bool chk = true;
            rep(k, m) if(a[i+k].substr(j, b[k].size()) != b[k]){ chk = false; break; }
            if(!chk) continue;
            ans = true;
        }
    }

    // 結果出力
    (ans) ? Yes() : No();
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

int main() {
    int a, b;
    cin >> a >> b;
    int ab = stoi(to_string(a) + to_string(b));
    bool ans = false;
    for (int i = 1; i < 317; ++i) {
        int tmp = i * i;
        if (tmp > ab) break;
        if (tmp == ab) {
            ans = true;
            break;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 760
n, k = map(int, input().split())

a = []
b = []
for i in range(n):
    tmp1, tmp2 = map(int, input().split())
    a.append(tmp1)
    b.append(tmp2)

p_list = []
t = zip(a, b)
ts = sorted(t)
a, b = zip(*ts)
ans = 0
count = 0
for ai, bi in zip(a, b):
    count += bi
    if count >= k:
        ans = ai
        break

print(ans)




Measured memory_bytes: 26860
from collections import Counter
N = int(input())
a_ls = list(map(int, input().split()))

if N % 3 != 0:
    res = 'Yes'
    for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
else:
    res = 'Yes'
    c = Counter(a_ls)
    if len(c) > 3:
        res = 'No'
    if len(c) == 3:
        if not list(c.values())[0] == list(c.values())[1] == list(c.values())[2]:
            res = 'No'
        for i in c.keys():
            for j in c.keys():
                for k in c.keys():
                    if i!=j and j!=k and k!=i and not i^j==k:
                        res = 'No'
    elif len(c) == 2:
        if not (list(c.values())[0] == N//3 or list(c.values())[1] == N//3):
            res = 'No'
        if list(c.values())[0] == N//3:
            if not list(c.keys())[0] == 0:
                res = 'No'
        if list(c.values())[1] == N//3:
            if not list(c.keys())[1] == 0:
                res = 'No'
    else:
        for i in range(N):
            if a_ls[i] != 0:
                res = 'No'
        
print(res)

Measured memory_bytes: 94400
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;

#define N 2005
long long int n,x,a[N],b[N][N];
long long int min(long long int a,long long int b){if(a<b)return a;else return b;}
void dp(){
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n-1;j++){
            if(j==0)b[i][j]=a[i];
            else if((i-j+n)%n==0){
               b[i][j]=min(a[n],b[i][j-1]);
            }else{
                b[i][j]=min(a[(i-j+n)%n],b[i][j-1]);
            }
        }
    }
}


int main() {
    cin>>n>>x;
    for(int i=1;i<=n;i++)cin>>a[i];
    long long int min=2000000000005;
    dp();
    for(int j=0;j<=n-1;j++){
        long long int sum=j*x;
        for(int i=1;i<=n;i++)sum+=b[i][j];
        if(min>sum)min=sum;
    }
    printf("%lld",min);
    return 0;
}


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

#define VIC ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;
typedef complex<ld> point;
#define endl '\n'
#define matrix vector<vector<ll>>
#define EPS 1e-9
#define X real()
#define Y imag()
#define vec(a, b) ((b) - (a))
#define dot(a, b) ((conj(a) * (b)).real())
#define cross(a, b) ((conj(a) *(b)).imag())
#define lengthsqr(v) (dot(v, v))
#define length(v) ((ld)hypot((v).Y, (v).X))
#define same(a, b) (lengthsqr(vec(a, b)) < EPS)

const int N = 1e2 + 5, inf = 1e9 + 5;
const ll mod = 1e9 + 7;

ll dp[N][(int)1e5 + 5];
pair<ll, int> a[N];

int main()
{
    VIC
    int n, w;
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first >> a[i].second;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= w; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (a[i].first <= j)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i].first] + a[i].second);
        }
    ll ans = 0;
    for (int i = 0; i <= w; i++)
        ans = max(ans, dp[n][i]);
    return cout << ans, 0;
}


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

#ifdef SG
	#include <debug.h>
#else
	template<typename T> struct outputer;
	struct outputable {};
	#define PRINT(...)
	#define OUTPUT(...)
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
	#define fbegin(...)
	#define fend
	#define pbegin(...)
	#define pend
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb emplace_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t ui;
typedef uint16_t us;
typedef uint8_t uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

struct Input {
	ll a, b;
	
	bool read () {
		return !!(cin >> a >> b);
	}

	void init (const Input &input) {
		*this = input;
	}
};

struct Data: Input {
	int ans;
	
	void write () {
		cout << ans << endl;
	}
};


namespace Main {
	
	struct Solution: Data {
		
		void solve () {
			ans = 0;
			while (a <= b) {
				ans++;
				a *= 2;
			}
		}
		
		void clear () {
			*this = Solution();
		}
	};
}


Main::Solution sol;

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);

	#ifdef SG
		freopen((problemname + ".in").c_str(), "r", stdin);
//		freopen((problemname + ".out").c_str(), "w", stdout);
		while (sol.read()) {
			sol.solve();
			sol.write();
			sol.clear();
		}
	#else
		sol.read();
		sol.solve();
		sol.write();
	#endif
	
	/*
	int t;
	cin >> t;
	forn (i, t) {
		sol.read();
		sol.solve();
		sol.write();
		sol.clear();
	}
	*/
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll int
#define ld double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}
main()
{
    IO
    ll n,x,t;
    cin>>n>>x>>t;
    ll f=(n+x-1)/x;
    cout<<(f*t);

}


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

int main(){
  int n; cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i < n; i++){
    cin >> b.at(i);
  }
  long long out = 0;
  for(int i = 0; i < n; i++){
    long long tmp = 0;
    for(int j = 0; j < i + 1; j++){
      tmp += a.at(j);
    }
    for(int j = i; j < n; j++){
      tmp += b.at(j);
    }
    if(tmp > out) out = tmp;
  }
  cout << out;
}

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

int main(){
    double a,b,c,d=0,e=0;
    cin>>a>>b;
    b*=2;
    a-=b;
    if(a<0){cout<<'0'; return 0;}
    else cout<<a;
    return 0;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  int n,h,w,ans=0;
  cin>>n>>h>>w;
  int a[n],b[n];
  for(int i=0;i<n;i++)
    {
    cin>>a[i]>>b[i];
    if(h<=a[i]&&w<=b[i])
      ans++;
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 3596
N, M = map(int, input().split())
ablist = [list(map(int, input().split())) for _ in range(N)]
cdlist = [list(map(int, input().split())) for _ in range(M)]

for a, b in ablist:
    min_distance = 10**9 + 7
    min_index = 0
    for index, cd in enumerate(cdlist, 1):
        c, d = cd
        distance = abs(a - c) + abs(b - d)
        if distance < min_distance:
            min_distance = distance
            min_index = index
    print(min_index)


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

using namespace std;


int main() {
int64_t a,b;
  cin>>a>>b;
  int d=0;
  int e=1;
  while(e<a+1)
  {
  e=e*b;
    d=d+1;
  
  }
cout<<d;
}


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

using namespace std;

const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};
const int INF = 1 << 30;

struct Dinic
{
  struct edge
  {
    int to, cap, rev;
  };

  vector< vector< edge > > graph;
  vector< int > min_cost, iter;

  Dinic(int n)
  {
    graph.resize(n);
  }

  void add_edge(int from, int to, int cap)
  {
    graph[from].push_back((edge) {to, cap, (int) graph[to].size()});
    graph[to].push_back((edge) {from, 0, (int) graph[from].size() - 1});
  }

  bool bfs(int s, int t)
  {
    min_cost.assign(graph.size(), -1);
    queue< int > que;
    min_cost[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int p = que.front();
      que.pop();
      for(int i = 0; i < graph[p].size(); i++) {
        const edge& e = graph[p][i];
        if(e.cap > 0 && min_cost[e.to] == -1) {
          min_cost[e.to] = min_cost[p] + 1;
          que.push(e.to);
        }
      }
    }
    return (min_cost[t] != -1);
  }

  int dfs(int idx, const int t, int flow)
  {
    if(idx == t) return (flow);
    for(int& i = iter[idx]; i < graph[idx].size(); i++) {
      edge& e = graph[idx][i];
      if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
        int d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return (d);
        }
      }
    }
    return (0);
  }

  int max_flow(int s, int t)
  {
    int flow = 0;
    while(bfs(s, t)) {
      iter.assign(graph.size(), 0);
      int f = 0;
      while((f = dfs(s, t, INF)) > 0) {
        flow += f;
      }
    }
    return (flow);
  }
};

int H, W;
string S[100];

bool isover(int y, int x)
{
  return (y < 0 || y >= H || x < 0 || x >= W);
}

int get(int y, int x, bool in = false)
{
  if(in) return (H * W + y * W + x);
  return (y * W + x);
}

int main()
{
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
  }

  Dinic flow(H * W * 2 + 2);

  for(int i = 0; i < H; i++) {
    if(S[i][0] == 'X' || S[i][W - 1] == 'X') {
      cout << -1 << endl;
      return (0);
    } else {
      flow.add_edge(get(i, 0, false), H * W * 2, INF);
      flow.add_edge(get(i, W - 1, false), H * W * 2, INF);
    }
  }
  for(int i = 0; i < W; i++) {
    if(S[0][i] == 'X' || S[H - 1][i] == 'X') {
      cout << -1 << endl;
      return (0);
    } else {
      flow.add_edge(get(0, i, false), H * W * 2, INF);
      flow.add_edge(get(H - 1, i, false), H * W * 2, INF);
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(S[i][j] == 'X') {
        flow.add_edge(H * W * 2 + 1, get(i, j, false), INF);
      }
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      flow.add_edge(get(i, j, true), get(i, j, false), 1);
      for(int k = 0; k < 4; k++) {
        int ni = i + vy[k], nj = j + vx[k];
        if(isover(ni, nj)) continue;
        flow.add_edge(get(i, j, false), get(ni, nj, true), INF);
      }
    }
  }

  cout << flow.max_flow(H * W * 2 + 1, H * W * 2) << endl;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n){
      cin>>a[i];
    }
    rep(i,n){
      cin>>b[i];
    }
    rep(i,n){
      cin>>c[i];
    }
    sort(begin(a),end(a));
    sort(begin(b),end(b));
    sort(begin(c),end(c));
    vector<ll> cnt1(n),cnt2(n);
    rep(i,n){
      cnt1[i]=n-(upper_bound(begin(b),end(b),a[i])-begin(b));
      cnt2[i]=n-(upper_bound(begin(c),end(c),b[i])-begin(c));
    }
    vector<ll> sum(n+1);
    sum[0]=0;
    FOR(i,1,n+1){
      sum[i]=cnt2[n-i]+sum[i-1];
    }
    ll ans=0;
    rep(i,n){
      ans+=sum[cnt1[i]];
    }
    /*
    cout_vec(a);
    cout_vec(b);
    cout_vec(c);
    cout_vec(cnt1);
    cout_vec(cnt2);
    */
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int f(int x) { //f(0, x)を返す
    int ans=0;
    rep(i, 41) { //2^iのbitを決定する
        int one_bits=0;
        if (i==0) {
            int m=4; //周期
            int r=x%m;
            if (r==1 || r==2) one_bits=1;
        } else {
            int m = 1LL<<(i+1); //周期
            int r = x%m;
            if (r >= m/2) one_bits=((r-(m/2)+1)%2);
        }
        if (one_bits % 2 == 1) { //1が奇数個あった場合のみ
            ans += (1LL<<i);
        }
    }
    return ans;
}


signed main(void) {
    int A, B; cin >> A >> B;
    if (A==0) cout << f(B) << endl;
    else cout << (f(B) ^ f(A-1)) << endl;

    return 0;
}

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

int main(){
	int a,count;
  	cin >> a;
  	if(a/100==1){
    	count++;
      	a=a-100;
    }
  	if(a/10==1){
    	count++;
      	a=a-10;
    }
  	if(a==1){
    	count++;
    }
  cout << count;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> mask(M, 0);
  vector<int> p(M, 0);
  for (int i = 0; i < M; i++) {
    int k, s;
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s;
      mask[i] = (1 << (s-1)) | mask[i];
    }
    // cout << i << " " << mask[i] << endl;
  }
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  int total = 0;
  for (int x = 0; x < (1 << N); x++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      int tmp = x & mask[i];
      int cnt = 0;
      while (tmp > 0) {
        if (tmp & 1) {
          cnt++;
        }
        tmp = tmp >> 1;
      }
      if ((cnt & 1) != p[i]) {
        ok = false;
        break;
      }
    }
    if (ok) total++;
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N % 10 == 7 || N % 100 / 10 == 7 || N /100 == 7 )
     cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 3596
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
mod = 1000000007

def comb(n, r, mod):
    if n < 0 or r < 0 or r > n: return 0
    nu = 1
    de = 1
    for i in range(r):
        nu = nu * (n-i) % mod
        de = de * (i+1) % mod
    return nu * inv(de, mod) % mod

def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    return p+mod if p < 0 else p

# 120
# 012

# n-k個は1以上
# k+1個以上が0

def enumfif(n, mod):
    f = [0] * (n+1)
    invf = [0] * (n+1)
    f[0] = 1
    for i in range(1, n+1):
        f[i] = f[i-1] * i % mod

    a = f[n]
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    invf[n] = p + mod if p < 0 else p
    for i in range(n-1,-1,-1):
        invf[i] = invf[i+1] * (i+1) % mod
    return f, invf

def C(n, r, mod, fif):
    if n < 0 or r < 0 or r > n:
        return 0
    return fif[0][n] * fif[1][r] * fif[1][n-r] % mod


if k >= n-1:
    print(comb(n-1+n, n, mod))
else:
    fif = enumfif(400005, mod)
    # sum C(n,z)*C(n-z-1+n, n, mod)
    ans = comb(n-1+n, n, mod)
    for z in range(k+1, n+1):
        ans -= C(n, z, mod, fif) * C(n-z-1+(n-(n-z)), (n-(n-z)), mod, fif)
    ans %= mod
    if ans < 0:
        ans += mod
    print(ans)

Measured memory_bytes: 47596
#include <stdio.h>
int main(void){
    int card[4][13] = {0};
    int num,rank,i,j;
    char suit;
    scanf( "%d\n" , &num );
    while( num ){
       //S -> 0 / H -> 1 / C -> 2 / D ->3
       scanf( "%c %d\n" , &suit , &rank );
       switch(suit){
           case 'S': card[0][rank-1] = 1; break;
           case 'H': card[1][rank-1] = 1; break; 
           case 'C': card[2][rank-1] = 1; break; 
           case 'D': card[3][rank-1] = 1; break;
       }
       num--;
       //printf("%c-%d-%d\n" , suit , rank , num );
    }
    
    for( i = 0; i < 4 ; i++ ){
        for( j = 0 ; j < 13; j++ ){
            if( card[i][j] != 1 ){
               switch(i){
                   case 0: printf( "S %d\n" , j + 1 ); break;
                   case 1: printf( "H %d\n" , j + 1 ); break;
                   case 2: printf( "C %d\n" , j + 1 ); break;
                   case 3: printf( "D %d\n" , j + 1 ); break;
               }
            }
        }
    }
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// ABC048B - Between a and b ...
int main(){
  int64_t a, b, x; // a <= b <= 1e18
  cin >> a >> b >> x;
  int64_t cnt = b / x + 1;
  if (a != 0) {
    cnt -= (a-1) / x + 1;
  }

  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
vector <int> g[100010];
long long opt[100010];
long long ans;
bool cyc[100010];
bool vis[100010];
int from[100010];
vector <int> can;

void find_cycle(int x, int par) {
	vis[x] = true;
	from[x] = par;
	for(auto i : g[x]) {
		if(!vis[i]) {
			find_cycle(i, x);
		} else if (i != par && can.empty()) {
			int cur = x;
			while(cur != i) {
				cyc[cur] = true;
				can.push_back(cur);
				cur = from[cur];
			}
			can.push_back(cur);
			cyc[cur] = true;
		}
	}
}

void dfs(int x, int par) {
	opt[x] = 1;
	for(auto i : g[x]) {
		if(i == par || cyc[i]) continue;
		dfs(i, x);
		opt[x] -= opt[i];
	}
	ans += abs(opt[x]);
}

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		g[p].push_back(q);
		g[q].push_back(p);
	}
	if(n % 2 == 1) {
		printf("-1\n");
		exit(0);
	}
	if(m == n-1) {
		dfs(1, 0);
		if(opt[1] == 0) {
			printf("%lld\n", ans);
		} else printf("-1\n");
		exit(0);
	}
	find_cycle(1, 0);

	int sz = can.size();
	vector <long long> cost (sz); 
	vector <long long> p (sz);

	for(int i = 0; i < sz; i++) {
		dfs(can[i], 0);
		cost[i] = opt[can[i]];
		ans -= abs(cost[i]);
		if(i > 0) {
			if(i & 1) p[i] = p[i - 1] - cost[i];
			else p[i] = p[i - 1] + cost[i]; 
		}
	}

	long long start;
	if(sz & 1) {
		long long sum = p[sz - 1] - cost[0];
		if(sum & 1) {
			printf("-1\n");
			exit(0);
		}
		start = sum / 2;
	} else {
		if(p[sz - 1] + cost[0] != 0) {
			printf("-1\n");
			exit(0);
		} 
		sort(p.begin(), p.end());
		start = p[sz / 2];
	}
	for(int i = 0; i < sz; i++) {
		ans += abs(start - p[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15352
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS =1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}

void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int is[10001];
int ps[10001];
int qs[10001];
int rs[10001];

void solve(){
	int n;
	while(cin>>n&&n){
		for(int j=0;j<n;j++){
			cin>>is[j]>>ps[j]>>qs[j]>>rs[j];
		}
		int P,Q,R,C;
		cin>>P>>Q>>R>>C;
		vector<int> res;
		for(int i=0;i<n;i++){
			int cal=4*ps[i]+9*qs[i]+4*rs[i];
			if(P>=ps[i]&&Q>=qs[i]&&R>=rs[i]&&C>=cal){
				res.push_back(is[i]);
			}
		}
		if(res.size()==0)cout<<"NA"<<endl;
		else{
			for(int i=0;i<res.size();i++){
				cout<<res[i]<<endl;
			}
		}
	}
}

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

Measured memory_bytes: 944