akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {												
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  

void solve(){
	string s, t ; 
	int a , b;
	re(s,t,a,b);
	string u ; re(u);
	if(s==u) cout << a-1 << ' '<< b << endl; 
	if(t==u) cout << a << ' ' << b-1 << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3652
s = input()
ans = "AC"
c = 0
for i in range(len(s)):
    if i==0 and s[i]!="A":
        ans = "WA"
    if i>=2 and i<len(s)-1:
        if s[i]=="C":
            c += 1
        elif ord(s[i])>=65 and ord(s[i])<=90:
            ans = "WA"
    if i==1 or i==len(s)-1:
        if ord(s[i])>=65 and ord(s[i])<=90:
            ans = "WA"
if c!=1:
    ans = "WA"
print(ans)

Measured memory_bytes: 61988
unittest
{
	assert( [ "5 2", "1 4", "2 5" ].parse.expand.solve == 1 );
	assert( [ "9 5", "1 8", "2 7", "3 5", "4 6", "7 9" ].parse.expand.solve == 2 );
	assert( [ "5 10", "1 2", "1 3", "1 4", "1 5", "2 3", "2 4", "2 5", "3 4", "3 5", "4 5" ].parse.expand.solve == 4 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nm[ 0 ], abs );
}

auto solve( long n, long[ 2 ][] abs )
{
	auto ans = 0L;
	auto d = -1L;
	foreach( ab; abs.sort() )
	{
		if( d < ab[ 0 ] )
		{
			// 橋を取り除く
			ans++;
			d = ab[ 1 ] - 1;
		}
		else
		{
			// 既に取り除いた橋で要望が満たされているようにする
			d = min( d, ab[ 1 ] - 1 );
		}
	}
	return ans;
}


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

int main() {
    int n; cin >> n;
    multiset<int> ms;
    for (int i = 0; i < n; i++) {
        int c; cin >> c; c *= -1;
        auto it = ms.upper_bound(c);
        if (it == ms.end()) ms.insert(c);
        else {
            ms.erase(it);
            ms.insert(c);
        }
    }
    cout << ms.size() << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,K;
ll V[200010];

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

  cin>>N>>K;
  rep(i,N)cin>>V[i];

  ll res=0;
  repl(i,1,min(K+1,N+1)){
    rep(l,i+1){
      ll r=i-l;
      vector<ll> vs;
      rep(j,l)vs.push_back(V[j]);
      for(ll j=N-1;j>=N-r;j--){
        vs.push_back(V[j]);
      }
      sort(all(vs));
      ll sum=0;
      ll rest=K-i;
      rep(j,vs.size())sum+=vs[j];
      rep(j,rest){
        if(vs[j]>=0)break;
        else sum-=vs[j];
      }
      maxch(res,sum);
    }
  }
  cout<<res<<endl;

  return 0;
}


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

int main() {
  int X,Y;
  cin>>X>>Y;
  int t = (X*4 - Y)/2;
  int k = (Y - X*2)/2;
  cout<<(Y%2 == 0 && t>=0 && k>=0 ? "Yes" : "No")<<endl;
  return 0;
}


Measured memory_bytes: 3096
n,l,t=map(int,input().split())
data=[]
s=0
for i in range(n):
  x,w=map(int,input().split())
  if w==1:
    data.append((x+t)%l)
    s+=(x+t)//l
  else:
    data.append((x-t)%l)
    s+=(x-t)//l
data.sort()
res=s%n
data=data[res:]+data[:res]
for i in data:
  print(i)

Measured memory_bytes: 14188
#ABC116

s = int(input())

l = [s]
for i in range(1000000):
    if l[-1] % 2 == 0:
        if l[-1] // 2 in l:
            print(len(l) + 1)
            break
        l.append(l[-1] // 2)
    else:
        if 3 * l[-1] + 1 in l:
            print(len(l)+1)
            break
        l.append(3 * l[-1] + 1)
        

Measured memory_bytes: 2940
l=[int(i) for i in input()]

for i in range(2**3):
  op=['-','-','-']
  for j in range(3):
    if (i>>j)&1:
      op[j]='+'

  num=l[0]
  for j in range(3):
    if op[j]=='+':
      num+=l[j+1]
    else:
      num-=l[j+1]

  if num==7:
    print(str(l[0])+op[0]+str(l[1])+op[1]+str(l[2])+op[2]+str(l[3])+'=7')
    exit()

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

int main(void){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3=x2-(y2-y1),y3=y2+(x2-x1);
    int x4=x3-(x2-x1),y4=y3-(y2-y1);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int LIM=10e5+5;
vector<vector<int>> arr(LIM);
vector<bool> visited(LIM,false);
vector<int> countt(LIM,0);

int dfs(int node){
	if(visited[node])
		return countt[node];
	visited[node]=true;
	//cout<<node<<"aba\n";
	for(int i=0;i<arr[node].size();i++){
		int x=arr[node][i];
		
		if(!visited[x]){
		//	cout<<x<<"\n";
			dfs(x);
		}
			
		countt[node]=max(countt[node],countt[x]+1);
		// cout<<countt[node]<<" "<<node<<"\n";
	}
	return countt[node] ;
	

}
int main(){
	//freopen ("t.txt","r",stdin);
	int n,m;
	scanf("%d %d",&n,&m);

	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		arr[a].push_back(b);
		//s.insert(b);
	}

	
	int maxx=0,tem=0;
	for(int i=1;i<=n;i++){
		if(!visited[i])
			maxx=max(dfs(i),maxx);
	}

	cout<<maxx;
return 0;
}


Measured memory_bytes: 32896
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[][] array = new int[3][3];
		String s = sc.next();
		List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<String> list_reverse=new ArrayList<String>(Arrays.asList(s.split("")));
		Collections.reverse(list_reverse);
		int a = (list.size()-1)/2;
		if(list.equals(list_reverse)) {
			List<String> list_mae=new ArrayList<String>();
			List<String> list_mae_re=new ArrayList<String>();
			for(int i=0;a>i;i++) {
				list_mae.add(list.get(i));
				list_mae_re.add(list.get(i));
			}
			Collections.reverse(list_mae_re);
			if(list_mae.equals(list_mae_re)) {
				List<String> list_ato=new ArrayList<String>();
				List<String> list_ato_re=new ArrayList<String>();
				for(int j=0;a>j;j++) {
					list_ato.add(list_reverse.get(j));
					list_ato_re.add(list_reverse.get(j));
				}
				Collections.reverse(list_ato_re);
				if(list_ato.equals(list_ato_re)) {
					System.out.println("Yes");
				}
				else {
					System.out.println("No");
				}

			}
			else {
				System.out.println("No");
			}

		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23892
# coding: utf-8
# Your code here!

from operator import itemgetter
n = int(input())
sp={}
for i in range(n):
    [name,value] = input().split()
    if sp.get(name) is None:
        sp[name] = [(int(value),i)]
    else:
        sp[name].append((int(value),i))


for key in sp.keys():
    sp[key] = sorted(sp[key], key=itemgetter(0))

    
sp = sorted(sp.items())

for s in sp:
    for p in s[1][::-1]:
        print(p[1]+1)

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] bi = new int[N+1], max = new int[N];
		for(int i = 0; i <= N; i++) bi[i] = sc.nextInt();
		for(int j = 0; j < N; j++) max[j] = sc.nextInt();

		long sum = 0;
		for(int i = 0; i < N; i++) {
			long x = Math.min(bi[i], max[i]);
			sum += x;
			x = Math.min(max[i]-x, bi[i+1]);
			bi[i+1] -= x;
			sum += x;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 65848
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[110000];
        int[] b = new int[110000];

        for(int i = 0; i < N/2; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            a[x]++;
            b[y]++;
        }
        int maxa = 0, maxb = 0;
        int maxaa = 0, maxbb = 0;
        for(int i = 1; i <= 100000; i++) {
            if(maxa < a[i]) {
                maxa = a[i];
                maxaa = i;
            }
            if(maxb < b[i]) {
                maxb = b[i];
                maxbb = i;
            }
        }
        if(maxaa != maxbb) {
            System.out.println(N - (maxa + maxb));
        } else {
            int maxaaa = 0, maxbbb = 0;
            int maxaaaa = 0, maxbbbb = 0;
            for(int i = 1; i <= 100000; i++) {
                if(i != maxaa && maxaaa < a[i]) {
                    maxaaa = a[i];
                    maxaaaa = i;
                }
                if(i != maxbb && maxbbb < b[i]) {
                    maxbbb = b[i];
                    maxbbbb = i;
                }
            }
            if(maxaaa > maxbbb) {
                System.out.println(N - (maxb + maxaaa));
            } else {
                System.out.println(N - (maxa + maxbbb));
            }
        }

    }
}


Measured memory_bytes: 60536
package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"strconv"
)

var defaultInitialValue = -999
var initialValueSInt int = defaultInitialValue
var recFuncSInt func(int) int = nil

type SIntList []int

func lib_DirectedAdjacencyList(x []int, y []int, length int) ([][]int, error) {
	if len(x) != len(y) {
		return nil, fmt.Errorf("x and y lengths are different. x:%d y:%d", len(x), len(y))
	}
	ret := make([][]int, length, length)
	for i := 0; i < len(x); i++ {
		ret[x[i]-1] = append(ret[x[i]-1], y[i])
	}
	return ret, nil
}
func lib_MaxInt(values ...int) (max int, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	max = values[0]
	for _, value := range values {
		if max < value {
			max = value
		}
	}
	return
}
func lib_MustDirectedAdjacencyList(x []int, y []int, length int) [][]int {
	_v0, _err := lib_DirectedAdjacencyList(x, y, length)
	if _err != nil {
		panic(_err)
	}
	return _v0
}
func lib_MustMaxInt(values ...int) (max int) {
	max, err := lib_MaxInt(values...)
	if err != nil {
		panic(err)
	}
	return max
}
func lib_NewSIntList(length int, initialValue int) SIntList {
	if initialValueSInt != defaultInitialValue {
		panic("SIntList is already used")
	}
	ret := make([]int, length, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	initialValueSInt = initialValue
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int
	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	var M int
	scanner.Scan()
	M, _ = strconv.Atoi(scanner.Text())
	x := make([]int, M)
	y := make([]int, M)
	for i := 0; i < M; i++ {
		scanner.Scan()
		x[i], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		y[i], _ = strconv.Atoi(scanner.Text())
	}
	fmt.Println(solve(N, M, x, y))
}
func (si SIntList) Rec(f func(int) int) {
	recFuncSInt = f
}
func (si SIntList) Update(v int) int {
	if recFuncSInt == nil {
		panic("recFuncSInt is nil")
	}
	if si[v] != initialValueSInt {
		return si[v]
	}
	ret := recFuncSInt(v)
	si[v] = ret
	return ret
}
func solve(N int, M int, x []int, y []int) (ret int) {
	dp := lib_NewSIntList(N+5, 0)
	neighbors := lib_MustDirectedAdjacencyList(x, y, N)
	dp.Rec(func(n int) (res int) {
		for _, neighbor := range neighbors[n-1] {
			res = lib_MustMaxInt(res, dp.Update(neighbor)+1)
		}
		return res
	})
	for i := 1; i <= N; i++ {
		ret = lib_MustMaxInt(ret, dp.Update(i))
	}
	return ret
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  int sum=0;
  for(auto &e: a) {
    sum+=e;
  }
  std::vector<int> div;
  for (int i = 1; i <= sum; ++i)
  {
    if(sum%i==0) div.push_back(i);
  }
  int ans;
  for(auto &e: div) {
    std::vector<int> tmp;
    for(auto &f: a) {
      tmp.push_back(f%e);
    }
    int tmp_sum=0;
    for(auto &g: tmp) {
      tmp_sum+=g;
    }
    if(tmp_sum%e!=0) continue;
    sort(tmp.begin(), tmp.end(),greater<int>());
  	
    tmp.erase(tmp.begin(),tmp.begin()+tmp_sum/e);
    int sum2=0;
    for(auto &h: tmp) {
      sum2+=h;
    }
    if(sum2<=k) ans=e;
  }
  cout<<ans;
}

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

int main(){
  int N,X,T;cin>>N>>X>>T;
  cout<<((N+X-1)/X)*T<<endl;
}
  



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main () {
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A+3);
    int ans = 0;
    while (A[0] + 2 <= A[2]) {
        A[0] += 2;
        ans++;
    }
    while (A[1] + 2 <= A[2]) {
        A[1] += 2;
        ans++;
    }
    sort(A, A+3);
    if (A[0] != A[2]) {
        if (A[0] == A[1]) {
            ans++;
            A[0]++;
            A[1]++;
        }
        else {
            ans += 2;
            A[0] += 2;
            A[1]++;
            A[2]++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
L = []
for i in range(M):
    a, b = map(int,input().split())
    L.append(a)
    L.append(b)
    
B = [0 for _ in range(N)]
for i in range(2*M):
    B[L[i]-1] = B[L[i]-1] + 1

for i in range(N):
    print(B[i])
    

Measured memory_bytes: 2940
from math import ceil
N,H=list(map(int,input().split()))
a_max=0
b_list=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    a_max = max(a_max,a)
    b_list.append(b)
b_list = sorted(b_list,reverse=True)

ans=ceil(H/a_max)
bcount=0
for b in b_list:
    bcount+=1
    H=max(0,H-b)
    ans=min(ans,bcount+ceil(H/a_max))

print(ans)

Measured memory_bytes: 57432
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main(){

	string data[] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	char inp;
	int n, cnt, num;
	string ans;

	cin >> n;

	getchar();

	for (int i = 0; i < n; i++){

		cnt = 0;
		ans = ("");

		while (1){

			inp = getchar();

			if (inp == '\n') break;
			if (inp != '0'){
				num = inp - '0';
				cnt++;
			}
			else{
				if (cnt > 0){
					ans += data[num-1][(cnt-1)%data[num-1].size()];
					cnt = 0;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto & in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


class union_find
{
private:
	std::vector<int>parent;
	std::vector<int>rank;
	std::vector<int>size;
public:
	union_find(int n)
	{
		parent.resize(n);
		rank.resize(n);
		size.resize(n);
		for (int i = 0; i < n; ++i)
		{
			parent[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}
	void unite(int x, int y)
	{
		int xr = find(x);
		int yr = find(y);
		if (xr == yr) {
			return;
		}

		//yrを新しい親に
		if (rank[xr] > rank[yr])
		{
			std::swap(xr, yr);
		}
		if (rank[xr] == rank[yr]) {
			++rank[yr];
		}
		size[yr] += size[xr];
		parent[xr] = yr;
	}
	int find(int x)
	{
		if (parent[x] == x)
		{
			return x;
		}
		else
		{
			return parent[x] = find(parent[x]);
		}
	}
	bool check(int x, int y)
	{
		return find(x) == find(y);
	}
	int getsize(int x) {
		return size[find(x)];
	}
};


int64_t N,M,Q;
int32_t A[200000];
int32_t B[200000];
int32_t T[200000];
std::set<int> graph[200000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M>>Q;
	union_find single(N+10);
	for (int i = 0; i < Q; i++)
	{
		in >> A[i] >> B[i] >> T[i];//--A[i]; --B[i];
	}
	for (int i = 0; i < Q; i++)
	{
		if (T[i] == 0) {
			single.unite(A[i], B[i]);
		}
	}
	bool T1find = false;
	for (int i = 0; i < Q; i++)
	{
		if (T[i] == 1) {
			T1find = true;
			if (single.check(A[i], B[i])) {
				out << "No" << endl;
				return 0;
			}
			auto a = single.find(A[i]);
			auto b = single.find(B[i]);
			graph[a].insert(b);
			graph[b].insert(a);
		}
	}


	int nnn = 0;
	int64_t needM = 0, maxM = 0;
	for (int i = 0; i < N; i++)
	{
		if (single.find(i) == i) {
			++nnn;
			needM += single.getsize(i) - 1;
		}
	}
	maxM = needM + int64_t(nnn) * int64_t(nnn - 1) / 2;
	if ((M < needM) || (maxM < int64_t(M))) {
		out << "No" << endl;
		return 0;
	}

	if(T1find){

		if (nnn < 3) {
			out << "No" << endl;
			return 0;
		}

		for (int i = 0; i < N; i++)
		{
			if (single.find(i) == i) {
				if (nnn - 1 == graph[i].size()) {
					++needM;
				}
			}
		}

	} else {
		--needM;
	}
	needM += nnn;
	if (M < needM) {
		out << "No" << endl;
		return 0;
	}


	out << "Yes" << endl;

	return 0;
}
#endif


Measured memory_bytes: 17024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = Integer.parseInt(scanner.next());
        int n = Integer.parseInt(scanner.next());
        int[] a = new int[n];
        int cost;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(scanner.next());
        }
        cost = k - Math.abs(k-a[n-1]+a[0]);
        for (int i = 1; i < n; i++) {
            cost = Math.min(cost, k - Math.abs(a[i]-a[i-1]));
        }
        System.out.println(cost);
    }
}

Measured memory_bytes: 51116
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b,m;
  cin >> a >> b >> m;

  vector<int> A(a),B(b);
  rep(i,a) cin >> A[i];
  rep(i,b) cin >> B[i];

  int mina = 1000000,minb = 1000000;
  rep(i,a) mina = min(mina,A[i]);
  rep(i,b) minb = min(minb,B[i]);
  int ans = mina+minb;
  rep(i,m){
    int x,y,c;
    cin >> x >> y >> c;
    ans = min(ans,A[x-1]+B[y-1]-c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
/*
    ABC-160
    Quarantine_Day : 6
*/
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<lint>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    lint jp;
    cin>>jp;

    lint fy = jp / 500;
    lint ry = jp % 500;

    lint fiy = ry / 5;

    cout<<(fy * 1000) + (fiy * 5)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	bool flag = false;
	while(n>0){
		if(n%10==7){
			flag = true;
		}
		n = n/10;
	}
	if(flag==true){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[110];
int q[110];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a==1){
		printf("1 1 1");
		return 0;
	}
	int ki=0;
	for(int i=0;i<b;i++){
		scanf("%d",p+i);
		if(p[i]%2)ki++;
	}
	if(ki>2){
		printf("Impossible\n");return 0;
	}
	if(b==1){
		printf("%d\n",p[0]);printf("2\n%d %d\n",p[0]-1,1);return 0;
	}
	int sz=0;
	for(int i=0;i<b;i++){
		if(p[i]%2){
			q[sz++]=p[i];
		}
	}
	q[b-1]=q[1];
	if(sz>1)sz=1;
	for(int i=0;i<b;i++){
		if(p[i]%2==0){
			q[sz++]=p[i];
		}
	}
	for(int i=0;i<b;i++){
		printf("%d ",q[i]);
	}printf("\n");
	q[0]--;q[b-1]++;
	if(q[0]==0){
		printf("%d\n",b-1);
		for(int i=1;i<b;i++)printf("%d ",q[i]);
		printf("\n");
	}else{
		printf("%d\n",b);
		for(int i=0;i<b;i++)printf("%d ",q[i]);
		printf("\n");
	}
}

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

using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> as(n + 1);
  rep(i, n) {
    cin >> as[i + 1];
  }
  vector<ll> dp(n + 1);
  dp[0] = 1000;
  for (int k = 1; k <= n; k++) {
    dp[k] = 0;
    for (int i = 0; i < k -1; i++) {
      int m = 99999;
      for (int j = i + 1; j < k ; j++) {
        m = min(m, as[j]);
      }
      dp[k] = max(dp[k], dp[i]/m*as[k]+dp[i]%m);
    }
  }
  ll ans = 0;
  rep(i, n+1) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
# AOJ 0591: Beads
# Python3 2018.6.29 bal4u
# (n + r - mn - 1) ! / {(n - 1) ! × (r - mn) !}

import math
n, m, r = map(int, input().split())
if r-m*n < 0: print(0)
else: print(math.factorial(n+r-m*n-1)//(math.factorial(n-1)*math.factorial(r-m*n)))



Measured memory_bytes: 5840
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int s; cin >> s;
    int size = 100000;
    vector<int> a(size);
    a[0] = s;
    for (int m = 1; m < size; m++)
    {
        int prev = a[m-1];
        if (prev % 2 == 0)
        {
            a[m] = prev/2;
        } else {
            a[m] = 3*prev + 1;
        }
        rep(i,m) {
            if (a[i] == a[m])
            {
                cout << ++m << endl;
                return 0;
            }
        }
    }
    return 0;
    
}

Measured memory_bytes: 640
import numpy as np
X = int(input())

t = np.arange(0, 2000001, 1)
t = t**5
S = set(t)

for B in range(0,200001,1):
    if X+B**5 in S:
        print("%d %d"%((X+B**5)**0.2, B))
        break
    if X-B**5 in S:
        print("%d %d"%((X-B**5)**0.2, -B))
        break


Measured memory_bytes: 195672
s = input()
upper_input = int(s[:2])
lower_input = int(s[2:])

if upper_input >= 1 and upper_input<= 12:
  if lower_input >= 1 and lower_input <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if lower_input >= 1 and lower_input <= 12:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 9120
#include <iostream>
using namespace std;
using ull = unsigned long long;

const int MAX = 10000000;
const int MOD = 1000000007;

ull fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ull COM(int n, int k)
{
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();

    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0)
    {
        cout << 0 << endl;
        return 0;
    }

    int k = (x + y) / 3;
    int n = y - k;
    int m = x - k;
    if (n < 0 || m < 0)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << COM(k, m) << endl;
}


Measured memory_bytes: 234752
import java.math.*;
import java.util.*;
import java.util.function.*;
 
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();
    }
    sc.close();

    BigInteger lcm = Arrays.stream(A).parallel()
        .mapToObj(BigInteger::valueOf)
        .reduce(BigInteger.ONE, (a, b) -> a.divide(a.gcd(b)).multiply(b));

//    Map<Integer, Integer> lcm = new HashMap<>();
//    for (int ai : A)
//      for (Map.Entry<Integer, Integer> fAi : f(ai).entrySet())
//        lcm.put(fAi.getKey(), Math.max(lcm.getOrDefault(fAi.getKey(), 0), fAi.getValue()));

    long mod = 1000000007;

//    long modLcm = 1;
//    for (Map.Entry<Integer, Integer> lcm_p : lcm.entrySet())
//      modLcm = (modLcm * modPow(lcm_p.getKey(), lcm_p.getValue(), mod)) % mod;

    long modLcm = lcm.remainder(BigInteger.valueOf(mod)).longValue();

    long ans = 0;
    for (int ai : A)
      ans = (ans + modDiv(modLcm, ai, mod)) % mod;

    System.out.println(ans);
  }

  private static long modDiv(long a, long b, long mod) {
    return (a % mod) * modInv(b, mod) % mod;
  }

  private static long modInv(long x, long mod) {
    return modPow(x, mod - 2, mod);
  }

  private static long modPow(long b, long e, long mod) {
    long ans = 1;
    long x = b % mod;
    for (long y = e; y != 0; y >>= 1) {
      if ((y & 1) == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
    }
    return ans;
  }
}

Measured memory_bytes: 66484
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

//    int n = 2000;
//    vector<int> a(n);
//    for (int i = 0; i < n; i++) a[i] = 2000;

    int s = 0;
    for (int i = 0; i < n; i++) s += a[i];
    std::bitset<4000001> bs;
    bs[0] = 1;
    for (int i = 0; i < n; i++) {
        bs = bs | (bs << a[i]);
    }
    int c = s / 2;
    while (bs[c] == 0) c--;
    cout << (s - c);

    return 0;
}

Measured memory_bytes: 2176
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a*n>b){
            System.out.println(b);
        }else{
            System.out.println(a*n);
        }

	}
}


Measured memory_bytes: 35580
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<string,string> pss;
ll ans=0;

class Shoot
{
public:
  int x,y,z;
  int sx,sy,sz,gx,gy,gz;
  Shoot(int sx,int sy,int sz,int gx,int gy,int gz):x(gx-sx),y(gy-sy),z(gz-sz),sx(sx),sy(sy),sz(sz){};
  ll norm(){return x*x+y*y+z*z;};
};


class Obstacle
{
public:
  int x,y,z;
  int r;
  ll cost;
  Obstacle(int x=0,int y=0,int z=0,int r=0,ll cost=0):x(x),y(y),z(z),r(r),cost(cost){};
  ll crosspow(Shoot St)
  {
    ll xlength=x-St.sx;
    ll ylength=y-St.sy;
    ll zlength=z-St.sz;
    ll cross=
      (xlength*St.y-ylength*St.x)*(xlength*St.y-ylength*St.x)+
      (xlength*St.z-zlength*St.x)*(xlength*St.z-zlength*St.x)+
      (ylength*St.z-zlength*St.y)*(ylength*St.z-zlength*St.y);
    return cross;
  }
  ll crush(Shoot St)
  {
    if(crosspow(St)>(r*r*(St.norm())))
      {
	return 0;
      }
    else
      {
	ll xlength=x-St.sx;
	ll ylength=y-St.sy;
	ll zlength=z-St.sz;
	ll dot=xlength*St.x+ylength*St.y+zlength*St.z;
	if(dot>=0 && dot<=St.norm())
	  {
	    return cost;
	  }
	else
	  {
	    return 0;
	  }
      }

  }
};

vector<Obstacle>Objs;
vector<Shoot> ShootPoint;
int main(void)
{
  int N,Q;
  cin >> N >> Q;
  for(int i=0;i<N;i++)
    {
      int x,y,z,r;
      ll l;
      cin >> x >> y >> z >> r >> l;
      Objs.push_back(Obstacle(x,y,z,r,l));
    }
  for(int i=0;i<Q;i++)
    {
      int sx,sy,sz,gx,gy,gz;
      cin >> sx >> sy >> sz >> gx >> gy >> gz;
      ShootPoint.push_back(Shoot(sx,sy,sz,gx,gy,gz));
    }
  for(int i=0;i<Q;i++)
    {
      ans=0;
      for(int j=0;j<N;j++)
	{
	  ans+=Objs[j].crush(ShootPoint[i]);
	}
      cout << ans << endl;
    }
}



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

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

    for(int i=n-1;i>=0;i--){
        cout <<a[i];
        if(i != 0) printf(" ");
    }
    cout << endl;
    return 0;
}


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--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0LL;
  rep(i,n-1) {
    ans += max(0LL,a[i]-a[i+1]);
    a[i+1] = max(a[i],a[i+1]);
  }
  cout << ans << endl;
  return 0;
}

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

