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

#define ll long long
#define sc(n) int n; scanf("%d",&n);
#define mod 10000007
#define N 100001
#define MX 1000000001
#define log(n) (int)log2(n)
#define pb(x) push_back(x);
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define scArr(n) int n; scanf("%d", &n); int a[n]; for(int i=0; i<n; i++) scanf("%d", &a[i]);


int main()
{
    long long int n, k;
    cin>>n>>k;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];

    long long int mn=1e18, sum;
    for(int i=0; i+k-1<n; i++)
    {
        sum=min(abs(a[i]),abs(a[i+k-1]))+abs(a[i+k-1]-a[i]);
        if(sum<mn) mn=sum;
    }
    cout<<mn;
}


Measured memory_bytes: 640
/* ex3_4 
　　　　　sachiyan*/

#include <stdio.h>
int main(void){
    int num; //入力Nの定義
    int rp1,rp2; //while内変数の定義
    scanf("%d", &num); //Nの読み取り
    rp1 = 1;
    while(rp1 <= 9){ //二重のループを1－９までで回して九九の解をすべてしらべる
        rp2 = 1;
        while(rp2 <= 9){
            if(rp1*rp2 == num){ //九九を総当たりで探し、Nと等しければ
                printf("Yes"); //Yesを出力しendの行まで飛ぶ
                goto end; //endの行まで飛ぶ
            }
            rp2++;
        }
        rp1++;
    }
    if(rp1 == 10 && rp2 == 10){ //九九全てに当てはまらないとき
        printf("No"); //Noを出力
    }
    end:
        printf("\n"); //改行を出力
    return 0;
}

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

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

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (x[i] < k - x[i]) {
			ans += x[i] * 2;
		} else {
			ans += (k-x[i]) * 2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int answer = 0;
  for (int i =0; i<N; i++) {
    int x;
    cin >> x;
    
    if (x > K/2) {
      answer+=(K-x)*2;
    } else {
      answer+=x*2;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<Integer> aList = new ArrayList<Integer>();
		ArrayList<Integer> bList = new ArrayList<Integer>();
		ArrayList<Integer> ansList = new ArrayList<Integer>();

		for (int i = 1; i <= a; i++) {
			if (a % i == 0) {
				aList.add(i);
			}
		}

		for (int i = 1; i <= b; i++) {
			if (b % i == 0) {
				bList.add(i);
			}
		}

		if(aList.size() > bList.size()){
			for (int val : aList) {
				if(bList.contains(val)){
					ansList.add(val);
				}
			}
		}else{
			for (int val : bList) {
				if(aList.contains(val)){
					ansList.add(val);
				}
			}
		}

		Collections.sort(ansList, Collections.reverseOrder());
		System.out.println(ansList.get(k - 1));

		sc.close();
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=128;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,ans=0;
vl v1,v2,v(200100,0),kaijo,gysku;
vp p;
string s;
ll solve(void){
    return ((a*3)+b)/2;
 
}
int main(){
    cin>>a>>b;
 
 
 
    cout<<solve()<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N = 2060, MOD = 924844033, G = 5;
int dp[N][N][2],n,k,val[N],jc[N],ans,rev[N],tmp[N];
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = 1ll * ret * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return ret;
}
void prework(int n) {
  rev[0] = 0;
  for (int i = 1 ; i < n ; ++ i)
    if (i&1) rev[i] = rev[i-1] | (n >> 1);
    else rev[i] = rev[i>>1] >> 1;
}
void dft(int* a,int n,int sgn) {
  for (int i = 0 ; i < n ; ++ i)
    if (i < rev[i]) swap(a[i],a[rev[i]]);
  int w,wp,u,v;
  for (int s = 2 ; s <= n ; s <<= 1) {
    wp = power(G,(MOD-1) / s);
    if (sgn) wp = power(wp,MOD-2);
    for (int k = 0 ; k < n ; k += s) {
      w = 1;
      for (int j = k ; j < k + (s >> 1) ; ++ j) {
	u = a[j];
	v = 1ll * w * a[j + (s >> 1)] % MOD;
	a[j] = u + v;
	if (a[j] >= MOD) a[j] -= MOD;
	a[j + (s >> 1)] = u - v + MOD;
	if (a[j + (s >> 1)] >= MOD) a[j + (s >> 1)] -= MOD;
	w = 1ll * w * wp % MOD;
      }
    }
  }
  if (sgn) {
    wp = power(n,MOD-2);
    for (int i = 0 ; i < n ; ++ i)
      a[i] = 1ll * a[i] * wp % MOD;
  }
}
int getval(int p,int v,int s) {
  if (p <= 0) {
    if (v == 0 && s == 0) return 1;
    return 0;
  }
  return dp[p][v][s];
}
int main() {
  scanf("%d%d",&n,&k);
  for (int i = 1 ; i <= n ; ++ i) {
    for (int j = 0 ; j < i ; ++ j) {
      (dp[i][j][0] += (getval(i - 2 * k, j, 1) + getval(i - 2 * k, j, 0)) % MOD) %= MOD;
      if (i > k) (dp[i][j+1][0] += getval(i - 2 * k, j, 0)) %= MOD;
      if (i + k <= n) (dp[i][j+1][1] += 1ll * (getval(i - 2 * k, j, 0) + getval(i - 2 * k, j, 1)) % MOD) %= MOD;
    }
  }
  val[0] = 1;
  int l = 1;
  while (l <= n) l <<= 1;
  prework(l);
  dft(val,l,0);
  for (int i = max(1,n - 2 * k + 1) ; i <= n ; ++ i) {
    for (int j = 0 ; j < l ; ++ j)
      tmp[j] = (dp[i][j][0] + dp[i][j][1]) % MOD;
    dft(tmp,l,0);
    for (int j = 0 ; j < l ; ++ j)
      val[j] = 1ll * val[j] * tmp[j] % MOD;
  }
  dft(val,l,1);
  jc[0] = 1;
  for (int i = 1 ; i <= n ; ++ i)
    jc[i] = 1ll * jc[i-1] * i % MOD;
  for (int i = 0, j = 1 ; i <= n ; ++ i, j = -j)
    (ans += 1ll * val[i] * jc[n - i] * j % MOD) %= MOD;
  ans = (ans % MOD + MOD) % MOD;
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;

typedef int64_t i64;

#define MAT_SIZE 121

int main() {
  i64 X;
  cin >> X;
  vector<i64> M(MAT_SIZE);
  for (i64 i = 0; i < M.size(); i++) {
    M[i] = i*i*i*i*i;
  }
  for (i64 a = 0; a < M.size()-1; a++) {
    for (i64 b = a+1; b < M.size(); b++) {
      i64 s[4] = {
         M[a] - M[b],
         M[a] + M[b],
        -M[a] - M[b],
        -M[a] + M[b]
      };
      if (s[0] == X) {
        cout << a << ' ' << b << endl; return 0;
      }
      if (s[1] == X) {
        cout << b << ' ' << -a << endl; return 0;
      }
      if (s[2] == X) {
        cout << -a << ' ' << b << endl; return 0;
      }
      if (s[3] == X) {
        cout << b << ' ' << a << endl; return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

vll par;
ll root(ll x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
}
void unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
}
bool same(ll x,ll y) {
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
}

signed main(){
    llin(n);
    llin(m);
    llin(q);
    vllin3(a,b,c,q);
    par=vll(n,0);
    FOR(i,0,n-1){
        par[i]=i;
    }
    FOR(i,0,q-1){
        if(c[i]==0){
            unite(a[i],b[i]);
        }
    }
    ll u=0;
    FOR(i,0,q-1){
        if(c[i]==1){
            if(same(a[i],b[i])){
                sal("No")
                return 0;
            }
            u=1;
        }
    }
    ll t=0;
    FOR(i,0,n-1){
        if(par[i]==i) t++;
    }
    if((t*(t-1)/2>=(m-(n-t)))&(u==0|m>n-1)) sal("Yes")
    else sal("No")
}


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

int main() {
  int A, B, s, m, p;
  cin >> A >> B;
  s = A + B;
  m = A - B;
  p = A * B;
  int out;
  if(B >= 0){
    out = s;
  }else{
    out = m;
  }
  if(out < p){
    out = p;
  }
  cout << out;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[20000],b[20000],i;
	char op[20000];


	for(i=0;i<20000;i++){
		scanf("%d %c %d",&a[i],&op[i],&b[i]);
		if(op[i]=='?'){
			break;
		}
	}

	for(i=0;i<20000;i++){
		if(op[i]=='+'){
			printf("%d\n",a[i]+b[i]);
		}else if(op[i]=='-'){
			printf("%d\n",a[i]-b[i]);
		}else if(op[i]=='*'){
			printf("%d\n",a[i]*b[i]);
		}else if (op[i]=='/') {
			printf("%d\n",a[i]/b[i]);
		}else{
			break;
		}
	}

		return 0;
	}



Measured memory_bytes: 2088
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define endl "\n"


void solve(){
	int n; cin>>n;
	ll a[n], b[n], c[n];
	f(i,n) cin>>a[i]>>b[i]>>c[i];
	ff(i,1,n-1){
		a[i] += max(b[i-1],c[i-1]);
		b[i] += max(a[i-1],c[i-1]);
		c[i] += max(a[i-1],b[i-1]);
	}
	cout<<max(a[n-1],max(b[n-1],c[n-1]))<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

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

#define ll long long
            
int main() {
    int N;
    string S;
  
  	cin >> N;
    cin >> S;
  
    ll count = 0;
  
    ll r = 0;
    ll g = 0;
    ll b = 0;
  
    for (int i = 0; i < N; i++) {
        char s = S[i];
        if (s == 'R') {
            r++;
        } else if (s == 'G') {
            g++;
        } else {
            b++;
        }
    }
  
    for (int i = 0; i < N-2; i++) {
        for (int j = 0; j < N-i-2; j++) {
            int k = (j + i + 1) + ((j + i + 1) - i);
            char a = S[i];
            char b = S[j+i+1];
            char c = S[k];
            if (k < N) {
                if (a != b && b != c && c != a) {
                    count++;
                }
            }
        }
    }
  
    ll answer = (r * g * b) - count;
    cout << answer << endl;
  
    return 0;
}




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

int main(){
  int N;
  cin >> N;
  vector<int> Ai(N);
  
  for(int i=0;i < N; i++){
	cin >> Ai.at(i);
  }
  
  int lcn = 1;
  int tmp = Ai.at(lcn-1);
  int prelcn = 0;
  int count = 0;
  while(count < 100000){
  	if(tmp == 2) {
      count++;
      cout << count << endl;
      break;
    }else if(tmp == lcn || tmp == prelcn){
      cout << -1 << endl;
      break;
    }else{
      prelcn = lcn;
      lcn = tmp;
      tmp = Ai.at(tmp-1);
      count++;
    }
  }
  if(count == 100000) {
   	cout << -1 << endl; 
  }
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>

const int N=500005;
int a[N],d[N];
long long b[N];
int main(){
	int n,q;
	scanf("%d%d\n",&n,&a[0]);
	for (int i=1;i<=n;i++){
		scanf("%d",&d[i]);
		a[i]=std::min(a[i-1],abs(a[i-1]-d[i]));
	}
	for (int i=n;i>=1;i--)
		b[i]=(b[i+1]>=d[i]/2)*d[i]+b[i+1];
	scanf("%d\n",&q);
	for (int i=1;i<=q;i++){
		int x;
		scanf("%d",&x);
		if (b[x+1]>=a[x-1]) printf("NO\n");
			else printf("YES\n");
	}
}

Measured memory_bytes: 9728
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

constexpr int SIZE = 40;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, t;
  cin >> n >> t;
  vector<pll> v(n);
  REP(i, n) cin >> v[i].first >> v[i].second;
  vl dp(SIZE, INF * INF);
  auto comp = [&](pll lhs, pll rhs) {
    return rhs.first * (lhs.second + 1) < lhs.first * (rhs.second + 1);
  };
  sort(ALL(v), comp);
  dp[0] = 0;
  REP(i, n) {
    if (v[i].first == 0) {
      break;
    }
    RREP(j, SIZE - 1) {
      if (dp[j] <= t) {
        chmin(dp[j + 1], dp[j] + 1 + v[i].first * (dp[j] + 1) + v[i].second);
      }
    }
  }
  vl b;
  REP(i, n) {
    if (v[i].first == 0)
      b.push_back(v[i].second + 1);
  }
  sort(ALL(b));
  vl c(b.size() + 1);
  REP(i, b.size()) { c[i + 1] = c[i] + b[i]; }
  ll ans = -1;
  REP(i, SIZE) {
    if (dp[i] <= t) {
      int l = 0, r = c.size();
      while (r - l > 1) {
        int mid = (r + l) / 2;
        if (c[mid] > t - dp[i]) {
          r = mid;
        } else {
          l = mid;
        }
      }
      chmax(ans, i + l);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6640
n = int(input())
list = []
c1,c2,c3,c4 = 0,0,0,0
for i in range(0,n):
  list.append(input())
for j in range(0,n):
  if list[j] == "AC":
    c1 = c1+1
  if list[j] == "WA":
    c2 = c2+1
  if list[j] == "TLE":
    c3 = c3+1
  if list[j] == "RE":
    c4 = c4+1
print("AC x {}\nWA x {}\nTLE x {}\nRE x {}".format(c1,c2,c3,c4))

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

typedef long long int LLI;
typedef pair<int, int> Pair;
typedef pair<int, Pair> Edge;

int N;
LLI ans;
int par[114514];
int myrank[114514];
vector<Pair> xs;
vector<Pair> ys;
vector<Edge> es;

int find(int v) {
  if (par[v] == v) return v;
  return par[v] = find(par[v]);
}

int same(int u, int v) {
  return find(u) == find(v);
}

void unite(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  if (myrank[u] > myrank[v]) par[v] = u;
  else {
    par[u] = v;
    if (myrank[u] == myrank[v]) myrank[v]++;
  }
}

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    xs.emplace_back(Pair(x, i));
    ys.emplace_back(Pair(y, i));
    par[i] = i;
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  for (int i=1; i<N; i++) {
    es.emplace_back(Edge(xs[i].first-xs[i-1].first, 
         Pair(xs[i-1].second, xs[i].second)));
    es.emplace_back(Edge(ys[i].first-ys[i-1].first, 
         Pair(ys[i-1].second, ys[i].second)));
  }
  sort(es.begin(), es.end());
  for (auto &e : es) {
    int u, v;
    tie(u, v) = e.second;
    if (same(u, v)) continue;
    unite(u, v);
    ans += e.first;
  }
  printf("%lld\n", ans);
}
    
  

Measured memory_bytes: 7400
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;


int main() {
  int n;
  cin >> n;
  modint sum = 0;
  modint sum2 = 0;
  modint a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum2 += a[i]*a[i];
  }
  modint foreans = sum*sum - sum2;
  cout << foreans / 2 << endl;
}

Measured memory_bytes: 4368
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
	long long n,ans=1;
	const int mod=1000000007;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans*=i;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 100003
#define inf 1e18
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;

signed main()
{
    Arena
    
    int s;
    cin>>s;
    int x2=1e9, y2=1, x3,y3;
    cout<<"0 0 "<<x2<<' '<<y2;
    y3=(s+x2-1ll)/x2;
    x3=y3*x2 - s;
    cout<<' '<<x3<<' '<<y3;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(void){
  P x;
  x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int key(int m,int n){
  if(m<n) return m;
  else return n;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
    u=dequeue();
    c=key(q,u.t);
    u.t=u.t-c;
    elaps=elaps+c;
    if(u.t>0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 11940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int x = input.nextInt();
		int y = input.nextInt();
		long temp = x;
		
		while (true) {
			if (temp % y == 0) {
				System.out.println(temp);
				break;
			} else {
				temp += x;
			}
		}
	}
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ++mp[s];
  }
  
  /*auto fac = [&](ll n) {
    ll res = 0;
    for(ll a = 1; a <= n-1; ++a) {
      res += a;
    }
    return res;
  }; */
  
  ll ans = 0;
  for(auto i = mp.begin(); i != mp.end(); ++i) {
    ans += ll(i->second)*(i->second-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11424
import math

def main():
    a, b, c, d = list(map(int, list(input())))
    if a + b + c + d == 7:
        print('{}+{}+{}+{}=7'.format(a, b, c, d))
    elif a + b + c - d == 7:
        print('{}+{}+{}-{}=7'.format(a, b, c, d))
    elif a + b - c + d == 7:
        print('{}+{}-{}+{}=7'.format(a, b, c, d))
    elif a + b - c - d == 7:
        print('{}+{}-{}-{}=7'.format(a, b, c, d))
    elif a - b + c + d == 7:
        print('{}-{}+{}+{}=7'.format(a, b, c, d))
    elif a - b + c - d == 7:
        print('{}-{}+{}-{}=7'.format(a, b, c, d))
    elif a - b - c + d == 7:
        print('{}-{}-{}+{}=7'.format(a, b, c, d))
    elif a - b - c - d == 7:
        print('{}-{}-{}-{}=7'.format(a, b, c, d))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
N,K=map(int,input().split(" "))

if K == 0:
    print(N**2)
    exit()

b = K + 1
s = 0
while b <= N:
    c = N % b
    s += (N//b)*(b-K) + max(0,c-K+1)
    b += 1

print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


struct edge{
  int to;
  ll cost;
};

ll dist[100001];
vector<edge> ed[100001];

void dfs(int p, int x){//属性、親、自分
  for(edge e : ed[x]){
    if(e.to == p) continue;
    else{
      dist[e.to] = dist[x] + e.cost;
      dfs(x, e.to);
    }
  }
}

int main(){
  int n;
  cin >> n;
  rep(i, n-1){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    edge p = {b, c}, q = {a, c};
    ed[a].push_back(edge(p));
    ed[b].push_back(edge(q));

  }

  int q, k;
  cin >> q >> k;
  for(int i = 0; i < ed[k].size(); i++){
    dist[ed[k][i].to] = ed[k][i].cost;
    dfs(k, ed[k][i].to);
  }
  for(int i = 1; i <= q; i++){
    int x, y;
    cin >> x >> y;
    cout << dist[x] + dist[y] <<endl;
  }
}

Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;


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

    int N; 
    cin >> N;
    string next,siritori;
    vector<string> already;
    bool flag = false;
    REP(i,N){
        cin >> siritori;
        already.push_back(siritori);
    }
    siritori = already[0];
    REPP(i,1,N){
        next = already[i];
        if(siritori[siritori.length()-1] == next[0]){
            REP(j,i){
                if(next == already[j]){
                    flag = true;
                    break;
                }
            }
            siritori = next;
        }else{
            flag = true;
        }
        if(flag) break;
    }

    if(flag){ 
        cout << "No" << endl;
    }else{ 
        cout << "Yes" << endl;
        }
    return 0;
}

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

int main() {
	while(1){
		int H, W;
		cin >> H >> W;
		if ( H == 0 || W == 0) break;
		
		for ( int i = 0; i < H ;  i++){
			for ( int j = 0; j < W ; j++){
				if ( (i + j) % 2 == 0 ) cout << "#";
				else cout << ".";
			}
			cout << "\n";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3068
void main() {
	auto N = ri;
	ulong cnt;
	foreach(i; 0..N) {
		if(rs == "E869120") cnt++;
	}
	cnt.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n,m;cin >>n>>m;
    vector<ll>co(n,0);
    for (int i = 0; i < m; ++i) {
        ll a,b;cin >>a>>b;
        a--;b--;
        co[a]++;co[b]++;
    }
    bool flg=true;
    for (int i = 0; i < n; ++i) {
        if(co[i]%2==1)flg=false;
    }
    if(flg)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits, ascii_letters
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = INT()
B = INT()

ans = list(range(1, 4))

ans.remove(A)
ans.remove(B)

print(ans.pop())




Measured memory_bytes: 12508
function main (s) {
    s=s.split(" ");
	for(var i=0;i<2;i++)s[i]=parseInt(s[i]);
        if(s[0]==1)s[0]=16;
        if(s[1]==1)s[1]=16;
	if(s[0]===s[1])console.log("Draw\n");
	else if(s[0]>s[1])console.log("Alice\n");
	else console.log("Bob\n");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
x, y, a, b, c = gets.split.map(&:to_i)

p = gets.split.map(&:to_i)
q = gets.split.map(&:to_i)
r = gets.split.map(&:to_i)

red = p.max(x)
green = q.max(y)
result = (red + green + r.max(x+y))

puts result.max(x+y).inject(&:+)

Measured memory_bytes: 36008
//Optimize
#pragma GCC optimize("Ofast")

//Head File
#include<bits/stdc++.h>
using namespace std;

#define il inline

//Variable
#define ll long long
#define ull unsigned long long
#define db double
#define lb long double
#define ui unsigned int

//Debug
#define B cerr<<"Break Point"<<endl;
#define P(x) cerr<<#x<<' '<<"="<<' '<<(x)<<endl;
#define p(x) cerr<<#x<<' '<<"="<<' '<<(x)<<' ';
#define ml(x) cerr<<"Size of array is "<<x*4/1024/1024<<" MB"<<endl;

//Vector
#define vc vector
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define vbe(x) x.begin(),x.end()

//Memset
#define ms(x) memset(x,0,sizeof(x))
#define MS(x) memset(x,0x3f3f3f3f,sizeof(x))

//Pair
#define fi first
#define se second

//File

#define fin(x) freopen(x,"r",stdin)
#define fou(x) freopen(x,"w",stdout)
void fio()
{
    #ifndef ONLINE_JUDGE
    freopen("sample.in","r",stdin);
    freopen("sample.out","w",stdout);
    #endif
}
void pti()
{
    double timeuse = clock()*1000.0/CLOCKS_PER_SEC;
    cerr<<"Timeuse "<<timeuse<<"ms"<<endl;
}
void end()
{
    pti();
    exit(0);
}

//Inf
#define INF 0x3f3f3f3f
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))

//IO
#define pc(s) putchar(s)
#define say(s) cout<<s<<endl
namespace io
{
    const int SIZ=55;int que[SIZ],op,qr;char ch;
    template<class I>
    il void gi(I &w)
    {
        ch=getchar(),op=1,w=0;while(!isdigit(ch)){if(ch=='-') op=-1;ch=getchar();}
        while(isdigit(ch)){w=w*10+ch-'0';ch=getchar();}w*=op;
    }
    template<class I>
    il void print(I w)
    {
        qr=0;if(!w) putchar('0');if(w<0) putchar('-'),w=-w;while(w) que[++qr]=w%10+'0',w/=10;
        while(qr) putchar(que[qr--]);
    }
}
using io::gi;
using io::print;

const int N=105;

int n;
int a[N];

int main()
{
    gi(n);
    for(int i=1;i<=n;++i) gi(a[i]);
    bool flag=true;
    for(int i=1;i<=n;++i) if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0) flag=false;
    if(flag) say("APPROVED");
    else say("DENIED");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

const int MAX=30;
int edge[MAX][MAX];
int ans;
bool dd[MAX];
int x,y;

int is(){
  rep(i,x){
    if(dd[i])continue;
    bool tok=false;
    rep(j,x){
      if(!edge[i][j])continue;
      if(dd[j]){
	tok=true;
	break;
      }
    }
    if(!tok)return false;
  }
  return true;
}

void dfs(int vis,int dm){
  if(dm>=ans)return;
  if(vis==x && is()){
    ans=min(ans,dm);
    return;
  }else if(vis==x)return;
  
  dd[vis]=0;
  dfs(vis+1,dm);
  dd[vis]=1;
  dfs(vis+1,dm+1);
}
    

main(){
  while(cin>>x>>y,x|y){


    memset(edge,0,sizeof(edge));
    ans=x;
  
    rep(i,y){
      int to,from;
      cin>>to>>from;
      edge[to][from]=1;
      edge[from][to]=1;
    }

    dfs(0,0);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll //9223372036854775807
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
#define nl "\n"
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
//ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
ll inve(ll x){return x==1?1:(mod-mod/x)*inve(mod%x)%mod;}

const int N = 1e5+5;

char s[N];

int st[N],tot;

int main()
{
    scanf("%s",s);
    int l = strlen(s), ans = 0;
    st[0] = s[0]-'0';
    tot = 1;
    for(int i=1;s[i];i++)
    {
        if(tot == 0 || (s[i]-'0' == st[tot-1]))
            st[tot++] = (s[i]-'0');
        else
        {
           // cout<<i<<nl;
            ans += 2;
            tot--;
        }
    }
    cout<<ans<<nl;

    return 0;
}



Measured memory_bytes: 768
import sys
l1, l2 = [sys.stdin.readline().strip() for i in range(2)]
input_list = [int(i) for i in l2.split()]
input_list.sort(reverse=True)
odd_index = [j for i, j in enumerate(input_list) if i%2 != 0]
even_index = [j for i, j in enumerate(input_list) if i%2 == 0]
print(sum(even_index) - sum(odd_index))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e6 + 5 ; 
const int P = 1e9 + 7 ; 
int a, b, c, n, m, Ans, fac[N], inv[N] ; 
int fpow( int x, int k ) {
	int ans = 1, base = x ;
	while(k) {
		if( k & 1 ) ans = ans * base % P ; 
		base = base * base % P, k >>= 1 ; 
	} return ans % P ; 
}
int C( int x, int y ) {
	if( y > x || x < 0 || y < 0 ) return 0 ; 
	return fac[x] * inv[y] % P * inv[x - y] % P ; 
}
signed main()
{
	a = gi(), b = gi(), c = gi() ; 
	n = a + b + c, fac[0] = inv[0] = 1 ; 
	rep( i, 1, n ) fac[i] = fac[i - 1] * i % P, inv[i] = fpow( fac[i], P - 2 ) ;
	int f = 1, l = - c ; -- a ; 
	for( re int i = a; i < n; ++ i ) {
		int x = i - a ; 
		if( l > b ) break ; 
		Ans = ( Ans + f * C( i, a ) % P * fpow( 3, n - i - 1 ) % P ) % P ;
		f = ( f * 2 + P - C( x, b ) + P - C( x, l ) ) % P, ++ l ; 
	}
	printf("%lld\n", Ans % P ) ;
	return 0 ;
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
typedef long long int INT;


int main()
{
    int n;
    cin>>n;
    for (int i=1;i<=n;++i){
        int cnt=0;
        for (int x=1;x<=sqrt(n);++x){
            for (int y=1;y<=sqrt(n);++y){
                if ((x+y)*(x+y)-4*(x*x+y*y+x*y-i)>0){
                    double z1=(-(x+y)+sqrt((x+y)*(x+y)-4*(x*x+y*y+x*y-i)))/2;
                    double z2=(-(x+y)-sqrt((x+y)*(x+y)-4*(x*x+y*y+x*y-i)))/2;
                    if(floor(z1)==z1 && z1>=1){
                        cnt+=1;
                    }
                    if(floor(z2)==z2 && z2>=1){
                        cnt+=1;
                    }
                }
                else if((x+y)*(x+y)-4*(x*x+y*y+x*y-i)==0){
                    double z1=(-(x+y)+sqrt((x+y)*(x+y)-4*(x*x+y*y+x*y-i)))/2;
                    if(floor(z1)==z1 && z1>=1){
                        cnt+=1;
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3556
#include <stdio.h>

int main(void)
{
    int x, y, s;
    int zeikomi1, hontai1, sinzei1;
    int zeikomi2, hontai2, sinzei2;
    int i, j, k;
    int sum;
    int max;

    while (1){
        scanf("%d%d%d", &x, &y, &s);
        if (x == 0 && y == 0 && s == 0){
            break;
        }
        
        max = 0;
        for (i = 1; i <= s - 1; i++){
            zeikomi1 = i;
            hontai1 = (zeikomi1 + 1) * 100 / (100 + x);
            if (hontai1 * (100 + x) / 100 != zeikomi1){
                continue;
            }
            sinzei1 = hontai1 * (100 + y) / 100;

            zeikomi2 = s - i;
            hontai2 = (zeikomi2 + 1) * 100 / (100 + x);
            if (hontai2 * (100 + x) / 100 != zeikomi2){
                continue;
            }
            sinzei2 = hontai2 * (100 + y) / 100;

            if (max < sinzei1 + sinzei2){
                max = sinzei1 + sinzei2;
            }
        }
        printf("%d\n", max);
    }
    
    return (0);
}



Measured memory_bytes: 2112
import sys
readline = sys.stdin.buffer.readline

n=int(readline())*2

def extgcd(a,b):
	if b==0:
		return (a,1,0)
	else:
		g,y,x=extgcd(b,a%b)
		y-=a//b*x
		return (g,x,y)

def sub(p):
	q=n//p
	g,x,y=extgcd(p,q)
	if g==1:
		x=-x
		while x<=0:
			x+=q
			y+=p
		return x*p
	else:
		return 10**18

ans=10**18
d=1
while d*d<=n:
	if n%d==0:
		ans=min(ans,sub(d),sub(n//d))
	d+=1

print(ans)


Measured memory_bytes: 73188
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)1<<32;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int n;
int h[100];
int c[100];
int main() {
	cin >> n;
	rep(i, n)cin >> h[i];
	int ans = 0;
	rep(i, n) {
		int d = h[i] - c[i];
		ans += d;
		Rep(j, i, n) {
			d = min(d, h[j] - c[j]);
			c[j] += d;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main() {
  int n,t,ans = 0;
  cin >> n >> t;
  int a[n];
  REP(i,n) {
    cin >> a[i];
  }
  REP(i,n-1) {
    ans += min(a[i+1]-a[i],t);
  }
  ans += t;
  cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> P(N), Q(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> P.at(i);
  }
  for (ll i = 0; i < N; i++)
  {
    cin >> Q.at(i);
  }

  vector<ll> p(N);
  for (ll i = 0; i < N; i++)
  {
    p.at(i) = i + 1;
  }

  ll a = -1, b = -1;
  ll i = 1;
  do
  {
    bool ok = true;
    for (ll j = 0; j < N; j++)
    {
      if (p.at(j) != P.at(j))
      {
        ok = false;
        break;
      }
    }
    if (ok)
      a = i;

    ok = true;
    for (ll j = 0; j < N; j++)
    {
      if (p.at(j) != Q.at(j))
      {
        ok = false;
        break;
      }
    }
    if (ok)
      b = i;

    //cerr << a << " " << b << " " << i << endl;
    i++;
  } while (next_permutation(p.begin(), p.end()));

  cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
    int n, m;
    cin >> n >> m;
    vector<int>a(n), b(n);
    for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
    
    ll t = 999999999999;

    vector<ll>dp(m + 1, -t);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = m; j >= 0; j--) {
            if (j + b[i] <= m)dp[j + b[i]] = max(dp[j + b[i]], dp[j] + a[i]);
        }
    }
    ll an = 0;
    for (int i = 0; i <= m; i++)an = max(an, dp[i]);
    cout << an << endl;


    return 0;

}


Measured memory_bytes: 3172
import sys
N,M=map(int,input().split())
d=[set()for _ in range(N+1)]
def f(v,h,q):
 if d[v]&q:
  l=[]
  for x in h:
   l=[x]+l
   if x in d[v]:break
  L=[]
  while v!=x:
   for y in l:
    if v in d[y]:
     L=[v]+L
     v=y
     break
  print("\n".join(str(x)for x in[len(L)+1,x]+L));sys.exit()
 for u in d[v]:f(u,[u]+h,q|{u})
for _ in range(M):a,b=map(int,input().split());d[a].add(b)
v=0;exec("v+=1;f(v,[v],{v});"*N)
print(-1)

Measured memory_bytes: 87408
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <cmath>
             
using namespace std;
             
int main(){
  int N ,X;
  cin >> N >> X;
  vector<int> mvec(N);
  int msum, mmin;
  int ans;
  ans = 0;
  msum = 0;
  mmin = 10000000;
  for(int i = 0; i < N; i++){
    cin >> mvec[i];
  }
  
  for(int i = 0; i < N; i++){
    msum += mvec[i];
    mmin = min(mvec[i], mmin);
  }
  
  X -= msum;
  ans = N + X / mmin;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define to first
#define w second
#define int long long
using namespace std;
typedef pair<int,int> ii;

ii L[140000];
ii R[140000];
vector<ii> dp[140000];

int S = 0;

void dfs(int u){
	if(L[u].first == 0){
		dp[u].push_back(ii(0,0));
		return;
	}
	
	dfs(L[u].to);
	dfs(R[u].to);
	vector<ii> A = dp[L[u].to];
	vector<ii> B = dp[R[u].to];
	
	int AW = L[u].w;
	int BW = R[u].w;
	
	int limit = S - AW - BW;
	
	if(A.size() > B.size()){
		swap(A,B);
		swap(AW,BW);
	}
	vector<ii> &res = dp[u];
	vector<ii> temp;
	
	vector<ii> stuff;
	for(ii x : A){
		stuff.push_back(x);
		stuff.push_back(ii(x.second,x.first));
	}
	
	sort(stuff.begin(),stuff.end());
	int ptr = B.size() - 1;
	
	for(int i = 0;i < (int)stuff.size();i++){
		int x = stuff[i].first;
		
		while(ptr >= 0){
			if(B[ptr].first + x > limit) ptr--;
			else break;
		}
		
		if(ptr == -1) break;
		
		temp.push_back(ii(AW + stuff[i].second, BW + B[ptr].second));
		temp.push_back(ii(BW + B[ptr].second, AW + stuff[i].second));
	}
		
	sort(temp.begin(),temp.end());
	for(ii x : temp){
		if(res.empty()){
			res.push_back(x);
		}
		else if(res.back().second > x.second){
			res.push_back(x);
		}
	}
}

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	for(int i = 2;i <= n;i++){
		int p, w; cin >> p >> w;
		if(L[p].first != 0) R[p] = ii(i,w);
		else L[p] = ii(i,w); 
	}
	
	
	int low = -1, high = 1LL << 58;
	while(low != high - 1){
		S = (low + high) / 2;
		for(int i = 1;i <= n;i++) dp[i].clear();
		dfs(1);
		if(dp[1].size() >= 1) high = S;
		else low = S;
	}
	
	cout << high;
}





Measured memory_bytes: 43004
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1;
  string s2;
  cin>>s1>>s2;
  int l1=s1.length();
  int l2=s2.length();
  int c=0;
  for(int i=0;i<l1;i++)
  {
    if(s1[i]!=s2[i])
    {
      c++;
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 3912
n = int(input())
l0,l1 = 2,1
if n == 1:
    ans = l1
elif n == 2:
    ans = l0 + l1
else:
    for i in range(1,n):
        ans = l0 + l1
        l0 = ans
        l0,l1 = l1,l0
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main() {
    string s;
    cin>>s;
    int n = s.length(), ctr = 0;
    for (int i = 0; i < n; i++) {
        if (s[n - i - 1] != s[i])
            ctr++;
    }
    cout<<ctr/2;
    return 0;
}


Measured memory_bytes: 256
a=int(input())

t = list(map(int,input().split()))

memo = sum(t)

res = 10000000000000000
i = 0
while sum(t[i:])-sum(t[:i])>0:
    if i == 0:
        res = min(abs(sum(t[i:])-sum(t[:i])), res)
        i += 1
    else:
        i += 1
        res = min(abs(sum(t[i:])-sum(t[:i])), res)
print(res)

Measured memory_bytes: 38576
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
D,X = map(int,input().split())
A = [int(input()) for _ in range(N)]
 
from math import ceil
ans = 0
for i in range(N):
    ans += ceil(D/A[i])
 
print(ans+X)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

  ll n;
  cin >> n;
  string s;
  cin >> s;
  int C2_bunsi = 1, bunsi_cnt = 0;
  int cnt2[1000010] = {}, not2[1000010];
  not2[0] = 1;
  for (int i = 1; i <= n - 1; i++)
  {
    int j = i;
    while (j % 2 == 0)
    {
      j /= 2;
      bunsi_cnt++;
      cnt2[i]++;
    }
    not2[i] = j % 4;
    C2_bunsi = C2_bunsi * not2[i] % 4;
  }

  //

  int C2_bunbo = C2_bunsi, bunbo_cnt = bunsi_cnt;
  int coeff = 1;
  int k1 = n - 1, k2 = 1;
  int sum = 0;
  int C;
  rep(i, n)
  {
    if (bunsi_cnt - bunbo_cnt >= 2)
    {
      C = 0;
    }
    else if (bunsi_cnt - bunbo_cnt == 1)
    {
      C = 2;
    }
    else
    {
      if (C2_bunsi == C2_bunbo)
        C = 1;
      else
        C = 3;
    }

    int a = (s[i] - '0');
    sum += (C * a * coeff) % 4;
    sum %= 4;
    bunbo_cnt -= cnt2[k1];
    bunbo_cnt += cnt2[k2];
    C2_bunbo = C2_bunbo * not2[k1] * not2[k2] % 4;

    k1--, k2++;
    coeff = (4 - coeff) % 4;
  }
  if (sum == 0 || sum == 2)
  {
    int b[1000010];
    rep(i, n - 1)
    {
      b[i] = abs(s[i] - s[i + 1]);
      if (b[i] == 1)
      {
        cout << 0 << endl;
        return 0;
      }
      b[i] /= 2;
    }
    sum = 0;
    bunsi_cnt = 0;
    for (int i = 1; i <= n - 2; i++)
      bunsi_cnt += cnt2[i];
    bunbo_cnt = bunsi_cnt;
    k1 = n - 2, k2 = 1;
    rep(i, n - 1)
    {
      if (bunbo_cnt == bunsi_cnt)
      {
        C = 1;
      }
      else
      {
        C = 0;
      }
      sum += b[i] * C % 2;
      sum %= 2;
      bunbo_cnt -= cnt2[k1];
      bunbo_cnt += cnt2[k2];
      k1--, k2++;
    }
    cout << (sum == 0 ? 0 : 2) << endl;
  }
  else
  {
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 13084