akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	int n,c,p[100];
	int i,j,sum,aum,z;
	aum=0;
	sum=0;
	scanf("%d %d",&n,&c);
	for(i=0;i<c;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<c;i++){
		sum=sum+p[i];
	}
	z=n+1;
	if(sum%z==0){
		aum=sum/z;
	}
	if(!(sum%z==0)){
		aum=(sum/z)+1;
	}
	printf("%d\n",aum);
	return 0;
}


Measured memory_bytes: 2120
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
		int n = ni();
		double[][] xy = new double[n][2];
		for(int i = 0; i < n; i++) {
			xy[i][0] = nd();
			xy[i][1] = nd();
		}
		double lengsum = 0;
		
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				double ax = xy[i][0];
				double ay = xy[i][1];
				double bx = xy[j][0];
				double by = xy[j][1];
 				lengsum += Math.pow(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2), 0.5);
 				//System.out.println(lengsum);
			}
		}
		
		int all = 1;
		int section = n - 1;
		int choice = n * (n - 1) / 2;
		int tmp = n;
		while(tmp > 1) {
			all = all * tmp;
			tmp--;
		}
		int b = all * section / choice;
		System.out.println(lengsum * b / all);

	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 21204
#include <iostream>

using namespace std;

int main(void){
  char x;
  cin >> x;
  if(x== 'a' || x== 'i' || x== 'u' || x== 'e' || x== 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)

N = int(input())
adj = [[] for _ in range(N+1)]
for e in range(1,N):
  a,b = map(int, input().split())
  adj[a].append((b,e))
  adj[b].append((a,e))

#print(adj)

col_num = max([len(ad) for ad in adj])
edge_color = [0]*N
visited = [False]*(N+1)

def dfs(v,c=-1):
  #print(v,e,edge_color)
  #col_lis = [i for i in range(1,col_num+1)]
  #if e >0:
    #col_lis.remove(edge_color[e])
  color = 1
  for w,f in adj[v]:
    if visited[w]==False:
      visited[v] = True
      if c==color: color+=1
      edge_color[f] = color
      dfs(w,color)
      color+=1

dfs(1)

print(col_num)
for i in range(1,N):
  print(edge_color[i])

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

public class Main {
    public static void main (String[] args ) {
        try {
           BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String strLine = reader.readLine();
            char[] chaAryLineS = strLine.toCharArray();
            char[] chaAryLineSAfter = new char[chaAryLineS.length * 2];

            strLine = reader.readLine();
            char[] chaAryLineP = strLine.toCharArray();
            // chaAryLineS??? chaAryLineSAfter???COPY
            System.arraycopy(chaAryLineS, 0, chaAryLineSAfter, 0,
                    chaAryLineS.length);
            
            // chaAryLineS??? chaAryLineSAfter???????????´???COPY
            System.arraycopy(chaAryLineS, 0, chaAryLineSAfter,
                    chaAryLineS.length, chaAryLineS.length);            
            
            int intlength = chaAryLineSAfter.length - chaAryLineP.length + 1;
            int intCount = 0;
            boolean booYes = false;
            
            for (int i = 0; i < intlength; i++) {
                for (int j = 0; j < chaAryLineP.length; j++) {
                    if (chaAryLineSAfter[i+j] == chaAryLineP[j]) {
                        intCount++;
                        if (intCount == chaAryLineP.length) {
                            booYes = true;
                        }
                    }
                }
                intCount = 0;
            }
            if (booYes) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }

        } catch (IOException e) {
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24408
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  int n, x; cin >> n >> x;
  int ans = 1;
  int d = 0;
  REP(i, n){
    int l;  cin >> l;
    d += l;
    if(d <= x){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = input()
if len(N) == 1:
    print(int(N))
    exit()

for c in N[1:]:
    if c != "9":
        print(int(N[0]) - 1 + (len(N) - 1) * 9)
        exit()
print(int(N[0]) + (len(N) - 1) * 9)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[100000],dp[100000];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    fill(dp,dp+n,1000000007);
    for(int i=n-1;i>=0;i--){
        *upper_bound(dp,dp+n,a[i])=a[i];
    }
    cout<<lower_bound(dp,dp+n,1000000007)-dp<<endl;
}

Measured memory_bytes: 1024
cards = Hash.new()
[2,3,4,5,6,7,8,9,10,11,12,13,1].zip((0..13).to_a) do |k, v|
  cards[k] = v
end

a, b = gets.chomp.split(" ").map(&:to_i)
if cards[a] < cards[b] then
  puts "Bob"
elsif cards[a] == cards[b] then
  puts "Draw"
else
  puts "Alice"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> A(N, 0);
	rep (i, N){
		cin >> A[i];
	} // end rep

	int diff = 0;
	for (int i = 0; i < N; ++i){
		for (int j = i + 1; j < N; ++j){
			int curr = abs(A[i] - A[j]);
			diff = max(diff, curr);
		} // end for
	} // end for

	cout << diff << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char S[99];
    char rS[99];
    int i,len,hantei,k=0;
    scanf("%s",S);
    for(i=0;S[i]!='\0';i++);
    len=i;
    for(i=0;S[i]!='\0';i++){
        rS[i]=S[len-i-1];
    }
    rS[len]='\0';
    if(len%2==0){
        hantei=len/2;
    }else{
        hantei=len/2+1;
    }
    for(i=0;i<hantei;i++){
        if(S[i]!=rS[i]){
            k=k+1;
        }
    }
    printf("%d\n",k);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
f = 0

if N % 4 == 0 or N % 7 == 0:
    f = 1
else:
    while N > 4:
        N -= 4
        if N % 7 == 0:
            f = 1
            break

if f == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 2940
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = 1; i <= test_cases; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }
}

class Solver {
    void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
    	String s = in.next();
    	int ans = 0;
    	for (int i = 0; i < s.length(); i++) {
    		if (s.charAt(i) == '1') ++ans;
    	}
    	out.println(ans);
    }
}


class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}

