akhauriyash/Code-Regression huggingface dataset:
def solve(N, A, S):
    B = [0] * 64
    for a, s in zip(reversed(A), reversed(S)):
        if s == '1':
            while a:
                n = a.bit_length() - 1
                if B[n] == 0:
                    return 1
                a ^= B[n]
        else:
            while a:
                n = a.bit_length() - 1
                if B[n] == 0:
                    B[n] = a
                    break
                a ^= B[n]
    return 0
    
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        print(solve(N, A, S))
main()


Measured memory_bytes: 9076
N = gets.to_i
A = gets.split.map(&:to_i)

nums = A.group_by { |x| x }
        .map { |k, v| [ k, v.size ] }
        .to_h

max = []
2.times do |i|
  if nums.select { |k, v| v >= 2 }.size > 0
    max[i] = nums.select { |k, v| v >= 2 }
                 .max_by { |k, v| k }
                 .first
    nums[max[i]] -= 2
  else
    max[i] = 0
  end
end

puts max.inject(1, &:*)

Measured memory_bytes: 33420
S=list(input())
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != "R" and S[i] != "U" and S[i] != "D":
            print("No")
            exit()
    else:
        if S[i] != "L" and S[i] != "U" and S[i] != "D":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
import sys

stdin = sys.stdin

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

li = ["A","T","G","C"]
max = 0
ct = 0
s = input()
for ch in s:
    if ch in li:
        ct += 1
        if max < ct:
            max = ct
    else:
        ct = 0
print(max)

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

