akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < (n);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main() {
  string s,t;cin>>s>>t;

  int dp[3300][3300];
  
  rep(i,s.size()){
    rep(j,t.size()){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j]+1;
      }else{
        dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  
  int i = s.size(),j = t.size();
  string ans = "";
  
  while(i > 0 && j > 0){
    if(dp[i][j] == dp[i-1][j])
      --i;
    else if(dp[i][j] == dp[i][j-1])
      --j;
    else{
      --i;--j;
      ans.pb(s[i]);
    }
  }
  reverse(all(ans));
  print(ans);
  return 0;
}

Measured memory_bytes: 40576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;




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

    int N;
    cin>>N;
    int zm=-INF,zn=INF,wm=-INF,wn=INF;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        int c=a+b;
        int d=a-b;
        zm=max(zm,c);
        zn=min(zn,c);
        wm=max(wm,d);
        wn=min(wn,d);
    }
    cout<<max(zm-zn,wm-wn)<<endl;



    
}


Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
	int a ,b;
	int d;
	int r;
	double f ;
	
	scanf("%d%d" ,&a ,&b);
	printf("%d %d %.5f" ,d = a / b ,r = a % b ,f = (double)a / b);
	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back



int main(void){
  int n, m;
  while(1){
    int suma = 0;
    int sumb = 0;
    int a[128],b[128];
    cin >> n >> m;
    if(n+m==0)break;
    rep(i,n)cin >> a[i];
    rep(j,m)cin >> b[j];
    rep(i,n)suma += a[i];
    rep(i,m)sumb += b[i];
    sort(a,a+n);
    sort(b,b+m);

    rep(i,n)rep(j,m){
      if(suma - a[i] + b[j] == sumb - b[j] + a[i]){
        cout << a[i] << " " << b[j] << endl;
        goto A;
      }
    }
    cout << "-1" << endl;
    A:;
  }
  return 0;
}

Measured memory_bytes: 3008
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i,ans=0,base=10;
    scanf("%d",&n);
    int digit=(int)log10(n);
    
        for( i=1;i<=digit;i++)
        {
          if(i&1)
          ans=ans*base+9;
          else
          ans=ans*base;
          
          
        }
    if(digit&1)
    printf("%d",ans);
    else
    printf("%d",n-ans);
     return 0;
}

Measured memory_bytes: 128
import java.util.*;
//import static java.lang.Integer.*;
import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		long a = parseLong(sc.next());
		long b = parseLong(sc.next());
		sc.close();
		long k;
		k = a+b;
		if((k&1)==0)out.println(k/2);
		else out.println("IMPOSSIBLE");
	}
}


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

