akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


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

    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans=a*x+b*y;
    if (x>y) {
        swap(x,y);
        swap(a,b);
    }
    ans=min(ans,b*(y-x)+2*c*x);
    ans=min(ans,2*c*y);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  if(N==3||N==5||N==7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		char a[] = x.toCharArray();
		if (a[0] == 'A') {
			System.out.println("T");
		} else if (a[0] == 'T') {
			System.out.println("A");
		} else if (a[0] == 'G') {
			System.out.println("C");
		} else {
			System.out.println("G");
		}
	}
}

Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1, 0}
// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1, 0}

var inf = math.MaxInt64

// var mod = 1000000007
// var next = newScanner()

var (
	readString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// ---------------------------------------------------------

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}
func main() {
	defer stdout.Flush()
	N := readInt()
	M := readInt()
	Q := readInt()
	data := make([][]int, 510)
	for i := 0; i < len(data); i++ {
		data[i] = make([]int, 510)
	}
	for i := 0; i < M; i++ {
		l, r := readInt(), readInt()
		data[l][r]++
	}
	for i := 0; i < N+1; i++ {
		for j := 1; j < N+1; j++ {
			data[i][j] += data[i][j-1]
		}
	}
	for i := N; i > 0; i-- {
		for j := 1; j < N+1; j++ {
			data[i][j] += data[i+1][j]
		}
	}

	for i := 0; i < Q; i++ {
		p, q := readInt(), readInt()
		fmt.Println(data[p][q])
	}
}

Measured memory_bytes: 6144
import sys
sys.setrecursionlimit(10**5)


def dfs(s):
    for i in to[s]:
        if not toflag[i]:
            toflag[i]=True
            dfs(i)


def rdfs(s):
    for i in ot[s]:
        if not otflag[i]:
            otflag[i]=True
            rdfs(i)


def bellman_ford():
    for i in range(n):
        upd=False
        for a,b,c in edges:
            if d[b]>d[a]+c:
                upd=True
                d[b]=d[a]+c     
        if not upd:
            break
        if i == n-1:
            print(-1)
            exit()


def main():

    for i in range(m):
        a,b,c=map(lambda x:int(x)-1,input().split())
        edges.append([a,b,-(c+1-p)])
        to[a].append(b)
        ot[b].append(a)

    toflag[0]=True
    otflag[n-1]=True
    dfs(0) # check for 0 to i path
    rdfs(n-1) # check for n-1 to i path
 
    for i in range(m):
        a,b,c=edges[i]
        if toflag[a] and otflag[a] and toflag[b] and otflag[b]: continue;
        edges[i]=[0,0,0]

    d[0]=0
    bellman_ford()
    print(max(0,-d[-1]))



if __name__=='__main__':
    n,m,p=map(int,input().split())
    edges=[]
    to=[[] for i in range(n)]
    ot=[[] for i in range(n)]
    toflag=[False]*n
    otflag=[False]*n
    d=[10**9]*n
    main()

Measured memory_bytes: 11836
#include <iostream>
#include <queue>
using namespace std;
int main()
{
	int n,to=0,ar[101];cin>>n;
	for (int i=0;i<n;i++) {cin>>ar[i];}
	for (int i=1;i<n;i++)
	{
		if (ar[i]<ar[i-1])
		{
			to+=ar[i-1]-ar[i];
		}
	}
	cout<<to+ar[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout.setf(ios::fixed);
    double d;
    cin >> d;
    //l//ong long int lli;
    //lli = (long long int) d;
    //cout << lli;
    //double after = d - lli;
    cout << d * d * d / 27;
}


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

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){

}

// 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)
int main(){
    long long A,B;cin >> A >> B;
    long long C = abs(A - B);
    if(C % 2 != 0){
        cout << NO << endl;
        return 0;
    }
    long long ans = (A*A - B*B)/(2*B-2*A);
    cout << abs(ans) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC103 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
ab = sorted(ab,key = itemgetter(1))
x = 0
ans = 0
for a,b in ab:
    if a >= x:
        x = b
        ans += 1
print(ans)


Measured memory_bytes: 65752
Q,H,S,D=map(int,input().split())
digs=sorted([(8*Q,1,Q),(4*H,2,H),(2*S,4,S),(D,8,D)])
N=4*int(input())
ans=0
for _,d,p in digs:
    ans+=p*(N//d)
    N=N%d
print(ans)

Measured memory_bytes: 38740
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]

ans=[]
for i in range(n):
    MIN=10**10
    index=0
    for g in range(m):
        if MIN>abs(ab[i][0]-cd[g][0])+abs(ab[i][1]-cd[g][1]):
            MIN=abs(ab[i][0]-cd[g][0])+abs(ab[i][1]-cd[g][1])
            index=g+1
    ans.append(index)

for i in range(n):
    print(ans[i])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int A,B;
	cin >> A >> B;
	int K = 0;
	
	while (1)
	{
		if (abs(A - K) == abs(B - K))break;
		if (K > 1000000000)
		{
			cout << "IMPOSSIBLE\n";
			return 0;
		}
		K++;
	}

	cout << K << endl;

	return 0;
}

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

