akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long arr[20000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long x,y,z,i,j,k;
    for (i=1;i<=10000000;i++)
    {
    	arr[i]=1;
	}
	for (i=2;i<=10000000;i++)
	{
		for (j=i;j<=10000000;j+=i)
		{
			arr[j]++;
		}
	}
	k=0;
	cin>>x;
	for (i=1;i<=x;i++)
	{
		k=k+i*arr[i];
	}
	cout<<k<<endl;
}

Measured memory_bytes: 81768
a = input().split()

for i in range(len(a)):
 a[i] = int(a[i])

mina = a[0]
maxa = a[1]
numbers = a[2]

for i in range(mina,mina+numbers):
 if i <= maxa:
  print (i)

for j in range(maxa-numbers+1,maxa+1):
 if j> i:
  print (j)



Measured memory_bytes: 3060
#!python3.4
# -*- coding: utf-8 -*-
# abc160/abc160_e
import sys
from collections import deque


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X, Y, A, B, C = i2nn()
    p = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:X])
    q = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:Y])
    r = deque(sorted(map(int, i2s().split(' '))))
    s = 0
    while p or q:
        if p and q:
            t = p if p[-1] < q[-1] else q
        else:
            t = p if p else q
        if r and t[-1] < r[-1]:
            t.pop()
            s += r.pop()
        else:
            s += t.pop()
    print(s)
    return

main()


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

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n;
char s[N], d[N];

int mult(int x, int y) {
  return (1LL * x * y) % mod;
}

int fact(int n) {
  if (n == 0)
    return 1;
  else
    return mult(n, fact(n - 1));
}

void flip(int at) {
  char c = d[at - 1];
  d[at] = (c == 'L' ? 'R' : 'L');
}

int main() {
  scanf("%d %s", &n, s);
  n += n;
  if (s[0] == 'W' || s[n - 1] == 'W') {
    puts("0");
    return 0;
  }
  d[0] = 'L';
  for (int i = 1; i < n; i++) {
    d[i] = d[i - 1];
    if (s[i] == s[i - 1])
      flip(i);
  }
  int l = 1, r = 0, ans = 1;
  for (int i = 1; i < n; i++) {
    if (d[i] == 'R') {
      ans = mult(ans, l - r);
      r++;
    } else {
      l++;
    }
  }
  printf("%d\n", (l != r ? 0 : mult(ans, fact(n / 2))));
  return 0;
}

Measured memory_bytes: 2176
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
judge = True

A_num = [0] * (N+1)
B_num = [0] * (N+1)
C = [0] * (N+1)
D = [0] * (N+1)

for a in A:
  A_num[a] += 1
for b in B:
  B_num[b] += 1
  
for a,b in zip(A_num,B_num):
  if a+b>N:
    judge = False
    break

if judge:
  for i in range(1,N+1):
    C[i] = C[i-1] + A_num[i]
    D[i] = D[i-1] + B_num[i]
  x = -float('inf')
  for i in range(1,N+1):
    x = max(x, C[i] - D[i-1])
    
  ans = B[-x:] + B[:-x]
  print('Yes')
  print(' '.join(map(str,ans)))
  
else:
  print('No')

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

#define int long long

