akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  
  vector<long long> A(N);
  
  for(int i = 0;i < N;++i){
    cin >> A[i];
  }
  
  sort(A.begin(),A.end());
  
  long long num = 1e6;
  
  long long num3 = 0LL;
  
  for(int i = A[0];i <= A[N - 1];++i){
    num3 = 0LL;
    for(int j = 0;j < N;++j){
      num3 = (A[j] - i) * (A[j] - i) + num3;
    }
    num = min(num,num3);
  }
  
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);

    double sum = 0;
    rep(i, N) {
        sum += pow(A.at(i), -1);
    }

    sum = pow(sum, -1);

    cout << setprecision(15) << sum << endl;
}

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;
typedef pair<int,int> P;
const int MAX_N = 200005;
int cnt[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N-1)
	{
		int a;
		cin >> a;
		a--;
		cnt[a]++;
	}
	rep(i,N)
	{
		cout << cnt[i] << endl;
	}
	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0; i<N; ++i) cin >> x[i] >> y[i];

    vector<int> perm(N);
    iota(perm.begin(), perm.end(), 0);
    double res = 0;
    do {
        for(int i=1; i<N; ++i) {
            res += sqrt((x[perm[i]] - x[perm[i - 1]]) * (x[perm[i]] - x[perm[i - 1]])
            + (y[perm[i]] - y[perm[i - 1]]) * (y[perm[i]] - y[perm[i - 1]]));
        }   
    } while(next_permutation(perm.begin(), perm.end()));

    for(int i=1; i<=N; ++i) res /= i;
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from queue import Queue

n, q = map(int, input().split())
nodes = [[] for _ in range(n)]  # 隣接ノード
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    nodes[a].append(b)
    nodes[b].append(a)

counts = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    counts[p-1] += x

ans = [0] * n
ans[0] = counts[0]
done = [0] * n
queue = Queue()
queue.put(0)
while True:
    node = queue.get()
    done[node] = 1
    next_nodes = nodes[node]
    for next_node in next_nodes:
        if not done[next_node]:
            queue.put(next_node)
            ans[next_node] = ans[node] + counts[next_node]
    if queue.empty():
        break

print(*ans)


Measured memory_bytes: 100368
#include <bits/stdc++.h>
using namespace std;
const int alpha = 26;
const int maxn = 2e5 + 10;
struct node {
  int cnt[alpha];
  node* nxt[alpha];
  node () {
    for(int i = 0; i < alpha; i++) {
      cnt[i] = 0;
      nxt[i] = NULL;
    }
  }
} *root;

void insert(string s) {
  int cnt[alpha] = {0};
  for(int i = 0; i < s.size(); i++) {
    cnt[s[i] - 'a'] += 1;
  }
  node* cur = root;
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < alpha; j++) cur -> cnt[j] += bool(cnt[j]);
    int c = s[i] - 'a';
    cnt[c] -= 1;
    if(cur -> nxt[c] == NULL) {
      cur -> nxt[c] = new node();
    }
    cur = cur -> nxt[c];
  }
}
int solve(string s) {
  node *cur = root;
  for(int i = 0; i + 1 < s.size(); i++) {
    int c = s[i] - 'a';
    cur = cur -> nxt[c];
  }
  return cur -> cnt[s.back() - 'a'] - 1;
}

string s[maxn];

