akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  string S;
  cin >> S;
  ll N = S.length();
  ll half = (N-1)/2;

  string ans = "Yes";
  rep(i, N) if(S[i] != S[N-i-1]) ans = "No";
  rep(i, half) if(S[i] != S[half-i-1]) ans = "No";
  rep(i, half) if(S[half+i+1] != S[half*2-i]) ans = "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x)	make_pair(x);
    
#define debug(x) 		cerr << #x << '=' << x << endl;
#define debug2(x, y)	cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a)		cerr << #a << ": "; for (auto x: a) cerr << x << ' '; cerr << endl;
#define debugm(a) 		cerr << #a << ":\n"; \
						for (auto v: a) { for(auto x: v) cout << x << ' '; cerr << "\n"; }
 
#define int long long
 
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;
 
const int INF  = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 1000000007;

const int N = 15;

vvi T;
vvi X;

int32_t main()
{
	int n;
	cin >> n;
	T.resize(n);
	X.resize(n);
	
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		int x, y;
		for (int j = 0; j < a; j++) {
			cin >> x >> y;
			x--;
			T[i].push_back(x);
			X[i].push_back(y);
		}
	}
	int res = 0;
	for (int i = 0; i < (1 << n); i++) {
		int cnt = 0;
		vi a;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				a.push_back(1);
				cnt++;
			} else {
				a.push_back(0);
			}
		}
		bool ok = true;
		for (int j = 0; j < n; j++) {
			if (a[j] == 1) {
				for (int k = 0; k < (int)T[j].size(); k++) {
					if (a[T[j][k]] != X[j][k]) {
						ok = false;
					}
				}
			}
		}
		if (ok)
			res = max(res, cnt);
	}
	cout << res << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined 


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

int main(){

    int n,m,x,y;
    cin >> n>> m >> x >> y;

    vector<int> a(n),b(m);

    rep(i,n) cin >> a[i];

    sort(a.begin(),a.end());

    rep(i,m) cin >> b[i];

    sort(b.begin(),b.end());

    if(a.back()<b[0]&&a.back()<y&&b[0]>x){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }

    return 0;
}

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  unsigned long long ull;

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}

template<typename U>
void pprint(U a){
    cout<<a<<" ";
}


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

    string s,t;
    cin >> s>>t;

    int ans = t.size();
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int diff = 0;
        rep(k,t.size()){
            if(s[i+k] != t[k]){
                diff++;
            }
        }
        ans = min(diff,ans);
    }

    fin(ans);
    return 0;
}




Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

int main() {
    int n,k;
    cin>>n>>k;
    int v[50];
    rep(i,n) cin>>v[i];

    int ans=0;
    rep(l,n+1){
        rep(r,n+1){
            if(n<l+r) continue;
            int rest=k-(l+r);
            if(rest<0) continue;

            vector<int> has;
            rep(i,l) has.push_back(v[i]);
            rep(i,r) has.push_back(v[n-1-i]);
            sort(all(has));

            int nn=has.size();
            int sm=0;
            for(auto e : has) sm+=e;
            rep(i,min(rest,nn)){
                if(0<has[i]) break;
                sm-=has[i];
            }
            ans=max(ans,sm);
        }
    }

    cout<<ans<<endl;
}

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

int main(){
    int n;
    int x;
    cin >> n >> x;
    int m[n];
    int ans = n;
    int min = 1000000000;
    for(int i=0;i<n;i++){
        cin >>m[i];
        x -= m[i];
        if(min>m[i]){
            min = m[i];
        }
    }
    ans += x/min;
    cout << ans << endl;
    return 0;

}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  string S;
  int Q;
  cin >> S >> Q;
  deque<char> ans;
  for (int i = 0; i < S.size(); i++) {
    ans.push_back(S[i]);
  }
  bool flag = false;
  for (int i = 0; i < Q; i++) {
    int T;
    cin >> T;
    if (T == 1) {
      flag = !flag;
    } else {
      int F;
      char C;
      cin >> F >> C;
      if (F == 1) {
        if (flag)
          ans.push_back(C);
        else
          ans.push_front(C);
      } else {
        if (flag)
          ans.push_front(C);
        else
          ans.push_back(C);
      }
    }
  }

  if (flag) {
    for (int i = ans.size() - 1; i >= 0; i--) {
      cout << ans[i];
    }
  } else {
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i];
    }
  }
  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}

