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

const int N = 1e5 + 100;

vector<int> g[N];
int depth[N];
int vis[N];

int dfs(int u, int p, int d = 0) {
    int cnt = 0;
    depth[u] = d;
    vis[u] = 1;
    for(int v : g[u]) {
        if(v == p) continue;
        if(vis[v] && depth[v] < depth[u]) {
            // back edge
            cout << u << " " << v << "\n";
            cnt++;
        }
        if(vis[v] == 0) {
            if(dfs(v, u, d+1)) {
                cout << u << " " << v << "\n";
                cnt++;
            }
        }
    }
    if(cnt&1) {
        cout << u << " " << p << endl;
        return 0;
    }
    return 1;
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

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

    return 0;
}



Measured memory_bytes: 17024
/*Bismillahir Rahmanir Rahim */
#include <bits/stdc++.h>
 
using namespace std ;
 
int main(){
	
	int n,i,c=0;
	
	scanf("%d",&n) ;
	
	int a[n+1] ;
	
//	int a[0]=0 ;
	
	for(i=1;i<n+1;i++){
		
		scanf("%d",&a[i]) ;
		
		if(i!=a[i]) {
			
			c++;
		}
		
		
	}
	
	if(c==2 || c==0){
		
		printf("YES\n") ;
	}
	
	else{
		
		printf("NO\n") ;
	}
	
	
}
	
	
	

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

template < class BidirectionalIterator >
bool next_combination ( BidirectionalIterator first1 ,
  BidirectionalIterator last1 ,
  BidirectionalIterator first2 ,
  BidirectionalIterator last2 )
{
  if (( first1 == last1 ) || ( first2 == last2 )) {
    return false ;
  }
  BidirectionalIterator m1 = last1 ;
  BidirectionalIterator m2 = last2 ; --m2;
  while (--m1 != first1 && !(* m1 < *m2 )){
  }
  bool result = (m1 == first1 ) && !(* first1 < *m2 );
  if (! result ) {
    // ???
    while ( first2 != m2 && !(* m1 < * first2 )) {
      ++ first2 ;
    }
    first1 = m1;
    std :: iter_swap (first1 , first2 );
    ++ first1 ;
    ++ first2 ;
  }
  if (( first1 != last1 ) && ( first2 != last2 )) {
    // ???
    m1 = last1 ; m2 = first2 ;
    while (( m1 != first1 ) && (m2 != last2 )) {
      std :: iter_swap (--m1 , m2 );
      ++ m2;
    }
    // ??¢
    std :: reverse (first1 , m1 );
    std :: reverse (first1 , last1 );
    std :: reverse (m2 , last2 );
    std :: reverse (first2 , last2 );
  }
  return ! result ;
}
 
template < class BidirectionalIterator >
bool next_combination ( BidirectionalIterator first ,
  BidirectionalIterator middle ,
  BidirectionalIterator last )
{
  return next_combination (first , middle , middle , last );
}

vector<int> data;
int L,H;



int main(){
  for(int i=0;i<=9;i++) data.push_back( i );
  while( cin >> L >> H && (H||L) ){
    vector<vector<int> > T;
    vector<int> Hit,Blow;    
    for(int i=0;i<H;i++){
      string s; int h,b; cin >> s >> h >> b;
      T.push_back( vector<int>() ); Hit.push_back( h ); Blow.push_back( b );
      for(int j=0;j<L;j++) T[i].push_back( s[j]-'0' );
    }
    vector<int> ans;
    bool flag = true;
    sort(data.begin(),data.end());
    do {
      do {
        int pos[10];
        memset(pos,-1,sizeof(pos));
        for(int i=0;i<L;i++) pos[data[i]] = i;
        bool f = true;
        for(int i=0;i<H;i++){
          int c1,c2; c1 = c2 = 0;
          for(int j=0;j<L;j++){
            int p = pos[T[i][j]];
            if( p == -1 ) continue;
            else if( p == j ) c1++;
            else c2++;
            if( c1 > Hit[i] || c2 > Blow[i] ) break;
          }
          if( c1 != Hit[i] || c2 != Blow[i] ) f = false;
          if(!f)break;
        }
        if( f ) {
          if( ans.empty() ) 
            for(int i=0;i<L;i++) ans.push_back( data[i] );
          else
            flag = false;
        }
      } while( next_permutation( data.begin(), data.begin() + L ) );
      if( !flag ) break;
    } while( next_combination( data.begin(), data.begin() + L, data.end() ) );

    if( flag && !ans.empty() ){
      for(int i=0;i<L;i++ ) cout << ans[i];
      cout << endl;
    } else
      cout << "NO" << endl;
  }

}

Measured memory_bytes: 1236
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,i,j,k;
	long long int s=1,d,f,g,h;
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		s=s*i;
		s=s%1000000007;
	}
	printf("%lld\n",s);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[3252];