Measured memory_bytes: 21460
N,K=map(int,input().split())
v=list(map(int,input().split()))
ans=0

for i in range(min(N,K)+1): #i個の宝石を得る
    for a in range(i+1): #左からa個の宝石を得る
        b=i-a #右からb個の宝石を得る
        val=sorted(v[:a]+v[N-b:]) #宝石の価値の合計
        s=sum(val)
#        print(val)
        for j in range(0,min(K-i,len(val))): #j個の宝石を捨てる、上限はk-iか得た宝石の個数i
            if j<len(val):
#                print("#",a,b,min(K-i,len(val)),val)
                if val[j]<0: #負の宝石を捨てる
                    s-=val[j]
            else:
                break
#        print(a,b,min(K-i,len(val)),val,sum(val))
        ans=max(ans,s)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int miny = 100000;
    for (int i = 0; i < n-2; i++) {
        int x = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        int y = abs(753 - x);
        miny = min(miny, y);
    }
    cout << miny << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> cities;
    Rep (i, M) {
        int p, y;
        cin >> p >> y;
        cities.push_back(make_tuple(y, p, i));
    }

    sort(cities.begin(), cities.end());
    vector<int> cnt(N+1, 0);
    vector<tuple<int, int, int>> ID;
    for (auto e : cities) {
        int i = get<2>(e);
        int city = get<1>(e);
        cnt[city]++;
        int order = cnt[city];
        ID.push_back(make_tuple(i, city, order));
    }

    sort(ID.begin(), ID.end());
    for (auto e : ID) {
        cout << setw(6) << setfill('0') << get<1>(e) << setw(6) << setfill('0') << get<2>(e) << "\n";
    }
}

Measured memory_bytes: 4340
#include<stdio.h>
#define M 1000000

