akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int age  = sc.nextInt();
          if(age == 1) {
            System.out.println("Hello World");
          } else {
            int num1 = sc.nextInt();
            int num2 = sc.nextInt();
            System.out.println(num1 + num2);
          }
        }
      }

Measured memory_bytes: 21332
import java.util.*;

public class Main{
    final long INF = (long)1e10;
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int W = scan.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        int V = 0;
        for(int i = 0; i < n; i++){
            w[i] = scan.nextInt();
            v[i] = scan.nextInt();
            V += v[i];
        }
        long[][] dp = new long[n + 1][V + 1];
        for(int i = 0; i <= n; i++) Arrays.fill(dp[i], INF);
        dp[0][0] = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= V; j++){
                if(j < v[i]) dp[i + 1][j] = dp[i][j];
                else dp[i + 1][j] = Math.min(dp[i][j], dp[i][j - v[i]] + w[i]); 
            }
        }
        for(int i = V; i >= 0; i--){
            if(dp[n][i] <= W){
                System.out.println(i);
                return;
            }
        }
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 141112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if (dist[i][j] != d) continue;
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

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

int main(){
  int A, B, C;
  cin >> A;
  cin >> B;
  cin >> C;

  if (A < B){
    if (A < C && C < B){
      cout << "Yes" << endl;
    } else{
      cout << "No" << endl;
    }
  } else{
    if (B < C && C < A){
      cout << "Yes" << endl;
    } else{
      cout << "No" << endl;
    }
  }
  return 0;
}


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

using namespace std;

int main() {
    int a[200];
    bool vis[200];
    memset(vis,0,sizeof(vis));
    for(int i = 1; i <= 3; i++) cin >> a[i];
    long long ans = 1e18;
    for(int i = 1; i <= 3; i++) {
        memset(vis,0,sizeof(vis));
        vis[i] = 1;
        for(int j = 1; j <= 3; j++) {
        long long sum = 0;
            if(!vis[j]) {
                vis[j] = 1;
                sum += abs(a[i] - a[j]);
                for(int k = 1; k <= 3; k++) {
                    if(!vis[k]) sum += abs(a[j] - a[k]),ans = min(ans,sum);;
                }
                vis[j] = 0;
            }
        }
        vis[i] =0;

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int n;
ll ans=0ll;

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
    }
//    ans=n;
    ll sum=0ll;
    ll xo=0ll;
    int l=1;
    int r=0;
    ll cnt=0ll;
    while(1)
    {
        while(r<n&&sum+a[r+1]==(xo^a[r+1]))
        {
            r++;
            sum+=a[r];
            xo^=a[r];
        }
        cnt=r-l+1;
//        ans+=(cnt*(cnt+1))/2;
        ans+=cnt;
        sum-=a[l];
        xo^=a[l++];
//        l=r;
        if(l==n+1)
        {
            break;
        }
    }

    cout<<ans<<endl;

    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

string a;
int sum=9999999;

int main() {
    cin>>a;
    for(int i=1; i<a.size(); i++) {
        if(a[i]!=a[i-1]) {
            sum=min(sum,max(i,int(a.size())-i));
        }
    }
    cout<<min(sum,int(a.size()))<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define sbits(a) __builtin_popcount(a)
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

const int N = 1e6 + 1;
vi G[N];
int in[N];

int unique(int a, int b)
{
    return min(a, b) * 1000 + max(a, b);
}

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        int prev;
        cin >> prev;
        for (int j = 2; j < n; j++) {
            int cur;
            cin >> cur;
            int a = unique(i, cur);
            int b = unique(i, prev);
            in[a]++;
            G[b].pb(a);
            prev = cur;
        }
    }

    vi v;

    for (int i = 0; i < N; i++)
        if (!in[i])
            v.pb(i);

    int total = 0;
    int day = 0;

    while (v.sz) {
        total += v.sz;
        ++day;
        vi z;
        for (auto& i : v) {
            for (auto& j : G[i]) {
                --in[j];
                if (!in[j])
                    z.pb(j);
            }
        }
        v = z;
    }

    if (total != N)
        cout << -1;
    else
        cout << day;

    return 0;
}


Measured memory_bytes: 45432
import sys
readline = sys.stdin.buffer.readline

