akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    
    class Program
    {
      
        static void Main(string[] args)
        {          
            string str01 = Console.ReadLine();            
            string str02 = Console.ReadLine();

            int[] start = new int[26];
            int[] goal = new int[26];

            for(int i = 0; i < 26; i++)
            {
                start[i] = -1;
                goal[i] = -1;
            }

            for(int i = 0; i < str01.Length; i++)
            {
                int a = str01[i] - 'a';
                int b = str02[i] - 'a';

                if(start[a] != -1 || goal[b] != -1)
                {
                    if(start[a] != b || goal[b] != a)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else
                {
                    start[a] = b;
                    goal[b] = a;
                }


            }

            Console.WriteLine("Yes");

        }
    }
}


Measured memory_bytes: 13208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int a[3];
    for (int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a + 3);

    cout << ((a[0] == 5 && a[1] == 5 && a[2] == 7) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner( System.in );
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		
		int a = 0;
		int b = 0;
		int c = 0;
		
		boolean status = true;
		char winner = 'A';
		char next = 'a';
		while( status ){
			switch ( next ){
			case 'a':
				if( a == A.length() ) 
				{
					winner = 'A';
					status = false;
					break;
				};
				next = A.charAt(a);
				a++;
				break;
			case 'b':
				if( b == B.length() ) 
				{
					winner = 'B';
					status = false;
					break;
				};
				next = B.charAt(b);
				b++;
				break;
			case 'c':
				if( c == C.length() ) 
				{
					winner = 'C';
					status = false;
					break;
				};
				next = C.charAt(c);
				c++;
				break;
			}
				
		}
		System.out.println( winner );
	}
}

Measured memory_bytes: 8660
def main():
    n = int(input())
    primes = get_primes_less_than(55556)
    out = []
    num = 0
    for prime in primes:
        if prime%5 == 1:
           out.append(prime)
           num += 1
        if n == num:
            print(*out)
            return

def get_primes_less_than(x):
    ans = []
    if x < 3:
        return ans
    if x == 3:
        ans.append(2)
        return ans
    else:
        for i in range(3, x, 2):
            if all(i%j for j in ans):
                ans.append(i)
    return ans
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int n,ans,frnt=4280;
  while(1){
    ans=1150;
    cin>>n;
    if(n==-1)break;
    if(n>=30)ans+=1250+1400+(n-30)*160;
    else if(n>=20)ans+=1250+(n-20)*140;
    else if(n>=10)ans+=(n-10)*125;
    cout<<frnt-ans<<endl;
  }
}

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int a, b, k; cin >> k >> a >> b;
  for (int i = a; i <= b; ++i) if (i % k == 0){
    cout << "OK"; return 0;
  }
  cout << "NG";
}



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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

char c[101][101];
int main() {
  int H,W;
  cin >> H >> W;
  vector<int> x;
  vector<int> y;
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> c[i][j];
      if( c[i][j] == '#' ) x.push_back(j), y.push_back(i);
    }
  };
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  for( auto i : y ){
    for(auto j : x ){
      cout << c[i][j];
    }
    cout << endl;
  }


  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a;i < b;i++)
