akhauriyash/Code-Regression huggingface dataset:
# Longest Common Subsequence

# 関数に入れる
def main():
    # input ← stdin.readline
    import sys
    input = sys.stdin.readline
    for _ in [0]*int(input()):
        # \n削除
        X = '_' + input()[:-1]
        Y = '_' + input()[:-1]

        lx = len(X)
        ly = len(Y)

        dp = [[0]*ly for _ in [0]*lx]

        # 変数に入れておく
        j_y = tuple(enumerate(Y))
        for i, x in enumerate(X):
            if i == 0:
                continue

            # 変数に入れておく
            dp_i = dp[i]
            dp_i1 = dp[i-1]
    
            for j, y in j_y:
                if x == y:
                    dp_i[j] = dp_i1[j-1] + 1
                else:
                    # max(a, b)を書き下す
                    a = dp_i1[j]
                    b = dp_i[j-1]
                    dp_i[j] = a if a > b else b

        print(dp[-1][-1])

if __name__ == '__main__':
    main()



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    ll res = 0;
    while(X >= 500) {
        X = X - 500;
        res += 1000;
    }

    while(X >= 5) {
        X = X - 5;
        res += 5;
    }

    cout << res << endl;
}


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

int main(void)
{
  int n,p,r,k,t,a,count[101];
  int queue[1000000],head=0,tail=0;
  int router[101][101],visited[101],i,j,b;
  
  struct mail{
    int s;
    int d;
    int v;
  }packet[N];
  
  for(i=0;i<101;i++)
    {
      for(j=0;j<101;j++)
	{
	  router[i][j]=0;
	}
    }
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&r,&k);
      
      for(j=1;j<=k;j++)
	{
	  scanf("%d",&t);
	  router[r][t]=1;
	}
    }
  
  for(i=1;i<=n;i++)
    {
      router[i][i]=0;
    }

  scanf("%d",&p);
  
  for(i=1;i<=p;i++)
    {
      scanf("%d%d%d",&packet[i].s,&packet[i].d,&packet[i].v);
    }
  
  for(i=1;i<=p;i++)
    {
      for(b=0;b<101;b++)
	count[b]=0;

      count[packet[i].s]=1;
      queue[tail++]=packet[i].s;
      
      for(b=0;b<=n;b++)
	visited[b]=0;
	    

      visited[packet[i].s]=1;

      while(head!=tail)
	{
	  
	  a=queue[head++];

	  for(j=1;j<=n;j++)
	    {
	      if(router[a][j]==1 && visited[j]==0)
		{
		  queue[tail++]=j;
		  visited[j]=1;
		  count[j]=count[a]+1;	
		} 	      
	    }
	}
        if(count[packet[i].d]<=packet[i].v && count[packet[i].d]!=0)printf("%d\n",count[packet[i].d]);
	else printf("NA\n");
		  
    }
  return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout<< #i<< "= "<< i << endl
