akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';
	return !f?x:-x;
}

const int N=200+19;
const int p=998244353;

struct Point{
	int x,y;
	bool operator < (const Point &B) const{
		return x<B.x||x==B.x&&y<B.y;
	}
} P[N],Pt;
typedef Point Vector;

int dp[N][N],val[N][N],val2[N][N],pw2[N];
int n,ans;

Vector operator - (Point A,Point B){
	return (Vector){
		A.x-B.x,A.y-B.y
	};
}
ll cross(Vector A,Vector B){
	return 1ll*A.x*B.y-1ll*A.y*B.x;
}
bool cmp(Point A,Point B){
	return cross(A-Pt,B-Pt)>0;
}

void Work(vector<Point> V){
	int n=V.size();
	memset(dp,0,sizeof(dp));
	memset(val,0,sizeof(val));
	memset(val2,0,sizeof(val2));
	sort(V.begin()+1,V.end(),cmp);
	For(i,1,n) For(j,i+1,n){
		For(k,1,n) if (k!=i&&k!=j&&cross(V[i]-V[0],V[k]-V[0])>=0&&cross(V[j]-V[i],V[k]-V[i])>=0){
			ll tmp=cross(V[k]-V[0],V[j]-V[0]);
			if (tmp>0) val[i][j]++;
			lf (tmp==0) val2[i][j]++;
		}
		val[i][j]=pw2[val[i][j]];
		val2[i][j]=pw2[val2[i][j]];
	}
	For(i,1,n) dp[0][i]=1;
	For(i,0,n) For(j,i+1,n) if (dp[i][j]){
		For(k,j+1,n) if (cross(V[j]-V[i],V[k]-V[j])>0){
			dp[j][k]=(dp[j][k]+1ll*val[j][k]*dp[i][j])%p;
		}
	}
	For(i,1,n) For(j,i+1,n)
		if (cross(V[j]-V[i],V[0]-V[j])>0){
			ans=(ans+1ll*val2[i][j]*dp[i][j])%p;
		}
}

