akhauriyash/Code-Regression huggingface dataset:
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static char c[1 << 20];
    fi>>(c + 1);
    int n = strlen(c + 1);
    puts((c[1] == c[n]) == (n&1) ? "Second" : "First");
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> a(h, vector<int>(w));
    rep(i,h) cin >> s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#'){
                if(i-1 >= 0 && j-1 >= 0)a[i-1][j-1]++;
                if(i-1 >= 0)a[i-1][j]++;
                if(i-1 >= 0 && j+1 < w)a[i-1][j+1]++;
                if(j-1 >= 0)a[i][j-1]++;
                if(j+1 < w)a[i][j+1]++;
                if(i+1 < h && j-1 >= 0)a[i+1][j-1]++;
                if(i+1 < h)a[i+1][j]++;
                if(i+1 < h && j+1 < w)a[i+1][j+1]++;
            }
        }   
    }

    rep(i,h){
        rep(j,w){
            if(s[i][j] != '#')cout << a[i][j];
            else cout << '#';
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
int main(void){
    int n,x;
    cin >> n >> x;
    int x_sa[n];
    for(int i=0;i<n;i++){
        int x1;
        cin >> x1;
        x_sa[i]=abs(x-x1);
    }
    int ans = x_sa[0];
    for(int i=1;i<n;i++){
        if(ans<x_sa[i]){
            swap(ans,x_sa[i]);
        }
        int r = ans % x_sa[i];
        while(r!=0){
            ans = x_sa[i];
            x_sa[i] = r;
        r = ans % x_sa[i];
        }
        ans = x_sa[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
//author-abhijit dey
 //Welcome to my code. btw I hate coding 😉
#include <bits/stdc++.h>
using namespace std;
#define     ff first
#define     ss second
#define     pb push_back
#define     mp make_pair
#define     INF 1000000005
#define     MOD 1000000000
#define     ninf -1000000000
#define     all(c) c.begin(), c.end()
#define     tinput long long int t;cin>>t;
#define     mem(a,x) memset(a,x,sizeof a)
#define     for0(i,n) for(long long int i=0;i<n;i++)
#define     pi 3.141592653589793238462643383279502884
#define     fori(i,a,n) for(long long int i=a;i<n;i++)
#define     forxy(i,x,y) for(int i=x;i<=y;i++)
#define     rfor(i,n) for(long long int i=n-1;i>=0;i--)
#define     ainput for(int i=0; i<n; i++) cin>>a[i];
#define     fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef     long long int ll;
typedef     vector<long long int>vll;
typedef     vector<vector<int> >vvll;
typedef     pair<long long int,long long int>pr;
typedef     vector<pair<long long int,long long int> >vp;

inline long long  min2(long long  a, long long  b)  {return (a)<(b)?(a):(b);}
inline long long  max2(long long  a, long long  b)  {return (a)>(b)?(a):(b);}
inline long long  max3(long long  a, long long  b, long long  c)    {return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  min3(long long  a, long long  b, long long  c)    {return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std::chrono;
ll N,W;
ll w[101],v[101];
ll dp[101][100001];
ll maxvalue(ll ind,ll W)
{
    ll left=INT_MIN,right=INT_MIN;

    if(ind==N+1)return 0;
    if(dp[ind][W]!=-1)return dp[ind][W];
    if(W>=w[ind])
    left=v[ind]+maxvalue(ind+1,W-w[ind]);
    right=maxvalue(ind+1,W);

    dp[ind][W]=max(left,right);
    return dp[ind][W];
}
void process()
{
    cin>>N>>W;
    for(ll i=1;i<=N;i++)cin>>w[i]>>v[i];
    memset(dp,-1,sizeof(dp));
    cout<<maxvalue(1,W);
}
int main()
{
    fastio;
    //tinput;
    //while(t--)
        process();
}

Measured memory_bytes: 79232
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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























int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			for(int k = 0; k < 9; k++){
				if ((i & (1 << k)) ^ (j & (1 << k))) {
					printf("%d ", k + 1);
					break;
				}
			}
		}
		printf("\n");
	}
}


Measured memory_bytes: 512
while(True):
    count = 0
    sc = input().split()
    n = int(sc[0])
    x = int(sc[1])
    if (n == 0) and (x == 0):
        break;
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    count += 1
    print(count)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
VI p(A), q(B), r(C); invec(p), invec(q), invec(r);

sort(ALL(p), greater<i64>());
sort(ALL(q), greater<i64>());

rep(i, 0, X) r.push_back(p[i]);
rep(i, 0, Y) r.push_back(q[i]);
sort(ALL(r), greater<i64>());

cout << accumulate(RANGE(r, 0, X+Y), (i64)0) << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 6512
def main():
    N = int(input())
    S = [input() for _ in range(N)]

    ac = 0
    wa = 0
    tle = 0
    re = 0

    for s in S:
        if s == 'AC':
            ac += 1
        elif s == 'WA':
            wa += 1
        elif s == 'TLE':
            tle += 1
        else:
            re += 1

    print('AC x '+str(ac))
    print('WA x '+str(wa))
    print('TLE x '+str(tle))
    print('RE x '+str(re))


if __name__ == "__main__":
    main()


Measured memory_bytes: 16320
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String[] s = sc.next().split("-");
        if(s.length != 2 || s[0].length() != a || s[1].length() != b){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23764
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans=1;
  vector <int> h(n,0);

  for (int i=0;i<n;i++){
    cin >> h[i] ;
  }

  int max=h[0];
  

  for(int i=1;i<n;i++){
    if((h[i]>=h[i-1]) and max<=h[i] ){
      ans++;
      max=h[i];
    }
  }

  cout << ans << endl;


  return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

#define MAX 100005
#define NIL -1

struct Node {
    int p, l, r;
};

Node T[MAX];
int  n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) {
        cout << "root, ";
    } else if (T[u].l == NIL) {
        cout << "leaf, ";
    } else {
        cout << "internal node, ";
    }
    cout << "[";
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int i, j, d, v, c, l, r;
    cin >> n;
    rep(i, n) { T[i].p = T[i].l = T[i].r = NIL; }
    rep(i, n) {
        cin >> v >> d;
        rep(j, d) {
            cin >> c;
            if (j == 0)
                T[v].l = c;
            else
                T[l].r = c;
            l      = c;
            T[c].p = v;
        }
    }
    rep(i, n) {
        if (T[i].p == NIL) r = i;
    }

    rec(r, 0);

    rep(i, n) print(i);
    return 0;
}



Measured memory_bytes: 7736
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() float64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return float64(i)
}

func main() {
	sc.Split(bufio.ScanWords)
	x := nextInt()
	a := nextInt()
	b := nextInt()

	if math.Abs(x-a) < math.Abs(x-b) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 2e4+5;
const ll mod = 1e9+7;
char s[maxn];
int arr[maxn];
int d,len;
ll dp[maxn][105][2];
ll getdp(int pos,int cur,int lim){
	if(pos == len +1 ){
		if(!cur) dp[pos][cur][lim] = 1;
		else dp[pos][cur][lim] = 0;
		return dp[pos][cur][lim];
	}
	if(dp[pos][cur][lim]!=-1) return dp[pos][cur][lim];
	int up = lim?arr[pos]:9;
	ll sum = 0;
	for (int i = 0; i <=up; ++i)
	{
		sum+=getdp(pos+1,(cur+i)%d,lim && i == up);
		sum%=mod;
		/* code */
	}
	dp[pos][cur][lim] = sum;
	return sum;
}
int main() {
	scanf("%s",s+1);
	scanf("%d",&d);
	len = strlen(s+1);
	for (int i = 1; i <=len; ++i)
	{
		arr[i] = s[i] - '0';
		/* code */
	}
	memset(dp,-1,sizeof(dp));
	ll ans = getdp(1,0,1);
	printf("%lld\n",(ans-1+mod)%mod);
	return 0;
}

Measured memory_bytes: 34176
// ABC111_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    string N;
    cin >> N;
    
    // calculation
    cout << (N[0] == '1' ? '9': '1') << (N[1] == '1' ? '9': '1') << (N[2] == '1' ? '9': '1') << "\n";
    
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


ans = 0
N, M = map(int, input().split())
path = [[False]*N for _ in range(N)]
# 0 to N-1, N nodes
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True


for i in itertools.permutations(range(N), N):
    if i[0] == 0:
        for j in range(N-1):
            if not path[i[j]][i[j+1]]:
                break
            if j == N-2:
                ans += 1

print(ans)

Measured memory_bytes: 13684
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define tr(s)                                      \
	for (auto it = v.begin(); it != v.end(); it++) \
		cout << *it << " ";
#define pv(a)                         \
	for (ll i = 0; i < a.size(); i++) \
		cout << a[i] << " ";
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\n';
ll i, j, le;
int main()
{
	IOS;
	int t;
t=1;


	while (t--)
	{
		ll a,b,c,k;
		cin>>a>>b>>c>>k;
		while(k>0)
		{  if(b<=a)
			{b=b*2;
         k--;}
		 else break;
		}
		while(k>0)
		{
			if(c<=b)
			{
				c=c*2;
				k--;
			}
			else break;
		}
		if(b > a && c>b)
		cout<<"Yes"<<e;
		else cout<<"No"<<e;
	}
	return 0;
}


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

using namespace std;

using pii = pair<int, int>;

int main()
{
    while (true) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;
        if (M == 0 and T == 0 and P == 0 and R == 0) {
            break;
        }
        vector<vector<int>> wa(T, vector<int>(P, 0));
        vector<pair<pii, int>> score(T, make_pair(make_pair(P, 0), 0));
        for (int i = 0; i < T; i++) {
            score[i].second = T - i;
        }
        for (int i = 0; i < R; i++) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--, p--;
            if (j == 0) {
                score[t].first.first--;
                score[t].first.second += (m + wa[t][p] * 20);
            } else {
                wa[t][p]++;
            }
        }
        sort(score.begin(), score.end());
        for (int i = 0; i < T; i++) {
            if (i > 0) {
                if (score[i - 1].first.first == score[i].first.first and score[i - 1].first.second == score[i].first.second) {
                    cout << '=';
                } else {
                    cout << ',';
                }
            }
            cout << T - score[i].second + 1;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll mod = 998244353;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  mint ans = 0;
  mint col = m;
  for (int x = n - 1; x >= 0; --x) {
    mint now = col;
    now *= c(n - 1, x);
    if (x <= k) ans += now;
    col *= m - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6236
#include<stdio.h>

int main(){
	
	int N,A[100010],i,B[100010];
	
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		scanf("%d",&A[i]);
		B[A[i]]=i;
	}
	
	for(i=1;i<=N;i++){
		printf("%d ",B[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
  map<string, int> s, t;
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    s[str]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    string str;
    cin >> str;
    t[str]++;
  }
  int count = 0;
  for (auto itr = s.begin(); itr != s.end(); itr++) {
    count = max(count, itr->second - t[itr->first]);
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 764
/*
AtCoder=abc081_b
g++ ${AtCoder}.cpp -o ${AtCoder}.out
./${AtCoder}.out
3
8 12 40
*/


#include <iostream>
#include <cmath>

using namespace std;

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

int main() {

    int N, a;
    scanf("%d", &N);

    int ans = 32767;
    int tmp = 0;

    REP(i, N){
        scanf("%d", &a);
        tmp  = 0;
        REP(j, ans){
            if (a % 2 == 0) {
                a   /= 2;
                tmp  = j + 1;
            } else {
                break;
            }
        }
        ans = min(ans, tmp);
        if (ans == 0) {
            break;
        }
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i,n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }

const int mod = 1000000007;
const int INF = 1001001001;

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    while(x <= y) {
        x *= 2;
        ans += 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
typedef long long ll;
 
int main()
{
    int a,b,c,d,e,f;
 
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
 
    double res = 0;
    ll anss = 0,sum = 0;
    ll pres = 0,prew = 0;
 
    for (ll i = 0;i <= 100;i++)
        for (ll j = 0;j <= 100;j++)
        for (ll k = 0;k <= 100;k++)
        for (ll l = 0;l <= 100;l++)
    {
        if (1.0 * (k * c + l *d) / e > i * a + j * b) continue;
        if (k * c + l * d + 100 * i * a + 100 * j * b > f) continue;
 
        if (i + j == 0) continue;
 
        ll w = 100 * (a * i + b * j);
        ll s = k * c + l * d;
 
        
 
        if (100 * s * (pres + prew) >= 100 * pres * (s + w))
        {
            prew = w;
            pres = s;
 
            anss = s;
            sum = w + s;
        }
    }
 
    printf("%lld %lld\n",sum,anss);
 
    return 0;
}

Measured memory_bytes: 128
A,B = map(int,input().split())
S = list(input())

erro = 0

for i in range(A):
  if S[i] == '-':
    erro += 1
    
if S[A] != '-':
  erro += 1
  
for _ in range(A+1,A+B+1):
  if S[_] == '-':
    erro += 1

if erro > 0:
  print('No')
  
else:
  print('Yes')
  

    

Measured memory_bytes: 3060
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    
    String ans = "";
    if(S.equals("Sunny")){
      ans = "Cloudy";
    }else if(S.equals("Cloudy")){
      ans = "Rainy";
    }else{
      ans = "Sunny";
    }
    System.out.println(ans);
  }
}

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



signed main() {
	int n;
	cin >> n;
	int val[n];
	for(int i=0;i<n;i++){
		cin >> val[i];
	}
	int dp[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i>j){
				dp[i][j]=0;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n-i;j++){
			if(i==0){
				dp[j][i+j]=val[j];
			}
			else{
				dp[j][i+j]=max(val[j]-dp[j+1][i+j],val[i+j]-dp[j][i+j-1]);
			}
		}
	}
	cout << dp[0][n-1];
	// your code goes here
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 20000000

vector <i64> v ;

int d(i64 x)
{
    int sum = 0 ;
    while(x!=0)
    {
        sum += x%10 ;
        x /=10 ;
    }
    return sum ;
}

int main()
{
    i64 i , j , k , last , dist ;

    v.pb(1) ;

    last = 1 ; dist = 1 ;

    while( last <1000000000000000 )
    {
        last = v[ (int)v.size() - 1 ] ;
        i64 cur = last + dist ;

        if( last*d(cur) > cur*d(last) )
        {
            dist *= 10 ;
            v.pop_back() ;
            continue ;
        }
        else v.pb(cur) ;
        last = cur ;
    }

  //  for(i=0 ; i<v.size() ; i++) printf("%lld: %lld\n",i+1,v[i]) ;

    scanf("%lld",&k) ;

    for(i=0 ; i<k ; i++) printf("%lld\n",v[i]) ;

    return 0 ;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {

		Scanner scanner=new Scanner(System.in);

		int n=scanner.nextInt();
		int m=scanner.nextInt();

		Map<Integer,Integer> data=new TreeMap<Integer,Integer>();

		for(int i=1;i<=n;i++) {
			data.put(i,0);
		}
		
		while(scanner.hasNext()) {

			Integer buf=scanner.nextInt();

			data.put(buf,data.get(buf)+1);
			
		}

		for(Integer key:data.keySet()) {
			System.out.println(data.get(key));
		}



		scanner.close();

	}

	public static int getsumofkakuketa(int n) {

		int result=0;

		while(true) {

			result+=n%10;

			if(n/10!=0) {
				n/=10;
			}else {
				return result;
			}
		}



	}

	public static boolean isMacthed(int a,int b,int sum) {

		if(sum>=a && sum<=b) {
			return true;
		}else {
			return false;
		}

	}



}







Measured memory_bytes: 21716
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return true;
    }
    else { // 発見できなかったとき
        return false;
    }
}

int main(){
    ll N;
    cin >> N;
    ll cnt=0;
    for(ll i=1; i<=(int)sqrt(N); i++){
        if (N%i==0){
            ll large = N/i;
            if (large-i>=2) cnt += (large-1);
        }
    }
    cout << cnt << endl;

    return 0;
}


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

int main() {
  ll i, j, k, N, K; cin >> N >> K;
  string s, t;
  vector<int> h(N);
  rep (i, N)  cin >> h.at(i);
  sort(h.begin(), h.end(), greater<int>());
  ll sum = 0;
  auto start = h.begin();
  int num = K;
  while (start < h.end() && num > 0) start++, num--;
  sum = accumulate(start, h.end(), sum);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using namespace std;

signed main (){
  int count = 0 ;
  rep(i,3){
    char a ;
    cin>>a ;
    if(a=='1'){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main (String[]args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N];
    int counter = 0;
    for(int i=0; i<N; ++i){
      a[i] = sc.nextInt();
    } //とりあえずaに全部代入
    while(true) {
      boolean exist_odd = false;
      for (int i=0; i<N; ++i){
        if(a[i]%2 != 0){
          exist_odd =true;
        }
      }
        //奇数あったら終了
        if(exist_odd){break;}
        //全て偶数なら操作を行う
        for (int i=0; i<N; ++i){
          a[i] /= 2;
          }
          ++counter;



    }

    System.out.println(counter);
  }
}


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

int main(){
    int N;
    cin >> N;
    int h[N];
    for(int i =0; i < N; i++){
        cin >> h[i];
    }
    for(int i =1; i < N; i++){
        if(h[i-1] > h[i] + 1){
            cout << "No" << endl;
            return 0;
        }
        if(h[i-1] == h[i] + 1){
            h[i] ++;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S){
  if (N % 2 != 0){
    cout << NO << endl;
    return;
  }
  string sub1 = S.substr(0, N / 2);
  string sub2 = S.substr((N+1) / 2 , N / 2);
  if(sub1 == sub2) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
  solve(N, S);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int N,M,ans=0,x=0;
string s[100],t[100],str;
int main(void){
	cin>>N;
	for(int i=0;i<N;i++)cin>>s[i];
	cin>>M;
	for(int i=0;i<M;i++)cin>>t[i];
	for(int i=0;i<N;i++){
		str=s[i];
		for(int i=0;i<N;i++)if(s[i]==str)x++;
		for(int i=0;i<M;i++)if(t[i]==str)x--;
		ans=max(x,ans);
		x=0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
MOD = 10**9+7

#c[i] := (i)C(K-1)
c = [0] * (N+1)
#frac[i] = i!%MOD
frac = [1] * (N+1)
for i in range(1, N+1):
  frac[i] = (frac[i-1]*i)%MOD
for i in range(1, N+1):
  if(i >= K-1):
    c[i] = frac[i]*pow(frac[K-1], MOD-2, MOD)*pow(frac[i-K+1], MOD-2, MOD)%MOD

  
ans = 0
for i in range(N):
  ans = (ans + A[i]*c[i])%MOD
for i in range(N):
  ans = (ans - A[i]*c[N-i-1])%MOD
  
print(ans)

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

int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  rep(i, s.size()) {
    if (s[i] != t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define vi vector<ll int>

int h,w,k,ans=1e9;
string s[1000];
vector <int> colsum[1000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		cin >> h >> w >> k;
		for(int i=0;i<h;i++) cin >> s[i];
		for(int rs=0;rs <1<<h-1;rs++){
			int temp = __builtin_popcount(rs);
			for(int j=0;j<w;j++){
				int sum=0;
				for(int i=0;i<h;i++){
					sum += s[i][j]&1;
					if(rs>>i&1){
						colsum[j].pb(sum);
						sum=0;
					}
				}
				colsum[j].pb(sum);
				for(int x : colsum[j]){
					if(x > k) temp = 1e9;
				}
			}
			vector <int> block(colsum[0].size());
			for(int j=0;j<w;j++){
				bool split=0;
				for(int i=0;i<block.size();i++){
					split |= block[i] + colsum[j][i] > k;
				}
				if(split){
					temp++;
					block = vector <int>(block.size());
				}
				for(int i=0;i<block.size();i++){
					block[i] += colsum[j][i];
				}
				colsum[j].clear();
			}
			ans = min(ans,temp);
		}
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int max(int,int,int);

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    
    int c,d,e;
    c=a+b;
    d=a-b;
    e=a*b;
    
    printf("%d",max(c,d,e));
    return 0;
}

int max(a,b,c){
    int max;
    max=a;
    if(b>max){max=b;}
    if(c>max){max=c;}
    
    return max;
}

Measured memory_bytes: 128
use proconio::fastout;
use whiteread::parse_line;
use std::collections::{HashMap, HashSet};

#[fastout]
fn main() {
    let (N, M): (usize, usize) = parse_line().unwrap();
    let heights: Vec<usize> = parse_line().unwrap();
    let mut map: HashMap<usize, usize> = HashMap::new();
    for i in 0..M {
        let (A, B): (usize, usize) = parse_line().unwrap();

        map.entry(A).or_insert(0);
        map.entry(B).or_insert(0);
        if map.get(&A).unwrap() < &heights[B-1] {
            map.insert(A, heights[B-1]);
        }
        if map.get(&B).unwrap() < &heights[A-1] {
            map.insert(B, heights[A-1]);
        }
    }
    let mut cnt = 0;
    for (k, v) in map.iter() {
        if heights[k-1] > *v {
            cnt += 1;
        } else {
            continue;
        }
        // println!("{:?} {:?}", k, v);
    }
    let tmp = N - map.keys().collect::<Vec<&usize>>().len();
    cnt += tmp;
    println!("{}", cnt)
}


Measured memory_bytes: 7308
#include<bits/stdc++.h>
using namespace std;
string s;
const int NMAX = 200000;
int v[NMAX+5];
 int main()
 {
     long long  t, n, k, x;
     int i;
     long long sum = 0;
     cin>>n;
     for(i=1;i<=n;i++)
     {
         cin>>v[i];
     }
     for(i=1;i<=n;i++)
     {
         if(v[i-1]> v[i]) {
             sum += v[i - 1] - v[i];
             v[i] = v[i-1];
         }
     }
     cout<<sum<<"\n";

 }

Measured memory_bytes: 4412
from heapq import heappop, heappush, heappushpop

Q = int(input())

b = 0
la = []
sl = 0
ra = []
sr = 0

cnt = 0
for _ in range(Q):
    q = input().split()
    # print(la, ra)
    if q[0] == '2':
        # 求値
        x = -la[0]
        print(x, ((cnt + 1) // 2 * x - sl) + (sr - cnt // 2 * x) + b)
    else:
        # 更新
        x, y = map(int, q[1:])
        b += y
        cnt += 1
        if cnt % 2 == 1:
            sr += x
            x = heappushpop(ra, x)
            sr -= x
            sl += x
            heappush(la, -x)
        else:
            sl += x
            x = heappushpop(la, -x)
            x *= -1
            sl -= x
            sr += x
            heappush(ra, x)


Measured memory_bytes: 79836
#include <iostream>
using namespace std;
int main(){
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int counter=0;
  for (int i=0; i<A+1; ++i){
    for (int j=0; j<B+1; ++j){
     for(int k=0; k<C+1; ++k){
      if(i*500+j*100+k*50==X){
        ++counter;
      }}}}
  cout<<counter<<endl;}
        

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    ll n,lim,ans,flag=0;
    cin >> n;
    lim = sqrt(n) + 1;
    while(n>=1){
        REP(i,1,lim){
            if(i*i==n){
                ans = n;
                flag = 1;
                break;
            }
        }
        if(flag) break;
        n--;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    int R , C , K , ans = 0;
    cin >> R >> C >> K;
    string area[R];

    for (int i = 0 ; i < R ; i++)
        cin >> area[i];

    for (int i = 0 ; i < (1 << R) ; i++){
        for (int j = 0 ; j < (1 << C) ; j++){
            int cnt = 0;
            for (int k = 0 ; k < R ; k++){
                if (((1 << k) & i) == 0)
                for (int l = 0 ; l < C ; l++)
                    if (((1 << l) & j) == 0 && area[k][l] == '#')
                        ++cnt;
            }
            if (cnt == K)
                ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
#define mk(x,y) make_pair(x,y)
#define F first
#define S second
#define accu(i) fixed<<setprecision(i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
using namespace std;

class score{
	public:
		ll curr;ll inc;
};

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k,q,t;cin>>n>>k>>q;
    score *a = new score[n];
    f(i,0,n){
    	a[i].curr = k-q;
    	a[i].inc = 0;
	}
	while(q--){
		cin>>t;
		a[t-1].inc++;
	}
	f(i,0,n){
    	if(a[i].curr+a[i].inc > 0) cout<<"Yes\n";
    	else cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 2176
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll p,q,r;
  std::cin>>p>>q>>r;

  std::cout<<std::min(p+q,std::min(q+r,r+p))<<"\n";

  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pii> a(n);
	rep(i, n){
		cin >>a[i].first;
		a[i].second = i;
	}
	sort(all(a));
	rep(i, n){
		cout << a[i].second+1 <<" ";
	}
	cout <<"\n";
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);

int main()
{
  int n;
  while( cin >> n, n ) {
    int max1 = 0, max2 = 0, min1 = INF, min2 = INF;
    int max1_n, max2_n, min1_n, min2_n;

    for(int i=0; i<n; i++) {
      int c1, m1, s1, m2, s2, m3, s3, m4, s4;
      int sum = 0;
      cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      sum += m1*60 +  s1 + m2*60 +  s2 + m3*60 +  s3 + m4*60 + s4;
      if( sum > max1 ) {
	max2 = max1; 
	max2_n = max1_n;
	max1 = sum;
	max1_n = c1;
      } 
      else if( sum > max2 ) {
	max2 = sum;
	max2_n = c1;
      }
      if( sum < min1 ) {
	min2 = min1; 
	min2_n = min1_n;
	min1 = sum;
	min1_n = c1;
      }
      else if( sum < min2 ) {
	min2 = sum;
	min2_n = c1;
      }
    }

    cout << min1_n << endl << min2_n << endl << max2_n << endl;
  }

}

Measured memory_bytes: 1160
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	int value(List<Integer> list) {
		int v = 0;
		for (int i : list)
			v = v*10 + i;
		return v;
	}
	
	void run() {
		String a;
		int l;
		List<Integer> list = new ArrayList<Integer>();
		List<Integer> save = new ArrayList<Integer>();
		while (true) {
			a = sc.next(); l = sc.nextInt();
			if (a.equals("0") && l == 0) break;
			
			save.clear();
			save.add(Integer.parseInt(a));
			while (true) {
				list.clear();
				for (int i = 0; i < a.length(); i++)
					list.add(Character.getNumericValue(a.charAt(i)));
				for (int i = 0; i < l-a.length(); i++)
					list.add(0);
				
				int temp1, temp2;
				Collections.sort(list);
				temp1 = value(list);
				Collections.reverse(list);
				temp2 = value(list);
				int v = temp2-temp1;
				if (save.contains(v)) {
					out.printf("%d %d %d\n", save.indexOf(v), v, save.size()-save.indexOf(v));
					break;
				} else {
					save.add(v);
					a = String.valueOf(v);
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 21340
INF = 10 ** 15
MOD = 10 ** 9 + 7 
from heapq import heappop,heappush,heapify
def dijkstra(G,start = 0):
    N = len(G)
    dist = [INF] *N
    dist[start] = 0
    q = [(0,start)]

    while q:
        d,v = heappop(q)
        if d > dist[v]:
            continue
        for e,c in G[v]:
            if dist[v] + c < dist[e]:
                dist[e] = dist[v] + c
                heappush(q,(dist[e],e))
    return dist[-1]

def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        l,r,c = map(int,input().split())
        l -= 1
        r -= 1
        G[l].append((r,c))
        G[r].append((l,c))
    for i in range(N - 1):
        G[i + 1].append((i,0))
    ans = dijkstra(G)
    print(ans if ans < INF else -1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 54504
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 3e3+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n, m, p;
vi e[N], c[N], re[N];
ll dis[N];
bool in[N];
int cnt[N], can[N];
void bfs() {
	mt(can, 0);
	queue<int> q;
	q.push(n); can[n] = 1;
	while(sz(q)) {
		int u = q.front(); q.pop();
		for(auto v: re[u]) {
			if(can[v]) continue;
			q.push(v); can[v] = 1;
		}
	}
	// rep(i, 1, n + 1) dd(i), de(can[i]);
}
ll spfa() {
	mt(dis, -1); mt(in, false); mt(cnt, 0);
	dis[1] = 0;
	queue<int> q;
	q.push(1); in[1] = 1;
	while(sz(q)) {
		int u = q.front(); q.pop();
		in[u] = 0;
		rep(i, 0, sz(e[u])) {
			int v = e[u][i], w = c[u][i];
			if(!can[v]) continue;
			if(dis[v]==-1||dis[v]<dis[u]+w) {
				dis[v] = dis[u] + w;
				if(!in[v]) {
					q.push(v), in[v] = 1;
					cnt[v]++;
					if(cnt[v] >= n) return -1;
				}
			}
		}
	}
	return max(dis[n], 0ll);
}
int main() {
	scanf("%d%d%d",&n, &m, &p);
	rep(i, 0, m) {
		int u, v, w; scanf("%d%d%d", &u, &v, &w);
		e[u].pb(v);
		re[v].pb(u);
		c[u].pb(w-p);
	}
	bfs();
	printf("%lld\n", spfa());
    return 0;
}


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

int main(){
    int w,a,b,r=0;
    cin>>w>>a>>b;
    if(a<=b){
        if(a+w<=b) r=b-(a+w);
        else r=0;
    }
    else{
        if(b+w<=a) r=a-(b+w);
        else r=0;
    }
    cout<<r<<endl;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 214748360012345

long l[200][200];
long s[200][200];

long dp[2][200];

int main(){
  int n,m;
  while(cin>>n>>m, n|m){
    fill(l[0], l[n], INF);
    fill(s[0], s[n], INF);
    rep(i,m){
      int a,b,c; char d;
      scanf("%d %d %d %c", &a, &b, &c, &d);
      a--; b--;
      if(d=='L'){
        l[a][b]=c;
        l[b][a]=c;
      } else {
        s[a][b]=c;
        s[b][a]=c;
      }
    }

    rep(i,n) l[i][i] = s[i][i] = 0;
    rep(k,n) rep(i,n) rep(j,n) l[i][j] = min(l[i][j], l[i][k]+l[k][j]);
    rep(k,n) rep(i,n) rep(j,n) s[i][j] = min(s[i][j], s[i][k]+s[k][j]);

    int r; cin>>r;
    vector<int> route(r);
    rep(i,r) scanf("%d", &route[i]);
    rep(i,r) route[i]--;

    long * prev = dp[0];
    long * crnt = dp[1];

    fill(prev, prev+n, INF);
    prev[route[0]] = 0;
    rep(i,r-1){
      // route[i] -> route[i+1]
      fill(crnt, crnt+n, INF);
      rep(j,n) if(prev[j]!=INF){
        // ??????j??????????????¨?????????????§?
        rep(k,n) crnt[k] = min(crnt[k], prev[j] + l[route[i]][j] + s[j][k] + l[k][route[i+1]]);
        crnt[j] = min(crnt[j], prev[j] + l[route[i]][route[i+1]]);
      }
      swap(crnt, prev);
    }

    cout << *min_element(prev, prev+n) << endl;

  }
  return 0;
}

Measured memory_bytes: 3740
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

ll a, b, c, d;

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

ll lcm(ll a, ll b) {
	return a * (b / gcd(a, b));
}

ll solve(ll a, ll b, ll c, ll d) {
	ll B = (b / c + b / d) - (b / lcm(c, d));
	ll A = (a / c + a / d) - (a / lcm(c, d));

	if (a % c == 0 || a % d == 0) return (b - a + 1) - (B - A + 1);
	return (b - a + 1) - (B - A);
}

int main(void){
	cin>>a>>b>>c>>d;

	cout<< solve(a, b, c, d) <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200001];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans=0;
	for(int i=1;i<=n;i++)
	if(a[i]==i)
	{
		++ans;
		if(i<n)
			swap(a[i],a[i+1]);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main(){
	string N,tmp;
	int sum=0;
	cin >> N;

	for(int i=0; i<N.length();i++){
		tmp = N[i];
		sum += atoi(tmp.c_str());
	}
	if(sum%9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0; 
}

Measured memory_bytes: 3740