ll dp[2][3252][3252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  // REP(b,2)REP(i,n+1)REP(j,n+1)dp[b][i][j] = -1ll<<60;
  REP(b,2)REP(i,n+1)dp[b][i][i] = 0;
  FOR(len,1,n+1)REP(b,2)REP(i,n+1-len){
    int j = i+len;
    dp[b][i][j] = -1ll<<60;
    CHMAX(dp[b][i][j], -dp[b][i+1][j] + a[i]);
    CHMAX(dp[b][i][j], -dp[b][i][j-1] + a[j-1]);
  }
  printf("%lld\n",dp[0][0][n]);
  return 0;
}


Measured memory_bytes: 155904
#include <iostream>
#include <algorithm>

using namespace std;

int P[100000];

struct Line{
  int a, b, weight;
};

bool lineCompare(Line a, Line b){return a.weight < b.weight;}

void init(int n){
  for (int i = 0; i < n; ++i){P[i] = i;}
}

int root(int n){
  if(P[n]==n){return n;}
  return root(P[n]);
}

int unite_sum(Line x){
  int sum = 0;
  if(root(x.a) != root(x.b)){
    P[root(x.a)] = root(x.b);
    sum += x.weight;
  }
  return sum;
}

bool is_in_the_same_tree(int a, int b){
  return root(a) == root(b);
}


int main(){
  int n, i, j, k, sum;
  cin >> n;
  init(n);
  Line lines[n*n];
  k = 0;
  for (i = 0; i < n; ++i){
    for (j = 0; j < n; ++j){
      Line line;
      line.a = i;
      line.b = j;
      cin >> line.weight;
      lines[k] = line;
      k++;
    }
  }
  sort(lines, lines+n*n, lineCompare);
  
  sum = 0;
  for (i = 0; i < n*n; ++i){
    if(lines[i].weight == -1){
      continue;
    }else{
      sum += unite_sum(lines[i]);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1280
n = int(input())
ls = list(map(int,input().split()))
a = [0]*8
p = 0
q = 0
co = 0
comax = 0
for i in range(n):
    p = ls[i]//400
    if p < 8:
        if a[p] == 0:
            a[p] += 1
            co += 1
        else:
            pass
    else:
        q += 1
comax = co + q
if co == 0:
    co = 1
print(co,comax)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    ll Q;
    cin >> Q;
    vector<ll> s(A+1,0);
    vector<ll> t(B+1,0);
    vector<ll> x(Q,0);
    for(ll i=0;i<A;i++){
        cin>>s[i+1]
    ;}
    for(ll i=0;i<B;i++){
        cin>>t[i+1]
    ;}
    for(ll i=0;i<Q;i++){
        cin>>x[i]
    ;}
    s[0]=-INF;
    t[0]=-INF;
    s.emplace_back(INF);
    t.emplace_back(INF);
    for(ll i=0;i<Q;i++){
        ll sl,tl,sr,tr;
        sr=*lower_bound(s.begin(), s.end(), x[i]);
        tr=*lower_bound(t.begin(), t.end(), x[i]);
        sl=*(upper_bound(s.begin(), s.end(), x[i])-1);
        tl=*(upper_bound(t.begin(), t.end(), x[i])-1);
        ll ans=INF;
        chmin(ans,x[i]-min(sl,tl));
        chmin(ans,max(sr,tr)-x[i]);
        chmin(ans,sr-tl+min(x[i]-tl,sr-x[i]));
        chmin(ans,tr-sl+min(x[i]-sl,tr-x[i]));
        print(ans);
    ;}

    
    return 0;
}


Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        
        long[] sum = new long[1001];
        for(int i = 1; i <= 1000; i++) {
            sum[i] = sum[i - 1] + i;
        }
        
        double result = 0;
        for (int i = 0; i < k; i++) {
            result += sum[p[i]] / (double) p[i];
        }
        double preValue = result;
        for(int i = k; i < p.length; i++) {
            double minus = sum[p[i - k]] / (double) p[i - k];
            double plus = sum[p[i]] / (double) p[i];
            double value = preValue + plus - minus;
            preValue = value;
            result = Math.max(result, value);
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 61508
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <stdio.h>
#include <queue>

//void Aoj_learning8();
//void Aoj_learning8sub(int, int, int*, int*);
//void Aoj_learning9();
void Aoj_learning10();

int main()
{
	Aoj_learning10();

	return 0;
}

void Aoj_learning10()
{
	std::string sInput;
	std::istringstream ss;	// 汎用文字列ストリーム
	int iInputProcessCnt = 0;
	int iInputUseTime = 0;

	// プロセス入力個数の取得
	std::cin >> sInput;
	ss = std::istringstream(sInput);
	ss >> iInputProcessCnt;
	if (iInputProcessCnt > 100000 || 1 > iInputProcessCnt)
	{
		exit(0);
	}
	// プロセスの処理一回にかける時間の取得
	std::cin >> sInput;
	ss = std::istringstream(sInput);
	ss >> iInputUseTime;
	if (iInputUseTime > 1000 || 1 > iInputUseTime)
	{
		exit(0);
	}

	// プロセス名とプロセスの処理時間キューにプッシュ
	std::queue<std::string> queName;
	std::queue<int> queTime;
	std::string sInputName;
	int iTime;
	for (int i = 0; i < iInputProcessCnt; i++)
	{
		std::cin >> sInputName;
		queName.push(sInputName);
		std::cin >> sInput;
		ss = std::istringstream(sInput);
		ss >> iTime;
		queTime.push(iTime);
	}

	// プロセスを処理した順に合計時間とともに出力
	int goukei = 0;
	int iTemp;
	std::string sTemp;
	while (1)
	{
		if (queTime.empty() == true)
		{
			break;
		}
		for (unsigned int i = 0; i < queTime.size(); i++)
		{
			if (queTime.front() <= iInputUseTime)
			{
				goukei += queTime.front();
				std::cout << queName.front() << " " << goukei << std::endl;
				// 処理が終了したものから要素を消していく
				queTime.pop();
				queName.pop();
			}
			else
			{
				goukei += iInputUseTime;
				queTime.front() -= iInputUseTime;
				iTemp = queTime.front();
				sTemp = queName.front();
				queTime.pop();
				queName.pop();
				queTime.push(iTemp);
				queName.push(sTemp);
			}
		}
	}
}


Measured memory_bytes: 6092
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int toji = 0;
		String left = "";
		String right = "";
		for(int i=0; i<n; ++i){
			if(s.charAt(i)==')'){
				if(toji==0){
					left += '(';
				}else{
					toji--;
				}
			}else if(s.charAt(i)=='('){
				toji++;
			}
		}
		for(int i=0; i<toji; i++){
			right += ')';
		}
		
		s = left + s + right;
		System.out.println(s);
		return;
	}
}

Measured memory_bytes: 21844
N = int(input())
L = list(map(int, input().split()))
lis = []
cou = 0
for i in range(N - 2):
    lis.append([L[i], L[i + 1], L[i + 2]])
for i in range(len(lis)):
    if lis[i][0] < lis[i][1] < lis[i][2] or lis[i][0] > lis[i][1] > lis[i][2]:
        cou += 1
print(cou)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
#define REV(n) reverse(n.begin(), n.end())
using namespace std;
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    vector<int>plain(3);
    FOR(i,3){
        cin >> plain[i];
    }
    SORT(plain);
    int ans;
    ans = plain[0] + plain[1];
    OUT(ans);
}

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

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      cout<<"#x "<<x<<"\n";
#define trace(x,y)  cout<<"#x "<<x<<" #y "<<y<<"\n";