int main() {
  int n;
  cin >> n;
  root = new node();
  for(int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    insert(s[i]);
  }
  long long ans = 0;
  for(int i = 0; i < n; i++) {
    ans += solve(s[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 323316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string nums; cin >> nums;
    for(int bit = 0; bit < (1<<3); ++bit){
        int res = nums[0]-'0';
        for(int i = 0; i < 3; ++i){
            if(bit & (1<<i)){
                res += nums[i+1]-'0';
            }else{
                res -= nums[i+1]-'0';
            }
        }
        if(res == 7){
            string ans = "";
            ans += nums[0];
            rep(i,3){
                if(bit & (1<<i)) ans+='+';
                else ans+='-';
                ans += nums[i+1];
            }
            ans += "=7";
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;
ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x ;
        x = x * x;
        n = n >> 1;
    }
    return ans;
}
signed main(){
    
    int n,a;
    cin >> n >> a;

    int eq = 0;
    int x[51];
    map<int,int> low;
    map<int,int> high;
    rep(i,n) cin >> x[i];
    sort(x,x+n);
    for(int i = 0;i < n;i++){
        if(x[i] == a) eq++;    
        else if(x[i] > a){
            int X = x[i]-a;
            map<int,int> l(low);
            for(auto y : low){
                l[X+y.fi] += low[y.fi];
            }
            l[X]++;
            low = l;
        }else{
            int X = a-x[i];
            map<int,int> l(high);
            for(auto y : high){
                l[X+y.fi] += high[y.fi];
            }
            l[X]++;
            high = l;
        }
    }
    int k = bitpow(2,eq);
    int ans = k-1;
    
    for(auto y:low){
        ans += k * y.se * high[y.fi];
        // auto itr = high.find(y.se);
        // if(itr != high.end()){
        //     ans += k*y.se*high[y.fi];
        // }
    }

    cout << ans << endl;

    // for(auto y:low)cerr << y.fi << " " << y.se << endl;
    // for(auto y:high)cerr << y.fi << " " << y.se << endl;
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

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

using namespace std;



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


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

int main() {
    uint64_t N;
    std::cin >> N;

    uint64_t t = 1, a = 1;
    uint64_t T, A;
    for (size_t i = 0; i < N; ++i) {
        std::cin >> T >> A;

        uint64_t nt = 0;
        if (t % T == 0) {  
            nt = t / T;
        } else {
            nt = t / T + 1;
        }
        
        uint64_t na = 0;
        if (a % A == 0) {  
            na = a / A;
        } else {
            na = a / A + 1;
        }

        const uint64_t n = std::max<uint64_t>(nt, na);

        t = T * n;
        a = A * n;
    }

    std::cout << t + a << std::endl; 

    return 0;
}


Measured memory_bytes: 256
//package beg_171;
import java.util.*;
import java.lang.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		char a = s.nextLine().charAt(0);
		
		boolean b = Character.isUpperCase(a);
		
		if (b) {
			System.out.println("A");
		}
		else {
			System.out.println("a");
		}
		
		
	}

}


Measured memory_bytes: 35668
#include <stdio.h>

void swap(int *, int *);
void pri(int [], int);

int main(void)
{
    int i, j, n, q, b, e, t, A[1000];

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", A + i);

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d %d %d", &b, &e, &t);
        for (j = b; b < e; b++)
            swap(A + b, A + (b - j) + t);
    }

    pri(A, n);
    return 0;
}

void swap(int *a, int *b)
{
    int t;

    t = *a;
    *a = *b;
    *b = t;
}

void pri(int A[], int N)
{
    int i;
    
    for (i = 0; i < N; i++) {
        if (i > 0) putchar(' ');
        printf("%d", A[i]);
    }
    putchar('\n');
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    for (int i=0; i<min((ll)s.size(), k); i++){
        if (s[i] >= '2') {
            out(s[i]);
            return 0;
        }
    }
    out('1');
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
bool flag;
int n;
bool isPalindrome(int l, int r) {
    while(l < r) {
        if(s[l] != s[r])    return false;
        l++;
        r--;
    }
    return true;
}
int main() {
    cin>>s;
    n = s.size();
    flag = isPalindrome(0, n - 1) && isPalindrome(0, ((n - 1) / 2) - 1);
    puts((flag) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int N;
   cin >> N;
   
   int V[N], C[N];
   
   for(int i = 0; i < N; i++) cin >> V[i];
   for(int i = 0; i < N; i++) cin >> C[i];
    
   int dp[N+1];
   
   dp[0] = 0;
   for(int i = 0; i < N; i++){
       dp[i+1] = max(dp[i], dp[i] + V[i] - C[i]);
   }
   
   int ans = 0;
   for(int i = 0; i <= N; i++){
       ans = max(ans, dp[i]);
   }
   
   cout << ans << endl;
}


Measured memory_bytes: 256
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        h: [u64;n]
    }
    let mut cnt = 0;
    let mut max = 0;
    for i in 0..n-1 {
        if h[i] < h[i+1] {
            cnt = 0;
        } else {
            cnt += 1;
            max = std::cmp::max(cnt, max);
        }
    }
    println!("{}", max);
}
/* vim:set foldmethod=marker: */


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()%
#define int long long

const int mod = 2019;

inline int modprod(int a, int b){
    return ((a % mod) * (b % mod)) % mod;
}

int solve(int l, int r){
    int ret = INT_MAX;
    reps(i, l, min(l+2018, r))reps(j, i+1, min(l+2018, r)){
        ret = min(ret, modprod(i,j));
    }
    return ret;
}

signed main(){
    int l, r;
    cin >> l >> r;
    cout << solve(l,r) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
int main()
{
 
 //OJ;
  ll a,b,c,k;
 cin>>a>>b>>c>>k;
 if(k<=a)
 {
     cout<<k;
 }else if(k<=a+b)
 {
      cout<<a;
 }else
 {
      cout<<a-(k-(a+b));
 }
 
 
 
 
 
 
return 0;
   
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
	int x, y;
	cin >> x >> y;
	int ans = abs(abs(y) - abs(x));
	if (x < 0 && y > 0)
		ans++;
	if (x > y)
	{
		ans++;
		if (x < 0 || y > 0)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int s(int i)
{
	int t=0;

	while(i>0){
		t+=i%10;
		i/=10;
	}
	return t;
}

int main()
{
	int n,a,b,t=0,i;

	scanf("%d%d%d",&n,&a,&b);

	for(i=1;i<=n;i++)
		if(a<=s(i)&&s(i)<=b)
			t+=i;
	printf("%d",t);
	return 0;
}

Measured memory_bytes: 128
import math
A, B, H, M = map(int, input().split())

a = 6*M
b = 30*H + 0.5*M

if a==b:
    print(abs(A-B))
    exit()
elif a < b:
    dif = b - a
else:
    dif = a - b

if int(dif) == 180:
    print(A+B)
else:
    deg = dif
    print(math.sqrt(pow(A,2)+pow(B,2)+(-2*A*B*math.cos(math.radians(deg)))))


Measured memory_bytes: 9524
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int x,y,s=0;
	scanf("%d%d",&x,&y);
	if(x%y!=0)
	{
	printf("%d",x);
	return 0;
	}
	else 
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf1 INT_MAX
#define inf2 LLONG_MAX
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sbit __builtin_popcount
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define rit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define fill(a,b) memset(a,b,sizeof(a))
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define infile ifstream fin; fin.open("input.txt")
#define outfile ofstream fout; fout.open("output.txt")
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<ll,int>
#define pll pair<ll,ll>
#define p_queue priority_queue< plii,vector< plii >,greater< plii > > 
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%lld",&x)
#define sst(x) scanf("%s",x)
#define pl(x) printf("%lld\n",x)
#define pi(x) printf("%d\n",x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

inline ll binex(ll a,ll b)
{
    ll ans=1,temp=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b=b>>1;
    }
    return ans;
}

bool solve(int n,int k,int arr[])
{
    bool dp[k+1]; fill(dp,0);
    sort(arr,arr+n);
    dp[arr[0]]=1;
    rep(i,arr[0]+1,k+1){
        rep(j,0,n){
            if(arr[j]>i) break;
            if(!dp[i-arr[j]]) dp[i]=1;
        }
    }
    
        //dbga(dp,k);
    
    return dp[k];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k; cin>>n>>k;
    int arr[n];
    rep(i,0,n) cin>>arr[i];
    if(solve(n,k,arr)) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

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

int n;
bool pn[10001] = { false };

int main(){
	for (int i = 2; i < 10001; i++) {
		if (!pn[i]) {
			for (int j = i+i; j < 10001; j += i) {
				pn[j] = true;
			}
		}
	}
	while (cin >> n) {
		for (int i = n; i >= 2; i--) {
			if (!pn[i] && !pn[i - 2]) {
				cout << i - 2 << " " << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<vector>
#include<fstream>
#include<math.h>
#include<algorithm>
using namespace std;
int DP[150][100][10];
int N, M;
int K[150];
int X[150][10], Y[150][10];
int main()
{
	while (true){
		  
		cin >> N >> M;
		if (N == 0 && M == 0)break;
		for (int i = 0; i <150; i++){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k <=M; k++){
					DP[i][k][j] = 1000000000;
				}
			}
		}
		for (int i = 0; i < N; i++){
			cin >> K[i];
			for (int j = 0; j < K[i]; j++){
				cin >> X[i][j] >> Y[i][j];
			}
		}
		for (int j = 0; j < K[0]; j++){
			DP[0][0][j] = 0;
		}
		for (int j = 0; j < K[1]; j++){
			DP[1][1][j] = 0;
		}
		for (int j = 0; j < K[1]; j++){
			for (int k = 0; k < K[0]; k++){
				DP[1][0][j] = min(DP[1][0][j],(Y[1][j] + Y[0][k])*abs(X[1][j] - X[0][k]));
			}
		}
		for (int i = 2; i < N; i++){
			for (int j = 0; j < K[i]; j++){
				for (int k = 0; k < K[i - 1]; k++){
					for (int l = 0; l <= M; l++){
						DP[i][l][j] = min(DP[i][l][j], DP[i - 1][l][k] + (Y[i][j] + Y[i - 1][k])*abs(X[i][j] - X[i - 1][k]));
					}
				}
				for (int k = 0; k < K[i - 2]; k++){
					for (int l = 0; l < M; l++){
						DP[i][l+1][j] = min(DP[i][l+1][j], DP[i - 2][l][k] + (Y[i][j] + Y[i - 2][k])*abs(X[i][j] - X[i - 2][k]));
					}
				}
			}
		}
		int ans = 1000000000;
		
		
		for (int j = 0; j < K[N - 1]; j++){
			for (int k = 0; k <= M; k++){
				ans = min(ans, DP[N - 1][k][j]);
			}
		}
		for (int j = 0; j < K[N - 2]; j++){
			for (int k = 0; k < M; k++){
				ans = min(ans, DP[N - 2][k][j]);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

char c[1001][1001];
bool a[1001][1001], b[1001][1001];
int h, w;
queue<int> pos, pos_next;

// void dfs(int x, int y){
//     if(y + 1 <= w && c[x][y + 1] == '.' && (a[x][y + 1] == 0 || a[x][y + 1] > a[x][y])){
//         a[x][y + 1] = a[x][y];
//         pos.push(x * 1001 + y + 1);
//         dfs(x, y + 1);
//     }
//     if(y - 1 >= 1 && c[x][y - 1] == '.' && (a[x][y - 1] == 0 || a[x][y - 1] > a[x][y])){
//         a[x][y - 1] = a[x][y];
//         pos.push(x * 1001 + y - 1);
//         dfs(x, y - 1);
//     }
//     if(x + 1 <= h && c[x + 1][y] == '.' && (a[x + 1][y] == 0 || a[x + 1][y] > a[x][y])){
//         a[x + 1][y] = a[x][y];
//         pos.push(x * 1001 + 1001 + y);
//         dfs(x + 1, y);
//     }
//     if(x - 1 >= 1 && c[x - 1][y] == '.' && (a[x - 1][y] == 0 || a[x - 1][y] > a[x][y])){
//         a[x - 1][y] = a[x][y];
//         pos.push(x * 1001 - 1001 + y);
//         dfs(x - 1, y);
//     }
// }

void dfs(int x, int y){
    if(x < 1 || x > h || y < 1 || y > w)
        return;
    if(a[x][y])
        return;
    if(c[x][y] != '.')
        return;
    a[x][y] = true;
    pos_next.push(x * 1001 + y);
    dfs(x + 1, y);
    dfs(x - 1, y);
    dfs(x, y + 1);
    dfs(x, y - 1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j)
            cin >> c[i][j];
    }

    pos.push(ch * 1001 + cw);
    int px, py;
    int k = 1;
    while(!pos.empty()){
        while(!pos.empty()){
            px = pos.front();
            pos.pop();
            pos_next.push(px);
            py = px % 1001;
            px = px / 1001;
            dfs(px, py);
        }
        // if(px == dh && py == dw){
        //     break;
        // }
        if(a[dh][dw])
            break;
        ++k;
        while(!pos_next.empty()){
            px = pos_next.front();
            pos_next.pop();
            py = px % 1001;
            px = px / 1001;
            for(int i = (px - 2 >= 1 ? px - 2 : 1); i <= (px + 2 <= h ? px + 2 : h); ++i)
                for(int j = (py - 2 >= 1 ? py - 2 : 1); j <= (py + 2 <= w ? py + 2 : w); ++j){
                    if(c[i][j] == '.' && !a[i][j] && !b[i][j]){
                        //a[i][j] = true;
                        b[i][j] = true;
                        pos.push(i * 1001 + j);
                    }
                }
        }
    }
    if(a[dh][dw])
        cout << k - 1 << "\n";
    else
        cout << -1 << "\n";
    return 0;
}


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

int main(){
    int n,l;
    cin >> n >> l;
    int ans=0;
    for(int i=0;i<n;i++){
        ans +=l+i;
    }
    if(l<=0&&abs(l)<n){
        cout << ans << endl;
    }
    else if(l<0){
        cout << ans - (l+n-1) << endl;
    }
    else{
        cout << ans - l << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&nums[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(nums)))
    ans := nums[0]*10 + nums[1] + nums[2]
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

constexpr int mod = 1000000007;
class mint {
 public:
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }
};

istream& operator>>(istream& is, const mint& m) {
  is >> m.x;
  return is;
}

ostream& operator<<(ostream& os, const mint& m) {
  os << m.x;
  return os;
}

mint choose(long long n, long long a) {
  mint x, y;
  x.x = 1;
  y.x = 1;
  for (long long i = (0); i < (a); ++i) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

ll tentou_num(vector<int>& d, int len) {
  ll ret = 0;
  REP(i, len - 1) {
    FOR(j, i + 1, len) {
      if (d[j] < d[i]) ret++;
    }
  }
  return ret;
}

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> data(n);
  REP(i, n) {
    int x;
    cin >> x;
    data[i] = x;
  }
  mint a, b, km;
  a.x = tentou_num(data, n);
  sort(ALL(data));
  reverse(ALL(data));
  b.x = tentou_num(data, n);
  km.x = k;
  mint ans;
  ans.x = 0;
  ans = km * a + (km * (km - 1)) * b / 2;
  cout << ans << endl;
}

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

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

  int n, m;
  cin >> n >> m;
  cout << n*(n-1)/2 + m*(m-1)/2 << endl;

  return 0;
}

Measured memory_bytes: 384
s = input()

N = int(s.split()[0])
K = int(s.split()[1])

have = []

for i in range(K):
  d = int(input())
  A = input().split()
  for k in range(d):
    have.append(int(A[k]))

result = 0
    
for i in range(N):
  if (i+1) not in have:
    result += 1
    
print(result)

Measured memory_bytes: 9200
#include <iostream>

using namespace std;

int main() {
	int i = 0;
	int a;
	int s;
	char b;
	cin >> s;
	i++;
	while(1) {
		if (i % 2 == 0) {
			cin >> a;
				if (b == '+') {
					s += a;
				} else if (b == '-') {
					s-= a;
				} else if (b == '*') {
					s *= a;
				} else {
					s /= a;
				}
		} else {
			cin >> b;
			if (b == '=') {
				cout << s << endl;
				break;
			}
		}
		i++;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int l, k;
unsigned long long int n = 0;

unsigned long long int permutation(int n, int s, int t);

int main() {
  scanf("%d %d", &l, &k);

  int thin = 2;
  int thick = k + 1;

  if ( l == 1 ) {
    printf("1\n");
    return 0;
  }

  n++;
  for ( int i = 1; i <= l; i++ ) {
    int s = l - 1 - thin * i;
    if ( s < 0 ) {
      break;
    }
    n++;
  }

  if ( k > l ) {
    printf("%llu\n", n);
    return 0;
  }

  n++;
  for ( int i = 1; i <= l; i++ ) {
    int s = l - k - thick * i;
    if ( s < 0 ) {
      break;
    }
    n++;
  }

  for ( int i = 1; i <= l; i++ ) {
    int s = l - thick * i + 1;
    if ( s < 0 ) {
      break;
    }
    for ( int j = 1; j <= l; j++ ) {
      int t = s - thin * j;
      if ( t < 0 ) {
        break;
      }
      n += permutation(i + j, i, j);
    }
  }

  printf("%llu\n", n);

  return 0;
}

unsigned long long int permutation (int n, int s, int t) {
    unsigned long long int sum = 1;
    long double dsum = 0.0000000001;
    int mx = s - t > 0 ? s : t;
    int mn = t - s < 0 ? t : s;

    // printf("mx:%d, mn%d\n", mx, mn);
    for ( int i = n; i >= mx + 1; i-- ) {
      dsum *= i;
    }

    if ( mn < 2 ) {
      return (unsigned long long int)(dsum * 10000000000);
    }


    for ( int i = mn; i >= 2; i-- ) {
      dsum /= i;
    }

    sum = dsum * 10000000000;
    // if (sum == 0) {
    //   printf("i:%d, j:%d, %llu\n", s, t, sum);
    // }
    return sum;
}

Measured memory_bytes: 3228
use std::io;
use std::cmp;
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: String = iter.next().unwrap().parse().unwrap();
    let b: String = iter.next().unwrap().parse().unwrap();
    println!("{}", if a == b { "H" } else { "D" });
}


Measured memory_bytes: 4352
#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int n;
	int i,max=-1;
	int C[100001] = {0};
	vector<int> A,B;
	scanf("%d",&n);
	A.resize(n);
	B.resize(n);
	C[0]=0;
	for(i=0; i<n; ++i) {
		scanf("%d",&A[i]);
		max=(max<A[i]?A[i]:max);
	}
	for(i=0; i<=max; ++i) {
		C[i]=0;
	}
	for(i=0; i<n; ++i) {
		++C[A[i]];
	}
	for(i=1; i<=max; ++i) {
		C[i]=C[i]+C[i-1];
	}
	for(i=n-1; i>=0; --i) {
		B[C[A[i]]-1] = A[i];
		--C[A[i]];
	}
	for(i=0; i<n-1; ++i) {
		printf("%d ",B[i]);
	}
	printf("%d\n",B[n-1]);
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  VI p(n);
  REP(i, n) cin >> p[i];

  VI a(n+1);
  set<int> s;
  REP(i, n) {
    // p[i]より大きい最小
    auto itr = s.upper_bound(p[i]);
    if(itr != s.end()) {
      chmax(a[*itr], p[i]);
    }
    s.insert(p[i]);
  }
  FOR(i, 1, n+1) a[i] = max(a[i], a[i-1]);

  VI b(n+1, INF);
  s.clear();
  for(int i=n-1; i>=0; --i) {
    // p[i]以下の最大
    auto itr = s.lower_bound(p[i]);
    if(itr == s.begin()) {

    } else {
      itr--;
      chmin(b[*itr], p[i]);
    }
    s.insert(p[i]);
  }
  for(int i=n-1; i>=0; --i) {
    b[i] = min(b[i], b[i+1]);
  }

  // cout << a << endl << b << endl;

  int ret = INF;
  FOR(i, 1, n+1) {
    int tmp = b[i];
    if(tmp == INF) tmp = 0;
    else tmp = n - b[i] + 1;
    chmin(ret, a[i] + tmp);
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 14336
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
bool prime[1000100];
void eratos()
{
	memset(prime,true,sizeof(prime));
	prime[0]=prime[1]=false;
	for(int i=2;i*i<=1000000;i++)
	{
		if(prime[i])for(int j=i*2;j<=1000000;j+=i)
		{
			prime[j]=false;
		}
	}
	return;
}
int main()
{
	eratos();
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		int cnt = 0;
		for(int i=2;i<=n/2;i++)if(prime[i]&&prime[n-i])cnt++;
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2144
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] digits = new int[m];
    int[] numbers = new int[m];
    int[] output = new int[n];
    for(int i = 0; i < m; i++){
      digits[i] = sc.nextInt();
      numbers[i] = sc.nextInt();
    }
    boolean bl = true;
    for(int i = 0; i < m; i++){
      if(digits[i] == 1 && numbers[i] == 0 && n != 1){
        bl = false;
      }
      for(int j = i + 1; j < m; j++){
        if(digits[i] == digits[j] && numbers[i] != numbers[j]){
          bl = false;
        }
      }
      output[digits[i] - 1] = numbers[i];
    }
    if(!bl){
      System.out.println(-1);
    }else if(output[0] == 0 && n == 1){
      System.out.println(0);
    }else if(output[0] == 0){
      int num = (int)(1 * Math.pow(10, n - 1));
      for(int i = 1; i < n; i++){
        num += output[i] * Math.pow(10, n - 1 - i);
      }
      System.out.println(Math.round(num));
    }else{
      int num = 0;
      for(int i = 0; i < n; i++){
        num += output[i] * Math.pow(10, n - 1 - i);
      }
      System.out.println(Math.round(num));
    }
  }
}

Measured memory_bytes: 22608
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int H, W;
int idx(int i, int j) {
	return i*W + j;
}
char board[403][403];

struct UnionFind {
	vector<int> parent;
	vector<int> black, white;

	UnionFind(int size) : parent(size, -1) {
		black.resize(size, 0);
		white.resize(size, 0);
		for (int u=0; u<size; u++) {
			int i = u/W;
			int j = u%W;
			if (board[i][j] == '#')
				black[u]++;
			else
				white[u]++;
		}
	}


	int find(int a) {
		if (parent[a] < 0) return a;
		return parent[a] = find(parent[a]);
	}

	// Returns false if a and b are already contained it the same set
	bool merge(int a, int b) {
		a = find(a); b = find(b);
		if (a==b) return false;

		// a should be the parent of b
		if (parent[a] > parent[b]) swap(a, b);
		parent[a] += parent[b];
		parent[b] = a;

		black[a] += black[b];
		white[a] += white[b];

		return true;
	}

	void clear() {
		for (int &p : parent) p = -1;
	}
};



int main() {
	//freopen("input.txt", "r", stdin);

	cin >> H >> W;
	for (int i=0; i<H; i++) cin >> board[i];

	UnionFind uf(H*W);
	for (int i=0; i<H; i++) for (int j=0; j<W-1; j++) 
		if (board[i][j] != board[i][j+1])
			uf.merge(idx(i, j), idx(i, j+1));

	for (int i=0; i<H-1; i++) for (int j=0; j<W; j++) 
		if (board[i][j] != board[i+1][j])
			uf.merge(idx(i, j), idx(i+1, j));

	ll ans = 0;
	for (int u=0; u<H*W; u++) if (uf.parent[u] < 0) {
		ans += (ll) uf.black[u] * uf.white[u];
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 2304
import math


def koch(d, p1, p2):
    if d == 0:
        return

    s, t, u = [0, 0], [0, 0], [0, 0]
    s[0] = (2 * p1[0] + 1 * p2[0]) / 3
    s[1] = (2 * p1[1] + 1 * p2[1]) / 3
    t[0] = (1 * p1[0] + 2 * p2[0]) / 3
    t[1] = (1 * p1[1] + 2 * p2[1]) / 3
    u[0] = (t[0] - s[0]) * math.cos(th) - (t[1] - s[1]) * math.sin(th) + s[0]
    u[1] = (t[0] - s[0]) * math.sin(th) + (t[1] - s[1]) * math.cos(th) + s[1]

    koch(d-1, p1, s)
    print(" ".join(map(str, s)))
    koch(d-1, s, u)
    print(" ".join(map(str, u)))
    koch(d-1, u, t)
    print(" ".join(map(str, t)))
    koch(d-1, t, p2)

if __name__ == "__main__":
    th = math.radians(60)
    n = int(input())
    a = [0, 0]
    b = [100, 0]

    print(" ".join(map(str, a)))
    koch(n, a, b)
    print(" ".join(map(str, b)))

Measured memory_bytes: 7984
#include<stdio.h>
#include<string.h>
int main(void){
  char a[15];
  char b[100] = "abcdefghijklmnopqrstuvwxyz";
  char c[4];
  int i;
  scanf("%s",a);
  i=-1;
  while(1){
    i++;
    if(b[i]==a[0]){
      break;
    }
  }
  c[0] = b[i+1];
  printf("%s",c);
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, a, b;
    cin >> n >> a >> b;
    llong h_max = -1;
    vector<llong> h(n);
    rep(i, n) {
        cin >> h[i];
        h_max = max(h_max, h[i]);
    }

    llong left = 0, right = 1e9, t;
    while (left + 1 < right) {
        t = (left + right) / 2;
        llong cnt = 0;
        rep(i, n) {
            if (h[i] > b * t) cnt += ceil((ldouble)(h[i] - b * t) / (a - b));
        }
        if (cnt <= t) right = t;
        else left = t;
    }

    cout << right << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
 
#define A first
#define B second
 
typedef long long ll;
constexpr int MOD = 1e9 + 7;

void solve() {
  string s;
  cin >> s;
  if(s[s.size() - 1] == 's') s += "es";
  else s += 's';
  cout << s;
}

 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}

Measured memory_bytes: 3664
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); ++i)

using namespace std;

int main(){
  ll D, G, count, point, ans = 1010, l, rem;

  cin >> D >> G;

  vector<ll> p(D), c(D);

  rep(i, D){
    cin >> p[i] >> c[i];
  }

  rep(i, (1<<D)){
    count = 0; point = 0; l = -1;
    rep(j, D){
      if ((i&(1<<j)) != 0) {
        count += p[j];
        if(count >= ans) break;
        point += p[j]*(j+1)*100 + c[j];
      }else{
        l = j+1; //完答していない中で一番配点高いのがl*100点問題
      }
    }
    if(count >= ans) continue;
    if(point < G && l != -1){
      rem = (G-point-1)/(l*100) +1;
      if(p[l-1] <= rem) continue;
      count += rem;
    }
    if(point < G && l == -1) continue;
    ans = min(ans, count);
  }

  cout << ans << endl;




  return 0;
}


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

int main () {
    string Alist;
    cin >> Alist;
    string list[9] = {"+++","++-","+-+","-++","-+-","-++","--+","---","+--",};
    int A = Alist[0] - '0';
    int B = Alist[1] - '0';
    int C = Alist[2] - '0';
    int D = Alist[3] - '0';

    for(int i = 0; i<9; i++) {
        int res = 0;
        if(list[i][0] == '+') {
            res = A + B;
        } else {
            res = A - B;
        }
        if(list[i][1] == '+') {
            res = res + C;
        } else {
            res = res - C;
        }
        if(list[i][2] == '+') {
            res = res + D;
        } else {
            res = res - D;
        }
        if(res == 7) {
            cout << A << list[i][0] << B << list[i][1] << C << list[i][2] << D << "=7\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,ans=0; cin>>N;
  vector<ll> A(100010,0);
  for(ll i=0; i<N; i++){
    ll a; cin>>a;
    A[a]++;
    ans+=a;
  }
  ll Q; cin>>Q;
  for(ll i=0; i<Q; i++){
    ll b,c; cin>>b>>c;
    ans-=A[b]*b;
    ans+=A[b]*c;
    A[c]+=A[b];
    A[b]=0;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 4040
while true
  w, h = gets.split.map(&:to_i)
  break if w == 0
  xa = {}; ya = {}
  xa[0] = 0; xa[w] = 0
  ya[0] = 0; ya[h] = 0
  points = []
  gets.to_i.times do
    p = gets.split.map(&:to_i)
    points << p
    xa[p[0]] ||= 0; xa[p[2]] ||= 0
    ya[p[1]] ||= 0; ya[p[3]] ||= 0
  end
  tmp_x = xa.keys.sort
  xa.keys.each{ |k| xa[k] = tmp_x.index(k) + 1 }
  tmp_y = ya.keys.sort
  ya.keys.each{ |k| ya[k] = tmp_y.index(k) + 1 }
  xs = xa.size; ys = ya.size
  fld = Array.new(ys+1){ Array.new(xs+1, true) }
  fld[0].fill(false); fld[ys].fill(false)
  fld.map{ |arr| arr[0] = arr[xs] = false }
  for p in points
    x1, y1, x2, y2 = p
    for y in (ya[y1]...ya[y2])
      for x in (xa[x1]...xa[x2])
        fld[y][x] = false
      end
    end
  end
  ret = 0
  for y in (1...ys)
    for x in (1...xs)
      next unless fld[y][x]
      arr = []
      arr << [y, x]
      until arr.empty?
        ny, nx = arr.shift
        [[-1,0],[0,-1],[1,0],[0,1]].each do |dy, dx|
          px = nx+dx; py = ny+dy
          if fld[py][px]
            arr << [py, px] 
            fld[py][px] = false
          end
        end
      end
      ret += 1
    end
  end
  p ret
end

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

signed main() {
	int n;
	cin >> n;
	vector<int> a(n);

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

	while (true) {
		sort(a.begin(), a.end());
		if (a[0] == a[n-1]) {
			break;
		}
		for (int i = 1; i < n; i++) {
			if (a[i] > a[0]) {
				if (a[i] % a[0] == 0) a[i] = a[0];
				else a[i] %= a[0];
			}
		}
	}

	cout << a[0] << endl;
}


Measured memory_bytes: 640
s = input()
lst = list(s)

first =list(map(int, lst[:2]))
last = list(map(int, lst[2:]))

f_num = first[0]*10 + first[1]
s_num = last[0]*10 + last[1]

if(f_num<=12 and f_num>0):
    if(s_num<=12 and s_num>0):
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif(s_num<=12 and s_num>0):
    print("YYMM")
else:
    print("NA")
    



Measured memory_bytes: 3064
while True:
    x,y = map(int,input().split())
    
    if x==0 and y==0:
        break
    
    
    if x < y:
        x,y = y,x
    
    z = 0
    while True:
        z += 1
        tmp = x % y
        x, y = y, tmp
        if tmp == 0:
            break

    print(x, z)



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

#define ll long  long
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;

int n;
ll A,B;
ll p[maxn];
int jump[maxn][2], near[maxn][2];

ll dp[maxn][2], sum[maxn][2];

ll add(ll x, ll y) {
    return ((x+y)%mod + mod)%mod;
}

ll get(int l, int r, int t) {
    if(l>r) return 0;
    return add(sum[r][t], l-1>=0 ? -sum[l-1][t] : 0);
}

int main() {
    scanf("%d%lld%lld",&n,&A,&B);
    for(int i=1;i<=n;i++) scanf("%lld",&p[i]);
    //find jump[x][t]
    for(int x=1;x<=n;x++) {
        jump[x][0] = p[x]-p[x-1]>=A ? jump[x-1][0] : x;
        jump[x][1] = p[x]-p[x-1]>=B ? jump[x-1][1] : x;
    }
    //find near[x][t]
    for(int x=1;x<=n;x++) {
        near[x][0] = near[x-1][0];
        near[x][1] = near[x-1][1];
        while(p[x]-p[near[x][0]+1]>=A) near[x][0]++;
        while(p[x]-p[near[x][1]+1]>=B) near[x][1]++;
    }
    near[n+1][0] = near[n+1][1] = n-1;
    //show
//    for(int x=1;x<=n;x++) {
//        printf("x = %d\n",x);
//        printf("\tjump = %d and %d\n",jump[x][0],jump[x][1]);
//        printf("\tnear = %d and %d\n",near[x][0],near[x][1]);
//    }
    //solve
    dp[0][0] = dp[0][1] = 1;
    sum[0][0] = sum[0][1] = 1;
    for(int x=1;x<=n;x++) {
        for(int t=0;t<=1;t++) {
            dp[x][t] = get(jump[x][t]-1, min(x-1,near[x+1][!t]), !t);
//            add(sum[min(x-1,near[x+1][!t])][!t], jump[x][t]-1-1>=0 ? -sum[jump[x][t]-1-1][!t] : 0);
            sum[x][t] = add(sum[x-1][t], dp[x][t]);
//            printf("dp %d %d = %lld [%d, %d]\n",x,t,dp[x][t],jump[x][t]-1,near[x+1][!t]);
        }
    }
    printf("%lld",add(dp[n][0],dp[n][1]));
}


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

int main(){
  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  
  if(b >= a){
    if(w*t +b-a <= v*t)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  else{
    if(w*t+a-b <= v*t)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 3632
#include <cstdio>

int main()
{
	char buf[200001];

	scanf("%s", buf);

	char *p = buf;
	long long n = 0;
	while (*p != '\0') {
		long long tmp = *p - '0';
		n += tmp;
		p++;
	}
	printf("%s\n", (n % 9 == 0) ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 1784
n=int(input())
minsum=float('inf')
for i in range(1,(n//2)+1):
    a=i
    b=n-i
    asum=0
    bsum=0
    while a>0:
        asum+=a%10
        a=a//10
    while b>0:
        bsum+=b%10
        b=b//10
    sum=asum+bsum
    if sum<minsum:
        minsum=sum
print(int(minsum))

Measured memory_bytes: 3064
#include<iostream>
#include<map>

using namespace std;

const long long MOD=1e9+7;

int main(){
    int ans=1;
    map<long long, long long> m;
    int n, a[100009];
    cin >> n;
    for(int i=0;i<n;i++)cin >> a[i];
    m[-1] = 3;
    for(int i=0;i<n;i++){
        ans = (m[a[i]-1]*ans) % MOD;
        m[a[i] - 1]--;
        m[a[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6912
n = int(input())
from collections import defaultdict
import bisect
xd0=defaultdict(list)
xd90=defaultdict(list)
xd180=defaultdict(list)
xd270=defaultdict(list)
xyd0=defaultdict(list)
xyd90=defaultdict(list)
xyd180=defaultdict(list)
xyd270=defaultdict(list)

def rotate(x,y,u):
    if u=='U': u0='R'
    elif u=='R': u0='D'
    elif u=='D': u0='L'
    else: u0='U'
    x0=y
    y0=200000-x
    return x0,y0,u0

for _ in range(n):
    x,y,u=input().split()
    x,y=int(x),int(y)
    if u=='U' or u=='D':
        xd0[x].append((y,u))
    x90,y90,u90=rotate(x,y,u)
    if u90=='U' or u90=='D':
        xd90[x90].append((y90,u90))
    x180,y180,u180=rotate(x90,y90,u90)
    if u180=='U' or u180=='D':
        xd180[x180].append((y180,u180))
    x270,y270,u270=rotate(x180,y180,u180)
    if u270=='U' or u270=='D':
        xd270[x270].append((y270,u270))
    if u=='U' or u=='R':
        xyd0[x+y].append((y,u))
    if u90=='U' or u90=='R':
        xyd90[x90+y90].append((y90,u90))
    if u180=='U' or u180=='R':
        xyd180[x180+y180].append((y180,u180))
    if u270=='U' or u270=='R':
        xyd270[x270+y270].append((y270,u270))

ans=float('inf')
for i in range(4):
    if i==0:
        xd=xd0
        xyd=xyd0
    elif i==1:
        xd=xd90
        xyd=xyd90        
    elif i==2:
        xd=xd180
        xyd=xyd180
    elif i==3:
        xd=xd270
        xyd=xyd270
    for j in range(200001):
        xl=xd[j]
        nxl=len(xl)
        if nxl<=1: continue
        elif nxl>1:
            xl=sorted(xl)
            for i in range(1,nxl):
                if xl[i][1]=='D' and xl[i-1][1]=='U':
                    ans=min(ans, (xl[i][0]-xl[i-1][0])*5)
    for j in range(400001):
        xyl=xyd[j]
        nxyl=len(xyl)
        if nxyl<=1: continue
        elif nxyl>1:
            xyl=sorted(xyl)
            for i in range(1,nxyl):
                if xyl[i][1]=='R' and xyl[i-1][1]=='U':
                    ans=min(ans, (xyl[i][0]-xyl[i-1][0])*10)            

if ans!=float('inf'):
    print(ans)
else:
    print('SAFE')

Measured memory_bytes: 419852
while True:
    n = int(input())
    if n==0 : break

    a = []
    for i in range(n):
        a.append(int(input()))

    maxp = -100001
    maxcont = -100001
    for i in range(n):
        maxcont = max(a[i], maxcont + a[i])
        maxp = max(maxp, maxcont)

    print(maxp)

Measured memory_bytes: 7544
def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N, S = [int(x) for x in input().strip().split()]
    An = [int(x) for x in input().strip().split()]
    dp = np.zeros((S+1), dtype=int)
    dp[0] = 2
    if An[0] <= S:
        dp[An[0]] = 1

    for n in range(1, N):
        dp *= 2
        dp[An[n]:] += dp[:-An[n]] // 2
        dp %= 998244353

    print(dp[S])
                
if __name__ == '__main__':
    main()

Measured memory_bytes: 27380
#include "bits/stdc++.h"
using namespace std;


int main() {

        int n, m; scanf("%d %d", &n, &m);

        int sq = sqrt(m);

        vector<int > v;
        for(int i = 1; i < sq + 5; i++) {
                if( m % i ) continue;
                int d = m / i ;
                if( d >= n ) v.push_back(i);

                if( i >= n ) v.push_back(d);
        }

        int ans = *max_element( v.begin(), v.end() );

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

        return 0;
}


Measured memory_bytes: 256
def solve():
    N, x = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    ans = 0
    for i in range(N - 1):
        sumvalue = A[i] + A[i + 1]
        if sumvalue <= x:
            continue
        if i + 1 == N - 1:
            A[i + 1] -= sumvalue - x
        else:
            if A[i + 1] < sumvalue - x:
                A[i] -= sumvalue - x - A[i + 1]
                A[i + 1] = 0
            else:
                A[i + 1] -= sumvalue - x
        ans += sumvalue - x
    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 85620
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
	int n;
  cin >> n;
  vector<int> swim(n);
  vector<int> bug(n);
  vector<int> home(n);
  for(int i= 0; i<n; i++)
  {
    cin >> swim[i]>>bug[i]>>home[i];
  }
  vector<vector<int> > dp(n,vector<int>(3,0));
  dp[0][0] = swim[0];
  dp[0][1] = bug[0];
  dp[0][2] = home[0];
  for(int i = 1; i<n; i++)
  {
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+swim[i];
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+bug[i];
    dp[i][2] = max(dp[i-1][1],dp[i-1][0])+home[i];
  }
  
  cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<"\n";
}

Measured memory_bytes: 6912