akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1010,P=1e9+7;
int n,m,ans,cnt,I,a[N],b[N],f[2][N][N];
void chk(int&x){x-=P;x+=(x>>31)&P;}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d",&n);m=2*n;
	FOR(i,1,m) scanf("%d",&a[i]),a[i]=max(a[i],0);
	FOR(i,1,n)if(a[2*i-0]) b[a[2*i]]++,b[a[2*i-1]]++;
	FOR(i,1,n)if(a[2*i-1]) b[a[2*i]]++,b[a[2*i-1]]++;
	f[I][0][0]=1;
	ROF(i,m,1){
		FOR(j,0,i)FOR(k,0,i-j)if(f[I][j][k]){
			if(b[i]==2) chk(f[I^1][j][k]+=f[I][j][k]);
			if(b[i]==1){
				      chk(f[I^1][j][k+1]+=f[I][j][k]);
				if(j) chk(f[I^1][j-1][k]+=f[I][j][k]);
			}
			if(b[i]==0){
				      chk(f[I^1][j+1][k]+=f[I][j][k]);
				if(j) chk(f[I^1][j-1][k]+=f[I][j][k]);
				if(k) chk(f[I^1][j][k-1]+=1ll*k*f[I][j][k]%P);
			}f[I][j][k]=0;
		}I^=1;
	}
	ans=f[I][0][0];
	FOR(i,1,n)if(!a[i*2] && !a[i*2-1]) ans=1ll*ans*++cnt%P;
	cout<<ans<<'\n';
} 

Measured memory_bytes: 5504
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}
int main() {
  LL N, X, M; cin >> N >> X >> M;
  map<LL, int> m = {{X, 0}};
  vector<LL> v = {X};

  bool loop = false;
  int i = 1;
  for (; i < N; ++i) {
    X = (X*X) % M;
    if (m.count(X)) {
      loop = true;
      break;
    }
    m[X] = i;
    v.push_back(X);
  }

  LL sum = 0;
  if (loop) {
    LL sum_head = 0, sum_loop = 0, sum_tail = 0;
    LL loop_size = i - m[X];
    LL loop_head = m[X];
    LL loop_num = (N-m[X])/loop_size;
    LL loop_tail = N - loop_head - loop_size * loop_num;

    for (int j = 0; j < m[X]; ++j) sum_head += v[j];
    for (int j = 0; j < loop_tail; ++j) sum_tail += v[loop_head + j];
    for (int j = m[X]; j <= i; ++j) sum_loop += v[j];

    sum = sum_head + sum_loop * loop_num + sum_tail;
  } else {
    for (auto [X, j] : m) sum += X;
  }
  cout << sum << endl;
}


Measured memory_bytes: 6616
#include<iostream>
using namespace std;
int main(){
int n, i, p;
while(cin>>n,n){
int min=1000,max=0,total=0;
for(int i=0;i<n;++i){
cin >> p;
if(p>max)max=p;
if(p<min)min=p;
total += p;
}
cout << (total-max-min)/(n-2) << "\n";
}
}

Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//using ll = long long;
//void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i,h) cin >> a[i];
    rep(i,w+2) cout << "#";
    cout << "\n";
    rep(i,h){
        cout << "#";
        cout << a[i];
        cout << "#";
        cout << "\n";
    }
    rep(i,w+2) cout << "#";

}

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

typedef long long ll;