const int mod = 1e9;
bool sortByFirst(const pair<int,int>& a, const pair<int,int>& b){
    return a.F < b.F;
}
int main(){
    IOS;
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    bool flag = false;
    for(int i = 0; i <= 1000 ; i++){
        if(i*k >= a && i*k <= b){
           flag = true;
        }
    }
    if(flag)cout<<"OK\n";
    else cout<<"NG\n";
return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        String s = sc.next().replace(".", "");
        long b = Long.parseLong(s);
        sc.close();

        // 主処理
        long result = a * b / 100;

        // 出力
        System.out.println(result);
    }
}


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 110, M = 4, mod = 1e9 + 7;

int n;
int f[N][M][M][M][M];

int check(int i, int j, int k, int l)
{
	if (i == 1 && j == 2 && k == 0) return 0;
	if (i == 1 && j == 0 && k == 2) return 0;
	if (i == 2 && j == 1 && k == 0) return 0;
	if (j == 1 && k == 2 && l == 0) return 0;
	if (j == 1 && k == 0 && l == 2) return 0;
	if (j == 2 && k == 1 && l == 0) return 0;
	if (i == 1 && j == 0 && k == 2 && l == 0) return 0;
	if (i == 1 && j == 2 && k == 2 && l == 0) return 0;
	if (i == 1 && j == 3 && k == 2 && l == 0) return 0;
	if (i == 1 && j == 2 && k == 1 && l == 0) return 0;
	if (i == 1 && j == 2 && k == 2 && l == 0) return 0;
	if (i == 1 && j == 2 && k == 3 && l == 0) return 0;
	if (i == 1 && j == 2 && k == 0 && l == 0) return 0;
	if (i == 1 && j == 1 && k == 2 && l == 0) return 0;
	return 1;
}

