akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <cstdio>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}


int main()
{
    ll n,W;
    cin>>n>>W;
    vector<ll>w(n+1);
    vector<ll>v(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[101][100001];
    for(int i=0;i<=n;i++)
    for(ll j=0;j<=W;j++)
        dp[i][j]=0;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=W;j++)
        {
            if(j>=w[i])
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
            else
                dp[i][j]=dp[i-1][j];
                
        }
    }
    ans=dp[n][W];
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 79104
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  int n; cin >> n;
  ll a[n + 1];
  for (int i = 0; i < n + 1; i++) cin >> a[i];
  ll b[n];
  for (int i = 0; i < n; i++) cin >> b[i];
  ll tot = 0;
  for (int i = 0; i < n; i++) {
   if (b[i] == 0) continue;
   if (a[i] > 0) {
    if (b[i] > a[i]) {
     tot += a[i];
     b[i] -= a[i];
     a[i] = 0;
    }
    else {
     tot += b[i];
     a[i] -= b[i];
     b[i] = 0;
    }
   }
   if (b[i] == 0) continue;
   if (a[i+1]) {
     if (b[i] > a[i+1]) {
     tot += a[i+1];
     b[i] -= a[i+1];
     a[i+1] = 0;
    }
    else {
     tot += b[i];
     a[i+1] -= b[i];
     b[i] = 0;
    }
   }
  }
  cout << tot << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
struct point{
	double x,y;
	point(){}
	point(double _x,double _y){
		x=_x;y=_y;
	}
	point operator +(const point &b) const{
		return point(x+b.x,y+b.y);
	}
	point operator -(const point &b) const{
		return point(x-b.x,y-b.y);
	}
	double operator ^(const point &b) const{
		return x*b.x+y*b.y;
	}
	double operator *(const point &b) const{
		return x*b.y-y*b.x;
	}
	point operator *(const double &b) const{
		return point(x*b,y*b);
	}
};
double len(point p){
	return p.x*p.x+p.y*p.y;
}
struct matrix{
	double xmin,xmax,ymin,ymax;
}a[2];
bool check(point p0,point p1,point p2,point p3){
	a[0].xmax=max(p0.x,p1.x);
	a[0].xmin=min(p0.x,p1.x);
	a[0].ymax=max(p0.y,p1.y);
	a[0].ymin=min(p0.y,p1.y);
	a[1].xmax=max(p2.x,p3.x);
	a[1].xmin=min(p2.x,p3.x);
	a[1].ymax=max(p2.y,p3.y);
	a[1].ymin=min(p2.y,p3.y);
	if(!(a[0].xmax<a[1].xmin || a[1].xmax<a[0].xmin || a[0].ymax<a[1].ymin || a[1].ymax<a[0].ymin)){
		if(((p1-p0)*(p2-p0))*((p1-p0)*(p3-p0))<=0 &&
		   ((p3-p2)*(p1-p2))*((p3-p2)*(p0-p2))<=0) return 1;
		else return 0;
	}
	else return 0;
}
double dist(point p,point p0,point p1){
	point q=(p1-p0)*(((p1-p0)^(p-p0))/len(p1-p0))+p0;
	if(min(p0.x,p1.x)<=q.x&&q.x<=max(p0.x,p1.x)&&min(p0.y,p1.y)<=q.y&&q.y<=max(p0.y,p1.y)) return sqrt(len(p-q));
	return min(sqrt(len(p0-p)),sqrt(len(p1-p)));
}
int main(){
	int n;
	point p0,p1,p2,p3;
	cin>>n;
	while(n--){
		cin>>p0.x>>p0.y>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
		if(check(p0,p1,p2,p3)) printf("%.10lf\n",0);
		else printf("%.10lf\n",min(min(dist(p0,p2,p3),dist(p1,p2,p3)),min(dist(p2,p0,p1),dist(p3,p0,p1))));
	}
	return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef struct Point {
	double x, y;
	Point operator - (const Point& o) const { return Point{x - o.x, y - o.y}; }
	Point operator + (const Point& o) const { return Point{x + o.x, y + o.y}; }
	Point operator * (double d) const { return Point{x * d, y * d}; }
	Point operator / (double d) const { return Point{x / d, y / d}; }
} Vector;

double angle(double a, double b, double c) { return acos((b * b + c * c - a * a) / (2.0 * b * c)); }
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a)); }
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
Vector unitVector(Vector a) { return a / abs(a); }
Vector rotate(Vector a, double s) { return Vector{a.x * cos(s) - a.y * sin(s), a.x * sin(s) + a.y * cos(s)}; }

int n;
double x[100], y[100], r[100];

pair< Point, Point > crossPoint(int i, int j) {
	Point a{x[i], y[i]}, b{x[j], y[j]};
	Point x = unitVector(b - a) * r[i];
	double s = angle(r[j], abs(b - a), r[i]);
	return pair< Point, Point >(a + rotate(x, s), a + rotate(x, -s));
}