int n;
vector<int> adj[100005];
const int mod = 1e9 + 7;
int dp[100005][2];

void add(int& a, int b) {
	a += b;
	a %= mod;
}

void mul(int& a, int b) {
	a *= b;
	a %= mod;
}

int dfs(int s, int p, int c) {
	if (dp[s][c] != -1)
		return dp[s][c];
	dp[s][c] = 1;
	if (!c) {
		for (auto i : adj[s]) {
			if (i != p) {
				mul(dp[s][c], (dfs(i, s, c) + dfs(i, s, 1 - c)) % mod);
			}
		}
	} else {
		for (auto i : adj[s]) {
			if (i != p) {
				mul(dp[s][c], dfs(i, s, 1 - c));
			}
		}
	}
	return dp[s][c];
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	memset(dp, -1, sizeof dp);
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int ans = dfs(1, -1, 0);
	add(ans, dfs(1, -1, 1));
	cout << ans << '\n';
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define INF 1e7
#define mod 1000000007

using namespace std;
typedef long long int ll;
typedef tuple<int,int,int> tii;
typedef tuple<long long int,long long int,long long int> tll;
typedef tuple<double,double,double> tdd;


int main()
{
    int x; cin >> x;
    cout << 1-x << endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	double t, a;
	cin >> t >> a;
	vector<double> h(n);
	rep(i, n) cin >> h[i];
	int ans;
	double res = 100000;
	rep(i, n) {
		if (res > abs(a - (t - h[i] * 0.006))) {
			res = abs(a - (t - h[i] * 0.006));
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////
vector<P>ans;
signed main(){
  string s;cin>>s;int n = s.length();s = '#' + s;
  bool b = true;
  repd(i,1,n/2+1)b = b && (s[i] == s[n-i]);
  if(s[1] == '0' || s[n] == '1' || !b){
    cout << -1 << endl;return 0;
  }
  int last = n;
  for(int i = n-1;i >= 1;i--){
    ans.push_back(P(last, i));
    if(i > n/2)continue;
    if(s[i] == '1'){
      last = i;
    }
  }
  rep(i,n-1)cout << ans[i].first << " " << ans[i].second << endl;
}


Measured memory_bytes: 3308
import bisect
n, *a = map(int, open(0).read().split())
a = a[::-1]
INF = 1 << 30
dp = [INF] * (n + 1)

for e in a:
    dp[bisect.bisect_right(dp, e)] = e
print(bisect.bisect_left(dp, INF))


Measured memory_bytes: 20040
program main
Implicit None
	integer(8)::n,a,b,c,i,k=4,u(3),e,f,j
	integer(8),allocatable::l(:),t(:)
	
	read*,n,a,b,c
	allocate(l(n),t(n))
	read*,l
	f = 1000000
	
	do i = 1,k**n-1
		u = 0
		call nb(i,k,t,n)
		e = 0
		do j = 1,n
			if(t(j) /= 0)then
				if(u(t(j))/=0) e=e+10
				u(t(j)) = u(t(j))+l(j)
			endif
		enddo
		if(product(u)==0) cycle
		e = e+abs(u(1)-a)+abs(u(2)-b)+abs(u(3)-c)
		if(e<f) f = e
	enddo
	
	print"(i0)",f
end program main

subroutine nb(a1,n,b,k)
Implicit None
	integer(8)::a1,n,k,i,a
	integer(8)::b(k)
	b = 0
	a = a1
	
	do i = 1,k
		b(i) = mod(a,n)
		a = (a-b(i))/n
	enddo
end subroutine nb

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N = 200;
const int mod = 998244353;
int x[N],y[N];
typedef pair<int,int> pii;
int C(int i,int j){
	return x[i]*y[j]-x[j]*y[i];
}
int ccw(int i,int j,int k){
	return C(i,j)+C(j,k)+C(k,i);
}
int pp[N+1];
#define mul(x,y) ((long long)(x)*(y)%mod)
int main(){
	int n;scanf("%d",&n);
	pp[0]=1;for(int i=1;i<=n;i++)pp[i]=mul(pp[i-1],2);
	for(int i=0;i<n;i++){
		scanf("%d%d",x+i,y+i);
	}
	int ans=pp[n];
	ans = (ans+mod-1)%mod;
	ans = (ans+mod-n)%mod;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			int r=n;
			pii a = min(pii(x[i],y[i]),pii(x[j],y[j]));
			pii b = max(pii(x[i],y[i]),pii(x[j],y[j]));
			for(int k=0;k<n;k++){
				if(ccw(i,j,k)==0 && a <= pii(x[k],y[k]) && pii(x[k],y[k])<=b)r--;
			}
			ans-=pp[n-2-r];
			if(ans<0)ans+=mod;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import math

ABHM = [int(x) for x in input().split()]

chou=ABHM[3]*6
tan=ABHM[2]*30+ABHM[3]*0.5

a=abs(chou-tan)

x=math.sqrt(ABHM[0]**2+ABHM[1]**2-2*ABHM[0]*ABHM[1]*math.cos(math.radians(a)))

print(x)

"""
3 4 10 40
4.56425719433005567605
"""

Measured memory_bytes: 9444
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var D = Sarray();
            long sum = 0;
            for (var i = 0; i < N - 1; ++i)
                for (var j = i + 1; j < N; ++j)
                    sum += D[i] * D[j];
            WriteLine(sum);
        }
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
#include <stdlib.h>

int compar(const int *val1, const int *val2) {//昇順並び替え ( < < ..)
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}

int main(){
  int n,k;
  scanf("%d %d\n",&n,&k);
  int h[n];
  for(int i = 0; i < n; ++i) scanf("%d\n",&h[i]);
  qsort(h, n, sizeof(int),(int (*)(const void *, const void *))compar);
  int answer = h[k-1] - h[0];
  int num;
  for(int i = 0; i < n-k+1; ++i){
    num = h[i + k - 1] - h[i];
    if(answer > num) answer = num;
  }
  printf("%d\n",answer);
  return 0;
}

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

class aizu_judge
{
    static void Main()
    {
        while(true)
        {
            int[] num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if(num[0] == 0 && num[1] == 0)
            {
                break;
            }
            Array.Sort(num);
            Console.WriteLine("{0} {1}", num[0], num[1]);
        }

    }
}

Measured memory_bytes: 9852
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

const int MAX = 1e6+10;
ll fac[MAX],inv[MAX],finv[MAX];

void init() {
    fac[0] = 1, fac[1] = 1;
	inv[0] = 0, inv[1] = 1;
    finv[0] = 1, finv[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;
    }
}

ll nCr(int n, int r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

ll nHr(int n, int r) {
    return nCr(n+r-1,r);
}

int main() {
    init();
    int n,k;
    cin >> n >> k;
    ll ans = 0;
    for(int i = 0; i <= min(n-1,k); i++){
        (ans += nCr(n,i)*nHr(n-i,n-(n-i))) %= MOD;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23680
#include <iostream>


unsigned long long int N, M;

void solve() {
    if (N > 1 && M > 1) {
        std::cout << (N-2)*(M-2) << std::endl;
    } else {
        if (N == 1 && M == 1) {
            std::cout << 1 << std::endl;
        } else {
            unsigned long long int L = std::max(N, M);
            std::cout << L-2 << std::endl;
        }
    }
}

int main() {
    std::cin >> N >> M;
    solve();
    return 0;
}


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

#define int long long



signed main(){
	
	int N,A,B;
	int ab=0,b=0;
	cin>>N>>A>>B;
	for(int i=0;i<N;i++){
		char c;
		cin>>c;
		if(c=='a'){
			if(ab<A+B){
				ab++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		else if(c=='b'){
			if(ab<A+B&&b<B){
				ab++;
				b++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		else if(c=='c'){
			cout<<"No"<<endl;
		}
	}
	
	
	
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define N 10000
ll tra[100006],tra1[100006];

int main()
{
    string s;
    cin>>s;
    ll one=0,zero=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1')
            one++;
        else
            zero++;
    }
    cout<<(min(one,zero)*2)<<endl;



}

Measured memory_bytes: 3764
use std::io::stdin;
use std::iter::Iterator;
use std::collections::VecDeque;
use std::collections::HashMap;

fn solve(cin: &mut ConsoleInputWrapper) {
    let n: i64 = cin.input().parse().unwrap();
    println!("{}",n*n*n);
    ()
}

//Other Functions Here

fn main() {
    let mut cin = ConsoleInputWrapper::new();
    solve(&mut cin);
}

fn factorization(value: i64) -> HashMap<i64, usize> {
    let sqrt = f64::sqrt(value.clone() as f64);
    let mut value = value;
    let mut map = HashMap::new();
    let mut p = 2;
    while p.clone() as f64 <= sqrt {
        let mut count = 0;
        while (value % p.clone()) == 0 {
            count += 1;
            value /= p.clone();
        }
        if count > 0 {
            map.insert(p.clone(), count);
        }
        p += 1;
    }
    if value != 1 {
        map.insert(value, 1);
    }
    map
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b.clone(), a % b)
    }
}

fn min(a: i32, b: i32) -> i32 {
    if a < b { a } else { b }
}

fn max(a: i32, b: i32) -> i32 {
    if a > b { a } else { b }
}

struct ConsoleInputWrapper {
    queue: VecDeque<String>
}

impl ConsoleInputWrapper {
    fn new() -> ConsoleInputWrapper {
        ConsoleInputWrapper {
            queue: VecDeque::new()
        }
    }
    fn input(&mut self) -> String {
        if self.queue.len() <= 0 {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let list: Vec<&str> = s.split_whitespace().collect();
            for string in list {
                self.queue.push_back(String::from(string));
            }
        }
        self.queue.pop_front().unwrap()
    }
}

Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

int n,m;
vector<vector<int> >g;
bool vis[222222];

void dfs(int x){
  if(vis[x]) return;
  vis[x]=true;
  for(int i=0;i<g[x].size();i++){
    dfs(g[x][i]);
  }
}

int main(void){
  cin>>n>>m;
  g.resize(n+m+1,vector<int>());
  int k,x;
  for(int i=0;i<n;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>x;
      g[i].pb(n+x);
      g[n+x].pb(i);
    }
  }
  dfs(0);
  for(int i=0;i<n;i++){
    if(!vis[i]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


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


using namespace std;


# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }

// DPテーブル
long long dp[110][100100] = {0};

int main() {
  int N,i,j =0;
  int64_t W;
  cin >> N >> W;
  
  //vector<vector<int64_t>> dp(W+5, vector<int64_t>(N+5));
  vector<int> weight(N);
  vector<int> value(N);
  rep(i, N) {
    //cin >> weight.at(i) >> value.at(i);
    cin >> weight[i] >> value[i];
  }
  
  rep(i, N) {
    reps(j, W) {
      if (j - weight[i] >= 0) {
        chmax(dp[i+1][j], dp[i][j - weight[i]] + value[i]);
      }
      chmax(dp[i+1][j], dp[i][j]);
    }
  }
  cout << dp[N][W] << endl;
}


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

int main()
{
	long long n;
  	cin>>n;
  	string s[n];
  	int t[n];
  	for(long long i=0; i<n; i++)
    {
      	cin>>s[i]>>t[i];
    }
  	string x;
  	cin>>x;
  	long long j=0;
  	for( ; j<n; j++)
    {
       if(x==s[j])
         break;
    }
  	long long sum=0;
  	for(long long i=j+1; i<n; i++)
    {
       sum+=t[i];
    }  
  	cout<<sum<<endl;
return 0;  
}  

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    limit = 10**18
    ans = 1
    for ai in a:
        ans *= ai
        if ans > limit:
            print(-1)
            exit(0)
        if ans == 0:
            break
    print(ans)

    


if __name__ == '__main__':
    main()

Measured memory_bytes: 20132
#include <bits/stdc++.h>
#pragma GCC optimize("O3")  
#define pb push_back
#define F first
#define S second
using ll = long long;
using namespace std;



void solve(){
	   int n;
	   cin>>n;
	   vector<int> a(n);
	   for(int &i:a) cin>>i;
	   sort(a.begin(),a.end(),greater<int>());
	   ll ans=a[0];
	   int sub=n-2;
	   int j=1;
	   while(sub>0){
	   	ans+=2*a[j];
	   	sub-=2;
	   	if(sub<0){
	   	  ans-=a[j];
	   	  break;
	   	}
	   	j++;
	   }	
	   cout<<ans<<endl;





	
}


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






Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
	int x;
	set<int> st;
	for(int i=1;i<=5;i++) st.insert(i);	
	for(int i=0;i<5;i++){
		cin>>x;
		if(st.find(x)!=st.end()) st.erase(x);
	}
	cout<<*st.begin();
	return 0;
}

Measured memory_bytes: 3548
n,w=map(int,input().split())
dp = [[0 for i in range(w+1)] for i in range(n+1)]
#print(dp)
for i in range(n):
    weight,value=map(int,input().split())
    for j in range(w+1):
        if j < weight:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-weight]+value)
print(dp[n][w])

Measured memory_bytes: 218748
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 







int main()
{
     int h,w,a,b;
     cin>>h>>w>>a>>b;
     for(int i=0;i<b;i++){
          for(int j=0;j<a;j++)cout<<0;
          for(int j=a;j<w;j++)cout<<1;
          cout<<"\n";
     }
     for(int i=b;i<h;i++){
          for(int j=0;j<a;j++)cout<<1;
          for(int j=a;j<w;j++)cout<<0;
          cout<<"\n";
     }
     
}




































Measured memory_bytes: 3608
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String s,s1;
		Scanner sc =new Scanner(System.in);
		int k=0;
		s=sc.next();
		s1=sc.next();
		for(int i=0;i<3;i++)
		{
		        if(s.charAt(i)!=s1.charAt(2-i))
		        {
		            k=1;
		        }
		}
		if(k==1)
		{
		    System.out.println("NO");
		}
		else
		{
		    System.out.println("YES");
		}
	}
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int min = Integer.MAX_VALUE;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            sum += s[i];
            if (s[i] % 10 != 0) min = Math.min(min, s[i]);
        }

        if (sum % 10 != 0) {
            System.out.println(sum);
        } else {
            if (min != Integer.MAX_VALUE) {
                System.out.println(sum - min);
            } else {
                System.out.println(0);
            }
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#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()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  char a, b; std::cin >> a >> b;

  bool AtCoDeer = false;
  if ( a == 'H' ) AtCoDeer = true;
  else AtCoDeer = false;

  if ( b == 'H' ) {
    if ( AtCoDeer ) std::cout << "H" << std::endl;
    else std::cout << "D" << std::endl;
  }
  else {
    if ( AtCoDeer ) std::cout << "D" << std::endl;
    else std::cout << "H" << std::endl;
  }

  return 0;
}


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

int main(){
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  int ans2;
  if(w/2 == x && h/2 == y) ans2 = 1;
  else ans2 = 0;
  double area = w*h/2;
  printf("%.10f\n", area);
  cout << ans2 << endl;
}


Measured memory_bytes: 3760
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

ll check(ll n){
  ll res = 0;
  while(n%2==0){
    n /= 2;
    res++;
  }
  return res;
}

int main(){
  ll N,M; cin>>N>>M;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];

  SORT(a);
  ll ans = 0;


  //まずできるかcheck
  vector<ll> b(N);
  rep(i,N) b[i] = a[i]/2;
  ll tmp = check(b[0]);
  rep(i,N){
    if(tmp!=check(b[i])){
      cout<<ans<<endl;
      return 0;
    }
  }

  //最初の数
  ll first = b[0];
  rep(i,N){
    first *= b[i]/gcd(b[i],first);
    if(first>M){
      cout<<ans<<endl;
      return 0;
    }
  }
  //確認
  //cout<<first<<endl;
  M -= first;
  ans++;

  //最小公倍数に1こある
  ll next = a[0];
  rep(i,N){
    next *= a[i]/gcd(a[i], next);
    if(next > M){
      cout<<ans<<endl;
      return 0;
    }
  }
  ans += M/next;
  cout<<ans<<endl;

}


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

typedef long long ll;
const int MOD = 1e9 + 7;
int H, W, ans = 0;
int g[1002][1002];
bool solved[1002][1002];
ll dp[1002][1002];

ll calc(int i, int j) {
    if(solved[i][j]) return dp[i][j];
    if(i + 1 == H && j + 1 == W) return 1LL;

    ll down = 0, right = 0;
    if(g[i + 1][j]) down = calc(i + 1, j) % MOD;
    if(g[i][j + 1]) right = calc(i, j + 1) % MOD;

    solved[i][j] = 1;
    return dp[i][j] = (down + right) % MOD;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> H >> W;

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            char inpt;
            cin >> inpt;
            if(inpt == '.') g[i][j] = 1;
        }
    }

    cout << calc(0, 0);

    return 0;
}


Measured memory_bytes: 13056
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
suma = sum(a)
counter = Counter(a)
for b, c in bc:
    suma -= b * counter[b]
    suma += c * counter[b]
    counter[c] += counter[b]
    counter[b] = 0
    print(suma)


Measured memory_bytes: 40376
#include <stdio.h>

int main()
{
  int ret, i;
  int N, A[200000];
  int max, max2;

  ret = scanf("%d", &N);
  for ( i=0; i<N; i++ )
    ret = scanf("%d", &(A[i]));
  if ( A[0] < A[1] ) {
    max = A[1];
    max2 = A[0];
  }
  else {
    max = A[0];
    max2 = A[1];
  }
  for ( i=2; i<N; i++ ) {
    if ( max < A[i] ) {
      max = A[i];
    }
    else if ( max2 < A[i] ) {
      max2 = A[i];
    }
  }
  for ( i=0; i<N; i++ ) {
    if ( A[i] == max )
      printf("%d\n", max2);
    else
      printf("%d\n", max);
  }
  return 0;
}

Measured memory_bytes: 2304
S = list(input())
T = list(input())

S.sort()
T.sort(reverse=True)

alpha = list('abcdefghijklmnopqrstuvwxyz')

check = False
cnt = 0
for s, t in zip(S,T):
  res = alpha.index(s) - alpha.index(t)
  if res < 0:
    check = True
    break
  elif res == 0:
    cnt += 1

if cnt == len(S):
  if len(S) < len(T):
    check = True

print("Yes" if check else "No")

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define Online
#define nowtime (double)clock()/CLOCKS_PER_SEC
void tie() {
	ios::sync_with_stdio(0);
	cin.tie(0);
}
int main() {
	tie();
#ifndef Online
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int x,y,cnt=0;
	n+=1;
	while(n--) {
		if(n>=1) cin>>x>>y;
		if(cnt==3) {
			cout<<"Yes\n";
			return 0;
		}
		if(n>=1) {
			if(x==y) {
				cnt++;
			} else cnt=0;
		}
	}
	cout<<"No\n";
#ifndef Online
	fclose(stdin);
	fclose(stdout);
#endif
	return 0;
}


Measured memory_bytes: 3648
main = do
    a <- readLn
    let h = a `div` 60 `div` 60
        m = a `div` 60 - h * 60
        s = a - h * 60 * 60 - m * 60
    putStrLn $ (show h) ++ ":" ++ (show m) ++ ":" ++ (show s)



Measured memory_bytes: 3652
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int l = sc.nextInt();
    int[][] a = new int[n][m];
    int[][] b = new int[m][l];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < l; j++) {
        b[i][j] = sc.nextInt();
      }
    }
    long[][] c = new long[n][l];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < l; j++) {
        for (int k = 0; k < m; k++) {
          c[i][j] += a[i][k] * b[k][j];
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < l - 1; j++) {
        System.out.print(c[i][j] + " ");
      }
      System.out.println(c[i][l - 1]);
    }
  }
}