int main(void){
  int i,j;
  int n;
  int array[M][2];
  int count;

  for(i=0;i<M;i++){
    array[i][0]=i+1;
    array[i][1]=1;
  }

  array[0][1]=0;

  for(i=1;i<M;i++)
    if(array[i][1]){
      for(j=i;j<M;j+=(i+1))
        array[j][1]=0;
      array[i][1]=1;
    }

  for(;scanf("%d",&n)==1;){
    count=0;

    for(i=0;i<n;i++)
      if(array[i][1])
        count++;

    printf("%d\n",count);
  }

  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int a[2][n];
  rep(i, 0, 2) rep(j, 0, n) cin >> a[i][j];
  rep(i, 1, n) {
    a[0][i] += a[0][i - 1];
    a[1][i] += a[1][i - 1];
  }
  int ans = 0;
  rep(i, 0, n) {
    int c = a[0][i] + a[1][n - 1];
    if(i > 0) c -= a[1][i - 1];
    ans = max(ans, c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#define N 100000
using namespace std;

void eratosthenes(int n, bool prime[]);

int main() {
	int l[N], r[N], wa[N];
	int q, tmp = 0;
	bool prime[N], like[N];

	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> l[i] >> r[i];
	}

	eratosthenes(N, prime);
	for (int i = 0; i < N; ++i) like[i] = 0;
	for (int i = 3; i < N; i += 2) {
		if (prime[i] && prime[(i + 1) / 2]) {
			like[i] = 1;
		}
	}
	for (int i = 0; i < N; ++i) {
		if (like[i]) {
			++tmp;
		}
		wa[i] = tmp;
	}
	for (int i = 0; i < q; ++i) {
		cout << wa[r[i]] - wa[l[i] - 1] << endl;
	}
	
	return 0;
}

void eratosthenes(int n,bool prime[]) {
	for (int i = 0; i < n; ++i) prime[i] = 1;
	prime[0] = prime[1] = 0;
	for (int i = 0; i < n; ++i) {
		if (prime[i]) {
			for (int j = i + i; j < n; j += i) {
				prime[j] = 0;
			}
		}
	}
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
	ll n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	cin >> v[i];
	ll ans=0;
	for(int i=1;i<n;i++)
	{
		ans+=max(0,v[i-1]-v[i]);
		v[i]=max(v[i],v[i-1]);
	}
	cout <<ans << endl;
}

int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 4000
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    int ans = 0;

    for (int i = 0; i < N; ++i) {
        if (A[i] == B[i]){
            if (A[i] == C[i]) {
                continue;
            }
            else {
                ++ans;
            }
        }
        else if (A[i] == C[i]) {
            ++ans;
        }
        else {
            if (B[i] == C[i]) {
                ++ans;
            }
            else {
                ans += 2;
            }
        }
    }
    cout << ans;
    return 0;
}

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

struct Dice {
	int d[6], E, S, U;
	void init(int a[]) {
		rep(i, 6)d[i] = a[i];
		E = 2; S = 1; U = 0;
	}
	void rotate(char C) {
		int a = E, b = S, c = U;
		switch (C) {
		case'E':E = U; U = 5 - a; break;
		case'N':U = S; S = 5 - c; break;
		case'S':S = U; U = 5 - b; break;
		case'W':U = E; E = 5 - c; break;
		case'R':S = E; E = 5 - b; break;
		case'L':E = S; S = 5 - a; break;
		}
	}
	int rotate(int a, int b) {
		rep(k, 2) {
			rep(i, 4) {
				rep(j, 4) {
					if (a == d[U] && b == d[S])return d[E];
					rotate('E');
				}
				rotate('S');
			}
			rotate('L');
		}
	}
	bool operator==(Dice b) {
		rep(k, 2) {
			rep(i, 4) {
				rep(j, 4) {
					if (b.d[b.U] == d[U] && b.d[b.S] == d[S] && b.d[b.E] == d[E] &&
						b.d[5 - b.U] == d[5 - U] && b.d[5 - b.S] == d[5 - S] && b.d[5 - b.E] == d[5 - E])
						return true;
					rotate('E');
				}
				rotate('S');
			}
			rotate('L');
		}
		return false;
	}
};
Dice d[100]; int a[100][6];
int main() {
	int n; cin >> n;
	rep(i, n) {
		rep(j, 6)cin >> a[i][j];
		d[i].init(a[i]);
	}
	rep(i, n)for (int j = i + 1; j < n; j++) {
		if (d[i] == d[j]) {
			puts("No"); return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 3080
import math
N=int(input())

def isPrime(x):
    if x==2:
        return True
    if x<2 or x%2==0:
        return False
    i=3
    while i<=math.sqrt(x):
        if x%i==0:
            return False
        i=i+2
    return True
    
ans=0

for i in range(N):
    x=int(input())
    if isPrime(x):
        ans=ans+1
print(ans)


Measured memory_bytes: 5672
#include<stdio.h>
#include<math.h>
struct Point { double x,y;};
void koch(int n,Point a,Point b){
  if(n==0)return;
  Point s,t,u;
  double th =M_PI*60.0/180.0;
  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}
int main(){
  Point a,b;
  int n;
  scanf("%d",&n);
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}
  



Measured memory_bytes: 2680
from collections import deque

H, W = map(int, input().split())
field = ['#' * (W+2)] * (H+2)
for i in range(1, H+1):
    field[i] = '#' + input() + '#'
di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]
ans = 0
q = deque()

for si in range(1, H+1):
    for sj in range(1, W+1):
        if field[si][sj] == '#':
            continue
        q.clear()
        q.append([si, sj])
        dist = [[-1 for _ in range(W+2)] for _ in range(H+2)]
        dist[si][sj] = 0
        dist_max = 0
        while len(q) != 0:
            current = q.popleft()
            ci = current[0]
            cj = current[1]

            for d in range(4):
                next_i = ci + di[d]
                next_j = cj + dj[d]

                if field[next_i][next_j] == '#':
                    continue

                if dist[next_i][next_j] != -1:
                    continue

                q.append([next_i, next_j])
                dist[next_i][next_j] = dist[ci][cj] + 1
                dist_max = max(dist_max, dist[next_i][next_j])
        ans = max(ans, dist_max)
print(ans)


Measured memory_bytes: 3316
# coding: utf-8
word=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
n = int(input())
print(word[n-1])

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    int h, w, a, b; cin >> h >> w >> a >> b;
    int s = h * w;
    int tmp = (a * (h / a)) * (b * (w / b));
    cout << s - tmp << endl;
    
    
}




Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll b=0,c=0,d,e,f;
    rep(i,n){
        b+=a[i];
    }
e=b;
f=b;
if(b%2==0){
    b/=2;
}else{
    b=b/2+1;
}
rep(i,n){
    c+=a[i];
    if(c>=b){
        d=c-a[i];
        break;
    }
}
    if(abs(e-2*c)>abs(e-2*d)){
   cout<<abs(e-2*d);
    }else{
        cout<<abs(e-2*c);
    }

    return 0;
}


Measured memory_bytes: 1792
use proconio::input;
use std::f64;

fn main() {
    input!(a: f64, b: f64, H: f64, M: f64);
    let mut rad: f64 = 30. * H + 0.5 * M - 6. * M;
    rad = rad.to_radians();
    let ans = (a * a + b * b - 2. * a * b * rad.cos()).sqrt();
    println!("{}", ans);
}


Measured memory_bytes: 2932
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int arr[n][3];
	for(int i=0;i<n;i++){
		for (int j=0;j<3;j++){
			scanf("%d",&arr[i][j]);
		}
	}
 	int dp[n][3];
 	dp[0][0]=arr[0][0];
 	dp[0][1]=arr[0][1];
 	dp[0][2]=arr[0][2];
 	
 	for (int i=1;i<n;i++){
 		for (int j=0;j<n;j++){
 			dp[i][j]=0;
		 }
	 }
 	for (int i=1;i<n;i++){
 		for (int j=0;j<3;j++){
 			for(int k=0;k<3;k++){
 				if (k==j){
 					continue;
				}
				
				
 				dp[i][j]=max(dp[i][j],dp[i-1][k]+arr[i][j]);
			}
			
 			
		}
	}

	cout<<*max_element(dp[n-1],dp[n-1]+3);
  	
}

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

