akhauriyash/Code-Regression huggingface dataset:
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 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...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int A,B;
    cin>>A>>B;
    cout<<(A*B)<<endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
 
int main()
{
  int a[3];
  int i, tmp;
  
  scanf("%d%d%d", &a[0], &a[1], &a[2]);
  for (i=1;i<3;i++){
	if (a[i-1]>a[i]){
	tmp = a[i-1];
    a[i-1]=a[i];
    a[i]=tmp;
    }
  }
  if ((a[0]==5)&&(a[1]==5)&&(a[2]==7)){
    printf("YES\n");
  }else{
	printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from time import clock
a=clock()
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;
# code here---
n = ii1()
arr = iia()
ans=0
for i in range(1,n):
    if arr[i]<arr[i-1]:
        ans+=abs(arr[i-1]-arr[i])
        arr[i]=arr[i-1]
print(ans)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

typedef pair<double, double> Point;

double distance_of_Point_to_Point(Point A, Point B) { // 点 A と点 B の距離
	return hypot(A.FI - B.FI, A.SE - B.SE);
}

Point triangle_incenter(Point A, Point B, Point C) { // 三角形 ABC の内心の座標
	double a = distance_of_Point_to_Point(B, C);
	double b = distance_of_Point_to_Point(C, A);
	double c = distance_of_Point_to_Point(A, B);
	return MP(
		(a * A.FI + b * B.FI + c * C.FI) / (a + b + c), 
		(a * A.SE + b * B.SE + c * C.SE) / (a + b + c)
	);
}

double distance_of_Point_to_Line(Point P, Point A, Point B) { // 点 P と直線 AB の距離
	double a = B.SE - A.SE;
	double b = A.FI - B.FI;
	double c = A.SE * B.FI - A.FI * B.SE;
	// 直線 AB の方程式は ax + by + c = 0
	return abs(a * P.FI + b * P.SE + c) / hypot(a, b);
}

// ----

Point p[3];
double IR;

double f(int a, int b) {
	double L = distance_of_Point_to_Point(p[a], p[b]);
	return L / (2.0 + L / IR);
}

int main() {
	inc(i, 3) { cin >> p[i].FI >> p[i].SE; }
	
	Point I = triangle_incenter(p[0], p[1], p[2]);
	IR = distance_of_Point_to_Line(I, p[0], p[1]);
	
	double ans = 0.0;
	inc(i, 3) { setmax(ans, f(i, (i + 1) % 3)); }
	
	printf("%.12f\n", ans);
	
	return 0;
}


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

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

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i%3 != 0 && i%5 != 0) ans += i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n;
  cin >>n;
  ll d[n];
  for(ll i=0;i<n;i++) cin>>d[i];
  sort(d,d+n);
  cout <<d[n/2]-d[n/2-1]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <string>
#include <memory.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 29;

const int MAX_N = 1000010;
ll euler[MAX_N];
ll s[MAX_N];

void euler_phi(){
  rep(i, MAX_N) euler[i] = i;
  for(int i = 2; i < MAX_N; i++){
    if(euler[i] == i){
      for(int j = i; j < MAX_N; j += i) euler[j] = euler[j] / i * (i - 1);
    }
  }
}

int main(){
  euler_phi();
  s[0] = euler[0] + 1;
  for(int i = 1; i < MAX_N; i++) s[i] = s[i-1] + euler[i];
  int t, n;
  cin >> t;
  rep(i, t){
    cin >> n;
    cout << s[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main () {
  int a;
  cin >> a;
  long long c=0;
  for (int i = 1; i <= a; i++)
  {
    if (i%3 && i%5)
    {
      c+=i;
    }
  }
  printf("%lld\n",c);
}

Measured memory_bytes: 3704
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <bitset>

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

using namespace std;

int main() {
	int N, M, t;
	cin >> N >> M;
	vector<int> a(N, 0);
	rep(i, M) {
		rep(j, 2) {
			cin >> t;
			a[t - 1]++;
		}
	}
	rep(i, N) {
		cout << a[i] << endl;
	}
}




Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const ll INF = LONG_LONG_MAX;

typedef ll Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
    src(src), dst(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;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void Dijkstra(const Graph &g, int s,
              vector<Weight> &dist, vector<int> &prev) {
    int n = (int)g.size();
    dist.assign(n, INF); dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
    for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
        Edge e = Q.top(); Q.pop();
        if (prev[e.dst] != -1) continue;
        prev[e.dst] = e.src;
        for(__typeof(g[e.dst].begin()) f = g[e.dst].begin();f != g[e.dst].end();f++) {
            if (dist[f->dst] > e.weight+f->weight) {
                dist[f->dst] = e.weight+f->weight;
                Q.push(Edge(f->src, f->dst, e.weight+f->weight));
            }
        }
    }
}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N;
    cin >> N;
    Graph g(N);
    repeat(i, N-1){
        int a,b;
        Weight c;
        cin >> a >> b >> c;
        a--;b--;
        g[a].push_back(Edge(a,b,c));
        g[b].push_back(Edge(b,a,c));
    }
    int Q,K;
    cin >> Q >> K;
    K--;
    vector<Weight> dist;
    vint p;
    Dijkstra(g, K, dist, p);
    vector<Weight> ans(Q);
    repeat(i, Q){
        int x,y;
        cin >> x >> y;
        x--;y--;
        ans[i] = dist[x]+dist[y];
    }
    repeat(i, Q){
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 11504
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
for i in range(a,max(c,d)):
    if s[i]==s[i+1]=="#":
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
ans=0
for i in range(b-1,d+2):
    if s[i]==".":
        ans+=1
    else:
        if ans>=3:
            print("Yes")
            exit()
        ans=0
if ans>=3:
    print("Yes")
    exit()
"""
if s[b+1]=="." and s[b-1]==".":
    print("Yes")
    exit()
if s[d-1]=="." and s[d+1]==".":
    print("Yes")
    exit()
"""
print("No")


Measured memory_bytes: 3572
#include<bits/stdc++.h>
//g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG b.cpp
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define sclng(x) scanf("%ld", &x)
typedef long long ll;

int main(){
    int N, x;
    scanf("%d", &N);
    scanf("%d", &x);
    vector<int> v(N);
    rep(i, N){
        scanf("%d", &v[i]);
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    int sum = 0;
    rep(i, N){
        sum += v[i];
        if(i == N - 1){
            if(sum == x){
                cnt++;
                break;
            }else{
                printf("%d", N - 1);
                return 0;
            }
        }
        if(sum <= x){
            cnt++;
        }else{
            break;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

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

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

using ll = long long;
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 )
		cout << "Possible";
	else
		cout << "Impossible";
	cout << "\n"; 
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>

#define PII pair<int,int>
#define LLI long long int

using namespace std;

int main(){
	int N,K;cin>>N>>K;
	vector<int>H(N);for(int i=0;i<N;i++)cin>>H[i];
	vector<int>dp(N,1000010000);
	dp[0]=0;
	for(int i=1;i<N;i++){
		for(int j=i-K;j<i;j++)if(j>=0)dp[i]=min(dp[j]+abs(H[i]-H[j]),dp[i]);
	}
	cout<<dp[N-1]<<endl;

	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int count[100000]={0};
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    for(int i=1;i<n;i++){
        count[i]=count[i-1];
        if(s[i-1]=='A'&&s[i]=='C')count[i]=count[i-1]+1;
        //cout<<count[i]<<" ";
    }
    //cout<<endl;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<count[r-1]-count[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
n = int(input())
a = [int(input()) for i in range(n)]

count = 0
nextbottun = 1

while(nextbottun != 2 and count <= 100000):
    nextbottun = a[nextbottun - 1]
    count += 1

if count <= 100000:
    print(count)
else:
    print(-1)


Measured memory_bytes: 7084
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#define ull unsigned long long 
#define ll long long
using namespace std;

//const int N = 1e5 + 5;
//const ll maxx = 1e18;
//
//ll a[N];
//int main() {
//	int n;
//	cin >> n;
//	ll ans = 1;
//	int flag = 0;
//	for (int i = 1; i <= n; i++) {
//		cin >> a[i];
//		if (a[i] == 0) {
//			flag = 1;
//		}
//	}
//	if (flag == 1) {
//		cout << 0;
//		return 0;
//	}
//
//	for (int i = 1; i <= n; i++) {
//		if (1000000000000000000 / a[i] < ans) {
//			cout << -1;
//			return 0;
//		}
//		else
//			ans *= a[i];
//	}
//	
//	cout << ans;
//}

int main() {
	ll a;
	double b;
	scanf("%lld%lf", &a, &b);

	printf("%lld", (ll)(a*(ll)(round(b*100))/100));
}

//int main() {
//
//}

Measured memory_bytes: 3748
#include<iostream>

using namespace std;

int main() {
	int h, w;

	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				if ((i + j) % 2 == 0) {
					cout << '#';
				}
				else {
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  bool f=false;
  if(s[a]=='-')f=true;
  bool q=false;
  for(int i=0;i<a;i++)if(0<=s[i]-'0'&&s[i]-'0'<=9)q=true;
  bool d=false;
  for(int i=a+1;i<a+b+1;i++)if(0<=s[i]-'0'&&s[i]-'0'<=9)d=true;
  if(f&&q&&d)
  cout <<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	int x;
	cin>>x;
	rep(i,-3000,3001){
		rep(j,-3000,3001){
			int a=i*i*i*i*i;
			int b=j*j*j*j*j;
			if(a-b==x){
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[200005],ans=0;
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
}
sort(a+1,a+n+1);
ll ans=a[n];
if(n%2==0){
    for(ll i=n-1;i>n/2;i--){
        ans+=2*a[i];
    }
}else {
for(ll i=n-1;i>n/2;i--)
{
    if(i==(n/2)+1){
        ans+=a[i];
    }else ans+=2*a[i];
}
}
cout<<ans<<endl;
}


Measured memory_bytes: 5164
using System;

namespace ABC052C
{
    class Program
    {
        static readonly int Mod = 1000000007;

        static void Main(string[] args)
        {
            uint n = UInt32.Parse(Console.ReadLine());
            int[] sups = new int[n + 1];
            for(int i = 2; i <= n; i++)
            {
                sups[i] = 1;
            }

            long res = 1;

            for (int i = 2; i <= n; i++)
            {
                int j = i;
                int k = 2;
                while (j > 1)
                {
                    if (j % k == 0)
                    {
                        sups[k]++;
                        j /= k;
                    }
                    else
                    {
                        k = NextPrime(k);
                    }
                }
            }

            for (int i = 2; i <= n; i++)
            {
                res = (res * sups[i]) % Mod;
            }

            Console.WriteLine(res);
            return;
        }

        static bool IsPrime(int num)
        {
            if ((num > 2) && ((num % 2) == 0)) return false;
            for (int i = 3; i <= (num / 3); i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        static int NextPrime(int num)
        {
            int i = num + 1 + (num % 2);
            while (!IsPrime(i))
            {
                i += 2;
            }
            return i;
        }

    }
}


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

int	main() {
	long N, K;
	cin >>N >>K;
	if (0==K) {
		cout <<N*N <<endl;
		return 0;
	}
	long S=0;
	for (long b=N; b>=K+1; b--) {
		/*
		for (long c=K; c<b; c++)
			S +=(N+b-c)/b;
		*/
		S += (N/b)*(b-K);
		if (N%b>=K)
			S += (N%b)-K+1;
	}
	cout <<S <<endl;
	return 0;
};


Measured memory_bytes: 256
// PKU 1979
#include<cstdio>
#define rep( i, a ) for( int i = 0; i != (a); ++i )

int W, H;
char fld[20][20];
int ans;

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

void dfs( int x, int y )
{
	++ans;
	fld[y][x] = ' ';

	rep( i, 4 )
	{
		int nx = x + dx[i], ny = y + dy[i];
		
		if( nx >= 0 && nx < W && ny >= 0 && ny < H && fld[ny][nx] == '.' )
			dfs( nx, ny );
	}

	return;
}

int main()
{
	while( scanf( "%d%d", &W, &H ), W | H )
	{
		ans = 0;
		int sx, sy;

		rep( i, H )
		{
			getchar();

			rep( j, W )
			{
				fld[i][j] = getchar();
			
				if( fld[i][j] == '@' )
					sx = j, sy = i;
			}
		}

		dfs( sx, sy );

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

	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;
 
ll a, b;
ll c;
ll cnt;

int main(){
	cin >> a >> b;
	
	cnt = 1;
	
	c = gcd(a, b);
	
	FOR(i,2,sqrt(c)+2){
		if (c%i == 0){
			cnt++;
			while (c%i == 0){
				c /= i;
			}
		}
	}
	
	if (c != 1) cnt++;
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int         // 10^18
#define INF 1000000001           // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

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

    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    
    int h,w;vector<string> board;cin>>h>>w;
    REP(i,h){
        string s;cin>>s;
        board.push_back(s);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(board[i][j]=='#'){
                if(i+1 >=h)continue;
                if(j+1 >=w)continue;
                if(board[i+1][j]=='.' && board[i][j+1]=='.'){
                    P("Impossible");
                    return 0;
                }
                if(board[i+1][j]=='#' && board[i][j+1]=='#'){
                    P("Impossible");
                    return 0;
                }
            }
        }
    }
    // 逆順に走査
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(board[i][j]=='#'){
                if(i-1 < 0)continue;
                if(j-1 < 0)continue;
                if(board[i-1][j]=='.' && board[i][j-1]=='.'){
                    P("Impossible");
                    return 0;
                }
                if(board[i-1][j]=='#' && board[i][j-1]=='#'){
                    P("Impossible");
                    return 0;
                }
            }
        }
    }
    P("Possible");
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Multiple Array
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N], bs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> as[i] >> bs[i];

  ll sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll d = (as[i] + sum) % bs[i];
    if (d > 0) sum += bs[i] - d;
  }

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int L, N, X[200000];
ll r[200001], l[200001], MAX;
int main(){
	cin >> L >> N;
	for (int i = 0; i < N; ++i){
        cin >> X[i];
    }

	for (int i = 0; i < N; ++i){
        l[i + 1] = l[i] + X[i] * 2;
    }
	for (int i = N - 1; i >= 0; --i){
        r[i] = r[i + 1] + (L - X[i]) * 2;
    }

	for (int i = 0; i < N; ++i){
		ll cnt = X[i] + l[i] + r[i + 1];
		if (i >= N - (i + 1)){
			cnt -= l[i - (N - (i + 1))];
		}
		else{
			cnt -= r[i + 1 + i + 1];
		}
		MAX = max(MAX, cnt);
		cnt = L - X[i] + l[i] + r[i + 1];
		if (i <= N - (i + 1)){
			cnt -= r[i + 1 + i];
		}
		else{
			cnt -= l[i - (N - (i + 1)) - 1];
		}
		MAX = max(MAX, cnt);
	}
	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 4096
import itertools
N, M = list(map(int, input().split()))

KS = [list(map(int, input().split())) for _ in range(M)]
S = [[KS[m][i]-1  for i in range(1, len(KS[m]))] for m in range(M)]
p = list(map(int, input().split()))

def check(l):
    for m in range(M): # denkyu
        tmp_sum = 0
        for switch in S[m]:
            if l[switch]:
                tmp_sum +=1
        if tmp_sum%2 != p[m]:
            return False
    return True



ans = 0
for l in itertools.product([0,1],repeat=N):
    if check(l):
        ans += 1

print(ans)

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

#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

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

	vector<string> ans;
	string s; cin >> s;
	int n = sz(s);
	set<char> st;
	string cand;
	FOR (i, 0, n) {
		if (i) {
			if (st.count(s[i - 1])) break;
			st.insert(s[i - 1]);
			cand += s[i - 1];
		}
		if (i == n) cand.push_back('a');
		else cand.push_back(s[i] + 1);
		while (st.count(cand.back())) cand.back()++;
		if (cand.back() <= 'z') ans.push_back(cand);
		cand.pop_back();
	}

	if (ans.empty()) cout << "-1\n";
	else cout << *min_element(all(ans));

	return 0;
}


Measured memory_bytes: 256
from itertools import product

n = int(input())
f_all = []
for i in range(n):
    fi = list(map(int, input().split()))
    f_all.append(fi)
p_all = []
for i in range(n):
    pi = list(map(int, input().split()))
    p_all.append(pi)

res = -99999999999
for pro in product([0, 1], repeat=10):
    if sum(pro) == 0:
        continue
    total = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if pro[j] == 1 and f_all[i][j] == 1:
                count += 1
        total += p_all[i][count]
    res = max(res, total)
print(res)

Measured memory_bytes: 3064
n,m = gets.split.map &:to_i
$node = Array.new(n){ [] }
m.times do
  a,b = gets.split.map(&:to_i)
  $node[a-1] << b - 1
  $node[b-1] << a - 1
end

link = Array.new(n){ nil }

def bfs(link)
  q = [0]
  while !q.empty?
    visit = q.shift
    $node[visit].each do |next_node|
      next unless link[next_node].nil?
      link[next_node] = visit
      q.push next_node 
    end
  end
end

bfs(link)
link.shift

puts 'Yes'
link.each do |v|
  puts v + 1
end



Measured memory_bytes: 32856
#include<stdio.h>
#include<string.h>
#define n 100000

int main(){
  long N, topp = 0, i;
  char s[n];
  scanf("%s", s);
  N = strlen(s);
  for(i = 0; i < N; i ++){
    if(s[i] == 'p') topp ++;
  }
  printf("%ld\n", N/2 - topp);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B, M; 
  cin >> A >> B >> M;

  int mina = INF, minb = INF;

  vector<int> a(A);
  REP(i, A){
    cin >> a[i];
    chmin(mina, a[i]);
  }

  vector<int> b(B);
  REP(i, B){
    cin >> b[i];
    chmin(minb, b[i]);
  }

  int ans = mina+minb;
  REP(i, M){
    int x, y, c;
    cin >> x >> y >> c;
    chmin(ans, a[x-1]+b[y-1]-c);
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string S;
    cin >> S;
    int m = (S[5]-'0') * 10 + S[6] - '0';
    if (m > 4) { print("TBD"); }
    else {
        print("Heisei");
    }
}


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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x,a,b;
	cin >> x >> a >> b;
	if (b - a <= 0) cout << "delicious" << endl;
	else if (b - a <= x) cout << "safe" << endl;
	else if (b - a >= x + 1) cout << "dangerous" << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define SIZE 8
#define DATA_SIZE 15 //2*SIZE-1
#define NIL -1
#define FREE 1
#define NON_FREE 0
 
/*
 * 
 */
 
int col[SIZE], row[SIZE], dpos[DATA_SIZE], dneg[DATA_SIZE];
 
void printQueenBoard();
void putQueen(int i);
 
int main(int argc, char** argv) {
    int k, r, c, i;
     
    for (int i = 0; i < SIZE; ++i)
    {
        row[i] = NIL;
        col[i] = FREE;
//        for (int ix = 0; ix < SIZE; ++ix) 
    }
    for (int j = 0; j < DATA_SIZE; ++j)
    {
        dpos[j] = FREE;
        dneg[j] = FREE;
    }
     
    scanf("%d", &k);
    for (int jx = 0; jx < k; ++jx)
    {
        scanf("%d %d", &r, &c);
        row[r] = c;
        col[c] = dpos[r+c] = dneg[r-c+SIZE-1] = NON_FREE;
    }
     
    for (i = 0; i < SIZE; ++i)
        if (row[i] == NIL) break;
    putQueen(i);
     
    return (EXIT_SUCCESS);
}
 
void printQueenBoard()
{
    for (int i = 0; i < SIZE; ++i)
    {
        for (int j = 0; j < SIZE; ++j) printf("%c", (row[i] == j) ? 'Q' : '.');
        printf("\n");
    }
}
 
void putQueen(int i)
{
    int ix;
    if (i == SIZE) 
    {
        printQueenBoard();
        return;
    }
     
    for (int j = 0; j < SIZE; ++j)
    {
        if (col[j] == NON_FREE || dpos[i+j] == NON_FREE || dneg[i-j+SIZE-1] == NON_FREE)
            continue;
        row[i] = j;
        col[j] = dpos[i+j] = dneg[i-j+SIZE-1] = NON_FREE;
        for (ix = i+1; ix < SIZE; ++ix)
            if (row[ix] == NIL) break;
        putQueen(ix);
        row[ix] = NIL;
        col[j] = dpos[i+j] = dneg[i-j+SIZE-1] = FREE;
    }
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
 
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
int64_t dp[110][10]; // 上からiの位置で、j本目に存在するパターン数
int64_t com[10][2];  // i番目の間, selected

void calcCom()
{
  com[0][0] = 1;
  com[0][1] = 1;
  for (int i = 1; i < 10; i++)
  {
    com[i][0] = com[i - 1][0] + com[i - 1][1]; // prevに関わらず選択可能
    com[i][1] = com[i - 1][0];                 // prevが未選択の場合のみ
  }
}

int64_t comb(int64_t w)
{
  if (w < 1)
    return 1; // 選ばないの1通り
  return (com[w - 1][0] + com[w - 1][1]);
}

int main()
{
  int H, W, K;
  cin >> H >> W >> K;
  K--; // 0 indexed
  calcCom();
  dp[0][0] = 1;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (j == 0)
      {
        (dp[i + 1][j] += dp[i][j] * comb(W - 2) % MOD) %= MOD;
        (dp[i + 1][j + 1] += dp[i][j] * comb(W - 3) % MOD) %= MOD;
      }
      else if (j == W - 1)
      {
        (dp[i + 1][j] += dp[i][j] * comb(W - 2) % MOD) %= MOD;
        (dp[i + 1][j - 1] += dp[i][j] * comb(W - 3) % MOD) %= MOD;
      }
      else
      {
        (dp[i + 1][j] += dp[i][j] * comb(j - 1) * comb((W - 1) - j - 1) % MOD) %= MOD;
        (dp[i + 1][j + 1] += dp[i][j] * comb(j - 1) * comb((W - 1) - j - 2) % MOD) %= MOD;
        (dp[i + 1][j - 1] += dp[i][j] * comb(j - 2) * comb((W - 1) - j - 1) % MOD) %= MOD;
      }
    }
  }
  cout << dp[H][K] % MOD << endl;
}


Measured memory_bytes: 3596
n, m = map(int, input().split())

problem = [0] * n
count = [0] * n

penal = 0

for i in range(m):
    p, x = map(str, input().split())
    p = int(p) - 1
    if x == "AC":
        if problem[p] == 0:
            problem[p] = 1
    elif x == "WA":
        if problem[p] == 0:
            count[p] += 1

for i in range(n):
    if problem[i] == 0:
        count[i] = 0

print("{}".format(sum(problem)) + " {}".format(sum(count)))



Measured memory_bytes: 4596
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.09.09 16:42:57
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    ll a, b;
    scanf("%lld%lld", &a, &b);
    if (a == b) {
        printf("%d\n", 0);
    } else if ((a + b) % 2 == 0) {
        printf("%lld\n", (a + b) / 2);
    } else {
        printf("IMPOSSIBLE\n");
    }

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;
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 ord(ll N, ll p) {
    ll res = 0;
    while (N % p == 0) {
        res++;
        N /= p;
    }
    return res;
}
int main() {
    int N, M;
    cin >> N >> M;
    int a;
    cin >> a;
    a /= 2;
    int x = ord(a, 2);
    rep(i, N - 1) {
        int b;
        cin >> b;
        b /= 2;
        if (ord(b, 2) != x) {
            cout << 0 << endl;
            return 0;
        }
        a = lcm(a, b);
        if (a > M) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 0;
    for (int i = 1; a * i <= M; i += 2) {
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
const C: usize = 42;

fn main() {
    proconio::input! {
        n: usize,
        a: [u64; n],
    }

    let s = a[0] + a[1];
    let mut x = 0;
    for i in 2..n {
        x ^= a[i];
    }

    let mut dp = vec![vec![vec![a[0] + 1; 2]; 2]; C];
    dp[0][0][0] = 0;
    for i in 0..(C - 1) {
        let cx = (x >> i) & 1;
        let cs = (s >> i) & 1;
        let ca = (a[0] >> i) & 1;

        for j in 0..2 {
            for k in 0..2 {
                if dp[i][j][k] > a[0] {
                    continue;
                }
                for na in 0..2 {
                    for nb in 0..2 {
                        if (na ^ nb) != cx {
                            continue;
                        }
                        let ns = na + nb + j as u64;
                        if ns % 2 != cs {
                            continue;
                        }
                        let ni = i + 1;
                        let nj = if ns >= 2 { 1 } else { 0 };
                        let nk = if ca < na { 1 } else if ca == na { k } else { 0 };
                        let v = dp[i][j][k] | ((1 << i as u64) * na);
                        if dp[ni][nj][nk] > a[0] || v > dp[ni][nj][nk] {
                            dp[ni][nj][nk] =v;
                        }
                    }
                }
            }
        }
    }

    let r = dp[C - 1][0][0];
    if r <= a[0] && r > 0 {
        println!("{}", a[0] - r);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()
 
#define P pair<int,int>
#define INF 1e9
 
int H,W;
char c[1010][1010];
int dx[4]{0,0,1,-1};
int dy[4]{1,-1,0,0};
vector<vector<int>> dist;

void bfs(P s){
  deque<P> que;
  que.push_back(s);
  while(!que.empty()){
    P q = que.front();que.pop_front();
    int x=q.first,y=q.second;
    rep(i,4){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx<0 || nx>=H || ny<0 || ny>=W) continue;
      if(dist[nx][ny]<=dist[x][y]) continue;
      else{
        if(c[nx][ny]=='.' && dist[nx][ny]>dist[x][y]){
        dist[nx][ny]=dist[x][y];
        que.push_front(make_pair(nx,ny));
        }
      }
    }
    for(int a=x-2;a<=x+2;++a){
      for(int b=y-2;b<=y+2;++b){
        if(a<0 || a>=H || b<0 || b>=W) continue;
        if(c[a][b]=='.' && dist[a][b]>dist[x][y]+1){
          dist[a][b] = dist[x][y] + 1;
          que.push_back(make_pair(a,b));
        }
      }
    }
  }
}
 
 
int main(){
  cin>>H>>W;
  dist.resize(H);
  rep(i,H)dist[i].resize(W);
  rep(i,H)rep(j,W)dist[i][j]=INF;
  int sh,sw;cin>>sh>>sw;sh--,sw--;
  int gh,gw;cin>>gh>>gw;gh--,gw--;
  rep(i,H)rep(j,W)cin>>c[i][j];
  P s=make_pair(sh,sw);
  dist[sh][sw] = 0;
  bfs(s);
  cout<< (dist[gh][gw] == INF ? -1 : dist[gh][gw]) <<endl;
}

Measured memory_bytes: 8552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int area1 = a * b;
		int area2 = c * d;
		if (area1 >= area2) {
			System.out.println(area1);
		} else {
			System.out.println(area2);
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

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

  int cur = 0;
  int cnt = 0;
  while (a[cur] > 0 && cur != 1) {
    cnt++;
    int tmp = cur;
    cur = a[cur] - 1;
    a[tmp] = -1;
  }
  if (a[cur] == -1) cout << -1 << endl;
  else cout << cnt << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
   int  i,n;
   double f;
   long a,s;

   scanf("%d",&n);
   s=1;
   for (i=0;i<n;i++) {
      scanf("%ld",&a);
      if (s>=1) {
         f=1.0*s*a;
         if (f<=1000000000000000000) 
            if (s*a<=1000000000000000000) s*=a;
            else                          s=-1;
         else                       s=-1;
      } else if (a==0) {
         s=0;
         break;
      }
   }
   printf("%ld\n",s);
   return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <vector>
typedef long long unsigned int ll;
using namespace std;

int main() {
    int n;
    cin>>n;
    
    int a[105];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int c;
    c=-a[0];
    reverse(a,a+n);
    c+=a[0];
    cout<<c<<endl;
    
    return 0;

 }


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
	int i,j,n,num[8],Min = 0,Max = 0,ten;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		Min = 0;
		Max = 0;
		ten = 1;
		scanf("%d",&num[0]);
		for(j = 7;j >= 0;j--){
			num[j] = num[0] / ten % 10;
			ten *= 10;
		}
		ten = 1;
		sort(num,num + 8);
		for(j = 7;j >= 0;j--) {
			Min += num[j] * ten;
			ten *= 10;
		}
		ten = 1;
		reverse(num,num + 8);
		for(j = 7;j >= 0;j--) {
			Max += num[j] * ten;
			ten *= 10;
		}
		printf("%d\n",Max - Min);
	}
	return 0;
}

Measured memory_bytes: 1044
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())

#%%code
def resolve():
    x=int(input())
    i=0;temp=0 
    while (1):
        i+=1
        temp+=i
        if temp > x:
            z=-x+temp
            
            for i in range(i):
                if i+1!=z:print(i+1)
            break
        if temp==x:
            for i in range(i):print(i+1)
            break
#%%submit!
resolve()

Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N;
  cin >> N;

  vector<int> color(9);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    int b = a / 400;
    if (8 <= b) {
      color[8]++;
    } else {
      color[b]++;
    }
  }

  int answer = 0;

  for (int i = 0; i < 8; i++) {
    if (color[i] != 0) {
      answer++;
    }
  }

  if (color[8] == 0) {
    cout << answer << " " << answer << endl;
  } else {
    if (answer == 0) {
      cout << 1 << " " << color[8] << endl;
    } else {
      cout << answer << " " << answer + color[8] << endl;
    }
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<queue>
#include<cstring>
#include<cmath>

using namespace std;

int main()
{
    int N,A,B;
    scanf("%d%d%d",&N,&A,&B);
    if(B<A)
        printf("0\n");
    else if(B==A){
        printf("1\n");
    }
    else{
        if(N==1)
            printf("0\n");
        else{
            printf("%lld\n",(long long)(N-2)*(B-A)+1);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,a,b;

    scanf("%d",&n);
    if(n==1){
        printf("Hello World");
    }
    else if(n==2){
        scanf("%d",&a);
        scanf("%d",&b);
        printf("%d",a+b);
    }
    return 0;
}

Measured memory_bytes: 128
N,C = map(int, raw_input().split())
T = [[] for _ in range(C)]
for _ in range(N):
  s,t,c = map(int, raw_input().split())
  T[c-1] += [(s,t)]
for t in T:
  t.sort()
D = [0]*(10**5+1)
for t in T:
  if len(t)>0:
    D[t[0][0]-1] += 1
    for i in range(len(t)-1):
      if t[i][1]<t[i+1][0]:
        D[t[i][1]] -= 1
        D[t[i+1][0]-1] += 1
    D[t[-1][1]] -=1
ans = 0
a = 0
for d in D:
  a += d
  ans = max(ans, a)
print ans


Measured memory_bytes: 19188
s = int(input())
x1 = 10 ** 9
if s < x1:
    print(0, 0, s, 0, 0, 1)
else:
    y2 = s // x1
    if s % x1 == 0:
        print(0, 0, x1, 0, 0, y2)
    else:
        y2 += 1
        y1 = y2 * x1 - s
        print(0, 0, x1, y1, 1, y2)

Measured memory_bytes: 3060