akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    int n,m,k;
    cin >> n >> m >> k;
    if(n==m){
        pri(k); 
        return 0;
    } 
    if(k==m){
        pri(n); 
        return 0;
    } 
        pri(m); 
        return 0;
}











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

using namespace std;

int main()
{
    int n,x;
    cin >> n >> x;

    vector<int> m(n);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> m.at(i);
        x -= m.at(i);
        count++;
    }

    sort(m.begin(), m.end());
    while (true)
    {
        x -= m.at(0);
        if(x<0)
        {
            break;
        }
        count++;
    }

    cout << count << endl;
}


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

int main(){
    long long A,B,N;
    cin >> A >> B >> N;
    long long X = min(N,B-1);

    long long ans = A*X/B;
    long long tmp = A* ( (long long) X/B );
    ans -= tmp;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
N = int(input())
a = list(map(int, input().split()))

a.sort(reverse = True)
p = a[0]
for i in range(N-2): #-1は上記a[0]分、もう-1は最初の要素挿入は加点されないため。
    p += a[(i//2)+1]

print(p)

Measured memory_bytes: 104804
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> H >> W >> K;
	vector<vector<int>>num(H + 1, vector<int>(W + 1));
	for (int i = 0; i < K; i++) {
		cin >> L >> R >> M;
		num[L][R] = M;
	}
	vector<vector<vector<long long int>>>dp(H + 1, vector<vector<long long int>>(W + 1, vector<long long int>(4,-MOD*MOD)));
	dp[0][0][0] = 0;
	for (int i = 0; i <= H; i++) {
		for (int j = 0; j <= W; j++) {
			for (int k = 0; k <= 3; k++) {
				if (i + 1 <= H) {
					dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
					dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + num[i + 1][j]);
				}
				if (j + 1 <= W) {
					dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
					if (k + 1 <= 3) {
						dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + num[i][j + 1]);
					}
				}
			}
		}
	}
	cout << *max_element(dp.back().back().begin(), dp.back().back().end()) << endl;
}

Measured memory_bytes: 671476
#include <stdio.h>

int main(void) {
    const char *wday_name[] = {
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"
    };
    const int month_day_count[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int m, d, i;

    while (scanf("%d%d", &m, &d) != EOF && m) {
        for (i = 1; i < m; i++) {
            d += month_day_count[i];
        }
        printf("%s\n", wday_name[(2 + d) % 7]);
    }
    return 0;
}

Measured memory_bytes: 584
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,i,j,k;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
     cin>>a[i];
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(i=3;i<=n;i++)
    {
        dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
nn = (n%10, 0)[n % 10 == 0]

if nn == 2 or nn == 4 or nn == 5 or nn == 7 or nn == 9:
  print('hon')
elif nn == 0 or nn == 1 or nn == 6 or nn == 8:
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9164
import java.util.Scanner

val sc = Scanner(System.`in`)

fun main(args : Array<String>) {
    val n = sc.nextInt()
    val aa = listOfInt(n)

    println(aa.fold(0, { acc, i -> acc + (i-1) }))
}

fun listOfInt(n: Int) = (1..n).map { sc.nextInt() }.toList()

Measured memory_bytes: 33044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    int l, q;
    cin >> l >> q;
    vector<vector<int>> dp(31, vector<int>(n+1));
    for(int i = 0; i < n; i++)
    {
        int now = x[i];
        dp[0][i+1] = lower_bound(x.begin(), x.end(), now + l + 1) - x.begin();
    }
    dp[0][n] = -1;
    for(int k = 0; k < 30; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            if(dp[k][i] == -1) dp[k+1][i] = -1;
            else dp[k+1][i] = dp[k][dp[k][i]];
        }
    }
    while(q--)
    {
        int a, b;
        cin >> a >> b;
        int left = min(a, b);
        int right = max(a, b);
        int ans = 0;
        for(int k = 30; k >= 0; k--)
        {
            int next = dp[k][left];
            if(next >= 0 && next < right)
            {
                left = next;
                ans += 1 << k;
            }
        }
        ans++;
        cout << ans << endl;
    }
}

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

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,count;
  scanf("%d",&N);
  int num[N];
  //for(int i=0;i<N;i++) scanf("%d",&num[i]);
  printf("%d",N/3);
  return 0;
}