int main()
{	
	cin >> n;
	if (n == 1)
	{
		puts("4");
		return 0;
	}
	if (n == 2)
	{
		puts("16");
		return 0;
	}
	if (n == 3)
	{
		puts("61");
		return 0;
	}
	
	int s = 0;
	for (int i = 0; i < M; i ++ )
		for (int j = 0; j < M; j ++ )
			for (int k = 0; k < M; k ++ )
				for (int l = 0; l < M; l ++ )
					f[4][i][j][k][l] = check(i, j, k, l);

	for (int len = 5; len <= n; len ++ )
		for (int i = 0; i < M; i ++ )
			for (int j = 0; j < M; j ++ )
				for (int k = 0; k < M; k ++ )
					for (int l = 0; l < M; l ++ )
						for (int u = 0; u < M; u ++ )	
							if (check(u, i, j, k))
								f[len][u][i][j][k] = (f[len][u][i][j][k] + f[len - 1][i][j][k][l]) % mod;
		
		
	int res = 0;
	for (int i = 0; i < M; i ++ )
		for (int j = 0; j < M; j ++ )
			for (int k = 0; k < M; k ++ )
				for (int l = 0; l < M; l ++ )
					if (check(i, j, k, l))
						res = (res + f[n][i][j][k][l]) % mod;
						
	cout << res << endl;
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	
	for (int i = 0; i < s.size() - 1; ++i) {
		if (s.at(i) == s.at(i+1)) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(void) {
    int n,max = -1000000,min = 10000000;
    long long a,goukei = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (min > a) {
            min = a;
        }
        if (max < a) {
            max = a;
        }
        goukei += a;
    }
    cout << min << " "<< max << " " << goukei << endl;
 
    return 0;
}


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

int main() {
  int n, c; cin >> n >> c;
  vector<vector<int>> d(c, vector<int>(c));
  vector<vector<int>> a(3, vector<int>(c, 0));
  rep(i, c) {
    rep(j, c) cin >> d[i][j];
  }
  rep(i, n) {
    rep(j, n) {
      int t; cin >> t;
      a[(i + j) % 3][t - 1] ++;
    }
  }

  int ans = 1e9;
  rep(i, c) {
    rep(j, c) {
      if (i != j) {
        rep(k, c) {
          if (i != k && j != k) {
            int t = 0;
            rep(l, c) {
              t += d[l][i] * a[0][l];
              t += d[l][j] * a[1][l];
              t += d[l][k] * a[2][l];
            }
            ans = min(ans, t);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int x = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		// スペース区切りの整数の入力
		for(int i=1;i<=n;i++){
			list.add(sc.nextInt());
		}

		Collections.sort(list);
		int count =0;
		int sum = 0;

		while (sum<x&&n>count) {
			int preNum = list.get(count);
			sum+=preNum;
			count++;
			
		// System.out.println(sum);
		}

		// System.out.println(count);
		if(sum>x){
		System.out.println(count-1);
		}else if(sum==x){
		System.out.println(count);
		}else if(sum<x){
		System.out.println(count-1);
		}
	}
}

Measured memory_bytes: 22736
n = int(input())
A = [*map(int, input().split())]
mx = max(A)
c = [0]*(1000000+1)
for a in A:
    for i in range(a, mx+1, a): c[i] += 1
ans = 0
for a in A:
    if c[a] == 1: ans += 1
print(ans)


Measured memory_bytes: 32304
X, K, D = map(int, input().split())
A= abs(X)%D
B = abs(X)//D
if abs(X) - K*D > 0:
  print(abs(X)-K*D)
elif K%2 != B%2:
  print(min(abs(A+D),abs(A-D)))
else:
  print(A)

Measured memory_bytes: 9180
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,C,K;
int main(){
    cin>>A>>B>>C>>K;
    ll ans=0;
    while(A>=B){
        B*=2;
        ans++;
    }
    while(B>=C){
        C*=2;
        ans++;
    }
    if(ans<=K){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

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

using namespace std;

int main() {
    vector<long long> ans;
    for (int i = 0; i <= 999; i++) {
        if (i % 10 == 9) {
            continue;
        }
        for (int j = 0; j <= 15; j++) {
            if (i == 0 && j == 0) {
                continue;
            }

            long long t = i;
            for (int k = 0; k < j; k++) {
                t = t * 10 + 9;
            }

            int ds = 0;
            for (long long k = t; k > 0; k /= 10) {
                ds += k % 10;
            }

            long long p = 1;
            bool f = true;
            while (p < t) {
                if (t / p % 10 != 9 && t > ds * p) {
                    f = false;
                }
                p *= 10;
            }

            if (f) {
                ans.push_back(t);
            }
        }
    }

    sort(ans.begin(), ans.end());

    int k;
    cin >> k;

    for (int i = 0; i < k; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main() {
  long n, nan=0, tem=0, oku=0, t=0;
  cin >> n;
  long a[n];
  rep(i,0,n){
    cin >> a[i];
    nan += a[i];
  }
  while(tem<=nan/2.0){
    tem+=a[t];
    t++;
  }
  long c=0, cc=0, dd=0, d=0;
  c=tem;
  cc=nan-tem;
  d=tem-a[t-1];
  dd=nan-d;
  long e;
  e=min(c-cc, dd-d);
  if(e<0) e*=-1;
  co(e);
  
  
  return 0;
  
}

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

int f[200010],l[20],r[20],qzh[200010];

signed main(){
	int n,k;
	cin>>n>>k;
	
	for(int i=1;i<=k;i++){
		cin>>l[i]>>r[i];
	}
	
	f[1]=qzh[1]=1;
	
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			f[i]+=(qzh[max(i-l[j],0ll)]-qzh[max(i-r[j]-1,0ll)]+998244353+998244353)%998244353;
			f[i]%=998244353;
		}
		qzh[i]=qzh[i-1]+f[i];
		qzh[i]%=998244353;
	}
	
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 6740
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

int main()
{
    string s;
    cin >> s;

    bool ok = true;
    for (ll i = 0; i < 3; i++)
    {
        if (s[i] == s[i + 1]) {
            ok = false;
        }
    }
    if (ok) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
   // Bad を、そうでなければ Good 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using v = vector<ll>;
void dpA(){
    int n;
    cin >> n;
    auto h = vector<ll>(n,0);
    for(ll i =0;i<n;i++) cin >> h[i];

    auto dp = vector<ll>(n+2,1e9);
    
    dp[0] = 0;
    dp[1] = 0;
    for(ll i=1;i<n;i++){
        if(i>=2) dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])); 
        else if(i>=1) dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
    }
    cout << dp[n-1];
}

void dpB(){
    ll n,k;
    cin >> n >> k;
    auto h = vector<ll>(n+1,0);
    for(ll i=0;i<n;i++) cin >> h[i];

    auto dp = vector<ll>(100000,1e9);
    dp[0] = 0;
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=k;j++){
           if(i+j<=n) dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1];
}

void dpC(){
    ll n; cin >> n;
    vector<v> a(n,v(3,0));
    for(ll i=0;i<n;i++) cin >> a[i][0] >> a[i][1] >> a[i][2];

    auto dp = vector<v>(n+1,v(3,0));

    for(ll i=0;i<n;i++)
        for(ll today=0;today<3;today++)
            for(ll oday=0;oday<3;oday++)
                if(today!=oday) 
                    dp[i+1][today] = max(dp[i+1][today],dp[i][oday] + a[i][today]);
    
    cout << max(dp[n][0],max(dp[n][1],dp[n][2]));
   
    
}

void dpD(){
    ll N,W;
  	cin >> N >> W;
    auto ww = v(N,0);
    auto vv = v(N,0);
    for(ll i=0;i<N;i++) cin >> ww[i] >> vv[i];

    auto dp = vector<v>(N+1,v(W+1,0));
    
    for (ll i = 0; i < N; i++)
    {
        for (ll j = 0; j <= W; j++)
        {
            if(j-ww[i]>=0) dp[i+1][j] = max(dp[i][j],dp[i][j-ww[i]]+vv[i]);
            else dp[i+1][j] = dp[i][j];
        }    
    }
    cout << dp[N][W];
}

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

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll ans[9][9];
int main() {
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		ll now=i;
		if(now%10==0){
			continue;
		}
		ll f=now%10;
		while(now/10!=0){
			now/=10;
		}
		ll e=now;
		ans[f][e]++;
	//	cout << ans[f][e]<<f<<e<<endl;
	}
	ll ANS=0;
	for(ll i=1;i<=9;i++){
		for(ll j=1;j<=9;j++){
			ANS+=ans[i][j]*ans[j][i];
		}
	}
	cout <<ANS;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	long long int N, mae = 0, H, c = 0;
	bool flag = false;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> H;
		if (i != 0) {
			if (mae > H)c++;
			else if(mae!=H)c = 0;
		}
		if (c == 2||(i!=0&&mae-H>1)) {
			flag = true; break;
		}
		mae = H;
	}
	if (!flag)cout << "Yes";
	else cout << "No";
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a < b) {
        cout << "a < b" << '\n';
    } else if(a > b) {
        cout << "a > b" << '\n';
    } else {
        cout << "a == b" << '\n';
    }
}


Measured memory_bytes: 3080
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <tuple>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

using pint = pair<int, int>;
using ppint = pair<pint, pint>;
int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    int num_odd = 0;
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if (a[i][j] & 1) ++num_odd;
    }

    vector<ppint> res;
    int num = 0;
    int y = 0, x = 0;
    rep(it, h * w) {
        if (a[y][x] & 1) ++num;

        int ny = y, nx = x;
        if (y % 2 == 0) {
            if (nx == w - 1) ++ny;
            else ++nx;
        } else {
            if (nx == 0) ++ny;
            else --nx;
        }

        if (num & 1) if (num < num_odd) res.push_back(ppint(pint(y, x), pint(ny, nx)));
        y = ny; x = nx;

    }
    cout << res.size() << endl;
    for (auto p : res) {
        int y, x, ny, nx;
        tie(y, x) = p.first;
        tie(ny, nx) = p.second;
        cout << y + 1 << " " << x + 1 << " " << ny + 1<< " " << nx + 1<< endl;
    }
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int x,y;
    vi abc(3);
    cin>>x>>y>>abc[0]>>abc[1]>>abc[2];

    vvi deli(3);

    rep(i,3){
        rep(j,abc[i]){
            int tmp;
            cin>>tmp;
            deli[i].push_back(tmp);
        }
    }

    deli[0].push_back(1000000001);
    deli[1].push_back(1000000001);
    rep(i,3)sort(all(deli[i]),greater<int>());

    ll ans=0;
    rep(i,x)ans+=deli[0][i+1];
    rep(i,y)ans+=deli[1][i+1];

    vi idx={x,y,0};
    bool ex=true;
    int m;

    while(ex){
        ex=false;
        if(deli[0][idx[0]]<deli[1][idx[1]])m=0;else m=1;
        // cerr<<"del["<<m<<"]="<<deli[m][idx[m]]<<"\n";
        // cerr<<"del[2]="<<deli[2][idx[2]]<<"\n";
        if(deli[2][idx[2]]>deli[m][idx[m]]){
            ans+=deli[2][idx[2]]-deli[m][idx[m]];
            // cerr<<"ans="<<ans<<"\n";
            idx[2]++;
            idx[m]--;
            if(idx[2]<abc[2])ex=true;
        }
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 1784
def main():
    n = int(input())
    A = list(map(int, input().split()))

    ans1 = 0
    total = 0
    is_plus = True
    for a in A:
        total += a

        if is_plus:
            if total <= 0:
                ans1 += -total + 1
                total = 1
        else:
            if total >= 0:
                ans1 += total + 1
                total = -1

        is_plus = not is_plus

    ans2 = 0
    total = 0
    is_plus = False
    for a in A:
        total += a

        if is_plus:
            if total <= 0:
                ans2 += -total + 1
                total = 1
        else:
            if total >= 0:
                ans2 += total + 1
                total = -1

        is_plus = not is_plus

    print(min(ans1, ans2))


if __name__ == "__main__":
    main()


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

a=list(map(int,input().split()))


min=a[0]
i=0
for i in range(N):
    if a[i]<min:
        k=0
        k=a[i]
        a[i]=min
        min=k
    i+=1

max=a[0]
i=0
for i in range(N):
    if a[i]>max:
        k=0
        k=a[i]
        a[i]=max
        max=k
    i+=1
    
c=max-min
import math

print(int(math.ceil(c/2)))


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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac[2000005], ifac[2000005];
ll qpow(ll a, ll b){
	ll ret = 1;
	for(; b; b >>= 1, a = a * a % mod){
		if(b & 1) ret = ret * a % mod;
	}
	return ret;
}
ll C(ll a, ll b){
	if(a < b) return 0;
	return fac[a] * ifac[b] % mod * ifac[a - b] % mod;
}
int n, m;
ll ans = 0;
int main(){
	scanf("%d", &n);
	fac[0] = 1;
	for(int i = 1; i <= n * 2; i ++) fac[i] = fac[i - 1] * i % mod;
	ifac[n * 2] = qpow(fac[n * 2], mod - 2);
	for(int i = n * 2; i >= 1; i --) ifac[i - 1] = ifac[i] * i % mod;
	m = n / 2 + (n % 2);
	ll pre = 0;
	for(int i = m; i < n; i ++){
		int x = i * 2 - n;
		ans = (ans + (C((n - 1 + x) / 2, x) * fac[i] % mod - pre + mod) % mod * fac[n - 1 - i] % mod * i) % mod;
		
		pre = C((n - 1 + x) / 2, x) * fac[i] % mod * (n - 1 - i) % mod;
	}
	printf("%lld\n", ans);
	return 0;
} 

Measured memory_bytes: 31488
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, M;
    cin >> N >> M;
    string s, t;
    cin >> s >> t;
    ll ans = lcm(N, M);
    rep(i, s.size()) {
        if((M * i) % N == 0) {
            if(t[M * i / N] != s[i]) {
                output(-1);
                return 0;
            }
        }
    }
    output(ans);
    
    
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int n;
  cin>>n;
  cout<<"ABC"<<n<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=5010;
const int mod=1000000007;
struct edge
{
    int t;
    edge *next;
}*con[maxn];
int n,sz[maxn];
ll jie[maxn],inv[maxn],g[2][maxn];
ll ksm(ll a,int b){ll r=1;for(;b;b>>=1){if(b&1) r=r*a%mod;a=a*a%mod;}return r;}
ll A(int a,int b){return jie[a]*inv[a-b]%mod;}
ll C(int a,int b){return A(a,b)*inv[b]%mod;}
void ins(int x,int y)
{
    edge *p=new edge;
    p->t=y;
    p->next=con[x];
    con[x]=p;
}
void getroot(int v,int fa,int &root)
{
    sz[v]=1;    bool flag=1;

    for(edge *p=con[v];p;p=p->next)
        if(p->t!=fa)
        {
            getroot(p->t,v,root);
            sz[v]+=sz[p->t];
            if(sz[p->t]*2>n) flag=0;
        }
    if(sz[v]*2<n) flag=0;
    if(flag) root=(root?-1:v);  
}
ll solve()
{
    int rt=0;
    getroot(1,-1,rt);
    if(rt==-1) return jie[n/2]*jie[n/2]%mod;
    for(edge *p=con[rt];p;p=p->next)
        sz[p->t]=-(sz[p->t]>sz[rt]?n-sz[rt]:sz[p->t]);
    for(int i=1;i<=n;i++)
        sz[i]=(sz[i]>0?0:-sz[i]);       
    int tot=0;
    g[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        tot+=sz[i];
        memset(g[i&1],0,sizeof(g[i&1]));
        for(int j=0;j<=tot;j++)
            for(int k=0;k<=min(sz[i],j);k++)
                g[i&1][j]=(g[i&1][j]+g[(i&1)^1][j-k]*C(sz[i],k)%mod*A(sz[i],k)%mod)%mod;
    }
    ll ans=0;
    for(int i=0,r=1;i<=n;i++,r=-r)
        ans=(ans+(g[n&1][i]*jie[n-i]%mod*r+mod)%mod)%mod;
    return ans; 
}


int main(){
    scanf("%d",&n);
    jie[0]=1;
    for(int i=1;i<=n;i++)
        jie[i]=jie[i-1]*i%mod;
    inv[n]=ksm(jie[n],mod-2);
    for(int i=n-1;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;  
    //for(int i=0;i<=n;i++)
    //  cout<<jie[i]<<' '<<inv[i]<<endl;    
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        ins(x,y);
        ins(y,x);
    }
    printf("%lld",solve());
    return 0;
}

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

using namespace std;
using ll = long long;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

bool prime(int x) {
	if (x < 2) {
		return false;
	}
	for (int d = 2; d * d <= x; ++d) {
		if (x % d == 0) {
			return false;
		}
	}
	return true;
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	int x;
	cin >> x;
	while (!prime(x)) {
		++x;
	}
	cout << x << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int a[N];
  REP(i,N)cin>>a[i];
  int A=0;
  int B=0;
  sort(a,a+N,std::greater<int>());
  REP(i,N){
    if(i%2==0)A+=a[i];
    else B+=a[i];
  }
  cout<<A-B<<endl;
  return 0;
}


Measured memory_bytes: 256
h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = [set() for i in range(h)]
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb[inp[0]-1].add(inp[1]-1)
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            if i in bomb[j]:
                flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)

Measured memory_bytes: 175832
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = k; i < n; i++)
    {
        if (a[i - k] < a[i])
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 4772
#include<stdio.h>

int main(){
 int x[5];
  scanf("%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&x[4]);
  
  int ans=0;
  if(x[0]==0)ans = 1;
  if(x[1]==0)ans =2;
  if(x[2]==0)ans = 3;
  if(x[3]==0)ans =4;
  if(x[4]==0)ans =5;
  
  printf("%d",ans);
  
  return 0;
}


Measured memory_bytes: 1680
#include <iostream>
#include <cmath>
#include <vector>
#include<bits/stdc++.h> 
#include<cstring>
#include<utility>
using namespace std;
 
int main()
{
   int n;
   cin>>n;
   	vector<double> p;
   	for(int i =0;i<n;i++)
   	{
   		double prob;
   		cin>>prob;
   		p.push_back(prob);
	   }
	  double dp[n+1][n+1];
   	memset(dp, 0, sizeof(dp));
   	dp[0][0] = 1;
	   for(int i = 1;i<=n;i++)
   	    dp[i][0] = dp[i-1][0]* (1-p[i-1]);
   	
   	for(int i = 1;i<=n;i++ )
   	{
   		for(int j =1;j<=n;j++)
   			dp[i][j] = dp[i-1][j]*(1-p[i-1])  + dp[i-1][j-1]*p[i-1];  
		
	}
	double sum =0;
	for(int i = (n+1)/2; i<=n;i++)
	sum+=dp[n][i];
	
	cout<<fixed<<setprecision(10)<<sum;
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n,k;
    cin>>n>>k;
    if(k>(n-1)*(n-2)/2) {
        cout<<-1<<endl;
        return 0;
    }
    
    int m=(n-1)+((n-1)*(n-2)/2-k);
    cout<<m<<endl;
    rep(i,n-1) {
        cout<<i+1<<" "<<n<<endl;
        m--;
    }
    
    rep(i,n-1) {
        rep(j,i) {
            if(m>0) {
                cout<<i+1<<" "<<j+1<<endl;
                m--;
            }
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <map>

using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)
int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};
bool gems[25][25];
vector<bool> hantei;
int main(){
	int n;
	cin >> n;
	while(n!=0){
		REP(i,25)memset(gems[i],0,sizeof(gems[i]));
		REP(i,n){
			int x,y;
			cin >> x >> y;
			gems[x][y] = true;
		}
		int ret=0;
		int m;
		cin >> m;
		int nowx,nowy;
		nowx = nowy = 10;
		REP(i,m){
			char c;
			int nor;
			cin >> c >> nor;
			int dir;
			switch(c){
				case 'N':
					dir = 0;
					break;
				case 'E':
					dir = 1;
					break;
				case 'S':
					dir = 2;
					break;
				case 'W':
					dir = 3;
					break;
			}

			REP(j,nor){
				nowx += dx[dir];
				nowy += dy[dir];
				if(gems[nowx][nowy]){
					ret++;
					gems[nowx][nowy] = false;
				}
			}
		}
		if(ret == n){
			hantei.push_back(1);
		}else{
			hantei.push_back(0);
		}
		cin >> n;
	}
	REP(i,hantei.size()){
		string dis = hantei[i] ? "Yes":"No";
		cout << dis << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    ll a,b,n;
    cin>>a>>b>>n;
    if(n>=b)
    cout<<(ll)(b-1)*a/b;
    else
    {
        cout<<(ll)(n)*a/b;
    }
    
  }  
  return 0;
}

Measured memory_bytes: 3608
use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let stdin = std::io::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: u32 = read();
    let k: u32 = read();
    let h: Vec<u32> = (0..n).map(|_| read()).collect();

    let mut res = 0;
    for v in h {
        if v >= k {
            res += 1;
        }
    }

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


Measured memory_bytes: 4352
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, m = LI()
    edge = [[] for _ in range(n)]
    cc = [-1]*n

    for _ in range(m):
        s, t = LI()
        edge[s].append(t)
        edge[t].append(s)

    ccid = 0
    for i in range(n):
        if cc[i]==-1:
            stk = [i]
            cc[i] = ccid
            while stk:
                c = stk.pop()
                for n in edge[c]:
                    if cc[n]==-1:
                        stk.append(n)
                        cc[n] = ccid

            ccid += 1

    q = I()
    for _ in range(q):
        s, t = LI()
        if cc[s] == cc[t]:
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 24088
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vi data(N + 1, 0);
    for (int i = 1; i < N + 1; i++) {
        cin >> data[i];
    }
    vb check(N + 1, false);
    check[1] = true;
    int i = 1;
    ll count = 0;
    while (true) {
        if (check[data[i]] || count == K - 1) {
            i = data[i];
            count++;
            break;
        }
        check[data[i]] = true;
        i = data[i];
        count++;
    }
    if (count == K) {
        cout << i << endl;
        return 0;
    }
    K -= count;
    int j = i;
    count = 0;
    while (true) {
        if (data[j] == i || count == K - 1) {
            count++;
            j = data[j];
            break;
        }
        j = data[j];
        count++;
    }
    if (count == K) {
        cout << j << endl;
        return 0;
    }
    K %= count;
    for (int k = 0; k < K; k++) {
        i = data[i];
    }
    cout << i << endl;
}


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

int main() {
  string s;
  cin >> s;
  s += "XXX";
//  cout << s << endl;

  int i = 0;
  long long int a = 0;
  long long int num = 0;
  int len = s.size();
  for (int i = 0; i < len; ++i) {
    if (s[i] == 'A') {
      ++a;
    } else if (s[i] == 'B' && s[i+1] == 'C') {
      num += a;
      ++i;
    } else {
      a = 0;
    }
  } 

  cout << num << endl;

  return 0;
}


Measured memory_bytes: 640
a,b,c=map(int,input().split())
if a==b==c==0:
    print("Close")
elif a==1 and b==c==0:
    print("Close")
elif a==c==0 and b==1:
    print("Close")
elif a==b==1 and c==0:
    print("Open")
elif a==b==0 and c==1:
    print("Open")


Measured memory_bytes: 5596
H,W,D = map(int,input().split())
A = {}
for i in range(H):
    l = list(map(int,input().split()))
    for j in range(W):
        A[l[j]] = [i+1,j+1]

Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int,input().split())))


ru = {}
for i in range(1,D+1):
    ru[i] = [0]

for i in range(1,D+1):
    c = 1
    while i + D*c <= H*W:
        now = A[i+D*(c-1)]
        will = A[i+D*c]
        mp = abs(will[0] - now[0]) + abs(will[1] - now[1])
        ru[i].append(mp + ru[i][c-1])
        c += 1

for i in range(Q):
    t = LR[i][0] % D
    if t == 0:
        t = D
        print(ru[t][LR[i][1]//D-1] - ru[t][LR[i][0]//D-1])
    else:
        print(ru[t][LR[i][1]//D] - ru[t][LR[i][0]//D])


Measured memory_bytes: 101464