Measured memory_bytes: 976
sc = input().split()
r = int(sc[0])
c = int(sc[1])
a = [[0 for i in range(c + 1)] for j in range(r + 1)]

for i in range(r):
    sc = input().split()
    for j in range(c):
        a[i][j] = int(sc[j])
for i in range(r):
    for j in range(c):
        a[i][c] += a[i][j]

for i in range(c + 1):
    for j in range(r):
        a[r][i] += a[j][i]

for i in range(r + 1):
    for j in range(c + 1):
        if j == 0:
            print(a[i][j], end = '')
        else:
            print(' {}'.format(a[i][j]), end = '')
    print('')


Measured memory_bytes: 6184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
 
int _;

//========================================================================
vector<ll>ve;
//========================================================================
int main()
{
    // ll temp=1,tem=0;
    // for(int i=1;i<=11;i++)
    // {
    //     temp*=26;
    //     ve.push_back(temp+tem);
    //     tem=temp+tem;
    // }
    // for(int i=0;i<11;i++) printf("%lld ",ve[i]);
    ll n,cnt=0;
    scanf("%lld",&n);
    // while(n>0)
    // {
    //     n-=ve[cnt];
    //     cnt++;
    // }
    // printf("%d\n",cnt);
    // n+=ve[cnt-1];
    ll k=n,num=0;
    string ans;
    while(k/26>0) 
    {
        if(k%26==0) ans+='z',k-=26;
        else ans+=k%26+'a'-1,k-=k%26;
        k/=26;
    }
    if(k%26==0) ;
    else ans+=k%26+'a'-1,k-=k%26;
    int l=ans.size();
    for(int i=l-1;i>=0;i--) 
    {
        printf("%c",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3

N, M = map(int, input().split())
from fractions import gcd

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def main():
    x = M // N
    divisors = sorted(make_divisors(M))
    ok = 0
    ng = len(divisors) - 1
    if divisors[ng] <= x:
        print(divisors[ng])
        exit()
    while ok + 1 < ng:
        c = (ok + ng) // 2
        if divisors[c] <= x:
            ok = c
        else:
            ng = c
    print(divisors[ok])

if __name__ == "__main__":
    main()


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

int main()
{
    int frr[30]={0};
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {

        int k=s[i]-'a';
        frr[k]++;
    }

   //for(int i=0;i<30;i++)cout<<frr[i]<<" ";cout<<endl;

    for(int i=0;i<30;i++)
    {
        if(frr[i]%2!=0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

using namespace std;

int main()
{
    int k, n, m, t, z, big=0;
    vector<int> S;
    cin>>k>>n;
    cin>>m>>t;
    S.push_back(t-m);
    big=t-m;
    z=m;
    int i;
    for(i=1; i<n-1;i++)
    {
        m=t;
        cin>>t;
        S.push_back(t-m);
        big=max(big,S[i]);
    }
    S.push_back(k-t+z);
    big=max(big,S[i]);
    cout<<k-big;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define FR first
#define SE second

using namespace std;

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

pr a[200005],num[100005];
bool vis[100005];

int main() {
  int n;
  scanf("%d",&n);
  ll s1=0,s2=0;
  for(int i=1;i<=n;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	a[2*i-1]=pr(x,i);
  	a[2*i]=pr(y,i);
  	s1+=x;s2+=y;
  	num[i]=pr(x,y);
  }
  sort(a+1,a+2*n+1);
  ll s=0;
  bool ok=0;
  for(int i=1;i<=n;i++) {
  	s+=a[i].FR;
    if (!vis[a[i].SE]) vis[a[i].SE]=1;
    else ok=1;
  }
  if (ok) {
  	printf("%lld\n",s);
  	return 0;
  }
  ll ans=min(s1,s2);
  for(int i=1;i<=n;i++) {
  	int x=a[i].SE;
  	ans=min(ans,s-a[i].FR+num[x].FR+num[x].SE-((i==n)?a[n-1].FR:a[n].FR));
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

auto input(size_t n) {
    return InputType2(n);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

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

int main() {
    string s = input();
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int a, b, c, ans=10000;
	cin >> a >> b >> c;
	ans=min(ans, abs(a-b)+abs(b-c));
	ans=min(ans, abs(a-c)+abs(c-b));
	ans=min(ans, abs(b-a)+abs(a-c));
	ans=min(ans, abs(b-c)+abs(c-a));
	ans=min(ans, abs(c-a)+abs(a-b));
	ans=min(ans, abs(c-b)+abs(b-a));
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    string s;
    cin >> s;
    int c = 0;
    ll ans = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'W') {
            ans += (ll)(i - c);
            c++;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 720
from collections import defaultdict

N=int(input())
A=[int(x) for x in input().split()]

d=defaultdict(int)

for a in A:
  d[a-1]+=1
  d[a]+=1
  d[a+1]+=1

ans=sorted(d.items(),key = lambda x:-x[1])

v,c=ans[0]
print(c)

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

#include <math.h>
#include <stdlib.h>


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

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; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, t; cin >> n >> t;
    ll ans = 0;
    ll s; cin >> s;
    ll e = s + t;
    for(int i = 1; i < n; i++){
        int tn; cin >> tn;
        if(tn < e) e = tn+t;
        else{
            ans += e-s;
            s = tn;
            e = tn+t;
        }
    }

    ans += e-s;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

N, Q = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0, -1)

print(*ans)


Measured memory_bytes: 230960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
struct Edge { int from, to; long long cost; };
using Graph = vector<vector<Edge>>;

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

    int n;
    while(cin>>n&&n){
        int ti[24*60*60*2]={};
        for(int i=0;i<n;i++){
            int t=0;
            string s;
            cin>>s;
            t+=(s[0]-'0')*10*60*60;
            t+=(s[1]-'0')*60*60;
            t+=(s[3]-'0')*10*60;
            t+=(s[4]-'0')*60;
            t+=(s[6]-'0')*10;
            t+=(s[7]-'0');
            ti[t]++;
            t=0;
            cin>>s;
            t+=(s[0]-'0')*10*60*60;
            t+=(s[1]-'0')*60*60;
            t+=(s[3]-'0')*10*60;
            t+=(s[4]-'0')*60;
            t+=(s[6]-'0')*10;
            t+=(s[7]-'0');
            ti[t]--;
        }
        int ans=ti[0];
        for(int i=1;i<=24*60*60;i++){
            ti[i]+=ti[i-1];
            ans=max(ans,ti[i]);
        }
        cout<<ans<<endl;
    }
}


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

int main(){
  ll N;cin>>N;
  ll cnt;
  ll k=0,m=0;
  rep(i,N){
    ll a;cin>>a;
    if(a%4==0) k++;
    else if(a%2==0) m++;
  }
  if(2*k+m+1>N || (2*k+m+1==N)&&m%2==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	vector<int> B(M);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	vector<vector<int> > dp(N + 1, vector<int>(M + 1, 0));


	for (int i = 0; i <= N; i++) {
		dp[i][0] = 1;
	}
	for (int i = 0; i <= M; i++) {
		dp[0][i] = 1;
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			if (A[i - 1] != B[j - 1]) {
				dp[i][j] -= dp[i - 1][j - 1];
			}
			dp[i][j] = (dp[i][j] + MOD) % MOD;
		}
	}
	cout << dp[N][M] << endl;
}


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

int main()
{
    int n, l;

    cin >> n >> l;

    vector < string > a;

    while(n--){
        string s;

        cin >> s;

        a.push_back(s);
    }

    sort(a.begin(), a.end());

    for(int i = 0; i < a.size(); i++) cout << a[i];

    cout << endl;

    return 0;
}


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

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N-1);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    rep(i, N-1) cin >> c[i];

    int ans = 0;
    int pre_num = N+1;
    rep(i, N){
        int num = a[i]-1;
        ans += b[num];
        if(pre_num + 1 == num) ans += c[pre_num];
        pre_num = num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define M 1000000007
typedef long long int ll;
#define INF 1000000000000000
int main()
{
    int n;
    cin>>n;
    double p[n];
    int i,j;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
    }
    double dp[n+1][n+1];
    memset(dp,0.0,sizeof(dp));
    dp[1][1]=p[0];
    dp[1][0]=1-p[0];
    for(i=2;i<=n;i++)
    {
        dp[i][0]=(dp[i-1][0])*(1-p[i-1]);
        for(j=1;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
        }
    }
    int pt=(n/2);
    double ans=0.0;
    for(i=pt+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<fixed<<ans;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N;
    cin >> N;
    vector<ld> v(N);
    for (auto &x : v) cin >> x;
    sort(ALL(v));
    ld tmp = 2;
    ld ans = (v[0] + v[1]) / tmp;
    FOR(i, 2, v.size()) {
        ans = (ans + v[i]) / tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    [$( $x:tt : $t:ty ),+] => {
        //declare variables
        $( let $x: $t; )+
        {
            use std::str::FromStr;
            // read
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            #[allow(deprecated)]
            let mut splits = buf.trim_right().split_whitespace();
            // assign each variable
            $(
                $x = splits.next().and_then(|s| <$t>::from_str(s).ok()).unwrap();
            )+
            // all strs should be used for assignment
            assert!(splits.next().is_none());
        }
    };
}

fn main() {
    parse_line![len: usize];
    parse_line![s: String];

    if s.len() <= len {
        println!("{}", s);
    } else {
        println!("{}...", &s[..len]);
    }
}


Measured memory_bytes: 2092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
int n,a,b;
int tmp,tmp2;
int main(){
    cin >> n >> a >> b;
    vector<ll> x(n-1,0);//町iからi+1間での最短距離
    ll distance;
    ll ans = 0;
    
    cin >> tmp;
    for(int i = 0; i < n-1; i++){ 
        cin >> tmp2;
        distance = tmp2-tmp;
        tmp = tmp2;
        if(distance * a > b) x[i] = b;
        else x[i] = distance * a;
    }

    for(auto e : x) ans += e;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
import Data.List
import Control.Monad
import Control.Applicative
main = do
    lst <- replicateM 10 (readLn :: IO Int)
    print $ (take 3 $ reverse $ sort lst)!!0
    print $ (take 3 $ reverse $ sort lst)!!1
    print $ (take 3 $ reverse $ sort lst)!!2

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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;}

int main () {
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for (auto p : mp) {
    chmax(mx,p.se);
  }
  for (auto p : mp) {
    if (p.se == mx) {
      cout << p.fi << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 25216
N, M, C = map(int, input().split())
b = list(map(int, input().split()))
rst = 0

for _ in range(N):
  a = list(map(int, input().split()))
  c = 0
  for i in range(M):
    c += a[i] * b[i]
  if c + C > 0:
    rst += 1
      
print(rst)

Measured memory_bytes: 3060
H,W=map(int,input().split())
MAP=[["#"]*(W+2)] + [["#"]+list(input())+["#"] for i in range(H)] + [["#"]*(W+2)]
white=0
for line in MAP:
    white+=line.count('.')
from collections import deque
check=deque([(1,1,1)])
dist=float('inf')
while len(check)>0:
    d,x,y=check.popleft()
    for i,j in [(-1,0),(1,0),(0,1),(0,-1)]:
        if MAP[x+i][y+j]==".":
            if x+i==H and y+j==W:
                dist=d+1
                check=[]
                break
            check.append((d+1,x+i,y+j))
            MAP[x+i][y+j]="#"
if dist>10**10:
    print(-1)
else:
    print(white-dist)

Measured memory_bytes: 3444
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int roundup(int n){
  return (n+9)/10*10;
}

bool comp(int a, int b){
  return (a+9)%10<(b+9)%10;
}

int main(){
  int a[5];
  REP(i,5) cin >> a[i];
  sort(a,a+5,comp);
  int ans = 0;
  ans += a[0];
  REP(i,4) ans += roundup(a[i+1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto X = lread();
    auto a = X == 7 || X == 5 || X == 3;
    writeln(a ? "YES" : "NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define rep( i, a, n ) for( ll i=a; i<n; i++ )
#define repp( i, a, n, p ) for( ll i=a; i<n; i+=p )
#define per( i, a, n ) for( ll i=n-1; i>=a; i-- )
#define size 1000001

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

  ll sum =0;
  rep ( i, 0, n+1 ){ 
    if ( i %3 and i % 5 ) {
      sum += i;
    }
  }
  cout << sum << endl;
}


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

const int maxn = 109;
int a[maxn*maxn], c[maxn][maxn];
int H, W, n, x, y;

int main(){
	scanf("%d%d%d", &H, &W, &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	x = 1; y = 1;
	for (int i=1; i<=n; i++)
		while (a[i]--){
			c[x][y] = i;
			if (y&1) { x++; if (x == H+1) { x = H; y++; } }
			else { x--; if (x == 0) { x = 1; y++; } }
		}
	for (int i=1; i<=H; i++){
		for (int j=1; j<=W; j++)
			printf("%d ", c[i][j]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;
	double s=v-w,p=abs(a-b);
	if(s<=0){
	    cout<<"NO";
	}
	else
	if(p/s-t<=0){
	    cout<<"YES";
	}
	else cout<<"NO";
}


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

int main(void){
    int i,a,N,hiku=0,cnt=0;
    int number[100000]={0};
    cin >> N;
    for(i=0;i<N;i++){
        cin >> a;
        number[a-1]++;
    }
    for(i=0;i<100000;i++){
        if(number[i]>=3){
            //hiku+=(number[i]/3)*2;
            //number[i]=number[i]/3+number[i]%3;
            while(1){
                hiku+=2;
                number[i]=number[i]-2;
                if(number[i]<3) break;
            }
        }
    }
    for(i=0;i<100000;i++){
        if(number[i]==2) cnt++;
    }

    cout << N-hiku-(cnt/2)*2-cnt%2*2 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int h,w; cin >>h >>w;
  vector<string> vs(h);
  rep(i,h) cin >>vs[i];
  vector<int> cnt(26,0);
  rep(i,h) rep(j,w) cnt[vs[i][j]-'a']++;
  if(df)print(cnt);
  vector<int> md(4,0);
  rep(i,26){
    md[cnt[i]%4]++;
  }
  if(df)print(md);
  int flag=(md[1]+md[3]<=1),border=h%2*w/2+w%2*h/2;
  if(md[2]+md[3]>border) flag=0;
  yn(flag);
}


Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int n;
char s[305][305];

bool check(int p, int q) {
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (s[(p + i) % n][(q + j) % n] != s[(p + j) % n][(q + i) % n])
                return false;
        }
    }
    return true;
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++) cin >> s[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += check(i, 0) * n;
    }
    cout << ans << endl;

}

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

int gcd(int x, int y) {
  while(y > 0) {
    int r = x % y; x = y; y = r;
  }
  return x;
}

int main() {
  int N, X; cin >> N >> X;
  vector<int> xx(N);
  for (int i = 0; i < N; i++) {
    cin >> xx.at(i);
    xx.at(i) -= X;
    xx.at(i) = abs(xx.at(i));
  }
  
  sort(xx.begin(), xx.end());
  
  int D = xx.at(0);
  for (int i = 1; i < N && D != 1; i++)
    D = gcd(D, xx.at(i));
    
  cout << D << endl;
}

Measured memory_bytes: 640
n = int(input())
a = [int(i) for i in input().split()]
text = 0
for j in range(n):
    if a[j] % 2 == 0:
        if a[j] % 3 != 0 and a[j] % 5 != 0:
            text = 1
            print("DENIED")
            break
if text == 0:
    print("APPROVED")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>

using namespace std;

long long a,b,n,k,ans;

int main()
{
  scanf("%lld%lld",&n,&k);
  if (k==0) {
  	cout<<n*n;
  	return 0;
  }
  for (int i=k+1;i<=n;i++)
  {
  	ans+=(n/i)*(i-k)+max((n%i-k+1),(long long)0);
  }
  cout<<ans;
  return 0;
}


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

int main(){

  while(1) {
    int n,m;
    cin >> n >> m;
    if(n==0 && m == 0) break;
    bool flg[3][501][501] ={}; //xy,yz,xz;
    int ans = -n*m;
    for(int j=0;j<m;j++) {
      string str;
      int a,b;
      cin >> str >> a >> b;
      if(str == "xy") {
	for(int i=1;i<=n;i++)
	  if(flg[1][a][i] == 1) ans++;
	  else if(flg[2][b][i] == 1) ans++;
	flg[0][a][b]=1;
      }

      else if(str=="xz") {
	for(int i=1;i<=n;i++)
	  if(flg[0][a][i] == 1) ans++;
	  else if(flg[2][i][b] == 1) ans++;
	flg[1][a][b] = 1;
      }
      else if(str=="yz") {
	for(int i=1;i<=n;i++)
	  if(flg[0][i][a] == 1) ans++;
	  else if(flg[1][i][b] == 1) ans++;
	flg[2][a][b]=1;
      }
    }
    cout << n*n*n+ans <<endl;
  }

  return 0;
}

Measured memory_bytes: 1952
s = gets.chomp

2.upto(3).each do |i|
  i.times do |j|
    s[j..-1].chars.each_slice(i) do |t|
      if t[0] == t[i-1]
          puts "#{s.index(t.join)+1} #{s.index(t.join)+i}"
          exit
      end
    end
  end
end

puts "-1 -1"

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

vector<vector<int>> g;
vector<int> ans;
vector<bool> visited;

void dfs(int now) {
    visited.at(now) = true;
    for (int next : g.at(now)) {
        if (!visited.at(next)) {
            ans.at(next) += ans.at(now);
            dfs(next);
        }
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    g.resize(n);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }

    ans.resize(n);
    visited.resize(n, false);
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans.at(p) += x;
    }
    dfs(0);
    rep(i,n) cout << ans.at(i) << endl;
    return 0;
}

Measured memory_bytes: 24324
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

vector<int> color;
vector<vector<int> > g;
void is_bipartite(int x){
	if(color[x] == 0){
		for(int i = 0; i < g[x].size(); i++){
			if(color[g[x][i]]<0){
				color[g[x][i]] = 1;
				is_bipartite(g[x][i]);
			}
		}
	}else{
		for(int i = 0; i < g[x].size(); i++){
			if(color[g[x][i]]<0){
				color[g[x][i]] = 0;
				is_bipartite(g[x][i]);
			}
		}
	}
}

int main()
{
	ll n,m;
	cin>>n>>m;
	g.resize(n,vector<int>());
	for(int i = 0; i < m; i++){
		int a,b;
		cin>>a>>b;
		g[a-1].push_back(b-1);
		g[b-1].push_back(a-1);
	}
	color.resize(n,-1);
	color[0] = 0;
	is_bipartite(0);
	bool flag = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < g[i].size(); j++){
			if(color[i] == color[g[i][j]]) flag = false;
		}
	}
	if(flag){
		ll left = 0,right = 0;
		for(int i = 0; i < n; i++){
			if(color[i]==0) left++;
			else if(color[i]==1) right++;
		}

	// 	for(int i = 0; i < n; i++){
	// 	cout << i << " " <<  color[i] << endl;
	// }

		// int cnt = 0;
		// for(int i = 0; i < n; i++){
		// 	if(color[i] == 0){
		// 		cnt += right - g[i].size();
		// 	}
		// }
		// cout << left << " " << right << endl;
		cout << left*right - m  <<endl;
	}else{
		// cout << "non-bipartite" << endl;
		cout << n*(n-1)/2 - m << endl;
	}


	return 0;
}

Measured memory_bytes: 6400
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, Count[100005];
int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    int A; cin >> A; Count[A]++;
  }
  
  int cnt = 0;
  for (int i = 0; i < 100005; i++){
    if (Count[i]) cnt += Count[i] - 1;
  }
  if (cnt % 2 != 0) cnt++;
  cout << N - cnt << endl;

  return 0;
}


Measured memory_bytes: 640
main = do
  li <- getLine
  let n = read li
  li <- getLine
  let ds = map read $ words li
  print $ compute n ds

{-
d1 * d2 + d1 * d3 + ... + d1 * dn = d1 * (d2 + ... + dn)
          d2 * d3 + ... + d2 * dn = d2 * (d3 + ... + dn)
逆の方がいいかな。
0 * d1 +
(d1) * d2 +
(d1 + d2) * d3 + ...
-}
compute :: Int -> [Int] -> Int
compute n ds = sum $ zipWith (*) ds $ scanl (+) 0 ds


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008
const int MOD = 1e9 + 7;


signed main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<vector<pair<int, int>>>  vp(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
    for (int j=0; j<a[i]; j++){
      int x, y;
      cin >> x >> y;
      x--;
      vp[i].emplace_back(x, y);
    }
  }

  int ans = 0;
  for (int bit=0; bit < (1 << n); bit++){
    int tmp = 0;
    vector<int> S;
    bool flag = true;
    for (int i=0; i<n;i++){
      if(bit & (1 << i)){
        for (int j=0; j<vp[i].size(); j++){
          if (((bit >> (vp[i][j].first) & 1)) ^ vp[i][j].second){
          //   cout << bit << endl;
          //   cout << i << " " << j << " " << vp[i][j].first << vp[i][j].second << endl;
            flag = false;
          }
        }
      }
    }
    if (flag) ans = max(ans, __builtin_popcount(bit));
  }

  // cout << (5 & (1 << 1)) << endl;
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
typedef long long int lld;
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define Error(x) cout<< #x << " = " << (x) <<endl;
#define Error2(a,b) cout<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cout<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll
 
typedef pair<lld,lld> PA;
 
lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}
 
bool bitSet(lld n,lld i){
    if((n&(1LL<<i))!=0) return true;
    else return false;
}
 
lld findGcd(lld a,lld b){
    if(a==0) return b;
    else return findGcd(b%a,a);
}
 
#define lim 500010
#define lim2 200003
#define qqqqqq 210
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];
// vector<lld> V[lim];
// int X[lim],Y[lim],C[lim];
// string S[lim];
lld A[lim],B[lim];
// map<lld,lld> M;

int main(){
    lld T,i,n,m,p,j,l,e,r,b,c,k,q,a,d,w,x,y,v,z,t,curr,prev,sum,ans,pos,val,countA,indicator;
    sc(n);
    rep(i,0,n-1) sc(A[i]);
    if(n&1){
        B[n/2] = A[0];
        i = n/2 + 1;
        j = n/2 - 1;
        x = 1;
    }
    else{
        i = n/2;
        j = n/2 - 1;
        x = 0;
    }
    while(x<n){
        // Error4(x,i,j,A[x]);
        // Error(A[x+1]);
        B[i++] = A[x++];
        B[j--] = A[x++];
    }
    // if(n&1) repD(i,n-1,0) prS(B[i]);
    // else 
        rep(i,0,n-1) prS(B[i]);
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
using namespace std;
int main(){
int w,h,x,y,r;
cin >>w>>h>>x>>y>>r;
if(x+r<=w && x-r>=0 && y+r<=h && y-r>=0){
cout <<"Yes"<<endl;
}else{
cout <<"No"<<endl;
}
return 0;
}



Measured memory_bytes: 3080
n = gets.split.map(&:to_i)
bam = Array.new(n[0],0)
n[0].times {|i| bam[i] = gets.to_i}
bam.sort!
ans = 10**10
use = Array.new(n[0],-1)
for i in 1..4**n[0]
  check = [0,0,0]
  leng = [0,0,0]
  mp = 0
  for j in 0..n[0]-1
    if use[j] != -1
      check[use[j]] += 1
      leng[use[j]] += bam[j]
    end
  end
  for j in 0..2
    if check[j] > 1
      mp += 10*(check[j]-1)
    end
  end
  for j in 0..2
    mp += (n[j+1] - leng[j]).abs
  end
  if check[0] != 0 && check[1] != 0 && check[2] != 0 && ans > mp
    ans = mp
  end
  use[0] += 1
  for j in 0..n[0]-2
    if use[j] == 3
      use[j+1] += 1
      use[j] = -1
    end
  end
  if use[-1] == 3
    break
  end
end
puts ans


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

int gcd(int a, int b){
  if(a % b == 0) return b;
  return gcd(b, a % b);
}
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
  for(int a = 1; a <= N; a++){
    for(int b = 1; b <= N; b++){
      for(int c = 1; c <= N; c++){
        sum += gcd(gcd(a,b), c);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
   
int m[101][101];
int p[101];
int length;
   
void MCO(){
  int n,i,l,q,j,k;
   
  n = length;
   
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
   
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = 9999999;
      for(k = i; k <= j-1; k++){
    q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
    m[i][j] = min(m[i][j],q);
      }
    }
  }
}
   
int min(int A,int B){
  if(A > B){
    return B;
  }else{
    return A;
  }
}
   
int main(){
  int i;
   
  scanf("%d",&length);
  for(i = 0; i < length; i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }
   
  MCO();
  printf("%d\n",m[1][length]);
   
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = (ll) 1e18;
int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  for(int i=0;i<b;i++){
    if((a*i)%b==c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b) a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b) a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n - h + 1) * (n - w + 1) << '\n';
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

def find_negative_loop(n,w,es):
  dist=[float("inf")]*n
  #この始点はどこでもよい
  dist[1]=0
  
  for i in range(n):
    for j in range(w):
      e=es[j]
      if dist[e[1]]>dist[e[0]]+e[2]:
        dist[e[1]]=dist[e[0]]+e[2]
        if i==n-1:
          return True
  return False

def shortest_path(s,n,w,es):
  #s→iの最短距離
  #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト]
  dist=[float("inf")]*n
  #d[i]: s→iの最短距離
  dist[s]=0

  while True:
    update=False
    for p,q,r in es:
      # e: 辺iについて [from,to,cost]
      if dist[p]!=float("inf") and dist[q]>dist[p]+r:
        dist[q]=dist[p]+r
        update=True
    if not update:
      break
      
  return dist

graph=[[] for _ in range(N+1)]
elist=[]
for _ in range(M):
  a,b,c=map(int,input().split())
  graph[a].append(b)
  elist.append((a,b,-c))
  
#remove unnecessary vertex and edge
visited=[None]*(N+1)
def check_reachable(u):
  if u==N:
    reachable[u]=True
    return True
  
  visited[u]=True
  cnt=0
  for v in graph[u]:
    if not visited[v]:
      ret=check_reachable(v)
      if ret:        
        reachable[u]=True
        cnt+=1
        
  if cnt>0:
    return True
  else:
    return False

reachable=[None]*(N+1)
for i in range(1,N+1):
  if reachable[i]==None:
    visited=[False]*(N+1)
    check_reachable(i)
#print(reachable)
  
elist2=[]
for a,b,nc in elist:
  if reachable[b]:
    elist2.append((a,b,nc))
  
M2=len(elist2)
res1=find_negative_loop(N+1,M2,elist2)

if res1:
  print("inf")
else:
  res2=shortest_path(1,N+1,M2,elist2)
  print(-res2[N])

Measured memory_bytes: 4340
#include <iostream>
using namespace std;
 
int main() {
	int A, B, C, D, area1=0,area2=0;
scanf("%d %d %d %d\n",&A,&B,&C,&D) ;
area1=A*B;
area2=C*D;
if(area1==area2){
printf("%d\n",area1) ;
}
else if(area1>area2) {
printf("%d\n",area1) ;
} 
else {
printf("%d\n",area2) ;
} 
	return 0;
}

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

int main(){

  int N,M=0;
  cin>>N>>M;
  if(N==1 && M==0){cout<<0;return 0;}
  else if(N==2 && M==0){cout<<10; return 0;}
  else if(N==3 && M==0){cout<<100; return 0;}
  int s[M];
  int c[M];
  
  int ans[N];
  int flag[N];
  rep(i,N){ans[N]=0;flag[i]=0;}
  
  rep(i,M){
    cin>>s[i]>>c[i];
  	int index=s[i]-1;
    
    if(flag[index]==1 && c[i]!=ans[index]){cout<<-1;return 0;}
    else if(s[i]==1 && c[i]==0 && N>1){cout<<-1;return 0;}
    ans[index]=c[i];
    flag[index]=1;
  }
  
  rep(i,N){

    if(flag[i]==0){

      if(i==0)ans[i]=1;
      else ans[i]=0;
      
    }

  }
  
  rep(i,N)cout<<ans[i];
  cout<<endl;
  
}

Measured memory_bytes: 256