int main(){
    long long n,a,b;
    cin >> n >> a >> b;
    long long c = n/(a+b);
    long long r = n%(a+b);
    if(r<=a){
        long long ans = c*a + r;
        cout << ans << endl;
    }
    else{
        long long ans = c*a + a;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def solve(m, d):
	cnt = 0

	for month in range(1, m+1):
		for day in range(22, d+1):
			day1 = day
			d1 = day1%10
			d2 = (day1//10)%10

			if d1 >= 2 and d2 >= 2 and d1*d2 == month:
				cnt += 1

	return cnt


def main():
	m,d = list(map(int, input().strip().split()))

	print (solve(m, d))

if __name__ == "__main__":
	main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
const int MOD = 1000000007;

int V,E; //グラフサイズ
int Tmax; //最大時間
int ans[10010] = {}; //出力用
int G[505][505]; //隣接matrix
int pre[505]; //minimum prev node
int disMin[505]; //最小コスト
bool used[505]; //Visited frag


void dijkstra(int start, int goal){
  rep(i, V) disMin[i] = MOD;
  rep(i, V) pre[i] = -1;
  disMin[start] = 0; //初期位置1
  rep(i,V) used[i] = false;

  while( 1 ){
    int v = -1;
    rep(u, V) {
      if( !used[u] && (v==-1 || disMin[u]<disMin[v]) ) v = u;
    }
    if(v == -1) break;
    used[v] = true;

    rep(u, V) {
      if( disMin[u] > disMin[v] + G[v][u] ){
        disMin[u] = disMin[v] + G[v][u];
        pre[u] = v;
      }
    }
  }
  // cout << "   disMin[i]:"; rep(i, V) cout << disMin[i] << " "; cout << "\n";
}
//(求めた最短経路が終了時刻いないなら)、往復の経路復元をする
vector<int> getPath(int g){
  vector<int> path = {};
  for(; g != -1; g = pre[g]) {
    path.push_back(g);
    // cout << g << "\n";
  }
  return path;
}

int main(void){
  cin >> V >> E; //input graph
  rep(i,V) rep(j,V) G[i][j] = MOD;
  rep(i, E){
    int u,v,dis; cin >> u >> v >> dis;
    G[u-1][v-1] = dis; G[v-1][u-1] = dis;
  }
  cin >> Tmax;
  rep(i,Tmax) ans[i] = -1;

  vector<P> order;
  rep(i, Tmax) {
		int orderSum; cin >> orderSum; //その時刻で発生した注文数
		rep(j, orderSum) {
			int new_id, dest; cin >> new_id >> dest; dest -= 1;
      order.push_back({i, dest});
		}
	}
  int i = 0; int j = 0; int now = 0;
  while(i < order.size() && j < Tmax ){
    dijkstra(now, order[i].second);
    // cout << "dis: " << disMin[order[i].second] << "\n";
    // cout << order[i].first << " "<< j <<  "\n";
    if( j + 2*disMin[order[i].second] < Tmax && j >= order[i].first ){
      vector<int> goPath = getPath( order[i].second );
      reverse( goPath.begin(), goPath.end() );
      for(int k = 1; i<goPath.size();k++) {
        rep(l, G[now][goPath[k]]){
          ans[j] = goPath[k]+1;
          j++;
        }
        now = goPath[k];
        i++;
      }
      vector<int> rePath = getPath( now );
      for(int k = 1; i<rePath.size();k++) {
        rep(l, G[now][rePath[k]]){
          ans[j] = rePath[k]+1;
          j++;
        }
        now = rePath[k];
        i++;
      }
    }else if(j + disMin[order[i].second] < Tmax && j >= order[i].first ){
      vector<int> goPath = getPath( order[i].second );
      reverse( goPath.begin(), goPath.end() );
      for(int k = 1; i<goPath.size();k++) {
        rep(l, G[now][goPath[k]]){
          ans[j] = goPath[k]+1;
          j++;
        }
        now = goPath[k+1];
        i++;
      }
      break;
    }else {
      j++;i++;
    }
  }
  rep(i, Tmax)  cout << ans[i] << "\n"; //output
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int s, w;
    cin >> s >> w ;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    
    return 0;
}



Measured memory_bytes: 3648
N, M = map(int, input().split())
dp = [0 for i in range(N+1)]
for i in range(M):
    A = int(input())
    dp[A] = -1
dp[0] = 1
if dp[1] != -1:
    dp[1] = 1
else:
    dp[1] = 0
for j in range(2, N + 1):
    if dp[j] == -1:
        dp[j] = 0
        continue
    dp[j] = dp[j-2] + dp[j-1]

print(dp[N] % 1000000007)

Measured memory_bytes: 460056
#include<bits/stdc++.h>
using namespace std;
int pos(int x,int y,int h,int w){
	return x*w+y;
}
int main(){
        int h,w,x1,y1,x2,y2;
        cin>>h>>w;
  		cin>>x1>>y1>>x2>>y2;
  		int s=pos(x1-1,y1-1,h,w);
  		int t=pos(x2-1,y2-1,h,w);
        char** G=new char*[h];        
        for(int i=0;i<h;i++){
          G[i]=new char[w];
          for(int j=0;j<w;j++){
          	cin>>G[i][j];
          }            
        }
  		
  		deque<int> q;  		 
  		q.push_front(s);
  		map<int,int> m;
 		m[s]=0;	
  		while(!q.empty()){
          int x=q.front();
          q.pop_front();
          G[x/w][x%w]='#';
          int a=x/w,b=x%w;
          if(a-1>=0&&G[a-1][b]=='.'){
          			int y=pos(a-1,b,h,w);
              		q.push_front(y);                	
            		if(m.find(y)!=m.end()&&m[y]<=m[x])
                        m[y]=m[y];
                    else{
                        m[y]=m[x];
                      	q.push_back(y);
                    }
          }
          if(a+1<h&&G[a+1][b]=='.'){
          			int y=pos(a+1,b,h,w);
              		q.push_front(y);                	
                	if(m.find(y)!=m.end()&&m[y]<=m[x])
                        m[y]=m[y];
                    else{
                        m[y]=m[x];
                      	q.push_back(y);
                    }
          }
          if(b-1>=0&&G[a][b-1]=='.'){
          			int y=pos(a,b-1,h,w);
              		q.push_front(y);                	
                	if(m.find(y)!=m.end()&&m[y]<=m[x])
                        m[y]=m[y];
                    else{
                        m[y]=m[x];
                      	q.push_back(y);
                    }
          }
          if(b+1<w&&G[a][b+1]=='.'){
          			int y=pos(a,b+1,h,w);
              		q.push_front(y);                	
                	if(m.find(y)!=m.end()&&m[y]<=m[x])
                        m[y]=m[y];
                    else{
                        m[y]=m[x];
                      	q.push_back(y);
                    }
          }
          for(int i=a-2;i<a+3;i++){
            for(int j=b-2;j<b+3;j++){              
              if(i>=0&&i<h&&j>=0&&j<w&&G[i][j]=='.'){
                	int y=pos(i,j,h,w);              		                	
                	if(m.find(y)!=m.end()&&m[y]<=m[x]+1)
                        m[y]=m[y];
                    else{
                        m[y]=m[x]+1;
                      	q.push_back(y);
                    }
              }                
            }
          }          
        }
  		if(m.find(t)!=m.end())
        	cout<<m[t]<<endl;
  		else
          	cout<<-1<<endl;
}


Measured memory_bytes: 27892
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main() {
	cin.tie(0); 
	ios::sync_with_stdio(false);
	int count = 0;
	int num;
	int dig;
	int n;
	int sum = 0;

	cin >> n;

	num = n;

	while (num) {
		dig = num % 10;
		if (dig > 0) {
			count++;
		}
		sum += dig;
		num = num / 10;
	}

	if (count == 1 && n / 10 > 0) {
		cout << 10;
		return 0;
	}
	cout << sum;

	return 0;
}

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

int main()
{
    int a[3];
    int five = 0;
    int seven = 0;
    cin >> a[0] >> a[1] >> a[2];
    for (int i = 0; i < 3; i++)
    {
        if (a[i] == 5)
            five++;
        else if (a[i] == 7)
            seven++;
    }

    if (five == 2 && seven == 1)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    int n; cin >> n;
    int ans = 0;
    vector<int> ar(n);
    vector<int> al(n);
    rep(i,n) cin >> ar[i];
    rep(i,n) cin >> al[i];
    rep(i,n){
        ans += max(0,ar[i] - al[i]);
    }
    cout << ans << endl;
}

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

#define ll long long
#define mod 1000000007
#define mod2 998244353

#define ff first
#define ss second
#define pb push_back
#define vec vector
#define gcd(a,b) __gcd((a),(b))
using namespace std;

bool prime[100005+5];

int SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
             for (int i=p*p; i<=n; i += p)
                prime[i] = false;
                }
    }
    return 0;
}


