akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main(){
    int A,B;
    char table[100][100];
    cin >> A >> B;
    for(int y=0;y<50;y++){
        for(int x=0;x<100;x++){
            table[y][x] = '#';
        }
    }
    for(int y=50;y<100;y++){
        for(int x=0;x<100;x++){
            table[y][x] = '.';
        }
    }
    for(int y=0;y<100;y+=2){
        for(int x=0;x<100;x+=2){
            if(A<=1)    break;
             table[y][x] = '.';
            A--;
        }
    }
    for(int y=99;y>=0;y-=2){
        for(int x=0;x<100;x+=2){
            if(B<=1)    break;
            table[y][x] = '#';
            B--;
        }
    }
    cout << 100 << ' ' << 100 << endl;
    for(int y=0;y<100;y++){
        for(int x=0;x<100;x++){
            cout << table[y][x];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

int main(void) {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli input(lli n, vector<lli> &ve);
lli input(lli n, vector<lli> &ve) {
    lli val;
    for (lli i = 0; i < n; i++) {
        cin >> val;
        ve.pb(val);
    }
    return 0;
}

lli n;
vector<lli> topo;
vector<lli> vis;
vector<vector<lli>> adj;

lli dfs_go(lli val) {
    for (lli i = 0; i < adj[val].size(); i++) {
        if (vis[adj[val][i]] == 0) {
            vis[adj[val][i]] = 1;
            dfs_go(adj[val][i]);
            topo.pb(adj[val][i]);
        }
    }
}

lli dfs() {
    for (lli i = 1; i <= n; i++) {
        if (vis[i] == 0) {
            vis[i] = 1;
            dfs_go(i);
            topo.pb(i);
        }
    }
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    lli a, m, b;
    cin >> n >> m;
    vis.resize(n + 2, 0);
    adj.resize(n + 2);
    fr(i, 0, m) {
        cin >> a >> b;
        adj[a].pb(b);
    }

    vector<lli> dis(n + 2, 0);
    dfs();
    reverse(all(topo));

    for (lli i = 0; i < topo.size(); i++) {
        for (lli j = 0; j < adj[topo[i]].size(); j++) {
            dis[adj[topo[i]][j]] = max(dis[topo[i]] + 1, dis[adj[topo[i]][j]]);
        }
    }

    lli ans = -1;
    for (lli i = 1; i <= n; i++) {
        ans = max(ans, dis[i]);
    }
    cout << ans << endl;
    rt;
}

Measured memory_bytes: 9848
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	bool flag=true;
	for (int i=0; i<s.size()-1; i++)
	{
		if (s[i]==s[i+1])
		{
			flag=false;
		}
	}
	if (flag)
	{
		cout<<"Good";
		return 0;
	}
	cout<<"Bad";
	return 0;
}



Measured memory_bytes: 256
K,N = map(int, input().split())
A = list(map(int,input().split()))

if N == 2:
    print(min(A[1] - A[0] , K + A[0] - A[1]))

max_distance = 0

if N > 2:
    for i in range(N-1):
        s = A[i+1] - A[i]
        if s > max_distance:
            max_distance = s

    print(min(K-max_distance,A[N-1]-A[0]))

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

const int N = 5000;

int p[N+5];
long long a[N+5];
bool vis[N+5];

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", p+i);
    for (int i = 1; i <= n; ++i) scanf("%lld", a+i);
    long long ans = LLONG_MIN;
    for (int i = 1; i <= n; ++i){
        if (!vis[i]){
            vector<long long> vc;
            for (int j = i; !vis[j]; j = p[j]){
                vc.push_back(a[j]);
                vis[j] = true;
            }
            long long sum = 0;
            for (auto it : vc) sum += it;
            int sz = vc.size();
            long long _max = LLONG_MIN;
            int tmp = max(0, k / sz - 1), res = k - tmp * sz;
            sum = sum > 0 ? tmp * sum : 0;
            for (int st = 0; st < sz; ++st){
                long long _sum = 0;
                for (int j = st, cnt = 1; cnt <= res; j = (j+1) % sz, ++cnt){
                    _sum += vc[j];
                    _max = max(_max, _sum);
                }
            }
            ans = max(ans, _max + sum);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3928
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


int main() {
	ll n,m;
    cin>>n>>m;
    vector<ll>l(m),r(m);
    ll maxl=0,minr=100005;
    rep(i,m)cin>>l[i]>>r[i];
    rep(i,m){
        maxl=max(maxl,l[i]);
        minr=min(minr,r[i]);
    }
    ll ans=minr-maxl+1;
    if(ans<=0)ans=0;
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val A = nextIntList().sorted().joinToString("")
    println(if (A == "557") "YES" else "NO")
}

Measured memory_bytes: 37772
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  int x, n;
  cin >> x >> n;
  int tmp;
  set<int> set;
  int ans;
  rep(i, n) {
    cin >> tmp;
    set.insert(tmp);
  }
  for (int i = 0;; i++) {
    ans = x - i;
    if (!set.count(ans)) {
      cout << ans;
      return 0;
    }
    ans = x + i;
    if (!set.count(ans)) {
      cout << ans;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3656
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=405;
int f[N][N][N],g[N][N],a[N],b[N],as[N],bs[N];
int n,m;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n),m=n/3;
	fp(i,1,n)scanf("%d",&a[i]),as[a[i]]=i;
	fp(i,1,n)scanf("%d",&b[i]),bs[b[i]]=i;
	f[1][1][0]=1;
	fp(i,1,n)fp(j,1,n)fp(k,0,m)if(f[i][j][k]){
		R int ret=f[i][j][k];
		if(bs[a[i]]<=j||as[b[j]]<=i){
			if(a[i]==b[j]){
				if(k)upd(f[i+1][j+1][k-1],mul(ret,k));
				continue;
			}
			upd((bs[a[i]]<=j?f[i+1][j][k]:f[i][j+1][k]),ret);
			continue;
		}
		upd(f[i+1][j+1][k+1],ret);
		if(k){
			upd(f[i+1][j][k-1],mul(ret,k));
			upd(f[i][j+1][k-1],mul(ret,k));
			if(k>1)upd(f[i+1][j+1][k-2],P-mul(ret,k*(k-1)));
		}
	}
	R int res=0;
	fp(i,m+1,n+1)upd(res,add(f[i][n+1][0],f[n+1][i][0]));
	upd(res,P-f[n+1][n+1][0]);
	g[0][0]=1;
	fp(i,0,n-1)fp(j,0,i)if(g[i][j]){
		if(i-j<m)upd(g[i+1][j],g[i][j]);
		if(j<m*2&&(i-j)*2>j)upd(g[i+1][j+1],mul(g[i][j],(i-j)*2-j));
	}
	res=mul(res,g[n][m<<1]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll n; cin >> n;
  vector<ll> x(n); rep(i,n) cin >> x.at(i);
  vector<ll> xxx(n); rep(i,n) xxx.at(i) = x.at(i);
  sort(xxx.begin(),xxx.end());

  ll middle_small = xxx.at(n/2 - 1), middle_big = xxx.at(n/2);
  if(middle_big == middle_small) {
    rep(i,n) {
      cout << middle_big << endl;
    }
    return 0;
  }
  else {
    rep(i,n) {
      if(x.at(i) <= middle_small) {
        cout << middle_big << endl;
      }
      else {
        cout << middle_small << endl;
      }
    }
  }

  
  
}



Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
      cout.precision(10);
      cout << fixed;
   }
} iofix;


const int64_t MOD = 1e9 + 7 ;

void solve(){
     int N, K; cin >> N >> K;
     vector<int64_t >v(N);

     for(int i = 0;i < N; i++){
         cin >> v[i];
     }
     int temp = N - K , j = 0;
     for(int t = v.size() - temp ;t < v.size(); t++){
         if(v[t] > v[j++])
            cout << "Yes\n";
         else 
            cout << "No\n";
     }
}

int main(){


   	solve();

#ifndef Time
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
int main(){

//    freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
        

    int n, m; cin >> n >> m;
    cout << max(n - 2 *m, 0) << endl;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


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

int n, k;

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

  sort(p, p + n);
  int ans = 0;
  for (int i = 0; i < k; i++)
    ans += p[i];
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 3208
N, M, X = map(int, input().split())

C = [1 for i in range(N)]
A = [[0 for i in range(M)] for j in range(N)]

for i in range(N):
    input_ = list(map(int, input().split()))

    C[i], A[i] = input_[0], input_[1:]

price_min = 10 ** 9
for pattern in range(2 ** N):
    price_sum = 0
    skill_levs = [0 for i in range(N)]

    pattern = str(bin(pattern)).lstrip('0b').zfill(N)

    for idx, p in enumerate(pattern):
        if p == '1':
            price_sum += C[idx]
            skill_levs = [lev + up for lev, up in zip(A[idx], skill_levs)]
    if min(skill_levs) >= X:
        price_min = min(price_min, price_sum)

if price_min != 10 ** 9:
    print(price_min)
else:
    print('-1')

Measured memory_bytes: 9260
/*
 * written by Yaqi Zhang (zhang623@wisc.edu)
 * University of Wisconsin-Madison
 * 2020
 */
#include <bits/stdc++.h>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> lights(m);
    vector<int> ps(m);
    for(int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        int mask = 0;
        for(int j = 0; j < k; ++j) {
            int s;
            cin >> s;
            --s;
            mask |= (1 << s);
            lights[i] = mask;
        }
    }
    for(int i = 0; i < m; ++i) cin >> ps[i];
    int cnt = 0;
    for(int state = 0; state < (1 << n); ++state) {
        int valid = true;
        for(int i = 0; i < m; ++i) {
            int ons = lights[i] & state;
            if(__builtin_popcount(ons) % 2 != ps[i]) {
                valid = false;
                break;
            }
        }
        if(valid) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}



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

using namespace std;
using ll = long long;

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

int main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3644
import math

def koch_curve(p1_x,p1_y,p2_x,p2_y,c):
	s_x = (p2_x + 2*p1_x) / 3
	s_y = (p2_y + 2*p1_y) / 3
	t_x = (2*p2_x + p1_x) / 3
	t_y = (2*p2_y + p1_y) / 3
	u_x = (math.cos(math.pi/3) * ( t_x - s_x ) - math.sin(math.pi/3) * ( t_y - s_y)) + s_x
	u_y = (math.sin(math.pi/3) * ( t_x - s_x ) + math.cos(math.pi/3) * ( t_y - s_y)) + s_y
	if c > 1:
		koch_curve(p1_x,p1_y,s_x,s_y,c-1)
		koch_curve(s_x,s_y,u_x,u_y,c-1)
		koch_curve(u_x,u_y,t_x,t_y,c-1)
		koch_curve(t_x,t_y,p2_x,p2_y,c-1)
	else:
		print("%.8f %.8f" % (p1_x,p1_y))
		print("%.8f %.8f" % (s_x, s_y))
		print("%.8f %.8f" % (u_x, u_y))
		print("%.8f %.8f" % (t_x, t_y))

if __name__ == '__main__':
	n = int(input())
	if n == 0:
		print("%.8f %.8f" % (0,0))
		print("%.8f %.8f" % (100,0))
	else:
		koch_curve(0,0,100,0,n)
		print("%.8f %.8f" % (100,0))


Measured memory_bytes: 5756
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#define WTF 11

using namespace std;

int n;
int q;
int v[1<<18], w[1<<18];
vector<pair<int, int>> dp[1<<WTF];

int fxxk(int x, vector<pair<int, int>>& brute_force) {
  if (x < (1 << WTF)) {
    return x;
  }
  int l = brute_force.size();
  for (int i = 0; i < l; i++) {
    brute_force.push_back({brute_force[i].first + w[x], brute_force[i].second + v[x]});
  }
  return fxxk(x/2, brute_force);
}

void solve(int u) {
    if (!dp[u].empty()) {
      return;
    }
    if (dp[u/2].empty()) {
      solve(u/2);
    }
    vector<pair<int, int>> wtf1, wtf2;
    for (pair<int, int> pii: dp[u/2]) {
      int ww = pii.first;
      int vv = pii.second;
      wtf1.push_back(pii);
      wtf2.push_back({ww + w[u], vv + v[u]});
    }
    int i = 0;
    int j = 0;
    while (true) {
      if (i == wtf1.size() && j == wtf2.size()) {
        break;
      } else if (i == wtf1.size()) {
        dp[u].push_back(wtf2[j++]);
      } else if (j == wtf2.size()) {
        dp[u].push_back(wtf1[i++]);
      } else if (wtf1[i] < wtf2[j]) {
        dp[u].push_back(wtf1[i++]);
      } else {
        dp[u].push_back(wtf2[j++]);
      }
    }
    for (int i = 1; i < dp[u].size(); i++) {
      if (dp[u][i].second < dp[u][i-1].second) {
        dp[u][i].second = dp[u][i-1].second;
      }
    }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &v[i], &w[i]);
  }
  dp[1].push_back({0, 0});
  dp[1].push_back({w[1], v[1]});
  for (int i = 1; i <= n && i < (1 << WTF); i++) {
    solve(i);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int u, l;
    scanf("%d %d", &u, &l);
    if (u < (1 << WTF)) {
      auto it = lower_bound(dp[u].begin(), dp[u].end(), make_pair(l+1, 0));
      if (it == dp[u].begin()) {
        printf("0\n");
      } else {
        printf("%d\n", (--it) -> second);
      }
    } else {
      vector<pair<int, int>> brute_force;
      brute_force.push_back({0, 0});
      brute_force.push_back({w[u], v[u]});
      int k = fxxk(u/2, brute_force);
      sort(brute_force.begin(), brute_force.end(), [] (auto x, auto y) {
        if (x.first == y.first) {
          return y.second < x.second;
        } else {
          return x.first < y.first;
        }
      });
      for (int j = 1; j < brute_force.size(); j++) {
        if (brute_force[j].second < brute_force[j-1].second) {
          brute_force[j].second = brute_force[j-1].second;
        }
      }
      auto it1 = dp[k].rbegin();
      auto it2 = brute_force.begin();
      int ans = 0;
      while(it1 != dp[k].rend() && it2 != brute_force.end()) {
        if (it1 -> first + it2 -> first > l) {
          ++it1;
        } else {
          ans = max(ans, it1 -> second + it2 -> second);
          ++it2;
        }
      }
      printf("%d\n", ans);
    }
  }
}


Measured memory_bytes: 27024
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k = 0;
	cin >> k;
	if (!(k & 1) || (k % 5 == 0))
	{
		cout << "-1" << endl; return 0;
	}
	int p = 7 % k, ct = 1;
	while (p)
	{
		++ct; p = (p * 10 + 7) % k;
	}
	cout << ct << endl;
}

Measured memory_bytes: 3652
n,A,B,C=map(int,input().split())
bam=[]
for i in range(n):
    bam.append(int(input()))
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == n: #curは０スタートだから、cur=nのときにはｎ本の竹の使い道が決まっている。
        #print(str(cur)+" "+str(a)+" "+str(b)+" "+str(c))
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF 
        #-30する理由は、２本の竹を使うときに20mpで合体してる。本当は、10mpでいいのに。
        #min(a, b, c) > 0 この条件は、A,B,Cどれにも最低一本は木を使わないといけないから
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + bam[cur], b, c) + 10 #Aにcur番目の竹を使う　使うときに10mp使っておく。
    ret2 = dfs(cur + 1, a, b + bam[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + bam[cur]) + 10
    #print(min(ret0, ret1, ret2, ret3))
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c;
string s, t;

int main()
{
	cin >> a;
	
  if(a==1)
    cout << "Hello World" << endl;
  else
   { cin >> b >> c;
  cout<<b+c<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/* #include <atcoder/all> */
#include <iostream>
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if (t1*a1 + t2*a2 < t1*b1 + t2*b2) {
        swap(a1,b1);
        swap(a2,b2);
    } else if (t1*a1 + t2*a2 == t1*b1 + t2*b2) {
        cout << "infinity" << endl;
        return;
    } 
    if (t1*a1 > t1*b1) {
        cout << 0 << endl;
        return;
    } else {
        ll dist_mid = t1*b1 - t1*a1, dist_en = t1*a1 + t2*a2 - (t1*b1 + t2*b2);
        if (dist_mid % dist_en == 0) {
            cout << 2LL * (dist_mid / dist_en) << endl;
        } else {
            cout << 1LL + 2LL*(dist_mid / dist_en) << endl;
        }
        return;
    }
}


int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 3540
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define all(a) a.begin(),a.end()
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

int main(){
    IOS;
    make(ll,n);
    ll a=n%10;
    if(a==3) cout<<"bon"<<endl;
    else if(a==0 || a==1 || a==6 || a==8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;


    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 15
using namespace std;
int main() {
  int n,t;
  cin >> n >> t;
  int a, b;
  int min=1005;
  for(int i=0;i<n;i++) {
    cin >> a >> b;
    if(min>a && t>=b) {
      min=a;
    }
  }
  if(min==1005) cout << "TLE" << endl;
  else cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	int C = sc.nextInt();
      	
      	boolean judge = false;
      	for(int i = 1; i * A <= A * B; i++){
          if((i * A) % B == C){
            judge = true;
            break;
          }
        }
      	if(judge){
        	System.out.println("YES");
        }else{
        	System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21716
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
bool valid(LL A,LL B,LL C,LL D){
    if(D<B)return 0;
    REP(i,100){
        if(A<B)return 0;
        LL need=max(1LL,(A-C+B-1)/B);
        A-=need*B;
        if(A<0)return 0;
        A+=D;
    }
    if(C>=B&&D>=B)return 1;
    if(B==D)return 1;
    LL gg=__gcd(D,B);
    A+=(C-A)/gg*gg;
    while(A<=C)A+=gg;
    return A>=B;
}
int main(){
    CASET{
        LL A,B,C,D;
        R(A,B,C,D);
        if(valid(A,B,C,D))W("Yes");
        else W("No");
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    from collections import defaultdict
    from heapq import heappush, heappop
    _, m, *ab = map(int, open(0).read().split())
    works = defaultdict(list)
    # == zip(ab[0::2], ab[1::2])
    for a, b in zip(*[iter(ab)]*2):
        # 最大値が欲しいが、heappopは最小値を取り出すので-1倍しておく
        works[a].append(-b)

    # candidates, pay = [], []
    # for day in range(1, m+1):
    #     for x in works[day]:
    #         heappush(candidates, x)
    #     if candidates:
    #         pay.append(heappop(candidates))
    # print(-sum(pay))

    # こっちの方が遅い
    candidates, pay = [], 0
    for day in range(1, m+1):
        for x in works[day]:
            heappush(candidates, x)
        if candidates:
            pay += heappop(candidates)
    print(-pay)


if __name__ == "__main__":
    main()


Measured memory_bytes: 35552
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector>
//const int maxn = 1e5+5;
#define ll long long
#define inf  0x3f3f3f3f
#define FOR(i,a,b) for( int i = a;i <= b;++i)
#define bug cout<<"--------------"<<endl

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;}
//const int maxn = 110000;
using namespace std;

int n,k;
int vis[1000010];
struct node 
{
	int val,nub;
}a[1000010];
bool cmp(node x,node y)
{
	return x.val > y.val;
}
int main()
{

	//freopen("C:\\ACM\\input.txt","r",stdin);
	cin>>n>>k;
	for(int i = 1;i <= n; ++i) cin>>a[i].nub>>a[i].val;

	sort(a+1 ,a+1+n,cmp);
	
	stack<int>sta;

	ll sum1 = 0;
	ll sum2 = 0;
	//for(int i = 1;i <= n; ++i) cout<<a[i].nub<<" "<<a[i].val<<endl;
	for(int i = 1;i <= k; ++i)
	{
		if(vis[a[i].nub] == 1) sta.push(i);
		else 
		{
			vis[a[i].nub] = 1;
			sum2++;
		}
		sum1 += a[i].val;
	}
	//cout<<sum1 + sum2 * sum2<<endl;
	ll maxn = sum1 + sum2 * sum2;
	for(int i = k+1;i <= n; ++i)
	{
		
		if(sta.size() == 0) break;
		if(vis[a[i].nub] == 1) continue;
		int x = sta.top();
		sta.pop();
		sum1 = sum1 - a[x].val + a[i].val;
		sum2++;
		vis[a[i].nub] = 1;
		maxn = max(maxn,sum1 + sum2 * sum2);
	}
	cout<<maxn<<endl;

}

Measured memory_bytes: 5248
#include<stdio.h>
  
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}


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

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import Counter

MAX = 51
# 階乗テーブル
factorial = [1] * (MAX)
factorial[0] = factorial[1] = 1
for i in range(2, MAX):
    factorial[i] = factorial[i-1] * i

# 組み合わせの数(必要な階乗のテーブルを事前に作っておく)
def nCr(n, r):
    # 10C7 = 10C3
    r = min(r, n-r)
    # 分子の計算
    numerator = factorial[n]
    # 分母の計算
    denominator = factorial[r] * factorial[n-r]
    return numerator / denominator

round = lambda x: int((x*2+1) // 2)

N, A, B = map(int, input().split())
vN = list(map(int, input().split()))

# 組み合わせ計算用に、各値の個数も出しておく
c = Counter(vN)
# 大きい値から欲しいので降順ソートしておく
vN.sort(reverse=True)

mx_avg = sum(vN[:A]) / A
lists = [vN[:A]]
for i in range(A+1, B+1):
    avg = sum(vN[:i]) / i
    if avg == mx_avg:
        # 平均値が最大になるなら、選び方リストに追加
        lists.append(vN[:i])

ans = 0
for l in lists:
    # 選び方を、同じ値の個数毎にまとめる
    c2 = Counter(l)
    combs = 1
    for k, v in c2.items():
        # 同じ値が複数ある場合の組み合わせを出す
        combs *= nCr(c[k], v)
    ans += combs
print(mx_avg)
print(round(ans))


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

using namespace std;

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

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s;
	cin >> s;
	vector<string> v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	rep (i, 7) {
	  if (v[i] == s) {
		cout << 7 - i << endl;
		return 0;
	  }
	}
    
    return 0;
}


Measured memory_bytes: 3616
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
 ll n,m,q;
vector<vector<ll>> v1;
void f(ll i,ll prev,vector<ll> v2){
	ll j;
	if(i==n+1){
		v1.push_back(v2);
		return ;
	}
	for(j=prev;j<=m;j++){
		v2.push_back(j);
		f(i+1,j,v2);
		v2.pop_back();
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>m>>q;
	ll i,j;
	vector<vector<ll>> v(q,vector<ll> (4));

	for(i=0;i<q;i++)
		cin>>v[i][0]>>v[i][1]>>v[i][2]>>v[i][3];
	vector<ll> v2;
	f(1,1,v2);
	ll mx=-1;
	for(i=0;i<v1.size();i++){
		ll sum=0;
		for(j=0;j<q;j++){
			ll a=v[j][0],b=v[j][1],c=v[j][2],d=v[j][3];
			if(v1[i][b-1]-v1[i][a-1]==c)
				sum+=d;

		}
		mx=max(mx,sum);
	}
	cout<<mx<<endl;
	return 0;
} 

Measured memory_bytes: 13856
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n,a;

int main()
{
    cin >> n >> a;
    cout<<n*n-a<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,o,ab;
  int num;
  char type[3];

  a=0;
  b=0;
  o=0;
  ab=0;
  while(scanf("%d,%s ",&num,type)!=EOF){
    if(type[0] == 'A'){
      if(type[1] == 'B'){
	ab++;
      }else{
	a++;
      }
    }
    if(type[0] == 'B'){
      b++;
    }
    if(type[0] == 'O'){
      o++;
    }
  }

  printf("%d\n%d\n%d\n%d\n",a,b,ab,o);

  return 0;
}

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

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

int main(){
  int a, b;
  cin >> a >> b;
  int n = b - a;
  int sum = 0;
  rep(i , n + 1) {
    sum += i;
  }
  cout << sum - b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
using pp=pair<int,pair<int,int>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  int L,R,d;
  cin>>L>>R>>d;
  int ans=0;
  for(int i=L;i<=R;i++){
    if(i%d==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3584
n = gets.to_i
hs = gets.split.map(&:to_i)
ans = 0
1.upto(hs.max) do |h|
  cnt = 0
  bool = false
  n.times do |i|
    if !bool && hs[i] - h >= 0
      bool = true
      cnt += 1
    elsif bool && hs[i] - h < 0
      bool = false
    end
  end
  ans += cnt
end
puts ans

Measured memory_bytes: 1916
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    vector<long long int>a(1000000);
    vector<long long int>b(1000000);
    int n;
    string ans="No";
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<n-2;i++){
        if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
            ans="Yes";
        }
    }
    cout<<ans<<endl;
    return 0;
}


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


vector<pair<ll, int> > F;

void factorx(ll x){
    for (ll i = 2; i*i <= x; i++){
        if(x % i != 0){
            continue;
        } else {
            F.emplace_back(i, 0);
            while(x % i == 0){
                F.back().second++;
                x /= i;
            }
        }
    }
    if(x != 1){
        F.emplace_back(x, 1);
    }
    return;
}

int main() {
    ll A, B; cin >> A >> B;
    ll g = __gcd(A, B);
    factorx(g);
    int ans = F.size() + 1;
    /*rep(i, F.size()){
        cout << F[i].first << " " << F[i].second << endl;
    }*/
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int x, n;
    cin >> x >> n;

    set<int> s;
    for (int i = -100; i < 201; i++) {
        s.insert(i);
    }
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        s.erase(p);
    }

    int diff = 1e9;
    int ans = 0;
    for (int p : s) {
        int d = abs(p - x);
        if (d < diff) {
            ans = p;
            diff = d;
        }
    }
    cout << ans << newl;

    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

class ModCalc
{
	LLONG m_mod = MOD;
	vector<LLONG> m_fac;
	vector<LLONG> m_ifac;

public:
	ModCalc(const LLONG mod)
	{
		m_mod = mod;
	}

	// Combinationを計算したいときの前処理：O(max)
	ModCalc(const int max, const LLONG mod)
	{
		m_mod = mod;
		m_fac = vector<LLONG>(max + 1);
		m_ifac = vector<LLONG>(max + 1);
		m_fac[0] = m_ifac[0] = 1;
		for (int i = 0; i < max; ++i)
		{
			m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
			m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
		}
	}

	const LLONG ModAdd(LLONG a, LLONG b) const
	{
		return (a + b) % m_mod;
	}

	const LLONG ModSubtract(LLONG a, LLONG b) const
	{
		LLONG diff = a - b;
		return diff >= 0 ? diff : diff + m_mod;
	}

	const LLONG ModMulti(LLONG a, LLONG b) const
	{
		LLONG prod = a * b % m_mod;
		return prod >= 0 ? prod : prod + m_mod;
	}

	const LLONG ModDiv(LLONG a, LLONG b) const
	{
		LLONG c = m_mod, u = 1, v = 0;
		while (c)
		{
			LLONG t = b / c;
			b -= t * c; swap(b, c);
			u -= t * v; swap(u, v);
		}
		u %= m_mod;
		if (u < 0) u += m_mod;
		return (a % m_mod) * u % m_mod;
	}

	const LLONG ModPow(LLONG x, LLONG n) const
	{
		LLONG ret = 1;
		while (n != 0)
		{
			if (n & 1) ret = ret * x % m_mod;
			x = x * x % m_mod;
			n = n >> 1;
		}
		return ret;
	}

	const LLONG ModComb(LLONG n, LLONG r) const
	{
		if (n == 0 && r == 0) return 1;
		if (n < r || n < 0) return 0;
		LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
		return tmp * m_fac[n] % m_mod;
	}
};

int main()
{
	int n; cin >> n;
	vector<LLONG> as(n); REP(i, n) cin >> as[i];
	ModCalc mod(MOD);
	LLONG sum = accumulate(as.begin(), as.end(), 0LL) % MOD;
	LLONG ans = mod.ModMulti(sum, sum);
	for (const LLONG ai : as)
	{
		ans = mod.ModSubtract(ans, mod.ModPow(ai, 2));
	}
	ans = mod.ModDiv(ans, 2);
	cout << ans << endl;
}


Measured memory_bytes: 4844
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

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

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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m, ans = 0;
    cin >> n >> m;
    int a[m], b[m];
    for(int i = 0; i < m; ++i) cin >> a[i] >> b[i];
    for(int i = 0; i < m; ++i) {
        UnionFind uf(n);
        for(int j = 0; j < m; ++j) {
            if(i != j) uf.unite(a[j]-1, b[j]-1);
        }
        int grope_num = 0;
        for(int j = 0; j < n; ++j) {
            if(uf.root(j) == j) grope_num++;
        }
        if(grope_num != 1) ans++;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys
a, b = map(int,input().split())
lsta = []
lstb = []
if (a%2 == 1):
    lsta.append(int(a*12.5//1 + 1))
else:
    lsta.append(int(a*12.5))
for i in range(12):
    if ((lsta[0] + i + 1)*0.08//1 == a):
        lsta.append(lsta[0] + i + 1)

lstb.append(b*10)
for i in range(9):
    lstb.append(lstb[0] + i + 1)

for i in range(len(lsta)):
    if (lsta[i] in lstb):
        print(lsta[i])
        sys.exit()

print(-1)
        


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  int ans=0;
  int first=0;
  for(int i=0;i<n;i++){
    if(s[first]==2){ans++;break;}
    else if(i<n-1&&s[first]!=2){first=s[first]-1;ans++;}
    else if(i==n-1&&s[first]!=2){ans=-1;}
  }
  cout<<ans;  
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n,cnt,x;
	scanf("%d",&n);
	while(n!=0) {
		x=n;
		cnt=0;
		while(x!=1) {
			if((x%2)!=0) {
				x=x*3+1;
				cnt=cnt+1;
			}
			else {
				x=x/2;
			cnt=cnt+1;
			}
		}
		printf("%d\n",cnt);
	scanf("%d",&n);
	}
	return 0;
}

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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


void _main() {
        int n; cin >> n;
        vector<pair<int,int>> a(n);
        for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;


        sort(all(a));
        auto calc = [](vector<pair<int,int>> a) {
                double cnt = 0;
                for (int i = 1; i < a.size(); i++) {
                        double dist = sqrt(pow(a[i].first - a[i - 1].first,2) + pow(a[i].second - a[i - 1].second, 2));
                        cnt += dist;
                }
                return cnt;
        };


        double ans = 0, k = 0;
        sort(all(a));
        do {
                ans += calc(a);
                k++;
        } while (next_permutation(all(a)));


        ans /= k;
        cout << fixed << setprecision(10) << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3832
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		solver();
	}

	long MODULO = 1_000_000_000 + 7;

	void solver() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] T = new long[N];
		long[] A = new long[N];
		long[] max = new long[N];
		for (int i = 0; i < N; i++) {
			T[i] = sc.nextLong();
			max[i] = T[i];
		}
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		if (T[N - 1] != A[0]) {
			System.out.println(0);
			return;
		}

		long[] fixed = new long[N];
		Arrays.fill(fixed, -1);
		fixed[0] = T[0];

		for (int i = 1; i < N; i++) {
			if (T[i] != T[i - 1])
				fixed[i] = T[i];
		}

		if (fixed[N - 1] != A[N - 1] && fixed[N - 1] != -1) {
			System.out.println(0);
			return;
		}
		fixed[N - 1] = A[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			if (A[i] != A[i + 1]) {
				if ((fixed[i] != -1 && fixed[i] != A[i]) || A[i] > T[i]) {
					System.out.println(0);
					return;
				}
				fixed[i] = A[i];
			}
		}

		for (int i = 0; i < N; i++) {
			max[i] = Math.min(A[i], T[i]);
		}

		long ans = 1;
		for (int i = 0; i < N; i++) {
			if (fixed[i] == -1) {
				ans = (ans * max[i]) % MODULO;
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 76356
#include <bits/stdc++.h>
#define MOD 1000000007
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> V(n);
    rep(i,n)cin >> V[i];
    sort(V.begin(),V.end());
    cout << V[n/2]-V[(n/2)-1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int MOD = 1e9+7;

const int MAX_N = 1e5;
const int BLACK = 0, WHITE = 1;

vvi edge(MAX_N);
ll dp[MAX_N][2];

void dfs(int prev, int cur) {
  dp[cur][0] = dp[cur][1] = 1LL;
  for (const auto& to : edge[cur]) {
    if (to == prev)
      continue;

    dfs(cur, to);
    dp[cur][WHITE] *= (dp[to][WHITE] + dp[to][BLACK]) % MOD;
    dp[cur][WHITE] %= MOD;
    dp[cur][BLACK] *= dp[to][WHITE];
    dp[cur][BLACK] %= MOD;
  }
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  IN(N);

  REP(i, N-1) {
    IN(x); IN(y);
    edge[x-1].push_back(y-1);
    edge[y-1].push_back(x-1);
  }

  dfs(-1, 0);
  OUT((dp[0][WHITE] + dp[0][BLACK]) % MOD);

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> tmp(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(a[i]>N) count++;
    else tmp[a[i]-1] +=1;
    //cout << a[i]-1 << endl;
  }
  for(int j=1;j<=N;j++){
  if(tmp[j-1]>j) count += tmp[j-1]-j;
  else if(tmp[j-1]<j) count+= tmp[j-1];
}
  /*
  int count=0;
  for(int i=1;i<=N;i++){
    int b=i;
    int c=0;
    for(int j=0;j<N;j++){
      if( a[j]==b) c++;
    }
    if(c>b) count += c-b;
    else if(c<b) count+= c;
  }

  for(int j=0;j<N;j++){
    if( a[j]>N) count++;
  }
  */
  cout << count << endl;
}


Measured memory_bytes: 1024