akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
cost = [0 for _ in range(m)]
key_set = [0 for _ in range(m)]
for i in range(m):
    a, b = LI()
    cost[i] = a
    trs = LI()
    ret = 0
    for j in trs:
        ret += 1 << (j - 1)
    key_set[i] = ret





dp = [INF] * (2 ** n)
dp[0] = 0
for j in range(m):
    for k in range(2 ** n):
        dp[key_set[j] | k] = min(dp[k] + cost[j], dp[key_set[j] | k])



if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 45400
N,W=map(int,input().split())
V=[]
M=[]
for _ in range(N):
    v,w=map(int,input().split())
    V.append(v)
    M.append(w)
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w-M[i]>=0:
            dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w-M[i]]+V[i])
        dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w])
print(max(dp[-1]))



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


int main() {

	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];

	int ans = 0;
	rep(i, n-1)rep(j, n - i - 1)
		ans += d[i] * d[i+j+1];
	cout << ans << endl;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

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


    cout << max(max(A+B,A-B),A*B) <<endl;
    return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll n,m,i,a,b,c;
vector<vi> adj;
bool pos = 1,visit[N];
ll co[N],val[N],in[N];
void dfs(ll v,ll d)
{
    visit[v] = true;
    co[v] = 1;
    val[v] = d;
    for(auto &it: adj[v]){
        if(co[it.f] == 0) dfs(it.f,d + it.se);
        else{
            if(co[it.f] == 1) pos = 0;
            if(abs(val[it.f] - val[v]) != it.se) pos = 0;
        }
    }
    co[v] = 2;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    adj.rs(n);
    rep(i,0,m){
        cin>>a>>b>>c;
        a--; b--;
        in[b]++;
        adj[a].pb({b,c});
    }
    rep(i,0,n) if(in[i] == 0) dfs(i,0);
    rep(i,0,n) if(!visit[i]){
        pos = 0;
        break;
    }
    if(!pos) cout<<"No";
    else{
        cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 12800
#include <cassert>
#include <cstdio>
using namespace std;

const int B = 1 << 7;
const int sz = 200064 / B * B;

int a[sz];
int b[sz];

int main() {
    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        scanf("%d", a + i);
    }
    for(int i = 0; i < N; i++) {
        scanf("%d", b + i);
    }
    int ans = 0;
    if(N & 1) {
        for(int i = 0; i < N; i++) {
            ans ^= a[i];
            ans ^= b[i];
        }
    }
    for(int i = 0; i < sz; i += B) {
        for(int j = 0; j < sz; j += B) {
            int lim_i = i + B;
            int lim_j = j + B;
            for(int ii = i; ii < lim_i; ii++) {
                for(int jj = j; jj < lim_j; jj++) {
                    ans ^= (a[ii] + b[jj]);
                }
            }
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    constexpr ll mod=1e9+7;
    ll ans=1;
    for(ll i=1;i<=N;++i){
        ans*=i;
        ans%=mod;
    }
    cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

signed main(){
	int l,k;
	cin>>l>>k;
	ll dp[110]={};
	dp[0]=1;
	dp[k-1]=1;
	for(int i=2;i<l;i++){
		if(i-k>0)dp[i]+=dp[i-k-1]+dp[i-2];
		else dp[i]+=dp[i-2];
	}
	ll ans=0;
	for(int i=0;i<l;i++)ans+=dp[i];
	cout<<ans<<endl;
}




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

using namespace std;

int main() {
    int n, c;  cin >> n >> c;
    vector<vector<long long> > d(c, vector<long long>(c)), s(n, vector<long long>(n));
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++)
            cin >> d[i][j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<vector<long long> > cnt(3, vector<long long>(c, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cnt[(i+j) % 3][s[i][j]]++;
        }
    }

    long long ans = 1e18, tmp;
    for (int k = 0; k < c; k++) {
        for (int l = 0; l < c; l++) {
            for (int m = 0; m < c; m++) {
                if (k == l || l == m || m == k)
                    continue;
                tmp = 0;
                for (int i = 0; i < c; i++) {
                    if (i != k)
                        tmp += cnt[0][i] * d[i][k];
                    if (i != l)
                        tmp += cnt[1][i] * d[i][l];
                    if (i != m)
                        tmp += cnt[2][i] * d[i][m];
                }

                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;


int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,k;
	cin >>n >>k;
	VI xx(n), yy(n), kek(n);
	rep(i,n) cin >> xx[i] >>yy[i];
	vector<pii> xy(n);
	rep(i,n) xy[i] = pii(xx[i],yy[i]);
	sort(all(xy));
	
	sort(all(yy));
	yy.erase(unique(all(yy)), yy.end());
	ll ans =1LL<<62;
	rep(iy,sz(yy)) rep2(jy,iy,sz(yy)){
		kek.clear();
		for(int t=0;t<n;t++){
			if(yy[iy] <= xy[t].second && xy[t].second <= yy[jy]){
				kek.push_back(xy[t].first);
				if(sz(kek)>=k){
					ll w = ((ll)yy[jy]-yy[iy]) * ((ll)kek.back() - kek[sz(kek)-k]);
					//printf("%d:%d:%d:%d::%lld\n", yy[iy],yy[jy],kek.back(),kek[sz(kek)-k],w);
					ans = min(ans, w);
				}
			}
		}
	}
	
	cout << ans <<"\n";
	return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def solve(H: int, W: int, a: "List[List[str]]"):
    grid = [[0]*W for _ in range(H)]

    grid[0][0] = 1
    for i in range(H):
        for j in range(W):
            if a[i][j] == "#":
                continue
            if i > 0:
                grid[i][j] += grid[i-1][j]
                grid[i][j] %= MOD
            if j > 0:
                grid[i][j] += grid[i][j-1]
                grid[i][j] %= MOD
    print(grid[H-1][W-1])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [next(tokens) for _ in range(H)]
    solve(H, W, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43592
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;

bool gcd(string s, string t) {
	if (s > t)return !gcd(t, s);
	if (s.size() > t.size()) return true;
	int cnt = 0;
	for (int i = 0; i + s.size() <= t.size(); i += s.size()) {
		cnt = i + s.size();
		for (int j = 0; j < s.size(); j++) {
			if (s[j] < t[i + j]) {
				return true;
			}
			if (s[j] > t[i + j]) {
				return false;
			}
		}
	}
	if (t.size() % s.size() == 0)return true;
	return !gcd(t.substr(cnt, t.size() - cnt), s);
}

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

	string s;
	string t;
	cin >> N;
	cin >> s >> t;
	if (s > t)swap(s, t);
	bool flag = gcd(s, t);
	if (!flag)swap(s, t);
	for (int i = N; i >= 0; i -= t.size()) {
		if (i%s.size() == 0) {
			for (int j = 0; j < i / s.size(); j++)cout << s;
			for (int j = 0; j < (N - i) / t.size(); j++)cout << t;
			cout << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1232
import java.util.Scanner;

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

	public void solve(Scanner sc) {
		int n = Integer.parseInt(sc.next());
		int answer = 0;
		for(int i=0; i<n; i++) {
			int a = Integer.parseInt(sc.next());
			answer += a-1;
		}
		
		System.out.println(answer);
	}
}

Measured memory_bytes: 25428
def primes(N):
    p = [False, False] + [True] * (N - 1)
    for i in range(2, int(N ** 0.5) + 1):
        if p[i]:
            for j in range(i * 2, N + 1, i):
                p[j] = False
    return p


N = int(input())
P = primes(N * 2)
print([i for i in range(N, N * 2) if P[i]][0])


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

	int X;
	cin >> X;

	int ans;
	int rest = X - 100*(X/100);
	int mod = rest % 5;
	int check = X/100;

	if(mod == 0){
		if(rest/5 > check) ans = 0;
		else ans = 1;
	}
	else{
		if(rest/5 + 1 > check) ans = 0;
		else ans = 1;
	}

	cout << ans << "\n";


return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n, sum = 0, result = 10000000000;
  int i, p;
  int x[100];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x[i]);
  }
  for(p = 1; p < 101; p++){
    for(i = 0; i < n; i++){
      sum += (x[i] - p) * (x[i] - p);
      if(result <= sum){
        break;
      }
    }
    if(result > sum){
      result = sum;
    }
    sum = 0;
  }
  printf("%d\n", result);
  
  return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE FlexibleContexts, BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Data.Array.IO
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    backet <- newArray ('a', 'z') 0 :: IO (IOUArray Char Int)
    !inp <- getContents
    let proc c = when (isAlpha c) $  writeArray backet c . (+1) =<< readArray backet c
    forM_ inp $ proc . toLower
    forM_ ['a'..'z'] $ \c ->
        (\f -> putStrLn (printf "%c : %d" c f)) =<< readArray backet c


Measured memory_bytes: 4196
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
const int maxn=2e5+10;
struct node{
	int x,y;
	bool operator<(const node &a)const{
		return y<a.y;
	} 
}cor[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&cor[i].x,&cor[i].y);
	}
	sort(cor+1,cor+n+1);
	ll now=0;
	for(int i=1;i<=n;i++){
		now+=cor[i].x;
		if(now>cor[i].y){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}



Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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


int main()
{
    string S; cin >> S;
    int N = S.size();

    int ns[10];
    rep(i, N)
        ns[i] = S[i] - '0';

    ll dp[11] = {0};
    ll c[11] = {0};
    c[N] = 1;
    for(int i = N-1; i >= 0; i--) {
        ll s = 0;
        for(int j = i; j < N; j++) {
            s = s*10+ns[j];
            dp[i] += dp[j+1]+s*c[j+1];
            c[i] += c[j+1];
        }
    }

    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import string

alpha = string.ascii_lowercase
nokori = [26-i for i in range(26)];nokori[0] = 0
s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())
sin = ""
for i in s:
    if nokori[alpha.index(i)] <= k:
        k -= nokori[alpha.index(i)]
        sin += "a"
    else:
        sin += i
q = alpha.index(sin[-1])
q += k
print(sin[:-1]+alpha[q%26])

Measured memory_bytes: 4212
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

bool check(ll N, ll K, vector<ll > A, vector<ll > F, ll mid){
    //mid（最小のコスト）にたどり着くまで何回トレーニングしなければいけないか
    ll training_cost = 0;
    for(ll i = 0; i < N; i++){
        //コストを減らす必要がない時
        if(A[i] * F[i] <= mid) continue;
        training_cost += A[i] - (mid / F[i]); 
    }

    if(training_cost > K) return false;

    return true;
}

int main(){

    ll N, K; cin >> N >> K;
    vector<ll > A(N, 0);
    vector<ll > F(N, 0);

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

    for(ll i = 0; i < N; i++){
        cin >> F[i];
    }
    
    sort(A.rbegin(), A.rend());
    sort(F.begin(), F.end());

    //最小の値なのでleftは当てはまらない数, rigthは当てはまりそうな数
    ll left = -1; ll right = A[0] * F[F.size()-1] + 1;

    //最小値を求める
    //rightを寄せていく
    while(left + 1 < right){
        ll mid = (left + right) / 2;
        if(check(N, K, A, F, mid)){
            right = mid;
        }else{
            left = mid;
        }
    }
    //最小値
    cout << right << endl;
}

Measured memory_bytes: 6552
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(b%a==0){
      System.out.println(a+b);
    }else{
      System.out.println(b-a);
    }
  } 
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a1,b1,c1;
	cin>>a1>>b1>>c1;
	char a2,b2,c2;
	cin>>a2>>b2>>c2;
	if(a1==c2)
	if(b1==b2)
	if(c1==a2)
	{
		cout<<"YES";
		return 0;	
	}
	cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static int print(int[] arr) {

		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == 0) {
				return i+1;
			}
		}
		return 0;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int[] arr = new int[5];

		for (int i = 0; i < arr.length; i++) {
			arr[i] = s.nextInt();
		}

		int result = print(arr);
		System.out.println(result);

	}

}


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


int main(){
   int n;cin>>n;
   vector<int> a(n);
   rep(i,n) cin>>a[i];
   int count = 1;
   int ans=0;
   rep(i,n){
       if(a[i]!=count)ans+=1;
       else count+=1;
   }
   if(count==1)cout<<-1<<endl;
else cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1E-11;

int bit[600000];
void update(int p, int v) {
	for (; p <= IT_MAX; p += p & (-p)) bit[p] += v;
}
int getsum(int p) {
	int rv = 0;
	for (; p; p -= p & (-p)) rv += bit[p];
	return rv;
}

ll in[200050];
ll sum[200050];
vector <ll> Vx;
int main() {
	int N, K, i;
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) {
		scanf("%lld", &in[i]);
		in[i] -= K;
		sum[i] = sum[i - 1] + in[i];
	}
	for (i = 0; i <= N; i++) Vx.push_back(sum[i]);
	sort(all(Vx));
	Vx.erase(unique(all(Vx)), Vx.end());
	
	ll ans = 0;
	for (i = 0; i <= N; i++) {
		int t = lower_bound(all(Vx), sum[i]) - Vx.begin() + 1;
		ans += getsum(t);
		update(t, 1);
	}
	return !printf("%lld\n", ans);
}

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

int main(){
	unsigned long long k, a, b;
	cin >> k >> a >> b;
	k++;
	unsigned long long kaisu, result;
	if(b > a){
		kaisu = (k - a) / 2;
		result = a;
		for(unsigned long long i = 0; i < kaisu; i++){
			result += b - a;
		}
		if((k - a) % 2 == 1) result++;
	}
	if(result > k) cout << result << endl;
	else cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

int main()
{
    int n, r;
    cin >> n >> r;

    int ans;
    if (n < 10)
        ans = r + 100 * (10 - n);
    else
        ans = r;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

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


Measured memory_bytes: 256
import scala.io.StdIn._
object Main {
  def main(args:Array[String]) {
    val N = readLine().toInt

    var m = Map[String, Int]()
    for(i <- 0 until N) {
      var str = readLine()
      m += str -> (m.getOrElse(str,0) + 1)
    }
    println(m.size)
  }
}


Measured memory_bytes: 84416
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int maxsize=0;
	int maxcnt=0;
	int ans_num;
	int ans_num2;
	vector<string> str_v;
	
	string in;
	while(cin>>in){
		str_v.push_back(in);
		if(maxsize < in.size()){
			maxsize = in.size();
			ans_num = str_v.size()-1;
		}
	}
	for(int i=0;i<str_v.size();i++){
		int cnt=0;
		for(int j=0;j<str_v.size();j++){
			if(str_v[i] == str_v[j]) cnt++;
		}
		if(maxcnt < cnt){
			maxcnt = cnt;
			ans_num2 = i;
		}
	}
	
	cout<< str_v[ans_num2]<< " "<< str_v[ans_num]<< endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

map<string, int>table;

int main(void)
{
	int n, m;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;

		table[s] = table[s] + 1;
	}

	cin >> m;

	for (int i = 0; i < m; i++)
	{
		string s;
		cin >> s;

		table[s] = table[s] - 1;
	}
	int best = 0;
	for (auto it = table.begin();it != table.end();it++)
	{
		if (it->second > best)
		{
			best = it->second;
		}
	}

	cout << best << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define orz cin
#define QAQ cout
using namespace std;
int main(){
    int i,a=0;
    string s;
    orz>>s;
    for(i=0;i<s.length();i++){
    	if(a==0&&s[i]=='C')a++;
    	if(a==1&&s[i]=='F')a++;
    }
    if(a==2)QAQ<<"Yes";
    else QAQ<<"No";
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int sum[112345];
const int m=86400;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  ll s=0;
  rep(i,n){
    int x,y;
    cin>>x>>y;
    (x+=s)%=m;
    ++sum[x];
    //--sum[y];
    //if(x>y) ++sum[0];
    s=(x+y)%m;
  }
  //rep(i,m) sum[i+1]+=sum[i];
  rep(i,11234) sum[i+m]=sum[i];
  s=0;
  rep(i,10801) s+=sum[i];
  ll re=s;
  rep(i,m+1){
    MX(re,s);
    s+=sum[10801+i]-sum[i];
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        int first = 0;
        int sec = 0;
        int pre = -1;
        for (int i = n-1; i >= 0; i--) {
            if(pre == a[i]){
                pre = -1;
                if(first == 0) first = a[i];
                else sec = a[i];
            }else{
                pre = a[i];
            }
            if(sec != 0) break;

        }

        System.out.println((long)first * sec);
        sc.close();
    }

}


Measured memory_bytes: 50428
n, k =[int(i) for i in input().split()]
a = [int(i) - 1 for i in input().split()]

go = dict()
res = []

go[0] = True
res = [0]

now = a[0]
while True:
    if now in go:
        break
    res.append(now)
    go[now] = True
    now = a[now]

# 1
# [0, 1, 2, 3]
# (5 - 1) % (xunhuan)
amari = res.index(now)
xunhuan = res[amari:]
#print(res, xunhuan, amari)

if k <= amari:
    print(res[k] + 1)
else:
    print(xunhuan[ (k - amari) % len(xunhuan)] + 1)

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

const int mn = 5e5+10;

int p[mn],q[mn],val[mn<<2],ans[mn];

#define ls idx<<1
#define rs idx<<1|1

void build(int idx,int l,int r){
	if(l==r){
		val[idx]=p[l];
		return;
	}
	int mid=(l+r)>>1;
	build(ls,l,mid);build(rs,mid+1,r);
	val[idx]=max(val[ls],val[rs]);
}

void update(int idx,int l,int r,int p,int v){
	if(l==r){
		val[idx]=v;
		return;
	}
	int mid = (l+r)>>1;
	if(p<=mid)
		update(ls,l,mid,p,v);
	else
		update(rs,mid+1,r,p,v);
	val[idx]=max(val[ls],val[rs]);
}

int query(int idx,int l,int r,int L,int R){
	if(L<=l&&r<=R)
		return val[idx];
	if(R<l||r<L)
		return -1;
	int mid=(l+r)>>1;
	return max(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R));
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		q[p[i]]=i;
	}
	build(1,1,n);
	priority_queue<int> pq;

	for(int i=1;i<=n;i++)
		if(query(1,1,n,max(1,i-k+1),min(n,i+k-1))==p[i])
			pq.emplace(i);
	for(int i=n;i>=1;i--){
		int x=pq.top();pq.pop();
		ans[x]=i;
		update(1,1,n,x,-1);
		int nr=query(1,1,n,x,min(n,x+k-1)),nl=query(1,1,n,max(1,x-k+1),x);
		if(nr!=-1&&query(1,1,n,max(1,q[nr]-k+1),min(q[nr]+k-1,n))==nr)
			pq.emplace(q[nr]);
		if(nl!=-1&&query(1,1,n,max(1,q[nl]-k+1),min(q[nl]+k-1,n))==nl)
			pq.emplace(q[nl]);
	}
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<'\n';
}


Measured memory_bytes: 17264
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];

    //rep(i,N) if (i%2==1) swap(A[i],B[i]);
    vector<int> C(N,1);
    rep (i,N/2) C[i] = 0;
    int ans = INF;
    do {
        vector<pii> P,Q;
        rep(i,N) {
            if (C[i]) {
                if (i%2==0) P.emplace_back(A[i],i);
                else P.emplace_back(B[i],i);
            } else {
                if (i%2==1) Q.emplace_back(A[i],i);
                else Q.emplace_back(B[i],i);
            }
        }
        sort(all(P)); sort(all(Q));
        bool ok = true;
        rep(i,N-1) {
            if (i%2==0) {
                if (P[i/2].first>Q[i/2].first) ok = false;
            } else {
                if (Q[i/2].first>P[i/2+1].first) ok = false;
            }
        }
        if (ok) {
            int cnt = 0;
            vector<int> X(N);
            rep(i,N) {
                if (i%2==0) X[i] = P[i/2].second;
                else X[i] = Q[i/2].second;
            }
            rep(i,N-1) {
                for (int j = N-1; j >= i+1; j--) {
                    if (X[j] < X[j-1]) {
	                swap(X[j],X[j-1]);
	                cnt++;
                    }
                }
            }
            chmin(ans,cnt);
        }
    } while (next_permutation(all(C)));

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

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

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

int dp[5005][5005];

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

    string S;
    cin >> S;

    for (int i = N - 1; i >= 0; i--) {
        for (int j = N - 1; j >= 0; j--) {
            if (S[i] != S[j]) dp[i][j] = 0;
            else dp[i][j] = dp[i + 1][j + 1] + 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            int cand = min(dp[i][j], j - i);
            chmax(ans, cand);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 98048
#include<stdio.h>
 
int main() {
    
  int H,W,i,j;
 
   while (1) {
      scanf("%d%d",&H,&W);
      if  (H == 0 && W == 0) {
         break;
      }
      for (j=0; j<H; j++) {      
         for (i=0; i<W; i++) {
            if ( i == 0 || j == 0 || i == W-1 || j == H-1) {
               printf("#");
            } else {
               printf(".");
            }
         }
      printf("\n");
      }
   printf("\n");
   }
    
   return 0;
       
}

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

class Point {
public:
    double x, y;
};

bool isIntersect(Point p1, Point p2, Point p3, Point p4) {
    return ((p1.x - p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x))
        * ((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x)) < 0;
}

int main () {
    Point p[4];
    while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
                 &p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y) != EOF) {
        if (isIntersect(p[0], p[2], p[1], p[3]) && isIntersect(p[1], p[3], p[0], p[2])) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1224
#include<stdio.h>
int ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MIN(int a,int b){return a<b?a:b;}
int MF(int s,int t,int e,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,e,MIN(min,co[i]));
    co[i]-=r;
    co[(i+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
//呼び出す方
//sからtへの最大流を求める　ノード数v辺の数e　aからbへキャパcのフローが流れる
int maxf(int s,int t,int v,int e,int *a,int *b,int *c){
  int i,f,r;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];
    co[ta[b[i]]=i+e]=0;
  }
  for(f=0;r=MF(s,t,e,1000000000);f+=r){
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}
int main(){
  int n,a[100010],b[100010],c[100010],r=0,i,j,x[1010],y[1010];
  scanf("%d",&n);
  for(i=0;i<2*n;i++)scanf("%d %d",&x[i],&y[i]);
  for(i=0;i<n;i++){
    a[r]=2*n;
    b[r]=i;
    c[r++]=1;
    a[r]=i+n;
    b[r]=2*n+1;
    c[r++]=1;
  }
  for(i=0;i<n;i++){
    for(j=n;j<2*n;j++){
      if(x[i]<x[j]&&y[i]<y[j]){
	a[r]=i;
	b[r]=j;
	c[r++]=1;
      }
    }
  }
  printf("%d\n",maxf(2*n,2*n+1,2*n+2,r,a,b,c));
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
#define N 1000
#define N2 N*N
bool prime[N2+1];
int cave[N+2][N+2]={};
pair<int,int> locate[N2+1];
int last[N+2][N+2];
int dp[N+2][N+2];
int m,n;

bool wall(int x,int y){ return x==0 || y==0 || x==N+1 || y==N+1; }

int rec(int x,int y){
    if(wall(x,y) || cave[x][y]>m)return 0;
    if(dp[x][y])return dp[x][y];
    pair<int,int> child[3];
    rep(i,3)child[i]=pair<int,int>(rec(x+i-1,y-1),last[x+i-1][y-1]);
    sort(child,child+3);
    dp[x][y]=child[2].first;
    if(prime[cave[x][y]])dp[x][y]++;
    last[x][y]=child[2].second;
    if(last[x][y]==0 && prime[cave[x][y]]) last[x][y]=cave[x][y];
    return dp[x][y];
}

int main(void){
    fill(prime,prime+N2+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i<=N2;i++){
        if(prime[i]) for(int k=2;i*k<=N2;k++) prime[i*k]=false;
    }

    int x=1,y=N,d=0;
    int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
    for(int i=N2;i>0;i--){
        cave[x][y]=i;
        locate[i] = pair<int,int>(x,y);
        if(wall(x+dx[d],y+dy[d]) || cave[x+dx[d]][y+dy[d]]) d=(d+1)%4;
        x+=dx[d];
        y+=dy[d];
    }

    while(cin>>m>>n, m|n){
        rep1(x,N)rep1(y,N) dp[x][y]=last[x][y]=0;
        int x=locate[n].first,y=locate[n].second;
        int cnt = rec(x,y);
        printf("%d %d\n",cnt,last[x][y]);
    }

    return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	int sm = (n + 1) - (n & 1);
	vector<pair<int, int> > an;
	f(i, 1, n + 1)f(j, i + 1, n + 1)if (i + j != sm)an.push_back(make_pair(i, j));
	printf("%d\n", (int)an.size());
	f(i, 0, an.size())printf("%d %d\n", an[i].first, an[i].second);
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll    = long long;
using vll   = vector<ll>;
using pll   = pair<ll,ll>;
using ld    = long double;

const ll mod = (ll)1e9 + 7;
const ll mxN = (ll)1e6 + 3;

void solve() {
	ll n;cin>>n;
	if(n%1000==0) cout<<0;
	else cout<<1000-(n%1000)<<"\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
		solve();
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int *arr = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int maxv = arr[1] - arr[0];
	int minv = arr[0];
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, arr[i] - minv);
		minv = min(minv, arr[i]);
	}
	delete[] arr;
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<n;i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0;i <= n;i++){
        ans = i*i;
        if(ans > n){
            ans = (i-1)*(i-1);
            break;
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#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>
#include<complex>
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 = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

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;
};

class mint {
	long long x;
public:
	mint(long long 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 operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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;
	}

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

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

ll N, M, Q;

vector<ll> a, b, c, d;

ll ans;

void dfs(vector<ll> v, ll sz) {
	if (sz < N) {
		ll x = v[sz];

		for (ll i = x; i <= M; i++) {
			v.push_back(i);
			dfs(v, sz + 1);
			v.pop_back();
		}
	}

	else {
		ll now = 0;
		repn(i, Q) {
			if (v[b[i]] - v[a[i]] == c[i]) { now += d[i]; }
		}
		ans = max(now, ans);
	}
}

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

	a.assign(Q + 1,0);
	b.assign(Q + 1, 0);
	c.assign(Q + 1, 0);
	d.assign(Q + 1, 0);
	repn(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

	ans = 0;

	vector<ll> v(1, 1);
	dfs(v, 0);
	cout << ans << endl;
	
	system("PAUSE");
}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,m,d[maxn],tot=1,head[maxn],a,b,vis[maxn];
struct edge{int to,nxt;}e[maxn<<1];

void ins(int u,int v) {e[++tot]=(edge){v,head[u]},head[u]=tot;}

void dfs(int x) {
    vis[x]=1;
    for(int i=head[x];i;i=e[i].nxt)
        if(!vis[e[i].to]) dfs(e[i].to);
}

int main() {
    read(n),read(m);
    for(int i=1,x,y;i<=m;i++) {
        read(x),read(y);
        d[x]++,d[y]++;
        ins(x,y),ins(y,x);
    }
    for(int i=1;i<=n;i++) if(d[i]&1) return puts("No"),0;
    if(m<n+2) return puts("No"),0;
    if(m>n+2) return puts("Yes"),0;
    for(int i=1;i<=n;i++) {
        if(d[i]>=6) return puts("Yes"),0;
        if(d[i]==4) {
            if(!a) a=i;
            else if(!b) b=i;
        }
    }
    vis[a]=vis[b]=1;
    for(int i=head[a];i;i=e[i].nxt)
        if(vis[e[i].to]) return puts("Yes"),0;
        else dfs(e[i].to);
    puts("No");
    return 0;
}


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

using namespace std;

long long a, b, c, d, x, y;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
}

Measured memory_bytes: 3644
def main():
    n = int(input())
    ws = list(map(int, input().split()))

    ans = float("inf")
    for i in range(1, n):
        left = sum(ws[:i])
        right = sum(ws[i:])
        diff = abs(left - right)
        ans = min(ans, abs(diff))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	int h,m,s,S;
	scanf("%d" , &S);
	h = S / 3600;
	m = S / 60 - h * 60;
	s = S % 60;
	printf("%d:%d:%d\n" , h , m , s);
	return 0;
}

Measured memory_bytes: 592
import math
a,b,c=map(float, input().split())
c=int(c)
c=math.pi*c/180
S=a*b*math.sin(c)/2
L=a+b+(a**2+b**2-2*a*b*math.cos(c))**(1/2)
h=b*math.sin(c)
print(round(S,6))
print(round(L,6))
print(round(h,6))


Measured memory_bytes: 5700
N, M = map(int, input().split()) 
A = input().split()

sum = 0
for a in A:
  sum += int(a)

#print(sum)
limit = sum/(4*int(M))

j = 0
for i in range(N):
  if int(A[i])>=limit:
    j += 1


if j >= int(M):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3060
N, K = list(map(int, input().split()))
A = list(map(lambda x: int(x) - 1, input().split()))

now = 0
route = []
seen = set()
while True:
    if now in seen:
        break
    route.append(now)
    seen.add(now)
    now = A[now]

loop_start = route.index(now)
loop_size = len(route) - loop_start

n_for_loop = min(K, loop_start)
n_in_loop = (K - n_for_loop) % loop_size

print(route[n_for_loop + n_in_loop] + 1)

Measured memory_bytes: 32452
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n),x;
	ll sum=0;
	rep(i, n) {
		cin >> a[i] ;
	}
	rep(i, n) {
		cin >> b[i];
	}
	int ans = 0;
	rep(i, n) {
		int z = a[i] - b[i];
		if (z > 0) {
			x.push_back(z);
		}
		else if(z < 0) {
			sum += z * (-1);
			ans++;
		}
	}
	if (sum == 0) {
		cout << 0 << endl;
		return 0;
	}

	sort(x);
	reverse(x);

	rep(i, x.size()) {
		sum -= x[i];
		ans++;
		if (sum <= 0) {
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}




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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

ll fact(ll n){
    if(n ==1) return 1;
    return n * fact(n-1);
}

ll N, M, Q;
vector<ll> A;
vector<ll> B;
vector<ll> C;
vector<ll> D;
ll ans = 0;

vector<ll> v;
void dfs(ll now, ll start, ll end){
    if(now == N){
        ll temp = 0;
        REP(i, Q){
            if(v[B[i]-1] - v[A[i]-1] == C[i]){
                temp += D[i];
            }
        }
        ans = max(ans, temp);
    }
    else{
        for(ll i=start; i<=end; i++){
            v[now] = i;
            dfs(now+1, i, end);
        }
    }
}
int main()
{
    cout << fixed << setprecision(15);
    cin >> N >> M >> Q;

    A.resize(Q);
    B.resize(Q);
    C.resize(Q);
    D.resize(Q);

    REP(i, Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }

    v.resize(N);

    ll start = 1;
    ll end = M;
    ll size = N;
    dfs(0, start, end);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640