def main():
    A, B = map(int, readline().split())
    S = input()
    if S[:A].isdecimal() and S[A]=='-' and S[A+1:].isdecimal():
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
int n,i,x,a[N],b[N];
int main(){
	n=read();
	for(i=1;i<=n;i++){
		x=read();
		a[i]++;b[i]++;
		a[x]+=i;b[x]+=i;
	}
	for(i=1;i<=n;i++)a[i]+=a[i-1];
	for(i=n;i>=1;i--)b[i]+=b[i+1];
	for(i=1;i<=n;i++)printf("%d ",a[i]);puts("");
	for(i=1;i<=n;i++)printf("%d ",b[i]);puts("");
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cmath>
main(){for(double r,i,j;std::cin>>r,r;printf("%.0f/%.0f\n",j,i)){for(i=0;++i<100000;){j=(int)(i*M_PI);if(fabs(j/i-M_PI)<=r||fabs(++j/i-M_PI)<=r)break;}}}

Measured memory_bytes: 0
function Main(input){
	input=input.trim().split("\n");
	let N = input[0];
	let vec_a = input[1].split(" ").map(e => parseInt(e, 10));
	let mi = Math.min.apply(null,vec_a);
	let ma = Math.max.apply(null,vec_a);
	let sum = vec_a.reduce(function(a, x){return a + x;});
	console.log("%d %d %d",mi,ma,sum);	
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 18224
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;


int N;
vector<int> A, B;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int tmpa, tmpb;
		cin >> tmpa >> tmpb;
		A.push_back(tmpa);
		B.push_back(tmpb);
	}
	vector<pli> C;
	for (int i = 0; i < N; i++)
	{
		C.push_back(pli(A[i] + B[i], i));
	}
	sort(C.rbegin(), C.rend());
	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0) {
			ans += A[C[i].second];
		}
		else {
			ans -= B[C[i].second];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3184
# -*- coding: utf-8 -*-
n = int(input())
a = [int(x) for x in input().split()]

maxa = max(a)
mida = min(a)
for x in a:
    # print(x,mida,maxa//2-x)
    if abs(maxa//2 - x)<abs(maxa//2-mida):
        mida = x
print(maxa, mida)


Measured memory_bytes: 14052
#!/usr/bin/env python3
n,m=map(int,input().split())
if n>=m:
    print(0)
    exit()
x = list(map(int,input().split()))
ans=0
x.sort()
data=[(float('inf'),0)]*m
for i in range(1,m):
    data[i]=(x[i]-x[i-1],i)
data2 = sorted(data ,reverse=True)
data3 = sorted([data2[i][1] for i in range(n)]+[len(x)])
for i in range(1,n+1):
    ans += x[data3[i]-1] - x[data3[i-1]]
print(ans)
    






Measured memory_bytes: 61608
using System;

namespace _0046
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Int32.Parse(Console.ReadLine());
            int hu = a % 3600;
            int h = (a - hu) / 3600;
            int second = hu % 60;
            int minutes = (hu - second) / 60;
            Console.WriteLine(h+ ":" + minutes + ":" + second);
        }
    }
}

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

using namespace std;

#define ll  long long
#define ld  double

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

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 205;
const int   mod = 1e9 + 7;

typedef pair<ll,ll> pll;

ll  a[N];
ll  b[N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    ll  K;  cin >> K;

    map<vector<ll>,vector<pll> >    mp;

    for(int i = 0 ; i <  n ; ++i)   cin >> a[i];    sort(a,a + n);
    for(int t = 0 ; t < 61 ; ++t)   {
        vector<ll>  vec;

        for(int i = 0 ; i < n ; ++i)
            vec.pb(a[i] & ((1ll << t) - 1));

        sort(all(vec));
        vec.erase(unique(all(vec)),vec.end());

        ll  lst = -1;

        for(ll  x : vec)    {
            if (x > a[0])   break;

            for(int i = 0 ; i < n ; ++i)    b[i] = (a[i] - x) >> t;
            for(int i = 1 ; i < n ; ++i)    assert(b[i] >= b[i - 1]);

            ll  cnt = t;
            if (lst >= 0)   {
                for(int b = 59 ; b >= 0 ; --b)  {
                    int u = (lst >> b & 1);
                    int v = (x   >> b & 1);

                    if (v)  cnt++;
                    if (u != v)
                        break;
                }
            }
            lst = x;

            if (K < cnt)
                continue;

            vector<ll>  d;
            for(int i = 1 ; i < n ; ++i)
                d.pb(b[i] - b[i - 1]);
            
            mp[d].pb(pll(b[0] - K + cnt,b[0]));
        }
    }
    ll  ans = 0;
    
    for(auto&it : mp)   {
        vector<pll>&vec = it.Y;
        sort(all(vec));

        ll  L = 0;
        ll  R = -1;

        for(pll T : vec)    {
            if (R < T.X)    {
                ans += R - L + 1;
                ans %= mod;
                L = T.X;
            }
            R = max(R,T.Y);
        }
        ans += R - L + 1;
        ans %= mod;

/*        for(pll T : it.Y)
            swp[T.X]++,
            swp[T.Y + 1]--;
        
        ll  lst = 0;
        int Sum = 0;

        for(auto it : swp)  {
            if (Sum)    {
                ans += it.X - lst;
                ans %= mod;
            }
            Sum += it.Y;
            lst  = it.X;
        }*/
    }
    cout << ans<< endl;
}