#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
typedef long long ll;
const int INF = 1 << 30;
//typedef long long ll;
ll B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;

signed main() {
    ll flag2 = 0;
    ll costmin = INF;
    ll cost = 0;
    std::cin >> N >> M >> X;
    ll A[N][M + 1];
    ll B[M];
    for (ll j = 0; j < M; j++) {
        B[j] = 0;
    }
    for (ll i = 0; i < N; i++) {
        std::cin >> A[i][M];
        for (ll j = 0; j < M; j++) {
            std::cin >> A[i][j];
        }
    }
    // {0, 1, ..., n-1} の部分集合の全探索
    for (ll bit = 0; bit < (1 << N); ++bit) {
        flag2 = 0;
        cost = 0;
        for (ll i = 0; i < N; ++i) {
            if (bit & (1 << i)) { // 列挙に i が含まれるか
                cost += A[i][M];
                for (ll j = 0; j < M; j++)
                    B[j] += A[i][j];
            }
        }
        for (ll j = 0; j < M; j++) {
            if (B[j] < X) {
                flag2++;
            }
            B[j] = 0;
        }
        if (flag2 == 0) {
            costmin = min(costmin, cost);
        }
    }
    if (costmin == INF) {
        cout << "-1" << endl;
    } else
        std::cout << costmin << std::endl;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  int N,x;
  cin >> N >> x;
  vector<int> A(N);
  REP(i,N){
    cin >> A[i];
  }

  sort(all(A));
  int cnt = 0;
  REP(i,N){
    x -= A[i];
    if(x<0){
      printf("%d",cnt);
      break;
    }
    cnt++;
  }
  if(x>0){
    printf("%d",N-1);
  }
  else if(x==0){
    printf("%d",N);
  }



  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll a,b;
  cin >> a >> b;
  ll ans;
  if(b%a) ans=b-a;
  else ans=a+b;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(long long i=a;i<=b;++i)

using namespace std;
const long long base[]={20200422,1000000007,9997,7};
long long n,m;
bool bi[N];
map<long long,long long>mp;
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

struct edge{
	long long l,r,v;
}E[N];

struct Graph{
	long long cnt;
	long long d[N],low[N],dfn[N];
	bool vis[N];
	deque<long long>q;
	struct node{
		long long n;
		long long v;
		long long id;
		node *next;
	}*e[N];
	// Graph(){
	// 	cnt=0;
	// 	memset(d,0,sizeof(d));
	// 	memset(low,0,sizeof(low));
	// 	memset(dfn,0,sizeof(dfn));
	// 	memset(vis,0,sizeof(vis));
	// 	memset(e,0,sizeof(e));
	// }
	void push(long long x,long long y,long long v,long long id){
		node *p;
		p=new node();
		p->n=y;
		p->v=v;
		p->id=id;
		if(e[x]==0)
			e[x]=p;
		else{
			p->next=e[x]->next;
			e[x]->next=p;
		}
	}

	void spfa(long long s){
		memset(d,0x3f,sizeof(d));		
		d[s]=0;
		q.push_front(s);
		while(!q.empty()){
			long long x=q.front();q.pop_front();
			vis[x]=1;
			for(node *i=e[x];i;i=i->next){
				if(d[i->n]>d[x]+i->v){
					d[i->n]=d[x]+i->v;
					if(!vis[i->n]){
						if(!q.empty()&&d[i->n]<d[q.front()]) q.push_front(i->n);
						else q.push_back(i->n);
						vis[i->n]=1;
					}
				}
			}
			vis[x]=0;			
		}
	}

	void tarjan(long long x,long long fa){
		dfn[x]=low[x]=++cnt;
	    vis[x]=1;
	    for(node *i=e[x];i;i=i->next){
	        if(i->n==fa) continue;
	        if(!dfn[i->n]){
	            tarjan(i->n,x);
	            low[x]=min(low[x],low[i->n]);
	            if(low[i->n]>dfn[x]) bi[i->id]=1;
	        }
	        else
	            if(vis[i->n])
	                low[x]=min(low[x],dfn[i->n]);
	    }
	}
}G1,G2,G3;

signed main(){
	//freopen("t.in","r",stdin);
 	//freopen("t2.out","w",stdout);
    in(n);in(m);
    For(i,1,m){
    	in(E[i].l);in(E[i].r);in(E[i].v);
    	G1.push(E[i].l,E[i].r,E[i].v,i);
    	G2.push(E[i].r,E[i].l,E[i].v,i);
    	mp[E[i].l*base[1]+E[i].r*base[2]+E[i].v*base[3]]++;
    }
    G1.spfa(1);G2.spfa(2);
    For(i,1,m){
    	if(G1.d[E[i].l]+G2.d[E[i].r]+E[i].v==G1.d[2]){
    		G3.push(E[i].l,E[i].r,E[i].v,i);
    		G3.push(E[i].r,E[i].l,E[i].v,i);
    	}
    }
    G3.tarjan(1,1);
    For(i,1,m){
    	if(G1.d[E[i].r]+G2.d[E[i].l]+E[i].v<G1.d[2]) puts("HAPPY");
    	else if(bi[i]&&mp[E[i].l*base[1]+E[i].r*base[2]+E[i].v*base[3]]==1) puts("SAD");
    	else puts("SOSO");
    }
    return 0;
}


Measured memory_bytes: 53240
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static const int kModulo = 1000 * 1000 * 1000 + 7;

int main() {
    ios::sync_with_stdio(false);

    int N; cin >> N;

    string S; cin >> S;
    vector<int> ways(N, 0);
    ways[0] = 1;

    for (int i = 0; i < int(S.size()); ++i) {
        if (S[i] == '>') {
            for (int j = i - 1; j >= 0; --j)
                ways[j] = (ways[j] + ways[j + 1]) % kModulo;
        } else {
            for (int j = 1; j <= i; ++j)
                ways[j] = (ways[j] + ways[j - 1]) % kModulo;
            rotate(ways.begin(), ways.begin() + i + 1, ways.begin() + i + 2);
            ways[0] = 0;
        }
    }

    int answer = 0;
    for (int i = 0; i < N; ++i)
        answer = (answer + ways[i]) % kModulo;
    cout << answer << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

void printArray(int *array, int);
void printVector(vector<string> &v);
void printDimention(DVector &dv);

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int K;
    cin >> s >> K;
    
    int len = s.length();
    vector<string> str;
    
    bool flg;
    string tmp;
    rep(i, len){
        int lim = min(len - i, 5);
        FOR(j, 0, lim){
            flg = true;
            tmp = s.substr(i, j + 1);
            //DEBUG_VARIABLE(tmp);
            rep(k, str.size()){
                if(tmp == str[k]){
                    flg = false;
                    break;
                }
            }
            if(flg){
                str.push_back(tmp);
            }
        }
    }
    sort(str.begin(), str.end());
    //printVector(str);
    
    cout << str[K - 1] << endl;
}

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

//Vectorの表示
void printVector(vector<string> &v){
    rep(i, (int)v.size()){
        if(i)   cout << " ";
        cout << v[i];
    }
    cout << endl;
}

//二次元配列の表示
void printDimention(DVector &dv){
    rep(i, (int)dv.size()){
        rep(j, (int)dv[i].size()){
            if(j)   cout << " ";
            cout << dv[i][j];
        }
        cout << endl;
    }
}

//numの中に何個2がかかってるか
int factor2(int num){
    int cnt = 0;
    while(num % 2 == 0){
        num /= 2;
        cnt++;
    }
    return cnt;
}

Measured memory_bytes: 1152
using System.Linq;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ps = new P[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            ps[i] = new P { x = x, y = y };
        }
        foreach (var a in ps.OrderBy(x => x.x).ThenBy(x => x.y))
            Console.WriteLine("{0} {1}", a.x, a.y);
    }
}



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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  int d = n % 10;
  if (d == 3) {
    cout << "bon" << endl;
  } else if (d == 0 || d == 1 || d == 6 || d == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	ll x, y;
	cin >> x >> y;
	if (x == 0) {
		if (y < 0) cout << 1 + abs(y) << endl;
		else cout << y << endl;
	} else if (y == 0) {
		if (x < 0) cout << abs(x) << endl;
		else cout << 1 + x << endl;
	} else if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
		if (x <= y) {
			cout << abs(y - x) << endl;
		} else {
			cout << abs(y - x) + 2 << endl;
		}
	} else {
		cout << 1 + abs(abs(x) - abs(y)) << endl;
	}
}