int main(){
    //cin>>t
    ll x,n=100005;
    cin>>x;
    SieveOfEratosthenes(100005+5);
    for(ll i=2;i<n;i++){
        if(i>=x && prime[i]){
            cout<<i;
            break;
        }
    }

    //}

    return 0;
}

Measured memory_bytes: 384
X = gets.to_i

if (400..599).include? X
 puts 8
elsif (600..799).include? X
  puts 7
elsif (800..999).include? X
  puts 6
elsif (1000..1199).include? X
  puts 5
elsif (1200..1399).include? X
  puts 4
elsif (1400..1599).include? X
  puts 3
elsif (1600..1799).include? X
  puts 2
elsif (1800..1999).include? X
  puts 1
end


Measured memory_bytes: 14432
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val arr = Array.fill(N)(sc.nextInt()).sorted(Ordering.Int.reverse)
    println(if (arr.head < arr.tail.sum) "Yes" else "No")
  }

}


Measured memory_bytes: 25652
#include<stdio.h>
int main(void)
{
	int a, b, c, i = 0, ave = 0, n[3];
		scanf("%d %d %d", &a, &b, &c);

		if (a == b && b == c)
		{
			printf("No");
		}
		else if (a != b && b == c)
		{
			printf("Yes");
		}
		else if (b != c && c == a) {
			printf("Yes");
		}
		else if (c != a && a == b) {
			printf("Yes");
		}
		else {
			printf("No");
		}
		
}

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

const long long MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    long long ans = 1;
    for (int i = 1; i <= n; i++) {
        ans *= (long long)i;
        ans %= MOD;
    }
    cout << ans << endl;
}   

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut ans = 0;
    for i in 1..n + 1 {
        if i % 2 != 1 {
            continue;
        }
        let mut cnt = 0;
        for j in 1..i + 1 {
            if i % j == 0 {
                cnt += 1;
            }
        }
        if cnt == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define diup(a, b) (a % b == 0 ? a / b : a / b + 1)
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	string s = "";
	s += s1[0] - 'a' + 'A';
	s += s2[0] - 'a' + 'A';
	s += s3[0] - 'a' + 'A';

	cout << s;
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
import sys


xs = list(sys.stdin.readline().split(' '))
a,b,c,d = [int(x) for x in xs]

f = (lambda x,y: abs(x - y) <= d)
g = (lambda x,y,z: f(x,y) or (f(x,z) and f(y,z)))

if g(a,c, b):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int n;
    cin >> n;
    REP(i, 10) {
        if (111 * i >= n) {
            cout << 111 * i << endl;
            return 0;
        }
    }
}


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

ll x;

int main() {
    cin>>x;
    ll l=0, r=x,m;
    while (l<r){
        m=(l+r)/2;
        if (m*(m+1)/2>=x) r=m;
        else l=m+1;
    }
    cout<<r;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

  int cnt = 0;

  public static Integer[] getG(int n) {
    // via https://stackoverflow.com/questions/2539545/fastest-gap-sequence-for-shell-sort
    int[] optimal = {1, 4, 10, 23, 57, 132, 301, 701, 1750};
    List<Integer> G = new ArrayList<Integer>();
    int i = 0;
    int num = optimal[i];
    G.add(num);
    while (num < n) {
      i++;
      if (i < optimal.length) {
        num = optimal[i];
      } else {
        num = (int)(num * 2.25);
      }
      if (num < n)
        G.add(num);
    }
    Collections.reverse(G);
    Integer[] G_ = new Integer[G.size()];
    G_ = G.toArray(G_);
    return G_;
  }

  public static void display(Integer[] a) {
    for (int i = 0; i < a.length; i++) {
      System.out.print(a[i]);
      if (i != a.length - 1)
        System.out.print(" ");
      else
        System.out.print("\n");
    }
  }

  public int[] insertionSort(int[] A, int n, int g) {

    for (int i = g; i < n; i++) {
      int v = A[i];
      int j = i - g;
      while (j >= 0 && A[j] > v) {
        A[j+g] = A[j];
        j = j - g;
        this.cnt++;
      }
      A[j + g] = v;
    }

    return A;
  }

  public int[] shellSort(int[] A, int n) {

    Integer[] G = getG(n);
    int m = G.length;

    // Display for aizu
    System.out.println(m);
    display(G);

    int[] result = new int[0];
    for (int i = 0; i < m; i++) {
      result = this.insertionSort(A, n, G[i]);
    }

    System.out.println(this.cnt);

    return result;
  }

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[] A = new int[n];
    for (int i = 0; i < n; i++) {
      A[i] = s.nextInt();
    }
    Main x = new Main();
    int[] result = x.shellSort(A, n);
    for (int i = 0; i < result.length; i++) {
      System.out.println(result[i]);
    }
	}
}