Measured memory_bytes: 128
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
double calc(ll x){
	int sum=0;
	ll y=x;
	while(x!=0){
		sum+=x%10;
		x/=10;
	}
	double ret=(double)y/(double)sum;
	return ret;
}
int main(){
	int K;
	cin>>K;
	vector<double> hoge;
	vector<ll> fuga;
	vector<ll> piyo;
	ll now=0,beki=1;
	for(int i=0;i<=16;i++){
		for(ll i=1;i<=100000;i++){
			if(i*beki+now>0)piyo.pb(i*beki+now);
		}
		now=now*10+9;
		beki=beki*(ll)10;
	}
	sort(piyo.begin(),piyo.end());
	//rep(i,100)cout<<piyo[i]<<endl;
	for(int i=0;i<piyo.size();i++){
		hoge.pb(calc(piyo[i]));
	}
	int x=piyo.size();
	double mi = hoge[x-1];
	vector<ll>ans;
	now=0;
	for(int i=x-1;i>=0;i--){
		if(mi>=hoge[i]){
			if(piyo[i]!=now){
				ans.pb(piyo[i]);
				now = piyo[i];
			}
			mi = hoge[i];
		}
	}
	reverse(ans.begin(),ans.end());
	rep(i,K)cout<<ans[i]<<endl;
	

}

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

// input
int A, B, C;


void input() {
    cin >> A >> B >> C;
}


