akhauriyash/Code-Regression huggingface dataset:
s=list(set((str(input()))))
s.sort()
s="".join(map(str,s))
t='abcdefghijklmnopqrstuvwxyz'
if s=='abcdefghijklmnopqrstuvwxy':
    print('z')
else:
    for i in range(len(s)):
        if s[i]!=t[i]:
            print(t[i])
            break
    else:
        print(None)

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


int main () {
    int n;
    string s, t;
    cin >> n >> s >> t;
    string res;
    for (int i = 0; i < n; i++)
        res.push_back(s[i]), res.push_back(t[i]);
    cout << res;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
PLL a[2010];
ll d[2010][2010];
ll dfs(int x,int y)
{
	if (d[x][y]!=-1) return d[x][y];
	int t=y-x+1;
	t=n-t;
	if (x==y) return abs(a[t].Snd-x)*a[t].Fst;
	return d[x][y]=max(dfs(x+1,y)+abs(a[t].Snd-x)*a[t].Fst,dfs(x,y-1)+abs(a[t].Snd-y)*a[t].Fst);
}
int main()
{
	cin >>n;
	for (ll i=0;i<n;i++) cin >>a[i].Fst,a[i].Snd=i;
	sort(a,a+n),reverse(a,a+n);
	memset(d,-1,sizeof(d));
	cout <<dfs(0,n-1);
	return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define eps 1e-6
#define pf printf
#define sf scanf
#define sd(n) scanf("%d", &n)
#define sdd(n1, n2) scanf("%d %d", &n1, &n2)
#define sddd(n1, n2, n3) scanf("%d %d %d", &n1, &n2, &n3)
#define sl(n) scanf("%lld", &n)
#define sll(n1, n2) scanf("%lld %lld", &n1, &n2)
#define slll(n1, n2, n3) scanf("%lld %lld %lld", &n1, &n2, &n3)
#define rep(i, n) for (i = 0; i < n; ++i)
#define rep0(i, n) for (i = 0; i <= n; ++i)
#define rep1(i, n) for (i = 1; i <= n; ++i)
#define repp(i, a, n) for (i = a; i <= n; ++i)
#define repb(i, a, n) for (i = a; i >= n; --i)
#define asort(a) sort(a.begin(), a.end())
#define all(a) (a).begin(), (a).end()
#define sq(n) (n)*(n)
#define mem(a, n) memset(a, n, sizeof(a))

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int n, i, j, a;
    sd(n);

    vector<pair<int, int> > v(n);
    rep(i, n) {
        sd(a);
        v[i] = make_pair(a, i);
    }
    asort(v);

    j = v[n-1].second;
    rep(i, n) pf("%d\n", v[n-1-(i==j)].first);

    return 0;
}


Measured memory_bytes: 3200
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    S = input().rstrip()
    ans = []
    for c in S:
        code = ord(c) + N
        if code > 90:code = 65 + (code-91)
        ans.append(chr(code))
    print("".join(ans))
if __name__ == "__main__":
    main()

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


int main() {
    long long int a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if(k>=a){
        k-=a;
        sum+=a;
    }
    else {
        sum+=k;
        k=0;
    }
    if(k>=b)
        k-=b;
    else
        k=0;
    if(k)
        sum-=k;
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define NUM 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll i,n,k;
    cin>>n>>k;
    ll sum=0,cnt=0,MIN,MAX;
    for(i=k;i<=n+1;i++){
        MIN=i*(i-1)/2;
        MAX=i*(2*n-(i-1))/2;
        cnt=(MAX-MIN)+1;
        sum=(sum+cnt)%NUM;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dp[111111][3];
bool used[111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  ll r,s,p;cin>>r>>s>>p;
  string t;cin>>t;

  for(int i=0;i<n;i++){
    if(i>=k){
      if(t[i] == t[i-k]&&used[i-k]){
	dp[i+1][0]=max(dp[i+1][0],max({dp[i][0],dp[i][1],dp[i][2]}));
	dp[i+1][1]=max(dp[i+1][1],max({dp[i][0],dp[i][1],dp[i][2]}));
	dp[i+1][2]=max(dp[i+1][2],max({dp[i][0],dp[i][1],dp[i][2]}));
      }else{
	if(t[i]=='r'){
	  used[i]=true;
	  dp[i+1][2]=max(dp[i+1][2],max({dp[i][0],dp[i][1],dp[i][2]})+p);
	}else if(t[i]=='s'){
	  used[i]=true;
	  dp[i+1][0]=max(dp[i+1][0],max({dp[i][0],dp[i][1],dp[i][2]})+r);
	}else{
	  used[i]=true;
	  dp[i+1][1]=max(dp[i+1][1],max({dp[i][0],dp[i][1],dp[i][2]})+s);
	}
	dp[i+1][0]=max(dp[i+1][0],max({dp[i][0],dp[i][1],dp[i][2]}));
	dp[i+1][1]=max(dp[i+1][1],max({dp[i][0],dp[i][1],dp[i][2]}));
	dp[i+1][2]=max(dp[i+1][2],max({dp[i][0],dp[i][1],dp[i][2]}));
      }
    }else{
      if(t[i]=='r'){
	used[i]=true;
	dp[i+1][2]=max(dp[i+1][2],max({dp[i][0],dp[i][1],dp[i][2]})+p);
      }else if(t[i]=='s'){
	used[i]=true;
	dp[i+1][0]=max(dp[i+1][0],max({dp[i][0],dp[i][1],dp[i][2]})+r);
      }else{
	used[i]=true;
	dp[i+1][1]=max(dp[i+1][1],max({dp[i][0],dp[i][1],dp[i][2]})+s);
      }
      dp[i+1][0]=max(dp[i+1][0],max({dp[i][0],dp[i][1],dp[i][2]}));
      dp[i+1][1]=max(dp[i+1][1],max({dp[i][0],dp[i][1],dp[i][2]}));
      dp[i+1][2]=max(dp[i+1][2],max({dp[i][0],dp[i][1],dp[i][2]}));
    }
  }
  ll  ans=0;

  for(int i=0;i<3;i++)
    ans=max(ans,dp[n][i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2896
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def naobou(d, q):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  if newans < ans:
    ZL[rd].insert(rq, d)
    del ZL[nd][nq + 1]
    return ans
  else:
    t[d - 1] = q
    return newans 

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

t = [1] * D

for i in range(D):
  print(t[i])


Measured memory_bytes: 77888
from sys import stdin
import itertools
def main():
    #入力
    readline=stdin.readline
    N,M,Q=map(int,readline().split())
    a=[0]*Q
    b=[0]*Q
    c=[0]*Q
    d=[0]*Q
    for i in range(Q):
        a[i],b[i],c[i],d[i]=map(int,readline().split())

    arrays=list(itertools.combinations_with_replacement(range(1,M+1),N))
    max_res=0
    for A in arrays:
        res=0
        for i in range(Q):
            if A[b[i]-1]-A[a[i]-1]==c[i]:
                res+=d[i]
        max_res=max(max_res,res)
    print(max_res)
if __name__=="__main__":
    main()

Measured memory_bytes: 21416
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> &P){
os << P.first;
os << " ";
os << P.second;
os << "\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;


int binary_knapsack(vector<int>& val,vector<int>& weight, int W){
    int N = val.size();
    vector<vector<int>> dp(N+1,vector<int>(W+1,0));
    REP(i,N){
        REP(w,W+1){
            if(w>=weight[i])
                dp[i+1][w] = dp[i][w-weight[i]]+val[i];
            chmax(dp[i+1][w], dp[i][w]);
        }
    }
    return dp[N][W];
} 
int nlimited_knapsack(vector<int>& val,vector<int>& weight, vector<int>& cnt, int W){
    vector<int> val_,weight_;
    int N = val.size();
    REP(i,N){
        int num = cnt[i];
        for(int k=1;num>0;k<<=1){
            chmin(k,num);
            val_.push_back(val[i]*k);
            weight_.push_back(weight[i]*k);
            num-=k;
        }
    }

    int res = binary_knapsack(val_,weight_,W);
    return res;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,W;
    cin >> N >> W;
    vector<int> val(N),weight(N),cnt(N);
    REP(i,N){
        cin >> val[i] >> weight[i] >> cnt[i];
    }
    int ans = nlimited_knapsack(val,weight,cnt,W);    
    cout << ans << endl;
}




Measured memory_bytes: 112432
import math

n = int(raw_input())

class Coord():
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def show(self):
        print self.x, self.y

def calcCoord(N, start, end):
    if N == 0:
        return [start]
    s = Coord((start.x * 2.0 + end.x) /3, (start.y * 2.0 + end.y) /3)
    t = Coord((start.x + end.x * 2.0) /3, (start.y + end.y * 2.0) /3)
    u = Coord(((t.x-s.x) - (t.y-s.y) * math.sqrt(3)) /2 + s.x, ((t.x-s.x) * math.sqrt(3) + (t.y-s.y)) /2 + s.y)
    if N == 1:
        return [start, s, u, t]
    return calcCoord(N-1, start, s) + calcCoord(N-1, s, u) + calcCoord(N-1, u, t) + calcCoord(N-1, t, end)
    
start = Coord(0.0, 0.0)
end = Coord(100.0, 0.0)
ans = calcCoord(n, start, end) + [end]
for i in range(len(ans)):
    print ans[i].x, ans[i].y

Measured memory_bytes: 7908
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int distance(P x, P y){
    return abs(x.first - y.first) + abs(x.second - y.second);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    vector<P> student, point;
    cin >> n >> m;
    REP(i, n){
        int a, b;
        cin >> a >> b;
        student.push_back(make_pair(a, b));
    }
    REP(i, m){
        int c, d;
        cin >> c >> d;
        point.push_back(make_pair(c, d));
    }

    REP(i, n){
        P sp = student[i];
        int min_dist = distance(sp, point[0]);
        int ans = 1;
        REP(j, m){
            if(min_dist > distance(sp, point[j])){
                min_dist = distance(sp, point[j]);
                ans = j + 1;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


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

int n, k;
long long h[100000], u[100000];

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

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

	sort(h, h + n);

	for (int i = 0; i < n - k + 1; i++)
		u[i] = h[i + k - 1] - h[i];

	sort(u, u + n - k + 1);

	cout << u[0] << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,a;
    cin>>x>>a;
    int ar[x+2];
    int sum=0;
    for(int i=1;i<=x;i++){
        cin>>ar[i];
        sum+=ar[i];
        if(sum>a){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<(x+1)<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(a>=b){
    cout<<"delicious";
  }
  else if(a+x>=b){
    cout<<"safe";
  }
  else if(b>a+x){
    cout<<"dangerous";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e15+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
int n;in n;
if(n>=400 && n<=599) out "8";
else if(n>=600 && n<=799) out "7";
else if(n>=800 && n<=999) out "6";
else if(n>=1000 && n<=1199) out "5";
else if(n>=1200 && n<=1399) out "4";
else if(n>=1400 && n<=1599) out "3";
else if(n>=1600 && n<=1799) out "2";
else if(n>=1800 && n<=1999) out "1";
return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
// get<0>(v[i])
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(40);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 40)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

// vector<ll> ans(1000005, 1);

void solve(){
    ll n; cin >> n;
    if(n%1000)
        cout << 1000 - n%1000 << nl;
    else
        cout << 0 << nl;
}
 
int main(){
    // boost;
    // cal(3);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 3632
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    int N=s.nextInt();
    int[] ai=new int[N];
    for(int i=0;i<N;i++)ai[i]=s.nextInt();
    int ans=0;
    for(int i=0;i<N;i+=2){
      if(ai[i]%2==1) ans+=1;
    }
    System.out.println(ans);

  }  
}

Measured memory_bytes: 35804
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
	return 0;
}


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

f = True
for i in A:
  if i == 0:
    print(0)
    f = False
    break

if f:
  for i in A:
    ans *= i
    if ans > 10**18:
      print(-1)
      break
  else:
    print(ans)

Measured memory_bytes: 21640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    cin >>Input[i] ;
  }

  sort(Input, Input+N);

  int mid = Input[N/2];
  int left = Input[N/2 - 1];

  int cnt = 0;
  while (mid != left) {
    cnt++;
    mid--;
  }
  cout << cnt << endl;
  
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        String strInput = input.nextLine();
        String[] str = new String[3];
        str = strInput.split(" ");
        if(Integer.parseInt(str[0]) < Integer.parseInt(str[1]) && Integer.parseInt(str[1]) < Integer.parseInt(str[2])){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26164
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 0;
		int[] like = new int[n+1];
		for(int i=1; i<=n; i++){
			like[i] = sc.nextInt();
		}
		for(int i=1; i<=n; i++){
			if(like[like[i]]==i){
				cnt++;
			}
		}
		System.out.println(cnt/2);
	}
}

Measured memory_bytes: 32272
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

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

int main(){
    int n;
    char s[100];
    scanf("%d%s",&n,s);
    if(n%2!=0){
        printf("No\n");
        return 0;
    }
    int flag=1;
    REP(i,n/2){
        if(s[i]!=s[i+n/2])flag=0;
    }
    if(flag)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
import sys
def ink(x,y,size):
    global paper
    paper[y][x]+=1
    for d in [-1,1]:
        paper[y+d][x]+=1
        paper[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        paper[y+d][x+d]+=1
        paper[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        paper[y+d][x]+=1
        paper[y][x+d]+=1
    return

R=range(14)
paper=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in paper[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Measured memory_bytes: 4268
while True:
    N, M = map(int, input().split())
    if N == 0:
        break
    mas = [int(input()) for _ in range(N)]
    dice = [int(input()) for _ in range(M)]
    p = 0
    ans = 0
    for d in dice:
        p += d
        ans += 1
        if p >= N:
            break
        p += mas[p]
        if p >= N:
            break
    print(ans)

Measured memory_bytes: 7604
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int a, b, t;
    cin >> a >> b >> t;

    int ans = 0;
    for (int i = 1; a * i <= t; i++) {
        ans += b;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int A;
  int B;
  int C;
  int D;
  int num = 1;
  cin>>A;
  cin>>B;
  cin>>C;
  cin>>D;
  while(A > 0 && C > 0){
    if(num % 2 == 1){
      C = C - B;
    }else if(num % 2 == 0){
      A = A - D;
    }
    num += 1;    
  }
  if(num % 2 == 0){
    cout<<"Yes"<<'\n';
  }else{
    cout<<"No"<<'\n';
  }
}

Measured memory_bytes: 3612
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, 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 (LLONG_MAX - 1e5)

using namespace std;

int A[3];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> A[0] >> A[1] >> A[2];
    sort(A, A + 3);

    int ans = abs(A[0] - A[1]) + abs(A[1] - A[2]);
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> l(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];

    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (l[i] + l[j] > l[k] && l[i] != l[j] && l[i] != l[k] && l[j] != l[k])
                    ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;


int a, b, c;
int x, y;
int ans;

int main(){
	cin >> a >> b >> c;

	ans = a + b + c;

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


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define pb push_back

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,p[N],sg[N],x;
vector<int> E[N];
bool vis[N],vv[N];

int dfs(int u) {
	if(vis[u]) return u;
	vis[u]=1;
	return dfs(p[u]);
}

void dfs2(int u) {
	for(auto v:E[u])
		if(!vis[v]) dfs2(v);
	for(auto v:E[u])
		if(!vis[v]) vv[sg[v]]=1;
	for(int i=0;;i++)
		if(!vv[i]) { sg[u]=i;break; }
	for(auto v:E[u]) vv[sg[v]]=0;

}

void solve(int u) {
	if(u==x) {
		for(auto v:E[u]) vv[sg[v]]=1;
		for(int i=0;;i++)
			if(!vv[i]) {
				if(sg[u]==i) { cout<<"POSSIBLE";exit(0); }
				else break;
			}
		for(auto v:E[u]) vv[sg[v]]=0;
		return;
	}
	for(auto v:E[u]) vv[sg[v]]=1;
	for(int i=0;;i++)
		if(!vv[i]) { sg[u]=i;break; }
	for(auto v:E[u]) vv[sg[v]]=0;
	solve(p[u]);
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) E[p[i]=gi()].pb(i);
	x=dfs(1);int v=x;
	memset(vis,0,sizeof(vis));
	do vis[v]=1,v=p[v]; while(v!=x);
	for(int i=1;i<=n;i++)
		if(vis[i]) dfs2(i);
	solve(p[x]);
	for(auto v:E[x]) if(!vis[v]) vv[sg[v]]=1;
	for(int i=0;;i++)
		if(!vv[i]&&sg[x]!=i) { sg[x]=i;break; }
	for(auto v:E[x]) vv[sg[v]]=0;
	solve(p[x]);
	cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, A, B; cin >> N >> A >> B;
  int a=0, b=0, c=0;
  REP(i, N) {
    int p; cin >> p;
    if (p <= A) a++;
    else if (A < p && p <= B) b++;
    else c++;
  }
  cout << min({a, b, c}) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define nax 500009LL
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;
 

ll pot(ll x, ll y){
	ll ans=1;
	while(y){
		if(y&1) ans=(ans*x)%mod;
		y>>=1;
		x=(x*x)%mod;
	}
	return ans;
}
 

int main(){
	fastio;
    
	string l;

    cin>>l;
    int n=sz(l);
    int ans=0, x=0;
    REP(i,n){
        if(l[i]=='1'){
            ans=(ans+(pot(2,x)*pot(3,n-1-i))%mod)%mod;
            x++;
        }
    }
    ans=(ans+pot(2,x))%mod;
    
    cout<<ans;


	return 0;
}

Measured memory_bytes: 3772
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)
#define asc less<llong>()
#define desc greater<llong>()

struct edge {
    llong from;
    llong to;
    llong cost;
};

llong ctoi(char c) {
    switch (c) {
        case '0': return 0;
        case '1': return 1;
        case '2': return 2;
        case '3': return 3;
        case '4': return 4;
        case '5': return 5;
        case '6': return 6;
        case '7': return 7;
        case '8': return 8;
        case '9': return 9;
        default: return 0;
    }
};

bool search(llong start, llong end, vector<vector<edge>> map){
    vector<bool> confilm(map.size() + 10, false);

    stack<llong> st;
    st.push(start);

    while(!st.empty()) {
        llong now = st.top();
        st.pop();

        if(confilm[now]) continue;
        confilm[now] = true;
        if(now == end) return true;

        for_each(map[now].begin(), map[now].end(), [&](edge e) {
            st.push(e.to);
        });
    }

    return false;
};

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

    llong N, M, P;
    cin >> N >> M >> P;

    vector<edge> edges;
    vecllong minDist(N + 10, INF);

    vector<vector<edge>> map(N + 10, vector<edge>(0));

    minDist[0] = 0;

    FOR(i, M) {
        llong from, to, cost;
        cin >> from >> to >> cost;
        from--;
        to--;
        cost -= P;
        edges.push_back({from, to, -cost});
        map[from].push_back({from, to, -cost});
    }

    FOR(i, N) {
        FOR(j, edges.size()) {
            edge e = edges[j];
            if(minDist[e.to] > minDist[e.from] + e.cost) {
                minDist[e.to] = minDist[e.from] + e.cost;
                if(i == N - 1) {
                    if(search(e.from, N - 1, map) and search(0, e.from, map)) {
                        cout << "-1" << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << max(-minDist[N - 1], 0LL) << endl;

    return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    if(s.size() < t.size()){
        cout << " UNRESTORABLE" << endl;
        return 0;
    }
    vector<int> tiv;
    bool found = false;
    for(int i=0; i<s.size(); i++){
        if(s[i] == t[0] || s[i] == '?'){
            int ci = i;
            int cj = 0;
            while(s[ci] == t[cj] || s[ci] == '?'){
                if(cj == t.size()-1){
                    tiv.push_back(i);
                    found = true;
                    break;
                }
                if(ci == s.size()-1){
                    break;
                }
                ci++;
                cj++;
            }
        }
    }
    
    if(found){
        for(auto &c: s){
            if(c == '?') c = 'a';
        }
        vector<string> v;
        for(auto ti: tiv){
            v.push_back(s.substr(0, ti) + t + s.substr(ti+t.size()) );
        }
        sort(v.begin(), v.end());
        cout << v[0] << endl;
    }else{
        cout << " UNRESTORABLE" << endl;
    }  
    return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        val k = readLine()!!.trim().toInt()
        if (n == 0 && k == 0) return
        val canMake = mutableSetOf<Int>()
        val cards = Array(n){readLine()!!.trim().toInt()}.toIntArray()
        setCanMake(k, cards, canMake)
        println(canMake.size)
    }
}
fun setCanMake(k:Int, cards:IntArray, canMake:MutableSet<Int>, made:Int = 0, used:Int = 0){
    if (k == 0){
        canMake.add(made)
        return
    }
    for (i in cards.indices){
        if (used and (1 shl i) == 0){
            setCanMake(k - 1, cards, canMake, cards[i] + made * if (cards[i] >= 10) 100 else 10, used or (1 shl i))
        }
    }
}


Measured memory_bytes: 30624
from queue import Queue

class Node:
    def __init__(self, data):
        self.data = data
        self.children = []

def main():
    N, M = map(int, input().split())
    dic = {}
    for i in range(1, N + 1):
        dic[i] = Node(i)
    for i in range(0, M):
        A, B = map(int, input().split())
        dic[A].children.append(dic[B])
        dic[B].children.append(dic[A])

    answerDic = {}
    q = Queue()
    q.put(dic[1])
    while not q.empty():
        current = q.get()
        for child in current.children:
            if child.data not in answerDic.keys() :
                answerDic[child.data] = current.data
                q.put(child)

    print('Yes')
    for key in range(2, N + 1):
        print(answerDic[key])

if __name__ == "__main__":
    main()

Measured memory_bytes: 54872
n = int(input())
lis = list(map(int,input().split()))
lis.sort()
if n % 2 == 1:
    if lis[0] != 0:
        print("0")
        exit()
    else:key = 0
else:key = -1
for i in range(n//2):
    if lis[i*2+key+1] != lis[i*2+key+2] or lis[i*2+key+2] != 2*(i+1) + key:
        print("0")
        exit()
ans = 1
for i in range(n//2):
    ans *= 2
    ans %= 10 ** 9 +7
print(ans)

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


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int a,b;

    cin >> a >> b;

    int sum = 1;
    int i = 2;

    while(1){
        int l = sum;
        int r = sum+i;

        int j = 1;

        while(1){
            if(a + j == l && b + j == r){
                cout << j << endl;
                return 0;
            }
            
            if(a + j > l || b + j> r){
                break;
            }

            j++;
        }

        sum += i;
        i++;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,k;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
	if(b-a<=k && c-a<=k && d-a<=k && e-a<=k && c-b<=k && d-b<=k && e-b<=k && d-c<=k && e-c<=k && e-d<=k){
		printf("Yay!\n");
	}
	else{
		printf(":(\n");
	}
	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  
  if (n % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  
  ll ans = 0;
  ll base = 10;
  while (base <= n) {
    ans += n / base;
    base *= 5;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#B問題
ans = 0
#文字列は自動的に配列扱いにできる(ex S=coffeeなら、S[2]=f という風に一文字ずつ参照可能)
S = input()
T = input()
for i in range(len(S)):
    if S[i] != T[i]:
        ans += 1
print(ans)

Measured memory_bytes: 9248
import           Control.Monad
import           Control.Applicative
import           Data.Ord
import           Data.List
import qualified Data.Vector                   as V
import           Data.Array.IO

main :: IO ()
main = do
  s <- group . sort <$> getLine

  print $ if length s == 1 then 0 else 2 * (minimum . map length) s

Measured memory_bytes: 13692
read = input
n,k = map(int, read().split())
a = read()
a = '1' + a + '1'
# -1 if use 0, -1 if use len(a) -1
pstart = 0
pcnt = 0
ptype = '1'
b = []
# (start, end, cnt)
for tp in enumerate(a):
    i, c = tp
    if ptype == c:
        pcnt = pcnt + 1
    else :
        b.append((pstart, i-1, pcnt))
        pstart = i
        ptype = c
        pcnt = 1
b.append((pstart, i, pcnt))
# print(b)
if k >= len(b)//2:
    print(sum(map(lambda tp:tp[2], b)) - 2)
else :
    start = 0
    end = k * 2
    ans = 0
    S = [0 for i in range(len(b)+10)]
    S[0] = b[0][2]
    for i in range(1, len(b)):
        S[i] = S[i-1] + b[i][2]
    while(end <= len(b) - 1):
        tmp = S[end] - (S[start - 1] if start - 1>=0 else 0)
        if b[start][0] == 0:
            tmp = tmp - 1
        if b[end][1] == len(a)-1:
            tmp = tmp -1
#         print(start, end ,tmp)
        ans = max(ans, tmp)
        start = start + 2
        end = end + 2
    print(ans)

Measured memory_bytes: 21528
#include <stdio.h>

int main(void)
{
    int i;
    char str[256];

    gets(str);
    for (i = 0; str[i] != '\0'; i++) {
        if ('a' <= str[i] && str[i] <= 'z') {
            str[i] += 'A' - 'a';
        }
    }
    printf("%s\n", str);

    return 0;
}

Measured memory_bytes: 520
n = int(input())
a = []
for i in range(2):
    a.append(list(map(int, input().split())))

maxa = 0
for i in range(n):
    tmpm = 0
    for j in range(n):
        if i >= j:
            tmpm += a[0][j]
        if i <= j:
            tmpm += a[1][j]
    maxa = max(maxa, tmpm)
print(maxa)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

vector<long long> a;
long long n;

map<pair<int, int>, long long> dp;

long long solve(int step, int x) {
	if (x * 2 - 1 > step + 1) return -(1LL << 60);
	if (dp.find({ step, x }) != dp.end()) return dp[{step, x}];
	if (x == 0) return 0;

	long long ans = -(1LL << 60);
	if (x == 1) {
		ans = max(ans, a[step]);
		if (step > 0) ans = max(ans, solve(step - 1, x));
	}
	else {
		if (step >= 2) ans = max(ans, a[step] + solve(step - 2, x - 1));
		ans = max(ans, solve(step - 1, x));
	}

	dp[{step, x}] = ans;
	return ans;
}

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

	long long i, j, k, ans, x;
	cin >> n;
	a.resize(n);
	for (i = 0; i < n; i++) cin >> a[i];
	x = n / 2;

	ans = solve(n - 1, x);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 29552
#!/use/bin/env python3

a = input()

b = int(a)

ans = 0

if b != 2:
    if b % 2 == 1:
        ans = b * ((b - 1) // 2)
    else:
        ans = b * ((b - 1) // 2) + (b // 2)
else:
    ans = 1

print(ans)

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

namespace modular{
    using ll = long long;

    const int mod = 998244353;

    int mul_mod(ll a, ll b){
        if (a < 0) a += mod;
        if (b < 0) b += mod;
        return a * b % mod;
    }

    int plus_mod(ll a, ll b){
        if (a < 0) a += mod;
        if (b < 0) b += mod;
        return (a + b) % mod;
    }

    int minus_mod(ll a, ll b){
        if (a < 0) a += mod;
        if (b < 0) b += mod;
        return (a - b + mod) % mod;
    }

    int pow_mod(ll a, ll k){
        ll res = 1;
        for (; k; k >>= 1, a = mul_mod(a, a))
            if (k & 1) res = mul_mod(res, a);
        return res;
    }

    ll ext_euclid(ll a, ll b, ll &x, ll &y){
        int g = a; x = 1; y = 0;
        if (b != 0){
            g = ext_euclid(b, a % b, y, x);
            y -= (a / b) * x;
        }
        return g;
    }

    int inverse(ll a){
        return pow_mod(a, mod - 2);
        ll x, y; ext_euclid(a, ll(mod), x, y);
        return x %= mod, x < 0 ? x + mod : x;
    }

    int div_mod(ll a, ll b){
        return mul_mod(a, inverse(b));
    }
};

using namespace modular;

const int N = 2e5 + 5;
const int C = 1e6 + 5;
int a[N], cnt[C], w[C];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, res = 0, maxv = 0; cin >> n;
    for (int i = 1, x; i <= n; i++){
        cin >> x; cnt[x]++; maxv = max(maxv, x);
    }
    for (int i = 1; i <= maxv; i++){
        w[i] += inverse(i);
        for (int j = 2 * i; j <= maxv; j += i)
            w[j] = minus_mod(w[j], w[i]);
        int x = 0, y = 0, z = 0;
        for (int j = i; j <= maxv; j += i){
            x = plus_mod(x, mul_mod(cnt[j], j));
            y = plus_mod(y, mul_mod(mul_mod(cnt[j],
                        cnt[j]), mul_mod(j, j)));
            z = plus_mod(z, mul_mod(mul_mod(j, j),
                        mul_mod(cnt[j], cnt[j] - 1)));
        }
        res = plus_mod(res, mul_mod(w[i],
                minus_mod(mul_mod(x, x), y)));
        res = plus_mod(res, mul_mod(w[i], z));
    }
    cout << div_mod(res, 2) << '\n';
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int, int>P;

bool stable;
char mp[62][12];
int flg[62][12];
void initMp(int w, int h){
    for(int y=0;y<62;y++){
        for(int x=0;x<12;x++){
            mp[y][x]='.';
            flg[y][x]=0;
        }
    }
    for(int y=1;y<=h;y++){
        for(int x=1;x<=w;x++){
            cin>>mp[y][x];
        }
    }
    for(int x=1;x<=w;x++){
        mp[h+1][x] = 'G';
    }
}

P solve(int y, int x){
    int weight = 0;
    int xSum = 0;
    
    int xl = 20, xr = -10;

    int dx[4]={0, 1, 0, -1};
    int dy[4]={1, 0, -1, 0};
    queue<int>X, Y;

    X.push(x);
    Y.push(y);
    flg[y][x]=1;

    while(!X.empty()){
        x = X.front();
        y = Y.front();
        X.pop();
        Y.pop();
        xSum += x;
        weight++;
        if(mp[y+1][x]!='.' && mp[y+1][x]!=mp[y][x]){
            xl = min(xl, x);
            xr = max(xr, x);
        }
        for(int i=0;i<4;i++){
            if(flg[y+dy[i]][x+dx[i]]==0 && mp[y+dy[i]][x+dx[i]]==mp[y][x]){
                flg[y+dy[i]][x+dx[i]]=1;
                X.push(x+dx[i]);
                Y.push(y+dy[i]);
            }
        }
        if(mp[y-1][x]!='.' && mp[y-1][x]!=mp[y][x] && flg[y-1][x]==0){
            P p = solve(y-1, x);
            xSum += p.first;
            weight += p.second;
        }
    }
    if((2*xSum <= weight * (2*xl-1) ) || (weight * (2*xr+1) <= 2*xSum))stable = false;
    return P(xSum, weight);
}

int main(){

    for(int w, h;cin>>w>>h,w;){
        initMp(w, h);
        stable = true;
        for(int x=1;x<=w;x++){
            if(mp[h][x]!='.'){
                solve(h, x);
                break;
            }
        }
        cout<<(stable?"STABLE":"UNSTABLE")<<endl;
    }

    return 0;
}


Measured memory_bytes: 3168
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int n;
  cin >> n;
  vector<int> t(n+1), x(n+1), y(n+1);
  t[0] = 0; x[0] = 0; y[0] = 0;
  for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];
  for (int i = 1; i <= n; i++){
    int d = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
    int u = t[i] - t[i-1];
    if ((u - d) % 2 == 0 && u - d >= 0) continue;
    else {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}

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

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

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

constexpr int MOD = 1000000007;

void print(const vi& dp) {
    for (auto d : dp) { cout << d << " "; }
    cout << endl;
}

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

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

    vector<string> dp(s.size() + 1);
    for (char c : t) {
        rrep(i, 1, s.size() + 1) {
            if (s[i - 1] == c && dp[i].size() < dp[i - 1].size() + 1) { dp[i] = dp[i - 1] + c; }
        }
        rep(i, 1, s.size() + 1) {
            if (s[i - 1] != c && dp[i].size() < dp[i - 1].size()) { dp[i] = dp[i - 1]; }
        }
    }
    cout << dp.back() << endl;

    return 0;
}

Measured memory_bytes: 14720
import math
import copy

def secize(n, k):
    n2=bin(n)
    n3=n2[2:]
    for i in range(k-len(n2)+2):
        n3='0'+n3
    return n3


n=int(input())
alist = list(map(int,input().split()))
saidai=max(alist)
keta=math.ceil(math.log(saidai+1, 2))
blist=[]
for i in range(n):
    kaz=secize(alist[i], keta)
    blist.append(kaz)

now1=0
now2=0
nowarr=[]
for bl in blist[0]:
    nowarr.append(int(bl))
answer=0
swit=0
while now1<=n-2 and now2<=n-2:
    """
    maearr=copy.deepcopy(nowarr)
    for i in range(keta):
        if blist[now2+1][i]=='1':
            if nowarr[i]==1:
                swit=1
            else:
                nowarr[i]=1
    """
    for i in range(keta):
        if blist[now2+1][i]=='1':
            if nowarr[i]==1:
                swit=1
            else:
                nowarr[i]=2
    if swit==1:
        for i in range(keta):
            if nowarr[i]==2:
                nowarr[i]=0
        answer+=(now2-now1+1)
        #nowarr=maearr
        for i in range(keta):
            if blist[now1][i]=='1':
                nowarr[i]=0
        if now1==now2:
            nowarr=[]
            for bl in blist[now1+1]:
                nowarr.append(int(bl))
            now1+=1
            now2+=1
            if now1==n-1:
                answer+=1
        else:
            now1+=1
        swit=0
    else:
        for i in range(keta):
            if nowarr[i]==2:
                nowarr[i]=1
        if now2!=n-2:
            now2+=1
        else:
            wa=now2-now1+2
            answer+=(wa*(wa+1)//2)
            now2+=1

#print(now1, now2)
if n!=1:
    print(answer)
else:
    print(1)


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

using ll = long long;
const ll mod = 1000000007;
int main()
{
    int N;
    cin >> N;
    ll A[N];
    ll sum = 0LL;
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
        sum += A[i];
        sum %= mod;
        sum = (sum + mod) % mod;
    }
    ll ans = 0LL;
    for (int i = 0; i < N; i++)
    {
        sum -= A[i];
        sum = (sum + mod) % mod;
        ans += A[i] * sum % mod;
    }
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 5172