Measured memory_bytes: 3644
// All Heil Fire Lord Zuko

#include <bits/stdc++.h>
using namespace std;

int a, b, c;

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> a >> b >> c;
    if (a == b && b == c && !(a % 2))
        return cout << -1, 0;
    int ans = 0;
    while (true) {
        if (a % 2 || b % 2 || c % 2)
            return cout << ans, 0;
        int x = (a + b) / 2;
        int y = (b + c) / 2;
        int z = (a + c) / 2;
        a = x;
        b = y;
        c = z;
        ans++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
int used[8];
bool G[8][8];
int N,M;
int ans;
bool all_used(){
  for(int i=0;i<N;i++){
    if(used[i]==false)return false;
  }
  return true;
}
void dfs(int now,int num){
  used[now]=1;
  //printf("%d %d\n",now,num);
  if(num==N){
    ans++;
    
    return ;
  }
  for(int i=0;i<N;i++){
    if(G[now][i]==true && used[i]==0){
      dfs(i,num+1);
      used[i]=0;
    }
  }
}
int main(){
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--;b--;
    G[a][b]=1;
    G[b][a]=1;
  }
  dfs(0,1);
  printf("%d\n",ans);
  return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

void print_res(string s) {
    // cout << s << endl;
    size_t pos = s.find("RL");
    ll size_before_r = pos;
    ll size_after_l = s.size() - pos - 2;
    rep(i, s.size()) {
        if (i < pos || pos + 1 < i) {
            cout << 0 << endl;
        } else {
            if (i == pos) {
                cout << size_before_r / 2 + (size_after_l - size_after_l / 2) + 1 << endl;
            } else {
                cout << size_after_l / 2 + (size_before_r - size_before_r / 2) + 1 << endl;
            }
        }
    }
}

int main()
{
    string s; cin >> s;
    size_t pos = s.find("LR");
    while (pos != string::npos) {
        print_res(s.substr(0, pos+1));
        s.erase(s.begin(), s.begin()+pos+1);
        pos = s.find("LR");
    }
    print_res(s);

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
int main() {
	string s;
	cin >> s;
	char f;
	f = s[0];
	int ans = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != f) {
			ans++;
		}
		f = s[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N =sc.nextInt();
      //空っぽの箱がN個用意しておく。のちにおいしさをいれる。
      int[] d =new int[N];
      //ここでd1から順に入れていける。でも、何個入れるかわからないので、ループを使う。
          
      for(int i=0; i<N; i++){
        //おいしさ。
      d[i] =sc.nextInt();
      }
      
      
      //Nから２つ選ぶとき、そのすべての組み合わせをループする。
      int total = 0;
      for(int x=0; x<N-1; x++){
      for(int y=x+1; y<N; y++){
      int r = d[x]*d[y];
        total += r;
      }
      }
          System.out.println(total);
    }
}


Measured memory_bytes: 20948
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int
def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod



def solve(n: int, a: int, b: int):
    k = pow(2, n, MOD) - combination(n,a) - combination(n,b)
    print(k % MOD - 1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(n, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}



vector<ll>v[Max+10];


int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

    bool flag=false;

    string str;

    cin>>n;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<n; j++)
        {
            cin>>a;

            v[i].eb(a);
        }
    }



    ll day=0;

    flag=true;

   // ll mark[n+3];

    while(flag)
    {
        flag=false;



      ll mark[n+3]={};

        for(i=1; i<=n; i++)
        {
            if(mark[i])continue;

            if(!v[i].empty())
            {
                a=v[i][0];

                if(!v[a].empty() && mark[a]==0)
                {
                    b=v[a][0];

                    if(b==i)
                    {
                      //  cout<<i<<" "<<a<<endl;

                        mark[i]=1;
                        mark[a]=1;

                        v[i].erase(v[i].begin());

                        v[a].erase(v[a].begin());

                        flag=true;
                    }
                }
            }
        }

        if(flag)day++;


    }

    flag=true;

    for(i=1; i<=n; i++)
        if(!v[i].empty())
        {
            flag=false;
            break;

        }


    if(flag)cout<<day<<endl;

    else cout<<-1<<endl;













}