ll gcd(ll a, ll b) {
    while (b) {
        ll tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}


int main() {
    input();
    string ans;
    ll g = gcd(A, B);
    if (C % g == 0) ans = "YES";
    else ans = "NO";
    cout << ans << endl;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int S = scan.nextInt();

		int count = 0;
		for (int i = 0; i <= K; i++) {
			for (int j = 0; j <= K; j++) {
				if (0 <= S - i - j && S - i - j <= K) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

}

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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

bool is_product_overflow(ull a, ull b) {
	ull prod = a * b;
	return (prod / b != a);
}

void Main()
{
	int N;
	std::cin >> N;
	std::vector<string> vec(N);
	int c[4] = { 0 };
	for (auto& v : vec)
	{
		std::cin >> v;
		if (v == "AC") {
			c[0]++;
		}
		else if (v == "WA") {
			c[1]++;
		}
		else if (v == "TLE") {
			c[2]++;
		}
		else if (v == "RE") {
			c[3]++;
		}
	}

	cout << "AC x "  << c[0] << endl;
	cout << "WA x "  << c[1] << endl;
	cout << "TLE x " << c[2] << endl;
	cout << "RE x "  << c[3];
}

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

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
	
	cin >> s;
	
	string v; v.push_back(s[0]);
	for(int i = 1; i < s.size(); ++i) if(s[i] != s[i - 1]) v.push_back(s[i]);
	printf("%d\n", (int)v.size() - 1);
	
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<numeric>
#include<cmath>


int main(){
    using namespace std;
    int n;
    double score[1000];

    while(1){
        cin>>n;
        if(n==0){break;}

        double total=0.0,ave=0.0;
        double var=0.0,stv=0.0;
        for(int i=0;i<n;i++){
            cin>>score[i];
            total+=score[i];
        }
        ave=total/n;
        
        for(int i=0;i<n;i++){
            var += (score[i]-ave)*(score[i]-ave);
        }
        stv=sqrt(var/n);
        cout<<stv<<endl;
    }
    return 0;
}


Measured memory_bytes: 3248
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        _: usize,
        s: Chars
    };

    let (min, end) = {
        // (((( ... 0, 4
        // )))) ... -4, -4
        // (()) ... 0, 0
        // ((()) ... 0, 1
        // (())) ... -1, -1
        // ))(( ... -2, 0
        let mut cur = 0;
        let mut min = 0;
        for &c in s.iter() {
            match c {
                '(' => cur += 1,
                ')' => {
                    cur -= 1;
                    min = std::cmp::min(min, cur);
                }
                _ => unreachable!(),
            }
        }
        (min, cur)
    };
    let mut t = vec![];
    for _ in 0..-min {
        t.push('(');
    }
    for &c in s.iter() {
        t.push(c);
    }
    for _ in 0..-min + end {
        t.push(')');
    }
    let ans = t.iter().collect::<String>();
    println!("{}", ans);
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// pairsをsecond優先キーとして昇順ソート
bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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

    vector<pair<ll, ll> > pairs(N);

    REP(i, N){
        cin >> pairs[i].first;
        cin >> pairs[i].second;
    }

    sort(pairs.begin(), pairs.end(), compare_by_b);

    ll limit = 0;
    REP(i, N){
        limit += pairs[i].first;
        if(limit > pairs[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    // REP(i, N){
    //     cout << pairs[i].first << " " << pairs[i].second << endl;
    // }
    return 0;
}

Measured memory_bytes: 3328
memos = {}
nines = [9 ** n for n in range(1, 6)]
sixs = [6 ** n for n in range(1, 7)]


def solve(N):
    if N < 6:
        return N
    if N in memos:
        return memos[N]
    n = 10 ** 9
    if N >= 9:
        nine_max = max(n for n in nines if n <= N)
        if N % nine_max == 0:
            n = min(n, N // nine_max)
        else:
            n = min(n, solve(N - nine_max) + 1)

    six_max = max(n for n in sixs if n <= N)
    if N % six_max == 0:
        n = min(n, N // six_max)

    memos[N] = min(n, solve(N - six_max) + 1)
    return memos[N]

if __name__ == "__main__":
    N = int(input())
    print(solve(N))


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
     long N=long.Parse(Console.ReadLine());
       long ans=0;
     while(N>0){
       N/=2;
       ans=ans*2+1;
     }
	Console.WriteLine(ans);
}
  }

}


Measured memory_bytes: 27440
def run(L, N, X):
    '''
    最初に向きを変える点をsとする
    その後は向きを変えながら最後の点まで行けばよい
    最後の点をfとする
    ある点をiと置く
    0からiの左回りの距離をli, 右回りの距離をriと置くと
    全体の距離は2*liのsからfの和と2*riのNからfの和を加算し
    最後の回りが左回りなら上記からlf+2*rfを減算し、
    右回りなら2*lf+rfを減算すれば全体の距離がでる
    sを1からfの場合すべてを求め、その最大値を出力すればよい
    ただし最初の回る方向が右と左両方を求める必要がある
    累積和を使えば、2*liのsからfの和をO(1)で求められる
    '''
    # 累積和取得
    l_sum = {0: 0}
    r_sum = {N+1: 0}
    for i in range(1, N+1):
        l_sum[i] = l_sum[i-1] + X[i-1]
    for i in range(N, 0, -1):
        r_sum[i] = r_sum[i+1] + L - X[i-1]
    # 開始左回り
    ret = 0
    for s in range(1, N+1):
        # 折り返す点の数
        nodes = (N - s + 1)
        # 最終地点
        f = int(s + (nodes - (nodes % 2)) / 2)
        if nodes % 2 == 1:
            last_dir_l = True
        else:
            last_dir_l = False
        if last_dir_l:
            tmp = 2*(l_sum[f] - l_sum[s-1]) + 2*(r_sum[f+1]) - X[f-1]
        else:
            tmp = 2*(l_sum[f-1] - l_sum[s-1]) + 2*(r_sum[f]) - (L - X[f-1])
        ret = max(ret, tmp)

    # 開始右回り
    for s in range(1, N+1):
        # 折り返す点の数
        nodes = s
        # 最終地点
        f = int((nodes + (nodes % 2)) / 2)
        if nodes % 2 == 1:
            last_dir_r = True
        else:
            last_dir_r = False
        if last_dir_r:
            tmp = 2*(l_sum[f-1]) + 2*(r_sum[f] - r_sum[s+1]) - (L - X[f-1])
        else:
            tmp = 2*(l_sum[f]) + 2*(r_sum[f+1] - r_sum[s+1]) - X[f-1]
        ret = max(ret, tmp)
    return ret


def main():
    L, N = map(int, input().split())
    X = []
    for _ in range(N):
        X.append(int(input()))
    print(run(L, N, X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 73188
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    string sentence;
    int count;

    while(getline(cin,sentence)){
        if(sentence== "END OF INPUT") break;
        else{
            count = 0;
            for(int i=0;i!=sentence.size();i++){
                if(sentence[i]!= ' ') count++;
                else{
                    cout<<count;
                    count = 0;
                }
            }
            cout<<count<<endl;
        }
    }
    return 0;
}



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

int main(){
        
    vector<int> dp(35,0);

    dp[0] = 1;

    for(int i=0; i<=30; i++){
        for(int j=1; j<=3; j++){
            dp[i+j] += dp[i];
        }
    }

    while(1){
        int N;
        cin>>N;
        if(N == 0) break;
        cout<<(dp[N]+365*10-1)/(365*10)<<endl;
    }

    return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll id = 1;
vvl G;
vl c, d;

void dfs(ll v, ll p = -1) {
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        d[u] = c[id];
        id++;
        dfs(u, v);
    }
}

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

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    c.resize(n);
    d.resize(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(rall(c));

    ll M = 0;
    exrep(i, 1, n-1) {
        M += c[i];
    }

    d[0] = c[0];
    dfs(0);

    out(M);
    rep(i, n) {
        cout << d[i] << " ";
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
import java.io.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int a = sc.nextInt();
            String op = sc.next();
            
            int b = sc.nextInt();
            
            switch(op){
            case "+":
                System.out.println(a + b);
                break;
            case "-":
                System.out.println(a - b);
                break;
            case "*":
                System.out.println(a * b);
                break;
            case "/":
                System.out.println(a / b);
                break;
            case "?":
                break;
            }
            if(op.equals("?"))     break;
        }
    }
}


Measured memory_bytes: 26332
#include <iostream>
#define mod 1000000007

using namespace std;

long long n,res,i,k,candy,X,a[101],S[101][100010];

int main()
{
    /// d[i][j] = cum impart j bomboane la primii i copii
    /// S[i][j] = d[i][0]+d[i][1]+...d[i][j]

    cin>>n>>k;
    for(i=1;i<=n;i++)cin>>a[i];

    for(i=1;i<=n;i++)S[i][0]=1;
    for(candy=1;candy<=k;candy++)
    {
        if(candy<=a[1])S[1][candy]=S[1][candy-1]+1;
        else S[1][candy]=S[1][candy-1];
    }

    for(candy=1;candy<=k;candy++)
    {
        for(i=2;i<=n;i++)
        {
            if(candy-a[i]>0)X=(S[i-1][candy]-S[i-1][candy-a[i]-1])%mod;
                else X=S[i-1][candy]%mod;

            if(X<0)X+=mod;

            S[i][candy]+=(S[i][candy-1]+X)%mod;
            if(S[i][candy]<0)S[i][candy]+=mod;
        }
    }

    res=(S[n][k]-S[n][k-1])%mod;
    if(res<0)res+=mod;

    cout<<res;
    return 0;
}


Measured memory_bytes: 78336
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	double x[20], y[20];
	double a, b;
	int c = 0;
	char ch;
	while(cin >> a >> ch >> b) {
		x[c] = a, y[c] = b;
		c++;
	}
	double ret = 0;
	rep2(i,1,c-1) {
		double d = sqrt(pow(x[i]-x[0],2.0) + pow(y[i]-y[0],2.0));
		double e = sqrt(pow(x[i+1]-x[0],2.0) + pow(y[i+1]-y[0],2.0));
		double f = sqrt(pow(x[i]-x[i+1],2.0) + pow(y[i]-y[i+1],2.0));
		double z = (d+e+f)/2;
		ret += sqrt(z*(z-d)*(z-e)*(z-f));
	}
	printf("%.6lf\n", ret);
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int aux;
    aux = b;
    b = a;
    a = aux;

    aux = a;
    a = c;
    c = aux;

    cout << a << ' ' << b << ' ' << c << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;

int main(void){
	int n,m;
	cin>>n>>m;
	if(n>=m){
		cout<<0<<endl;
		return 0;
	}
	int x[m];
	rep(i,m)cin>>x[i];
	sort(x,x+m);
	int sub[m-1];
	ll ans=0;;
	rep(i,m-1){
		sub[i]=x[i+1]-x[i];
		ans+=sub[i];
	}
	sort(sub,sub+m-1);
	rep(i,n-1)ans-=sub[m-2-i];

	cout<<ans<<endl;

	return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector<long long int> memo(100000,0);
long long int fib(int prev);
int main() {
    int N,M;
    cin >> N >> M;
    vector<int> A(M+2);
    A[0]=-1;
    A[M+1]=N+1;
    for(int i=1;i<=M;i++){
        cin >> A[i];
    }    
    long long int ans=1;
    for(int i=0;i<=M;i++){
        int x=A[i+1]-A[i]-1;
        ans = ans*(fib(x)%1000000007)%1000000007;
    }
    cout << ans%1000000007 << endl;
    
    return 0;
}
long long int fib(int prev){
    if(prev==0)return 0;
    if(prev==1)return 1;
    if(memo[prev]!=0)return memo[prev];
    return memo[prev] = (fib(prev-1)+fib(prev-2))%1000000007;
}

Measured memory_bytes: 4096
import sys

n = int(input())
a = [int(x) for x in input().split()]

if 0 in a:
    print(0)
    sys.exit()

ans = a[0]
for i in range(1, n):
    ans *= a[i]
    if 10**18 < ans:
        print(-1)
        sys.exit()
    
print(ans)

Measured memory_bytes: 21756
from collections import Counter

X,N = map(int,input().split())
P = list(map(int,input().split()))

ans = sorted([abs(i-X) for i in P])

if 0 not in ans:
    print(X)
    exit()
c = Counter(ans[1:])

for i in range(1,201):
    if c[i] != 2:
        if X - i not in P:
            print(X-i)
            exit()
        else:
            print(X+i)
            exit()

Measured memory_bytes: 9468
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

const int INF = 1000000000;
int value[] = {500, 100, 50, 10, 5, 1};

int opt(int p, int num[])
{
  int ret = 0;
  REP(i, 6) {
    int use = min(num[i], p / value[i]);
    p -= value[i] * use;
    ret += use;
  }
  return p ? INF : ret;
}

int main()
{
  int p;
  while (scanf("%d", &p), p) {
    int num[6], sum = 0;
    REP(i, 6) {
      scanf("%d", &num[5-i]);
      sum += num[5-i] * value[5-i];
    }
    int big[] = {INF, INF, INF, INF, INF, INF};
    int ans = INF;
    FOREQ(i, p, min(sum, p + 10000)) {
      ans = min(ans, opt(i, num) + opt(i - p, big));
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 760
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let abc: Vec<u32> = read_vec();
  let ans = if abc[2] <= abc[0] + abc[1] {
    abc[1] + abc[2]
  } else {
    abc[0] + abc[1] + 1 + abc[1]
  };

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


Measured memory_bytes: 4352
n=int(input())
s=input()

cntR = 0
for i in range(0,n):
	if(s[i]=="R"):
		cntR+=1

cntRL = 0
for i in range(0,cntR):
	if(s[i]=="R"):
		cntRL+=1

print(cntR-cntRL)

Measured memory_bytes: 9468
S = input()
mod = [0] * 2019
res = 0
for c in S:
    m = int(c)
    new_mod = [0] * 2019
    for i, n in enumerate(mod):
        new_mod[(i*10 + m) % 2019] = n
    new_mod[m] += 1
    mod = new_mod
    res += mod[0]
print(res)


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, x;
    cin >> n >> x;
	int mn = 10000;
  	int m;
  	for (int i = 0; i < n; i++) {
      	cin >> m;
      	x -= m;
      	mn = min(mn, m);
    }

    cout << n + x / mn << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst ll T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define ll long long int
#define vt vector
#define pb push_back
int main()
{
	vite;
	for (ll i = 1; i <= 5;i++)
	{
		ll x;
		cin >> x;
		if(x==0)
		{
			cout << i;
			break;
		}
	}

		return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)
typedef string::const_iterator State;

string s;

int eval(State &beg);

int number( State &beg ){
    if(*beg=='('){
        beg++;
        int ret = eval(beg);
        beg++;
        return ret;
    }
    
    string ret="";
    while(1){
        if( isdigit(*beg) ){
            ret+=*beg;
            beg++;
        }
        else break;
    }
    
    return stoi(ret);
}

int term(State &beg){
    int ret = number(beg);
    
    while(1){
        if( *beg=='*' ){
            beg++;
            ret *= number(beg);
        }
        else if( *beg=='/' ){
            beg++;
            ret /= number(beg);
        }
        else break;
    }

    return ret;
}

int eval(State &beg){
    int ret=term(beg);
    
    while(*beg!='=' && *beg!=')'){
        beg++;
        if(*(beg-1)=='+')       ret+=term(beg);
        else if(*(beg-1)=='-')  ret-=term(beg);
        else throw("error");
    }
    return ret;
}
int main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>s;
        
        State beg = s.begin();
        try{
            cout<<eval(beg)<<endl;
        }catch(string s){
            cout<<s<<endl;
        }
    }
}

Measured memory_bytes: 3008
q,h,s,d=map(int,raw_input().split())
n=int(raw_input())
if n>=2:
    if n%2!=0:
        a=(n/2)*d+min(s,2*h,4*q)
    else:
        a=(n*d)/2
    print min(4*n*q,2*n*h,n*s,a)
else:
    print min(4*n*q,2*n*h,n*s)


Measured memory_bytes: 2568
import math
import copy
import numpy as np

n = int(input())
i = 0
a_list = []

while i < n:
  a_list.append(int(input()))
  i += 1
  
tmp_a_list = copy.deepcopy(a_list)
first_max = max(a_list)
first_idx = np.argmax(a_list)

tmp_a_list[first_idx] = 0
second_max = max(tmp_a_list)
second_idx = np.argmax(tmp_a_list)

i = 0
while i < n:
  if i == first_idx:
    print(second_max)
  else:
    print(first_max)
  i += 1

Measured memory_bytes: 24448
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

long long pow(long long a,long long b,long long mod){
    if(b==0){
        return 1;
    }else{
        if(b%2==0){
            return pow(a*a%mod,b/2,mod);
        }else{
            return pow(a*a%mod,b/2,mod)*a%mod;
        }
    }

}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    ll mod=10e8+7;

    ll ans=pow(2,n,mod)-1;
    ll nca,ncb;
    ll comb=1;
    for(int i=1;i<=b;i++){
        comb*=(n+1-i);
        comb%=mod;
        comb*=modinv(i,mod);
        comb%=mod;
        if(i==a){
            nca=comb;
        }
    }
    ncb=comb;
    ans-=nca;
    ans+=mod;
    ans%=mod;
    ans-=ncb;
    ans+=mod;
    ans%=mod;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3592
# 長方体の内小さい2辺を元に長方形の外接円を考える
# sqrt(a^2+b^2)/2が長方形の外接円の半径となるため
# r>sqrt(a^2+b^2)/2であれば入口に接さずにチーズを搬入可能
while 1:
    dwh = list(map(int,input().split()))
    if dwh[0]==dwh[1]==dwh[2]==0:
        break
    dwh.sort()
    cir = ((dwh[0]**2 + dwh[1]**2)**(1/2))/2
    n = int(input())
    for i in range(n):
        print("OK" if int(input()) > cir else "NA")


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

int main()
{
    int n,n1;
    cin>>n;
    n1=n;
    int k,tem;
    cin>>k;
    vector<int>v;
    for(int i=0;i<k;i++)
    {
       cin>>tem;
       v.push_back(tem);
    }
    sort(v.begin(),v.end());
    vector<int>av;
    for(int i=0;i<10;i++)
    {  int t=count(v.begin(),v.end(),i);
        if(t==0)
        {
            av.push_back(i);
        }
    }

    int d,c=0;


     while(1)
        {
          bool check=true;
          vector<int>v1;
        while(n1!=0)
        {
            v1.push_back(n1%10);
            n1=n1/10;
        }
        reverse(v1.begin(),v1.end());
        for(int i=0;i<v1.size();i++)
        {
          if(binary_search(av.begin(),av.end(),v1[i]))
          {
              check=true;

          }
          else
          {
              check=false;
              break;
          }

        }
        if(check==false)
        {
            n++;
            n1=n;
        }
        else
        {
            cout<<n<<"\n";
            break;
        }


}



return 0;}


Measured memory_bytes: 3588
class RKSearch:
    shift = 40
    size = 33554393

    def __init__(self, s1, s2):
        self.haystack = self._encode(s1)
        self.needle = self._encode(s2)

    def find(self):
        m, n = len(self.haystack), len(self.needle)
        if m < n:
            return

        h1 = self._hash(self.haystack, n)
        h2 = self._hash(self.needle, n)
        dm = self.shift**(n-1) % self.size

        for i in range(m-n+1):
            if h1 == h2:
                yield i
            if i+n < m:
                h1 = ((h1 - self.haystack[i]*dm) * self.shift
                      + self.haystack[i+n]) % self.size

    def _hash(self, s, length):
        h = 0
        for i in range(length):
            h = (h * self.shift + s[i]) % self.size

        return h

    def _encode(cls, s):
        basea = int.from_bytes(b'a', 'little')
        based = int.from_bytes(b'0', 'little')
        bs = []
        for c in s:
            if c.isdigit():
                bs.append(int.from_bytes(c.encode('utf8'), 'little')-based+27)
            else:
                bs.append(int.from_bytes(c.encode('utf8'), 'little')-basea)

        return bs


def run():
    s1 = input()
    s2 = input()
    rk = RKSearch(s1, s2)
    for i in rk.find():
        print(i)


if __name__ == '__main__':
    run()



Measured memory_bytes: 16080
//
// Created by Naman Bhalla on 2019-05-26.
//

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

int dp[100005][3];

using namespace std;

int main(){
    memset(dp, 0, sizeof dp);
    int n;
    cin >> n;

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

//    cout << -1 % 3 << endl;
    for(int i = 1; i < n; ++i){
        for(int j = 0; j < 3; ++j){
            dp[i][j] = dp[i][j] + max(dp[i - 1][(j - 1 + 3) % 3], dp[i - 1][(j + 1 + 3) % 3]);
//            cout << dp[i][j] << " ";
        }
//        cout << endl;
    }

    cout << *max_element(dp[n - 1], dp[n - 1] + 3) << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {

		List<Integer> hills = new ArrayList<Integer>();

		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		for(int i=0; i<10; ++i){
			hills.add(Integer.parseInt(br.readLine()));
		}

		Collections.sort(hills);

		System.out.println(hills.get(9));
		System.out.println(hills.get(8));
		System.out.println(hills.get(7));

	}
}

Measured memory_bytes: 24264
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>


#ifdef MY_LOCAL
namespace sandbox {
#endif

using namespace std;

int main() {

	int n, m;
	cin >> n >> m;

	vector<vector<int>> passages(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		passages[a].push_back(b);
		passages[b].push_back(a);
	}

	vector<int> signposts(n, -2);
	queue<int> q;
	signposts[0] = -1;
	q.push(0);
	while (!q.empty())
	{
		int this_room = q.front();
		q.pop();
		for (auto next_room : passages[this_room])
		{
			if (signposts[next_room] == -2)
			{
				q.push(next_room);
				signposts[next_room] = this_room;
			}
		}
	}

	for (auto this_signpost : signposts)
	{
		if (this_signpost == -2)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int j = 1; j < n; j++)
	{
		cout << signposts[j] + 1 << endl;
	}

	return 0;
}

#ifdef MY_LOCAL
}
#endif

Measured memory_bytes: 10188
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int n,i,a;
    int *b;
    scanf("%d",&n);
    b = (int *)malloc(n * sizeof(int));
    for(i=0;i<n;i++){
        scanf("%d",&a);
        b[a-1] = i+1;
    }
    for(i=0;i<n-1;i++)printf("%d ", b[i]);
    printf("%d\n",b[n-1]);
    free(b);
    return 0;
}

Measured memory_bytes: 1152
l = [list(map(int,input().split())) for i in range(3)]

n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if l[j][k] == b:
                l[j][k] = -1

for i in range(3):
    flg = True
    for j in range(3):
        flg &= l[i][j] == -1
    if flg:
        print('Yes')
        exit()

for i in range(3):
    flg = True
    for j in range(3):
        flg &= l[j][i] == -1
    if flg:
        print('Yes')
        exit()

flg = True
for i in range(3):
    flg &= l[i][i] == l[0][0]
if flg:
    print('Yes')
    exit()

flg = True
for i in range(3):
    flg &= l[i][2 - i] == l[0][2]
if flg:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3064
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
		String[] s=new String[n];
  		
		for(int c=0;c<n;c++){
          	s[c]=sc.next()+"_"+(1100-sc.nextInt())+"_"+(c+1);
          	
    	}
        Arrays.sort(s);
  		for(String s1:s){
		String ans=s1.split("_")[2];
    	System.out.println(ans);
        }
    }
}

Measured memory_bytes: 21588
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        boolean[] po=new boolean[N+1];
        int[] pena=new int[N+1];
        Arrays.fill(pena,0);
        for(int i=0; i<M; i++){
            int p=sc.nextInt();
            String s=sc.next();
            if(s.equals("WA")){
                if(!po[p]){
                    pena[p]++;
                }
                else{}
            }
            else if(s.equals("AC")){
                if(!po[p]){
                    po[p]=true;
                }
            }
        }
        int penasum=0;
        int ans=0;
        for(int i=0; i<=N; i++){
            if(po[i]) {
                ans++;
                penasum+=pena[i];
            }
        }

        System.out.println(ans+" "+penasum);
    }

}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
typedef pair<ll,int> P;