Measured memory_bytes: 300008
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct fenwick {
	vector<int> t;
	int n;

	fenwick(int _n) {
		n = _n;
		t.assign(n, 0);
	}
	int sum(int r) {
		int res = 0;
		for(; r >= 0; r = (r & (r + 1)) - 1) {
			res += t[r];
		}
		return res;
	}
	int sum(int l, int r) {
		return sum(r) - sum(l - 1);
	}

	void update(int pos, int delta) {
		for(; pos < n; pos = (pos | (pos + 1))) {
			t[pos] += delta;
		}
	}
};

main() {
	int n, q;
	cin >> n >> q;
	fenwick fenw(n);
	for(int i = 0; i < n; i++) {
		int val;
		cin >> val;
		fenw.update(i, val);
	}
	while(q--) {
		int id, l, r;
		cin >> id >> l >> r;
		if(!id) {
			fenw.update(l, r);
		} else {
			cout << fenw.sum(l, r - 1) << endl;
		}
	}
}

Measured memory_bytes: 8220
using namespace std;
#include <iostream>
#include <string>
#include <vector>
#include <map>

typedef vector<int> VI;
typedef pair<int, int> PII;

#define REP(i, n) for(int i=0; i<n; i++)

PII solve(string ans, string call)
{
	int nHit = 0;
	int nBlow = 0;

	//count up hit
	REP(i, ans.size())
	{
		if(ans[i] == call[i])
		{
			nHit++;
		}
	}

	REP(i, ans.size())
	{
		REP(j, call.size())
		{
			if(i != j && ans[i]==call[j])
			{
				nBlow++;
			}
		}
	}

	return PII(nHit, nBlow);
}

int main()
{
	string ans, call;
	while( 1 )
	{
		cin >> ans;
		cin >> call;
		if(ans == "0" && call == "0")
			break;

		PII out = solve(ans, call);
		printf("%d %d\n", out.first, out.second);
	}
}

Measured memory_bytes: 0
def solve(V, E, G):
    done = [False] * V
    def dfs(i, path):
        path.add(i)
        for j in G[i]:
            if j in path:
                return True
            if not done[j] and dfs(j, path):
                return True
        path.remove(i)
        done[i] = True
        return False
    for i in range(V):
        if not done[i] and dfs(i, set()):
            return 1
    return 0

v,e=map(int,input().split())
g=[set() for _ in range(v)]
for _ in range(e):
    s,t=map(int,input().split())
    g[s].add(t)

#閉路を持つ場合1,持たない場合0
print(solve(v,e,g))


Measured memory_bytes: 5620
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int a,b,c,d;
    double f;
    cin >> a >> b;
    f = (double)a/b;
    d = a/b;
    c =a % b;
    
    
    cout << fixed << setprecision(5) << d << " " << c << " " << f << endl;
}


Measured memory_bytes: 3268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <deque>
using namespace std;

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;
	vector <int> v;
	map <int, long long> m;
	v.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		m[v[i]]++;
	}
	
	vector <int> vv = v;
	sort(vv.begin(), vv.end());
	auto result = unique(vv.begin(), vv.end());
	vv.resize(distance(vv.begin(), result));

	long long sum = 0;
	for (int i = 0; i < vv.size(); ++i) {
		sum += m[vv[i]] * (m[vv[i]] - 1) / 2;
	}

	for (int i = 0; i < v.size(); ++i) {
		cout << sum - m[v[i]] * (m[v[i]] - 1) / 2 + (m[v[i]] - 1) * (m[v[i]] - 2) / 2 << endl;
	}
}

Measured memory_bytes: 11136
n,m = map(int,input().split())
S = []
for _ in range(m):
    S.append(list(map(int,input().split()))[1:])
P = list(map(int,input().split()))

ans = 0
for i in range(2**n):
    state = bin(i)[2:]
    state = '0'*(n - len(state)) + state
    state = [int(i) for i in state]
    flag=1
    for j in range(m):
        sum_k = 0
        for k in S[j]:
            sum_k += state[k-1]
        if sum_k %2 != P[j]:
            flag = 0
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi H(N);
  rep(i,N) {
    cin >> H[i];
  }
  int prevH = INF;
  drep(i,N) {
    if(prevH < H[i] - 1) {
      cout << "No" << endl;
      return 0;
    }
    if(prevH == H[i]-1) {
      H[i]--;
    }
    prevH = H[i];
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
int main(){
  map<int,int> pr,th;
  string s;
  bool f = true;
  int a;
  while(getline(cin,s)){
    if(s.find(',') == string::npos){f = false; continue;}
    sscanf(s.c_str(),"%d,%*d",&a);
    if(f) pr[a]++;
    else if(th[a]!=0) th[a]++;
    else if(pr[a]!=0) th[a] = pr[a]+1;
  }
  for(map<int,int>::iterator it = th.begin(); it!=th.end(); it++)
    if(it->second!=0)
      cout <<(it->first)<<" "<<(it->second)<<endl;
  return 0;
}

Measured memory_bytes: 1236
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int n, m, v;
	bool f = 1;
	cin >> n;
	map<int, int> mp;
	rep(i, 0, n)cin >> v, mp[v]++;
	cin >> m;
	rep(i, 0, m) {
		cin >> v;
		mp[v]--;
		if (mp[v] < 0)f = 0;
	}
	puts(f?"YES":"NO");
	return 0;
}