#define rrep(i,a,b) for(int i = a;i >= b;i--)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << #x << ": " << x << endl;
typedef long long ll;
using namespace std;

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

   int n,ans = 0,max = -100;
   cin >> n;
   int h[n];
   rep(i,0,n){
      cin >> h[i];
   }
   rep(i,0,n){
      if(h[i] >= max){
         ans++;
         max = h[i];
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXN 100010
#define NUM 1000000007

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

int N, T;
int level[MAXN];

int main(void) {
    cin >> N >> T;
    for (int i = 0; i < N; i++) {
        cin >> level[i];
    }
    sort(level, level+N);
    ll ans = 1;
    for (int i = 1; i < N; i++) {
        // level[i]がどこに挿入されても大丈夫か
        int low = -1, high = i;
        // (low, high]が範囲とする
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (level[mid] < level[i] - T) low = mid;
            else high = mid;
        }
//        cout << "low:" <<low << endl;
        ans = (ans * (i-low)) % NUM;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int n;
    cin >> n;

    cout << (n%1000? 1000 - n%1000 : 0)<< endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define ll long long
unordered_map<int, int>mp;

signed main(){
    ll N;
    cin>>N;
    ll A[N];
    for(int i=0; i<N; i++){
        cin>>A[i];
        mp[A[i]]++;
    }
    ll count=0;
//    signed a = 100000;
//    cout<<a*a;
    for(auto p: mp){
        count += (((p.second-1)*(p.second))/2);
    }
//    cout<<4*3/2<<endl;
    for(int i=0; i<N; i++){
        int tmp = mp[A[i]];
        cout<<count - ((tmp*(tmp-1))/2) + ((tmp-1)*(tmp-2)/2)<<endl;
    }
    return 0;
}




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

int main(void){
    int X;
    int A;
    
    scanf("%d %d",&X,&A);
    
    if (X<A){
        printf("0\n");
    }
    else{
        printf("10\n");
    }
    return 0;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int n, m, result = 0;
  string ns[101], ms[101];
  cin >> n;
  list_input(ns, n)
  cin >> m;
  list_input(ms, m)
  map<string, int> mp;
  rep(i, n){
    auto is_find = mp.find(ns[i]);
    if (is_find != mp.end()) {
      mp[ns[i]] += 1;
    }else{
      mp[ns[i]] = 1;
    }
  }

  rep(i, m){
    auto is_find = mp.find(ms[i]);
    if (is_find != mp.end()) {
      mp[ms[i]] -= 1;
    }
  }

  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
    result = max(result, itr->second);
  }

  puts(result)

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,a[10],b[10],ans;
int p;
 
void saiki(int ima,int sum){
  if(sum==p) ans++;
  if(ima==n||sum>=p) return;
  for(int i=0;i<=b[ima];i++) saiki(ima+1,sum+a[ima]*i);
}
 
int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    int m;
    cin>>m;
    while(m--){
      cin>>p;
      ans=0;
      saiki(0,0);
      cout <<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2!=0){
            cout<<"first"; return 0;
        }
    }
    cout<<"second";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(a); sll(b); sll(t);
	pll(b*(t/a)); nl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


// dijikstra
/* int V;
vector<edge> G[10];
int d[10];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int main(){
    int a, b;
    bool flag = true;
    cin >> a >> b;
    char c;
    REP(i, a){
        cin >> c;
        if(c == '-') flag = false;
    }
    cin >> c;
    if(c != '-') flag = false;
    REP(i, b){
        cin >> c;
        if(c == '-') flag = false;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

using i64 = long long int;
using ui64 = unsigned long long int;

////////

using pic = pair<int,char>;
#define mp make_pair
using psic = pair<stack<int>,char >;

pic parse(string &s){
    return make_pair(s.length()-1,s[s.length()-1]);
}

void calc(deque<psic> &q, int lv){
    while(q.size() > lv){
        psic p = q.back();
        
        q.pop_back();
        // cerr << q.size() << " " << p.second << endl;
        if(p.second == '+'){
            int ret = 0;
            while(!p.first.empty()){
                ret += p.first.top();
                p.first.pop();
            }
            q.back().first.push(ret);
        }
        else if(p.second == '*'){
            int ret = 1;
            while(!p.first.empty()){
                ret *= p.first.top();
                p.first.pop();
            }
            q.back().first.push(ret);
        }else assert(false);
    }
}

int solve(deque<psic> &q){
    calc(q,1);
    psic p = q[0];
    if(p.second == '+'){
        int ret = 0;
        while(!p.first.empty()){
            ret += p.first.top();
            p.first.pop();
        }
        return ret;
    }
    else if(p.second == '*'){
        int ret = 1;
        while(!p.first.empty()){
            ret *= p.first.top();
            p.first.pop();
        }
        return ret;
    }else assert(false);
}

int main(){
    int n;
    while(cin >> n,n){
        int curlv = 0;
        deque< psic > q;
        q.push_back(mp(stack<int>(),'+'));

        for(int i=0;i<n;i++){
            string s;
            cin >> s;
            
            pic ps = parse(s);
            // cerr << ps.first << " " << ps.second << endl;
            if(ps.first < curlv){
                calc(q,ps.first + 1);
                curlv = ps.first;
                if(ps.second == '+' || ps.second == '*'){
                    psic ne;
                    ne.second = ps.second;
                    q.push_back(ne);
                    curlv++;
                } 
                else{
                    q.back().first.push(((int)(ps.second-'0')));
                }
            }
            else if(ps.first == curlv){
                if(ps.second == '+' || ps.second == '*'){
                    psic ne;
                    ne.second = ps.second;
                    q.push_back(ne);
                    curlv++;
                } 
                else{
                    q.back().first.push(((int)(ps.second-'0')));
                }
            }else assert(false);
        }
        cout << solve(q) << endl;
    }
}



Measured memory_bytes: 3076
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R


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

	cin >> N >> K;
	vector<vector<int>>edge(N + 1);
	int box = 0;
	while ((1 << box) < N) {
		for (int i = (1 << box) + 1; i <= N; i++) {
			if ((i >> box) & 1)edge[1 << box].push_back(i);
		}
		box++;
	}
	vector<pair<int, int>>ret;
	for (int i = 1; i <= N; i++) {
		for (auto j : edge[i]) {
			ret.push_back({ i,j });
		}
	}
	cout << ret.size() << endl;
	for (auto i : ret) {
		cout << i.first << " " << i.second << endl;
	}
	for (int i = 0; i < K; i++) {
		int box = 1;
		int ans = 0;
		bool flag = false;
		while (box <= N) {
			cout << box << endl;
			string s;
			cin >> s;
			if (s == "Yes") {
				flag = true;
				break;
			}
			else if (s == "Near")ans += box;
			box *= 2;
		}
		if (!flag) {
			cout << ans << endl;
			string s;
			cin >> s;
		}
	}
	return 0;
}



Measured memory_bytes: 3304
import sys
def input():
    return sys.stdin.readline()[:-1]

"""
H Wの後に
#.#.
###.
みたいな文字列を受け取る
"""
H,W = map(int,input().split(' '))
MAP = [['#']*(W+1)] + [None]*H

for i in range(1,H+1):
    MAP[i] = ['#'] + list(map(str,input()))
import queue
q = queue.Queue()


MAP[H][W] = 'G'
visited = [None]*(H+1)
for i in range(H+1):
    visited[i] = [False]*(W+1)

d_num = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if MAP[i][j]=='#':
            d_num += 1

def is_okay(x,y):
    if not (0<x<W+1) or not (0<y<H+1):
        return False
    if visited[y][x] or MAP[y][x]=='#':
        return False
    return True

n = 0
q.put([1,1,n])
ans = 10**7 + 7

while not q.empty():
    x,y,n = q.get()
    k = MAP[y][x]

    n += 1
    if k=='G':
        ans = min(ans,n)
        break

    if is_okay(x+1,y):
        q.put([x+1,y,n])
        visited[y][x+1] = True
    if is_okay(x-1,y):
        q.put([x-1,y,n])
        visited[y][x-1] = True
    if is_okay(x,y+1):
        q.put([x,y+1,n])
        visited[y+1][x] = True
    if is_okay(x,y-1):
        q.put([x,y-1,n])
        visited[y-1][x] = True


if not ans==10**7 + 7:
    ANS = H*W - ans - d_num
else:
    ANS = -1

print(ANS)

Measured memory_bytes: 45928
n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x,p,f = [],0,0
for i in range(m):
    b,c = (int(i) for i in input().split())
    x.append((-c,b))
x,a = sorted(x),sorted(a)
for i,j in x:
    for k in range(p,min(n,p+j)):
        if a[k]<-i: a[k] = -i
        else:
            f = 1
            break
    p = min(n,p+j)
    if f or p>=n: break
print(sum(a))

Measured memory_bytes: 22520
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){

    input!{
        a: usize,
        b: f64,
    }
    //let b_tmp: usize = (b*(100 as f64)) as usize;
    // println!("{}", b_tmp);
    println!("{}", a*(((b+0.001)*(100 as f64)) as usize)/100);

}

Measured memory_bytes: 2168
n,m = map(int,input().split())
a = list(map(int,input().split()))
sum = 0
count = 0
for i in range(n):
    sum += a[i]
sum /= 4*m
for i in range(n):
    if a[i] >= sum:
        count +=1
if count >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N = int(input())

A_list = list( map(int, input().split() ) )
B_list = list( map(int, input().split() ) )
C_list = list( map(int, input().split() ) )
# print(d,n,m)
# print(A_list)
# print(B_list)
# print(C_list)

A_sort = sorted(A_list)
C_sort = sorted(C_list)

# print("A:", A_sort)
# print("C:", C_sort)

def is_ok_lower(list_data, index: int, key: int):
    if (list_data[index] >= key):
        return True
    else:
        return False

def is_ok_upper(list_data, index: int, key: int):
    if (list_data[index] > key):
        return True
    else:
        return False


def binary_search(list_data, key: int, is_ok_func):
    ng = -1  #「index = 0」が条件を満たすこともあるので、初期値は -1
    ok = len(list_data) # 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    # どんな二分探索でもここの書き方を変えずにできる！
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2

        if (is_ok_func(list_data, mid, key)):
            ok = mid
        else:
            ng = mid

    # left は条件を満たさない最大の値、ok は条件を満たす最小の値になっている
    return ok

sum_conbi = 0
for B in B_list:
    a_key = binary_search(A_sort, B, is_ok_lower)
    c_key = binary_search(C_sort, B, is_ok_upper)

    # print(a_key, N-c_key)
    # print(B,">", A_sort[:a_key])
    # print(B,"<", C_sort[c_key:])

    sum_conbi += (a_key) * (N-c_key)

print(sum_conbi)


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll p[N];
  for(ll i=0;i<N;i++)cin>>p[i];
  ll ans=0;
  for(ll i=1;i+1<N;i++){
    ans += min(p[i-1],p[i+1])<p[i]&&p[i]<max(p[i-1],p[i+1]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a == 1) {
    a = 14;
  }
  if (b == 1) {
    b = 14;
  }
  if (a > b) {
    printf("Alice\n");
  } else if (a < b) {
    printf("Bob\n");
  } else {
    printf("Draw\n");
  }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	cin >> n;
	vector<int> v(n), c(n);
	REP(i, n) cin >> v[i];
	REP(i, n) cin >> c[i];
	vector<int> diff(n);
	int sum = 0;
	REP(i, n) {
		diff[i] = v[i] - c[i];
		if (diff[i] < 0) diff[i] = 0;
		sum += diff[i];
	}
	cout << sum << endl;
	return 0;
}



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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
ll a[maxn];
ll cnt[maxn];
void run_case()
{
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += 1ll * a[i];
        cnt[a[i]]++;
    }
    int q;
    cin >> q;
    while (q--)
    {
        int b, c;
        cin >> b >> c;
        sum = sum - cnt[b] * b + cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << "\n";
    }
    //cout << sum << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 5160
/**
*    created: 11.07.2020 01:00:27
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int a, b; cin >> a >> b;
    int x; cin >> x;
    if (a == 0) cout << b/x + 1 << endl;
    else cout << b/x - (a-1)/x << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int A, B; cin >> A >> B;

    rep(i, 2000) {
        if (floor(i * 0.08) == A && floor(i * 0.1) == B) {
            cout << i << endl;
            exit(0);
        }
    }
    cout << -1 << endl;
}


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

int main()
{
    string S;
    cin >> S;
    bool easy_dance = true;
    for (int i=0; i<S.size(); i++) {
        if (i % 2 == 0) {
            if (S[i] == 'L') easy_dance = false;
        }
        if (i % 2 == 1) {
            if (S[i] == 'R') easy_dance = false;
        }
    }
    if (easy_dance) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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


int main() {
	int H, W;
	vector<string> a;
	int dx[] = { 1,-1,0,0 };
	int dy[] = { 0,0,1,-1 };
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		string temp;
		cin >> temp;
		a.push_back(temp);
	}


	int ans = 0;
	vector<vector<bool> > reached(H, vector<bool>(W, false));
	vector<vector<int> > num(H, vector<int>(W, 0));
	queue<pair<int, int> > q;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '#') {
				q.emplace(i, j);
				reached[i][j] = true;
			}
		}
	}

	while (!q.empty()) {
		pair<int, int> now = q.front();
		int now_x = now.first;
		int now_y = now.second;
		q.pop();
		for (int k = 0; k < 4; k++) {
			int nex = now_x + dx[k];
			int ney = now_y + dy[k];
			if (nex >= 0 && nex < H && ney >= 0 && ney < W && !reached[nex][ney]) {
				q.emplace(nex, ney);
				reached[nex][ney] = true;
				num[nex][ney] = num[now_x][now_y] + 1;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, num[i][j]);
		}
	}

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

Measured memory_bytes: 13712
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<complex>
#include<bitset>
#include<iostream>
using namespace std;

/**** Type Define ****/

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;


/**** main function ****/
char ans[4] ="Yes";

ll N,d=0;
struct ABC {
	ll A, B, C;
};
int main() {
	scanf("%lld",&N);
	vector<ABC> abc(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld %lld", &abc[i].A, &abc[i].B);
		abc[i].C = abc[i].B -abc[i].A;
	}

	sort(abc.begin(), abc.end(), [](const ABC& s, const ABC& t) {return s.B < t.B;});

	for (ll i = 0; i < N; i++) {
		d += abc[i].A;
		if (d> abc[i].B)
		{
			strcpy(ans, "No");
			break;
		}

	}

	printf("%s", ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

int main() {
    string s;cin>>s;
    ll ans = 0;
    int w = 0;
    rep(i,s.size()){
        if(s[i]=='W'){
            ans += i-w;
            w++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <iostream>
#define ll long long
using namespace std;
int main()
{
  
  ll N, a, b;
  ll div;
  ll count = 0;
  cin>>N>>b>>a;
  ll sum = a+b;
      div = N/sum;
    count = b*div;
    N=N-(div*sum);
       if(b!=0)
    {
     if(N>b)
       count = count+b;
        else
          count = count+N;
      }
  cout<<count<<"\n";
       
  return 0;
}
  
  
      
    

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

string solve(string s, int L[]){

}

int main(){

    int  i;
    bool L[27] = {false};
    string s;

    cin >> s;

    for(i = 0; i < s.length(); ++i){
        if( L[(int)s[i] - 97] ){
            cout << "-1";
            return 0;
        }else{
            L[(int)s[i] - 97] = true;
        }
    }
    if(s.length() < 26){
        i = 0;
        while(L[i])i++;
        s += (char)(i + 97);
        cout << s;
        return 0;
    }else{
        i = 25;
        while( true ){
            if(i == -1){cout << "-1"; return 0;}
            int aux = (int)s[i] - 97;
            L[aux] = false;
            aux += 1;
            for(; aux <= 25; ++aux){
                if(!L[aux]){
                    s [i]= (char)(aux + 97);
                    cout << s;
                    return 0;
                }
            }

            s.erase(s.begin() + i);
            --i;
        }
    }
}


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 m = sc.nextLong();
		ArrayList<Abc> abl = new  ArrayList<>(n);
		int i;
		for(i = 0; i < n; i++) {
			Abc ab = new Abc(sc.nextLong(), sc.nextLong());
			abl.add(ab);
		}
		sc = null;
		Collections.sort(abl, new Abcmp());
		long yen = 0;
		long m1 = m;
		for(i = 0; i < n; i++) {
			if(m1 >= abl.get(i).b) {
				yen += abl.get(i).a * abl.get(i).b;
				m1 -= abl.get(i).b;
			} else {
				yen += abl.get(i).a * m1;
				break;
			}
		}
		System.out.println(yen);
	}
}

class Abc {
	long a;
	long b;
	Abc(long a, long b) {
		this.a = a;
		this.b = b;
	}
}

class Abcmp implements  Comparator<Abc> {
	@Override
	public int compare(Abc p1, Abc p2) {
		return p1.a < p2.a ? -1 : (p1.a > p2.a ? 1 : 0);
	}
}


Measured memory_bytes: 92196
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
int main(void){
    int a, b;
    cin>>a>>b;
    int now=1;
    int ans=0;
    while(now<b){
        now=now-1+a;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n, m, c,sum=0,count=0;
	cin >> n >> m >> c;
	vector<int>b(m);
	int a[20][20];
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		sum = 0;
		for (int j = 0; j < m; j++) {
			sum += a[i][j] * b[j];
			if (j == m - 1) {
				sum += c;
				if (sum > 0) {
					count++;
				}
			}
		}
	}
	cout << count << endl;

}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
asum = sum(a)

cnt = 0
for i in a:
	if i >= asum / (4 * m):
		cnt = cnt + 1

	if (m==cnt):
		print('Yes')
		exit(0)

print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) ); 
// 大文字65-90(-32)
// 小文字97-122(+32)

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n; cin >> n;

  int d=1;
  vector<vector<int>> lr(10, vector<int>(10,0));
  bool isend = false;
  // i 桁数
  // l 最高位の桁
  // k 実際の値
  // nになるか桁数を満足するまで、計算を行う
  rep(i,6){
    repz(l,1,10){
      repz(k,l*d,(l+1)*d){
        if(k>n){
          isend = true;
          break;
        }
        int r = k%10;
        lr[l][r]++;
      }
      if(isend) break;
    }
    if(isend) break;
    d*=10;
  }

  ll res=0;
  rep(r,10){
    rep(l,10){
      res+=lr[r][l]*lr[l][r];
    }
  }
  cout << res << endl;

  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
struct UnionFind{
    vector<int> nxt;
    vector<int> num;
    void init(int x){
        nxt.clear();
        nxt.resize(x);
        num.clear();
        num.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
            num[i] = 1;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        
        nxt[find(y)] = find(x);
        num[find(x)]++;
    }
    int getnum(int x){
        return num[find(x)];
    }
};



ll N,M,Q;
UnionFind uf;
vector<pll> ab0v,ab1v;
ll i, j, k, ans;
int main(){
    scanf("%lld%lld%lld", &N, &M,&Q);
    
    fornum(i,0,Q){
        ll a,b,c;
        scanf("%lld%lld%lld", &a, &b, &c);
        if(c==0){
            ab0v.push_back({a, b});
        }else{
            ab1v.push_back({a, b});
        }
    }
    if(M==N-1){
        if(ab1v.size()==0){
            printf("Yes");
        }else{
            printf("No");
        }
    }else{
        uf.init(N + 1);
        //printf("a");
        fornum(i,0,ab0v.size()){
            pll ab = ab0v[i];
            uf.unite(ab.first, ab.second);
        }
        
        fornum(i,0,ab1v.size()){
            pll ab = ab1v[i];
            if(uf.find(ab.first)==uf.find(ab.second)){
                break;
            }
        }
        if(i<ab1v.size()){
            printf("No");
            return 0;
        }
        j = 0;
        fornum(i,0,N){
            if(uf.find(i)==i)
                j++;
        }
        //printf("%lld\n", j);
        if((j-1)*j/2<M-(N-j)){
            printf("No");
        }else{
            printf("Yes");
        }
    }
    return 0;
}

Measured memory_bytes: 3188
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[3001][3001];
ll dp(int i,int j,const vector<ll>&A){
    if(i>j)return 0;
    if(i == j) return A[i];
    if(memo[i][j] != -1)
        return memo[i][j];
    ll res = 0;
    ll r1 = min(dp(i+2,j,A)+A[i],dp(i+1,j-1,A)+A[i]);
    ll r2 = min(dp(i+1,j-1,A)+A[j],dp(i,j-2,A)+A[j]);
    res = max(r1,r2);
    memo[i][j] = res;
    return res;
}

int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);
    vector<ll>A(n+1);
    ll sum = 0;
    for(int i=0;i<n;i++){
        scanf("%lld",&A[i]);
        sum += A[i];
    }
    memset(memo,-1,sizeof(memo));
    ll res = dp(0,n-1,A);
    printf("%lld\n",2*res - sum);
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<int, int> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

bool visited[MAX];

//abc077d
//0-1bfs
void solve(void){
    int K, ans = INF;
    cin >> K;
    deque <P> dq;
    memset(visited, false, sizeof(visited));
    dq.push_front(P(1,1));
    while (!dq.empty()) {
        P next = dq.front();
        dq.pop_front();
        visited[next.first] = true;
        if (next.first%K==0) {
            ans = next.second;
            break;
        }
        if (!visited[(next.first+1)%K]) {
            dq.push_back(P((next.first+1)%K, next.second+1));
        }
        if (!visited[(next.first*10)%K]) {
            dq.push_front(P((next.first*10)%K, next.second));
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	for(int i=0;i+1<(int)s.size();i++) {
		if (s[i]=='A'&&s[i+1]=='C') {
			printf("Yes");return 0;
		}
	}
	printf("No");return 0;
}

Measured memory_bytes: 256
#■標準入力ショートカット

def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def get_next_str():
    return input()
def get_next_strs(delim=" "):
    return tuple(input().split(delim))

def get_next_by_types(*value_types,delim=" "):
    return tuple([t(x) for t, x in zip(value_types,input().split(delim))])

def main(print=print):
    n, m, a, b = get_next_ints()  
    
    result = {} 
    
    if n % 2 == 1:
        for j in range(1,m,2):
            if a == 0:
                break
            result[(n, j)] = "<"
            result[(n, j+1)] = ">"
            a -= 1
    
    if m % 2 == 1:
        for i in range(1,n,2):
            if b == 0:
                break
            result[(i, m)] = "^"
            result[(i+1, m)] = "v"
            b -= 1
    if n % 2 == 1 and a % 2 == 1 and m % 2 == 1 and b % 2 == 1:
        #右下3x3を風車風に詰める
        result[(n, m-2)] = "<"
        result[(n, m-1)] = ">"
        result[(n-2, m-1)] = "<"
        result[(n-2, m)] = ">"
        result[(n-1, m)] = "^"
        result[(n , m)] = "v"
        result[(n-2, m-2)] = "^"
        result[(n-1 , m-2)] = "v"
        a -= 1
        b -=1
        
    inside_n = n - (n % 2)
    inside_m = m - (m % 2)
    #print("inside=",inside_n,inside_m)
    for i in range(1,inside_n+1,2):
        for j in range(1,inside_m+1,2):
            #print(i,j,a,b)
            if a > 0:
                result[(i, j)] = "<"
                result[(i, j+1)] = ">"
                a -= 1
                if a > 0:
                    result[(i+1, j)] = "<"
                    result[(i+1, j+1)] = ">"
                    a -= 1
            elif b > 0:
                result[(i, j)] = "^"
                result[(i+1, j)] = "v"
                b -= 1
                if b > 0:
                    result[(i, j+1)] = "^"
                    result[(i+1, j+1)] = "v"
                    b -= 1
            else:
                break
        if (a + b) == 0:
            break
    if (a + b) > 0:
        print("NO")
    else:
        print("YES")
        for i in range(1, n+1):
            buffer = []
            for j in range(1, m+1):
                buffer.append(result.get((i,j),"."))
            print("".join(buffer))

if __name__ == '__main__':
    main()

Measured memory_bytes: 146280
#include <stdio.h>
int main() {
	int H, W;
	 while (1){
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0)
			break;
		for (int n = 0; n < W; n++)
		{
			printf("#");
		}
		printf("\n");
		for (int i = 0+1; i < H-1; i++)
		{
			printf("#");
			for (int j = 0+1; j < W-1; j++)
			{
				printf(".");
			}
			printf("#");
			printf("\n");
		}
		for (int j = 0; j < W; j++)
		{
			printf("#");
	    }
		printf("\n");
		printf("\n");
	}
	 return 0;
}

Measured memory_bytes: 2592
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 300031;

vector<long long> v;

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	for (int i=0;i<3;i++){
		int val;
		cin>>val;
		v.push_back(val);
	}
	sort(v.begin(),v.end());
	int k;
	cin>>k;
	cout<<v[0]+v[1]+(v[2]<<k);

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256