Measured memory_bytes: 54516
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	run()
}

func run() {
	// scanner := bufio.NewScanner(reader)
	// scanner.Scan()
	// S := scanner.Text()
	burReader := bufio.NewReaderSize(reader, 100000)
	input := make([]byte, 0, 100000)

	for {
		line, isPrefix, err := burReader.ReadLine()

		if err != nil {
			if err.Error() == "EOF" {
				break
			}

			panic(err)
		}

		input = append(input, line...)

		if !isPrefix {
			break
		}
	}

	words := []string{"dream", "dreamer", "erase", "eraser"}

LOOP_MAIN:
	for i := len(input) - 1; i >= 0; {
	LOOP_WORDS:
		for _, word := range words {
			if len(word)-1 > i {
				continue
			}

			for j := 0; j < len(word); j++ {
				if word[len(word)-1-j] != input[i-j] {
					continue LOOP_WORDS
				}
			}

			i -= len(word)
			continue LOOP_MAIN
		}

		fmt.Fprintln(writer, "NO")
		return
	}
	fmt.Fprintln(writer, "YES")
}


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

int main() {
  int x, a, b;
  scanf("%d%d%d", &x,&a, &b);
  if(a>=b) cout << "delicious" << endl;
  else if(a+x>=b) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N, P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
else:
    ctr = defaultdict(int)
    ctr[0] = 1
    cur = 0
    for i in reversed(range(N)):
        cur = (cur + int(S[i]) * pow(10, N - i - 1, P)) % P
        ctr[cur] += 1

    ans = 0
    for v in ctr.values():
        ans += v * (v - 1) // 2
    print(ans)


Measured memory_bytes: 74824
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        int[] d = LineInt();
        Array.Sort(d);
        Console.WriteLine(d[N / 2] - d[N / 2 - 1]);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 19680
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

ll dp[100100][2];

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    dp[0][0] = a[0];
    dp[0][1] = -a[0];
    for(int i = 1; i<n; ++i) {
        dp[i][0] = max(dp[i-1][0]+a[i],dp[i-1][1]-a[i]);    
        dp[i][1] = max(dp[i-1][0]-a[i],dp[i-1][1]+a[i]);
    }
    cout << dp[n-1][0] << endl;
    return 0;
}





