int lab[100001];
void init(int l, int r){
    for(int i = l; i<=r; i++) lab[i] = i;
}
int find(int v){
    if(v == lab[v]) return v;
    return lab[v] = find(lab[v]);
}
bool same(int u, int v){
    return find(u) == find(v);
}
void join(int u, int v){
    if(same(u, v)) return;
    lab[find(v)] = find(u);
}

int n, m;
int p[100001];

int main(){
    cin >> n >> m;
    for(int i=1; i<=n; i++) cin >> p[i];
    init(1, n);
    for(int i=0; i<m; i++){
        int x, y; cin >> x >> y;
        join(x, y);
    }
    
    int ans = 0;
    
    for(int i=1; i<=n; i++){
        if(same(i, p[i])) ans++;
    }
    
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int n, m;
	long long r, a;
	long long x[1000], y[1000], z[1000], t[1000];

	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);

	int P[8][3] = { { 1,1,1 },{ 1,1,-1 },{ 1,-1,1 },{ 1,-1,-1 },{ -1,1,1 },{ -1,1,-1 },{ -1,-1,1 },{ -1,-1,-1 } };
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < n; ++j)
			t[j] = x[j] * P[i][0] + y[j] * P[i][1] + z[j] * P[i][2];
		sort(t, t + n);
		a = 0;
		for (int k = n - m; k < n; ++k)
			a += t[k];
		if (r < a)
			r = a;
	}
	printf("%lld\n", r);
	return 0;
}

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

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)