const int V=100000;
const ll INF=123456789012345LL;

struct edge{int to,cost;};
vector<edge> G[V];
ll d[V];

int r[V];

int main()
{
    int n,m;
    ll C;
    scanf(" %d %d %lld", &n, &m, &C);

    vector<int> a(m),b(m),c(m);
    rep(i,m)
    {
        scanf(" %d %d %d", &a[i], &b[i], &c[i]);
        --a[i];
        --b[i];
        G[a[i]].pb(edge{b[i],c[i]});
        G[b[i]].pb(edge{a[i],c[i]});
    }

    fill(d,d+V,INF);
    priority_queue<pi,vector<pi>,greater<pi>> que;
    d[0]=0;
    que.push(pi(0,0));
    while(!que.empty())
    {
        pi p=que.top();
        que.pop();
        int v=p.se;
        if(d[v]<p.fi) continue;
        rep(i,G[v].size())
        {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                que.push(pi(d[e.to],e.to));
            }
        }
    }

    ll ans=0;
    // ??¨???????????´???
    rep(i,m) ans+=c[i];
    ll sum=ans;

    vector<P> p;
    for(int i=1; i<n; ++i) p.pb(P(d[i],i));
    sort(all(p));

    r[0]=-1;
    rep(i,p.size()) r[p[i].se]=i;

    vector<pi> q;
    rep(i,m) q.pb(pi(max(r[a[i]],r[b[i]]),i));
    sort(all(q));

    ll tsum=0;
    int idx=0;
    rep(i,p.size())
    {
        ll tmp = p[i].fi*C;

        while(idx<m && q[idx].fi==i)
        {
            tsum+=c[q[idx].se];
            ++idx;
        }

        tmp += sum-tsum;

        // printf(" X=%lld ,tmp %lld\n", p[i].fi,tmp);
        ans = min(ans,tmp);
    }

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