Measured memory_bytes: 9600
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

s = input()
N = len(s)

indices = [[] for _ in range(26)]

for i,c in enumerate(s):
    indices[ord(c)-ord('a')].append(i)


res = N-1
for l in indices:
    if not l:
        continue

    t = 0
    for a,b in zip([-1]+l,l+[N]):
        t = max2(t,b-a-1)
    res = min2(res, t)

print(res)

Measured memory_bytes: 8936
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int r, g, b;
  	cin >> r >> g >> b;
  	if( (10*g+b)%4 == 0 ){puts("YES");}
  	else{puts("NO");}
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    long[] t = new long[n];
    long[] a = new long[n];
    for (int i = 0; i < n; i++) {
      t[i] = s.nextLong();
      a[i] = s.nextLong();
    }
    long ct = t[0];
    long ca = a[0];
    for (int i = 1; i < n; i++) {
      long kt = ct / t[i] + (ct % t[i] > 0 ? 1 : 0);
      long ka = ca / a[i] + (ca % a[i] > 0 ? 1 : 0);
      long k = Math.max(kt, ka);
      ct = k * t[i];
      ca = k * a[i];
    }
    System.out.println(ct + ca);
  }
}


Measured memory_bytes: 12908
#include<iostream>

using namespace std;

int main(){
  int N,X;
  int L[100];
  L[0]=0;
  cin >> N >> X;
  for(int i=1; i<=N;i++){
    cin >> L[i];
    L[i]+=L[i-1];
  }
  bool a=false;
  for(int i=0;i<=N;i++){
    if(X<L[i]){
      cout << i <<endl;
      a=true;
      break;
    }
  }
  if(!a){
    cout << N+1<< endl;
  }
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef VI  Vec;
typedef VVI Mat;

void debug(const Mat M) {
  int n = M.size();
  rep (i, n) {
    rep (j, n) {
      cout << M[i][j] << " ";
    }
    cout << endl;
  }
  cout << "---" << endl;
}

Mat mul(const Mat& A, const Mat& B) {
  int n = A.size();
  Mat res = Mat(n, Vec(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        res[i][j] += A[i][k] * B[k][j];
        if (res[i][j] > 1) res[i][j] = 1;
      }
    }
  }
  return res;
}

// x^k mod m を計算
Mat pow(Mat A, int k) {
  int n = A.size();
  Mat res = Mat(n, Vec(n, 0));
  rep(i, n) res[i][i] = 1;
  while(k > 0) {
    if (k & 1) {
      res = mul(res, A);
      // debug(res);
    }
    A = mul(A, A);
    k >>= 1;
  }
  return res;
}

struct Edge {
  int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

bool solve(int n, int m, int z) {
  vector<Edge> es;
  es.push_back(Edge(-1, 0));  // 初期値用のダミーのエッジ
  rep(i, m) {
    int s, d;
    cin >> s >> d;
    s--;
    d--;
    es.push_back(Edge(s, d));
    es.push_back(Edge(d, s));
  }
  // 各エッジをもとにグラフを構築
  int gn = es.size();
  Mat g(gn, Vec(gn, 0));
  rep(i, gn) {
    Edge& e1 = es[i];
    rep(j, gn) {
      Edge& e2 = es[j];
      if (e1.to == e2.from && e1.from != e2.to) {
        // 直前に戻る辺でなく辿れるので辺を張る
        g[j][i] = 1;
      }
    }
  }
  // debug(g);
  
  Mat trasimitted = pow(g, z);
  rep(i, gn) {
    if (trasimitted[i][0] > 0 && es[i].to == n - 1) return true;
  }
  return false;
}

int main() {
  int n, m, z;
  while (cin >> n >> m >> z, n||m||z) cout << (solve(n, m, z) ? "yes" : "no") << endl;
  
  return 0;
}

Measured memory_bytes: 1380
#include<bits/stdc++.h>
using namespace std;
int main() {
  long A, B, K, z; cin >> A >> B >> K;
  if (A<=K){
    if (B-(K-A)>0){
      B = B-(K-A);
      A = 0;
    }
    else{
      B = 0;
      A = 0;
    }
  }
  else{
    A = A-K;
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if   ((a + b) % 3 == 0 || (a % 3 ==0) || (b % 3 ==0)) {
			System.out.println("Possible");
		}else
			System.out.println("Impossible");
	}
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  vector<int> a(m);
  rep(i, m){
    cin >> a[i];
    sum += a[i];
  }
  if(n < sum) {
    cout << -1 << endl;
  }else {
    cout << n - sum << endl;
  }
}

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

int main() 
{
    // Count function
    int n;
    cin >> n;
    vector <int> v(n);
    for (int i=0; i<n; i++)
        cin >> v[i];
    int sum = 1;
    int max = v[0];
    for (int i=1; i<n; i++)
    {
        if (v[i] >= max)
        {
            sum ++;
            max = v[i];
        }
    }
    cout << sum;        
    return 0;
}

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

int main(void)
{
  int i,n,m,a,sum=0,ans;
  scanf("%d%d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d",&a);
    sum+=a;
  }