int main(){
    ll ans=0;
    ll n,m;
    cin>>n>>m;
    ans+=min(n,m/2);
    n-=ans;
    m-=ans*2;
    if(m){
        ans+=m/4;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
P = list(map(int, input().split()))
XY = [list(map(int, input().split())) for i in range(M)]


class UnionFind():
    def __init__(self, N):
        self.rank = [0] * N
        self.par = [i for i in range(N)]
        self.counter = [1] * N

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            z = self.counter[x] + self.counter[y]
            self.counter[x], self.counter[y] = z, z
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        x = self.find(x)
        return self.counter[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)


graph = UnionFind(N)
for x, y in XY:
    graph.unite(x-1, y-1)

ans = 0
for i in range(N):
    if P[i]-1 == i or graph.same(i, P[i]-1):
        ans += 1

print(ans)

Measured memory_bytes: 103428
use contest::io::Scanner;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let a = sc.next::<usize>();
    let b = sc.next::<usize>();
    let c = sc.next::<usize>();
    if a == b && b == c {
        println!("Yes");
    } else {
        println!("No");
    }
}
pub mod contest {
    pub mod io {
        /// Scanner
        ///
        /// # Example
        /// ```
        /// use contest::io::Scanner;
        /// let mut sc = Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
        /// assert_eq!("1".to_string(), sc.next::<String>());
        /// assert_eq!(2, sc.next());
        /// assert_eq!(3.5, sc.next());
        ///
        /// // To create a scanner from stdin:
        /// Scanner::new(std::io::stdin());
        /// ```
        use std;
        use std::io;
        use std::io::BufRead;

        pub struct Scanner<R: io::Read> {
            br: io::BufReader<R>,
            // Read tokens are stored in reversed order per line.
            buf: Vec<String>,
        }

        pub fn new<R: io::Read>(r: R) -> Scanner<R> {
            Scanner::new(r)
        }

        impl<R: io::Read> Scanner<R> {
            #[inline]
            pub fn new(r: R) -> Scanner<R> {
                Scanner {
                    br: io::BufReader::new(r),
                    buf: vec![],
                }
            }
            #[inline]
            pub fn next<T>(&mut self) -> T
            where
                T: std::str::FromStr,
                T::Err: std::fmt::Debug,
            {
                self.next_string()
                    .map(|s| s.parse::<T>().expect("Parse failed: "))
                    .expect("Unexpected EOF")
            }
            #[inline]
            pub fn next2<T1, T2>(&mut self) -> (T1, T2)
            where
                T1: std::str::FromStr,
                T2: std::str::FromStr,
                T1::Err: std::fmt::Debug,
                T2::Err: std::fmt::Debug,
            {
                (self.next(), self.next())
            }
            fn next_string(&mut self) -> Option<String> {
                self.buf.pop().or_else(|| match self.update() {
                    true => self.next_string(),
                    false => None,
                })
            }
            #[inline]
            fn update(&mut self) -> bool {
                let mut s = String::new();
                let res = self.br.read_line(&mut s);
                match res.expect("I/O error.") {
                    0 => false,
                    _ => {
                        self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                        true
                    }
                }
            }
        }

        #[test]
        fn test_next() {
            let mut sc = new("hoge".as_bytes());
            let s: String = sc.next();
            assert_eq!("hoge", s);
        }
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int N;
	      	  cin >> N;
	      	  vector<int> a(N),b(N),c(N);

	      	  REP(i,N) cin >> a[i];
	      	  REP(i,N) cin >> b[i];
	      	  REP(i,N) cin >> c[i];

	      	  sort(a.begin(),a.end());
	      	  sort(b.begin(),b.end());
	      	  sort(c.begin(),c.end());

	      	  ll ans=0;
	      	  REP(i,N){
	      		  int x,y;
	      		  x=upper_bound(c.begin(),c.end(),b[i])-c.begin();
	      		  if(x==N) continue;

	      		  y=lower_bound(a.begin(),a.end(),b[i])-a.begin();


	      		  ans+=((ll)y)*((ll)(N-x));

	      	  }

	      	  cout << ans << endl;


	          return 0;
}


Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
			       c > 0 ? i < b : i > b; \
			       i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
	v.push_back(buffer);
    }
    return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}
 