Measured memory_bytes: 19948
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
using namespace std;

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

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main(){
    map<string,int> m;
    int N,M;
    cin>>N;
    REP(i,N){
        string s;cin>>s;
        m[s] += 1;
    }
    cin>>M;
    REP(i,M){
        string s;cin>>s;
        m[s] -= 1;
    }
    int ans=0;
    for(auto itr=m.begin();itr!=m.end();++itr) ans=max(ans,itr->second);
    cout<<ans;
}



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

using namespace std;

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int mi = -101, ma = 101;
	for (int i = 0; i < n; i++)
	{
		int buf;
		cin >> buf;

		mi = max(mi, buf);
	}
	if (x >= mi) {
		cout << "War" << endl;
		return 0;
	}
	for (int i = 0; i < m; i++)
	{
		int buf;
		cin >> buf;
		ma = min(ma, buf);
	}
	if (y < ma) {
		cout << "War" << endl;
		return 0;
	}
	if (mi >= ma)
		cout << "War" << endl;
	else
		cout << "No War" << endl;
}


Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
s,t=gets.chomp.split
a,b=gsmi
u=gs
if u==s
  puts [a-1,b].join(" ")
else
  puts [a,b-1].join(" ")
end

Measured memory_bytes: 1788
from itertools import product
N = int(input())
count = 0

