akhauriyash/Code-Regression huggingface dataset:
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}
const int N = 1e5 + 6;
int cnt[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  Long sum = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    sum += x;
    ++cnt[x];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= 1LL * b * cnt[b];
    sum += 1LL * c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 4004
import math
n = int(input())

if n % 2 != 0:
  print(0)
elif n == 0:
  print(0)
else:
  #print(zerocnt(n))
  r = 0
  for i in range(int(math.log(n, 5))):
    r = r + (n // (5**(i+1))) // 2
  print(r)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
#define endl "\n"
#define FILEIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define LL long long 
#define mod 1000000007LL
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
//#define p push
#define I insert
#define bg begin()
#define ed end()
#define sz size()
#define all(v) v.begin(),v.end()
typedef vector<LL> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef map<LL ,LL > mii;
//typedef priority_queue<int> pq;
typedef queue<int>que;
typedef stack<int>stk;
#define Inf 100000005LL
#define f first
#define s second





vi vect_2pow;
void pow_of_2(){
    vect_2pow.assign(32,0);
      for(int i=0;i<=32;i++){
           LL y = 1<<i;
           vect_2pow[i]=y;
      }
}
bool Ispalindrome(string str){
        LL len = str.size();
		bool flag;
		for(int i=0;i<len/2;i++){
				if(str[i]==str[len-i-1])
				     {
						 flag=0;
						 continue;
					 }
					 else 
					    {
							flag=1;
							break;
						}
			}
		if (flag==1)
		  return false;
		else return true;  
		
}
vector<LL> prime_check;
mii get_high_prime;
int high_prime_factor(){
	//cout<<"ecd";
	LL max_prime=0;
	for(int i=2;i<100000;i++)
	{
		LL n=i;
		
		while(n%2==0)
		{
			max_prime=2;
			n>>=1;
		}
		for(int j=3;j<=sqrt(n);j++)
		{
			while(n%j==0){
				max_prime=j;
				n/=j;
			}
		}
		if(n>2)
		  max_prime=n;
		  
		//prime_check.pb(max_prime);
		get_high_prime[i]=max_prime;
	}
	
			
}

//const LL inf = 10e+9;
void max_self(LL &a,LL b){
	a=max(a,b);

}
const int maxi= 1e5+5;
vector<int> vect[maxi];
vector<int> dp(maxi);
vi indegre(maxi);
LL j=0;

vector<bool > visited(maxi);
void dfs(int k)
{
	assert(!visited[k]);
	visited[k]=true;
	for(auto x: vect[k])
	{
        dp[x]=max(dp[x],dp[k]+1);
		--indegre[x];
		if(indegre[x]==0)
		    dfs(x);
	}
}
int main()
{
	 
	int n , e;
	cin>>n>>e;
    //visited.assign(n+1,false);
	for(int i=0;i<e;i++)
	{
		int a,b;
		cin>>a>>b;
		vect[a].pb(b);
		++indegre[b];
		
	}
	for(int i=1;i<=n;i++)
	{
		if(!visited[i] && indegre[i]==0)
		    dfs(i);
		
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	   ans=max(ans,dp[i]);
	 cout<<ans<<endl;  
}

Measured memory_bytes: 9984
icase=0
if icase==0:
    n=int(input())
    c=[]
    s=[]
    f=[]
    for i in range(n-1):
        ci,si,fi=map(int,input().split())
        c.append(ci)
        s.append(si)
        f.append(fi)
elif icase==1:
    n=3
    c=[6,1]
    s=[5,10]
    f=[1,1]
elif icase==2:
    n=4
    c=[12,52,99]
    s=[24,16,2]
    f=[6,4,2]
elif icase==3:
    n=4
    c=[12,44,66]
    s=[13,17,4096]
    f=[1,17,64]

def nipf(ii,tt,s,f):
#    print(ii)
    if tt<=s[ii]:
        return 0
    else:
        n=(tt-s[ii]-1)//f[ii]+1
        return n

for i in range(n-1):
    tt=s[i]+c[i]
    for ii in range(i+1, n-1):
#        print("1: i:",i,"ii:",ii,"tt:",tt,"n-2:",n-2)
        nip=nipf(ii,tt,s,f)
#        print("2: i:",i,"ii:",ii,"tt:",tt,"nip:",nip)
        tt=s[ii]+c[ii]+nip*f[ii]
    print(tt)
print(0)   

Measured memory_bytes: 3188
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct P {
    int x, d;
}

void main() {
    int n, m;
    while (scanf("%d %d\n", &n, &m), n || m) {
        P[][] g = new P[][n];
        foreach (i; 0 .. n) {
            int k; scanf("%d", &k);
            foreach (j; 0 .. k) {
                int x, d; scanf(" %d %d", &x, &d);
                g[i] ~= P(x, d);
            }
        }
        int cache[150][10][100]; memset(cast(void*)cache, -1, cache.sizeof);
        int dfs(int y, int i, int m) {
            if (y == n) return 0;
            if (y == n - 1) return 0;
            if (cache[y][i][m] >= 0) return cache[y][i][m];
            int r = int.max;
            P c = g[y][i];
            if (m >= 1) {
                if (y + 2 == n) {
                    return 0;
                } else {
                    foreach (int j, s; g[y + 2]) {
                        r = min(r, abs(s.x - c.x) * (s.d + c.d) + dfs(y + 2, j, m - 1));
                    }
                }
            }
            foreach (int j, s; g[y + 1]) {
                r = min(r, abs(s.x - c.x) * (s.d + c.d) + dfs(y + 1, j, m));
            }
            return cache[y][i][m] = r;
        }
        int ans = int.max;
        if (m >= 1) {
            foreach (int i, _; g[1]) {
                ans = min(ans, dfs(1, i, m - 1));
            }
        }
        foreach (int i, _; g[0]) {
            ans = min(ans, dfs(0, i, m));
        }
        ans.writeln;
    }
}

Measured memory_bytes: 1896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void check(String[] data) {
        for (int i = 1; i < 14; i++) {
            if (data[i] == null) {
                System.out.printf("%s %d\n", data[0], i);
            }
        }
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // space ,clube, dia , heart
        String space[] = new String[14];
        String heart[] = new String[14];
        String clobe[] = new String[14];
        String dia[] = new String[14];

        space[0] = "S";
        heart[0] = "H";
        clobe[0] = "C";
        dia[0] = "D";
        // s,h,c,d
        try {
            int rep = Integer.parseInt(br.readLine());
            String data[] = new String[2];
            while (rep-- > 0) {
                data = br.readLine().split(" ");
                if (data[0].equals("S")) {
                    space[Integer.parseInt(data[1])] = "O";
                } else if (data[0].equals("H")) {
                    heart[Integer.parseInt(data[1])] = "O";
                } else if (data[0].equals("C")) {
                    clobe[Integer.parseInt(data[1])] = "O";
                } else if (data[0].equals("D")) {
                    dia[Integer.parseInt(data[1])] = "O";
                } else {
                    continue;
                }
            }
            check(space);
            check(heart);
            check(clobe);
            check(dia);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24740
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a[23333];
int main(){
	int n,aa=0,b=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n,greater<int>());
	for(int i=0;i<n;i++){
		if(i%2) aa+=a[i];
		else b+=a[i];
	}
	cout<<abs(aa-b)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  ll M;
  cin >>N>>M;
  vl vec;
 ll x=sqrt(M);
  //vec.push_back(1);
  repl(i,1,x+1) {
    if(M%i==0) {
      
      vec.push_back(M/i);
      vec.push_back(i);
    }
  }
  
  
  sort(all(vec));
 
  ll b=vec.size();
 //cout<<b<<endl;
  //cout<<vec.at(b-1)<<"A"<<vec.at(0)<<endl;
  per(i,b) {
    if(M/(vec.at(i))>=N) {
      cout<<vec.at(i)<<endl;
     break;
    }
  }
  
  
  
}
 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int N;
int main() {
  while (cin >> N && N>0) { //??????????????????????????????
    int A[N];
    A[0] = 1;
    for (int i=1; i<=N; ++i) { //A[n]????¨????
      A[i] = A[i-1];
      if (i>1) A[i] += A[i-2];
      if (i>2) A[i] += A[i-3];
    }
    cout << ((A[N]+9)/10+364)/365 << endl; //int??§????????¨???????????????????????????????¶??????¨???
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include<stdio.h>
#include<algorithm>
#define PI 3.14159265
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;

int main() {
	ll d,n;
	cin >> d >> n;
	if (n != 100) {
		cout << n * pow(100, d) << endl;
	}
	else if(d!=2){
		cout<< (n+1) * pow(100, d) << endl;
	}
	else {
		cout << "1010000" << endl;
	}

	return 0;
}

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

for i in range(N):
    if i%2 == 0:
        Amax += max(A)
        A.remove(max(A))
    else:
        Bmax += max(A)
        A.remove(max(A))

print(Amax - Bmax)


Measured memory_bytes: 2940
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 1


int mcxi_a(char *s){
	int sum = 0;
	int k = 1;
	for(;*s!='\0';s++){
		if( isdigit(*s) ){
			k = *s - '0';
		}else{
			switch(*s){
			  case 'm':
				sum += k*1000; break;
			  case 'c':
				sum += k*100; break;
			  case 'x':
				sum += k*10; break;
			  case 'i':
				sum += k; break;
			}
			k = 1;
		}
	}
	return sum;
}

int main(){
	int n;
	const char mozi[] = {'i','x','c','m'};
	char in1[16],in2[16];
	scanf("%d",&n);
	while(n--){
		scanf("%s %s",in1,in2);
		int sum = mcxi_a(in1) + mcxi_a(in2);
		string ans;
		int tmp = sum;
		int k = 0;
		while(sum>0){
			if( sum%10>0 ){
				ans += mozi[k];
			}
			k++;
			if( sum%10>1 ){
				ans += sum%10+'0';
			}
			sum/=10;
		}
		reverse(all(ans));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
def score(day, contest, prev_list, loss_list, satisfied_matrix):
    plus = satisfied_matrix[day][contest]
    minus = 0
    for type, prev in enumerate(prev_list):
        spend = day - prev
        minus += loss_list[type] * spend

    return plus - minus



days = int(input())
loss_list = list(map(int, input().split()))
satisfied_matrix = [list(map(int, input().split())) for _ in range(days)]

prev_list = [-1] * 26

total = 0
for day in range(days):
    contest = int(input())
    prev_list[contest-1] = day
    total += score(day, contest-1, prev_list, loss_list, satisfied_matrix)
    print(total)

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

using namespace std;

int GCD( int a, int b){
  if( b == 0){ return a;}
  else{ return GCD( b , a % b);}
}

int main(){
  int N; cin >> N;
  vector<int> A(N); for(int i = 0; i < N; i++){ cin >> A[i];}
  
  int g = A[0];
  
  for(int i = 0; i < N ; i++){
    
    g = GCD( g, A[i]);}
  
  cout << g << endl; return 0;}

Measured memory_bytes: 640
import sys
from heapq import heappop, heappush
readline = sys.stdin.readline


H,W = map(int,readline().split())
grid='#'*(W+2) + ''.join('#'+readline().strip()+'#' for _ in range(H)) + '#'*(W+2)
INF = 400
def shortest(grid, start, cost=0):
    dist = [INF] * (H+2)*(W+2)
    move=(-1,1,W+2,-W-2)
    st = [start]
    dist[start]=0
    while(st):
        sx = heappop(st)
        c=dist[sx]
        for a in move:
            x = sx + a
            if grid[x]=='#':
              continue
            dx = dist[sx] + 1
            if dist[x] <= dx:
                continue
            dist[x] = dx
            heappush(st, x)
    return max(x for x in dist if x < INF)

m=0
for i in range(W+3, (H+1)*(W+2)-1):
    if grid[i]=='#':
      continue
    tm = shortest(grid, i)
    if m < tm:
      m=tm
print(m)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  for(int i = 0; i < s.size(); i++){
    for(int j = 1; j <= k; j++){
      st.insert(s.substr(i, j));
    }
  }
  vector<string> v(st.begin(), st.end());
  sort(v.begin(), v.end());
  cout << v[k-1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int a[100],b[100];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<m;i++) cin>>b[i];
  sort(a,a+n);
  sort(b,b+m);
  int z=min(y,b[0]);
  if(max(x,a[n-1])<z) cout<<"No War";
  else cout<<"War";
}

Measured memory_bytes: 256
N = int(input())
s = input()
t = input()
ans = -1
for i in range(N):
    j = 0
    while i+j < N:
        if s[i+j] == t[j]:
            j += 1
        else:
            break
        
        if i+j == N:
            ans = i
            break
    
    if ans != -1:
        break

if ans != -1:
    print(len(s[:ans]+t))
else:
    print(len(s+t))

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC094A
{
    class Program
    {
        
            static void Main(string[] args)
            {



                var word = Console.ReadLine().Split();

            int a = int.Parse(word[0]);
            int b = int.Parse(word[1]);
            int c = int.Parse(word[2]);

            if (a > c)
                Console.WriteLine("NO");
            else if (a - c > b)
                Console.WriteLine("NO");
            else if (a + b < c)
                Console.WriteLine("NO");

            else
                Console.WriteLine("YES");


            Console.ReadKey();


            }
        }
    }

Measured memory_bytes: 11092
import std.stdio, std.conv, std.string, std.math;

void main()
{
  int input = to!int(chomp(readln()));
  int i = 1;
  if(input==1) {
    writeln(1);
    return;
  }
  while (pow(i, 2) <= input) {
    i++;
  }
  writeln(pow(i-1, 2));
}


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

using namespace std;

struct edge{
    int to, cost;
};

vector<edge> G[100000];
long dist[100000];
bool used[100000];

void dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge e = G[v][i];
        if(!used[e.to]){
            dist[e.to] = dist[v] + e.cost;
            dfs(e.to);
        }
    }
}

int main(){
    int N;
    cin >> N;
    for(int i = 0;i < N-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back((edge{v, w}));
        G[v].push_back((edge{u, w}));
    }
    dist[0] = 0;
    dfs(0);
    for(int i = 0; i < N; i++){
        if(dist[i]%2 == 0) cout << 0 << endl;
        else cout << 1 << endl;
    }
}

Measured memory_bytes: 8832
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll ans=INF;
int main(){
	//A,AB,BA,BAB
	ll x,y;
	scanf("%lld%lld",&x,&y);
	if(y>x)ans=min(ans,y-x);//A
	if(x+y<=0)ans=min(ans,-(x+y)+1);//AB
	if(x+y>=0)ans=min(ans,x+y+1);//BA
	if(y<x)ans=min(ans,x-y+2);//BAB
	printf("%lld\n",ans);
}

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

int main() {
	int N;
	cin >> N;
	vector<string> Spin(N);
	string ch;
	int c=1;
	
	for(int i=0;i<N;i++){
		cin >> Spin.at(i);
	}
	sort(Spin.begin(),Spin.end());
	ch = Spin.at(0);
	for(int i=0;i<N;i++){
		string dh = Spin.at(i);
		if(ch!=dh){
			ch = dh;
			c++;
		}
	}
	
	cout << c << endl;
}	


Measured memory_bytes: 9528
main = do
  _ <- getLine
  s <- getContents
  let v = map (map read . words) . lines $ s
  mapM_ (putStrLn . show . aux) v

aux :: [Double] -> Int
aux [xa,ya,ra,xb,yb,rb]
  | ab > ra + rb = 0
  | ab + rb < ra = 2
  | ab + ra < rb = -2
  | otherwise = 1      
  where ab = sqrt((xb-xa)^2 + (yb-ya)^2)

Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

template<class T>
ostream& operator<< (ostream& fout, const vector<T>& vec) {
  for (const auto& el : vec) {
    fout << el << ' ';
  }
  return fout;
}

template <class T>
istream& operator>> (istream& fin, vector<T>& vec) {
  for (size_t i = 0; i < vec.size(); ++i) {
    cin >> vec[i];
  }
  return fin;
}

int Solve() {
  int h, w;
  int n;
  cin >> h >> w >> n;
  vector<int> a(n);
  cin >> a;
  int cur = 0;
  vector<vector<int>> grid(h, vector<int> (w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[cur] == 0) cur++;
      grid[i][j] = cur + 1;
      a[cur] --;
    }
    if (i % 2 == 1) {
      std::reverse(grid[i].begin(), grid[i].end());
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      std::cout << grid[i][j] << ' ';
    }
    std::cout << '\n';
  }
  return 0;
}


int main() {
#ifndef LOCAL
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
#endif
#ifdef LOCAL
  //freopen("input.txt", "rt", stdin);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Solve();
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
int main() {
	int a,b,c;
	scanf("%1d%1d%1d", &a, &b, &c);
	if (a == 7 || b == 7 || c == 7) 
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

using namespace std;
typedef long long ll;
const int N=1e6+100;
vector <int>ve[N];
int n,m,k;
int a[15][N];
int main()
{
   scanf("%d%d%d",&n,&m,&k);
   for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
        scanf("%1d",&a[i][j]);
   int ans=1e9;
   for(int i=0;i<1<<(n-1);i++){
      vector<int>R;
      int now=0;
      R.push_back(0);
      for(int j=1; j<n; j++)
         if(i&1<<j-1) R.push_back(j);
      R.push_back(n);
      now+=R.size()-2;
      vector<int>cnt(R.size()-1,0);
      int isok;
      for(int j=1; j<=m;j++){
        isok=1;
        vector<int>cnt1(R.size()-1,0);
        for(int s=0; s<R.size()-1; s++){
            for(int l=R[s]+1; l<=R[s+1];l++)
                if(a[l][j]&1)cnt1[s]++;
            if(cnt1[s]>k) {isok=-1;break;}
            else if(cnt1[s]+cnt[s]>k) isok=0;
        }
        if(isok==-1)break;
        else if(isok==1)
            for(int l=0;l<R.size()-1;l++)
             cnt[l]+=cnt1[l];
        else now++,cnt=cnt1;
      }
      if(isok!=-1) ans=min(ans,now);
  }
  cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 45440
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e6+5;
const ll M=16;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
ll n,q,m,ans[N];
vector<ll> g[N];

void DFS(ll cur,ll par)
{
    ans[cur]+=ans[par];
    for(auto i:g[cur])
    {
        if(i==par){continue;}
        DFS(i,cur);
    }
}

int main()
{
    cin>>n>>q;
    ll m=n-1;
    while(m--)
    {
        ll u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    while(q--)
    {
        ll u,val;
        cin>>u>>val;
        ans[u]+=val;
    }
    DFS(1,0);
    for(ll i=1;i<=n;i++){cout<<ans[i]<<" ";}
}

Measured memory_bytes: 44672
#include<stdio.h>

int main()
{	
	int a, b;
	scanf("%d %d",&a, &b);
	if(a > b)
	{
		printf("a > b\n");
	} 
	else if(a == b)
	{
		printf("a == b\n");
	}	
	else
	{
	printf("a < b\n");
	}
		return 0;
	
} 


Measured memory_bytes: 2556
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin>>n;
    int cnt=0;
    n--;
    deque<char> q;
    while(n>=0){
        q.push_front((char)'a'+(n%26));
        n/=26;
        n--;
    }
    while(!q.empty()){
        cout<<q.front();
        q.pop_front();
    }
    cout<<endl;
}


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

using namespace std;

#define int long long 

signed main(){

  string s;
  int n;

  cin >> n;

  cin >> s;

  int ans = 0;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'I') cnt++;
    else cnt--;

    ans = max(cnt, ans);
  }
  cout << ans << endl;
  
  return 0;
}


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

int main(void){
    
    ll s, w;
    
    cin >> s >> w;
    
    if(w>=s){
        
        cout << "unsafe" << endl;
        
    } else {
        
        cout << "safe" << endl;
        
    }
    
    return 0;
    
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int a,b;

main() {
    cin >> a >> b;
    if (b<0) {
        if (abs(a-b)%2) ct("Positive")
        else ct("Negative")
    } else if (a>0) ct("Positive")
    else ct("Zero")
}


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

int main() {
  int n,a,b;
  string s;
  cin>>n>>a>>b>>s;
  int p=0,q=0;
  for(int i=0;i<n;i++){
    if(s[i]=='a'){
      if(p+q<a+b){
        cout<<"Yes"<<endl;
        p++;
      }
      else{
        cout<<"No"<<endl;
      }
    }
    if(s[i]=='b'){
      if(p+q<a+b&&q<b){
        cout<<"Yes"<<endl;
        q++;
      }
      else{
        cout<<"No"<<endl;
      }
    }
    if(s[i]=='c'){
      cout<<"No"<<endl;
    }
  }
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second


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

    ll n , m , a=1 , b;
    cin >> n >> m;

    vector< pair<int,int> > ans;

    if (n%2)
    {
        a = n/2 , b = a+1;
        for(int i=1; i<=m; i++)
        {
            cout << a << ' ' << b << '\n';
            a-- , b++;
        }
    }
    else
    {
        a=1 , b=n/2;
        for(int i=1; i<=m; i++)
        {
            if (b > a) cout << a++ << ' ' << b-- << '\n';
            else
            {
                a = n/2+1 , b=n-1;
                cout << a++ << ' ' << b-- << '\n';
            }
        }
    }

    return 0;
}

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

void judgment(char me, char enemy, int &g_count, int &p_count, int &score);

int main(void){
    string s;
    cin >> s;
    int g_count = 0, p_count = 0, score = 0;
    char me;

    for(int i = 0; i < s.length(); ++i){
        me = p_count + 1 <= g_count ? 'p' : 'g';
        if(p_count + 1 > g_count) {
            me = 'g';
        }

        judgment(me, s.at(i), g_count, p_count, score);
    }

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

void judgment(char me, char enemy, int &g_count, int &p_count, int &score){
    if(me == 'g') {
        g_count++;
        if(enemy == 'p') {
            score--;
        }
    } else {
        p_count++;
        if(enemy == 'g') {
            score++;
        }
    }
}

Measured memory_bytes: 512
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n,m,h,K;
	while(cin>>n>>m>>h>>K,n){
		vint v(n);
		set<pii> se;
		rep(i,n) cin>>v[i];
		vector<pii> w(m);
		rep(i,m) cin>>w[i].S>>w[i].F,w[i].S--;
		sort(ALL(w));
		vint pos(n);
		rep(i,n) pos[i]=i;
		rep(i,m){
			se.insert(minmax(pos[w[i].S],pos[w[i].S+1]));
			swap(pos[w[i].S],pos[w[i].S+1]);
		}
		int ans=0;
		vint score(n);
		rep(i,n){
			if(pos[i]<K){
				ans+=v[i];
			}
			score[pos[i]]=v[i];
		}
		int tmp=0;
		for(pii x:se){
			if(x.F<K&&x.S>=K){
				tmp=max(tmp,score[x.F]-score[x.S]);
			}
		}
		cout<<ans-tmp<<endl;
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
  	cout<<fixed<<setprecision(0);
    mainmain();
}

Measured memory_bytes: 2640
<?php
	$n = trim( fgets( STDIN ) );
	$thScore = array_fill( 0, 2, 0 );
	while( $n-- ) {
		$th = explode( " ", trim( fgets(STDIN) ) );
		if( $th[0] < $th[1] ) {
			$thScore[1] += 3;
		} else if( $th[0] > $th[1] ) {
			$thScore[0] += 3;
		} else {
			$thScore[0] += 1;
			$thScore[1] += 1;			
		}
	}
	print $thScore[0]." ".$thScore[1];
?>

Measured memory_bytes: 15448
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2236
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

map<char, int> mp;
string s;

void solve() {
    char t[30];
    
    if(s.size() == 26) {
        for(int i = 0; i < 26; i++) t[i] = s[i];
        if(!next_permutation(s.begin(), s.end())){
            cout << -1 << endl;
            return;
        }
        for(int i = 0; i < 26; i++) {
            cout << s[i];
            if(s[i] != t[i]) break;
        }
        cout << endl;
    }
    else{
        for(int i = 0; i < s.size(); i++) {
            mp[s[i]]++;
        }
        cout << s;
        for(char c = 'a'; c <= 'z'; c++) {
            if(mp[c] == 0) {
                cout << c << endl;
                break;
            }
        }
    }
}

int main() {
    cin >> s;
    solve();
}

Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    string[] ipt = Console.ReadLine().Split(' ');
    int N = int.Parse(ipt[0]);
    int M = int.Parse(ipt[1]);
    int[] arr = new int[N];
    bool[] result = new bool[N];
    ipt = Console.ReadLine().Split(' ');
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(ipt[i]);
      result[i] = true;
    }
    for (int i = 0; i < M; i++) {
      ipt = Console.ReadLine().Split(' ');
      int A = int.Parse(ipt[0]);
      int B = int.Parse(ipt[1]);
      if (arr[A-1] <= arr[B-1]) {
        result[A-1] = false;
      }
      if (arr[B-1] <= arr[A-1]) {
        result[B-1] = false;
      }
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
      if (result[i]) {
        count++;
      }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 51704
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N, M;
  cin>>N>>M;
  pair<int, int> p[M], pp[M];
  map<int, int> look;
  REP(i, M){
    cin>>p[i].first>>p[i].second;
    pp[i].first = p[i].first;
    pp[i].second = p[i].second;
    look[p[i].second] = i;
  }
  int bangou[M];
  sort(pp, pp+M);

  int work=1;
  bangou[look[pp[0].second]] = 1;
  REP(i, M-1){
    if(pp[i+1].first == pp[i].first){
      ++work;
      bangou[look[pp[i+1].second]]=work;
    }
    else{
      work=1;
      bangou[look[pp[i+1].second]]=work;
    }
  }

  int w;
  REP(i, M){
    w=look[p[i].second];
    printf("%06d%06d\n", p[w].first, bangou[i]);
  }

  return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a == b ? c : b == c ? a : b) << endl;
	return 0;
}
 

Measured memory_bytes: 256
x,n = map(int,input().split())
if n==0:
  print(x)
  exit()
ls = list(map(int,input().split()))

ls = sorted(ls)
d = 10**3
ans = 0
for i in range(ls[0]-1,ls[-1]+2):
  if i in ls:
    continue
  if d>abs(i-x):
    d = abs(i-x)
    ans = i
print(ans)



Measured memory_bytes: 9192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		boolean yet[] = new boolean[30];
		Arrays.fill(yet, true);

		for(int i=0; i<28; i++){
			yet[Integer.parseInt(br.readLine()) - 1] = false;
		}
		for(int i=0; i<30; i++){
			if(yet[i]){
				System.out.println(i+1);
			}
		}
	}
}

Measured memory_bytes: 24168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		A = new int[N];
	}

	public boolean hasNext() {
		return cnt < N;
	}

	int[] A;
	int First = 1;
	int Second = 1;

	public void readBody(String str) {
		// System.out.println(str);
		int a = Integer.parseInt(str);
		A[cnt] = a;
		if (First < a)
			First = a;
		else if (Second < a)
			Second = a;
		cnt++;
	}

	public void solve() {
		for (int i = 0; i < N; i++) {
			if (A[i] == First)
				System.out.println(Second);
			else
				System.out.println(First);
		}
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0 ; i < n; i++){
    cin >> a[i];
    if (a[i] == 0){
      cout << 0 << endl;
      return 0;        
    }
  }
  float ansf = 1;
  ll ans = 1;
  for (int i = 0; i < n ; i++){
    ans *= a[i];
    ansf *= a[i];
    if (ans > 1000000000000000000 || ansf > 1000000000000000000 ){
      cout << -1 << endl;
      return 0;
    }
    if (ans < 0){
      cout << -1 << endl;
      return 0;
    }
  }  
  cout << ans << endl;
}


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

bool dfs(int x, int y) {
    if (x<=1 && y<=1) return false;
    int res = false;
    for (int i=1; 2*i<=x; i++) res |= not dfs(x-2*i, y+i);
    for (int j=1; 2*j<=y; j++) res |= not dfs(x+j, y-2*j);
    return res;
}

bool table[5][5];
int X, Y;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    rep(i, 5) rep(j, 5) table[i][j] = dfs(i, j);
    //rep(i, 5) {
        //rep(j, 5) cout << table[i][j] << " ";
        //cout << endl;
    //}
    cin >> X >> Y;
    if (abs(X-Y)<=1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
}

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

int main() {
  long long int N, K;
  cin>>N>>K;
  vector<pair<long long int, long long int>> ab(N);
  for(int i; i<N; i++) {
    long long int a, b;
    cin>>a>>b;
    ab.push_back(make_pair(a, b));
  }
  sort(ab.begin(), ab.end());
  long long int r=0, ans=0, i=0;
  while(r<K) {
    r+=ab[i].second;
    ans=ab[i].first;
    i++;
  }
  cout<<ans;
  return 0;
}



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

int main() {
  int a,b,x;
  cin >> a>>b>>x;
 
    cout<<(a+b)*x/2<<endl;
  
  
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    
    bool flag = false;
    for(int i = 0; i < s.size() - 1; i++) {
        if(s[i] == s[i + 1]) {
            flag = true;
        }
    }
    
    if(flag) {
        cout << "Bad" << endl;
    }
    else {
        cout << "Good" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>

int main(int argc, char const* argv[])
{
	int n;
	std::map<char,std::array<bool,13>> card;
	std::array<char,4> marks{'S','H','C','D'};

	for (auto&& m : marks) {
		for (int i = 0; i < 13; i++) {
			card[m][i] = true;
		}
	}

	std::cin >> n;
	for (int i = 0; i < n; i++) {
		char mark;
		int rank;
		std::cin >> mark >> rank;
		card[mark][rank-1] = false;
	}
	for (auto&& m : marks) {
		for (int i = 0; i < 13; i++) {
			if (card[m][i])
				std::cout << m << " " << i+1 << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;



int main() {
	string s;
	cin >> s;
	
	int n = s.size()-1;
	
	ull ans = 0;
	
	for (int tmp = 0; tmp < (1 << n); tmp++) {
		
		string m[10];
		int j = 0;
		bitset<10> t(tmp);
		ull sum = 0;

		for (int i = 0; i < n+1; i++) {
			if (i>0 && t[i-1]) j++;
			m[j] += s[i];
			
		}
		
		for (int i = 0; i <= j; i++) {
			ull a = stoull(m[i]);
			//cout << "/" << a << endl;
			sum += a;
		}
		
		ans += sum;
		//cout << sum << endl;
	}
	cout << ans << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

void solve(long long H, long long W, vector<string> a){
	vs red,blue;

	string buf = "";
	REP(i,W)buf+='.';

	red.resize(H,buf);
	blue.resize(H,buf);

	// REP(i,H){
	// 	red[i][0] = '#';
	// 	blue[i][W-1] = '#';
	// }

	REP(h,H){
		REP(w,W){
			if(h % 2 == 0){
				red[h][w] = '#';
			}else{
				blue[h][w] = '#';
			}

			if(a[h][w] == '#'){
				red[h][w] = '#';
				blue[h][w] = '#';
			}
		}

		red[h][0] = '#';
		red[h][W-1] = '.';
		blue[h][W-1] = '#';
		blue[h][0] = '.';
	}

	REP(h,H){
		REP(w,W){
			cout << red[h][w];
		}
		cout << endl;
	}

	cout << endl;

	REP(h,H){
		REP(w,W){
			cout << blue[h][w];
		}
		cout << endl;
	}
}



int main(){	
	ios::sync_with_stdio(false);
	long long W;
	long long H;
	cin >> H;
	vector<string> a(H-1+1);
	cin >> W;
	for(int i = 0 ; i <= H-1 ; i++){
		cin >> a[i];
	}
	solve(H, W, a);
	return 0;
}


Measured memory_bytes: 1792
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 
const ll inf=1e18+1e17;
const ll mod=1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
/*ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}*/
const ll N =2e5+5;

void solve(){
	int n;
	cin>>n;
	ll x;
	cin>>x;
	ll tot=0;
	for ( int i=0;i<n-1;i++){
		ll y;
		cin>>y;
		tot=(tot+x*y)%mod;
		x=(x+y)%mod;
	}
	cout<<tot<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, K;
	cin >> N >> K;
	ll ma;
	if(N%2==0) ma = N/2;
	else ma = (N/2)+1;
	cout << (K<=ma?"YES":"NO") << endl;
    return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  ll ans = INF;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    ll cost = 0;
    ll tmpHeight = a[0];
    vector<ll> b = a;
    for (int i = 1; i < N; i++)
    {
      if (bit & (1 << i))
      {
        if (a[i] <= tmpHeight)
        {
          b[i] = tmpHeight + 1;
          cost += b[i] - a[i];
          tmpHeight++;
        }
        else
        {
          b[i]++;
          cost++;
          tmpHeight = b[i];
        }
      }
      else
      {
        if (a[i] > tmpHeight)
          tmpHeight = a[i];
      }
    }
    int num = 1;
    ll nowHeight = a[0];
    for (int i = 1; i < N; i++)
    {
      if (b[i] > nowHeight)
      {
        nowHeight = b[i];
        num++;
      }
    }
    if (num >= K)
      ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		sc.close();
		for (i = 0; i < n; i++) {
			out.print(s[i]);
			out.print(t[i]);
		}
		out.println();
	}
}


Measured memory_bytes: 21716
def mx(p,w,h,l):
	if h <= c/2:
		if w == 0: p[h][w] += p[h-1][w]
		elif w == l-1: p[h][w] += p[h-1][w-1]
		else: p[h][w] += max(p[h-1][w],p[h-1][w-1])
	else:
		p[h][w] += max(p[h-1][w],p[h-1][w+1])
	return p

c = 0
p = []
while True:
	try:
		p.append(map(int, raw_input().split(",")))
		c += 1
	except:
		break
	
for h in range(1,c):
	l = len(p[h])
	for w in range(l):
		p = mx(p,w,h,l)
print p[c-1][0]

Measured memory_bytes: 4312
//
//  main.cpp
//  atcoder
//
//  Created by Jonathan Bramley on 6/2/19.
//  Copyright © 2019 Jonathan Bramley. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    a--;b--;c--;d--;
    
    string s; cin >> s;
    

        while(a < c) {
            if ((a+1 == b && s[a+2]=='#') || (a+2 == b&& s[a+1]=='#')) {
                if(s[b+1] == '.') b+=1;
                else if(b+2<n && s[b+2] == '.') b+=2;
                else {
                    cout<<"No"<<endl;
                    return 0;
                }
            } else if(s[a+1] == '.') a+=1;
            else if(a+2<n&&s[a+2] == '.') a+=2;
            else {
                cout<<"No"<<endl;
                return 0;
            }
        }
        while(b < d) {
            if ((b+1 == a && s[b+2]=='#') || (b+2 == a&& s[b+1]=='#')) {
                cout<<"No"<<endl;
                return 0;
            } else if(s[b+1] == '.') b+=1;
            else if(b+2<n&&s[b+2] == '.') b+=2;
            else {
                cout<<"No"<<endl;
                return 0;
            }
        }

    if(b==d && a==c) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 644
#include <iostream>

using namespace std;

int main() {
  int N, Y;
  cin >> N >> Y;

  bool can_continue = true;
  int l = 0;
  // 10,000
  for (int i = 0; i <= N; i++) {
    if (!can_continue) {
      break;
    }
    // 5,000
    for (int j = 0; j <= N; j++) {
      l++;
      if (l % 1000000 == 0) {
        //cout << l << " times" <<endl;
      }
      if (!can_continue) {
        break;
      }
      int diff = N - i - j;
      int sum = 10000 * i + 5000 * j + 1000 * diff;
      //cout << i << " " << j << " " << diff << " " << sum << endl;
      if (diff >= 0 && 10000 * i + 5000 * j + 1000 * diff == Y) {
        cout << i << " " << j << " " << diff << endl;
        can_continue = false;
      }
    }
  }
  if (can_continue) {
    cout << "-1 -1 -1" << endl;
  }
}


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

int main(){
    int n;
    cin>>n;
    int a;
    set<int> s;
    for(int i=0;i<n;i++){
        cin>>a;
        s.insert(a);
    }
    
    cout << s.size() << endl;
    
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a_input = list(map(int,input().split()))

'''
k=4,a_input=[5,2,4,1]の場合を考える
5 2 4 1 5 2 4 1 5 2 4 1 5 2 4 1 

例えば、4に着目すると
5 2 [4] <1> |5 <2> 4 <1> |5 <2> 4 <1> |5 <2> 4 <1>
1 + 2 + 2 + 2
1 + 2 + 2
1 + 2
1 + 0
で総数を求めることができる
左側の1は(a内の右側でa_i>a_jの個数)*k

それ以外は等差数列の和として
(初項+最終項)*項数/2
= n*(k-1)*k/2
で求めることができる

あとは各数字ごとにこれを足し合わせる
'''
ans=0
for i in range(n):
    tmp1=0#内部の個数
    tmp2=0#a列全体の個数
    for j in range(n):
        if i==j:
            continue
        if j>=i+1:
            if a_input[i]>a_input[j]:
                tmp1+=1
        if a_input[i]>a_input[j]:
            tmp2+=1
    ans+=tmp1*k
    ans+=tmp2*(k-1)*k//2
print(ans%(10**9+7))

Measured memory_bytes: 3188