akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use std::cmp::{max, min};

const MAX_L: u32 = 100_000;
const BASE_SIZE: usize = 1 << 10;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        ul: [(usize, usize); q],
    }
    let dp = make_dp(&vw);
    for (u, l) in ul {
        println!("{}", calc(&dp, &vw, u - 1, l));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if i < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L as usize)
            .map(|i| {
                let w = vw[c].1 as usize;
                let v = if i < w { 0 } else { dp[p][i - w] + vw[c].0 };
                max(dp[p][i], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    dp: &Vec<Vec<u32>>,
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: usize,
) -> u32 {
    if u < dp.len() {
        dp[u][l]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1 as usize;
        let pv1 = calc(dp, vw, p, l);
        let pv2 = if l < w { 0 } else { calc(dp, vw, p, l - w) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 411028
#include<iostream>
#include<string>
using namespace std;
int main ()
{
    int n,k;
    cin>>n>>k;
    char ch[n];
    cin>>ch;
    for( int i=0; i<n;  i++)
    {
       if(i==k-1)
        ch[i]=ch[i]+32;
    }

    cout<<ch<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

struct Shop {
	string name;
	Int point;
	Int number;
};

bool f(const Shop& a, const Shop& b) {
	if (a.name == b.name)return a.point > b.point;
	return a.name < b.name;

}

int main() {

	Int N;
	cin >> N;

	vector<Shop> shop;

	for (Int i = 0; i < N; i++) {
		Shop s;

		cin >> s.name >> s.point;
		s.number = i + 1;

		shop.push_back(s);

	}

	sort(shop.begin(), shop.end(), f);

	for (Int i = 0; i < N; i++) {

		cout << shop[i].number << 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 x = sc.nextInt();
		
		int d = 0;
		int count = 1;
		for (int i = 1; i <= n; i++) {
			int l = sc.nextInt();
			d = d + l;
			if(d <= x) {
				count++;
			}
		}
		
		System.out.println(count);
		
	}
}


Measured memory_bytes: 23892
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647;
const long long int llINF = 9223372036854775807;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pair<string, ll> &a, const pair<string, ll> &b) {
  if (a.first == b.first)
    return a.second > b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<pair<string, ll>> D(N);
  map<ll, ll> M;
  REP(i, N) {
    string s;
    ll p;
    cin >> s >> p;
    D[i] = make_pair(s, p);
    M[p] = i + 1;
  }
  sort(ALL(D), paircomp);
  REP(i, N) { cout << M[D[i].second] << endl; }
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;

int main()
{
    ll a;
    double b;
    cin >> a >> b;
    int b_i=b;
    ll ans=a*b_i;
    b-=b_i;
    string b_s=to_string(b);
    int b_deci=0;
    int i=0;
    while(i<int(b_s[2]-'0')){
        i++;
    }
    b_deci+=10*i;
    i=0;
    while(i<int(b_s[3]-'0')){
        i++;
    }
    b_deci+=i;

    ans+=a*b_deci/100;


    
    cout << ans<< endl;

}

Measured memory_bytes: 3756
#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;


//　Solve by creating parallel vectors
//!! Created parallel vector should have reversed direction
//   in order to follow anti-clockwise 
void shift_point(point or_point, point* sh_point, int dif_x, int dif_y){
    sh_point -> x_elem = or_point.x_elem - dif_y;
    //printf("shift point x %d\n", sh_point -> x_elem);
    sh_point -> y_elem = or_point.y_elem + dif_x;
}

int main(void){
    int x1, y1, x2, y2;
    int dif_x, dif_y;
    point a, b, c, d;
    point *pc, *pd;
    pc = &c; pd = &d;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    a.x_elem = x1; a.y_elem = y1;
    b.x_elem = x2; b.y_elem = y2;

    dif_x = x2 - x1;
    dif_y = y2 - y1;

    shift_point(b, pc, dif_x, dif_y);
    shift_point(a, pd, dif_x, dif_y);

    printf("%d %d ", c.x_elem, c.y_elem);
    printf("%d %d\n", d.x_elem, d.y_elem);

    return 0;

}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5 ;
const int INF = 1e9 + 1e5 + 2;
const int mod= 1e9+7;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define what_is(x) cerr << #x << " = " << x << endl;
#define eps 1e-15
#define F first
#define S second
typedef long long ll;
ll fib[100006];
int main()
{
    fastIO
    fib[0]=2,fib[1]=1;

    for (int i=2; i<=100; ++i)
        fib[i]=fib[i-1]+fib[i-2];

    int n;
    cin>>n;

    cout<<fib[n];




}


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

int main() {
  int N, Y;
  cin >> N >> Y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for (int a = 0; a <= N; a++) {
    for (int b = 0; b + a <= N; b++) {
      int c = N - a - b;
      int total = 10000 * a + 5000 * b + 1000 * c;
      if (total == Y) {
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


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


//vector<double >coins;
double dp[3000][3000];


int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		double a; cin >> a;
		if(i == 0){
			dp[1][1] = 1 - a;
			dp[1][2] = a;
		}else{
			for(int j = 1; j <= i + 2; j++){
				dp[i + 1][j] = dp[i][j] * (1 - a) + dp[i][j - 1] * a;
			}
		}
		//double a; cin >> a;
		//coins.emplace_back(a);
	}
	/*dp[1][1] = 1 - coins[0];
	dp[1][2] = coins[0];
	for(int i = 2; i <= n; i++){
		for(int j = 1; j <= i + 1; j++){
			dp[i][j] = dp[i - 1][j] * (1 - coins[i - 1]) + dp[i - 1][j - 1] * coins[i - 1];
		}
	}*/
	/*for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i+1; j++){
			cout << dp[i][j] << " ";
		}cout << "\n";
	}*/
	double ans = 0;
	int k = n / 2 + 1;
	//cout << k << "\n";
	for(int i = k + 1; i <= n + 1; i++){
		ans += dp[n][i];
	}cout << setprecision(20) << ans << "\n";
}













Measured memory_bytes: 68864
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

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

int main(){
    int H, W;
    char s[100][100];

    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
        }
    }

    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            bool flag = true;
            if(s[i][j] == '#'){
                for(int p = 0; p < 4; p++){
                    int nx = j + dx[p];
                    int ny = i + dy[p];

                    if(0 <= nx && nx <= W-1 && 0 <= ny && ny <= H-1){
                        if(s[ny][nx] == '#'){
                            flag = false;
                            break;
                        }

                    }
                }
            }else flag = false;

            if(flag){
                cout << "No" << endl;
                return 0;
            }

        }
    }

    cout << "Yes" << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, opt[(int)1e6 + 5];

int main(){
  FAST_IO

  cin >> N;
  opt[0] = 0;

  for(int t = 1; t <= N; ++t) opt[t] = t;
  
  for(int coin : {6, 9}){
    for(int exp = 1; pow(coin, exp) <= N; ++exp){
      int deno = pow(coin, exp);
      for(int t = deno; t <= N; ++t){
        min_self(opt[t], opt[t - deno] + 1);
      }
    }
  }

  cout << opt[N] << '\n';
  return 0;
}

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

using namespace std;

int main() {

    int n, p;
    bool is_prime[1000001];
    vector<int> prime;

    fill(is_prime, is_prime + 1000001, true);

    for(int i = 2; i <= sqrt(1000000); ++i) {
        if(is_prime[i]) {
            for(int j = i * 2; j <= 1000000; j += i) {
                is_prime[j] = false;
            }
        }
    }

    for(int i = 2; i <= 1000000; ++i) {
        if(is_prime[i]) {
            prime.push_back(i);
        }
    }

    while(cin >> n >> p && n != -1 && p != -1) {

        priority_queue<int, vector<int>, greater<int> > pq;
        vector<int>::iterator it = upper_bound(prime.begin(), prime.end(), n);

        for(int i = 0; i < p; ++i) {
            for(int j = i; j < p; ++j) {
                pq.push(*(it + i) + *(it + j));
            }
        }

        for(int i = 0; i < p - 1; ++i) {
            pq.pop();
        }

        cout << pq.top() << endl;

    }

}

Measured memory_bytes: 2568
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff ** 2

        flag = False
        for k in range(norm+1):
            if k ** 2 == norm:
                flag = True
        if flag:
            ans += 1

print(ans)


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

int main(){
    int A, B, C, D, L, R;
    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;
    if(L > R){
        cout << "Left" << endl;
    }
    else if(L == R){
        cout << "Balanced" << endl;
    }
    else{
        cout << "Right" << endl;
    }

}

Measured memory_bytes: 256
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;
int main(){
  int m,n;
  cin>>n>>m;
  ll res=1;
  if(max(n,m)-min(n,m)>1){cout<<0<<endl;
    return 0;
  }
  for(int i=1;i<=max(m,n);i++){
      res*=(ll)i;
      res%=(ll)1000000007;
  }
  for(int i=1;i<=min(m,n);i++){
      res*=(ll)i;
      res%=(ll)1000000007;
  }
  if(m==n){
      res*=(ll)2;
      res%=(ll)1000000007;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
H = list(map(int,input().split()))
notwinner = []
for i in range(M):
    ab = list(map(int,input().split()))
    if H[ab[0]-1] > H[ab[1]-1]:
        notwinner.append(ab[1])
    elif H[ab[0]-1] < H[ab[1]-1]:
        notwinner.append(ab[0])
    else:
        notwinner.append(ab[0])
        notwinner.append(ab[1])
wtou = N - len(set(notwinner))#set()で重複する要素を含まない要素にしてlenで数える
print(wtou)


Measured memory_bytes: 20120
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000001
#define x first
#define y second

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

vector<pint> oresens[100];
int chk[100];
int n;

void culc(void){
	int i,j;
	for(i=1;i<=n;i++){
		if(oresens[0].size()==oresens[i].size()){
			for(j=0;j<oresens[0].size();j++){
				if(oresens[0][j]!=oresens[i][j]) break;
			}
			if(j==oresens[0].size()) chk[i]=1;
		}
	}
}


int main(){
	while(cin >> n){
		if(n==0) break;
		int i,j;
		for(i=0;i<=n;i++) oresens[i].clear();
		int m;
		for(i=0;i<=n;i++){
			cin >> m;
			int x,y,x2,y2;
			cin >> x >> y;
			pint p;
			for(j=0;j<m-1;j++){
				cin >> x2 >> y2;
				oresens[i].push_back(pint(x2-x,y2-y));
				x=x2;
				y=y2;
			}
		}
		for(i=0;i<100;i++) chk[i]=0;
		
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		reverse(&oresens[0][0],&oresens[0][oresens[0].size()]);
		for(i=0;i<oresens[0].size();i++){
			oresens[0][i].x*=-1;
			oresens[0][i].y*=-1;
		}
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		culc();
		for(i=0;i<oresens[0].size();i++){
			swap(oresens[0][i].x,oresens[0][i].y);
			oresens[0][i].x*=-1;
		}
		culc();
		
		for(i=0;i<100;i++) if(chk[i]==1) cout << i << endl;
		cout << "+++++" << endl;
	}
		
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    // convinationの固定する左側見つける
    int a_max = *max_element(a.begin(), a.end());
  	int a_min = *min_element(a.begin(), a.end());
    // 全探索
    double target = a_max / 2.0;
    int ans_right = a_min;
    for(int i = 0;i < n;i++) {
        double a_bin = abs((double)a[i] - target);
        double a_bin2 = abs(ans_right - target);
        if(a_bin < a_bin2){
            ans_right = a[i];
        }
    } 
    cout << a_max << " " << (int)ans_right << endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long double ll;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a>b)
        cout<<"GREATER";
    else if(a<b)
        cout<<"LESS";
    else if(a==b)
        cout<<"EQUAL";    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B>> C;
    cout << max(0, C - (A - B)) << endl;

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s == "abc"){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  ull a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  if ((a1 + a2 + a3) >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
use std::io::{Read, stdin};
use std::str::FromStr;


fn main() {
    let n: usize = read();
    let mut c = vec![0; n-1];
    let mut s = vec![0; n-1];
    let mut f = vec![0; n-1];
    for i in 0..n-1 {
        c[i] = read();
        s[i] = read();
        f[i] = read();
    }
    let mut ansv = vec![0; n];
    for i in 0..n-1 {
        let mut t = 0;
        for j in i..n-1{
            if s[j] > t {
                t = s[j] + c[j];
            }else {
                t += (f[j]- (t- s[j]) % f[j]) % f[j] + c[j];
            }
        }
        ansv[i] = t;

    }
    for ans in ansv {
        println!("{}", ans);
    }
}


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

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;

int main(){
    int a,b;cin>>a>>b;
    if(a==0){
        if(b<0)cout<<abs(b)+1<<endl;
        else cout<<abs(b)<<endl;
        return 0;
    }
    if(b==0){
        if(a>0)cout<<a+1<<endl;
        else cout<<abs(a)<<endl;
        return 0;
    }
    int dif=abs(abs(a)-abs(b));
    if(b>a&&a>0&&b>0)cout<<dif<<endl;
    else if(b<a&&a>0&&b>0)cout<<dif+2<<endl;
    else if((a>0&&b<0))cout<<dif+1<<endl;
    else if((a<0&&b>0)){
        int _a=abs(a);
        if(_a>b)cout<<dif+1<<endl;
        else cout<<dif+1<<endl;
    }else if(a<0&&b<0){
        if(a>b)cout<<dif+2<<endl;
        else cout<<dif<<endl;
    }
    
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

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

	int a, b, k;
	cin >> a >> b >> k;

	vector<int> v;
	for(int i = min(a, b); i >= 1; i--){
		if(a % i == 0 && b % i == 0) v.push_back(i);
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define Max 1001
#define INF 0x3f3f3f3f
using namespace std;
char a[5],ans[5]="+++=";
int flag = 0;
void dfs(int k,int sum)
{
    if(flag)return;
    if(k == 4)
    {
        if(sum == 7)
        {
            flag = 1;
            for(int i = 0;i < 4;i ++)
                cout<<a[i]<<ans[i];
            cout<<7;
        }
        return;
    }
    ans[k-1] = '+';
    dfs(k+1,sum+a[k]-'0');
    ans[k-1] = '-';
    dfs(k+1,sum-a[k]+'0');
}
int main()
{
    cin>>a;
    dfs(1,a[0]-'0');
}


Measured memory_bytes: 256
x,y = map(int,input().split())
if (2*x - y) % 3 != 0 or (2*y-x) % 3 != 0 or 2 * min(x,y) < max(x,y):
    print(0)
    exit()

mod = 10**9 + 7
n = (x+y) // 3
a = (max(x,y)*2 - min(x,y)) // 3

fact = [1]
finv = [1]
for i in range(1, n+1):
    fact += [(fact[i-1] * i) % mod]
    finv += [pow(fact[i], mod-2, mod)]
print((fact[n]*finv[a]*finv[n-a]) % mod)

Measured memory_bytes: 130768
import math

n, m = list(map(int, input().split()))

ys = []

for i in range(1, int(math.sqrt(m)) + 2):
    if m % i == 0:
        ys.append(i)

ys2 = ys.copy()

for y in reversed(ys):
    ys2.append(m // y)

for y in reversed(ys2):
    if y <= m // n:
        print(y)
        break


Measured memory_bytes: 3060
import math
count = 0
amari = 10
for i in range(5):
  n = int(input())
  if n%10 == 0:
    count += n
  else:
    count += math.ceil(n/10)*10
    amari = min(amari,n%10)
if amari %10 == 0:
  print(count + amari - 10) 
else:
  print(count + amari -10)

Measured memory_bytes: 62064
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

// int MOD = 998244353;
int MOD = 1000000007;

signed main(){
    
    ll a,b,t;
    cin >> a >> b >> t;

    cout << t/a*b << endl;
    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://jsc2019-qual.contest.atcoder.jp/tasks/jsc2019_qual_a
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc125.contest.atcoder.jp/tasks/abc125_a


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

typedef long long ll;



int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    pair<int,int> a[300000];
    int b[300000];
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a[i].first=x;
        a[i].second=i;
    }
    sort(a,a+n);
    //return 0;
    for(int i=0;i<n/2;i++){
        b[a[i].second]=a[n/2].first;
    }
   // return 0;
    for(int i=n/2;i<n;i++){
        b[a[i].second]=a[n/2-1].first;
    }
   // return 0;
    for(int i=0;i<n;i++){
        cout<<b[i]<<endl;
    }
    return 0;
}

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

int main() {
	int n;
	cin>>n;
	if(n/100>12 || n/100==0){
		if(n%100==0 || n%100>12) cout<<"NA\n";
		else cout<<"YYMM\n";
	}else if(n%100>12 || n%100==0){
		if(n/100==0 || n/100>12) cout<<"NA\n";
		else cout<<"MMYY";
	}else if(!n) cout<<"NA\n";
	else cout<<"AMBIGUOUS\n";
}

Measured memory_bytes: 256
//ABC164 A

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint n,k;
lint a[200001];

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

/*   rep(i,n){
    scanf("%lld",&a[i]);
  } */
  
  if(n<=k){
    printf("unsafe\n");
  }
  else{
    printf("safe\n");
  }

  //printf("%lld\n",ans);
}


Measured memory_bytes: 3644
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(60 + 1):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans = (ans + 2 ** i * cnt * (N - cnt)) % (10 ** 9 + 7)
print(ans)

Measured memory_bytes: 122936
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		boolean ok = true;
		for (int i = 1; i < n; i++) {
			if (h[i - 1] <= h[i]) {

			} else if (h[i - 1] <= h[i] + 1) {
				h[i]++;
			} else {
				ok = false;
				break;
			}
		}
		if (ok) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 51152
import math

a,b,x=map(float,raw_input().split())

novo=2*x/(a*b)

tangente=b/novo


res= math.atan(tangente)*180/(math.pi)

if novo<=a:
	print("%.10f" %(res))

else:
	novo=2*x/(a*a)-b
	tangente=(b-novo)/a
	
	res= math.atan(tangente)*180/(math.pi)
	print("%.10f" %(res))


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	vector<long long int> v;
	for(long long int i=0;i<s.size()-1;){
		if(s[i]=='A'&&s[i+1]=='C'){
			v.push_back(i);
			i+=2;
		}
		else{
			i++;
		}
	}
	sort(v.begin(),v.end());
	while(q--){
		long long int l,r;
		//long long int c=0;
		cin>>l>>r;
		l--;r--;
		long long int li=lower_bound(v.begin(),v.end(),l)-v.begin();
		long long int ri=lower_bound(v.begin(),v.end(),r)-v.begin();
		cout<<ri-li<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  
  ll num;
  map<ll, ll> single;
  pql pairs;
  rep(_, n) {
    cin >> num;
    single[num]++;
    if(single[num]==2) {
      pairs.push(num);
      single[num]=0;
    }
  }
  
  if(pairs.size() >= 2) {
    ll length = pairs.top();
    pairs.pop();
    ll width = pairs.top();
    cout << length * width << newl;
  }else {
    cout << 0 << newl;
  }
  
  return 0;
}

Measured memory_bytes: 9724
from collections import Counter

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

cnt = Counter([0, a[0]])

for ai in a[1:]:
    temp = Counter()
    for k, v in cnt.items():
        temp[k + ai] = v
        
    cnt += temp

ans = 0
for k, v in cnt.items():
    if k % 2 == p:
        ans += v
        
        
print(ans)

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>

using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
typedef long long ll;

int a, b, c;
int main(){
	scanf("%d %d %d", &a, &b, &c);
	swap(a, b);
	swap(a, c);
	printf("%d %d %d\n", a, b, c);
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

C = [0] * N
D = [0] * N

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            D[i] += 1
            if j > i:
                C[i] += 1

ans = (K * sum(C) + K * (K-1) // 2 * sum(D)) % (10 ** 9 + 7)
print(ans)

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[x - 1] = i + 1;
    }
    for (int x : a) {
        cout << x << " ";
    }

    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;
public class Main {
    public static void main(String[] aegs){
        Scanner scan = new java.util.Scanner(System.in);
        for(;;){
            int m = scan.nextInt(); // ???????????????
            int f = scan.nextInt(); // ???????????????
            int r = scan.nextInt(); // ???????¨?
            if(m == -1 && f == -1 && r == -1){
                break;
            }else{
                if(m == -1){
                    notM(m, f, r);
                }
                if(f == -1){
                    notF(m, f, r);
                }
                if(m != -1 && f != -1){
                    Seiseki(m, f, r);
                }
            }
        }
    }
    // m == -1
    public static void notM(int m, int f, int r){
        /*if(f >= 30 && (r == -1 || r < 50)){
            System.out.println("D");
        }else if(f >= 30 && r >= 50){
            System.out.println("c");
        }else if(f < 30 && r == -1){
            System.out.println("F");
        }*/
        System.out.println("F");
    }
    // f == -1
    public static void notF(int m, int f, int r){
        /*if(m >= 30 && (r == -1 || r < 50)){
            System.out.println("D");
        }else if(m >= 30 && r >= 50){
            System.out.println("c");
        }else if(m < 30 && r == -1){
            System.out.println("F");
        }*/
        System.out.println("F");
    }
    // m != -1 && f != -1
    public static void Seiseki(int m, int f, int r){
        if(m + f >= 80 && r == -1){
            System.out.println("A");
        }else if((m + f < 80 && m + f >= 65) && r == -1){
            System.out.println("B");
        }else if((m + f < 65 && m + f >= 50)){
            if(r == -1){
                System.out.println("C");
            }else if(r >= 50){
                System.out.println("C");
            }
        }else if(m + f < 50 && m + f >= 30){
            if(r >= 50){
                System.out.println("C");
            }else{
                System.out.println("D");
            }
        }else if((m + f < 30) && (r == -1 || r >= 0)){
            System.out.println("F");
        }
    }

}

Measured memory_bytes: 26124
#include<stdio.h>
#include <string.h>
#include <math.h>
typedef struct{
    int quantify;
    int switch_num[10];
    int p;
} _info_switch;

_info_switch s[10];
int N, M;

void input(){
    char input[200];
    char* tp;
    int j = 0;
    scanf("%d %d", &N, &M);
    fgets(input, 200, stdin);
    for(int i = 0; i < M; i++){
        fgets(input, 200, stdin);
        tp = strtok(input, " ");
        s[i].quantify = atoi(tp);
        j = 0;
        while( tp = strtok(NULL, " ") ){
            s[i].switch_num[j++] = atoi(tp);
        }
    }
    fgets(input, 200, stdin);
    j=0;
    tp = strtok(input, " ");
    s[j++].p = atoi(tp);
    while( tp = strtok(NULL, " ") ){
        s[j++].p = atoi(tp);
    }
}
int check(int state, int light_num){
    int P = s[light_num].p;
    int mask = 0b1;
    int count = 0;
    for(int i = 0; i < s[light_num].quantify; i++){
        count += (mask << ((s[light_num].switch_num[i] - 1)) & state) >> (s[light_num].switch_num[i] - 1);
    }
    if(P == (count%2)){
        return 1;
    }else{
        return -1;
    }
}
int check_light(int check_state){
    for(int i = 0;i < M;i++){
        if(check(check_state, i) == -1){
            return -1;
        }
    }
    return 1;
}
int sum_clear(){
    int count = 0;
    for(int i = 0; i < (int)pow(2.0, (double)N); i++){
        if(check_light(i) == 1){
            count++;
        }
    }
    return count;
}

int main(){
    input();
    printf("%d", sum_clear());
}

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

int N, K;
int X1[50], Y1[50], D1[50], X2[50], Y2[50], D2[50];
vector<int> x, y, d;
map<int, int> zipx, zipy, zipd;
int unzipx[100], unzipy[100], unzipd[100];
int grid[100][100][100];

signed main()
{
	cin >> N >> K;
	rep(i,N) {
		cin >> X1[i] >> Y1[i] >> D1[i] >> X2[i] >> Y2[i] >> D2[i];
		x.push_back(X1[i]); x.push_back(X2[i]);
		y.push_back(Y1[i]); y.push_back(Y2[i]);
		d.push_back(D1[i]); d.push_back(D2[i]);
	}

	//??§?¨???§???
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	sort(d.begin(), d.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	d.erase(unique(d.begin(), d.end()), d.end());
	rep(i,x.size()) {
		zipx[x[i]] = i;
		unzipx[i] = x[i];
	}
	rep(i,y.size()) {
		zipy[y[i]] = i;
		unzipy[i] = y[i];
	}
	rep(i,d.size()) {
		zipd[d[i]] = i;
		unzipd[i] = d[i];
	}

	rep(i,N) {
		for (int xx=zipx[X1[i]]; xx<zipx[X2[i]]; xx++) {
			for (int yy=zipy[Y1[i]]; yy<zipy[Y2[i]]; yy++) {
				for (int dd=zipd[D1[i]]; dd<zipd[D2[i]]; dd++) {
					grid[xx][yy][dd]++;
				}
			}
		}
	}

	ll ans = 0;
	rep(i,x.size()-1) {
		rep(j,y.size()-1) {
			rep(k,d.size()-1) {
				if (grid[i][j][k] >= K) {
					ans += (unzipx[i+1]-unzipx[i]) * (unzipy[j+1]-unzipy[j]) * (unzipd[k+1]-unzipd[k]);
				} 
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 8432
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int h,w,n,sx,sy;
char S[maxn],T[maxn];

int main()
{
	scanf("%d %d %d%d %d",&h,&w,&n,&sx,&sy);
	scanf("%s",S+1);
	scanf("%s",T+1);
	
	int u=0, d=h+1, l=0, r=w+1;
	bool pd=0;
	fd(i,n,1)
	{
		if (T[i]=='U') d=min(d+1,h+1);
			else if (T[i]=='D') u=max(u-1,0);
			else if (T[i]=='L') r=min(r+1,w+1);
			else l=max(l-1,0);
		if (S[i]=='U') u=min(u+1,h+1);
			else if (S[i]=='D') d=max(d-1,0);
			else if (S[i]=='L') l=min(l+1,w+1);
			else r=max(r-1,0);
		if (l+1>=r || u+1>=d) {pd=1; break;}
	}
	
	puts((!pd && u<sx && sx<d && l<sy && sy<r) ?"YES" :"NO");
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int q = int.Parse(str[1]);
        var queues = new Queue<int>[n];
        for(int i=0; i<n; i++){
            queues[i] = new Queue<int>();
        }
        for(int i=0; i<q; i++){
            var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            switch(line[0]){
                case 0:
                    queues[line[1]].Enqueue(line[2]);
                    break;
                case 1:
                    if(queues[line[1]].Count != 0){
                        Console.WriteLine(queues[line[1]].Peek());
                    }
                    break;
                case 2:
                    if(queues[line[1]].Count != 0){
                        queues[line[1]].Dequeue();
                    }
                    break;
            }
        }
    }
}



Measured memory_bytes: 24188
s = gets.chomp

result = true
s.chars.each_with_index do |c, i|
    i += 1
    if c == 'U' || c == 'D'
        next
    end

    if i.odd?
        next if c == 'R'
    else
        next if c == 'L'
    end

    result = false
end

puts "#{result ? 'Yes' : "No"}"

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

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

    int x = 2;
    vector<int> S;
    while(true){
        bool a = true;
        rep(i, S.size()){
            if(x % S[i] == 0){
                a = false;
                break;
            }
        }
        if(a){
            if (x >= X){
                cout << x << endl;
                break;
            }
            S.push_back(x);
        }
        x++;
    }
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n,m,x; cin >> n >> m >> x;
    vi c(n);
    vii a(n, vi(m));
    rep(i,n) {
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    i32 ans = inf;
    vi tmp, init(n);
    for(i32 bit = 0; bit < (1<<n); bit++) {
        i32 tmp_cnt = 0;
        vi tmp = init;
        for(i32 i = 0; i < n; ++i) if((bit>>i)&1) {
            tmp_cnt += c[i];
            for(i32 j = 0; j < m; ++j) {
                tmp[j] += a[i][j];
            }
        }
        bool can = 1;
        rep(i,m) if(tmp[i] < x) can = 0;
        if(can) chmin(ans, tmp_cnt);
    }

    if(ans == inf ) cout << -1 << '\n';
    else {
        cout << ans << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

struct Edge {
  int s,t;
  ll w;
};

#define MAX 3000
int V,E,P;
vector<Edge> es;
ll mini[MAX];
vector<int> rG[2][MAX];

bool visited[2][MAX];
void dfs(int cur,int type) {
  rep(i,(int)rG[type][cur].size()) {
    int nex = rG[type][cur][i];
    if( visited[type][nex] ) continue;
    visited[type][nex] = true;
    dfs(nex,type);
  }
}

inline bool ok(int v) { return visited[0][v] && visited[1][v]; }

void compute() {
  memset(visited,false,sizeof visited);
  visited[1][V-1] = 1;
  dfs(V-1,1);
  visited[0][0] = 1;
  dfs(0,0);

  rep(i,V) mini[i] = LLONG_MAX;
  mini[0] = 0;
  //rep(i,V) if( ok(i) ) cout << "OK " << i << endl;
  rep(i,V) {
    rep(j,(int)E) {
      Edge &e = es[j];
      if( !( ok(e.s) && ok(e.t) ) ) continue;
      if( mini[e.s] != LLONG_MAX && mini[e.t] > mini[e.s] + e.w ) {
	mini[e.t] = mini[e.s] + e.w;
	if( i == V-1 ) {
	  puts("-1");
	  return;
	}
      }
    }
  }
  cout << max(0LL,-mini[V-1]) << endl;
}

int main() {
  cin >> V >> E >> P;
  Edge e;
  rep(i,E) {
    cin >> e.s >> e.t >> e.w;
    --e.s; --e.t;
    e.w = -( e.w - P );
    rG[0][e.s].pb(e.t);
    rG[1][e.t].pb(e.s);
    es.pb(e);
  }
  compute();
  return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        for(int i=0;i<=3000;i++){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a<b){
                System.out.printf("%d %d\n",a,b);
            }else if(a>b){
                System.out.printf("%d %d\n",b,a);
            }else if(a==b && a!=0){
                System.out.printf("%d %d\n",a,b);
            }else{
                break;
            }
        }
    }
}



Measured memory_bytes: 40604
#include<iostream>
using namespace std;
int main() {
    int k, s; cin >> k >> s;
    int cnt = 0;
    for (int i = 0; i <= k; ++i) {
        int x = i;
        for (int j = 0; j <= k; ++j) {
            int y = j;
            int z = s - x - y;
            if (z >= 0 && z <= k) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}



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

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

  int ans = 0;
  int x = 0;
  while (x < N) {
    x += 1000;
  }
  ans = abs(N - x);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
bool cmp(string a , string b){
  for(int i = 0 , j = 0 ; i < a.length() && j < b.length() ; i++ , j++){
     if(a[i] > b[j]){
	  return b >= a;
	 }
  }
  return a<=b; 
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
set<string> v;
map<string , int> m;
for(int i = 0 ;i  < n; i++){
 string str;
 cin>>str;
 m[str]++;
}
vector<string> yes;
int maxi = -1;
for(auto it:m){
  maxi = max(maxi , it.s);
}
for(auto it:m){
 if(it.s == maxi){
   yes.pb(it.f);
 }
}
sort(yes.begin() , yes.end() , cmp);
for(auto it:yes){
 cout<<it<<endl;
}
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<int64_t> fact, fact_inv;

void create_mod_tables(int num){
    fact.assign(num+1, 1);
    fact_inv.assign(num+1, 1);
    for(int i=1; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[num] = inv_mod(fact[num]);
    for(int i=num; i>0; i--) fact_inv[i-1] = fact_inv[i] * i % MOD;
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    create_mod_tables(300000);

    int64_t ans = 0;
    for(int i=0; i<=K; i++){
        int64_t res = comb_mod(N-1, i);
        int num = N-i;
        mul(res, M);
        mul(res, power_mod(M-1, num-1));
        add(ans, res);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int N; cin >> N;
    double A[100], ps[100]; for (int i = 0; i < 100; i++) ps[i] = 1;
    double Ai = 0;
    double P = 1;
    for (int i = 0; i < N; i++) {
        cin >> Ai;
        P *= Ai;
        for (int j = 0; j < N; j++) {
            if (j != i) ps[j] *= Ai;
        }
    }
    double S = 0.;
    for (int i = 0; i < N; i++) S += ps[i];
    double I = P / S;

    cout << setprecision(16) << I << endl;
    return 0;
}

Measured memory_bytes: 256