  ans=n-sum;

  if(ans<0)
    printf("-1");
  else
    printf("%d",ans);

	return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
string L;
ll Q, q[200010][4], num, X, Y, bit[200010];
vector<P> xcd;
 
ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
 
void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}
 
ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}
 
ll div(ll x)
{
	return po(x, mod - 2);
}
 
int main(void)
{
	cin >> Q;
	for (int i = 0; i < Q; i++)
	{
		cin >> q[i][0];
		if (q[i][0] == 1)
		{
			cin >> q[i][1] >> q[i][2];
			xcd.push_back(P(q[i][1], i));
		}
	}
	num = xcd.size();
	sort(xcd.begin(), xcd.end());
	for (int i = 0; i < num; i++)
	{
		q[xcd[i].second][3] = i + 1;
	}
	ll t = 1;
	for (int i = 0; i < Q; i++)
	{
		if (i == 0)
		{
			X = q[i][1], Y = q[i][2];
			add(q[i][3], 1);
			t++;
		}
		else if (q[i][0] == 1)
		{
			ll half = (t + 1) / 2;
			add(q[i][3], 1);
			ll lb = 0, ub = num;
			while (lb + 1 < ub)
			{
				ll mid = (lb + ub) / 2;
				if (sum(mid - 1) >= half)
				{
					ub = mid;
				}
				else
				{
					lb = mid;
				}
			}
			if (t % 2 == 0)
			{
				Y += abs(xcd[lb - 1].first - X) + q[i][2] + abs(q[i][1] - xcd[lb - 1].first);
			}
			else
			{
				Y += abs(q[i][1] - xcd[lb - 1].first) + q[i][2];
				if (q[i][1] < X)
				{
					Y += 2 * abs(X - xcd[lb - 1].first);
				}
			}
			X = xcd[lb - 1].first;
			t++;
		}
		else
		{
			cout << X << ' ' << Y << endl;
		}
	}
	int www;
	cin >> www;
}

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

signed main () {
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	map < char, vector < int > > nxt;
	for (int i = 0; i < n; ++i) 
		nxt[s[i]].push_back(i);
	int64_t ans = 0;
	int i = 0;
	bool fucked = 0;
	while (i < m) {
		int j = -1;
		while (j < n && i < m) {
			ans -= j + 1;
			if (nxt[t[i]].empty()) {
				fucked = 1;
				break;
			}
			else {
				auto it = upper_bound(nxt[t[i]].begin(), nxt[t[i]].end(), j);
				if (it == nxt[t[i]].end())
					break;
				else {
					j = *it;
					ans += j + 1;
				}
				++i;
			}
		}
		if (i == m || fucked)
			break;
		else
			ans += n;
	}
	if (fucked)
		ans = -1;
	cout << ans << '\n';
}


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

long long mod = 1000000000+7;
int main(){
  long long N,K;
  cin >> N >> K;
  long long ans = 0;
  for(long long i=K; i<=N+1; i++){
    long long min_value = i*(i-1)/2;
    long long max_value = i*(N-i+1+N)/2;
    long long diff = max_value - min_value+1;
    ans = (ans+diff%mod)%mod;
  }
  cout << ans << endl;
  return 0;
}

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