Measured memory_bytes: 58316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

ll modnum = 1000000007;


long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main() {
    ll x; cin >> x;
    ll ans = (x/500) * 1000;
    ll tmp = x%500;
    ans += (tmp/5) * 5;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a;
	int b;
	int c;
	int d;
	a = n % 10;
	b = (n - a) % 100;
	c = (n - (b  + a)) % 1000;
	d = n - a - b - c;
	b = b / 10;
	c = c / 100;
	d = d / 1000;
	if (a == b)
	cout << "Bad";
	else if (b == c)
	cout << "Bad";
	else if (c == d)
	cout << "Bad";
	else 
	cout << "Good";

}

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

k = []
p = []
swt = []
result = 0

for num in range(N):
    swt.append(0)

for num in range(M):
    k.append(list(map(int,input().split())))

p =list(map(int,input().split()))

#print(k)
#print(p)

for i in range(2**N):
    for j in range(N):
        if(i&(1<<j)):
            swt[j] = 1

    #print(i,swt)
    for l1 in range(M):
        count = 0
        for l2 in range(k[l1][0]):
            count += swt[k[l1][l2+1]-1]

        if count%2 != p[l1]:
            for num in range(N):
                swt[num]=0
            break
        if l1==M-1:
            result +=1
            for num in range(N):
                swt[num]=0