Measured memory_bytes: 19656
#include <bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int r;
	cin >> r;
	cout << 2*r*3.1415926;

	return 0;
}


Measured memory_bytes: 3788
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll n,k;
    cin>>n>>k;
    ll ss= (n-2)*(n-1)/2;
    if(k>ss) cout<<"-1"<<endl;
    else{
        ll sss=n-1+(ss-k);
        cout<<sss<<endl;
        rep(i,n-1){
            cout<<"1 "<<i+2<<endl;
        }
        for(int i=1;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(ss<=k) break;
                else{
                    cout<<i+1<<" "<<j+1<<endl;
                    ss--;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, C, s, t, c;
pair<pair<int, int>, int>p[100000];
pair<int,int> r[30];


int main() {
	cin >> N >> C;
	for (int i = 0; i != N; ++i) {
		cin >> p[i].first.first >> p[i].first.second >> p[i].second;
	}
	sort(p, p + N);
	for (int i = 0; i != C; ++i) {
		r[i].first = -0xe869120;
	}
	for (int i = 0; i != N; ++i) {
		bool f = false;
		for (int j = 0; j != C; ++j) {
			if (r[j].second == p[i].second) {
				r[j].first = p[i].first.second + 1;
				f = true;
				break;
			}
		}
		if (f)continue;
		for (int j = 0; j != C; ++j) {
			if (r[j].first <= p[i].first.first) {
				r[j] = mkp(p[i].first.second + 1, p[i].second);
				break;
			}
		}
	}
	int cnt = 0;
	for (int i = 0; i != C; ++i) {
		if (r[i].second)++cnt;
	}
	cout << cnt << endl;
}

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

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

    int n, k;
    cin >> n >> k;

    vector<int> as(n);
    for (int i = 0; i < n; i++) cin >> as[i];
    for (int i = 0; i < n - k; i++) {
        if (as[i] < as[i + k]) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
    }
}


Measured memory_bytes: 3972
#!/usr/bin/env python3
# coding:utf-8

def main():
    stdIn = input()
    stdOut = solve(stdIn)
    print(stdOut)

"""
方針


"""

def solve(stdIn):
    if stdIn[-1] == 's' :
        return stdIn + 'es'
    return stdIn + 's'

if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define Scan(a) scanf("%I64d", &a);
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int main()
{
    string s[4];
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> s[1] >> s[2] >> s[3];
    cout << s[1][0] << s[2][0] << s[3][0];
    return 0;
}


Measured memory_bytes: 256
def myAnswer(S:str) -> int:
   ans =10**9
   for i in range(3,len(S)+1):
      X = int(S[i-3:i])
      ans = min(ans,abs(753 - X))
   return ans

def modelAnswer():
   tmp=1
def main():
   S = (input())
   print(myAnswer(S))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
length = int(input())
ar = list(map(int, input().split()))
t_1, t_2 = 0, 0
res = 0

if length < 3:
    print(0)
else:
    while t_1 < length - 2: 
        t_2 = t_1 + 1

        while t_2 < length:
            for i in range(t_2+1, length):
                x, y, z = ar[t_1], ar[t_2], ar[i]
                if x == y or y == z or x == z:
                    continue
                
                if x + y > z and x + z > y and y + z > x:
                    res += 1
            t_2 += 1

        t_1 += 1

    print(res)
    
        


Measured memory_bytes: 9116
function main(input) {
  var N = input[0]-0;
  var a = input[1].split(" ").map(v=>v-0);
  var b = input[2].split(" ").map(v=>v-0);
  var c = input[3].split(" ").map(v=>v-0);
  var ans = 0;
  b.forEach(v=>ans+=v);
  for(var i=1;i<N;i++){
    if(a[i]-1==a[i-1]){
      ans += c[a[i-1]-1];
    }
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
map<char,int> cnt;
int main()
{
	string S;
	cin>>S;
	for(int i=0;i<4;i++)
		cnt[S[i]]++;
	if(cnt[S[0]]==2&&cnt[S[1]]==2&&cnt[S[2]]==2&&cnt[S[3]]==2)
		cout<<"Yes\n";
	else	cout<<"No\n";
	return 0;
}

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

int main(void){
	int n, q;
	queue<pair<string, int> > que;

	cin >> n >> q;
	for(int i=0; i<n; i++){
		string s;
		int t;

		cin >> s >> t;
		que.push(pair<string, int>(s, t) );
	}

	int time = 0;
	while(!que.empty()){
		pair<string, int> temp = que.front();
		que.pop();
		temp.second -= q;
		time += q;
		if(temp.second <= 0){
			time = time + temp.second;
			cout << temp.first << " " << time << endl;
		}else{
			que.push(temp);
		}
	}

	return 0;
}

Measured memory_bytes: 4404
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int h, w;
vector<vector<pair<int,int>>> a;

bool dp[100][100][13000] = {false};
int main(void){
    cin >> h >> w;

    a.resize(h, vector<pair<int,int>>(w));
    rep(i, h){
        rep(j, w){
            cin >> a[i][j].first;
        }
    }
    rep(i, h){
        rep(j, w){
            cin >> a[i][j].second;
        }
    }
    dp[0][0][abs(a[0][0].first - a[0][0].second)] = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < 12800; k++){
                if(dp[i][j][k]){
                    if(i + 1 < h){
                        int next = abs(a[i + 1][j].first - a[i + 1][j].second);
                        dp[i + 1][j][k + next] = true;
                        dp[i + 1][j][abs(k - next)] = true;
                    }
                    if(j + 1 < w){
                        int next = abs(a[i][j + 1].first - a[i][j + 1].second);
                        dp[i][j + 1][k + next] = true;
                        dp[i][j + 1][abs(k - next)] = true;
                    }
                    //cout << i << " " << j << " " << k << endl;
                }
            }
        }
    }

    rep(i, 12800){
        if(dp[h - 1][w - 1][i]){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 101632
chomp (my ($n, $k) = split / /, <STDIN>);
chomp (my @a = split / /, <STDIN>);
print (($n - $k) % ($k - 1) == 0 ? 1 + ($n - $k) / ($k - 1) : 2 + int(($n - $k) / ($k - 1))), "\n";

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

vector<int> et[100000];

int dfs(int v) {
	if (et[v].size() == 0) {
		return 0;
	}
	
	vector<int> res;
	for (int i = 0; i < et[v].size(); i++) {
		res.push_back(dfs(et[v][i]));
	}
	sort(res.begin(), res.end(), greater<int>());
	
	int ret = 0;
	for (int i = 0; i < et[v].size(); i++) {
		ret = max(ret, res[i] + i + 1);
	}
	return ret;
}

signed main() {
	int n, a, i;
	
	cin >> n;
	for (i = 0; i < n - 1; i++) {
		cin >> a;
		a--;
		et[a].push_back(i + 1);
	}
	cout << dfs(0) << endl;
	return 0;
}

Measured memory_bytes: 15104
import sys, os
from queue import PriorityQueue

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

x, y, z, k = f()

def merge(a, b):
    q = PriorityQueue()
    ans = []

    for i in range(len(a)):
        q.put((-a[i] - b[0], 0))


    for i in range(min(k, len(a)*len(b))):
        cur = q.get()
        ans.append(-cur[0])
        idx = cur[1]
        if cur[1] + 1<len(b):
            q.put(( cur[0]+ b[idx] - b[idx+1] , cur[1] + 1))
    return ans

def solve():
    a = f()
    b = f()
    c = f()


    a = sorted(a, reverse = True)
    b = sorted(b, reverse = True)
    c = sorted(c, reverse = True)

    ans = merge(a,b)
    ans = merge(ans,c)

    for i in ans:
        print(i)


solve()


Measured memory_bytes: 4968
#include<stdio.h>
int main(void){
        int n,i,j,x,f;
        char h;
        scanf("%d",&n);
        int c[4][13];
        for(i=0;i<4;i++){
         for(f=0;f<13;f++){
          c[i][f]=0;
         }
        }
        for(i=0;i<n*2;i++){
         scanf("%c %d",&h,&x);
         if(h=='S'){
          c[0][x-1]=1;
         }
         if(h=='H'){
          c[1][x-1]=1;
         }
         if(h=='C'){
          c[2][x-1]=1;
         }
         if(h=='D'){
          c[3][x-1]=1;
         }
        }
        for(i=0;i<13;i++){
          if(c[0][i]==0){
          printf("S %d\n",i+1); 
         }
        }
        for(i=0;i<13;i++){
          if(c[1][i]==0){
          printf("H %d\n",i+1); 
         }
        }
        for(i=0;i<13;i++){
          if(c[2][i]==0){
          printf("C %d\n",i+1); 
         }
        }
        for(i=0;i<13;i++){
          if(c[3][i]==0){
          printf("D %d\n",i+1); 
         }
        }
 
	return 0;
}


Measured memory_bytes: 2004
// https://atcoder.jp/contests/abc171/tasks/abc171_c

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 
#define ll long long

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

    ll N;
    cin >> N;

    string ans;

    while(N) {
        N--;

        ans += 'a'+(N%26);
        N /= 26;
    }

    reverse(ans.begin(), ans.end());
    
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a,b,x;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void smax(ll &x,ll y) {
	x=x<y?y:x;
}
int main() {
//	freopen("in.txt","r",stdin);
	cin>>a>>b>>x;
	if (x>a) {
		b-=(x-a);
		smax(b,0);
	}
	a-=x;
	smax(a,0);
	cout<<a<<' '<<b<<endl;
	return 0;
}

Measured memory_bytes: 3588
#!/usr/bin/env python3
import sys

def solve(N: int, A: "List[int]"):
    A.sort()
    ans =1
    for a in A:
        ans = ans * a

        if ans > 10**18:
            print(-1)
            return
    
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24308
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N, Y = map(int, readline().split())

for x in range(0, N + 1):
    for y in range(0, N - x + 1):
        z = N - x - y
        otoshi = 10000 * x + 5000 * y + 1000 * z
        if otoshi == Y:
            print(x, y, z)
            quit()
print("-1 -1 -1")

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;

	cout << ((a * b) & 1 ? "Odd" : "Even") << endl;
	return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
a_b = n.times.map { gets.split.map(&:to_i) }.sort{ |p, q| p[0] <=> q[0] }
ans = 0
a_b.each do |p, q|
    if q > m
        ans += p * m
        break
    else
        ans += p * q
        m -= q
    end
end
puts ans


Measured memory_bytes: 12560
(defun main ()
  (let ((h1 (read))
        (m1 (read))
        (h2 (read))
        (m2 (read))
        (k  (read))
        (ans 0))
    (setf ans (- (- (+ (* h2 60)  m2) (+ (* h1 60) m1)) k))
    ans))

(format t "~a~%" (main))


Measured memory_bytes: 24284
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            MyDebugger.Test(process, "../TextFile1.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        int ones = ary.Count(x=>x==1);
        if (ones > 0){
            if(ones > 1) return 0;
            return 1;
        }

        var hash = new DefaultDectionary<int, int>(0);
        var list = new List<int>();

        foreach (var x in ary) {
            if(!hash.ContainsKey(x)){
                list.Add(x);
            }
            hash[x] += 1;
        }

        list.Sort();

        int co = 0;

        foreach(var x in list) {
            //var sq = Math.Sqrt(x);
            var zero = false;
            for(int i=2; i<=Math.Sqrt(x); i++) {
                if (x % i == 0) {
                    if(hash.ContainsKey(i) || hash.ContainsKey(x / i)) {
                        zero = true;
                        break;
                    }
                }
            }
            if(!zero && hash[x]==1) co++;
        }

        return co;
    }

    class DefaultDectionary<Tkey, TValue> : Dictionary<Tkey, TValue>
    {
        TValue DefaultValue;
        public DefaultDectionary(TValue defaultvalue) {
            this.DefaultValue = defaultvalue;
        }
        public new TValue this[Tkey key] {
            get {
                if (this.ContainsKey(key)) return base[key];
                else return DefaultValue;
            }
            set {
                base[key] = value;
            }
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        if(n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 55216
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int[] v = new int[N];
            for (int i = 0; i < N; i++)
            {
                v[i] = int.Parse(s[i]);
            }

            int ans = 0;
            for (int i = 1; i < N - 1; i++)
            {
                if (v[i-1] < v[i] && v[i] < v[i + 1])
                {
                    ans++;
                }
                else if ( v[i-1] > v[i] && v[i] > v[i+1])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
import math

n = int(input())
ans = 0
if n== 0:
  print(0)
  exit()
m = math.floor(math.log(n,5))

if n%2 == 1:
  print(0)
else:
  for j in range(1,m+1):
    ans += n//((5**j)*2)
    
    
  print(ans)

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

int main(){
	int n;
	cin >> n;
	string x;
	set<string> data;
	for(int i = 0; i < n; i++){
		cin >> x;
		string tmp;
		cin >> tmp;
		if(x == "insert"){
			data.insert(tmp);
		}else{
			(data.find(tmp) != data.end()) ? (x = "yes") : (x = "no");
			cout << x << endl;
		}
	}
	return 0;
}		

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

int sheet[8]={1, 2, 1, 2, 1, 4, 1, 4};

int main(){
  int p[8];
  while(cin>>p[0]){
    for(int i=1; i<8; i++)cin>>p[i];
    int max=0, maxn=0, n=0;
    for(int i=0; i<8; i++){
      int sum=0, sumn=0;
      for(int j=0; j<8; j++){
        sum+=(sheet[(i+j)%8]<p[j] ? sheet[(i+j)%8] : p[j]);
        sumn=sumn*10+sheet[(i+j)%8];
      }
      if(max<sum){n=i; max=sum; maxn=sumn;}
      if(max==sum && maxn>sumn){n=i; max=sum; maxn=sumn;}
    }
    for(int i=0; i<8; i++){
      if(i==7)cout<<sheet[(n+i)%8]<<endl;
      else cout<<sheet[(n+i)%8]<<' ';
    }
  }
  return 0;
}

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  vector<int> a(3);
  for (int i=0; i<3; i++) {
    cin>>a[i];
  }
  SORT(a);
  int s = abs(a[2]-a[0])+abs(a[2]-a[1]);
  if (s%2==0) {
    cout << s/2 << endl;
  } else {
    cout << s/2+2 << endl;
  }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];

  int l=0, r=n;
  while(r-l>1){
    int x = l + (r-l)/2;
    auto f = [&](){
      // can make with X?
      if(x==0) return false;

      vector<pair<int,int>> st;
      st.pb({v[0], 0});
      rep(i,1,n){
        if(v[i] > v[i-1]){
          st.pb({v[i], 0});
        } else {
          bool done = false;
          do {
            auto la = st.back();
            st.pop_back();

            if (st.size() == 0) {
              if (la.second + 1 >= x) return false;
              if (min(v[i], la.first) > 1) {
                st.pb({min(v[i], la.first) - 1, la.second});
              }
              st.pb({min(v[i], la.first), la.second + 1});
              if (v[i] > la.first) st.pb({v[i], 0});
              done = true;
            } else if (st.back().first < v[i] && la.second + 1 < x) {
              if (min(v[i], la.first) - st.back().first > 1) {
                st.pb({v[i] - 1, la.second});
              }
              st.pb({min(v[i], la.first), la.second + 1});
              if (v[i] > la.first) st.pb({v[i], 0});
              done = true;
            }
          } while (!done);
        }
        dbg(x,st);
      }
      return true;
    };
    if(f()) r = x;
    else l = x;
  }

  cout << r << endl;
  return 0;
}


Measured memory_bytes: 4692
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let solve n q =
  let s = Array.init n (fun i -> i) in
  let rec find u =
    if u = s.(u) then u
    else begin
      s.(u) <- find s.(u);
      s.(u)
    end in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> s.(find x) <- find y
      | 1 :: x :: y :: _ -> print_endline (if find x = find y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 4360
function bomb(y,x,color){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || xx<0 || yy>=12 || xx>=6)continue;
      if(yx[yy][xx]==color) {
         CNT++;
         if(CNT==4)p.push([yy,xx]);
         yx[yy][xx]=color+0;
         bomb(yy,xx,color);
      }
   }
}
function BOMB(y,x,color){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || xx<0 || yy>=12 || xx>=6)continue;
      if(yx[yy][xx]==color){
         yx[yy][xx]=".";
         BOMB(yy,xx,color);
      }else if(yx[yy][xx]=="O"){
         yx[yy][xx]=".";
      }
   }
}
function up(y,x){
   var yy=y;
   while(y>0){
      y--;
      if(yx[y][x]!="."){
         yx[yy][x]=yx[y][x];
         yx[y][x]=".";
         break;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
for(var I=0;I<n;I++){
   var yx=[];
   for(var i=0;i<12;i++){
      var arr=(Arr.shift()).split("");
      yx.push(arr);
   }
   var result=0;  
   while(true){
        var p=[];
        var CNT;
         for(var i=0;i<12;i++){
               for(var j=0;j<6;j++){
                  if(yx[i][j]=="R"){yx[i][j]="R"+0;CNT=1;bomb(i,j,"R");}
                  if(yx[i][j]=="G"){yx[i][j]="G"+0;CNT=1;bomb(i,j,"G");}
                  if(yx[i][j]=="B"){yx[i][j]="B"+0;CNT=1;bomb(i,j,"B");}
                  if(yx[i][j]=="Y"){yx[i][j]="Y"+0;CNT=1;bomb(i,j,"Y");}
                  if(yx[i][j]=="P"){yx[i][j]="P"+0;CNT=1;bomb(i,j,"P");}
               }
         }
         for(var i=0;i<12;i++){
            for(var j=0;j<6;j++){
               yx[i][j]=yx[i][j].slice(0,1);
            }
         }
         if(p.length==0)break;
         result++; 
         p.forEach(function(v){
            var i=v[0];
            var j=v[1];
            var color=yx[i][j];
            if(color!=".")BOMB(i,j,color);
         });
         for(var i=11;i>0;i--){
            for(var j=0;j<6;j++){
               if(yx[i][j]==".")up(i,j);
            }
         }
   }
   console.log(result);
}

Measured memory_bytes: 9804
def buildstr(d,mask):
    s = '+'
    for i in xrange(len(mask)):
        s += d[i]
        if mask[i] == '1':
            s += '+'
        else:
            s += '-'
    s += d[-1]
    return s

def eval(s):
    add = True
    tot = 0
    for i in xrange(4):
        if s[2*i] == '-':
            add = False
        else:
            add = True
        if add:
            tot += int(s[2*i+1])
        else:
            tot -= int(s[2*i+1])
    return tot

d = list(raw_input())
for i in xrange(8):
    mask = bin(8+i)[3:]
    temp = buildstr(d,mask)
    if eval(temp) == 7:
        print temp[1:]+"=7"
        break

Measured memory_bytes: 2696
# -*- coding: utf-8 -*-

from sys import stdin

def calc(s):

    a = int(s[:2])
    b = int(s[2:])

    if 0 < a and a <= 12:
        a = 1
    elif 0 <= a and a <= 99:
        a = 2
    else:
        a = 3

    if 0 < b and b <= 12:
        b = 1
    elif 0 <= b and b <= 99:
        b = 2
    else:
        b = 3

    if a == 1 and b == 1:
        ans = 'AMBIGUOUS'
    elif a == 1 and b == 2:
        ans = 'MMYY'
    elif a == 2 and b == 1:
        ans = 'YYMM'
    else:
        ans = 'NA'

    return ans

def main():
    s = stdin.readline().rstrip()
    ans = calc(s)
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#define INF 9999999
using namespace std;
typedef unsigned long long int ll;

int main() {
	int R;
	cin >> R;
	if (R < 1200) cout << "ABC" << endl;
	else if (R < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}

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

int main(){
    ll N, M;
    cin >> N >> M;
    if(N == 1 && M == 1){
        cout << 1 << endl;
    }else if(N == 1){
        cout << M - 2 << endl;
    }else if(M == 1){
        cout << N - 2 << endl;
    }else{
        cout << (N - 2) * (M - 2) << endl;
    }
    return 0;
}

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

int tate[500000], yoko[500000];
int main()
{
    int N, W, H, x, y, w;
    cin >> N >> W >> H;
    bool flagtate = true, flagyoko = true;
    for (int i = 0; i < N; i++)
    {
        cin >> x >> y >> w;
        tate[max(x - w, 0)]++;
        tate[x + w]--;
        yoko[max(y - w, 0)]++;
        yoko[y + w]--;
    }
    for (int i = 1; i < W; i++)
    {
        tate[i] += tate[i - 1];
        if (tate[i] == 0)
        {
            flagtate = false;
            break;
        }
    }
    for (int i = 1; i < H; i++)
    {
        yoko[i] += yoko[i - 1];
        if (yoko[i] == 0)
        {
            flagyoko = false;
            break;
        }
    }
    for (int i = 0; i < W; i++)
    {
        if (tate[i] == 0)
        {
            flagtate = false;
            break;
        }
    }
    for (int i = 0; i < H; i++)
    {
        if (yoko[i] == 0)
        {
            flagyoko = false;
            break;
        }
    }
    if (flagtate || flagyoko)
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}


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

const int N = 1e3 + 1;

int used[N];
int a[N][N], pos[N][N];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        used[i] = 1;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - 1; j++) {
            cin >> a[i][j];
            pos[i][a[i][j]] = j;
        }
    }
    int cnt = 0, days = 0;
    while (true) {
        int flag = 0;
        vector<int> played(n + 1, 0);
        for (int v = 1; v <= n; v++) {
            if (used[v] == n)
                continue;
            int i = used[v];
            int u = a[v][i];
            if (used[u] == n)
                continue;
            int j = pos[u][v];
            if (used[v] == i && used[u] == j && !played[v] && !played[u]) {
                flag++;
                used[v]++;
                used[u]++;
                played[v] = played[u] = 1;
            }
        }
        if (!flag)
            break;
        days++;
    }
    for (int i = 1; i <= n; i++)
        cnt += (used[i] == n);

    if (cnt == n)
        cout << days;
    else
        cout << -1;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


Measured memory_bytes: 8064
a, b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A = set(prime_factorize(a))
B = set(prime_factorize(b))
ans = A&B
print(len(ans)+1)


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


int main(){
    string s;
    cin >> s;
    if (s=="Sunny"){
        cout << "Cloudy";
    }else if(s=="Cloudy"){
        cout << "Rainy";
    }else{
        cout << "Sunny";
    }
    return 0;
}


Measured memory_bytes: 256
def solve(n, k, p):
    mu = [(p[i] + 1) / 2.0 for i in range(n)]
    best = sum(mu[:k])
    cur = best
    for i in range(k, n):
        cur += mu[i] - mu[i-k]
        best = max(best, cur)
    return best

n, k = map(int, input().split())
p = list(map(int, input().split()))
print(solve(n, k, p))

Measured memory_bytes: 25060
function Main(input) {
  	input = input.split(" ");
    if(input[0] == 1) {
      console.log(input[1]);
      return;
    }
    var leftNum = parseInt(input[1]) - parseInt(input[0]) + 1;
    var rightNum = parseInt(input[1]) + parseInt(input[0]) - 1;
    var output = [];
    for(var leftNum; leftNum <= rightNum; leftNum++){
      output.push(leftNum);
    }
    console.log(output.join(" "));
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
N,a,b = map(int, input().split())


mod = 10**9+7 #出力の制限
n = max(a, b)
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

A = 1
for i in range(a):
    A *= (N-i)
    A %= mod
B = 1
for i in range(b):
    B *= (N-i)
    B %= mod

ans = pow(2, N, mod) - ((A*g2[a])%mod) - ((B*g2[b])%mod) - 1
print(ans%mod)

Measured memory_bytes: 26836
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mx=-1,i,a[200],j;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            mx=max(mx,abs(a[i]-a[j]));
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int n,m,a,b,c,d,t;
    cin >>n>>m>>a>>b;
    int x[n],y[m];
    c=a;
    for(int i=0;i<n;i++){
        cin >>x[i];
        if(c<x[i]) c=x[i];
    }
    d=b;
    for(int i=0;i<m;i++){
        cin >> y[i];
        if(d>y[i]) d=y[i];
    }
    t=1;
    if(c>=d) t=0;
    if(t==0){
        cout <<"War"<<endl;
    }else{
        cout<<"No War"<<endl;
    }
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    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;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int x;
    cin >> x;
    ll tmp = 0;
    while(x >= 500) {
        x -= 500;
        tmp+=1000;
    }
    while(x>=5) {
        x -= 5;
        tmp += 5;
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 3644