for i in range(1,len(str(N))+1):
  for j in product(['3','5','7'], repeat = i):
    s = ''.join(j)
    if '7' in s and '5' in s and '3' in s and int(s) <= N:
      count += 1

print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    REP(i, M) { cin >> X.at(i); }
    sort(ALL(X));
    if (N >= M) {
        cout << 0 << endl;
    } else {
        vector<int> dif(M - 1);
        REP(i, M - 1) { dif[i] = X[i + 1] - X[i]; }
        sort(ALL(dif));
        vector<int> sum(M - 1);
        sum[0] = dif[0];
        REP(i, M - 2) { sum[i + 1] = sum[i] + dif[i + 1]; }

        cout << sum[M - N - 1] << endl;
    }
    return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

void lower(int& h)
{
    if (h > 1) --h;
}

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    lower(H[0]);
    for (int i = 1; i < N; ++i)
    {
        if (H[i] > H[i - 1])
        {
            lower(H[i]);
        }
        else if (H[i] < H[i - 1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define N 200050
#define K 105
const int MOD = 1e9+7;
int dp[N][K][2] ;
char s[N] ;
int a[N] ;
int n, m ;

int dfs(int k, int now, int lim) {
    if (dp[k][now][lim] >= 0) return dp[k][now][lim] ;
    if (k == m) return dp[k][now][lim] = (now == 0) ;
    int sum = 0, up = lim ? a[k] : 9 ;
    for (int i = 0; i <= up; i++) {
        sum += dfs(k + 1, (now - i + n) % n, lim && i == up) ;
        if (sum >= MOD) sum -= MOD ;
    }
    return dp[k][now][lim] = sum ;
}

signed main(){
    scanf("%s%d", s, &n) ;
    m = strlen(s) ;
    for (int i = 0; i < m; i++) a[i] = s[i] - '0' ;
    for(int i = 0; i < N; i++)
        for(int j = 0; j <  K; j++)
            for(int k = 0; k < 2; k++)
                dp[i][j][k]=-1;
    printf("%d\n", (dfs(0, 0, 1) + MOD - 1) % MOD) ; // 0 is incorrect
    return 0 ;
}


Measured memory_bytes: 165248
#include <iostream>
using namespace std;
int main( void )
{
	string name;
	int gozen, gogo;

	for ( int i = 0; i < 9; i++ )
	{
		cin >> name >> gozen >> gogo;
		cout << name << " " << gozen + gogo << " " << gozen * 200 + gogo * 300 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include <iostream>
using namespace std;
int X, A, B, C ;

int a = 0;

int main()
{
	int yen=0;
	cin >> A >> B>>C>>X;
	for (int i = 0;i < A+1;i++) 
	{
		yen = 0;
		yen += 500 * i;
	
		for (int j = 0;j < B+1;j++) 
		{
			yen = 500 * i;
			yen += 100 * j;
			for (int k = 0;k < C+1;k++) {
				yen = 500 * i + 100 * j;
				yen += 50 * k;
				if(yen==X)a++;
			}
		}
    }
	cout << a;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt() % 10;
		if(N == 3)
			System.out.println("bon");
		else if(N == 0 || N == 1 || N == 6 || N == 8)
			System.out.println("pon");
		else
			System.out.println("hon");
	}

}


Measured memory_bytes: 35724
#!/usr/bin/env python3
from itertools import permutations
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    e = set(zip(a, b))
    print(sum(
        1 for p in permutations(range(2, N + 1))
        if all((n1, n2) in e or (n2, n1) in e for n1, n2 in zip((1,) + p, p))
    ))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;

int n, len;
int t[111], v[111];
double ma[111*222*2];

int main() {
	scanf("%d", &n);
	len = 0;
	for(int i=1;i<=n;i++) {
		scanf("%d", &t[i]);
		len += t[i]*2;
	}
	int it = 0;
	ma[0] = 0;
	for(int i=1;i<=n;i++) {
		scanf("%d", &v[i]);
		for(int j=0;j<t[i]*2;j++) {
			it++;
			ma[it] = min(1.*ma[it-1]+.5, 1.*v[i]);
		}
	}
	it = len;
	ma[len] = 0;
	for(int i=n;i>0;i--) {
		for(int j=0;j<t[i]*2;j++) {
			it--;
			ma[it] = min(ma[it], min(1.*ma[it+1]+.5, 1.*v[i]));
		}
	}
	
	double ans = 0LL;
	for(int i=1;i<=len;i++)
		ans += ma[i-1] + ma[i];
	printf("%.12lf\n", ans/4);
	
	return 0;
}

Measured memory_bytes: 512