int ccw(Point a, Point b, Point c) {
	Vector ba = b - a, ca = c - a;
	if (cross(ba, ca) > 0) return 1;
	if (cross(ba, ca) < 0) return -1;
	if (dot(ba, ca) < 0) return 2;
	if (abs(ba) < abs(ca)) return -2;
	return 0;
}

void solve() {
	vector< vector< Point > > vp(2, {Point{x[0], y[0]}});
	
	for_(i,0,n-1) {
		pair< Point, Point > cp = crossPoint(i, i + 1);
		vp[0].push_back(cp.first);
		vp[1].push_back(cp.second);
	}
	
	vp[0].push_back(Point{x[n-1], y[n-1]});
	vp[1].push_back(Point{x[n-1], y[n-1]});
	
	assert((int)vp[0].size() == n+1);
	vector< vector< double > > dst(2, vector< double >(n+1, 1e9));
	dst[0][0] = 0;
	
	for_(i,0,n) for_(bi,0,2) {
		if (dst[bi][i] < 1e9) {
			for_(j,i+1,n+1) for_(bj,0,2) {
				bool flag = true;
				for_(k,i+1,j) flag &= (ccw(vp[bi][i], vp[bj][j], vp[0][k]) * ccw(vp[bi][i], vp[bj][j], vp[1][k]) == -1);
				if (flag) dst[bj][j] = min(dst[bj][j], dst[bi][i] + abs(vp[bi][i] - vp[bj][j]));
			}
		}
	}
	
	printf("%.9f\n", dst[0][n]);
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> x[i] >> y[i] >> r[i];
		solve();
	}
}