int main() {
  ll l, r;
  cin >> l >> r;
  if (l == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 999999999999;
  if (r - l + 1 >= 2019) {
    ans = 0;
  }
  else {
    for (ll i = l; i <= r - 1; i++) {
      for (ll j = i + 1; j <= r; j++) {
        ll tmp = (i*j)%2019;
        if (tmp < ans) {
          ans = tmp;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  int i;
  scanf("%d", &n);
  int a[n];
  for( i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  for( i = n - 1; i >= 0; i--){
    if( i != n - 1)
      printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
  return 0;
}




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

int solve(vector<int> &arr ,int n,int k)
{
vector <int> dp(n+1,INT_MAX);
 //just for the sake of answer
dp[1]=0; //reacher from one to one is always be zero 

for(int i=2;i<=n;i++)
{
    for(int j=i-1;j>=1 and (i-j)<=k;j--)
    {   
            dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
    }
}
return dp[n];

}

int main() 
{
    int n;cin>>n;int k;cin>>k;
    vector <int> arr(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    cout<<solve(arr,n,k);
}


Measured memory_bytes: 4024
#include <iostream>
#include <cmath>

static int max_dist = 1000000000;

using namespace std;

int main (void)
{
    int n, m;
    int a[50], b[50];
    int c[50], d[50];

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++) {
        int pos = 0;
        int man_dist = max_dist;
        for (int j = 0; j < m; j++) {
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dist < man_dist) {
                man_dist = dist;
                pos = j + 1;
            }
        }
        cout << pos << endl;
    }

    return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int mx = 55556;
	vector<bool> a(mx);
	fill(a.begin(), a.end(), true);
	a[0] = a[1] = false;
	for(int i = 2; i < mx; i++) {
		if(a[i]) {
			for(int j = i * 2; j < mx; j += i) {
				a[j] = false;
			}
		}
	}
	vector<int> p;
	for(int i = 0; i < a.size(); i++) {
		if(a[i]) {
			p.push_back(i);
		}
	}
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 0; i < p.size(); i++) {
		if(p[i] % 5 == 1) {
			cout << p[i] << " ";
			cnt++;
		}
		if(cnt == n) {
			cout << endl;
			return 0;
		}
	}
	return 0;	
}


Measured memory_bytes: 384
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let n: usize = read_line().trim().parse().unwrap();
    let mut a = Vec::with_capacity(n);
    for i in 0..n {
        let v:usize = read_line().trim().parse().unwrap();
        a.push((v, i));
    }
    a.sort();
    let mut ans = 0;
    for i in 0..n {
        if a[i].1 % 2 != i % 2 {
            ans += 1;
        }
    }

    println!("{}", ans / 2);
}


Measured memory_bytes: 6396
import sys

#from scipy.misc import comb #scipy.special

#import numpy as np

def choose(n):
    return n*(n-1)/2

n = int(input())

a = [int(i) for i in input().split()]

bunpu = [0]*(n+1)

for i in range(len(a)):
    bunpu[a[i]]+=1


sum = 0
for i in bunpu:
    sum+=choose(i)
i = 0
for i in a:
    print(int(sum-choose(bunpu[i])+choose(bunpu[i]-1)))


Measured memory_bytes: 25716
import static java.lang.System.in;
import static java.lang.System.out;

import java.io.*;
import java.util.*;

public class Main {
	static final double EPS = 1e-10;
	static final double INF = 1L << 31;
	static final double PI = Math.PI;

	public static Scanner sc = new Scanner(in);
	StringBuilder sb = new StringBuilder();
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public void run() throws IOException {
		String input;
		String[] inputArray;
		input = br.readLine();
		inputArray = input.split(" ");

		int W = Integer.valueOf(inputArray[0]);
		int H = Integer.valueOf(inputArray[1]);
		int [] p = new int[W];
		int [] q = new int[H];
		long sp = 0L, sq = 0L;
		for (int i=0; i<W; i++){
			p[i] = Integer.valueOf(br.readLine());
			sp+=p[i];
		}
		for (int i=0; i<H; i++){
			q[i] = Integer.valueOf(br.readLine());
			sq+=q[i];
		}
		Arrays.sort(p);
		Arrays.sort(q);		
		long ans = 0;
		int i,j=0;
		for (i=0; i<W; i++){
			while(j<H && p[i]>q[j])
				j++;
			ans+=(1L*j*p[i]);
		}
		i=0;
		for (j=0; j<H; j++){
			while(i<W && q[j]>=p[i])
				i++;
			ans+=(1L*i*q[j]);
		}
		sb.append(sp*(H+1)+sq*(W+1)-ans);
		ln(sb);
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	public static void ln(Object obj) {
		out.println(obj);
	}
}


Measured memory_bytes: 28912
#include<iostream>   //AA06( 26/ 04/ 20) If u see my code, Have a Good Day! (^_^)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL)

using namespace std;

int main()
{
    fastio;
    int S, W;

    cin >> S >> W;

    if(W >= S)
        cout << "unsafe\n";

    else
        cout << "safe\n";

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

//#define LengthOf()

#if 0
//No.3
int main()
{

	return 0;
}
#endif

#if 1
//No.2
int main()
{
	INT N, M;
	cin >> N >> M;

	vector<INT> A(N);
	INT total = 0;
	for (INT i = 0; i < N; ++i) {
		cin >> A[i];
		total += A[i];
	}

	INT selCnt = 0;
	for(int i = 0; i < N; ++i) {
		if (A[i] >= (double)total / (4 * M)) {
			selCnt++;
		}
	}

	if (selCnt >= M) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}
#endif

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

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

#define loop1(i,n) for(int i=1; i<=n; i++)

#define ll long long

#define ld long double

#define pii pair<int,int>

#define pll pair<ll,ll>

#define pld pair<ld,ld>

#define pb push_back
const int MAXN = 2e3+7;
int ans[MAXN];
int dist(int x, int y){return (y>=x) ? y-x : x-y;}
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	loop1(i,n){
		for(int j=i+1; j<=n; j++){
			int di = min(dist(i,j), min( dist(i,a)+1+dist(j,b), dist(i,b)+1+dist(j,a) ) );
			ans[di]++;
		}
	}
	for(int i=1; i<n; i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <complex>
#include <algorithm>
#include <unordered_set>
#include <vector>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int, in){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}

using P = complex<long>;

struct hash_complex {
	inline size_t operator() (const P &p) const {
		return (p.real() << 32) + p.imag();
	}
};

int main() {
	for (int m; (m = in());) {
		vector<P> p(m - 1);
		P z = {in(), in()};
		for(P &x : p)
			x = P{in(), in()} - z;
		unordered_set<P, hash_complex> S;
		for (int n = in(); n--;)
			S.insert(P{in(), in()});
		for (P s: S)
			if([&]{
			   for (P i: p)
				   if (!S.count(s + i))
					   return false;
			   return true;}()) {
				P r = s - z;
				outl(r.real(), ' ', r.imag());
				break;
			}
	}
}


Measured memory_bytes: 2688
import math
import numpy as np


N =  int(input())
t = []
for i in range(N):
    X,Y = map(int,input().split())
    t.append([X,Y])

diff = np.expand_dims(t, axis=1) - np.expand_dims(t, axis=0)
dis = np.sqrt(np.sum(diff ** 2, axis=-1))
#print(dis)
#print(dis.sum())
print(dis.sum()/N)

Measured memory_bytes: 12392
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  i64 ans = 0;
  rep(i,1,N + 1) {
    ans += i * (N - i + 1);
  }
  rep(i,0,N - 1) {
    i64 a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    ans -= a * (N - b + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    cs
    int n,m,x,y,f,t,ans=1e9+7;
    cin>>n>>m>>x;
    vector<pair<int,vector<int>>> v(n);
    rep(i,n) {
        cin>>v[i].fi;
        vector<int> vv(m);
        for(auto &i:vv) cin>>i;
        v[i].se=vv;
    }
    rep(i,1<<n){
        f=i;y=0;bool b=1;t=0;
        vector<int> vv(m);
        while(f){
            if(f&1) {
                rep(j,m) vv[j]+=v[y].se[j];
                t+=v[y].fi;
            }
            f>>=1;y++;
        }
        rep(j,m) if(vv[j]<x) {b=0;break;}
        if(b) ans=min(ans,t);
    }
    if(ans==1e9+7) bye(-1)
    cout<<ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<vector<int>> ans(B);
    if (N < A + B - 1 || N > A * B) {
        cout << -1 << endl;
        return 0;
    }
    int count = 0;
    for (int i = 1; i <= B; i++) ans[i - 1].push_back(i);
    for (int i = B + 1; i <= N; i++) {
        if (ans[count].size() == A) count++;
        ans[count].push_back(i);
    }

    for (int i = B - 1; i >= 0; i--) {
        for (int j = 0; j < ans[i].size(); j++) {
            cout << ans[i][j] << (i == 0 && j == ans[i].size() - 1 ? '\n' : ' ');
        }
    }
}


Measured memory_bytes: 13568
v,e,r = map(int,input().split())
d = [float('INF')]*v
d[r] = 0
edges=[]

for i in range(e):
  s,t,c = map(int,input().split())
  edges.append([s,t,c])

for i in range(v):
  count = 0
  for s,v,c in edges:
    if d[v] > d[s]+c:
      count += 1
      d[v] = d[s]+c
  if count == 0:
    break

for i in d:
  if i == float('inf'):
    print('INF')
  else:
    print(i)


Measured memory_bytes: 102480
# encoding: utf-8                                                            

def z(a, i)
  b = []
  1.step(i) { b << $x; $x += 1}
  b.reverse! if $c > 0
  $c^=1; a << b
end

t = 0

while (n = gets.to_i) > 0
  puts "Case #{t += 1}:"
  a = []; $x= $c = 1
  1.step(n) { |i| z(a, i)}
  (n - 1).step(1, -1) { |i| z(a, i)}
  n.times { |i| n.times { |j| printf("%3d", a[i + j].shift)}; puts }
end

Measured memory_bytes: 6116
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin() (a).end()

int main(){
	int x,y,a,b,c;
	cin >>x>>y>>a>>b>>c;
        ll app[a], org[b], ext[c];
	for(int i = 0 ; i < a ; i++)cin>>app[i];
	for(int j = 0 ; j < b ; j++)cin>>org[j];
	for(int i = 0 ; i < c ; i++)cin>>ext[i];
	sort(app, app+a,greater<int>());
	sort(org, org+b,greater<int>());
	sort(ext, ext+c,greater<int>());

        long long int ans =0;
	ll sol[x+y];
	memset(sol,0,sizeof(sol));
	for(int i = 0; i <min(a,x); i++)
		sol[i]=app[i];
	for(int i = min(a,x); i <min(a,x)+min(b,y);i++)
		sol[i]=org[i-min(a,x)];
	sort(sol,sol+x+y,greater<int>());
	int i = x+y-1;
	int j = 0;
        
	while(j<c && i>=0){
		if(sol[i] < ext[j]){
			sol[i] = ext[j];
			j++;i--;
		}
		else break;
	}
	for(int i = 0 ; i < x+y; i++){
		ans+=sol[i];
	}
	cout<<ans<<"\n";
return 0;
}


Measured memory_bytes: 3968
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int prev = arr[0];
        int cnt = 1;
        int ans = 0;
        for(int i = 1; i < n; i++){
            if(prev == arr[i]){
                cnt++;
            }else{
                if(cnt % 2 != 0) ans++;
                prev = arr[i];
                cnt = 1;
            }
        }
        System.out.println(cnt % 2 == 0 ? ans : ans+1);
    }
}


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

int a, d, n;
bool isPrime[1000001];

void setPrime() {
	for (int i = 0; i < 1000001; i++) isPrime[i] = true;
	isPrime[0] = isPrime[1] = false;
	
	for (int i = 2; i < 1000001; i++) {
		if (isPrime[i]) {
			for (int j = i * 2; j < 1000001; j += i) {
				isPrime[j] = false;
			}
		}
	}
}

int main() {
	setPrime();
	
	while (cin >> a >> d >> n) {
		if (!a) break;
		
		int cnt = 0;
		for (int i = 0; ; i++) {
			if (isPrime[a + d * i]) cnt++;
			if (cnt == n) {
				cout << a + d * i << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main(){

int h,w;
h=0,w=0;

while(true){
    cin >> h >> w; 
        rep(i,h){
            rep(j,w){
                if(i % 2 == 0){
                    if (j % 2 == 0) cout << '#';
                    else if ( j % 2 == 1) cout << '.';}
                else if (i % 2 == 1){
                    if (j % 2 == 0 ) cout << '.';
                    else if (j % 2 == 1) cout << '#';
                }
            }
            cout << endl;
        }
  if (h == 0 && w == 0) break;
    cout << endl;
}
}


Measured memory_bytes: 3096
# include<bits/stdc++.h>
using namespace std;
vector<int>m;
int main(){
int a,b,c;
cin>>a>>b>>c;
m.push_back(a);
m.push_back(b);
m.push_back(c);
sort(m.begin(),m.end());
cout<<m[0]+m[1];
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,m,d[100010]={};
  char s[100010];
  scanf("%*d %d %s",&m,s);
  for(i=0;s[i];i++){
    d[i+1]=d[i];
    if(s[i]=='A'&&s[i+1]=='C')d[i+1]++;
  }
  while(m--){
    scanf("%d %d",&i,&j);
    printf("%d\n",d[j-1]-d[i-1]);
  }
  return 0;
}
    


Measured memory_bytes: 1280
from sys import stdin

import time
def dprint(*args):
    #print(*args)
    pass


n, a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
ans = "Yes"

card = []
sentaku = []

for i in range(n):
    s = stdin.readline().rstrip()
    card.append(s)

if a+b+c == 0:
    ans = "No"

nums = {"A": a, "B": b, "C": c}


def judge(i, j, k):
    global ans
    dprint(n, i, j, k, ans, nums, sentaku)
    if nums[j] == 0 and nums[k] == 0:
        ans = "No"
        return

    if nums[j] == 0:
        nums[j] += 1
        nums[k] -= 1
        sentaku.append(j)
        return
    if nums[k] == 0:
        nums[k] += 1
        nums[j] -= 1
        sentaku.append(k)
        return

    total = sum(nums.values())
    if total > 2 or i == n-1:
        if nums[k] > 1:
            nums[j] += 1
            nums[k] -= 1
            sentaku.append(j)
        else:
            nums[k] += 1
            nums[j] -= 1
            sentaku.append(k)
        dprint("tekitou")
        return

    ns = card[i+1]
    if ns[0] == j or ns[1] == j:
        nums[j] += 1
        nums[k] -= 1
        sentaku.append(j)
        return
    else:
        nums[k] += 1
        nums[j] -= 1
        sentaku.append(k)
        return
    pass


for i in range(n):
    s = card[i]
    judge(i, s[0], s[1])

print(ans)

if ans == "Yes":
    for i in range(len(sentaku)):
        print(sentaku[i])


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int a[100005];

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    ll ans = 1e18;
    for(int j=0;j<2;j++){
        ll res = 0, sum = 0;
        for(int i=1;i<=n;i++){
            sum += a[i];
            if(i%2 == j){
                if(sum > 0) continue;
                res += abs(sum) + 1;
                sum = 1;
            }
            else{
                if(sum < 0) continue;
                res += abs(sum) + 1;
                sum = -1;
            }
        }
        ans = min(ans, res);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--) 

const int maxn = 2500 + 5;
const int maxm = 5000 + 5;
const int MOD = 1e9 + 7;

struct node{
    int s,t,w; 
}e[maxm];
int n,m,p,cnt;
int dist[maxn],reach1[maxn],reachn[maxn];
vector<int>to[maxn],rto[maxn];

void dfs(int v)
{
    if(reach1[v]) return;
    reach1[v] = 1;
    for(int u : to[v])
        dfs(u);
}

void rdfs(int v)
{
    if(reachn[v]) return;
    reachn[v] = 1;
    for(int u : rto[v])
        rdfs(u);
}

inline void Bellman() 
{
    rep(i,1,n)dist[i] = inf;
    dist[1] = 0;
    int sum;
    rep(i,1,n){
        int up = 0;
        rep(j,1,m){
            int x = e[j].s , y = e[j].t;
            if(!reach1[x] || !reach1[y]) continue; 
            if(dist[x] < inf && dist[x] + e[j].w < dist[y]){
                dist[y] = dist[x] + e[j].w;
                up = 1;
            }
        }
        if(!up)break;
        if(i == n && up) {
            cout << -1 ;
            exit(0);
        }
    }

    cout << max(-dist[n],0);
    return;
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   cin >> n >> m >> p;
   rep(i,1,m){
        cin >> e[i].s >> e[i].t >> e[i].w;
        e[i].w = p - e[i].w;
        to[e[i].s].push_back(e[i].t);
        rto[e[i].t].push_back(e[i].s);
   }
   dfs(1),rdfs(n);
   rep(i,1,n) reach1[i] &= reachn[i];
   Bellman();
   return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    string s, t, tmp;
    cin >> s >> t;
    bool flag = false;
    for (int i = 0; i < s.length(); i++) {
        tmp.clear();
        if (i == 0) {
            tmp = s;
        }else{
            tmp = s.substr(i, s.length() - i) + s.substr(0, i);
        }
        //cout << tmp << endl;
        if (tmp == t) {
            flag = true;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

def resolve():
    readline=sys.stdin.readline
    n,x=map(int, readline().rstrip().split())
    arr=list(map(int, readline().rstrip().split()))
    ans=0
    for i in range(1,len(arr)):
        xx=arr[i-1]+arr[i]
        if xx > x:
            arr[i]-=(xx-x)
            ans+=(xx-x)
            if arr[i]<0:
                arr[i-1]+=arr[i]
                arr[i]=0
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Measured memory_bytes: 14252
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int a, b, c, d;
	char aa, bb, cc, dd;
	cin >> aa >> bb >> cc >> dd;
	a = (aa - '0');
	b = (bb - '0');
	c = (cc - '0');
	d = (dd - '0');
	vector<char> ops{'+', '-'};
	for(auto &op1 : ops)
		for(auto &op2 : ops)
			for(auto &op3 : ops)
			{
				int answer = a;
				answer += (op1 == '+' ? b : -b);
				answer += (op2 == '+' ? c : -c);
				answer += (op3 == '+' ? d : -d);
				if(answer == 7) return cout << a << op1 << b << op2 << c << op3 << d << "=7\n", 0;
			}
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;

  double ans = 0;
  REP(i, 0, n){
      double x;
      string str;
      cin >> x >> str;
      if(str == "JPY")
        ans += x;
      else
        ans += x * 380000;
  }

  cout << fixed << setprecision(6) << ans <<endl;

  return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      int cnt = 0;
      if (i != 0) {
        if (j != 0 && s[i - 1][j - 1] == '#') cnt++;
        if (s[i - 1][j] == '#') cnt++;
        if (j != w - 1 && s[i - 1][j + 1] == '#') cnt++;
      }
      if (j != 0 && s[i][j - 1] == '#') cnt++;
      if (j != w - 1 && s[i][j + 1] == '#') cnt++;
      if (i != h - 1) {
        if (j != 0 && s[i + 1][j - 1] == '#') cnt++;
        if (s[i + 1][j] == '#') cnt++;
        if (j != w - 1 && s[i + 1][j + 1] == '#') cnt++;
      }
      s[i][j] = cnt + '0';
    }
    cout << s[i] << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <ctype.h>

int main(void){
	
	char a[100],b[100],c[100],d='a';
	int ar=0,br=0,cr=0;

	scanf("%s",&a);
	scanf("%s",&b);
	scanf("%s",&c);

	for(;;){
		if(d=='a'){
			if(a[ar]=='\0')break;
			d=a[ar];
			ar++;
		}
		else if(d=='b'){
			if(b[br]=='\0')break;
			d=b[br];
			br++;
		}
		else if(d=='c'){
			if(c[cr]=='\0')break;
			d=c[cr];
			cr++;
		}
	}
	printf("%c\n",toupper(d));

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int a[3], i;
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  cout << (a[2]-a[1])+(a[1]-a[0])/2+(a[1]-a[0])%2*2;
  return 0;
}

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

int main()
{
	int a, b, c;
	a = 0; b = 0; c = 0;
	cin >> a >> b >> c;
	string output = "No";
	if (a < c)
	{
		if(c<b)
		output = "Yes";
	}
	if (a > c) {
		if(c>b)
			output = "Yes";
	}
	cout << output;
}

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

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

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;

		long long ans = 0;
		vector<pair<int, int>> right, left;
		for (int i = 0; i < n; ++i) {
			int k, l, r;
			cin >> k >> l >> r;
			ans += min(l, r);
			if (l < r) {
				right.emplace_back(r - l, n - k);
			} else if (l > r) {
				left.emplace_back(l - r, k);
			}
		}
		sort(right.rbegin(), right.rend());
		sort(left.rbegin(), left.rend());

		auto proc = [&ans, &n](vector<pair<int, int>> left) {
			set<int> ndx;
			for (int i = 1; i <= n; ++i) {
				ndx.insert(i);
			}
			for (auto [x, k] : left) {
				auto it = ndx.upper_bound(k);
				if (it != ndx.begin()) {
					ndx.erase(--it);
					ans += x;
				}
			}
		};

		proc(left);
		proc(right);
		cout << ans << "\n";
	}
}


Measured memory_bytes: 14900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000003;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll inv(ll n){return modpow(n,mod-2);}
vi fac,finv,invv;
void init(ll n){
    fac=vi(n);finv=vi(n);invv=vi(n);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    invv[1] = 1;
    REP(i,2,n){
        fac[i]=fac[i-1]*i%mod;
        invv[i]=mod-invv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*invv[i]%mod;
    }
}
ll solve(ll x,ll n){
    if(x+n-1>=mod)return 0;
    if(x==0)return 0;
    ll res=fac[x+n-1];
    res*=finv[x-1];
    res%=mod;
    return res;
}
int main(){
    ll q;cin>>q;
    init(mod);
    rep(qq,q){
        ll x,d,n;cin>>x>>d>>n;
        if(x==0){
            out(0);continue;
        }
        if(d==0){
            out(modpow(x,n));continue;
        }
        out(solve(x*inv(d)%mod,n)*modpow(d,n)%mod);
    }
}

Measured memory_bytes: 26112
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> linkhash = new LinkedHashSet<String>();
		for (int i = 0; i < n; i++) {
			linkhash.add(sc.next());
		}
		System.out.println(linkhash.size());
	}
}


Measured memory_bytes: 79560
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int a =scan.nextInt();
		int b =scan.nextInt();
		int c =scan.nextInt();

		int x ;
		if(a > b) {
			x =a;
			a =b;
			b =x;
		}	
		if(a > c) {
			x =a;
		    a =c; 
		    c =x;
		}   
		if(b > c) {
			x =b;
		    b =c;
		    c =x;
		} 
		System.out.println(a + " " + b + " " + c);
	}

}



Measured memory_bytes: 26168
#すぬけ君N人，お菓子K種類
N, K = map(int, input().split())

#下はansに人数分の”1”の要素を作成している
ans = [1]*N
#print(ans)

#K種類のお菓子が誰に渡っているかを入力するfor文
for i in range(K):
    #お菓子iの個数d
    d = int(input())
    for j in list(map(int, input().split())):
        #ansの要素のうちjに含まれる（つまりお菓子iを持っている人間を1→0に変換する）
        #ただし配列は0,1...と数えるが，ここで入力されるのは1,2...という正の整数のため-1する
        ans[j-1] = 0

print(ans.count(1))




Measured memory_bytes: 9168
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int i,count=0;
    for(i=a;i<=b;i++)
     {if(i%c==0)
        {count++;
        }
     }
     cout<<count;

    return 0;
}


Measured memory_bytes: 3632
open System

let a, b, h, m =
    let l = Console.ReadLine().Split(' ') |> Array.map float
    l.[0], l.[1], l.[2], l.[3]

let l =
    let theta =
        let h = int h
        let t1 = ((60.0 * float (h % 12) + m) / (12.0 * 60.0)) * 2.0 * Math.PI
        let t2 = (m / 60.0) * 2.0 * Math.PI
        Math.Abs (t1 - t2)

    let l2 = a * a + b * b - 2.0 * a * b * (Math.Cos theta)

    Math.Sqrt(l2)

l |> Console.WriteLine

Measured memory_bytes: 28264
import math
n,d=map(int,input().split())
s=[list(map(int,input().split())) for i in range(n)]

count = 0
for i in range(n):
    for j in range(i + 1, n):
      sum=0
      for k in range(d):
        sum+=(s[i][k]-s[j][k])**2
      dist=math.sqrt(sum)
      if dist == int(dist):
        count+=1
print(count)
      

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int ans;
vector<int>v;
vector<int>pos;
int sol(int i,int j){
	int smsm=0;
	int tmp=k;
	priority_queue<int>pq;
	for(int s=0;s<=i&&tmp;s++){
		smsm+=v[s];
		pq.push(-v[s]);
		tmp--;if(tmp==0)break;
	}
	if(j<=i){
		int ssss=smsm;
		int ttmp=tmp;
		priority_queue<int>ppq=pq;
		while(ppq.size()&&ttmp){
			if(ppq.top()<=0)break;
			ssss+=ppq.top();ppq.pop();
			ttmp--;if(ttmp==0)break;
		}
		ans=max(ans,ssss);
	}else{
		priority_queue<int>ppq=pq;
		int ttmp=tmp;
		int ssss=smsm;
		for(int z=i+1;z<=j&&ttmp;z++){
			ppq.push(-v[z]);
			ssss+=v[z];
			ttmp--;
			if(ttmp==0)break;
		}
		while(ppq.size()&&ttmp){
			if(ppq.top()<=0)break;
			ssss+=ppq.top();ppq.pop();
			ttmp--;
			if(ttmp==0)break;
		}
		ans=max(ans,ssss);
		ppq=pq;ttmp=tmp;ssss=smsm;
		for(int z=n-1;z>=j&&ttmp;z--){
			ppq.push(-v[z]);
			ssss+=v[z];
			ttmp--;if(ttmp==0)break;
		}
		while(ppq.size()&&ttmp){
			if(ppq.top()<=0)break;
			ssss+=ppq.top();ppq.pop();
			ttmp--;if(ttmp==0)break;
		}
		ans=max(ans,ssss);
	}
	priority_queue<int>cls;
	smsm=0;tmp=k;pq=cls;
	for(int z=n-1;z>=i&&tmp;z--){
		smsm+=v[z];
		pq.push(-v[z]);
		tmp--;if(tmp==0)break;
	}
	if(j>=i){
		int ssss=smsm;
		int ttmp=tmp;
		priority_queue<int>ppq=pq;
		while(ppq.size()&&ttmp){
			if(ppq.top()<=0)break;
			ssss+=ppq.top();ppq.pop();
			ttmp--;if(ttmp==0)break;
		}
		ans=max(ans,ssss);
	}else{
		priority_queue<int>ppq=pq;
		int ttmp=tmp;
		int ssss=smsm;
		for(int z=i-1;z>=j&&ttmp;z--){
			ppq.push(-v[z]);
			ssss+=v[z];
			ttmp--;if(ttmp==0)break;
		}
		while(ppq.size()&&ttmp){
			if(ppq.top()<=0)break;
			ssss+=ppq.top();ppq.pop();
			ttmp--;if(ttmp==0)break;
		}
		ans=max(ans,ssss);
		ppq=pq;ttmp=tmp;ssss=smsm;
		for(int z=0;z<=j&&ttmp;z++){
			ppq.push(-v[z]);
			ssss+=v[z];
			ttmp--;if(ttmp==0)break;
		}
		while(ppq.size()&&ttmp){
			if(ppq.top()<=0)break;
			ssss+=ppq.top();ppq.pop();
			ttmp--;if(ttmp==0)break;
		}
		ans=max(ans,ssss);
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int a;cin>>a;
		v.push_back(a);
		if(a>0)pos.push_back(i);
	}
	for(int i=0;i<pos.size();i++){
		for(int j=0;j<pos.size();j++){
			sol(pos[i],pos[j]);
			// cout<<"---------------"<<endl;
			// cout<<pos[i]<<' '<<pos[j]<<endl;
			// cout<<ans<<endl;
		}
	}
	cout<<ans;
	return 0;
}

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

int main() {
	int Array[100];
	int x,i;
	cin >> x;
	for (i = 0; i < x; i++){
		cin >> Array[i];
	}
	for  (int n = x-1; n > -1; n--){
		if (n == 0) 
			cout << Array[n] << endl;
		else
		cout << Array[n]<<" ";
	}
	cin >> i;
}

Measured memory_bytes: 3028
"""test programm for Q-B 20200719 """
# test programm for B


def __main__():
    str1 = str(input())
    str2 = str(input())
    list_str1 = list(str1)
    list_str2 = list(str2)

    if len(list_str1) < 1 or 2*10**5 < len(list_str1):
        raise ValueError
    elif str1.isalpha() == False or str1.islower() == False:
        raise ValueError
    elif str2.isalpha() == False or str2.islower() == False:
        raise ValueError
    elif len(str1) != len(str2):
        raise ValueError

    cnt = 0
    for n in range(len(list_str1)):
        if list_str1[n] != list_str2[n]:
            cnt += 1
        else:
            continue

    print(cnt)


if __name__ == "__main__":
    __main__()

Measured memory_bytes: 12696
// AOJ 1253: Dice Puzzle
// 2017.10.21 bal4u@uu

#include <stdio.h>
#include <string.h>

char rot[24][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };

typedef struct { int x, y, z; } T;
T n2xyz[28];

char dice[3][3][3][7];
int top[3][3], front[3][3];
char ans[55], sz;

void combi(char dice[3][3][3][7], int n)
{
	int s, x, y, z, i;

	if (n == 27) {
		for (s = 0, y = 0; y < 3; y++) for (z = 0; z < 3; z++) s += dice[z][y][2][3];
		sz = 1;
		ans[s] = 1;
		return;
	}
	x = n2xyz[n].x, y = n2xyz[n].y, z = n2xyz[n].z;
	for (i = 0; i < 24; i++) {
		memcpy(dice[z][y][x], rot[i], 7);
		if (x > 0 && dice[z][y][x][4] + dice[z][y][x-1][3] != 7) continue;
		if (y == 0) { if (front[z][x] > 0 && front[z][x] != dice[z][0][x][2]) continue; }
		else { if (dice[z][y][x][2] + dice[z][y-1][x][5] != 7) continue; }
		if (z == 0) { if (top[y][x] > 0 && top[y][x] != dice[0][y][x][1]) continue; }
		else { if (dice[z][y][x][1] + dice[z-1][y][x][6] != 7) continue; }
		combi(dice, n + 1);
	}
}

int main()
{
	int n, i, x, y, z;

	for (x = 0; x < 3; x++) for (y = 0; y < 3; y++) for (z = 0; z < 3; z++) {
		n = 9 * z + 3 * y + x;
		n2xyz[n].x = x, n2xyz[n].y = y, n2xyz[n].z = z;
	}

	scanf("%d", &n);
	while (n-- > 0) {
		memset(ans, 0, sizeof(ans));
		for (y = 2; y >= 0; y--) for (x = 0; x < 3; x++) scanf("%d", &top[y][x]);
		for (z = 0; z < 3; z++) for (x = 0; x < 3; x++) scanf("%d", &front[z][x]);

		sz = 0;
		combi(dice, 0);
		if (sz == 0) puts("0");
		else {
			for (i = 9; i <= 54; i++) if (ans[i]) {
				if (sz > 0) sz = 0;
				else putchar(' ');
				printf("%d", i);
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 1748
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#define N 110
using namespace std;

int n,m,Ans,i;
int p[10010];

inline int Abs(int x){return (x<0)?-x:x;}
inline int Max(int a,int b){return (a>b)?a:b;} 

int main(){
//	freopen("zht.in","r",stdin);
//	freopen("zht.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (i=1;i<=(int)sqrt(m);i++){
		if (m%i!=0)	continue;
		p[++p[0]]=i;	p[++p[0]]=m/i;
	}
	n=m/n;
	for (i=1;i<=p[0];i++)
	if (p[i]<=n&&p[i]>Ans)	Ans=p[i];
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int limit = n / 2, ans = 0;
    for (int i = 1; i <= limit; i++) {
        if(i != n - i)
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}

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

int main(){
	int n,m;

	while(true){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}

		int* data = new int[n+m];

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

		int max = 0;
		int countbuf = 0;

		for(int i=0;i<n+m;i++){
			if(max < data[i] - countbuf){
				max = data[i] - countbuf;
			}
			countbuf = data[i];
		}

		cout << max << endl;
	}
}

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

right = 0
ans = 0
add_sum = 0
xor_sum = 0
for left in range(N):
    while right < N and add_sum + A[right] == xor_sum ^ A[right]:
        add_sum += A[right]
        xor_sum ^= A[right]
        right += 1

    ans += (right-left)

    if left == right:
        right += 1
    else:
        add_sum -= A[left]
        xor_sum ^= A[left]
print(ans)

    


Measured memory_bytes: 24584
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- \n"
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int SIZE = 1e5+7 ;  
const int MOD = 1e9 +7 ; 
const int INF = 2e9+7 ;
/*  
    time : 08 : 48    
    date : 16...02...2020
*/ 
void I_O(){
    ios::sync_with_stdio(false) ;
    cin.tie(NULL);
    cout.tie(NULL);
}
int tests(){
  int H,W,N ; 
  cin >> H >> W ;
  cin >> N  ;
  H = max(H,W) ;
  cout << (N + H-1)/H << '\n' ; 

  return  0 ;   
}
int main(){ 

    I_O() ;  
    int cases = 1 ;
    // cin >> cases;  
    while(cases--) 
      tests(); 
  return 0 ;
}
// web dev simplified
// LearnCode.Academy
/*
 g++ subminnnt.cpp -Wall -Wextra -pedantic
 -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal
 -Wconversion -Wlogical-op -Wshift-overflow=2
 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG
 -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address 
 -fsanitize=undefined -fno-sanitize-recover -fstack-protec    
*/         
         
  

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

vector<int> G[100001];
vector<bool> done(100001);

bool get_pass(int from, int to, vector<int> &pass) {
    if (done.at(from)) return false;

    if (from == to) {    
        pass.push_back(from);
        return true;
    }
    
    done.at(from) = true;
    
    for (int i = 0; i < (int)G[from].size(); i++) {
        if (get_pass(G[from].at(i), to, pass)) {
            pass.push_back(from);
            return true;
        }
    }

    return false;
}

vector<bool> used(100001);
void dfs(int p, int &cnt) {
    if (used.at(p)) return;
    
    used.at(p) = true;
    cnt++;

    for (int i = 0; i < (int)G[p].size(); i++) {
        dfs(G[p].at(i), cnt);
    }

    return;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> pass;
    get_pass(1, n, pass);
    
    int len = (int)pass.size();
    
    for (int i = 0; i < len; i++) {
        used.at(pass.at(i)) = true;
    }
    
    int f = 0, s = 0;
    for (int i = 0; i < len - len / 2; i++) {
        f++;
        for (int j = 0; j < (int)G[pass.at(len - 1 - i)].size(); j++) {
            dfs(G[pass.at(len - 1 - i)].at(j), f);
        }
    }
    
    for (int i = 0; i < len / 2; i++) {
        s++;
        for (int j = 0; j < (int)G[pass.at(i)].size(); j++) {
            dfs(G[pass.at(i)].at(j), s);
        }
    }

    if (f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 12668