void solve();
 
signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
	char s[MAX];
	if (scanf("%s", s) == EOF)
	    break;
	int n = strlen(s);
	for (int i = n - 1; i > -1; i--)
	{
	    ungetc(s[i], stdin);
	}
	solve();
    }
    return 0;
}

int N, W;
vector<int> objects[4];
int w[105];
int v[105];

int ans(int i, int used) {
	if (i == 4) return 0;
	int res = ans(i+1, used);
	int sum_v = 0;
	rep(j, (int)objects[i].size()) {
		used += w[0] + i;
		sum_v += objects[i][j];
		if (used > W) break;
		chmax(res, ans(i+1, used) + sum_v);
	}
	return res;
}

void solve()
{
	cin >> N >> W;
	rep(i, N) {
		cin >> w[i] >> v[i];
		objects[w[i] - w[0]].push_back(v[i]);
	}
	rep(i, 4) sort(all(objects[i]), greater<int>());
	// rep(i, objects[0].size()) rep(j, objects[1].size()) 
	// 	rep(k, objects[2].size()) rep(l, objects[3].size()) {
	// 		if ((i+j+k+l) * w[0] + j + 2 * k + 3 * l > W) continue;

	// 	}
	// }
	cout << ans(0, 0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        int b = sc.nextInt();
        if (s.equals("+")) {
            System.out.println(a + b);
        } else {
            System.out.println(a - b);
        }

    }

}