print(result)

Measured memory_bytes: 3064
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
int main(){
    init();
    ll N;cin>>N;
    vector<bool>use(N+1,false);
    vector<ll>A(N+1);
    for(int i=1;i<=N;i++)cin>>A[i];

    for(int num=N;num>=1;num--){
        ll a=A[num];
        ll data=0;
        for(int i=1;i*num<=N;i++){
            if(use[i*num])data++;
        }
        //cout<<"data="<<data<<endl;
        if(data%2!=a)use[num]=true;
    }
    vector<ll>ans;
    for(int i=1;i<=N;i++){
        if(use[i])ans.push_back(i);
    }

    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
    cout<<endl;

}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sim template < class c
#define ris return *this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", ", d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; it++)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N, W;
	cin >> N >> W;
	vector<ll> w(N + 1), v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<ll>> dp(N + 1, vector<ll> (W + 1));
	for (int i = 0; i <= N; i++) {
		dp[i][0] = 0;
	}
	for (int i = 0; i <= W; i++) {
		dp[0][i] = 0;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= W; j++) {
			if (w[i] > j) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
			}
		}
	}
	cout << dp[N][W];
	
	return 0;
}


Measured memory_bytes: 80256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
#n = ip()                                     #入力整数1つ
h,w= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
n = ip()
a = [int(i) for i in input().split()]
horz = 1
vert = 1
x = 0
y = 0
ans  = [[0 for i in range(w)] for i in range(h)]
pos = 0
for i in range(h*w):
    ans[y][x] = pos+1
    a[pos]-=1
    if a[pos] ==0:
        pos+=1
    if y == h-1 and vert == 1:
        x+=1
        vert = -1
    elif y == 0 and vert == -1:
        x+=1
        vert = 1
    else: y+=vert