int main(){
	pw2[0]=1;
	For(i,1,N) pw2[i]=2ll*pw2[i-1]%p;
	n=IN();
	For(i,1,n+1) P[i]=(Point){IN(),IN()};
	sort(P+1,P+n+1);
	For(i,1,n+1){
		Pt=P[i];
		vector<Point> V;
		For(j,i,n+1) V.pb(P[j]);
		Work(V);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 896
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [-a for a in list(map(int, input().split()))]

sumA = -sum(A)
heapify(A)

for _ in range(M):
    a = -heappop(A)
    sumA -= a-a//2
    heappush(A, -(a//2))

print(sumA)

Measured memory_bytes: 68260
import sys
in1 = sys.stdin.readlines()

#in1 = ['5','7 2 3 8 5','3','4 2','1 7','4 13']

N = int(in1[0])
T_N = list(map(int, in1[1].split()))
M = int(in1[2])
P_M = [None] * M
X_M = [None] * M
idx1 = 0
for PX in in1[3:]:
    P_M[idx1], X_M[idx1] = map(int, PX.split())
    idx1 += 1

sumT = sum(T_N)
for idx1 in range(M):
    print(sumT - T_N[P_M[idx1] - 1] + X_M[idx1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18,INF=1<<30;

int main(){
    
    int K,N;cin>>K>>N;
    if(K%2==0){
        cout<<K/2;
        for(int i=1;i<N;i++){
            cout<<" "<<K;
        }
        cout<<endl;
    }else if(K==1){
        for(int i=0;i<(N+1)/2;i++){
            cout<<1<<" ";
        }
        cout<<endl;
    }else{
        vector<int> A(N,(K+1)/2);
        for(int i=0;i<N/2;i++){
            int now=N-1;
            while(1){
                if(A[now]>=2){
                    A[now]--;
                    for(int j=now+1;j<N;j++){
                        A[j]=K;
                    }
                    break;
                }else if(A[now]==1){
                    A[now]=-1;
                    break;
                }else{
                    now--;
                }
            }
        }
        for(int i=0;i<N;i++){
            if(A[i]!=-1){
                cout<<A[i]<<" ";
            }else break;
        }
        cout<<endl;
    }
}



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

using namespace std;

const int N = 1e5+100;

long long int a[N];

bool win[N];

int main () {
    long long int n, k;
    cin >> n >> k;
    for(int i = 0 ; i < n ; i++ ) cin >> a[i];
    sort(a,a+n);
    for(int i = a[0] ; i <= k ; i++ ) {
        bool who = 0;
        for(int j = 0 ; j < n ; j++ ) {
            if(i-a[j]>=0) who|=(!(win[i-a[j]]));
        }
        win[i]=who;
    }
    cout << ((win[k])?"First":"Second");
}


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

int n,m,l,r,d,pos[100010]={0},maks,mins;
vector<pair<int,int> > v[100010];
bool vi[100010]={0};
stack<int> act;

bool dfs(int x) {
	vi[x] = 1;
	act.push(x);
	for (auto c:v[x]) {
		int nx = c.first, rpos = pos[x]+c.second;
		if (vi[nx] && pos[nx] != rpos) {
			return false;
		} else {
			pos[nx] = rpos;
			maks = max(maks, rpos);
			mins = min(mins, rpos);
		}
		if (!vi[nx]) {
			if (!dfs(nx)) return false;
		}
	}
	return true;
}

int main()
{
	cin >> n >> m;
	while (m--) {
		cin >> l >> r >> d;
		v[l].push_back({r, d});
		v[r].push_back({l, -d});
	}
	for (int i=1;i<=n;++i) {
		if (!vi[i]) {
			maks = -2e9-10;
			mins = 2e9+10;
			while (!act.empty()) {
				pos[act.top()] = 0;
				act.pop();
			}
			if (!dfs(i) || maks-mins>1000000000) {
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 12544
n = int(input())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
cnt = 0
for i in range(1, n+1, 2):
    if len(make_divisors(i)) == 8:
        cnt +=1
print(cnt)


Measured memory_bytes: 9128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
#define cint(...) ll __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__);

int main() {
	char a;
	char b;
	cin >> a >> b;
	if (a < b) cout << "<" << endl;
	if (a > b) cout << ">" << endl;
	if (a == b) cout << "=" << endl;
}

Measured memory_bytes: 256
def solve(a,M):
	for x,y in xy:
		if x in a and (y not in a or a.index(x) > a.index(y)):
			break
	else:
		if len(a) == m: return a
		for i in range(len(M)):
			r =  solve([M[i]] + a,M[:i]+M[i+1:])
			if r:
				return r

m = input()
xy = [map(int,raw_input().split()) for i in range(input())]
M = range(m)
ans = solve([],range(1,m+1))
for i in ans: print i

Measured memory_bytes: 4236
N=int(input())
S=input()
x=len([s for s in S[1:] if s=='E'])
x_min=x

for i in range(1,N):
	if S[i-1]=='W':
		x+=1
	if S[i]=='E':
		x-=1
	if x<x_min:
		x_min=x

print(x_min)

Measured memory_bytes: 6304
from typing import List


class Dice:

    def __init__(self, s: List[int]):
        self.s = s

    def get_s(self) -> int:
        return self.s[0]

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
            return None
        if mkey == 'N':
            self.N()
            return None
        if mkey == 'E':
            self.E()
            return None
        if mkey == 'W':
            self.W()
            return None
        raise ValueError(f'This method does not exist. : {mkey}')

    def set_s(self, s0, s1, s2, s3, s4, s5) -> None:
        self.s[0] = s0
        self.s[1] = s1
        self.s[2] = s2
        self.s[3] = s3
        self.s[4] = s4
        self.s[5] = s5

    def S(self) -> None:
        self.set_s(self.s[4], self.s[0], self.s[2], self.s[3], self.s[5],
                   self.s[1])

    def N(self) -> None:
        self.set_s(self.s[1], self.s[5], self.s[2], self.s[3], self.s[0],
                   self.s[4])

    def E(self) -> None:
        self.set_s(self.s[3], self.s[1], self.s[0], self.s[5], self.s[4],
                   self.s[2])

    def W(self) -> None:
        self.set_s(self.s[2], self.s[1], self.s[5], self.s[0], self.s[4],
                   self.s[3])


# 提出用
data = [int(i) for i in input().split()]
order = list(input())

# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('SE')

dice = Dice(data)
for o in order:
    dice.invoke_method(o)
print(dice.get_s())



Measured memory_bytes: 7180
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> x(n), y(n); for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];

  auto fn = [&](double sx, double sy) -> double {
    V<double> dist;
    for (int i = 0; i < n; ++i) {
      dist.push_back(hypot(x[i] - sx, y[i] - sy));
    }
    sort(rbegin(dist), rend(dist));
    return accumulate(begin(dist), begin(dist) + k, 0.0);
  };

  auto calc = [&](double sx) -> double {
    double ly = -1e3, ry = 1e3;
    for (int _ = 0; _ < 100; ++_) {
      double ml = (2 * ly + ry) / 3, mr = (ly + 2 * ry) / 3;
      if (fn(sx, ml) < fn(sx, mr)) {
        ry = mr;
      } else {
        ly = ml;
      }
    }
    return ly;
  };

  double lx = -1e3, rx = 1e3;
  for (int _ = 0; _ < 100; ++_) {
    double ml = (2 * lx + rx) / 3, mr = (lx + 2 * rx) / 3;
    if (fn(ml, calc(ml)) < fn(mr, calc(mr))) {
      rx = mr;
    } else {
      lx = ml;
    }
  }
  cout << fixed << setprecision(15) << fn(lx, calc(lx)) << '\n';
}


Measured memory_bytes: 3384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int k = in.nextInt();
            if (a > b) {
                int temp = b;
                b = a;
                a = temp;
            }
            if (b > c) {
                int temp = c;
                c = b;
                b = temp;
            }
            long ans = c * (1l << k) + a + b;
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	ll t;
	//cin>>t;
	t=1;
	while(t--)
	{
	  ll n;
	  cin>>n;
	  ll a[n+1]={0};
	  ll k;
	  cin>>k;
	  for(ll i=0;i<k;i++)
	  {
	      ll x;
	      cin>>x;
	      for(ll j=0;j<x;j++)
	      {
	          ll y;
	          cin>>y;
	          a[y]++;
	      }
	  }
	  ll c=0;
	  for(ll i=1;i<=n;i++)
	  if(a[i]==0)
	  c++;
	  cout<<c;
	}
	return 0;
}

Measured memory_bytes: 3636
using System;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            //a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            c = int.Parse(str[1]);
            int res;
            if(b > 12) res = c;
            else if(b > 5) res = c/2;
            else res = 0;

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    def judge():
        res = True
        prev = input()
        used = set()
        used.add(prev)
        for _ in range(N - 1):
            cur = input()
            if prev[-1] != cur[0]:
                res = False
            if cur in used:
                res = False
            used.add(cur)
            prev = cur

        return res

    if judge():
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
int  a,b,c,d;
cin >> a >>b >> c >>d ;
if(a == c) cout << 0 << endl;
else cout << 1 << endl;
}


Measured memory_bytes: 3600
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll N;
	cin >> N;

	if (N == 3) {
		cout << 2 << " " << 3 << " " << 25 << endl;
		return 0;
	}
	vector<ll> results;

	ll num_3 = 2;
	for (; num_3 + 2 <= N - 2 && num_3 + 2 <= 5000; num_3 += 2);
	for (ll i = 0; i < num_3; ++i) {
		results.emplace_back(i * 6 + 3);
	}

	N -= num_3;
	for (ll i = 0; i < N / 3; ++i) {
		results.emplace_back(i * 6 + 2);
		results.emplace_back(i * 6 + 4);
		results.emplace_back(i * 6 + 6);
	}
	if (N - 3 * (N / 3) == 1) {
		results.emplace_back((N / 3) * 6 + 6);
	}
	else if (N - 3 * (N / 3) == 2) {
		results.emplace_back((N / 3) * 6 + 2);
		results.emplace_back((N / 3) * 6 + 4);
	}

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

	for (ll i = 0; i < results.size(); ++i) {
		cout << results[i];
		if (i + 1 != results.size()) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 640
//
// Created by kuribohkute on 20/04/2019.
//
#include <unordered_map>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define mp make_pair
#define X first
#define Y second
const int N = 200005;
int n;
int f[N];
bool deter[N];
vector <int> e[N];
int res = 1;
void dfs(int u, int p) {

    int mx1 = -1, mx2 = -1;
    f[u] = 1;
    vector<int>b;
    for (auto v: e[u]) {
        if (v != p) {
            dfs(v, u);
            f[u] = max(f[u], f[v] + 1);
            res = max(res, f[v] + 1);

            if (f[v] > mx1) {
                if (mx1 != -1) {
                    mx2 = mx1;
                }
                mx1 = f[v];
            } else {
                if (f[v] > mx2) {
                    mx2 = f[v];
                }
            }
        }
    }
    res = max(res, mx1 + mx2 + 1);
}
int main () {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1, 0);
    deter[1] = 1;
    deter[2] = 0;
    for (int i = 3; i < N; i++) {
        deter[i] = !(deter[i - 1] & deter[i - 2]);
    }
//    cout << res << "\n";
    if (deter[res]) {
        cout << "First";
    } else {
        cout << "Second";
    }
    return 0;
}


Measured memory_bytes: 27136
n = int(input())
a = list(map(int, input().split()))
temp0 = a[0]
result = 0
for i in range(n-1):
    temp1 = a[i+1]
    if(temp0>temp1):
        result+=(temp0-temp1)
    else:
        temp0 = temp1
print(result)
    

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

 
int main() {
  int n;cin>>n;
  vector<tuple<string,int,int>> a;
   for (size_t i = 0; i < n; i++)
   {
    string x;
    int y;
    cin>>x>>y;
    a.push_back(make_tuple(x,-y,1+i));
    
  }  
  sort(a.begin(),a.end());
  
  for (int i = 0; i<n; i++)
  {
    /* code */
    cout<<get<2>(a[i])<<endl;
  }
  
}   

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 3030;



int n, m;
string s;
int a[maxn];
int b[maxn];
ll dp[maxn][maxn];//# ways to fill first i elems, holding j 1's



void add(ll& x, ll y) {
    x %= mod;
    y %= mod;
    x += y;
    x %= mod;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m;
    cin>>s;
    for (int i=0; i<n; i++) {
	a[i]=(s[i]-'0');
	b[i]=i+1;
    }

    for (int i=0; i<m; i++) {
	int l,r; cin>>l>>r;
	--l; --r;
	b[l]=max(b[l],r+1);
    }

    for (int i=1; i<n; i++) {
	b[i]=max(b[i],b[i-1]);
    }

    dp[0][0]=1;
    for (int i=0, j=0; i<n; i++) {
	int ones = 0;
	while (j<b[i]) ones+=a[j++];

	for (int x=0; x<=n; x++) {
	    if (dp[i][x] == 0) continue;
	    int cur=x+ones;

	    //put 1 at ith index
	    if (cur>0) {
		add(dp[i+1][cur-1], dp[i][x]);
	    }

	    // put 0 at ith index
	    if (cur < j-i) {
		add(dp[i+1][cur], dp[i][x]);
	    }
	}
    }

    ll ans = dp[n][0];
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout<<ans<<endl;
  

    return 0;
}


Measured memory_bytes: 70272
// abc121_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n,m,c;
  cin>>n>>m>>c;
  vi b(m);
  int a;
  ll sum,cnt=0;
  rep(i,m){
    cin>>b.at(i);
  }

  rep(i,n){
    sum=0;
    rep(j,m){
      cin>>a;
      sum+=a*b.at(j);
    }
    sum+=c;
    if (sum>0)cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

int main(){
  ll k,x;
  cin>>k>>x;
  rep(i,x-k+1,x+k) cout<<i<<' ';
}


Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9

typedef pair<int, int> pos;
pos operator+(const pos &lhs, const pos &rhs) {
    pos p = { lhs.first + rhs.first,lhs.second + rhs.second };
    return p;
}
pos dir[4] = {
    { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 }
};

int main() {
    int H, W, cnt = 0;
    cin >> H >> W;
    vector<vector<char>>s(H + 2, vector<char>(W + 2, '#'));
    for (int i = 1; i < H+1; i++) {
        for (int j = 1; j < W + 1; j++) {
            cin >> s[i][j];
            if (s[i][j] == '.')cnt++;
        }
    }
    vector<vector<int>>distance_(H + 2, vector<int>(W + 2, 0));
    

    pos start = make_pair(1, 1), goal = make_pair(H, W);
    queue<pos>q;
    q.push(start);

    while (!q.empty()){
        pos now = q.front(); q.pop();
        if (now == goal)break;
        for (int i = 0; i < 4; i++) {
            pos next = now + dir[i];
            if (s[next.first][next.second] == '.'&&distance_[next.first][next.second] == 0) {
                distance_[next.first][next.second] = distance_[now.first][now.second] + 1;
                q.push(next);
            }
        }
    }

    if (distance_[H][W] != 0) {
        cout << cnt - distance_[goal.first][goal.second] - 1 << endl;
    }
    else {
        cout << - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val t = readLine()!!

    var dup = 0
    for (i in 1..n) {
        if (s.takeLast(i) == t.take(i)) {
            dup = Math.max(i, dup)
        }
    }
    println(n * 2 - dup)
}




Measured memory_bytes: 31820
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 19/07/2017 14:48:22
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ull unsigned long long
using namespace std;

int main(){
	int a, b;
	cin>>a>>b;
	if((a+b) % 3 == 0 || a%3 == 0 || b % 3 == 0)  cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b;
    cin>>a>>b;
    for (int i=0;i<max(a,b);++i)
    {
        cout<<min(a,b);
    }
    return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
  power = 1.0
  
  n = int(input())
  
  for i in range(n):
    power *= (i + 1)
    if power / (10**9 + 7) >= 1.0:
        power %= (10**9 + 7)

  result = power % (10**9 + 7)
  
  print(int(result))

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();
		int B = in.nextInt();
		int C = in.nextInt();
		int D = in.nextInt();
		int E = in.nextInt();
		int F = in.nextInt();
		
		int maxW = 1;
		int maxS = 0;
		
		for(int i=0;i*100*A<=F;i++) {
			for (int j = 0; i*100*A + j*100*B <=F ; j++) {
				int water = i*100*A + j*100*B;
				for (int k = 0; 
						k*C*100 <= E*water
						&& water + k*C <= F; 
						k++) {
					for (int l = 0; 
							(k*C*100 + l*D*100 <= E*water) 
							&& water + k*C + l*D <= F;
							l++) {
						int suger = k*C + l*D;
						if(maxS *(water+suger) <= suger*maxW){
							maxW = water + suger;
							maxS = suger;
						}
					}
				}
			}
		}
		System.out.println(maxW+" "+maxS);
	}

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

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

int main()
{
	char a;
	int english[26] = { 0 };

	while (cin >> a) {//EOF終了
		if ('A' <= a&&a <= 'Z') {//大文字なら
			english[a - 'A']++;
		}
		else if ('a' <= a&&a <= 'z') {//小文字なら
			english[a - 'a']++;
		}
	}

	//出力
	for (char b = 'a'; b <= 'z'; b++) {
		cout << b << " : " << english[b - 'a'] << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
#define ll long long
#define trace(x) cerr << #x << " = " << x << endl
using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("ouput.txt","w",stdout);
    #endif 

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--){
         int x;
	 cin>>x;
	 if(x>=30)
		 cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3608
s = gets.chomp
if s.size < 26
    puts s + ("a".."z").to_a.find{|v| !s.include?(v)}; exit
end
x = s[-1]
y = x
(s.size-1).times.reverse_each{|v|
    if y < s[v]
        y = s[v]; next
    end
    puts s[0...v] + s[v..-1].chars.select{|c| s[v] < c}.sort[0]; exit
}
puts -1

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli l,r;
	cin>>l>>r;

	/*lとrの間に2019の倍数があれば0が答え*/
	/*ない場合はl%2019 * (l+1)%2019が答え*/

	/*
	lli min2019 = l/2019 * 2019;
	lli max2019 = r/2019 * 2019;
	if(l <= min2019 && min2019 <= r){
		cout<<0<<endl;
		return 0;
	}
	if(l<=max2019 && max2019 <= r){
		cout<<0<<endl;
		return 0;
	}
	cout<< ((l%2019)*((l+1)%2019)) %2019 <<endl;
	*/

	/*100000000000通りくらいやれば答えが出るはずなのでそれで行う*/
	const lli cntMax = 100000000;
	lli cnt=0;
	lli ans=INF;
	for(lli i=l;i<=l+2030;i++){
		if(i>r-1)break;
		for(lli j=l+1;j<=l+1+2030;j++){
			if(j>r)break;
			lli tmp = (i * j) %2019;
			ans = min(ans,tmp);
			if(ans==0)break;
			cnt++;
			if(cnt>cntMax)break;
		}
		if(ans==0)break;
		if(cnt>cntMax)break;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
int a,b; cin>>a>>b;
 
int arr[]={0,300000, 200000,100000};
int sum=0;
  if(a>3) a=0;
  if(b>3) b=0;
  sum+=(arr[a]+arr[b]);
  if(a==1 and b==1) sum+=400000;
  cout<<sum;
  

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) (lld)((a).size())
#define all(c) (c).begin(),(c).end()             
typedef long double ldb;
typedef long long lld;
const lld MOD = 1e9+7;
const lld INF = 1011111111;
const lld LLINF = 1000111000111000111LL;
const ldb EPS = 1e-10;
const ldb PI = 3.14159265358979323;
using namespace std;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
const lld N = 100005;
lld fact[N], invfact[N],sum[N];
lld fact_pre() {
    fact[0] = invfact[0] = 1;
    rep(i,1,N) fact[i] = (fact[i-1]*i)%MOD, invfact[i] = powm(fact[i],MOD-2);
}
lld a[N];
lld get(lld l,lld r) {
    if(l>r) return 0;
    return (sum[r]-sum[l-1]+MOD)%MOD;
}
int32_t main() {
    fact_pre();
    sum[0] = 1;
    rep(i,1,N) sum[i] = (sum[i-1] + powm(i,MOD-2))%MOD;
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    lld n;
    cin>>n;
    rep(i,1,n+1) cin>>a[i];
    lld ret = 0;
    rep(i,1,n+1) {
        lld curr = (get(1,n-i+1) + get(2,i))%MOD;
        curr = (curr * a[i])%MOD;
        ret = (ret + curr)%MOD;
    } 
    ret = (ret * fact[n])%MOD;
    cout<<ret;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 3e5 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 8e17 + 51;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

gp_hash_table <string, int> mp, mp1;

bool cmp (string s, string s1) {
    if (mp[s] == mp[s1]) return s < s1;
    return mp[s] > mp[s1];
}

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <string> s;
    for (int i = 0; i < n; i++) {
        string s1;
        cin >> s1;
        s.pb(s1);
        mp[s1]++;
    }
    sort(s.begin(), s.end(), cmp);
    int kol = mp[s[0]];
    for (auto to : s) {
        if (mp1[to] == 0 && mp[to] == kol) {
            mp1[to] = 1;
            cout << to << "\n";
        }
    }

}


Measured memory_bytes: 49320
#!/usr/bin/python

n = int(input())
t = input().split()
a = []
for c in t:
    a.append(int(c))

# hash
h = {}
for v in a:
    if v in h:
        h[v] += 1
    else:
        h[v] = 1
total = 0
for k in h.values():
    if k > 1:
        total += (k*(k-1)//2)

for c in a:
    aa = total
    if h[c] > 1:
        aa -= (h[c]*(h[c]-1)//2)
    if h[c] > 2:
        aa += ((h[c]-1)*(h[c]-2)//2)
    print(aa)


Measured memory_bytes: 91212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

long double dp[3001][3001]; //dp[i][j] = i枚目までで表がj枚出る確率

int main() {
    int N;
    cin >> N;
    vector<long double> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }    
    for(int i = 0;i < 3001;i++) {
        for(int j = 0;j < 3001;j++) {
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < 3000;j++) {
            dp[i + 1][j + 1] += dp[i][j] * vec.at(i);
            dp[i + 1][j] += dp[i][j] * (1 - vec.at(i));
        } 
    }
    long double ret = 0;
    for(int i = N / 2 + 1;i <= N;i++) {
        ret += dp[N][i];
    }
    cout << fixed;
    cout << setprecision(20) << ret << endl;
}

Measured memory_bytes: 144572
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

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

    int cnt = 0;
    rep(i, s.size()) if(s[i] != t[i]) cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3816
from collections import Counter

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

Asum = [0]*N
Asum[0] = A[0]
for i in range(1,N):
    Asum[i] = A[i]+Asum[i-1]

ans = 0
counter = Counter([0])
counter.update(Asum)
counts = counter.most_common()

for count in counts:
    if count[1] < 2:
        break
    else:
        ans += count[1]*(count[1]-1)//2

print(ans)

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

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

    cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;
vector<vector<int>> to;
vector<int> ans;

void dfs(int v, int p = -1) {
  for(int u: to[v]) {
    if(u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int N, Q; cin >> N >> Q;
  to.resize(N);
  rep(i, N-1) {
    int a, b; cin >> a >> b; a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  ans.resize(N);

  rep(i, Q) {
    int p, x; cin >> p >> x;
    p--;
    ans[p] += x;
  }

  dfs(0);

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

  return 0;
}


Measured memory_bytes: 23424
#include <cstdio>
long long n, x, s, d, a[100005];
int main() {
    scanf("%d%d%d", &n, &x, &a[0]);
    for (int i=1; i<n; i++) {
        scanf("%d", &a[i]);
        d = a[i] + a[i-1] - x;
        if (d>0) a[i] -= d, s += d;
        if (a[i]<0) a[i-1] += a[i], a[i] = 0;
    }
    printf("%lld", s);
    return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
int prime[1000001];
int dp[1000001];
int dat[30];
int main(){
	prime[0]=-1;
	prime[1]=-1;
	for(int i=2;i<=1000000;i++){
		if(~prime[i]){
			prime[i]=1;
			for(int j=i*2;j<=1000000;j+=i)prime[j]=-1;
		}
	}
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			scanf("%d",dat+i);
		}
		for(int j=0;j<=b;j++)dp[j]=0;
		dp[0]=1;
		for(int i=0;i<a;i++){
			for(int j=0;j<=b;j++){
				if(dat[i]<=j&&dp[j-dat[i]])dp[j]=1;
			}
		}
		bool dame=true;
		for(int j=b;j>=0;j--){
			if(prime[j]==1&&dp[j]==1){
				dame=false;
				printf("%d\n",j);
				break;
			}
		}
		if(dame)printf("NA\n");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    ll N , M , X;
    cin >> N >> M >> X;
    vector<vector<ll>> data(N, vector<ll>(M + 1));
    rep(i, N) {
        rep(j, M + 1) {
            cin >> data.at(i).at(j);
        }
    }

    ll min_c = 100000000;
    for(int bit = 0; bit < (1 << N); bit++) {
        bitset<12> S(bit);

        vector<ll> tmp(M + 1);
        rep(i, N) {
            if(S.test(i)) {
                vector<ll> V = data.at(i);
                rep(j, M + 1) {
                    tmp.at(j) += V.at(j);
                }
            }
        }

        bool flg = true;
        repi(i, 1, M + 1) {
            if(tmp.at(i) < X) {
                flg = false;
            }
        }
        if(flg) {
            min_c = min(tmp.at(0), min_c);
        }
    }

    cout << (min_c == 100000000 ? -1 : min_c) << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

#define MAX 2000001
#define VMAX 10000

int main() {
  unsigned short *A, *B;

  int C[VMAX + 1];
  int n;
  scanf("%d", &n);

  A = (unsigned short *)malloc(sizeof(short) * n + 1);
  B = (unsigned short *)malloc(sizeof(short) * n + 1);

  for ( int i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( int i = 0; i < n; i++ ) {
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( int i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( int j = 1; j <= n; j++ ) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( int i = 1; i <= n; i++ ) {
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 11052
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
s = gets.chomp

def valid?(s, ans, i)
  (s[i-1] == 'o' && ans[i-1] == 'S') || (s[i-1] == 'x' && ans[i-1] == 'W')
end

def solve(n, s, ans)
  2.upto(n-1) do |i|
    if valid?(s, ans, i)
      ans[i] = ans[i-2]
    else
      ans[i] = ans[i-2] == 'S' ? 'W' : 'S'
    end
  end
end

['SS', 'SW', 'WS', 'WW'].each do |sw|
  ans = ' ' * n
  ans[0] = sw[0]
  ans[1] = sw[1]
  solve(n, s, ans)
  if ((valid?(s, ans, 0) && ans[-2] == ans[0]) || (!valid?(s, ans, 0) && ans[-2] != ans[0])) &&
     ((valid?(s, ans, 1) && ans[-1] == ans[1]) || (!valid?(s, ans, 1) && ans[-1] != ans[1]))
    puts ans
    exit
  end
end

puts -1


Measured memory_bytes: 15116
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define All(x) (x).begin(), (x).end()
#define lowbit(x) ((x) & -(x))
using namespace std;
inline int read()
{
	int 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;
}
inline ll read1()
{
	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;
}
const ll mod = 1e9 + 7;
const int N = 4e6 + 10;
const db pi = acos(-1);
//int a[N];
int main()
{
	int n = read();
	vi a(n);
	rep0(i, n) a[i] = read();
	int q = read();
	while(q --)
	{
		int x = read();
		int y = read();
		reverse(a.begin() + x, a.begin() + y);
	} 
	rep0(i, n)
	{
		if(i) cout << " ";
		cout << a[i];
	}
	puts("");
	return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,K;
	int d,a;
	int cnt=0;
	cin>>N>>K;
	static vector<bool> okashi_have(N);
	for(int i=0;i<K;i++){
		cin>>d;
		for(int j=0;j<d;j++){
			cin>>a;
			okashi_have[a]=true;
		}
	}
	for(int i=1;i<=N;i++)
		if(!okashi_have[i]) cnt++;
	cout<<cnt<<endl;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
string IntToString(ll num){
  string res;stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}

bool check(ll lb,ll mid,ll base,ll s,int i){
  ll fiz1=(lb)/3;
  ll buz1=(lb)/5;
  ll fizbuz1=(lb)/15;
  ll fiz2=(mid)/3;
  ll buz2=(mid)/5;
  ll fizbuz2=(mid)/15;
  ll difiz=fiz2-fiz1;
  ll dibuz=buz2-buz1;
  ll difizbuz=fizbuz2-fizbuz1;
  ll cnt=(mid-lb);
  ll tmp=base+cnt*i+(difiz+dibuz)*4-(difiz+dibuz-difizbuz)*i;
  return s<=tmp;
}
ll getCnt(ll lb,ll mid,ll base,ll s,int i){
  ll fiz1=(lb)/3;
  ll buz1=(lb)/5;
  ll fizbuz1=(lb)/15;
  ll fiz2=(mid)/3;
  ll buz2=(mid)/5;
  ll fizbuz2=(mid)/15;
  ll difiz=fiz2-fiz1;
  ll dibuz=buz2-buz1;
  ll difizbuz=fizbuz2-fizbuz1;
  ll cnt=(mid-lb);
  ll tmp=base+cnt*i+(difiz+dibuz)*4-(difiz+dibuz-difizbuz)*i;
  return tmp;
}


int main(){
  ll s;
  cin>>s;
  ll cur=0;
  ll curLen=0;
  ll add=9;
  ll prvTmp;
  int i;
  for(i=1;;i++){
    ll fiz1=(cur)/3;
    ll buz1=(cur)/5;
    ll fizbuz1=(cur)/15;
    ll fiz2=(cur+add)/3;
    ll buz2=(cur+add)/5;
    ll fizbuz2=(cur-1+add)/15;
    ll difiz=fiz2-fiz1;
    ll dibuz=buz2-buz1;
    ll difizbuz=fizbuz2-fizbuz1;
    ll tmp=add*i+(difiz+dibuz)*4-(difiz+dibuz-difizbuz)*i;
    curLen+=tmp;
    cur+=add;
    add*=10;
    prvTmp=tmp;
    if(curLen>s)break;
  }
  ll ub=cur;
  ll lb=(cur/10);
  ll base=curLen-prvTmp;
  while(ub-lb>1){
    ll mid=(ub+lb)/2;
    if(check(cur/10,mid,base,s,i))ub=mid;
    else lb=mid;
  }
  ll a=getCnt(cur/10,ub-1,base,s,i);
  int pos=0;
  for(int i=1;;i++){
    if(a+i==s){
      pos=i;
      break;
    }
  }
  string res;
  for(int i=0;i<20;i++){
    if((ub+i)%15==0)res+="FizzBuzz";
    else if((ub+i)%3==0)res+="Fizz";
    else if((ub+i)%5==0)res+="Buzz";
    else{
      res+=IntToString(ub+i);
    }
  }
  for(int i=pos-1;i-pos+1<20;i++)cout<<res[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1220
<?php

fscanf(STDIN, "%d", $n);
$k = 1;
$ans = [];
$sum = 0;
if ($n % 2 == 1) {
    echo 0;
    exit;
}
for ($i = 10; $i <= $n; $i *= 5) {
    $ans[] = intdiv($n, $i);
}
//rsort($ans);
//$count = count($ans);
//$buff = 0;
//foreach($ans as $value){
//    $sum += $value - $buff) * $count;
//}

echo array_sum($ans);

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

using ll = long long;
void update(vector<ll> &bit, int x, ll t) {
  for (; x < (int)bit.size(); x = (x|(x+1))) {
    bit[x] = max(bit[x], t);
  }
}

ll query(const vector<ll> &bit, int x) {
  ll res = 0;
  for (; x >= 0; x = (x & (x + 1)) - 1) {
    res = max(res, bit[x]);
  }
  return res;
}

int main() {

  int n;
  cin >> n;
  vector<int> h(n), a(n);
  int max_h = 0;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
    max_h = max(h[i], max_h);
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<ll> bit(max_h, 0);
  ll ans = a[0];
  update(bit, h[0], ans);
  for (int i = 1; i < n; ++i) {
    ll prev_max = query(bit, h[i]-1);
    ans = max(ans, a[i] + prev_max);
    update(bit, h[i], a[i] + prev_max);
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 6404
#include <iostream>
#include <string>
using namespace std;
bool isAlpha(char c){
	return ('a' <= c && c <= 'z');
}
char getShift(char c, int v){
	if (0 == v) return c;
	return char('a' + int(c + v + 26 - 'a') % 26);
}
int getShiftIndex(string& line){
	int s = line.size();
	string::size_type ps = 0, pe = 0;
	while (true){
		while (ps < s && !isAlpha(line[ps])) ++ps;
		pe = ps;
		while (pe < s && isAlpha(line[pe])) ++pe;
		if (ps >= s || pe >= s)
			break;
		int len = pe - ps;
		if (3 == len){
			if(	   line[ps] == getShift(line[ps + 1], 12)
				&& line[ps] == getShift(line[ps + 2], 15))
				return int('t' - char(line[ps]));
		}
		else if (4 == len){
			if(	   line[ps] == getShift(line[ps + 1], 12)
				&& line[ps] == getShift(line[ps + 2], 11)
				&& line[ps] == getShift(line[ps + 3], 1))
				return int('t' - char(line[ps]));
			if (   line[ps] == getShift(line[ps + 1], 12)
				&& line[ps] == getShift(line[ps + 2], 19)
				&& line[ps] == getShift(line[ps + 3], 0))
				return int('t' - char(line[ps]));
		}
		ps = pe;
	}
	return -1;
}

int main()
{
	string line;
	while (std::getline(cin, line)){
		int s = line.size();
		int v = getShiftIndex(line);
		for (int i = 0; i < s; ++i){
			char c = line[i];
			if (isAlpha(c)) cout << getShift(c, v);
			else cout << c;
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long int a,za,shu,s=0;
	cin>>a;
	za=sqrt(a);
	for(int i=za;i>0;--i)
	{
		if(a%i==0)
		{
			shu=a/i;
			break;
		}
	}
	while(shu>0)
	{
		++s;
		shu/=10;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include<iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int dat[16][16];
	int n;
	while(cin>>n,n){
		rep(i,n){
			rep(j,n){
				dat[j][i]=0;
			}
		}
		int ssum=0;
		rep(i,n){
			int sum=0;
			rep(j,n){
				cin>>dat[j][i];
				sum+=dat[j][i];
			}
			ssum+=sum;
			dat[n][i]=sum;
		}
		dat[n][n]=ssum;
		rep(i,n){
			int sum=0;
			rep(j,n){
				sum+=dat[i][j];
			}
			dat[i][n]=sum;
		}
		rep(i,n+1){
			rep(j,n){
				cout<<setw(5)<<dat[j][i];
			}
			cout<<setw(5)<<dat[n][i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1172