using namespace std;
int isfound[26] = {};
int main(){
    string s;
    cin >> s;
    int l = s.length();

    REP(i,l){
        isfound[s[i]-'a']++;
    }
    REP(i,26){
        if(!isfound[i]){
            char ans = ('a' + i);
            cout << ans << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
from functools import reduce
from collections import Counter

MOD = 10**9 + 7
N = int(input())
S = input()

print(
    reduce(lambda x, y: (x * y) % MOD,
           map(lambda x: x + 1,
               Counter(list(S)).values())) - 1)


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

typedef struct node{
  int key;
  struct node *parent, *left, *right;
}Node;

Node *root,*NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
  //zの初期設定
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else{ 
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

Node *find(Node *u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node *getMinimum(Node *x){
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node *getSuccessor(Node *x){
  Node *y;
  if(x->right != NIL) return getMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void deleteNode(Node *z){
  Node *y, *x;
  if((z->left == NIL) || (z->right == NIL)) y = z;
  else y = getSuccessor(z);
  if(y->left != NIL) x = y->left;
  else x = y->right;
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  if(y != z) z->key = y->key;
}

void inParse(Node *u){
  if(u == NIL) return;
  inParse(u->left);
  printf(" %d",u->key);
  inParse(u->right);
}

void preParse(Node *u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preParse(u->left);
  preParse(u->right);
}

int main(){
  int i,n,k;
  Node *findCheck;
  char order[10];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s",order);
    if(strcmp(order,"insert") == 0){
	scanf("%d",&k);
	insert(k);
  }
    else if(strcmp(order,"print") == 0){
      inParse(root);
      printf("\n");
      preParse(root);
      printf("\n");
    }
    else if(strcmp(order,"find") == 0){
      scanf("%d",&k);
      findCheck = find(root,k);
      if(findCheck != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(order,"delete") == 0){
      scanf("%d",&k);
      deleteNode(find(root,k));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=4e6+5;
ll to[maxn],pos[maxn],vis[maxn],mp[maxn];
int main(){
	ll n,k;cin>>n>>k;	
	for(int i=1;i<=n;i++){
		cin>>to[i];
	}
	pos[1]=1;vis[1]=1;mp[1]=1;
	ll now=to[1],cnt=1,dis=0,l=0;
	while(!vis[now]){
		vis[now]=++cnt;
		mp[cnt]=now;
		now=to[now];
		if(vis[now]){
			dis=cnt+1-vis[now];
			l=vis[now];
		}
	}
	k=k+1;
	if(l==0){cout<<"1"<<endl;return 0;}
	if(k<l){
		cout<<mp[k]<<endl;
	}else{
		k=k-l;
		k%=dis;
		k+=l;
		cout<<mp[k]<<endl;
	}
}
/*
3 4
2 2 2
*/









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

int main() {
  ll n;cin>>n;
  ll ans=1,x=1e18;
  bool ng=false;
  rep(i,n){
    ll a;cin>>a;
    if(a==0){
      cout<<0<<endl;
      return 0;
    }
    if(ng||x/a<ans)ng=true;
    ans*=a;
  }
  if(ng)cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3672
#include<iostream>
//#include<CastingInterop.h>
#include<string>
#include<array>
using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	/*string ar[2][3];
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> ar[i][j];
		}
	}
	ar[0][0] == ar[1][2] && ar[1][0] == ar[0][2] && ar[0][1] == ar[1][1]
	*/
	if (a[0]==b[2]&&a[2]==b[0]&&a[1]==b[1])
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

void solve()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans=-1e18;
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout << ans << endl;
    
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();

    return 0;
}  

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


int main(){
	char i;
	cin >> i;
	if(isupper(i)) cout << "A" << endl;
	else           cout << "a" << endl;

}


Measured memory_bytes: 3564
x,y=map(int,input().split())
if x==1:
  if y==1:
    print(1000000)
  elif y==2:
    print(500000)
  elif y==3:
    print(400000)
  else:
    print(300000)
elif x==2:
  if y==1:
    print(500000)
  elif y==2:
    print(400000)
  elif y==3:
    print(300000)
  else:
    print(200000)
elif x==3:
  if y==1:
    print(400000)
  elif y==2:
    print(300000)
  elif y==3:
    print(200000)
  else:
    print(100000)
else:
  if y==1:
    print(300000)
  elif y==2:
    print(200000)
  elif y==3:
    print(100000)
  else:
    print(0)

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

int main(void) {
	int H;
	cin >> H;
	vector<long long int>A(H);
	for (int i = 0; i < H; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end(), greater<long long int>());
	bool issyo = true;
	for (long long int i = 0; i < H; i++) {
		if (A[i] == A[i + 1]) {
			issyo = false;
		}
	}
	if (issyo == false) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

}

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

int main(){
  int age,tax;
  cin >> age >> tax;
  if(age>=13){
  	cout << tax << endl;
  }
  else if((6<=age) && (age<=12)){
  	cout << tax/2 << endl;
  }
  else{
  	cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 21;
const int mod = (int) 1e9 + 7;

int n;
int a[MAXN][MAXN];
int dp[MAXN][(1 << MAXN) + 123];

int main() { 

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

  for (int i = 0; i < n; i++) {
    for (int mask = 0; mask < (1 << n); mask++) {
      if (__builtin_popcount(mask) != i + 1) {
        continue;
      }
      for (int j = 0; j < n; j++) {
        if (a[i][j] == 0 || (mask & (1 << j)) == 0) {
          continue;
        }
        if (i == 0) {
          dp[i][mask] = (dp[i][mask] + 1) % mod;
        } else {
          dp[i][mask] = (dp[i][mask] + 1ll * dp[i - 1][mask ^ (1 << j)] % mod) % mod;
        }
      }
    }
  }

  cout << dp[n - 1][(1 << n) - 1] << endl;

  return 0;
}


Measured memory_bytes: 160000
import java.util.*;
import java.util.Collections;

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();
    String ans = "NO";
    for (int i = A; i <= A * B; i += A) {
      if (i % B == C) {
        ans = "YES";
        break;
      }
    }
    System.out.println(ans);
  }

  public static void primeFactorization(int num) {
    int Z = 0;
    for (int i = 2; num > i; i++) {
      while (num % i == 0) {
        System.out.println(i);
        num /= i;
        Z = num;
      }
    }
    System.out.println(Z);
  }

  public static boolean isPrime(int num) {
    if (num < 2)
      return false;
    else if (num == 2)
      return true;
    else if (num % 2 == 0)
      return false;

    for (int i = 3; i < num; i += 2) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 21716
#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*(q+1)
right = [0]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    #l≦d<rを満たすdがxでぶつかる
    #各dにおいて一番最初にぶつかるxを求めたい
    while l < r:
        while ans[l] != -1:
            l = right[l]
        if r <= l:
            break
        ans[l] = x
        right[l] = r
        l += 1
for i in ans[:-1]:
    print(i)


Measured memory_bytes: 109996
s = list(input())

#sは回文
for i in range(len(s)//2):
    if s[i] != s[-i-1]:
        print('No')
        exit()

#Sの1文字目から(N−1)/2 文字目まで(両端含む)からなる文字列は回文
s_begin = s[:len(s)//2:]
for j in range(len(s_begin)//2):
    if s_begin[j] != s_begin[-j-1]:
        print('No')
        exit()

#Sの(N+3)/2文字目からN文字目まで(両端含む)からなる文字列は回文
s_end = s[len(s)//2+1::]
for k in range(len(s_end)//2):
    if s_end[k] != s_end[-k-1]:
        print('No')
        exit()

print('Yes')



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

int main() {
  
  int a, b;
  std::cin >> a >> b;
  
  if (a * b % 2 == 0) {
    std::cout << "No" << endl;
  } else {
    std::cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

#define int ll
void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>p(n),c(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
	}
	rep(i,n)cin>>c[i];
	ll ans=-INF;
	rep(i,n){
		int cnt=k;
		ll res=0;
		vector<bool>used(n);
		int s=i;
		int nx=s;
		int loop=1;
		vector<ll>v(n),res_v(n);
		ll val=0;
		while(cnt>0){
			nx=p[nx];
			if(used[nx]){
				loop=v[nx]-cnt;
				val=res-res_v[nx];
				break;
			}
			res_v[nx]=res;
			res+=c[nx];
			chmax(ans,res);
			v[nx]=cnt;
			--cnt;
			used[nx]=true;
		}
		//cout<<loop<<"\n";
		if(val>0&&cnt>0){
			if(cnt/loop>=1)res+=(cnt/loop-1)*val,cnt=cnt%loop+loop;
			else res+=cnt/loop*val,cnt=cnt%loop;
			int pos=0;
			chmax(ans,res);
			while(cnt>0&&pos<=2*(loop+1)){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
		else{
			int pos=0;
			while(cnt>0&&pos<=loop+1){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
	}
	cout<<ans;
}
#undef int
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+2;j++){
			if(j<n)
			 dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
		}
	}
	cout<<dp[n-1]<<" ";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int count = 0;
		for(; scanner.hasNext();)
		{
			String input = scanner.next();
			String inverse = "";
			
			for(int i=input.length(); i>0; i--)
			{
				inverse += input.substring(i-1, i);
			}
			
			if(input.equals(inverse))
			{
				count ++;
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 26020
#include<stdio.h>
#include<math.h>
int main(void)
{
	int t,y,h,n;
	int a,b,c;
	int s,s1,s2[10000],i;
	int r[10000];

	scanf("%d %d %d",&t,&y,&h);
	while(t!=0 && y!=0 && h!=0){
		a=t+y;
		b=t+h;
		c=y+h;
		if(a<b && a<c){
			s=t*t+y*y;
			s1=sqrt(s);
		}
		else if(b<a && b<c){
			s=t*t+h*h;
			s1=sqrt(s);
		}
		else if(c<a && c<b){
			s=y*y+h*h;
			s1=sqrt(s);
		}

		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&r[i]);
			s2[i]=r[i]*2;
			if(s1<s2[i]){
				printf("OK\n");
			}
			else {
				printf("NA\n");
			}
		}
		scanf("%d %d %d",&t,&y,&h);
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  rep(i, s.size()) cout << "x";
  
  cout << endl;
    
  return 0;
}


Measured memory_bytes: 256
//ABC086C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	char x, y;
	cin >> x >> y;
	if(x < y){
		cout << "<" << endl;
	}else if(x == y){
		cout << "=" << endl;
	}else{
		cout << ">" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val H = readLine()!!.split(" ").map(String::toInt)
    var sum = 1
    for (i in 1 until N) {
        var b = true
        for (j in 0 until i) {
            if (H[i] < H[j]) {
                b = false
                break
            }
        }
        if (b) {
            sum++
        }
    }
    println(sum)
}

Measured memory_bytes: 36152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main()
{
    vector<int> num(26, 0);
    int iru2=0,iru4=0;
    int h, w;
    cin >> h >> w;
    char c;
    rep(i, h) rep(j, w)
    {
        cin >> c;
        num.at(c - 'a')++;
    }

    sort(all(num));
    

    for (int i = min(h, w); 1 < i; i -= 2)
    {

        for (int j = 0; j < (i / 2); j++)
        {
            iru4++;
        }

        if(i%2==1){
            iru2++;
        }

        for (int j = 0; j < (max(h,w)+i-min(h,w)-2)/2; j++)
        {
            iru4++;
        }
        if(max(h,w)%2==1){
            iru2++;
        }

    }

    if (min(h,w)%2==1)
    {
        for(int i=0;i < (max(h,w)-min(h,w)+1)/2;i++)
        {
            iru2++;
        }
        //最後の一つはどうでもいい
    }
//cout<<iru2<<":"<<iru4<<endl;
    while(iru4--){
        auto it=lower_bound(all(num),4);
        if(it==num.end()){
            cout<<"No"<<endl;
            return 0;
        }
        num.at(it-num.begin())-=4;
        sort(all(num));
    }
    


    while(iru2--){
        auto it=lower_bound(all(num),2);
        if(it==num.end()){
            cout<<"No"<<endl;
            return 0;
        }
        num.at(it-num.begin())-=2;
        sort(all(num));
    }
    cout<<"Yes"<<endl;
}

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

using namespace std;

int a[10];

int main() {
	int sum = 0;
	for(int i = 1; i <= 7; i ++) cin >> a[i];
	long long ans = 0;
	ans += a[1] / 2 * 2;
	ans += a[2];
	ans += a[4] / 2 * 2;
   	ans += a[5] / 2 * 2;
	if(a[1]-- && a[4]-- && a[5]--) ans = max(ans, (long long)3 + a[1]/2*2+a[4]/2*2+a[5]/2*2 + a[2]);
	printf("%lld\n", ans);
}


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

using namespace std;

int main(){
  int i, j, t, n, m, x, y, sum;
  vector<int> data;

  cin >> t;

  for(i=0; i<t; ++i){
    cin >> n >> m;

    for(j=0; j<n; ++j){
      cin >> x;
      if(j != 0) data.push_back(x-y);
      y = x;
    }

    sum = 0;
    if(n > m){
      sort(data.begin(), data.end());
      for(j=0; n>m; ++j, --n) sum += data[j];
    }

    cout << sum << endl;
    data.clear();
  }

  return 0;
}

Measured memory_bytes: 1428
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n ;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<n;i++){
		cout<<s[i]<<t[i];
	}
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 3584
a, b, c, d = [int(s) for s in input()]
ans = [str(a), '+', str(b), '+', str(c), '+', str(d), '=7']
for i in range(-1, 2, 2):
  for j in range(-1, 2, 2):
    for k in range(-1, 2, 2):
      if a + b * i + c * j + d * k == 7:
        ans[1] = '+' if i > 0 else '-'
        ans[3] = '+' if j > 0 else '-'
        ans[5] = '+' if k > 0 else '-'
print(''.join(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a==b&&b==c)cout<<"No";
	else if(a==b||a==c||b==c)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int a = sc.nextInt();
	if(a<1200){
		System.out.println("ABC");
		return;
	}
	// 出力
	System.out.println("ARC");
	}
 }


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

using namespace std;

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

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

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

struct Vertex {
    vector<pll> node;
};

Vertex V[105];
ll C[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        ll n, k;
        cin >> n >> k;
        REP(_, k) {
            ll v, c;
            cin >> v >> c;
            V[n].node.push_back(pll(v, c));
        }
    }
    REP(i, N) {
        C[i] = INF;
    }
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
    q.push(pll(0, 0));
    C[0] = 0;
    while (!q.empty()) {
        pll t = q.top();
        q.pop();
        if (C[t.first] < t.second)
            continue;
        for (auto &n : V[t.first].node) {
            ll nxt = n.first;
            ll cost = n.second + t.second;
            if (C[nxt] <= cost)
                continue;
            C[nxt] = cost;
            q.push(pll(nxt, cost));
        }
    }

    REP(i, N) {
        cout << i << " " << C[i] << endl;
    }
    return 0;
}


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

int main(void)
{
	long long n, q;
	cin >> n >> q;
	vector<queue<long long> >res(n);
	while (q--)
	{
		int op;
		cin >> op;
		if (op == 0)
		{
			long long t, x;
			cin >> t >> x;
			res[t].push(x);
		}
		else if (op == 1)
		{
			long long t;
			cin >> t;
			if (!res[t].empty())
				cout << res[t].front() << endl;
		}
		else if (op == 2)
		{
			long long t;
			cin >> t;
			if (!res[t].empty())
				res[t].pop();
		}
	}
	return 0;
}


Measured memory_bytes: 5236
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll a , ll mod ){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}

ll mul(ll a,ll b,ll m)
{
    return (a%m*b%m)%m;
}
  
 


int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<ll> pre(m);
    cin>>pre[0];
    for(int i=1;i<m;i++)
    {
        ll b;
        cin>>b;
        pre[i] = pre[i-1] + b;
    }
    ll s = 0;
    ll ans = 0;;
    int g = lower_bound(pre.begin(),pre.end(),k) - pre.begin();
    if(pre[g]!=k)
        g--;
    ans = g+1;
    for(ll i=0;i<n;i++)
    {
        s+=a[i];
        if(k-s<0)
            continue;
        ll g = lower_bound(pre.begin(),pre.end(),k-s) - pre.begin();
        if(pre[g]!=k-s)
            g--;
        ans = max(ans,g+1+i+1);
    }
    cout<<ans;
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed : "<< 1.0*clock() / CLOCKS_PER_SEC << " s\n";
    #endif
    
    return 0;
}

Measured memory_bytes: 6364
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int BubbleSort(vector<int> vi, int n)
{
  int flag = 1;
  int times = 0;
  while(flag)
  {
    flag = 0;
    for(int j=n-1; j>0; j--)
    {
      if(vi[j] < vi[j-1])
      {
        swap(vi[j], vi[j-1]);
        times++;
        flag = 1;
      }
    }
  }
  for(int i=0; i<n; i++)
  {
    if(i != 0)
      printf(" ");
    printf("%d", vi[i]);
  }
  printf("\n");
  printf("%d\n", times);
  return 0;
}
int main()
{
  vector<int> vi;
  int n;
  scanf("%d", &n);
  for(int i=0; i<n; i++)
  {
    int temp;
    scanf("%d", &temp);
    vi.push_back(temp);
  }
  BubbleSort(vi, n);

  return 0;
}



Measured memory_bytes: 3220
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n;
			n = sc.nextInt();
			if(n==0)break;
			int sum=0;
			for(int i=0;i<n/4;i++){
				sum += sc.nextInt();
			}
			System.out.println(sum);
		}
	}

}

Measured memory_bytes: 26124
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 998244353;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
//unordered_map
typedef long long ll;
ll fac[MAXN],inv[MAXN];
ll qpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=(ans%mod*a%mod)%mod;
		a=(a%mod*a%mod)%mod;
		b>>=1;
	}
	return ans%mod;
} 
ll C(int i,int n)
{
	return ((fac[n]%mod*inv[n-i]%mod)%mod*inv[i]%mod)%mod;
}
//没看到复杂度 应该是组合数 
int main()
{
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	ll ans=0;
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=(fac[i-1]%mod*i%mod)%mod;
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;i--) inv[i]=(inv[i+1]%mod*(i+1)%mod)%mod;
	ans=0;
	//printf("%lld\n",ans);
	for(int i=n-k;i<=n;i++)
	{
		ans=(ans+m*qpow(m-1,i-1)%mod*C(i-1,n-1)%mod)%mod;
	//	printf("%d %lld %lld %lld %lld\n",n-i,sum,C(1,n-i),qpow(m-1,n-i-1),ans);
	}
	printf("%lld\n",ans);
}

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

using namespace std;

using ll =long long;

ll M,N;
ll A;


int main()
{
    cin >> N >> M;
    ll sum = 0;
    for(int i = 0;i < M;i++)
    {
        cin >> A;
        sum += A;
    }
    ll ans = N - sum;
    cout << (ans >= 0 ? ans : -1) << endl;
    return 0;
}


Measured memory_bytes: 3164
import java.util.*;

public class Main {
    List<String> list = new ArrayList<String>();
    Map<Integer,Integer> map = new HashMap<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String T = sc.next();
        sc.close();
        System.out.println(T.replace("?", "D"));
    }
}


Measured memory_bytes: 41036
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll x[m],b[m];
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    if(n>=m){
        cout <<0<<endl;
        return 0;
    }
    sort(x,x+m);
    for(int i=0;i<m-1;i++){
        b[i]=x[i+1]-x[i];
    }
    sort(b,b+(m-1));
    for(int i=m-2;i>m-1-n;i--){
        b[i]=0;
    }
    ll sum=0;
    for(int i=0;i<m-1;i++){
        sum+=b[i];
    }
    cout << sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int a[n];
    for(int i=0;i<4;i++){
        a[0]=i%2;
        a[1]=i/2;
        for(int i=1;i<n-1;i++){
            if(s[i]=='o')a[i+1]=a[i-1];
            else a[i+1]=a[i-1]^1;
            if(a[i])a[i+1]^=1;
        }
        bool can=true;
        if(s[n-1]=='o'){
            if(a[n-1]&&a[n-2]==a[0])can=false;
            else if(!a[n-1]&&a[n-2]!=a[0])can=false;
        }
        else{
            if(a[n-1]&&a[n-2]!=a[0])can=false;
            else if(!a[n-1]&&a[n-2]==a[0])can=false;
        }
        if(s[0]=='o'){
            if(a[0]&&a[n-1]==a[1])can=false;
            else if(!a[0]&&a[n-1]!=a[1])can=false;
        }
        else{
            if(a[0]&&a[n-1]!=a[1])can=false;
            else if(!a[0]&&a[n-1]==a[1])can=false;
        }
        if(can){
            for(int i=0;i<n;i++){
                if(a[i]==0)cout<<'S';
                else cout<<'W';
            }
            cout<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


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

// ABC 083 B
int main() {
  int N, A, B;
  int ans = 0;
  cin >> N >> A >> B;

  for (int i = 0; i <= N; i++) {
    int sum = 0;
    int n = i;
    while (n) {
      sum += n % 10;
      n /= 10;
    }
    if (sum >= A && sum <= B) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
int a[500005];
char s[500005];
int main()
{
	scanf("%s",s);
	int n=strlen(s),sum=0,ans;
	for (int i=0;i<n;i++) a[n-i-1]=(s[i]-'0')*9;
	for (int i=0;i<n;i++)
	{
		a[i+1]+=a[i]/10;
		sum+=a[i]%=10;
	}
	sum+=a[n];
	for (ans=0;sum>ans;ans+=9)
	{
		a[0]+=9;sum+=9;
		for (int i=0;a[i]>9;a[++i]++)
		{
			a[i]-=10;
			sum-=9;
		}
	}
	printf("%d\n",ans/9);
	return 0;
}


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

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    Combination comb(n+2);
    vector<int> used(n+1, -1);
    int l = 0, r = 1;
    rep(i,n+1){
        int a;
        cin >> a;
        if(used[a] == -1) used[a] = i;
        else{
            l = used[a];
            r = i;
        }
    }
    for(int k = 1; k <= n+1; ++k){
        mint ans = comb(n+1, k) - comb(n-r+l, k-1);
        cout << ans.x << endl;
    }
	return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  vector<long long> as(n);
  for (long long &a : as) cin >> a;
  sort(as.begin(), as.end());
  reverse(as.begin(), as.end());

  long long result = 0;
  for (int i = 1; i < n; i++) {
    result += as[i / 2];
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4768
#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,z;
    cin>>n>>z;
    vector<ll> x(n),y(n);
    rep(i,n){
      cin>>x[i]>>y[i];
    }
    ll ans=4*1e18;
    rep(i,n){//左辺
      rep(j,n){//右辺
        if(x[i]>=x[j]){
          continue;
        }
        rep(k,n){//上辺
          rep(l,n){//下辺
            if(y[l]>=y[k]){
              continue;
            }
            ll wid=x[j]-x[i];
            ll hei=y[k]-y[l];
            ll cnt=0;
            rep(m,n){
              if(x[i]<=x[m] && x[m]<=x[j] && y[l]<=y[m] && y[m]<=y[k]){
                cnt++;
              }
            }
            if(cnt>=z && ans>wid*hei){
              //cout<<wid<<' '<<hei<<' '<<cnt<<'\n';
              ans=wid*hei;
            }
          }
        }
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long ans = 1;
		
		
		for (int i = 1; i <= N; i++) {
			ans = (ans * i) % 1000000007;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

ll comb(ll N_, ll C_) {
	const int NUM_ = 2000010;
	static ll fact[2000020], factr[2000020], inv[2000020];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}
ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

int solve(int x, int y) {
	//cout << x << " " << y << endl;
	int res = 0;
	y += x;
	y++;
	while (y > x) {
		res += comb(y--, x);
		res %= mod;
	}
	//cout << res << endl;
	return res;
}


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

	
	int a, b, c, d; cin >> a >> b >> c >> d;
	a--; b--;
	int ans = solve(c, d);
	ans -= solve(a, d);
	ans = (ans + mod) % mod;
	ans -= solve(c, b);
	ans = (ans + mod) % mod;
	ans += solve(a, b);
	ans %= mod;
	cout << ans << endl;
	return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll w, h, n;
  cin >> w >> h >> n;
  ll l = 0, b = 0;
  rep(i, 0, n){
    ll x, y, a;
    cin >> x >> y >> a;
    if(a == 1 && x > l) l = x;
    if(a == 2 && x < w) w = x;
    if(a == 4 && y < h) h = y;
    if(a == 3 && y > b) b = y;
  }
  ll area = (w - l) * (h - b);
  cout << (w - l < 0 || h - b < 0 ? 0 : area) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a;
int main(){
	ios::sync_with_stdio(false);
	cin>>a;
	if(a=='a'||a=='o'||a=='i'||a=='u'||a=='e'){
		cout<<"vowel"<<endl;
	}else{
		cout<<"consonant"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

#0埋め　桁合わせ
def digit(n, r):
    n = str(n)
    l = len(n)
    for i in range(r - l):
        n = '0' + n
    return n

def solv(i):
    global honest, flag
    tmp = []
    for j in range(len(arr[i])):
        if honest[arr[i][j][0] - 1] == arr[i][j][1]:
            pass
        else:
            flag = False
            break

n = INT()
arr = []
for _ in range(n):
    a = INT()
    arr.append([LIST() for _ in range(a)])
ans = 0
for i in range(2 ** n):
    bitstr = digit(bin(i)[2:], n)
    honest = [int(i) for i in bitstr]
    flag = True
    for j in range(n):
        if honest[j]:
            solv(j)
        if not flag:
            break
    debug(flag, honest)
    if flag:
        ans = max(ans, honest.count(1))
print(ans)

Measured memory_bytes: 68440
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
  int n,l;
  cin >> n >> l;
  vector<string> a(n);
  for(int i = 0 ; i < n; i++){
      cin >> a[i];
  }
  sort(a.begin(), a.end());
  for(int i = 0 ; i < n; i++){
      cout << a[i];
  }
}


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

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = write!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! eprintln {
    () => { eprintln!(""); };
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = writeln!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! dbg {
    ($v:expr) => {{
        let val = $v;
        eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
        val
    }}
}

macro_rules! mat {
    ($($e:expr),*) => { Vec::from(vec![$($e),*]) };
    ($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
    ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
    ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
    ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
        $a$([$i])*.$f($($t),*)
    };
    ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
        let t = $e;
        ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
    } };
}

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
    ($($t:tt),*; $n:expr) => {{
        let stdin = ::std::io::stdin();
        let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
            let line = line.unwrap();
            let mut it = line.split_whitespace();
            _read!(it; $($t),*)
        }).collect::<Vec<_>>();
        ret
    }};
    ($($t:tt),*) => {{
        let line = readln();
        let mut it = line.split_whitespace();
        _read!(it; $($t),*)
    }};
}

macro_rules! _read {
    ($it:ident; [char]) => {
        _read!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        Vec::from(_read!($it; String).into_bytes())
    };
    ($it:ident; usize1) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_read!($it; $t)),*)
    };
}


pub fn main() {
    let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/3;

fn solve() {
    let n = read!(usize);
    let ans = (1000 - n%1000)%1000;
    println!("{}",ans);
}

fn run() {
    solve();
}

Measured memory_bytes: 2268
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

using Pair = pair<LL, pii>;

int N;
int M;
LL X[114514];
bool ok[114514];
int belong[114514];
vector<int> es[114514];
vector<int> vs[114514];
vector<Pair> eds;
vector<LL> we;

int main() {
  scanf("%d%d", &N, &M);
  rep(i, N) {
    scanf("%lld", &X[i]);
    we.eb(X[i]);
    belong[i] = i;
    vs[i].eb(i);
  }

  rep(i, M) {
    int a, b;
    LL y;
    scanf("%d%d%lld", &a, &b, &y);
    --a;
    --b;
    eds.eb(Pair(y, pii(a, b)));
  }
  sort(all(eds));

  rep(i, M) {
    auto &e = eds[i];

    LL c = e.X;
    int u, v;
    tie(u, v) = e.Y;

    int p = belong[u];
    int q = belong[v];
    if (p != q) {
      LL tot = we[p] + we[q];
      if (vs[p].size() < vs[q].size()) swap(p, q);
      for (int v : vs[q]) {
        vs[p].eb(v);
        belong[v] = p;
      }

      if (es[p].size() < es[q].size()) {
        for (int v : es[p]) {
          es[q].eb(v);
        }
        es[p].swap(es[q]);
      } else {
        for (int v : es[q]) {
          es[p].eb(v);
        }
      }

      we[p] = tot;
      if (c <= we[p]) {
        ok[i] = true;
        while (!es[p].empty()) {
          int v = es[p].back();
          ok[v] = true;
          es[p].pop_back();
        }
      } else {
        es[p].eb(i);
      }
    } else {
      if (c <= we[p]) {
        ok[i] = true;
      } else {
        es[p].eb(i);
      }
    }
    //uf.unite(u, v);
    //int r = uf.root(u);
    //we[r] = we[p] + we[q];
  }

  int ans = 0;
  rep(i, M) {
    ans += !ok[i];
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 18672