i64 dp[101][4][4][4];
i64 MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  rep(i) rep(j) rep(k) {
    dp[3][i][j][k] = 1;
  }
  dp[3][0][1][2] = 0;
  dp[3][0][2][1] = 0;
  dp[3][1][0][2] = 0;
  for(int a = 4;a <= N;a++) {
    rep(i) rep(j) rep(k) rep(n) {
      if(j == 0 && k == 1 && n == 2) continue;
      if(j == 0 && k == 2 && n == 1) continue;
      if(j == 1 && k == 0 && n == 2) continue;
      if(i == 0 && k == 1 && n == 2) continue;
      if(i == 0 && j == 1 && n == 2) continue;
      (dp[a][j][k][n] += dp[a - 1][i][j][k]) %= MOD;
    }
  }

  i64 ans = 0;
  rep(i) rep(j) rep(k) {
    (ans += dp[N][i][j][k]) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
a,b=list(map(int,input().split()))
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
print (len(Base_10_to_n(a, b)))

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>

int main(int argc, const char * argv[]) {
    int n;
    scanf("%d", &n);
    
    int m;
    scanf("%d", &m);
    
    std::map<int, std::set<int>> map;
   
    for (int i = 0; i < m; i++) {
        int k;
        scanf("%d", &k);
        
        std::set<int> set;
        
        for (int j = 0; j < k; j++) {
            int x;
            scanf("%d", &x);
            
            set.insert(x - 1);
        }
        
        map[i] = set;
    }
    
    std::vector<bool> p;
    
    for (int i = 0; i < m; i++) {
        int x;
        scanf("%d", &x);
        
        p.push_back(x);
    }
    
    int count = 0;
    
    int max = 1 << n;
    for (int i = 0; i < max; i++) {
        bool on = true;
        
        for (int j = 0; j < m; j++) {
            bool sw = false;
            
            for (int k : map.at(j)) {
                sw ^= (i & (1 << k)) != 0;
            }
            
            if (sw != p.at(j)) {
                on = false;
                break;
            }
        }
        
        if (on) count++;
    }
    
    printf("%d\n", count);
    
    return 0;
}


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


int main() {

    int n;
    cin >> n;
    set<int> d;
    rep(i, n) {
        int a; cin >> a;
        d.insert(a);
    }
    cout << d.size() << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

const int inf = 1e9;
vector<pair<int,int> > vec;

int n, a, b;


#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};


typedef Point<ll> P;

pair<vi, vi> ulHull(const vector<P>& S) {
	vi Q(sz(S)), U, L;
	iota(all(Q), 0);                                                                                                                                                                         
	sort(all(Q), [&S](int a, int b){ return S[a] < S[b]; });
trav(it, Q) {
#define ADDP(C, cmp) while (sz(C) > 1 && S[C[sz(C)-2]].cross(\
	S[it], S[C.back()]) cmp 0) C.pop_back(); C.push_back(it);
		ADDP(U, <=); ADDP(L, >=);
	}   
	return {U, L}; 
}