void solve() {
	int n;
	cin>>n;
	int sum=0;
	for(int a=1;a<=n;a++) {
		for(int b=1;b<=n;b++) {
			for(int c=1;c<=n;c++) {
				int g=__gcd(a,b);
				g=__gcd(g,c);
				sum+=g;
			}
		}
	}
	cout<<sum<<"\n";
}

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

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mxn 300007
#define ar array
#define mod 1000000007
#define ld long double
#define pb push_back
#define ar array
#define fi first
#define se second
typedef long long int ll;
using namespace std;
int main(void){
	fast;
	int x;
	cin>>x;
	if(x<600)
	cout<<8;
	else if(x<800)
	cout<<7;
	else if(x<1000)
	cout<<6;
	else if(x<1200)
	cout<<5;
	else if(x<1400)
	cout<<4;
	else if(x<1600)
	cout<<3;
	else if(x<1800)
	cout<<2;
	else if(x<2000)
	cout<<1;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;


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

    bool flg = true;
    int start = -1;
    for(int i=0;i<s.length()-t.length()+1;i++){
        flg = true;
        for(int j=0;j<t.length();j++){
            if(s[i+j]!=t[j] && s[i+j]!='?'){
                flg = false;
                break;
            }
        }
        if(flg){
            start = i;
            //cout << "i:" << i << endl;
        }
    }
    if(start==-1)cout << "UNRESTORABLE" << endl;
    else{
        for(int i=0;i<start;i++){
            if(s[i]=='?')cout << 'a';
            else cout << s[i];
        }
        for(int i=0;i<t.length();i++)cout << t[i];
        for(int i=start+t.length();i<s.length();i++){
            if(s[i]=='?')cout << 'a';
            else cout << s[i];
        }
        cout << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>

int p[2*100005];
int main()
{
	int n;
	std::cin>>n;
	for(int i=1;i<=n;i++)
		std::cin>>p[i];
	int max_x = p[1],ans=1;
	for(int i=2;i<=n;i++)
	{
		if(p[i] <= max_x) ans++;
		max_x = std::min(p[i],max_x);
	}
	std::cout<<ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int MAXN=1e5+50;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main()
{
    //freopen("in.txt","r",stdin);
   ll a,b;
   scanf("%lld%lld",&a,&b);
   printf("%lld\n",a*b/gcd(a,b));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

int main(int argc, const char* argv[]) {
  u64 k, s;
  cin >> k >> s;
  
  u64 ret = 0;
  rep(x, k+1) {
    debug(x);
    u64 a = s - x; // a を y + z で作る
    
    if(2 * k < a) {
      ;
    } else if(k < a) {
      ret += 2 * k + 1 - a;
    } else {
      ret += a + 1;
    }
    debug(ret);
  }
  
  cout << ret << endl;
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1 && b>1)
    {
        cout<<"Alice"<<endl;
    }
    else if(b==1 && a>1)
    {
        cout<<"Bob"<<endl;
    }
    else if(b==a)
    {
        cout<<"Draw"<<endl;
    }
    else if(a>b)
    {
        cout<<"Alice"<<endl;
    }
    else if(b>a)
    {
        cout<<"Bob"<<endl;
    }



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 ll n;
 cin>>n;
 ll a[n],b[n],c[n];
 for(ll i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
 ll dp[n][3];
 dp[n-1][0]=a[n-1];
 dp[n-1][1]=b[n-1];
 dp[n-1][2]=c[n-1];
 for(ll i=n-2;i>=0;i--){
  dp[i][0]=max(a[i]+dp[i+1][1],a[i]+dp[i+1][2]);
  dp[i][1]=max(b[i]+dp[i+1][0],b[i]+dp[i+1][2]);
  dp[i][2]=max(c[i]+dp[i+1][0],c[i]+dp[i+1][1]);
 }
 cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<endl;
 return 0;
}

Measured memory_bytes: 4992
'use strict';
(function(stdin) {
	for(var i= 1;i<= 9;i++){
	 for (var j= 1;j<= 9;j++){
		  console.log([i,'x' ,j ,'=' ,i*j].join(''));
		}
	}
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7640
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
typedef long long ll;
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int main()
{
	//4 8 3
	int a, b, k;
	cin >> a >> b >> k;
	set<int>s;
	for (int i = a; i < k + a && i <= b; i++)
	{
		s.insert(i);
	}
	for (int i = b,j=1; j<=k &&i>=a; i--,j++)
		s.insert(i);
	set<int>::iterator it=s.begin();
	for (;it!=s.end();it++)
	{
		cout << *it << endl;;
	}


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int n;
map<string,int> m;
vector<pair<pair<int,string>,int> > v;
int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    int a;
    cin >> s >> a;
    if(m.find(s) == m.end()){
      m[s] = v.size();
      v.push_back(make_pair(make_pair(s.size(),s),-a));
    }else{
      v[m[s]].second -= a;
    }
  }
  sort(v.begin(),v.end());
  for(int i = 0; i < (int)v.size(); i++){
    cout << v[i].first.second << " " << -v[i].second << endl;
  }
}

Measured memory_bytes: 1232
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long S = sc.nextLong();

        int result = dfs("0", S);

        System.out.println(result);
    }

    public static int dfs(String target, Long S) {
        int result = 0;

        if (Long.parseLong(target) > S) {
            return result;
        }

        if (target.matches(".*3.*") && target.matches(".*5.*") && target.matches(".*7.*")) {
            result++;
        }

        result += dfs(target + "3", S);
        result += dfs(target + "5", S);
        result += dfs(target + "7", S);
        return result;
    }

}

Measured memory_bytes: 46704
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;
 
int main(void) {
    int n;
    cin >> n;
    int a[2][n], tmp=0;
    int i, j;
    for(i=0; i<2; i++) {
        for(j=0; j<n; j++)
            cin >> a[i][j];
    }
    int ans=a[0][0];
    for(i=0; i<n; i++)
        ans += a[1][i];
    tmp=ans;
    for(i=0; i<n-1; i++) {
        tmp = tmp - a[1][i] + a[0][i+1];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
gcdl, gcdr = [0] + [None] * N + [0], [0] + [None] * N + [0]
gcd = lambda x, y : x if y == 0 else gcd(y, x % y)
for i in range(1, N + 1):
    gcdl[i] = gcd(gcdl[i - 1], A[i])
    gcdr[N + 1 - i] = gcd(gcdr[N + 2 - i], A[N + 1 - i])
ans = 1
for i in range(1, N + 1):
    tmp = gcd(gcdl[i - 1], gcdr[i + 1])
    if tmp > ans:
        ans = tmp
print(ans)

Measured memory_bytes: 64364
def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  maximam = 10**18

  result = 1
  if 0 in A:
    print(0)
    return True

  for a in A:
    result *= a
    if result > maximam:
      print(-1)
      return True
  print(result)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 21772
def partial_match_table(word):
    table = [0] * (len(word) + 1)
    table[0] = -1
    i, j = 0, 1
    while j < len(word):
        matched = word[i] == word[j]
        if not matched and i > 0:
            i = table[i]
        else:
            if matched:
                i += 1
            j += 1
            table[j] = i
    return table

def kmp_search(text, word):
    table = partial_match_table(word)
    i, p = 0, 0
    results = []
    while i < len(text) and p < len(word):
        if text[i] == word[p]:
            i += 1
            p += 1
            if p == len(word):
                p = table[p]
                results.append((i-len(word), i))
        elif p == 0:
            i += 1
        else:
            p = table[p]
    return results

inf = 10**18
s = input().strip()
t = input().strip()
m=(len(t)+len(s)-1+len(s)-1)//len(s)
es = set()
d = [set() for _ in range(len(s)+1)]
d2 = [set() for _ in range(len(s)+1)]
#print(t, m*s)
#print(kmp_search(m*s, t))
for a, b in kmp_search(m*s, t):
    a, b = a%len(s)+1, b%len(s)+1
    es.add((a, b))
    d[a].add(b)
    d2[b].add(a)

#print(es)
fs = set()
r = 0
for x in range(len(s)+1):
    if x in fs:
        continue
    vs = set()
    vs.add(x)
    fs.add(x)
    depths = dict()
    depths[x] = 0
    stack = [x]
    mt = x
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt]:
                    mt = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    vs = set()
    vs.add(mt)
    depths = dict()
    depths[mt] = 0
    stack = [mt]
    mt2 = mt
    while stack:
        v = stack.pop()
        if v > 0:
            for u in d2[v]:
                if u in vs:
                    r = inf
                    break
                stack.append(-v)
                stack.append(u)
                depths[u] = depths[v] + 1
                if depths[u] > depths[mt2]:
                    mt2 = u
                vs.add(u)
                fs.add(u)
        else:
            pass
    r = max(depths[mt2], r)
print(r if r != inf else -1)


Measured memory_bytes: 470696
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n;
    cin >> n;
    vector<vector<ll>> g(n);
    rep(i, n){
        ll num;
        cin >> num;
        num--;
        ll edgenum;
        cin >> edgenum;
        rep(j,edgenum){
            ll next;
            cin >> next;
            next--;
            g[num].push_back(next);
        }
    }

    queue<ll> que;
    que.push(0);
    vector<ll> ans(n, -1);
    ans[0] = 0;
    while(!que.empty()){
        ll now = que.front();
        ll dist = ans[now];
        que.pop();
        for(ll i = 0; i < g[now].size(); i++){
            if(ans[g[now][i]] != -1){
                continue;
            }

            ans[g[now][i]] = ans[now] + 1;
            que.push(g[now][i]);

        }
    }

    rep(i,g.size()){
        cout << i+1 << " " << ans[i] << endl;
    }



}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = 998244353;
ll dp[3030][3030];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int n = c - a + 1;
	int m = d - b + 1;
	//cout << n <<  " " << m << endl;
	rep(i, 1, n + 1){
		rep(j, 1, m + 1){
			if(i == 1 && j == 1) dp[i][j] = 1;
			else{
				dp[i][j] = (dp[i - 1][j] * (j + b - 1) + dp[i][j - 1] * (i + a - 1) - dp[i - 1][j - 1] * (j - 1 + b - 1) % mod * (i - 1 + a - 1) % mod  + mod) % mod;
			}
			//cout << i << " " << j << " " << dp[i][j]<< endl;
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}

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


long gcd (long a, long b) {
	ldiv_t t = ldiv (a,b);
	long c = t.rem;
	if (c==0)
		return b;
	return gcd (b, c);
}

int main () {
	int n;
	long x, d;

	scanf ("%d %ld", &n, &x);
	scanf ("%ld", &d);
	d = labs (d - x);
	for (int i=1; i<n; i++) {
		long tmp;
		scanf ("%ld", &tmp);
		d = gcd (labs (tmp-x), d);
	}
	printf ("%ld\n", d);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		long total = 0;
		long sum = -1;
		long length = 0;
		for (int i = 0; i < m; i++) {
		    int d = sc.nextInt();
		    long c = sc.nextLong();
		    length += c;
		    sum += d * c;
		    total += sum / 9;
		    sum %= 9;
		}
		total += length - 1;
		System.out.println(total);
   }
}



Measured memory_bytes: 92048
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let l = read_line () in
  match List.map int_of_string (split l ' ') with
  | [] | [_] -> exit 1
  | a :: b :: _ ->
      let d = a / b in
      let r = a mod b in
      let f = (float_of_int a) /. (float_of_int b) in
      Printf.printf "%d %d %f\n" d r f

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

int main(){
	int N,X;
	cin >> N >> X;
	int count=1;
	int axis=0;
	int loop,ctin;
	for(loop=0;loop<N;loop++){
		cin >> ctin;
		axis+=ctin;
		if(axis<=X){
			count++;
		}else{
			break;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  int H,W;
  cin >> H >> W;
  int cnt[26] = {};
  REP(i,H){
    string s;
    cin >> s;
    REP(i,W){
      cnt[(int)(s[i] - 'a')]++;
    }
  }
  int cnt1 = 0;
  int cnt2 = 0;
  bool ans = false;
  REP(i,26){
    if(cnt[i]%2 == 1) cnt1++;
    else if(cnt[i]%4 == 2) cnt2++;
  }
  if(H%2 == 0 && W%2 == 0){
    if(cnt1 == 0 && cnt2 == 0) ans = true;
  }
  else if(H%2 == 0){
    if(cnt1 == 0 && cnt2 <= H/2) ans = true;
  }
  else if(W%2 == 0){
    if(cnt1 == 0 && cnt2 <= W/2) ans = true;
  }
  else{
    if(cnt1 == 1 && cnt2 <= H/2 + W/2) ans = true;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n,m; cin >>n>>m;
  vector<vector<ll>> a(n,vector<ll>(2));
  rep(i,n) cin >>a[i][0]>>a[i][1];
  sort(all(a));
  ll ans=0;
  ll can=0;
  rep(i,n){
    if(can+a[i][1]>m){
      ans+=a[i][0]*(m-can);
      can=m;
    }else{
      ans+=a[i][0]*a[i][1];
      can+=a[i][1];
    }
  }
  cout <<ans<<endl;
}
  

Measured memory_bytes: 8832
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  string hand[15] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"};
  map<string, int> hand_id;
  REP(i, 15) hand_id[hand[i]] = i;
  int N;
  while(cin>>N && N){
    vector<string> result(N);
    REP(i, N) cin>>result[i];
    vector<int> win(N);
    vector<int> lose(N);
    REP(i, N) {
      int id1 = hand_id[result[i]];
      FOR(j, i + 1, N){
        int id2 = hand_id[result[j]];
        if(id1 == id2){
        }else if((id1 - id2 + 15) % 15 <= 7){
          win[j] ++;
          lose[i]++;
        }else{
          assert((id2 - id1 + 15) % 15 <= 7);
          win[i] ++;
          lose[j]++;
        }
      }
    }
    string winner = "Draw";
    REP(i, N) if(win[i] > 0 && lose[i] == 0) winner = result[i];
    cout<<winner<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int hmt()
{
    int x=0;
    int c=getchar(),n=0;
    for(; !isdigit(c); c=getchar())
        n=(c=='-');
    for(; isdigit(c); c=getchar())
        x=x*10+c-'0';
    if(n)
        x=-x;
    return x;
}
#define in hmt()
#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})
#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forb(i,BS) for(int i=BS._Find_first();i< BS.size();i = BS._Find_next(i))
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
const int N=310,mod=1e9+7;
int n,m,f[N][N][N];
struct pi {int l,x;};
vector<pi> a[N];
int calc(int u,int v,int l)
{
    return 1+(u>=l)+(v>=l);
}
void add(int &x, int y)
{
    x+=y;
    if(x>=mod) x-=mod;
}
int main()
{
    //freopen("E_.inp","r",stdin);
    n=in,m=in;
    while(m--)
    {
        int l=in,r=in,x=in;
        a[r].pb({l,x});
    }
    f[1][0][0]=1;
    forinc(i,0,a[1].size()-1) if(a[1][1].x>1) f[1][0][0]=0;
    forinc(i,2,n)
    {
        forinc(j,0,i-1) forinc(k,0,i-1)
        {
            add(f[i][j][k],f[i-1][j][k]);
            add(f[i][i-1][k],f[i-1][j][k]);
            add(f[i][j][i-1],f[i-1][j][k]);
        }
        forinc(j,0,i-1) forinc(k,0,i-1)
        forinc(z,0,a[i].size()-1) if(calc(j,k,a[i][z].l)!=a[i][z].x) f[i][j][k]=0;
    }
    int ans=0;
    forinc(i,0,n-1) forinc(j,0,n-1) add(ans,f[n][i][j]);
    cout<<((ans+ans)%mod+ans)%mod<<"\n";
}


Measured memory_bytes: 112896
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> dp[2000];
int main(void){
    ll n,m;
    cin>>n>>m;
    ll s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        ll a=s[i];
        dp[i].push_back(a);
        for(int j=1;j<n;j++){
            a=min(a,s[(i+j)%n]);
            dp[i].push_back(a);
        }
    }
    /*for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cout<<dp[i][j]<<endl;
        }
    }*/
    ll ans=1LL<<60;
    for(int i=0;i<n;i++){
        ll rans=0;
        for(int j=0;j<n;j++){
            rans+=dp[j][i];
        }
        //cout<<rans<<i<<endl;
        ans=min(rans+i*m,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 32384
program prob3
    implicit none
    integer::H, W, i,j
    character,allocatable::a(:,:),c(:,:)
    character(len=50)::S
    integer,allocatable::ans(:,:)
    read(*,*) H, W
    allocate(a(H+2,W+2),c(H+2,W+2))
    allocate(ans(H+2,W+2))
    a(1,:) = "."
    a(H+2,:) = "."
    a(:,1) = '.'
    a(:,W+2) = '.'
    do i = 1, H
        read(*,*) S
        do j = 1, W
            a(i+1,j+1) = S(j:j)
        end do
    end do

    ans = 0
    do i = 2, H+1
        do j = 2, W+1
            if(a(i,j) .eq. "#") then
                c(i,j) = "#"
            else
                if(a(i-1,j-1) .eq. "#") then
                    ans(i,j) = ans(i,j) + 1 
                end if
                if(a(i,j-1) .eq. "#") then
                    ans(i,j) = ans(i,j) + 1
                end if
                if(a(i+1,j-1) .eq. "#") then
                    ans(i,j) = ans(i,j) + 1
                end if
                if(a(i-1,j) .eq. "#") then
                    ans(i,j) = ans(i,j) + 1
                end if
                if(a(i+1,j) .eq. "#")then
                    ans(i,j) = ans(i,j) + 1
                end if
                if(a(i-1,j+1) .eq. "#") then
                    ans(i,j) = ans(i,j) + 1
                end if
                if(a(i,j+1) .eq. "#")   then
                    ans(i,j) = ans(i,j) + 1
                end if
                if(a(i+1,j+1) .eq. "#")then
                    ans(i,j) = ans(i,j) + 1
                end if
            end if
        end do
    end do

    do i = 2, H+1
        do j= 2, W+1
            if(ans(i,j) == 0)then
                if(c(i,j) .ne. "#")then
                    c(i,j) = '0'
                end if
            else
                c(i,j) = char(ichar('0')+ ans(i,j))
            end if
        end do
    end do

    do i = 2, H+1
        do j = 2, W+1
            S(j-1:j-1) = c(i,j)
        end do
        write(*,*) S
    end do

    deallocate(a)
    stop
end program

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

public class Main {
    public static void main(String[] args) throws Exception {

        // 入力データの取得
        Scanner scanner = new Scanner(System.in);
        String inputDataRow1 = scanner.nextLine();
        String inputDataRow2 = scanner.nextLine();
        scanner.close();

        // 入力データの編集
        String[] editedInputDataRow1 = inputDataRow1.split(" ");
        int enemyCount = Integer.parseInt(editedInputDataRow1[0]);
        int skillCount = Integer.parseInt(editedInputDataRow1[1]);

        // モンスターの数で処理を分岐させる
        long totalDamageDemand = 0;
        if (enemyCount != 1) {
            String[] editedInputDataRow2 = inputDataRow2.split(" ");
            long[] enemyHPList = new long[enemyCount];
            for (int index = 0; index < enemyCount; index++) {
                enemyHPList[index] = Long.parseLong(editedInputDataRow2[index]);
            }

            // モンスターのHPをソートする
            // 昇順
            Arrays.sort(enemyHPList);

            // 必要攻撃回数の判定
            enemyCount -= skillCount;
            for (int index = 0; index < enemyCount; index++) {
                totalDamageDemand += enemyHPList[index];
            }

        } else {
            long enemyHP = Long.parseLong(inputDataRow2);
            if (skillCount == 0) {
                totalDamageDemand = enemyHP;
            } else {
                totalDamageDemand = 0;
            }
        }

        // 結果の出力
        System.out.println(totalDamageDemand);

    }

}

Measured memory_bytes: 76812
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
s = set(A)

if 0 in s:
    print(0)
    exit()

now = 1

for Ai in A:
    if now*Ai>10**18:
        print(-1)
        exit()
    
    now *= Ai

print(now)

Measured memory_bytes: 96016
#include <stdio.h>
int dists[300][300];
int main(void){
  int N;
  scanf("%d\n", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      scanf("%d", &dists[i][j]);

  unsigned long long ans = 0;
  for(int i = 0; i < N; ++i)
    for(int j = 0; j < N; ++j){
      int a = dists[i][j];
      int flg = 0;
      for(int k = 0; k < N; ++k){
        int b = dists[i][k] + dists[k][j];
        if (a > b) {
          puts("-1");
          return 0;
        } else if (a == b && i != j && j != k && k != i)
          flg = 1;
      }
      if (!flg)
        ans += a;
    }
  printf("%llu\n", ans/2);
}


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

using namespace std;

long long n,x;
vector<pair<long long,int> > ls,us,ps;
int lu[100000];

void solve(){
    int i,j;
    string str;
    cin >> n >> x;
    vector<long long> b(n),l(n),u(n);
    for(i = 0;i < n;i++){
        cin >> b[i] >> l[i] >> u[i];
        ls.push_back(make_pair(l[i],i));
        us.push_back(make_pair(u[i],i));
        ps.push_back(make_pair(x*u[i]-b[i]*(u[i]-l[i]),i));
    }
    sort(ls.begin(),ls.end());
    sort(us.begin(),us.end());
    sort(ps.begin(),ps.end());
    long long mi = -1,ma = x*n;
    while(ma-mi > 1){
        long long m = (ma+mi)/2;
        memset(lu,0,sizeof(lu));
        long long lm = m;
        long long gp = 0,ep = 0;
        int g;
        for(i = n-1;i >= 0;i--){
            if(lm >= x){
                lm -= x;
                j = ps[i].second;
                gp += u[j]*x;
                lu[j] = 1;
            }
            if(lm > 0 && lm < x){
                g = ps[i-1].second;
                break;
            }
        }
        for(i = 0;i < n;i++){
            if(lu[i]) ep += b[i]*u[i];
            else ep += b[i]*l[i];
        }
        int f = 0;
        for(i = 0;i < n;i++){
            if(lm == 0){
                if(ep <= gp) f = 1;
                break;
            }
            if(lu[i]){
                if(lm > b[i]){
                    if(ep+b[g]*(u[g]-l[g]) <= gp-(x-lm)*u[i]+x*u[g]){
                        f = 2;
                        break;
                    }
                }
                else{
                    if(ep+b[g]*(u[g]-l[g])-b[i]*(u[i]-l[i]) <= gp-x*u[i]+lm*l[i]+x*u[g]){
                        f = 3;
                        break;
                    }
                }
            }
            else{
                if(lm > b[i]){
                    if(ep+b[i]*(u[i]-l[i]) <= gp+lm*u[i]){
                        f = 4;
                        break;
                    }
                }
                else{
                    if(ep <= gp+lm*l[i]){
                        f = 5;
                        break;
                    }
                }
            }
        }
        if(f) ma = m;
        else mi = m;
    }
    cout << ma << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 7892
#include <cmath>
#include <climits> /* LLONG_MAX */

#include <string>
#include <vector>
#include <numeric> /* gcd, lcm, partial_sum, reduce*/
#include <iomanip> /* setprecision */
#include <iostream>
#include <algorithm>

using ll = long long; // c++11

const std::string ans[2] = { "No\n", "Yes\n" };

int GetDegit(int n) {
    return log10(n) + 1;
}

int main() {
    using namespace std;
    int n;
    cin >> n;

    int match[10][10]; // 1-9
    fill(match[0], match[10], 0);
    for (int i = 1; i <= n; i++){
        int d = i<10 ? 1 : i<100 ? 10 : i<1000 ? 100 : i<10000 ? 1000 : i <100000 ? 10000 : 100000;
        int s = (i<10) ? i : (i / d);
        int e = i % 10;
        if(s>=10)
            cout << i << endl;
        match[s][e]++;
    }
    ll ans = 0LL;
    for (int i = 1; i < 10; i++){
        for (int j = i; j < 10; j++){
            if(j==i)
                ans += match[i][j] * match[i][j];
            else {
                ans += 2 * match[i][j] * match[j][i];
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <stack>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
    int N, K;
    cin >> N >> K;
    int ans;
    if (K == 1)
        ans = 0;
    else
        ans = N - K;
    cout << ans << endl;
}


Measured memory_bytes: 256
#B
x, y = map(int, input().split())

kame = (y-2*x)/2
tsuru = x - kame

if all(list(map(float.is_integer, [tsuru, kame])) + list(map(lambda x: x>=0, [tsuru, kame]))):
    print("Yes")
else:
    print("No")

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

using namespace std;

#define rep(i, n) for(int=0; i<(int)(n); i++)

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

    vector<int> ruizyou(0);
    int shift = 1;
    while(shift <= N){
        ruizyou.push_back(shift);
        shift *= 2;
    }
    cout << shift/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>

using namespace std;

bool solve(char *a, char *b, int len);
bool dfs(char *data);

int main()
{
    char data[100020];

    cin >> data;

    int p = 0;
    if (dfs(data)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

bool dfs(char *data)
{
    bool ret = false;
    if (data[0] == 0) {
        return true;
    }
    if (solve(data, "dream", 5)) {
        ret = (dfs(data + 5) | ret);
    }
    if (solve(data, "dreamer", 7)) {
        ret = (dfs(data + 7) | ret);
    }
    if (solve(data, "erase", 5)) {
        ret = (dfs(data + 5) | ret);
    }
    if (solve(data, "eraser", 6)) {
        ret = (dfs(data + 6) | ret);
    }

    return ret;
}



bool solve(char *a, char *b, int len)
{
    int ln = strlen(a);
    if (ln < len) {
        return false;
    }
    for (int i = 0; i < len; i++) {
        if (a[i] != b[i]) {
            return false;
        }
    }
    return true;
}


Measured memory_bytes: 896
from math import ceil

n, hp = map(int, input().split())
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
MAX_A = max(A)
B.sort(reverse=True)

cnt = 0
for b in B:
    if b > MAX_A:
        hp -= b
        cnt += 1
    else:
        break
    if hp <= 0:
        break
if hp > 0:
    cnt += ceil(hp / MAX_A)
print(cnt)


Measured memory_bytes: 11312
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
//#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAX 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

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

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

int main() {
  ll N;
  cin >> N;
	ll h[N];
  ll dp[N];
  
	FOR(i,0,N-1){
		cin>>h[i];
    dp[i]=LLONG_MAX;
	}
	dp[0]=0;
  dp[1]=abs(h[0],h[1]);
	FOR(i,2,N-1){
		dp[i]=min(dp[i-2]+abs(h[i],h[i-2]),dp[i-1]+abs(h[i],h[i-1]));
	}
  cout<<dp[N-1]<<endl;

	FOR(i,0,N-1){
  //cout<<dp[i]<<endl;
	}

}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;
const long long mod=1000000007;

struct SegTree{
    static const int size=1<<17;
    bool data[size*2];
    
    void update(int x){
        data[x]=data[x*2] || data[x*2+1];
        if(x>1)update(x/2); 
    }
    
    void update(int x,bool v){
        data[x+size]=v;
        update((x+size)/2);
    }
    
    bool query(int x,int nl,int nr,int l,int r){
        if(nl>r || nr<l)return false;
        if(nl>=l && nr<=r)return data[x];
        int mid=(nl+nr)/2;
        return query(x*2,nl,mid,l,r) || query(x*2+1,mid+1,nr,l,r);
    }
    
    bool query(int l,int r){
        return query(1,0,size-1,l,r);
    }
} tra,trb;
 
int n,nxa[100005],nxb[100005],jmpa[100005],jmpb[100005];
long long s[100005],a,b,dpa[100005];
 
int nextjmpb(int);
 
int nextjmpa(int x){
    if(x>=n)return x;
    if(jmpa[x]!=-1)return jmpa[x];
    if(nxa[x-1]<=x && nxb[x-2]<=x)return jmpa[x]=x;
    if(nxa[x-1]<=x){
        if(tra.query(x+1,nxb[x-2]-1))return jmpa[x]=-2;
        int i=nxb[x-2];
        if(nxa[i-1]<=i)return jmpa[x]=i;
        return jmpa[x]=nextjmpb(i+1);
    }
    if(nxb[x-2]<=x)return jmpa[x]=nextjmpb(x+1);
    return jmpa[x]=-2; // Not exist
}
 
int nextjmpb(int x){
    if(x>=n)return x;
    if(jmpb[x]!=-1)return jmpb[x];
    if(nxb[x-1]<=x && nxa[x-2]<=x)return jmpb[x]=x;
    if(nxb[x-1]<=x){
        if(trb.query(x+1,nxa[x-2]-1))return jmpb[x]=-2;
        int i=nxa[x-2];
        if(nxb[i-1]<=i)return jmpb[x]=i;
        return jmpb[x]=nextjmpa(i+1);
    }
    if(nxa[x-2]<=x)return jmpb[x]=nextjmpa(x+1);
    return jmpb[x]=-2; // Not exist
}
 
long long dfs(int x){
    if(x<0)return 0;
    if(x>=n)return 1;
    if(dpa[x]!=-1)return dpa[x];
    long long res=0;
    if(nxa[x]<=x+1)res=(res+dfs(x+1))%mod;
    else res=(res+dfs(nextjmpb(x+2)))%mod;
    if(nxb[x]<=x+1)res=(res+dfs(x+1))%mod;
    else res=(res+dfs(nextjmpa(x+2)))%mod;
    return dpa[x]=res;
}
 
int main(){
    memset(jmpa,-1,sizeof jmpa);
    memset(jmpb,-1,sizeof jmpb);
    memset(dpa,-1,sizeof dpa);
    scanf("%d %lld %lld",&n,&a,&b);
    for(int i=0;i<n;i++)scanf("%lld",s+i);
    int pos=0;
    for(int i=0;i<n;i++){
        while(pos<n && s[pos]-s[i]<a)pos++;
        nxa[i]=pos;
        if(i>0 && nxa[i-1]>i)tra.update(i,true);
    }
    pos=0;
    for(int i=0;i<n;i++){
        while(pos<n && s[pos]-s[i]<b)pos++;
        nxb[i]=pos;
        if(i>0 && nxb[i-1]>i)trb.update(i,true);
    }
    printf("%lld\n",dfs(0));
    return 0;
}


Measured memory_bytes: 11648
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int t = (s[0] == s[n-1]);
  if ((t + n) % 2 && n > 2) cout << "First\n";
  else cout << "Second\n";
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}

int main()
{
	int n, d;
	int ans = 0;
	cin >> n >> d;
	vector<vector<int>>x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int norm = 0;
			for (int k = 0; k < d; k++) {
				int diff = abs(x[i][k] - x[j][k]);
				norm += diff * diff;
			}
			bool flag = false;
			for (int k = 0; k <= norm; k++) {
				if (k * k == norm) {
					flag = true;
				}
			}
			if (flag) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

ll ps[60];

ll eat(ll n, ll num, ll x){
    printde(n, num, x);
    if(x <= 0){ return 0; }
    if(n == 0){ return (bool)x; }
    if(x * 2 - 1 == num){
        return ps[n - 1] + 1;
    }else if(x * 2 - 1 > num){
        ll mid = num / 2 + 1;
        return ps[n - 1] + eat(n - 1, num / 2 - 1, x - mid) + 1;
    }else{
        return eat(n - 1, num / 2 - 1, x - 1);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, x;
    cin >> n >> x;
    ll num = 1;
    ps[0] = 1;
    for(int i = 0; i < n; i++){
        ps[i + 1] = ps[i] * 2 + 1;
        num = num * 2 + 3;
    }
    cout << eat(n, num, x) << '\n';
}


Measured memory_bytes: 256
/*input
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[205][205],c[15][15],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,w,ans=0,sum=0,p,x,y;
	cin>>h>>w;
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cin>>c[i][j];
		}
	}
	for(int k=0;k<10;k++)
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(c[i][k]+c[k][j]<c[i][j])
					c[i][j]=c[i][k]+c[k][j];
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			cin>>a[i][j];
			if(a[i][j]!=-1) ans+=c[a[i][j]][1];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A, B; cin >> A >> B; 
	int count[100] = {}; 
	count[0] = 1; 
	count[1] = A; 
	for(int i = 2; i < 80; i++){
		count[i] = count[i-1] + A - 1; 
	}
	int ans = 0; 
	for(int i = 0; i < 80; i++){
		if(count[i] >= B){
			cout << i << endl; break; 
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int digit10(int b){
    int result = 10;
    while(b >= 10){
        b = b / 10;
        result *= 10;
    }
    return result;
}

int main(){

    int a,b;
    cin >> a >> b;

    a = a * digit10(b) + b;

    int round_sqrta = round(sqrt((double)a));
    
    if(round_sqrta * round_sqrta == a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <queue>

using namespace std;

bool compare_F(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

bool compare_S(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main(){
    uint32_t N, M;
    cin >> N >> M;
    vector<pair<uint32_t, uint32_t>> AB(N);

    for(uint32_t i = 0;i<N;++i){
        cin >> AB[i].first >> AB[i].second;
    } 

    uint64_t res = 0;

    sort(AB.begin(),AB.end(),compare_F);

    priority_queue<uint32_t> pay;
    uint32_t current = 0;

    for(uint32_t i = 1;i <= M;++i){
        while(AB[current].first <= i){
            pay.push(AB[current].second);
            ++current;
        }
        if(pay.size() != 0){
            res+= pay.top();
            pay.pop();
        }
    }

    cout << res << endl;

	return 0;
}



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

def solve(N: int, A: "List[int]"):
    jo=[0]*N
    for i in range(N-1):
        jo[A[i]-1]+=1
    for i in range(N):
        print(jo[i])

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 2 + 1)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 34384
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		long p=s[0]%s[1];
		Console.WriteLine("{0}",Min(p,Abs(p-s[1])));
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#include"bits/stdc++.h"
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

#define pii pair<int,int>
#define ff first
#define ss second
#define endll '\n'

using ll = long long int;

int main()
{
    string s;cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}




Measured memory_bytes: 3612