int main() {
  ll N, M;
  cin >> N >> M;
  ll a[N];
  vector<ll> v;
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  
  ll b[M], c[M];
  priority_queue<P> que;
  for (ll i = 0; i < M; i++) {
    cin >> b[i] >> c[i];
    que.push(P(c[i], b[i]));
  }
  
  vector<ll> vc;
  
  while (vc.size() <= N && !que.empty()) {
    P q = que.top();
    for (ll j = 0; j < q.second; j++) {
      vc.push_back(q.first);
    }
    que.pop();
  }
  
  while (vc.size() < N) {vc.push_back(0);}
  
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (v[i] < vc[i]) {v[i] = vc[i];}
    ans += v[i];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 8048
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

vector<int> a,b,c,d;
int N,M,Q;
int ans = 0;
vector<int> t;

void dfs(int cnt,int last=1){
	if(cnt==0){
		int score = 0;
		for(int i=0;i<Q;i++){
			if(t[b[i]]-t[a[i]]==c[i])score += d[i];
		}
		ans = max(ans,score);
		return;
	}
	else{
		for(int i=last;i<=M;i++){
			t.push_back(i);
			dfs(cnt-1,i);
			t.pop_back();
		}
	}
}

int main(){
	
	cin>>N>>M>>Q;
	
	for(int i=0;i<Q;i++){
		int x,y,z,w;
		cin>>x>>y>>z>>w;
		x--;y--;
		a.push_back(x);
		b.push_back(y);
		c.push_back(z);
		d.push_back(w);
	}
	
	dfs(N);
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3576
#include<stdio.h>

int S(int T[],int n, int key);


int main(){
  int i,n,T[10000+1],q,key,sum =0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&T[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(S(T,n,key))sum++;
  }
  printf("%d\n",sum);

  return 0;
}


int S(int T[], int n, int key){
  int i = 0;
  T[n] = key;
  while(T[i] != key)i++;
  return i !=n;
}



Measured memory_bytes: 2080
#include<stdio.h>
int main() {
	int a, b;
	while (scanf("%d %d", &a, &b), a + b) {
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++)
				putchar('#');
			puts("");
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2612
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int N, M;

void dfs(const vector<vector<bool>>& graph, int p, vector<bool>& visit) {
    if (visit[p]) {
        return;
    }

    // cout << "* " << p << endl;

    visit[p] = true;
    for (int i = 0; i < M; i++) {
        if (graph[p][i]) {
            dfs(graph, i, visit);
        }
    }
}

bool allVisit(const vector<bool>& visit) {
    for (int i = 0; i < N; i++) {
        if (!visit[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> N >> M;

    vector<vector<bool>> graph(N, vector<bool>(N, false));
    vector<pair<int, int>> edge(M);

    for (int i = 0; i < M; i++) {
        int ai, bi;
        cin >> ai >> bi;
        edge[i].first = ai - 1;
        edge[i].second = bi - 1;
        graph[ai - 1][bi - 1] = true;
        graph[bi - 1][ai - 1] = true;
    }

    int ans = 0;
    for (int i = 0; i < M; i++) {
        graph[edge[i].first][edge[i].second] = false;
        graph[edge[i].second][edge[i].first] = false;

        vector<bool> visit(N, false);

        dfs(graph, 0, visit);

        if (!allVisit(visit)) {
            // cout << "+ " << edge[i].first << ", " << edge[i].second << endl;
            ans++;
        }

        graph[edge[i].first][edge[i].second] = true;
        graph[edge[i].second][edge[i].first] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# include<iostream>

using namespace std;

int main(void){
  int n, d, ans=0;
  cin >> n >> d;
  if(n % (2 * d + 1) != 0){
    ans = n / (2 * d + 1) + 1;
  }else{
    ans = n / (2 * d + 1);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a, b, c;
	int count=0;
	scanf("%d%d%d",&a,&b,&c);
	for (;a <= b;a++) {
		if (c%a==0) {
			count++;
		}
	}
	printf("%d\n",count);
}

Measured memory_bytes: 1820
n, x, y = map(int, input().split())
ans = [0] * (n - 1)
for i in range(1, n):
    for j in range(i + 1, n + 1):
        dis = min(j - i, abs(x - i) + 1 + abs(y - j))
        ans[dis - 1] += 1
for i in range(n - 1):
    print(ans[i])

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}


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

int main() {
  int N,A,a,b;
  a=0;
  cin >> N;

  cin >> A;
  if(A%2==0){
    while(true){
      A/=2;
      if(A%2==1){
        a++;
        break;
      }
      a++;
    }
  }


  for(int i=1;i<N;i++){
    cin >> A;
    b=0;
    if(A%2==0){
      while(true){
        A/=2;
        if(A%2==1){
          b++;
          break;
        }
        b++;
      }
      if(a>b){
        a=b;
      }
    }else{
      a=0;
    }
  }

  cout << a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int a[20], b[20], c[19];
	int i;
	int sum = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < n; i++) {
		scanf("%d", &b[i]);
		sum += b[i];
	}

	for (i = 0; i < n - 1; i++) {
		scanf("%d", &c[i]);
	}

	for (i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1] - 1) {
			sum += c[a[i]-1];
		}
	}

	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 128
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll tp; cin>>tp; while(tp--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
}

Measured memory_bytes: 3640
// This code is written By Philip Haddad (Philip97hd on codeforces).
// ICPC - One day I'll be there :D
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <algorithm>
#include <set>
#define ll long long
#define ld long double
#define rep(i,j,n) for(int i =j ; i < n ; i++)
#define repi(i,j,n) for(int i =n-1 ; i>=j ; i--)
#define repn for(int i =0 ; i < n ; i++)
#define pf printf
#define sf scanf
#define all(s) s.begin(),s.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define IndxLowr lower_bound(v.begin(),v.end(),n)-v.begin()
#define FIO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define len(s)	s.length()
#define siz(s)	s.size()
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
ll const MAXA = (ll)1e9 + 1;
int n , k ;
ll memo[1001][1001];
ll solve(int last , int i )
{
    if( i == n ) return 1 ;
    ll ans =  0 ;
    if(memo[last][i] != -1 ) return memo[last][i] ;
    for(int j= 1 ; j <= k ; j++)
    {
        if(last != j)
           ans+= solve(j , i+1);
    }
    return memo[last ] [i] = ans ;
}
int main()
{
 	cin >> n >> k ;
 	memset(memo , -1 , sizeof(memo) ) ;
 	cout << solve(0 , 0) <<endl;
}

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

int main() {
    char c;
    cin >> c;

    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

#define SIZE 12

void Erase(int map[SIZE][SIZE], int x, int y);

int main(){
    int map[SIZE][SIZE];
    char buf[SIZE+1];
    int count;
    
    while (scanf("%s",buf)!=EOF){
        // load map
        for (int j=0; j<SIZE;j++){
            map[0][j] = buf[j] - '0';
        }            
        for (int i=1; i<SIZE;i++){
            scanf("%s",buf);
            for (int j=0; j<SIZE;j++){
                map[i][j] = buf[j] - '0';
            }            
        }
        // count islands
        count=0;
        for (int i=0; i<SIZE;i++){
            for (int j=0; j<SIZE;j++){
                if (map[i][j]){
                    count++;
                    Erase(map, i, j);
                }
            }            
        }
        printf("%d\n",count);
    }
    
    return 0;
}

void Erase(int map[SIZE][SIZE], int x, int y){
    if (x<0 || x>=SIZE) return;
    if (y<0 || y>=SIZE) return;
    if (map[x][y]==0) return;
    map[x][y]=0;
    Erase(map, x-1, y);
    Erase(map, x+1, y);
    Erase(map, x, y-1);
    Erase(map, x, y+1);
    return;
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	string s;cin>>s;
	vector<int>w; vector<int>r;
	for(int i = 0;i<n;i++){
		if(s[i]=='W'){
			w.push_back(i);
		}
	} for(int i = n;i>0;i--){
		if(s[i]=='R'){
			r.push_back(i);
		}
	}int ans =0 ;
	int M = min(w.size(),r.size());
	for(int i =0;i<M;i++){
		if(w[i]<r[i]) ans++;
	} cout<<ans;
	return 0;
}

Measured memory_bytes: 4588
#include <stdio.h>

int main(void) {
	int N,M,Q;
	while(scanf("%d%d%d",&N,&M,&Q)==3 && (N|M|Q)!=0) {
		char sw[64];
		char op[64];
		char stat[1024];
		char cannot_taiou[1000][36]={{0}};
		int i,j,k;
		for(i=0;i<N;i++)sw[i]=0;
		for(i=0;i<Q;i++) {
			if(scanf("%s%s",op,stat)!=2)return 1;
			for(j=0;j<N;j++) {
				if(op[j]=='1')sw[j]=1-sw[j];
			}
			for(j=0;j<M;j++) {
				for(k=0;k<N;k++) {
					if(stat[j]-'0'!=sw[k])cannot_taiou[j][k]=1;
				}
			}
		}
		for(i=0;i<M;i++) {
			int candidate=-1;
			int candidate_count=0;
			for(j=0;j<N;j++) {
				if(!cannot_taiou[i][j]) {
					candidate=j;
					candidate_count++;
				}
			}
			if(candidate_count!=1)putchar('?');
			else if(candidate<10)putchar(candidate+'0');
			else if(candidate<36)putchar(candidate-10+'A');
			else putchar('!');
		}
		putchar('\n');
	}
	return 0;
}

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

//#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

//#define int long long
typedef pair <int, int> pii;
const int maxn = 101;
string s[maxn];
int dp[maxn][maxn];

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	int t = 0, q = 0;
	for (int i = 0; i < n; i++) {
		s[i]--;
		if ((i & (n - 1)) == i) {
			t = (t + (s[i] - '0')) % 2;
		}
		if (s[i] == '1')
			q = 1;
	}
	if (t) {
		cout << 1;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '2')
			s[i] = '1';
	}
	t = 0;
	for (int i = 0; i < n; i++) {
		if ((i & (n - 1)) == i) {
			t = (t + (s[i] - '0')) % 2;
		}
	}
	if (t && !q)
		cout << 2;
	else
		cout << 0;
}


Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
 
const int MAX = 1e5+10;
 
ll N, X, L;
 
 
int main() {
    cin >> N >> X;
    ll S = 0;
    ll ans = 1;
    REP (i, N) {
        cin >> L;
        S += L;
        if (S <= X) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int max = 0;
		int min = 0;
		long sum = 0;
		int n;

		Scanner stdIn = new Scanner(System.in);

		n = stdIn.nextInt();
		max = min = stdIn.nextInt();
		sum = max;

		for (int i = 1, tmp = 0; i < n; i++) {
			tmp = stdIn.nextInt();

			if(max < tmp) {
				max = tmp;
			}
			if(min > tmp) {
				min = tmp;
			}
			sum += tmp;
		}
		System.out.println(min + " " + max + " " + sum);
	}
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  string a,b; cin>>a>>b;
  string s = a+b;
  ll n = stoll(s);
  for (int i=1; i*i<=n; i++) {
    if (i*i == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <queue>
#include <utility>
#include <cfloat>
#include <cmath>
#include <cstdio>
using namespace std;
#define EPS 1e-8
 
struct P{
  double t;
  char v,p,pre;
  P(double T=0.0,int V=0,int pp=0,int PRE=0){
    t=T;v=V;p=pp;pre=PRE;
  };
  bool operator<(const P &p)const{
    return t>p.t;
  }
};
struct Path{
  char d,c;
  Path(int D=0,int C=0){ d=D;c=C;};
};
 
int main(){
  int n,m, s,g, x,y,d,c;
  Path path[30][30];
  priority_queue<P> q;
 
  while( cin>>n>>m && (n|m) ){
    cin >> s >> g;
    s--; g--;
    for( int i=0;i<n;i++ )
      for( int j=0;j<n;j++ ){
	path[i][j].d=-1.0; path[i][j].c=-1;
      }
 
    for( int i=0;i<m;i++ ){
      cin >> x >> y >> d >> c;
      x--;y--;
      path[x][y].d=d; path[x][y].c=c;
      path[y][x] = path[x][y];
    }
 
    double cost[30][35][30]; // place,velocity, pre
    int dv[3] = {1,0,-1};
    for( int i=0;i<n;i++ )
      for( int j=1;j<31;j++ )
	for( int k=0;k<31;k++ )
	  cost[i][j][k] = DBL_MAX;
 
    while( !q.empty() ) q.pop();
    for( int i=0;i<n;i++ ){
      if( path[s][i].c<0 ) continue;
      q.push( P(path[s][i].d,1,i,s) );//t ,v, np, pre
      cost[i][1][s] = path[s][i].d;
    }

    double ans = DBL_MAX; 
    while( !q.empty() ){
      P p = q.top(); q.pop();
      double t = p.t;
      int v=p.v, np=p.p, pre=p.pre;
      if( np==g && v==1 ){
	ans = t;
	break;
      }
 
      for( int i=0;i<n;i++ ){
	if( path[np][i].c<0 ) continue;// たどり着けないノード
	if( i==pre ) continue; // 前回のノード
	
	for( int j=0;j<3;j++ ){
	  int nv = v + dv[j];
	  if( nv==0 || nv>path[np][i].c )    continue;
	  double nCost = t + (double)path[np][i].d/nv;
	  if( nCost>cost[g][1][np] || fabs(nCost-cost[g][1][np])<EPS ) continue;
	  if( cost[i][nv][np] < nCost ) continue;
	  if( fabs(cost[i][nv][np]-nCost)<EPS ) continue;
	  cost[i][nv][np]=nCost;
	  
	  q.push( P(nCost,nv,i,np) );
	}
      }
      
    }
    if( fabs(ans-DBL_MAX)<EPS )
      cout << "unreachable" << endl;
    else
      printf("%.6lf\n",ans);
 
  }
  return 0;
}

Measured memory_bytes: 1460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int q; cin >> q;
    arr<int> dp(1005, vector<int>(1005, 0));
    string s, t;
    rep(i, q){
        cin >> s >> t;
        int s_l = s.size(), t_l = t.size();
        rep(si, s_l) rep(ti, t_l){
            if(s[si]==t[ti]){
                dp[si+1][ti+1] = max(dp[si][ti]+1, dp[si+1][ti]);
            }else{
                dp[si+1][ti+1] = max(dp[si+1][ti], dp[si][ti+1]);
            }
        }

        pr(dp[s_l][t_l]);
        rep(si, s_l+1) rep(ti, t_l+1) dp[si][ti] = 0;
    }
    return 0;}


Measured memory_bytes: 6788
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll N, A, B;
	cin >> N >> A >> B;

	ll ans;

	if (N == 1) {
		if (A == B) { ans = 1; }
		else { ans = 0; }
	}

	else {
		if (A > B) { ans = 0; }
		else { ans = (N - 2)*(B - A) + 1; }
	}

	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 504
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

enum class Result
{
    UNKNOWN,
    LOSE,
    WIN,
};

bool setResult(vector<vector<Result> >& result, vector<pair<int, int> >& cnt, int x, int y)
{
    result[x][y] = Result::WIN;
    result[y][x] = Result::LOSE;
    ++ cnt[x].first;
    ++ cnt[y].second;
    int n = result.size();
    return cnt[x].first <= n / 2 && cnt[y].second <= n / 2;
}

void resetResult(vector<vector<Result> >& result, vector<pair<int, int> >& cnt, int x, int y)
{
    result[x][y] = Result::UNKNOWN;
    result[y][x] = Result::UNKNOWN;
    -- cnt[x].first;
    -- cnt[y].second;
}

int solve(vector<vector<Result> >& result, vector<pair<int, int> >& cnt, int k)
{
    int n = result.size();
    if(k == n * n)
        return 1;

    int x = k / n;
    int y = k % n;
    if(x == y || result[x][y] != Result::UNKNOWN)
        return solve(result, cnt, k+1);

    int ans = 0;
    for(int i=0; i<2; ++i){
        if(setResult(result, cnt, x, y))
            ans += solve(result, cnt, k+1);
        resetResult(result, cnt, x, y);
        swap(x, y);
    }
    return ans;
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<Result> > result(n, vector<Result>(n, Result::UNKNOWN));
        vector<pair<int, int> > cnt(n);
        bool ng = false;
        for(int i=0; i<m; ++i){
            int x, y;
            cin >> x >> y;
            -- x;
            -- y;
            result[x][y] = Result::WIN;
            result[y][x] = Result::LOSE;
            ++ cnt[x].first;
            ++ cnt[y].second;
            if(cnt[x].first > n / 2 || cnt[y].second > n / 2)
                ng = true;
        }

        if(ng)
            cout << 0 << endl;
        else
            cout << solve(result, cnt, 0) << endl;
    }
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  string s;
  cin >> s;
  if (s[2]==s[3] && s[4]==s[5]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
double dist(pair<int,int> A, pair<int,int> B)
{
	double res=(A.first-B.first)*(A.first-B.first)+(A.second-B.second)*(A.second-B.second);
	return sqrt(res);
}
int n;
double ans=0;
pair<int,int> a[1000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)	cin>>a[i].first>>a[i].second;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)	ans=ans+dist(a[i],a[j]);
	printf("%0.7f",ans/n);
	return 0;
}

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

const int MX =  1000000007;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct Sieve{
  int n;
  vector<int> f,primes;
  Sieve(int n=1):n(n),f(n+1){
    f[0] = f[1] = -1;
    for(ll i = 2; i<=n;++i){
      if(f[i]) continue; //素数でない場合continue
      primes.push_back(i);
      f[i] = i;
      for(ll j=i*i;j<=n;j+=i){
        if(!f[j]) f[j]=i;
      }
    }
  }
  bool isPrime(int x){
    return f[x]==x;
  }
  vector<int> factorList(int x){
    vector<int> res;
    while(x != 1){
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x){
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1,P(fl[0],0));
    for (int p:fl){
      if(res.back().first == p){
        res.back().second++;
      }else{
        res.emplace_back(p,1);
      }
    }
    return res;
  }
};

/*
int main() {
  int n;
  cin>>n;
  Sieve si(n);
  for(int i=0,size=si.f.size();i<size;++i){
    cout << i <<" " << si.f[i] << endl;
  }

  cin >> n;
  vector<P> res;
  res = si.factor(n);
  return 0;
}
*/

int main(){
  Sieve sieve(1e6);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  map<int,int> mp;
  rep(i,n){
    auto f=sieve.factor(a[i]);
    for (auto p:f){
      mp[p.first] = max(mp[p.first], p.second);
    }
  }

  mint lcm = 1;
  for (auto p:mp){
    rep(i,p.second){
      lcm *= p.first;
    }
  }

  mint ans;
  rep(i,n){
    mint b = lcm/a[i];
    ans += b;
  }

cout << ans.x << endl;

}

Measured memory_bytes: 4984
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	vector<int> aa(a);
	vector<int> bb(b);
	for (int i = 0; i < a; i++) {
		cin >> aa[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> bb[i];
	}

	int MAX = 0;

	for (int i = 0; i < b; i++) {
		int c = 0;
		int ii = i;
		for (int j = 0; j < a; j++) {
			if (aa[j] == bb[ii]) {
				c++;
				ii++;
			}
		}
		if (c > 0) {
			MAX = max(MAX, c);
		}
	}

	cout << MAX << endl;

	return 0;
}

Measured memory_bytes: 1236
from functools import reduce

def cmb(n, r, mod):
    r = min(r, n-r)
    if r == 0: return 1
    num = reduce(lambda x, y: x * y % mod, range(n, n-r, -1))
    den = reduce(lambda x, y: x * y % mod, range(1, r+1))
    return num * pow(den, mod-2, mod) % mod

n, a, b = map(int, input().split())
mod = 10**9 + 7

temp = pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)
ans = temp % mod

print(ans)

Measured memory_bytes: 3572
#include <stdio.h>

int try(long n, long div){
	return (n % div) ? (n % div == 1) : try(n/div, div);
}

int main(void){
	long n;
	int count = 0;

	scanf("%ld", &n);

	for(long i=1; i*i <= n; i++) {
		if((n-1) % i == 0) {
			count += 2;
			if(i*i == n-1)
				count--;
		}

		if(n % i == 0) {
			if(i != 1 && try(n, i))
				count++;
			if(i != n / i && try(n, n/i))
				count++;
		}
	}
	count--;
	printf("%d", count);

	return 0;
}


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

int main(){
  int r,c;
  while(cin >> r >> c && r && c){
    vector<vector<int> > v(r,vector<int>(c)), v2;
    int ans = 0;
    for(int i=0;i<r;i++) for(int j=0;j<c;j++) cin >> v[i][j];

    for(int i=0;i<(1<<(r-1));i++){
      v2 = v;
      for(int j=0;j<r-1;j++){
	if((i & (1<<j)) != 0){
	  for(int k=0;k<c;k++) v2[j][k] = (v2[j][k] + 1) % 2;
	}
      }
      int a = 0;
      for(int j=0;j<c;j++){
	int b = 0;
	for(int k=0;k<r;k++){
	  if(v2[k][j] == 0) b++;
	}
	a += max(b,r-b);
      }
      ans = max(ans,a);
    }
    cout << ans << endl;
  }
    return 0;
}

Measured memory_bytes: 1728
class Array
  def minus(other)
    b=self.dup
    other.each do |i|
      fl = false
      b = b.reject{ |j| i==j && !fl ? fl = true : false }
    end
    b
  end
end

@pairs=(1..7).map{|i| [i,i+1,i+2]}+(1..9).map{|i| [i,i,i]}
def c(arr)
  return false if (1..9).any?{ |i| arr.count(i) > 4 }
  return true if ((arr.size == 2)&&(arr.uniq.size == 1))
  @pairs.each do |p|
    if arr.size - arr.minus(p).size == 3
      return true if c(arr.minus(p))
    end
  end
  return false
end

while s = gets do
  arr = s.chomp.chars.map(&:to_i)
  res = (1..9).select{|i| c(arr+[i])}
  puts res.empty? ? '0' : res.join(' ')
end

Measured memory_bytes: 6712
#include<cstdio>
int main() {
	int n,m,x,y;
	int a,b;
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i = 0; i < n; i++) {
		scanf("%d",&a);
		if(a > x) {
			x = a;
		}
	}
	for(int i = 0; i < m; i++) {
		scanf("%d",&b);
		if(b < y) {
			y = b;
		}
	}
	if(y > x) {
		puts("No War");
	}
	else {
		puts("War");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 0;
string s;
map<string, ll> m;
ll top = 0;

void input() {
  IN(N);
  REP(i, N) {
    IN(s);
    if (m.count(s)) {
      decltype(m)::iterator itr = m.find(s);
      itr->second += 1;
      CHMAX(top, itr->second);
    } else {
      m.insert(mp(s, 0));
    }
  }
}

void solve() {
  for (auto itr = m.begin(); itr != m.end(); itr = next(itr, 1)) {
    if (itr->second == top) {
      PRINT(itr->first);
    }
  }
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 25216
cnt = gets.to_i
max = 10**18

inputs = gets.split.map(&:to_i).sort.reverse
if inputs.include?(0)
  result = 0
else
  result = 1
  for i in 0..cnt-1
  	result *= inputs[i]
    if result > max
      result = -1
      break
    end
  end
end
p result

Measured memory_bytes: 23144
fn lower_bound<T: std::cmp::Ord>(arr: &Vec<T>, b: T) -> usize {
    let (mut lt, mut ge) = (0, arr.len());
    // lt=-1にすると型強制しなきゃなのでここで確かめる
    if arr[lt] >= b {
        return 0;
    }
    while lt + 1 < ge {
        let m = (lt + ge) / 2;
        if arr[m] < b {
            lt = m;
        } else if arr[m] > b {
            ge = m;
        } else {
            return m;
        }
    }
    ge
}

fn main() {
    let n = read();
    let mut p: Vec<usize> = vec![];
    for _ in 0..n {
        p.push(read());
    }
    let mut q = vec![0; n];
    for i in 0..n {
        q[p[i] - 1] = i;
    }
    let mut prev = std::usize::MAX;
    let mut cont = 1;
    let mut anss = 0;
    for i in 0..n {
        if prev < q[i] {
            cont += 1;
        } else {
            cont = 1;
        }
        prev = q[i];
        anss = max(anss, cont);
    }
    println!("{}", n - anss);

    // let mut dp = vec![std::usize::MAX; n];
    // let mut ans = 0;
    // for i in 0..n {
    //     let b = lower_bound(&dp, v[i]);
    //     dp[b] = v[i];
    //     ans = max(ans, b + 1);
    // }
    // println!("{}", n - ans);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

ll manh(ll x1, ll x2, ll y1, ll y2);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<ll>> ab(N, vector<ll>(2));
  REP(i, N) cin >> ab[i][0] >> ab[i][1];
  vector<vector<ll>> cd(M, vector<ll>(2));
  REP(j, M) cin >> cd[j][0] >> cd[j][1];
  for(int i = 0; i < N; i++) {
    ll mn = 1e18;
    int mnindex = -1;
    for(int j = M - 1; j >= 0; j--) {
      ll temp = manh(ab[i][0], cd[j][0], ab[i][1], cd[j][1]);
      if(temp <= mn) {
        mn = temp;
        mnindex = j;
      }
    }
    cout << mnindex + 1 << endl;
  }
  return 0;
}

ll manh(ll x1, ll x2, ll y1, ll y2) { return abs(x1 - x2) + abs(y1 - y2); }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
LL A[MAX_N];
int N,K;

void solve() {
  int res=N;
  int p=-1;
  REP(i,N) if(A[i]==1) p=i;
  assert(p!=-1);
  
  FOR(i,p-K,p) {
    int l=max(0,i+1),r=max(0,N-(i+K)-1);
    int a=(l+K-2)/(K-1),b=(r+K-2)/(K-1);
    SMIN(res,a+b+1);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>K;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n, m int
	var a []int
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		var tmp int
		fmt.Scan(&tmp)
		a = append(a, tmp)
	}

	sum := 0
	for i := 0; i < m; i++ {
		sum += a[i]
	}

	if n >= sum {
		fmt.Println(n - sum)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 2900
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n;
    long[] a;
    long max;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n==0) break;
	    a = new long[n];
	    max = Integer.MIN_VALUE;
	    for(int i=0; i<n; i++)
		a[i] = sc.nextLong();

	    for(int first=0; first<n; first++){
		long sum=0;
		for(int p=first; p<n; p++){
		    sum += a[p];
		    max = Math.max(max, sum);
		}
	    }

	    System.out.println(max);
	}
    }
}

Measured memory_bytes: 26452
#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

static const int MAX = 1e5;
static const long long INF = 1e9;
int N;
long A[MAX], s, r, cnt;

int main() {
    scanf("%d", &N);
    s = 0;
    r = INF;
    cnt = 0;

    for ( int i = 0; i < N; i++ ) {
        scanf("%ld", &A[i]);
        s += abs(A[i]);
        r = min(r, abs(A[i]));

        if ( A[i] < 0 ) {
            cnt = (cnt + 1) % 2;
        }
    }
    
    if ( cnt == 1 ) {
        s -= r * 2;
    }
    
    printf("%ld\n", s);
    return 0;
}


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

using namespace std;

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

	vector<int> D;
	for (int i = 0; i < N; i++) {
		int d;
		cin >> d;
		D.push_back(d);
	}

	int total = 0;
	for (int x = 1; x <= N; x++) {
		for (int y = 1; y <= N; y++) {
			if (x != y) {
				//cout << x << " " << y << endl;
				total += D[x-1] * D[y-1];
			}
		}
	}

	cout << total / 2 << endl;

}
	


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

using namespace std;

int main(){
	int m1,m2,m3,m4;
	cin >> m1>> m2 >> m3>> m4;
	m1=m1+m2+m3+m4;
	cout << m1/60 << endl << m1%60 << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b<c?"No":"Yes")<<endl;
}


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

int n, m;
bool graph[60][60];

bool check[60];

void dfs(int x)
{
  check[x] = true;
  for (int i = 0; i < n; ++i)
  {
    if(check[i]) continue;
    else if (graph[x][i]) dfs(i);
  }
}

int main()
{
  cin >> n >> m;
  for (int i = 0; i < m; ++i)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[a][b] = graph[b][a] = true;
  }
  
  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i; j < n; ++j)
    {
      if(graph[i][j])
      {
        memset(check, 0, sizeof(check));
        graph[i][j] = graph[j][i] = false;
        dfs(0);
        for (int k = 0; k < n; ++k)
        {
          if(!check[k])
          {
            cnt++;
            break;
          }
        }
        graph[i][j] = graph[j][i] = true;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
/*  AC祈願アンコウ
   　／￣＼
   ○    ／￣￣￣＼ヘ
    　 /・　 ・　 ＼>   
    ／￣￣￣＼　　  Ｖ| 
    ｜ ――― ｜　　  ｜|
    ＼＿＿＿／　　  ∧|
    　　＼　　　　／
    　　　￣￣￣￣
*/

#include<bits/stdc++.h>
using namespace std;
 
#define int ll
typedef long long ll;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

void fastscan(int &number){
    bool negative = false;
    register int c;

    while(!isdigit((c=getchar()))&&(c!='-')){}
    ungetc(c,stdin);
 
    number = 0;
 
    c = getchar();
    if(c=='-'){
        negative = true;
        c = getchar();
    }
    for(;(c>47 && c<58);c=getchar()) number = number *10 + c - 48;
    if(negative) number *= -1;
}

signed main(){
    int n,h;
    cin >> n >> h;
    pair<int,int> v[114514];
    int Marx=-INF,Engels;
    REP(i,n){
        int tm,p;
        fastscan(tm);
        fastscan(p);
        if(Marx<tm){
            Marx = tm;
            Engels = p;
        }
        v[i] = MP(p,tm);
    }
    int sum = 0,num = 0;
    sort(v,v+n);
    RREP(i,n){
        if(v[i].FI<Marx) break;
        /*if(v[i].fi==Engels){
            Engelse = -1;
            continue;
        } else {*/
            h -= v[i].FI;
            num++;
            if(h<=0){
                printf("%lld\n",num);
                return 0;
            }
        //}
    }
    printf("%lld\n",num+(h+Marx-1)/Marx);
 
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;cin >> s;
	rep(i,s.size()){
		s.at(i) = (s.at(i) - 'A' + n) % 26 + 'A';
	}
	cout << s << endl;
}


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

int main() {
	long long a,v;cin>>a>>v;
	long long b,w;cin>>b>>w;
	long long t;cin>>t;
	long long xdiff=abs(a-b);
	long long vdiff=v-w;
	if(vdiff*t>=xdiff){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#define INF 2100000000
#define INVALID -1
using namespace std;
int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
int absint(int a)
{
	return max(a , - a);
}
int main()
{
	int n,i,ans=0;
	string  a, b, c;
	cin >> n >> a >> b >> c;
	for (i = 0; i < n; i++)
	{
		if (a[i] == b[i]&&b[i] == c[i]);
		else if (a[i] == b[i]) ans++;
		else if (b[i] == c[i]) ans++;
		else if (a[i] == c[i]) ans++;
		else ans += 2;
	}
	cout << ans << endl;
}


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

using namespace std;

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

    string S;
    cin >> S;

    int count = 0;
    int two_char_flag = 0;
    int i = 0;
//    cout << "S.size(): " << S.size() << endl;
    while (i < S.size()) {
//        cout << "i: " << i << endl;
//        if (i > 0) {
//            cout << "before: " << S.at(i - 1) << endl;
//        }
//        cout << "current: " << S.at(i) << endl;
//        cout << "two_char_flag: " << two_char_flag << endl;
//        cout << "count: " << count << endl;
        if (i == 0) {
            count++;
            i++;
            continue;
        }

        // 前の文字が2文字連結だったとき
        if (two_char_flag == 1) {
            count++;
            i++;
            two_char_flag = 0;
            continue;
        }

        // 最後の文字の場合
        if (i == S.size() - 1) {
            if (S.at(i - 1) == S.at(i)) {
                i += 1; // iインクリメントを1にし、カウントを増やさない
                two_char_flag = 1;
                continue;
            } else {
                count++;
                i++;
                continue;
            }
        }

        // 前の文字が1文字だったとき
        // 同じ文字の場合は連結させる
        if (S.at(i - 1) == S.at(i)) {
            count++;
            i += 2;
            two_char_flag = 1;
            continue;
        } else {
            count++;
            i++;
        }
    }

    cout << count << endl;
}


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

using namespace std;

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

    int n , m;
    cin >> n >> m;

    vector<int> adj[n];
    for (int i = 0 ;i < m ;i++) {
        int k;
        cin >> k;
        while (k--) {
            int s;
            cin >> s;
            adj[s - 1].push_back(i);
        }
    }

    vector<int> p(m);
    for (int i = 0 ;i < m ;i++)
        cin >> p[i];

    int ans = 0;
    for (int i = 0 ;i < (1 << n) ;i++) {
        vector<int> cnt(m , 0);
        for (int j = 0 ;j < n ;j++) {
            if (i & (1 << j)) {
                for (int b : adj[j])
                    cnt[b]++;
            }
        }

        bool good = 1;
        for (int j = 0 ;j < m ;j++)
            good &= p[j] == cnt[j] % 2;

        ans += good;
    }

    cout << ans;
}


Measured memory_bytes: 256