Measured memory_bytes: 23636
import itertools

def cal(n,s):
    l = list(itertools.combinations(range(10),n))
    count = 0
    for i in l:
        if sum(i) == s:
            count += 1
    return count

while True:
    n,s = map(int,input().split())
    if n == 0 and s==0:
        break
    else:
        print(cal(n,s))

Measured memory_bytes: 7788
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=700;
    rep(i,0,s.size())if(s[i]=='o')ans+=100;
    cout<<ans<<endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
st = 1 * 10 ** (N-1)
en = st * 10
SC = []
for i in range(M):
    sc = list(map(int,input().split()))
    SC.append(sc)
if N == 1:
    for i in range(0, 10):
        t = str(i)
        judge = True
        for j in range(M):
            if t[SC[j][0] - 1] != str(SC[j][1]):
                judge = False
        if judge:
            print(i)
            exit()
    print("-1")
    exit()
    
for i in range(st,en):
    t = str(i)
    judge = True
    for j in range(M):
        if t[SC[j][0]-1] != str(SC[j][1]):
            judge = False
    if judge:
        print(i)
        exit()
print("-1")


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
 
using namespace std;
using namespace __gnu_pbds;
 	// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inff (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
#define SPEED ios_base::sync_with_stdio(false) ;cin.tie(NULL) ;cout.tie(NULL) ;
#define fp(i,a,n) for(ll i=n-1; i>a ;i--)
#define deb(x) cout << #x << " ---> " << x << endl;
#define X first
#define Y second
#define pia 3.1415926536
#define mod 1000000007