vi convexHull(const vector<P>& S) {
	vi u, l; tie(u, l) = ulHull(S);
	if (sz(S) <= 1) return u;
	if (S[u[0]] == S[u[1]]) return {0};
	l.insert(l.end(), u.rbegin()+1, u.rend()-1);
	return l;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	vector<P> v;
	for(int i = 0; i < n; ++i){
		cin>>a>>b;
		Point<ll> p(a, b);
		v.emplace_back(p);
	}
	auto res = convexHull(v);
	ll t = 0;
	for(int i = 0; i < res.size(); ++i){
		for(int j = i + 1; j < res.size(); ++j){
			ll ans = abs(v[res[i]].x - v[res[j]].x) + abs(v[res[i]].y - v[res[j]].y);
			t = max(t, ans);
		}
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 7424
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int l;
	string s;
	while (cin >> s >> l, l) {
		int cnt = 0;
		vector<string>v;

		while (s.size() < l)s = '0' + s;
			
		v.push_back(s);
		
		while (1) {

			string big(s), small(s);

			sort(small.begin(), small.end());
			sort(big.begin(), big.end(), greater<int>());
			s = to_string(stoi(big) - stoi(small));
			while (s.size() < l)s = '0' + s;
			v.push_back(s);
			int f = distance(v.begin(), find(v.begin(), v.end(), s));


			if (f!=v.size()-1) {
				cout << f << " " << stoi(s) << " " << v.size()-1-f << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3232
#include <iostream>
#include <map>
#include <string>
#include <queue>
#include <string.h>
#include <math.h>
#define ll long long
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int maxe,mine,max_pos,min_pos;
	maxe = -10000005,max_pos = 1;
	mine = -maxe,min_pos = 1;
	int num[55];
	for(int i=1;i<=n;i++)
		cin>>num[i];
	for(int i=1;i<=n;i++)
	{
		if(maxe < num[i])
		{
			maxe = num[i];
			max_pos = i;
		}
		if(num[i] < mine)
		{
			mine = num[i];
			min_pos = i;
		}
	}
	cout<<n*2-2<<endl;
	if(abs(maxe) >= abs(mine))
	{
		for(int i=1;i<=n;i++)
		{
			if(i == max_pos);
			else
				cout<<max_pos<<" "<<i<<endl;
		}
		for(int i=2;i<=n;i++)
		{
			cout<<i-1<<" "<<i<<endl;
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			if(i == min_pos);
			else cout<<min_pos<<" "<<i<<endl;
		}
		for(int i=n-1;i>=1;i--)
		{
			cout<<i+1<<" "<<i<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int k, n;
	cin >> k >> n;
	if (500 * k >= n) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

int main(){
  int N; cin>>N;
  set<int> q;
  for(int i=0; i<N; i++){
    int a; cin>>a;
    q.insert(a);
  }
  if(q.size()==N){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
}

Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int main(void) {
	int k; cin >> k;

	int ans = 0;
	for (int i = 1; i <= k; i++) {
		int tmp = i, digit=0;
		while (tmp > 0) {
			tmp /= 10;
			digit++;
		}
		if (digit % 2 != 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, W; cin >> N >> W;
	vector<int> v(N), w(N); rep(i, 0, N) { cin >> v[i] >> w[i]; }
	int lim = 100 * 110;
	vector<int>dp(lim, INF);
	dp[0] = 0;
	rep(i, 0, N)rrep(j, v[i], lim)
		chmin(dp[j], dp[j - v[i]] + w[i]);
	int ans(0);
	rep(i, 0, lim)if (dp[i] <= W)chmax(ans, i);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);
	ll a, b, k;
	cin >> a >> b >> k;
	ll w = min(a, k);
	a -= w;
	k -= w;
	w = min(b, k);
	b-=w; k-=w;
	cout << a << " " << b << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
using namespace std;
int main() {
  
  int n;
  cin >> n;
  
  vector<int64_t> cont(n);
  vector<int64_t> dam(n);
  
  rep(i,n){
    cin >> cont.at(i);
  }
  
  int a = 0;
  
  rep(i,n){
    
    if(i%2 == 0){
      a += cont.at(i);
    }
    else{
      a -= cont.at(i);
    }
  }
  //b
  dam.at(0) = a/2;
  
  for(int i = 1; i < n ; i++){
    
    dam.at(i) = cont.at(i-1) - dam.at(i -1);
    
  }
  
  rep(i,n){ 
    cout << 2*dam.at(i) << " ";
  }
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int counter = 0;
  int k = 1;
  while(pow(10,k) <= N){
    if(k == 1) counter += 9;
    else if(k % 2 == 1){
      counter += (pow(10,k) - pow(10,(k - 1)));
    }
    k++;
  }
  k--;
  if(k % 2 == 0) counter += (N + 1 - pow(10,k));
  cout << counter << endl;
}



Measured memory_bytes: 256
import bisect
N = 10**6
dp = [0] * (N+1)
dp[0], dp[1] = 1, 1
prime = []
for i in range(2,N+1):
    if dp[i]==0:
        prime.append(i)
        for j in range(N//i+1):
            dp[j*i] = 1

like2017 = []
for p in prime:
    query = (p+1)//2
    idx = bisect.bisect_left(prime, query)
    if prime[idx] == query:
        like2017.append(p)
    

Q = int(input())
for q in range(Q):
    l, r = map(int,input().split())
    l = bisect.bisect_left(like2017, l)
    r = bisect.bisect_right(like2017, r)
    print (r-l)

Measured memory_bytes: 14460
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){
    int n, k ,q;
    int a[110000];
    int tmp;
    cin >> n >> k >> q;
    rep(i,n) a[i]=0;
    rep(i,q){
        cin >> tmp;
        tmp--;
        a[tmp]++;
    }
    rep(i,n){
        tmp = k + a[i] -q;
        if(tmp<=0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

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

int main(){
	int n,m,x,a[110],b[110];
	cin>>n>>m>>x;
	int left = 0,right = 0;
	for(int i=1; i<=m; ++i){
		cin>>a[i];
		if(a[i]>x)right++;
		else left++;
	}
	cout<<min(left,right);
	return 0;
}

Measured memory_bytes: 256
import heapq

n = int(input())
a = list(map(int, input().split()))
plus = [sum(a[:n])]
minus = [-sum(a[-n:])]
p = a[:n]
m = [-i for i in a[-n:]]
heapq.heapify(p)
heapq.heapify(m)
for i in range(n,2*n):
  pn = a[i]
  mn = -a[-(i+1)]
  if pn > p[0]:
    plus.append(plus[-1] + pn - heapq.heappop(p))
    heapq.heappush(p, pn)
  else:
    plus.append(plus[-1])
  if mn > m[0]:
    minus.append(minus[-1] + mn - heapq.heappop(m))
    heapq.heappush(m, mn)
  else:
    minus.append(minus[-1])
minus.reverse()
ans = []
for i,j in zip(plus,minus):
  ans.append(i+j)
print(max(ans))

Measured memory_bytes: 38148
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 100005
int n,w;
vector<int> wt(MAX);
vector<int> val(MAX);
vector<int> test(12);

void max_self(ll&a ,ll b)
{
    a = max(a,b);
}

int main()
{
    cin >> n >> w;
    
    vector<ll> dp(w+1);
    // dp[i] -> the maximum total value for weight exactly
    for(int item = 0;item < n; ++item)
    {
        int weight,value;
        cin >> weight >> value;
        for(int wt_done = w-weight;wt_done>=0;--wt_done)
        max_self(dp[wt_done+weight],dp[wt_done]+value);
    }

    ll ans = 0;
    for(int i=0;i<=w;i++)
    max_self(ans,dp[i]);
    cout << ans;
}

Measured memory_bytes: 1792