Measured memory_bytes: 2560
from collections import deque
def bfs(s):
	que = deque([])
	que.append(s-1)
	while que:
		v = que[0]
		que.popleft()
		for b, c in d[v]:
			if l[b] == 0:
				l[b] = l[v] + c
				que.append(b)
n = int(input())
l = [0 for i in range(n)]
d = [[] for i in range(n)]
for i in range(n-1):
	a, b, c = map(int, input().split())
	d[a-1].append((b-1,c))
	d[b-1].append((a-1,c))
q, k = map(int ,input().split())
bfs(k)
#print (l)
for i in range(q):
	x, y = map(int, input().split())
	print (l[x-1]+l[y-1])


Measured memory_bytes: 43664
#include <bits/stdc++.h>
using namespace std;
int main(void){

	int A,B;
  cin >> A >> B;
  
  if(A <= 9 && B <= 9)
  {
    cout << A*B;
  }
  else
  {
    cout << -1;
  } 
  
  
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main(){
  string S;
  cin>>S;
  int n=S.size();
  int x[n];
  for(int i=0;i<n;i++){
    x[i]=S.at(i)-'0';
  }
  int min=10000;
  for(int i=0;i<n-2;i++){
    int l=100*x[i]+10*x[i+1]+x[i+2];
    if(abs(l-753)<min){
      min=abs(l-753);
    }

  }
  cout<<min<<endl;

  


  

  



}


  

Measured memory_bytes: 888
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


const int max_comb = 2100000;
vector<ll> fac(max_comb + 1); //n! (mod M)
vector<ll> ifac(max_comb + 1); //k!^(-1) (mod M)

ll mpow(ll x, ll n) { //x^n(mod M)
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % MOD;
		x = x * x % MOD;
		n = n >> 1;
	}
	return ans;
}