#define ml map<ll,ll>
#define mll map<pll,ll>
#define letsh(a,b) (a<<b)
#define rigsh(a,b) (a>>b)
 #define vvl vector<vl>
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()) ;
		ll lcm(ll a, ll b){
               return a / __gcd(a, b) * b;
       }
	   bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 	   

       ll power(ll a,ll n)
	   {
        ll ans=1;
        while(n)
		{
        if(n&1) ans=(ans*a)%mod;
        a=(a*a)%mod ;
        n=n>>1;
   		 }
   		 return ans;
      }
      ll power2(ll a,ll n)
      {
      	ll ans =1 ;
      	while(n)
      	{
      		if(n&1) ans =(ans*a) ;
      		a = (a*a) ;
      		n =n>>1 ;
		  }
		  return ans ;
	  } 
	  void p1(ll x,ll y)
	  {
	  cout<<x<<" "<<y<<endl ; 	
	  }
	  void p2(ll x,ll y)
	  {
	  	cout<<x<<" "<<y<<" " ;
	  }
  vvl dir({{1, 0}, {-1, 0}, {0, 1}, {0, -1}});
 #define N 100000 
  #define LSB(i) ((i) & -(i)) // zeroes all the bits except the least significant one
	 bool inside(int x, int y)
   {
    	return 1 <= min(x, y) && max(x,y) <= N;
   }
   void readme(int x) 
   {
   	cout<<x<<endl ,exit(0) ;
   }

  void solve()
 {
  ll n ; cin>>n ;
	 cout<<(n^1)<<endl ;
 }
  int main() 
  	{
  	ll t=1 ;//N = 317 ;
  //	get_prime() ;
  //	cout<<setprecision(12); 
	  while(t--) solve() ;
   	}
   	

Measured memory_bytes: 3628