Measured memory_bytes: 3544
#include<iostream>
using namespace std;
int main(){
	int A,B,C;
	cin>>A>>B>>C;
	int count = 0;
	for(int i = 0; i < C; i++){
		if(A <= B){
			B-=A;
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <cstdlib>
#include <memory>
#include <cstring>
#include <sstream>
#include <list>
#include <deque>
#include <bitset>
#include <vector>

using namespace std;

#define INF 0x3f3f3f3f
#define PI 3.141592653579
#define FRER() freopen("input.txt" , "r" , stdin);
#define FREW()  freopen("output.txt" , "w" , stdout);
#define  QIO std::ios::sync_with_stdio(false)
#define mem(a, b) memset(a , b , sizeof(a))
const double eps = 1e-8;
typedef long long ll;
const int maxn = 200;
int cnt, n;
ll ans;
ll C[maxn][maxn];

int main()
{
    QIO;
    for (int i = 0; i < 103; i++)
    {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
    ll l, k;
    cin >> l >> k;
    ll res = 0;
    for (int i = 1; i <= l; i++)
    {
        ll maxbig = (i + 1) / (k + 1);
        for (int j = 0; j <= maxbig; j++)
        {
            ll tl = i - k * j + j;
            if (tl % 2 == 0) continue;
            res += C[tl / 2 + 1][j];
        }
    }
    cout << res << endl;
    return 0;

}


Measured memory_bytes: 3368
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String S = scan.next();
        String cnt;
        
        //パターンはOOXX,OXOX,OXXOの3パターンで文字が同じか調べればよいだけ
        
        if(S.substring(0,1).charAt(0) == S.substring(1,2).charAt(0) &&
          S.substring(2,3).charAt(0) == S.substring(3,4).charAt(0))
          cnt = "Yes";
        else if(S.substring(0,1).charAt(0) == S.substring(2,3).charAt(0) &&
          S.substring(1,2).charAt(0) == S.substring(3,4).charAt(0))
          cnt = "Yes";
        else if(S.substring(0,1).charAt(0) == S.substring(3,4).charAt(0) &&
          S.substring(1,2).charAt(0) == S.substring(2,3).charAt(0))
          cnt = "Yes";
        else
          cnt = "No";
        
        if(S.substring(0,1).charAt(0) == S.substring(1,2).charAt(0) &&
           S.substring(1,2).charAt(0) == S.substring(2,3).charAt(0) &&
           S.substring(2,3).charAt(0) == S.substring(3,4).charAt(0) )
          cnt = "No";
            
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)

typedef struct {
    ll to;
    ll cap;
    ll rev;
} edge;

ll used[110] = {};
vector<edge> tree[110];

ll dfs(ll v, ll t, ll f){
    if(v == t) return f;
    used[v] = true;
    for(auto &e: tree[v]){
        if(!used[e.to] && e.cap > 0){
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                tree[e.to][e.rev].cap += d;
                return d;
            }
        }

    }
    return 0;
}

int main(){
    int N,M;
    cin >> N >> M;
    
    rep(i,0,M){
        ll u,v,c;
        cin >> u >> v >> c;
        // u--; v--;
        tree[u].push_back({v, c, (ll) tree[v].size()});
        tree[v].push_back({u, 0LL, (ll)(tree[u].size() - 1)});
    }
    ll flow = 0;
    while(true){
        memset(used, 0, sizeof(used));
        ll f = dfs(0, N-1, INF);
        if(f == 0) break;
        flow += f;
    }
    cout << flow << endl;

}


Measured memory_bytes: 3264
import java.lang.Math

fun main(args: Array<String>) {
    val INF = 1000000000
    val (H, W) = readInputLine().split(" ").map { it.toInt() }
    val S = Array(H) { readInputLine().toCharArray() }

    val d = Array(H * W) { IntArray(H * W) { INF } }

    for (i in 0 until H * W) {
        if (S[i / W][i % W] == '.') {
            d[i][i] = 0
        }
    }

    for (h in 0 until H) {
        for (w in 0 until W) {
            if (S[h][w] == '#') {
                continue
            }
            if (h > 0 && S[h - 1][w] == '.') {
                d[(h - 1) * W + w][h * W + w] = 1
                d[h * W + w][(h - 1) * W + w] = 1
            }
            if (h < H - 1 && S[h + 1][w] == '.') {
                d[(h + 1) * W + w][h * W + w] = 1
                d[h * W + w][(h + 1) * W + w] = 1
            }
            if (w > 0 && S[h][w - 1] == '.') {
                d[h * W + (w - 1)][h * W + w] = 1
                d[h * W + w][h * W + (w - 1)] = 1
            }
            if (w < W - 1 && S[h][w + 1] == '.') {
                d[h * W + (w + 1)][h * W + w] = 1
                d[h * W + w][h * W + (w + 1)] = 1
            }
        }
    }

    for (k in 0 until H * W) {
        for (i in 0 until H * W) {
            for (j in 0 until H * W) {
                d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j])
            }
        }
    }

    var ans = 0

    for (i in 0 until H * W) {
        for (j in 0 until H * W) {
            if (d[i][j] == INF) {
                continue
            }
            ans = Math.max(ans, d[i][j])
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 40636
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
  int a,b,c;
  vector<int> v;
  cin >> a >> b >> c;
  v = {a,b,c};
  sort(v.begin(),v.end());
  cout << v.at(0) * v.at(1) / 2;
  
}

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


int main(void)
{
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a < c && b < c && a < b){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 1012
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

#define rep(i,n) for(int i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int)v.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template<class T> bool chmin(T& a,T b){if(a>b){a=b;return 1;}else return false;}
template<class T> bool chmax(T& a,T b){if(a<b){a=b;return 1;}else return false;}

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

    int64_t n;cin >> n;
    n %= 1000;
    if(n == 0)cout << 0 << '\n';
    else cout << 1000 - n << '\n';

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1001001002;

int main() {
    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<int>> dist(N, vector<int>(N, INF));
    rep(i,M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; 
        b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    rep(i,N) dist[i][i] = 0;
    rep(k,N) rep(i,N) rep(j,N) {
        chmin(dist[i][j], dist[i][k]+dist[k][j]);
    }
    vector<vector<int>> dist2(N, vector<int>(N, INF));
    rep(i,N) rep(j,N) {
        if (dist[i][j] <= L) dist2[i][j] = 1;
    }
    rep(i,N) dist2[i][i] = 0;
    rep(k,N) rep(i,N) rep(j,N) {
        chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
    }
    int q, s, t;
    cin >> q;
    rep(i,q) {
        cin >> s >> t;
        s--;
        t--;
        int ans = dist2[s][t] - 1;
        if (dist2[s][t] == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 7368792;

int main() {
    int n, m;

    while (cin >> n >> m && n) {
        VI d(N,1);
        FOR(i,n,N){
            if (d[i] && m == 0){
                cout << i << endl;
                break;
            }
            if (d[i] && m > 0){
                m--;
                int x = 2*i;
                while (x < N){
                    d[x] = 0;
                    x += i;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 31740
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

void getBinary(lli len, lli n, string *t);

vector<lli> beki2(40 + 1);

int main(){
    lli n, k;
    cin >> n >> k;

    lli a_max = -1;
    vector<lli> a_vec;
    vector<string> bin_vec;
    for(lli i = 0; i < n; i++){
        lli a_input;
        cin >> a_input;
        a_max = max(a_max, a_input);
        a_vec.push_back(a_input);
    } // 100005

    lli binLength, checkNum = max(a_max, k);
    beki2[0] = 1;
    for(lli i = 1; i < 40 + 1; i++){
        beki2[i] = beki2[i - 1] * 2;
        //cout << "beki2[" << i << "] = " << beki2[i] << endl;
        if(beki2[i - 1] <= checkNum && checkNum < beki2[i]){
            binLength = i;
            break;
        }
    } // 40

    vector<lli> bits0(binLength);
    vector<lli> bits1(binLength);
    for(lli i = 0; i < n; i++){
        string bin;
        getBinary(binLength, a_vec[i], &bin);
        bin_vec.push_back(bin);
        //cout << i << ": " << bin_vec[i] << endl;

        for(lli j = 0; j < binLength; j++){
            if(bin_vec[i][j] == '0') bits0[j]++;
            else bits1[j]++;
        }
    } // 40 * 100005

    /*for(lli j = 0; j < binLength; j++){
        //cout << "bits0[" << j << "] = " << bits0[j] << ", bits1[" << j << "] = " << bits1[j] << endl;
    }*/

    vector<lli> bits_ans(binLength);
    lli nXorMax = 0;
    for(lli i = 0; i < binLength; i++){
        lli sisu = binLength - 1;
        if(nXorMax + beki2[sisu - i] > k){
            //printf("a\n");
            bits_ans[sisu - i] = 0;
        }else{
            //printf("b\n");
            bits_ans[sisu - i] = (bits0[i] > bits1[i])? 1 : 0;
        }
        nXorMax += (bits_ans[sisu - i])? beki2[sisu - i] : 0;
        //printf("bits_ans[%lld] = %lld, nXorMax = %lld\n", sisu - i, bits_ans[sisu - i], nXorMax);
    } // 40

    lli ans = 0;
    for(lli i = 0; i < n; i++){
        ans += nXorMax ^ a_vec[i];
    } // 100005

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

void getBinary(lli len, lli n, string *t){
    lli r;
    string s;
    for(lli i = 0; i < len; i++){
        r = n % 2;
        s += '0' + r;
        n /= 2;
    }
    reverse(s.begin(), s.end());
    *t = s;
    ////cout << "getBinary: t = " << *t << endl;
    return;
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

//累乗(nのk乗）
long long ruijou(ll n, ll k){
    if(k==0) return 1;
    int x=k/2;
    long long t=ruijou(n,x);
    
    if(k%2==1) return n*t*t;
    else return t*t;
}

int main(){
  ll X; cin>>X;
  ll K=X/100;
  ll amari=X%100;
  if(amari>5*K) cout<<0<<endl;
  else cout<<1<<endl;

}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc144/tasks/abc144_b
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    for i in range(1, 10):
        for j in range(1, 10):
            if n == i * j:
                print('Yes')
                return
    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 998244353

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

ll n,m;

void dijkstra(Graph &G,map<P,ll> &bet,ll start,vector<ll> &dist,vector<ll> &prev){
    priority_queue<P,vector<P>,greater<P>> que;
    que.push({0,start});
    
    prev.assign(n,-1);
    dist.assign(n,INF);
    dist[start]=0;

    while(que.size()){
        P now=que.top();
        que.pop();
        if(dist[now.second]<now.first) continue;//今、最短距離でないなら無視する

        for(auto next:G[now.second]){
            if(dist[next]>dist[now.second]+bet[make_pair(now.second,next)]){//最短になる場合
                dist[next]=dist[now.second]+bet[make_pair(now.second,next)];//最短距離更新
                que.push(make_pair(dist[next],next));
            
                prev[next]=now.second;//now.secondを通って、nextに到着
            }
        }
    }
}

vector<ll> get_path(vector<ll> &prev,int goal){//経路復元
    vector<ll> path;
    for (ll cur=goal;cur!=-1;cur=prev[cur]){
        path.push_back(cur);
    }
    reverse(path.begin(),path.end());//逆順なのでひっくり返す
    return path;
}

int main(){
    cin>>n>>m;
    Graph G(n);
    map<P,ll> bet;//2点間距離
    vector<P> stay;//pairを保存

    rep(i,m){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
        bet[make_pair(a,b)]=c;//a-b間距離
        bet[make_pair(b,a)]=c;

        stay.push_back(make_pair(a,b));//頂点を保存
        stay.push_back(make_pair(b,a));
    }

    map<P,bool> visit;
    rep(i,stay.size()){
        visit[stay[i]]=false;//初期化
    }

    rep(i,n){
        rep(j,n){
            if(i==j) continue;
            vector<ll> dist,prev;

            dijkstra(G,bet,i,dist,prev);
            vector<ll> path=get_path(prev,j);

            rep(k,path.size()-1){
                visit[make_pair(path[k],path[k+1])]=true;//訪れた辺
                visit[make_pair(path[k+1],path[k])]=true;
            }
        }
    }

    ll ans=2*m;
    rep(i,stay.size()){
        if(visit[stay[i]]){
            ans--;
        }
    }

    cout<<ans/2<<endl;

    return 0;
}

Measured memory_bytes: 512
using System;

class B {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var h = int.Parse(line[0]);
        for (int i = 0; i < h; ++i) {
            var s = Console.ReadLine();
            Console.WriteLine(s);
            Console.WriteLine(s);
        }
    }
}


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

string num = "0123456789";
int ctoi(char c){
    stringstream ss;
    int n;
    ss << c;
    ss >> n;
    return n;
}
string itos(int n){
    stringstream ss;
    string s;
    ss << n;
    ss >> s;
    return s;
}

int mcxitoi(string s){
    int n=0;
    while(true){
        if(num.find(s[0])!=string::npos){
            if(s[1]=='m') n+=ctoi(s[0])*1000;
            else if(s[1]=='c') n+=ctoi(s[0])*100;
            else if(s[1]=='x') n+=ctoi(s[0])*10;
            else if(s[1]=='i') n+=ctoi(s[0]);
            if(s.size()<=2) break;
            s = s.substr(2);
        }else{
            if(s[0]=='m') n+=1000;
            else if(s[0]=='c') n+=100;
            else if(s[0]=='x') n+=10;
            else if(s[0]=='i') n+=1;
            if(s.size()<=1) break;
            s = s.substr(1);
        }
    }
    return n;
}

string itomcxi(int n){
    string s;
    if(n/1000>=1){
        if(n/1000!=1) s+=itos(n/1000);
        s+="m";
    }
    n %= 1000;
    if(n/100>=1){
        if(n/100!=1) s+=itos(n/100);
        s+="c";
    }
    n %= 100;
    if(n/10>=1){
        if(n/10!=1) s+=itos(n/10);
        s+="x";
    }
    n %= 10;
    if(n>=1){
        if(n!=1) s+=itos(n);
        s+="i";
    }
    return s;
}

int main(){
    int n;
    string sx, sy;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> sx >> sy;
        cout << itomcxi(mcxitoi(sx)+mcxitoi(sy)) << endl;
    }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  set<string>s;
  for(int i=0;i<n;i++){
    string ss;cin>>ss;
    s.insert(ss);
  }
  cout<<s.size()<<endl;
  return 0;
}

Measured memory_bytes: 19248
from collections import defaultdict
d=(1,-1,4,-4)

def solve():
    que=["01234567"]
    while que!=[]:
        v=que[0]
        del que[0]
        pos=v.index("0")
        for i in range(4):
            idx2=pos+d[i]
            if idx2<0 or idx2>7:
                continue
            if (pos==3 and d[i]==1) or (pos==4 and d[i]==-1):
                continue
            u=list(v)
            u[pos],u[pos+d[i]]=u[pos+d[i]],u[pos]
            u="".join(u)
            if res[u]==0:
                que.append(u)
                res[u]=res[v]+1
res=defaultdict(int)
res["01234567"]=1
solve()
while True:
    try:
        s=raw_input().split()
    except EOFError:
        break
    s="".join(s)
    print res[s]-1

Measured memory_bytes: 6180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    int n,m;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    cin >> m;
    vector<string> t(m);
    rep(i,m) cin >> t[i];

    map<string,int> mps,mpt;
    rep(i,n) mps[s[i]]++;
    rep(i,m) mpt[t[i]]++;

    int ans = 0;
    rep(i,n) ans = max(ans,mps[s[i]] - mpt[s[i]]);

    cout << ans << endl;


}

Measured memory_bytes: 3588
from collections import Counter
import bisect

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
L = Counter(prime_factorize(n))
A = [0]*50
for i in range(50):
    cnt = 1
    while i >= (cnt+1)*(cnt+2)//2:
        cnt += 1
    A[i] = cnt
ans = 0
for c in L.values():
    ans += A[c]
print(ans)

Measured memory_bytes: 9308
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 4010;

int a[N], b[N], c[N], d[N], e[N], f[N];
bool l[N][N], r[N][N], u[N][N], dd[N][N]; // blocked ? 
bool vis[N][N];

int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

vi xs({-INF, INF}), ys({-INF, INF});

queue<pi> q;

void BFS(int x, int y) {
	vis[x][y] = 1;
	q.push({x, y});
	while(q.size()) {
		int x = q.front().F, y = q.front().S;
		q.pop();
		for(int i = 0; i < 4; i++) {
			if(i == 0 && u[x][y]) continue;
			if(i == 1 && dd[x][y]) continue;
			if(i == 2 && r[x][y]) continue;
			if(i == 3 && l[x][y]) continue;
			int xx = x + dir[i][0];
			int yy = y + dir[i][1];
			if(xx < 0 || yy < 0) continue;
			if(xx >= xs.size() - 1 || yy >= ys.size() - 1) continue;
			if(vis[xx][yy]) continue;
			vis[xx][yy] = 1;
			q.push({xx, yy});
		}
	}
}

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		xs.PB(a[i]);
		xs.PB(b[i]);
		ys.PB(c[i]);
	}
	for(int i = 0; i < m; i++) {
		cin >> d[i] >> e[i] >> f[i];
		xs.PB(d[i]);
		ys.PB(e[i]);
		ys.PB(f[i]);
	}
	sort(ALL(xs));
	sort(ALL(ys));
	xs.resize(unique(ALL(xs)) - xs.begin());
	ys.resize(unique(ALL(ys)) - ys.begin());
	int x = lower_bound(ALL(xs), 0) - xs.begin();
	int y = lower_bound(ALL(ys), 0) - ys.begin();
	x--, y--;
	for(int i = 0; i < n; i++) {
		int aa = lower_bound(ALL(xs), a[i]) - xs.begin();
		int bb = lower_bound(ALL(xs), b[i]) - xs.begin();
		int cc = lower_bound(ALL(ys), c[i]) - ys.begin();
		for(int j = aa; j < bb; j++) {
			u[j][cc-1] = 1;
			dd[j][cc] = 1;
		}
	}
	for(int i = 0; i < m; i++) {
		int ddd = lower_bound(ALL(xs), d[i]) - xs.begin();
		int ee = lower_bound(ALL(ys), e[i]) - ys.begin();
		int ff = lower_bound(ALL(ys), f[i]) - ys.begin();
		for(int j = ee; j < ff; j++) {
			r[ddd-1][j] = 1;
			l[ddd][j] = 1;
		}
	}
	BFS(x, y);
	if(vis[0][0]) {
		cout << "INF" << endl;
		return 0;
	}
	ll ans = 0;
	for(int i = 0; i < xs.size() - 1; i++) {
		for(int j = 0; j < ys.size() - 1; j++) {
			if(vis[i][j]) {
				ans += (ll) (xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
			}
		}
	}
	cout << ans << endl;
}





Measured memory_bytes: 49812
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
using namespace std;

int main() {
    //input
    int n;cin >> n;
    string str; cin >> str;
    vector<int> e(n,0);
    vector<int> w(n,0);
    vector<int> change(n,0);

    //compute
    int ans = 0;
    e[0] = bool(str.at(0) == 'E');
    w[0] = bool(str.at(0) == 'W');

    for(int i = 1; i < n; i++){
            if(str.at(i) == 'E'){
                e[i] = e[i - 1] + 1;
                w[i] = w[i - 1];
            }else{
                w[i] = w[i - 1] + 1;
                e[i] = e[i - 1];                
            }
    }

    for(int i = 0; i < n; i++) {
        if(str.at(i) == 'E'){
            change[i] = w[i] + e[n - 1] - e[i];
        }else{
            change[i] = w[i] - 1 + e[n - 1] - e[i];
        }
    }

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

    ans = change[0];

    //output
    cout << ans << endl;

}


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

using namespace std;

int main(){
    int N,M,x,y;
    bool ans = false;
    cin >> N >> M;
    vector<vector<int>> ab(N);
    for(int i=0;i<M;i++){
        cin >> x >> y;
        x--;
        y--;
        ab[x].push_back(y);
        ab[y].push_back(x);
    }

    for(int i=0;i<ab[0].size();i++){
        for(int j=0;j<ab[ab[0][i]].size();j++){
            if(ab[ab[0][i]][j] == N-1){
                ans = true;
            }
        }
    }

    if(ans){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 12016
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
from math import gcd
cm = 1
for i in range(n):
    cm = cm*a[i]//gcd(cm, a[i])
ai = sum(pow(x, mod-2, mod) for x in a)
print(int(ai*cm%mod))

Measured memory_bytes: 10144
N, M = map(int, input().split())
H = list(map(int, input().split()))
g = [1] * N
ab = [list(map(int, input().split())) for i in range(M)]
for a, b in ab:
    if H[a-1] < H[b-1]:
        g[a-1] = 0
    elif H[a-1] > H[b-1]:
        g[b-1] = 0
    else:
        g[a-1] = g[b-1] = 0
print(sum(g))

Measured memory_bytes: 31948
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

ll gcd(ll a, ll b) {
	if (a > b) {
		swap(a, b);
	}
	if (a == 0) {
		return b;

	}

	return gcd(b % a, a);
}

int main() {
	int t;
	cin >> t;

	for (int i = 0; i < t; i++) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;

		if (a < b) {
			cout << "No" << endl;
			continue;
		}
		if (b > d) {
			cout << "No" << endl;
			continue;
		}

		if (b <= c) {
			cout << "Yes" << endl;
			continue;
		}

		ll g = gcd(b, d);
		if (c >= (b - g + a % g)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
			
	}
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
    int n,x,ans,i,j,k;
    while (cin>>n>>x) {
        if (n == 0 && x == 0) break;
        ans = 0;
        for (i=1;i<n-1||i<=x/3;i++) {
            for (j=i+1;j<n||j<=x/2;j++) {
                if (j < x-i-j && x-i-j <= n) ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int Prime[100010];   //Prime[i]が1ならiは素数。0ならiは素数でない

void Eratosthenes(int n) {  //n未満の素数を求める

    rep(i, n) {
        Prime[i] = 1;
    }

    Prime[0] = 0;  Prime[1] = 0;
    for(int i = 2; i*i < n; i++) {
        if(Prime[i]) {
            for(int j = 2; i*j < n; j++) {
                Prime[i*j] = 0;
            }
        }
    }
}

int f[100010];

int main() {

    Eratosthenes(100000);

    for(int i = 3; i < 100000; i += 2) {
        f[i] = f[i-2];

        if(Prime[i] && Prime[(i+1)/2]) {
            f[i]++;
        }
    }

    int q;
    cin >> q;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << f[r] - f[l-2] << "\n"; 
    }
    
    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

    string S;

    cin>>S;

    yn(S[2]==S[3]&&S[4]==S[5]);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


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

    int ans = 1;
    Rep(i, 0, n-2){
        if(s[i] != s[i+1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

/*
 
 A * x // B - A * x // B
 == (A * x - A * x % B) / B - A * (x - x % B) / B
 == - A * x % B / B + x % B * A / B
 == (x % B * A - x * A % B) / B
 == (x % B * A - x % B * A % B) / B
 X := x % B とすると
 == (X * A - X * A % B) / B
 == X * A // B
 よって X はできるだけ大きくとるべき
 
*/

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    if(n >= b) n = b - 1;
    cout << n * a / b << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<functional>
#include<queue>
using namespace std;
string S1, S2; long long n, mod = 1000000007;
int main() {
	cin >> n >> S1 >> S2;
	long long A = 1;
	if (S1[0] == S2[0])A *= 3;
	else A *= 6;
	for (int i = 1; i < n; i++) {
		if (S1[i] == S2[i]) {
			if (S1[i - 1] == S2[i - 1])A *= 2;
		}
		else {
			if (S1[i - 1] == S2[i - 1])A *= 2;
			else if (S1[i - 1] != S1[i] && S2[i - 1] != S2[i])A *= 3;
		}
		A %= mod;
	}
	cout << A << endl;
	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < h; i++) cin >> g[i];

  vector<vector<int> > a(h, vector<int>(w, INF));

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (g[y][x] != '#')
        for (int i = 0; i < 4; i++) {
          if (0 <= y + dy[i] && y + dy[i] < h && 0 <= x + dx[i] && x + dx[i] < w) {
            if (g[y + dy[i]][x + dx[i]] == '#')
              a[y][x] = 1;
            else if (g[y + dy[i]][x + dx[i]] > 0)
              a[y][x] = min(a[y][x], a[y + dy[i]][x + dx[i]] + 1);
          }
        }
      else
        a[y][x] = 0;
    }
  }

  for (int y = h - 1; y >= 0; y--) {
    for (int x = w - 1; x >= 0; x--) {
      if (g[y][x] != '#')
        for (int i = 0; i < 4; i++) {
          if (0 <= y + dy[i] && y + dy[i] < h && 0 <= x + dx[i] && x + dx[i] < w) {
            if (g[y + dy[i]][x + dx[i]] == '#')
              a[y][x] = 1;
            else if (g[y + dy[i]][x + dx[i]] > 0)
              a[y][x] = min(a[y][x], a[y + dy[i]][x + dx[i]] + 1);
          }
        }
      else
        a[y][x] = 0;
    }
  }

  int ans = -1;
  for (auto x : a) {
    ans = max(ans, *max_element(x.begin(), x.end()));
  }
  cout << ans << endl;
}


Measured memory_bytes: 5248
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e16;
typedef array<int, 3>arr3;
void die(string s) { cout << s << endl; exit(0); }
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

//10^7までの素数を列挙する
bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 1000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.push_back(i);
			c++;
		}
	}
}
void solve() {
	int N; cin >> N;
	Eratosthenes();
	vector<int>ans;
	for (auto p : sosuu) {
		if (p <= 55555 && p % 5 == 1)ans.push_back(p);
	}
	REP(i, N) {
		pe(ans[i]);
	}cout << endl;
}


signed main() {
	solve();
}



Measured memory_bytes: 2424
#input one int
#a = int(input())

#input some val
#a, b, c = (int(i) for i in input().split())
#val = [[int(i) for i in input().split()] for i in range(N)]

#input matrix
#a = [input().split() for i in range()]

N = int(input())

temp = N
Sn = 0

while(temp >= 1):
    Sn = Sn + temp%10
    temp = temp//10

if(N%Sn==0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <stdio.h>
#include<string.h>

int main() {
	
	long long int N;
	long long int sum = 0;
	
	scanf("%lld", &N);
	
	for(int i = 1; i <= N; i++){
		if(i % 3 != 0 && i % 5 != 0 ){
			sum += i;
		}
	}
	
	printf("%lld\n", sum);
	
	
	return 0;
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

long long l_max = 3234566667;

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

vll v;

bool dfs(string s) {
    if (stoll(s) > l_max) {
        return false;
    } else {
        string t = s + s[s.size() - 1];

        long long temp = stoll(t);

        switch (temp % 10) {
        case 0: {
            v.push_back(temp);
            v.push_back(temp + 1);
            dfs(to_string(temp + 1));
            dfs(to_string(temp));
            break;
        }
        case 9: {
            v.push_back(temp);
            v.push_back(temp - 1);
            dfs(to_string(temp - 1));
            dfs(to_string(temp));
            break;
        }
        default: {
            v.push_back(temp);
            v.push_back(temp - 1);
            v.push_back(temp + 1);
            dfs(to_string(temp - 1));
            dfs(to_string(temp));
            dfs(to_string(temp + 1));
        }
        }
    }

    return false;
}

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

    long long k;
    cin >> k;

    for (long long i = 1; i < 10; i++) {
        v.push_back(i);
        while (dfs(to_string(i))) {
        }
    }

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

    cout << v[k - 1] << endl;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p.at(i);
    
    sort(p.begin(), p.end());

    int count = 0;
    for(int i = 0; i < k; i++)
        count += p[i];

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3632
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    a,b,c,d=map(int,input().split())
    A=[]
    A.append(a*c)
    A.append(a*d)
    A.append(b*c)
    A.append(b*d)
    print(int(max(A)))
   




if __name__ == '__main__':
    main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

    ll n,we;
    cin>>n>>we;

    vl v(n),w(n);
    ll sum = 0;
    forn(i,0,n)
    {
        cin>>w[i]>>v[i];
        sum += v[i];
    }

        
    // v2l dp(n+1,vl(we+1,0));

// 3 8
// 3 30
// 4 50
// 5 60


    vl dp(sum+1,imx);
/*    forn(i,0,sum+1)
    {
        cout<<dp[i]<<" "<<i<<endl;
    }*/
    dp[0] = 0;
    for(ll i = 0; i < n; i++)
    {
        for(ll j = sum-v[i]; j >= 0; j--)
        {
            dp[j+v[i]] = min(dp[j+v[i]],w[i]+dp[j]);
        }
    }

    ll maxi = 0;

    forn(i,0,sum+1)
    {
        // cout<<dp[i]<<" "<<i<<endl;
        if(dp[i] <= we)
        {
            maxi = max(maxi,(ll)i);
        }
    }

/*    forn(i,0,sum+1)
    {
        cout<<dp[i]<<" "<<i<<endl;
    }*/

    cout<<maxi;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int n,ans=0,same=0;
	string s;
	vector<string> w;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		w.push_back(s);
	}
	for (int i = 0; i < (n-1); i++)
	{
		if (w[i].back() == w[i + 1].front())
			ans++;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (j != i && w[i]==w[j])
				same++;
		}
	}
	if (same == 0 && ans == (n-1))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;

struct uf {
private:
	vector<int> par, ran;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

void solve() {
	int n, m; cin >> n >> m;
	uf u; u.init(n + 1);
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		u.unite(a, b);
	}
	int tmp = 0;
	rep(i, n) {
		if (u.same(i, n))continue;
		tmp++; u.unite(i, n);
	}
	cout << m - n + tmp << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n,n)solve();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 3236
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
//最大公約数
ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K; cin >> N >> K;
  ll A[N];
  ll mx = 0;
  FOR(i,0,N) {
    cin >> A[i];
    mx = max(mx, A[i]);
  }
  int g = gcd(A[0], A[1]);
  FOR(i,2,N) g = gcd(g, A[i]);
  if(K <= mx && (mx - K) % g == 0) puts("POSSIBLE");
  else puts("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
int main() {
  //
  ll n;
  cin >> n;
  map<ll, ll> mp;
  rep(i, n) {
    ll a;
    cin >> a;
    mp[a] = i;
  }
  set<ll> s1;
  set<ll, greater<ll>> s2;
  ll ans = 0;
  for (auto& x : mp) {
    ll a = x.first;
    ll i = x.second;
    s1.insert(i);
    s2.insert(i);
    set<ll>::iterator rit = s2.find(i);
    set<ll>::iterator it = s1.find(i);
    ll c1 = 0, c2 = 0;
    rit++;
    it++;
    if (rit == s2.end()) {
      c1 = i + 1;
    } else {
      c1 = i - *rit;
    }
    if (it == s1.end()) {
      c2 = n - i;
    } else {
      c2 = *it - i;
    }
    ans += a * c1 * c2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 32248