ll minv(ll x) {
	return mpow(x, MOD - 2);
}

ll comb(int a, int b) {     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % MOD;
	return tmp * fac[a] % MOD;
}

ll perm(int a, int b) {     // P(a,b) = a! * (a-b)!^(-1)
	if (b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] % MOD;
	return tmp * fac[a] % MOD;
}

void pre_comb()
{
	fac[0] = 1;
	ifac[0] = 1;
	for (int i = 0; i < max_comb; i++) {
		fac[i + 1] = fac[i] * (i + 1) % MOD; // n!(mod M)
		ifac[i + 1] = ifac[i] * minv(i + 1) % MOD; // k!^(-1) (mod M)
	}
	return;
}


void solve()
{
	int a, b;
	scanf("%d%d", &a, &b);
	ll x = (ll)2 * a - b;
	ll y = (ll)2 * b - a;
	if (x<0 || y<0 || x % 3 || y % 3) {
		printf("0\n"); return;
	}
	x /= 3; y /= 3;
	pre_comb();
	printf("%lld\n", comb(x+y, x));

	return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 33152
n, m = map(int, input().split())
ans = [-1] * n
exist = True
for i in range(m):
    s, c = map(int, input().split())
    if (n != 1 and (s, c) == (1, 0)) or (ans[s - 1] != -1 and ans[s - 1] != c):
        exist = False
        break
    else:
        ans[s - 1] = c

if exist:
    for i in range(n):
        if n != 1 and i == 0:
            if ans[i] == -1:
                ans[i] = 1
        else:
            if ans[i] == -1:
                ans[i] = 0
    print(*ans, sep='')
else:
    print(-1)

Measured memory_bytes: 9144
K, S = list(map(int,input().split()))
ans = 0
for i in range(K+1):
    tmp = S - i
    if tmp >= 0:
        for j in range(K+1):
            if (S - i - j) >= 0 and (S - i -j) <= K:
                ans += 1
print(ans)

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

int N, temp, ans = 0;
std::vector<int> H;

using itr = std::vector<int>::iterator;

void div(itr s, itr e) {
    if (s == e) return;
    
    auto m_itr = std::min_element(s, e);
    ans += *m_itr;
    int min = *m_itr;
    
    for (auto i=s; i!=e; i++) {
        *i -= min;
    }
    
    div(s, m_itr);
    div(m_itr+1, e);
}

int main() {
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        H.push_back(temp);
    }
    
    div(H.begin(), H.end());
    
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    int a[100][2];
    for (int i=0; i<n; i++){
        cin >> a[i][0] >> a[i][1];
    }
    // Be careful when the loop ends
    for (int i=0; i<n-2; i++){
        if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3616
A, B = tuple(map(int, input().split()))
if A == 1:
    if B == 1:
        print("Draw")
    else:
        print("Alice")
else:
    if B == 1:
        print("Bob")
    else:
        if A < B:
            print("Bob")
        elif A > B:
            print("Alice")
        else:
            print("Draw")

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

string s, t;

int main(){
  cin >> s >> t;
  int n = s.size();
  bool clr = false;
  for(int i = 0; i < n; i++){
    if(s == t) {
      clr = true;
      break;
    }
    s = s.back() + s.substr(0, n - 1);
  }
  
  if(clr) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(void){
	int i, j, n, maxv=-1000000000, temp, minv;
	int *r;
	scanf("%d", &n);
	r = malloc(n*sizeof(int));
	for(i=0;i<n;i++){
		scanf("%d", &r[i]);
	}
	minv=r[0];
	for(j=1;j<n;j++){
		temp=r[j]-minv;
		if(maxv<temp){
			maxv=temp;
		}
		if(minv>r[j]){
			minv=r[j];
		}
	}
	printf("%d\n", maxv);
}

Measured memory_bytes: 2580
N = int(input())
Nums = [int(e) for e in input().split()]
D = Nums[0]
X = Nums[1]
dayList = []
for i in range(N):
  dayList.append(int(input()))
#Xは最後にたすよね～　各人数forで
totalChocolate = X
for i in range(N):
  Ai = dayList[i]
  chocolateCount = 0
  j = 0
  while Ai * j + 1 <= D:
    chocolateCount += 1
    j += 1
  totalChocolate += chocolateCount
print(totalChocolate)

Measured memory_bytes: 3188
#include <iostream>

#define SIZE 100000

using ll = long long;

int N;
ll  x;
ll a[SIZE];

ll solve() {
    int idx = 1;
    ll  ans = 0;
    if (a[0] > x) {
        ans  += a[0] - x;
        a[0]  = x;
    }
    while (idx < N) {
        if (a[idx-1] + a[idx] > x) {
            ans    += a[idx-1] + a[idx] - x;
            a[idx] -= a[idx] + a[idx-1] - x;
        }
        ++idx;
    }
    return ans;
}

int main() {
    std::cin >> N >> x;
    for (int i=0; i<N; ++i) std::cin >> a[i];
    std::cout << solve() << std::endl;
    return 0;
}

Measured memory_bytes: 1024
all_question, submission_count = map(int, input().split())
results = {}
for _ in range(submission_count):
    question_num, res = input().split()
    if question_num not in results:
        results[question_num] = []
    results[question_num].append(res)


def get_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

clear_count = penalty_count = 0

for questuin_num, res_list in results.items():
    index = get_index(res_list, "AC")
    if index == -1:
        continue
    penalty_count += index
    clear_count += 1

print(clear_count, penalty_count)

Measured memory_bytes: 31564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll t1,t2,a1,a2,b1,b2;cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if(t1*a1+t2*a2==t1*b1+t2*b2){
    cout << "infinity" << endl;
    return 0;
  }
  ll c1=a1-b1;
  ll c2=a2-b2;
  if(c1<0){
    c1*=-1;
    c2*=-1;
  }
  if(c1*t1+c2*t2>0){
    cout << 0 << endl;
    return 0;
  }
  ll u=c1*t1;
  ll v=c1*t1+c2*t2;
  if(abs(u)%abs(v)==0){
    cout << abs(u)/abs(v)*2 << endl;
  }
  else{
    cout << abs(u)/abs(v)*2+1 << endl;
  }
}

Measured memory_bytes: 256