for i in range(h):
    for k in range(w):
        if k+1 != w: print(ans[i][k],"",end="")
        else : print(ans[i][k],end="")
    print()


Measured memory_bytes: 14436
import math

def minkowski(x, y, p):
    if p == 0:
        return max(map(lambda xi,yi: abs(xi-yi), x, y))
    else:
        return math.pow(sum(map(lambda xi,yi: math.pow(abs(xi-yi), p), x, y)), 1/p)

if __name__ == '__main__':
    n = int(input())
    x = [int(i) for i in input().split()]
    y = [int(i) for i in input().split()]
    print("{0:.6f}".format(minkowski(x, y, 1)))
    print("{0:.6f}".format(minkowski(x, y, 2)))
    print("{0:.6f}".format(minkowski(x, y, 3)))
    print("{0:.6f}".format(minkowski(x, y, 0)))

Measured memory_bytes: 6868
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

typedef struct rest {
    string s;
    ll p;
    ll itr;
} Rest;

bool comp(Rest &a, Rest &b) {
    if (a.s != b.s) return a.s < b.s;
    else return a.p > b.p;
}
 
int main() {
    ll ans = 0;
    ll n;
    cin >> n;

    vector<Rest> r;

    for (ll i = 0; i < n; i++) {
        string s;
        ll p;
        cin >> s >> p;
        Rest temp = {s, p, i+1};
        r.push_back(temp);
    }

    sort(ALL(r), comp);
    
    for (int i = 0; i < n; i++) {
        cout << r[i].itr << endl;
    }




}

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

    int main()
    {
       char string[1000000], ch;
       int c = 0, count[26] = {0},p=0;
       gets(string);
       while ( string[c] != '\0' )
       {

          if ( string[c] >= 'a' && string[c] <= 'z' )
             count[string[c]-'a']++;

          c++;
       }

       for ( c = 0 ; c < 26 ; c++ )
       {
          if( count[c] == 0 )
          {
              printf("%c\n",c+'a');
              p=1;
             break;
          }

       }
       if(p==0)printf("None\n");

       return 0;
    }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    char op;
    while (1) {
        cin >> a >> op >> b;
        if( op == '?') break;
        
        if ( op == '+') {
            cout << a+b << endl;
        }
        if ( op == '-') {
            cout << a-b << endl;
        }
        if ( op == '*') {
            cout << a*b << endl;
        }
        if ( op == '/') {
            cout << a/b << endl;
        }
    }
}



Measured memory_bytes: 3084