akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	int n;
	scanf("%d", &n);
	ll ans[4] = {0};
	ll tmp[4] = {0};
	int c[4];

	while (n--) {
		for (int i = 0; i < 3; i++) {
			scanf("%d", &c[i]);
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i != j) {
					tmp[j] = max(tmp[j], ans[i] + c[j]);
				}
			}
		}
		for (int i = 0; i < 3; i++) ans[i] = tmp[i];

	}
	ll final = max({ans[0], ans[1], ans[2]});
	printf("%lld\n", final);

	return 0;
}


Measured memory_bytes: 256
h,w,k = gets.chomp.split(" ").map(&:to_i)
m = []
h.times do |i|
  tmp = []
  tmp = gets.chomp.split("")
  m << tmp
end

#p m[0][1]

bi = 0
bj = 0
bh = Array.new(h,0)
bw = Array.new(w,0)
ball = 0
m.each do |es|
  bj = 0
  es.each do |e|
    if e == "#"
      bh[bi] += 1
      bw[bj] += 1
      ball += 1
    end
    bj += 1
  end
  bi += 1
end

#p bh
#p bw
#p ball

ans = 0

(0..h).each do |i|
  if i == 0
    (0..w).each do |j|
      if j == 0
        if ball == k
          ans += 1
        end
      else
        (1..w).to_a.combination(j).each do |fs|
          tmp = ball
          fs.each do |f|
            tmp -= bw[f-1]
          end
          #p "H "+tmp.to_s
          if tmp == k
            ans += 1
          end
        end
      end
    end
  else
    (1..h).to_a.combination(i).each do |es|
      (0..w).each do |j|
        if j == 0
          tmp = ball
          es.each do |e|
            tmp -= bh[e-1]
          end
          if tmp == k
            ans += 1
          end
          #p "W "+tmp.to_s
        else
          (1..w).to_a.combination(j).each do |fs|
            tmp = ball
            es.each do |e|
              w.times do |ii|
                if m[e-1][ii] == "#"
                  tmp -= 1
                end
              end
            end
            fs.each do |f|
              h.times do |jj|
                if m[jj][f-1] == "#"
                  tmp -= 1
                end
              end
            end
            es.each do |e|
              fs.each do |f|
                if m[e-1][f-1] == "#"
                  tmp += 1
                end
              end
            end
            if tmp == k
              ans += 1
            end
            #p tmp
          end
        end
      end
    end
  end
end

p ans

Measured memory_bytes: 14328
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

import sys

K, T = map(int, input().split())
a = sorted(list(map(int, input().split())))

if T == 1:
    print(a[-1]-1)
    sys.exit()
maxc = a[-1] - sum(a[:-1]) - 1
print(max(maxc, 0))


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int W,H; cin >> W >> H;
    vector<int> p(W),q(H);
    vector<Pi> v;
    rep(i,W) cin >> p[i],v.push_back(Pi(p[i],0));
    rep(i,H) cin >> q[i],v.push_back(Pi(q[i],1));
    sort(v.begin(),v.end());
    int cnt0 = 0,cnt1 = 0;
    ll ans = 0;
    rep(i,W+H){
        if(v[i].second == 0){
            ans += (ll)v[i].first*(H+1-cnt1);
            cnt0++;
        }
        else{
            ans += (ll)v[i].first*(W+1-cnt0);
            cnt1++;
        }
    }
    cout << ans << endl;

}

    



Measured memory_bytes: 3316
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

def func():
    N = input()
    S = raw_input()

    S1 = S[:N]
    S2 = S[N:]

    m = {}

    for i in range((1 << N)):
        s1 = s2 = ''
        for j in range(N):
            if(i & (1 << j)):
                s1 = s1 + S1[j]
            else:
                s2 = S1[j] + s2
        if (s1, s2) in m:
            m[(s1, s2)] += 1
        else:
            m[(s1, s2)] = 1

    ans = 0

    for i in range((1 << N)):
        s1 = s2 = ''
        for j in range(N):
            if(i & (1 << j)):
                s1 = S2[j] + s1
            else:
                s2 = s2 + S2[j]
        if (s1, s2) in m:
            ans += m[(s1, s2)]

    print ans

func()

Measured memory_bytes: 67608
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>

using ll = long long;

using namespace std;

int main() {
    string s;
    int q, rev = 0;
    cin >> s >> q;
    deque<char> dq(s.begin(), s.end());
    for (int i=0; i<q; i++) {
        int t; cin >> t;
        if (t == 1) rev ^= 1;
        else {
            int f; char c;
            cin >> f >> c;
            if (rev == f-1) dq.push_front(c);
            else dq.push_back(c);
        }
    }
    cout << (rev ? string(dq.rbegin(), dq.rend()) : string(dq.begin(), dq.end())) << '\n';
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int H,N;
  cin >> H >> N;
  vector<int> A(N),B(N);
  int i,j,k;
  for(i=0;i<N;i++)cin >> A[i] >> B[i];
  vector<vector<int>> dp(N,vector<int>(H+1,2000000000));
  dp[0][0] = 0;
  for(i=0;i<N;i++) {
    for(j=0;j<=H;j++) {
      dp[i][min(H,j+A[i])] = min(dp[i][min(H,j+A[i])],dp[i][j]+B[i]);
      dp[min(i+1,N-1)][j] = min(dp[min(i+1,N-1)][j],dp[i][j]);
    }
  }
  cout << dp[N-1][H] << endl;
}

Measured memory_bytes: 39424
n,a,b = map(int,input().split())

x = [str(i) for i in range(1,n+1)]

ans = 0
for str_num in x:
    num = 0
    for j in range(len(str_num)):
        num += int(str_num[j])
    if (a <= num and num <= b):
        ans += int(str_num)

print(ans)


Measured memory_bytes: 3572
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


n, p = map(int, read().split())
ans = 1
for k, v in Counter(prime_decomposition(p)).items():
    v //= n
    ans *= k ** v
print(ans)


Measured memory_bytes: 3316
import collections
s = input()
ls = len(s)
if ls ==2 and s[0]!=s[1]:
    print(-1,-1)
    exit()
elif ls ==2 and s[0]==s[1]:
    print(1,2)
    exit()
for i in range(2,ls):
    tmp = collections.Counter(s[i-2:i+1])
    if len(tmp.keys())<=2:
        print(i-1,i+1)
        exit()
print(-1,-1)


Measured memory_bytes: 9524
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>

#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define EPS 1e-10
#define ll long long
using namespace std;
typedef struct E{
  ll to;
  double cost;
}edge;
const int MAX_V=1100;
const double Inf=1e19;
vector<vector<edge> >E(MAX_V);
double d[MAX_V];
void dijkstra(int s){
  priority_queue<pair<double,ll>,vector<pair<double,ll> >,greater<pair<double,ll> > >que;
  fill_n(d,MAX_V,Inf);
  d[s] = 0.0;
  que.push(pair<double,ll>(0.0,s));
  while(!que.empty()){
    pair<double,ll> p=que.top();que.pop();
    ll v = p.second;
    if(d[v]<p.first)continue;
    for(int j=0;j<E[v].size();j++){
      edge t = E[v][j];
      if(d[t.to]>d[v]+t.cost){
	d[t.to]=d[v]+t.cost;
	que.push(pair<double,ll>(d[t.to],t.to));
      }
    }
  }
}
int main(){
  ll xs,ys,xt,yt;
  int n;
  cin>>xs>>ys>>xt>>yt;
  cin>>n;
  vector<pair<pair<ll,ll> ,ll> >p(n);
  for(int i=0;i<n;i++){
    ll x,y,r;cin>>x>>y>>r;
    edge e;
    double kk,kk2;
    if(sqrt((ll)(xs-x)*(xs-x)+(ll)(ys-y)*(ys-y))-(ll)r<0)kk=0;
    else kk=sqrt((ll)(xs-x)*(xs-x)+(ll)(ys-y)*(ys-y))-(ll)r;
    e.to=i;e.cost=kk;
    E[n].pb(e);
    e.to=n;
    E[i].pb(e);
    if(sqrt((ll)(xt-x)*(xt-x)+(ll)(yt-y)*(yt-y))-(ll)r<0)kk2=0;
    else kk2=sqrt((ll)(xt-x)*(xt-x)+(ll)(yt-y)*(yt-y))-(ll)r;
    e.to=i;e.cost=kk2;
    E[n+1].pb(e);
    e.to=n+1;
    E[i].pb(e);
    p[i]=mp(mp(x,y),r);
  }
  edge eee;
  eee.to=n;eee.cost=Inf;
  E[n].pb(eee);
  eee.to=n+1;
  E[n+1].pb(eee);
  eee.to=n;
  eee.cost=sqrt((ll)(xs-xt)*(xs-xt)+(ys-yt)*(ys-yt));
  E[n+1].pb(eee);
  eee.to=n+1;
  E[n].pb(eee);
  for(int i=0;i<n;i++){
    edge ee;ee.to=i;ee.cost=Inf;
    E[i].pb(ee);
    for(int j=i+1;j<n;j++){
      double kyori;
      if(sqrt((ll)(p[i].F.F-p[j].F.F)*(p[i].F.F-p[j].F.F)+(ll)(p[i].F.S-p[j].F.S)*(p[i].F.S-p[j].F.S))-(ll)p[i].S-(ll)p[j].S<0)
	kyori=0.0;
      else
	kyori=sqrt((ll)(p[i].F.F-p[j].F.F)*(p[i].F.F-p[j].F.F)+(ll)(p[i].F.S-p[j].F.S)*(p[i].F.S-p[j].F.S))-(ll)p[i].S-(ll)p[j].S;
      edge e;e.to=j;e.cost=kyori;
      E[i].pb(e);
      e.to=i;
      E[j].pb(e);
    }
  }
  dijkstra(n);
  printf("%.10f\n",d[n+1]);
  return 0;
}


Measured memory_bytes: 22148
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    String st;
    int n, score, run, count;
    int i;

    n = sc.nextInt();
    for(i = 0;i < n;i++){
      score = 0; run = 0; count = 0;
      for(;;){
        st = sc.next();
        if("HIT".equals(st)){
          ++run;
          if(run == 4){
            run = 3; score++;
          }
        }else if("OUT".equals(st)){
          if(++count == 3)break;
        }else{
          score += run + 1; run = 0;
        }
      }
      out.println(score);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> H(N+K,pow(10,9));
  for (int i=0;i<N;i++){
    cin >> H.at(i+K);
  }
  vector<int> DP(N+K,0);
  for (int i=1;i<N;i++){
    vector<int> kouho(K,0);
    for (int j=0;j<K;j++){
      kouho.at(j)=DP.at(K+i-j-1)+abs(H.at(K+i)-H.at(i+K-j-1));
    }
    DP.at(i+K)=*min_element(kouho.begin(),kouho.end());
  }
  cout << DP.at(N+K-1) << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define mod 1000000007
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
        // freopen("input.txt", "r", stdin); (input from the file)
	// freopen("output.txt", "w", stdout);   
	cin.tie(0);
	cout.tie(0);
        string s,t;
        cin>>s>>t;
        int n=s.size();
        int m=t.size();
        if(m!=(n+1))
        {
        	cout<<"No";
        }
        else
       {   int f=1;
        
        for(int i=0;i<s.size();i++)
        {
        	if(s[i]!=t[i])
        	{
        		f=0;
        		break;
        	}
        }
        if(f==0)
        cout<<"No"<<"\n";
        else
        cout<<"Yes"<<"\n";
       } 
return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
    int W,a,b;
    int ans;
    scanf("%d %d %d",&W, &a, &b);
    if((a <= b && b <= (a + W)) || (a <= (b + W) && (b + W) <= 6)) ans = 0;
    else if(b > (a + W)){
        ans = b - (a + W);
    }else{
        ans = a - (b + W);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
a=0

for i in range(1,n+1):
  j=2
  t=1
  x=i
  while j*j<i:
    f=0
    while x%j==0:
      x //= j
      f+=1
    if f != 0:
      t *= f+1
    j+=1
  if x==i:
    t *= 2
  if t==8 and i%2:
    a += 1
print(a)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc100/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

ll n, m;
ll ans = 0;
ll buf;
vector<ll> tmp;
vector<vector<ll>> v;

void func(){
    buf = 0;
    sort(tmp.begin(), tmp.end(), greater<ll>());
    rep(i, m){
        buf += tmp[i];
    }
    if(ans < buf) ans = buf;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    v.resize(n, vector<ll>(3));
    rep(i, n){
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    tmp.resize(n);

    rep(i, n){
        tmp[i] = v[i][0] + v[i][1] + v[i][2];
    }
    func();
    rep(i, n){
        tmp[i] = v[i][0] + v[i][1] - v[i][2];
    }
    func();
        rep(i, n){
        tmp[i] = v[i][0] - v[i][1] + v[i][2];
    }
    func();
    rep(i, n){
        tmp[i] = v[i][0] - v[i][1] - v[i][2];
    }
    func();
    rep(i, n){
        tmp[i] = -v[i][0] + v[i][1] + v[i][2];
    }
    func();
    rep(i, n){
        tmp[i] = -v[i][0] + v[i][1] - v[i][2];
    }
    func();
    rep(i, n){
        tmp[i] = -v[i][0] - v[i][1] + v[i][2];
    }
    func();
    rep(i, n){
        tmp[i] = -v[i][0] - v[i][1] - v[i][2];
    }
    func();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 892
fn main() {
    use std::collections::BTreeMap;
    let mut m: BTreeMap<String, i64> = BTreeMap::new();
    let n: i64 = read();
    let mut max: i64 = 0;
    for _ in 0i64..n {
        let s: String = read();
        let current = match m.get(&s) {
            Some(cnt) => *cnt,
            None => 0,
        };
        let added = current + 1;
        m.insert(s, added);
        if max < added {
            max = added;
        }
    }
    use std::iter::FromIterator;
    let mut vs = Vec::from_iter(&m);
    vs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
    for (s, n) in vs {
        if *n == max {
            println!("{}", s);
        }
    }
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 26492
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        Input input = InputParser.perse(sn, 1);
        sn.close();

        Integer a = input.getInt(1, 1);
        Integer b = input.getInt(1, 2);

        Integer min = Math.min(a, b);
        Integer max = Math.max(a, b);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i< max; i++) {
            sb.append(min);
        }
        System.out.println(sb);
    }

    private static class InputParser {
        static Input perse(Scanner sn, int line) {
            Input result = new Input();
            while (line-- > 0) {
                String[] args = sn.nextLine().split(" ");
                result.addAll(args);
            }
            return result;
        }
    }

    private static class Input {
        private Map<Integer, Map<Integer, String>> inputs;
        private int now = 1;
        private int innerNext = 1;

        Input() {
            inputs = new HashMap<>();
            inputs.put(now, new HashMap<>());
        }

        void addAll(String[] args) {
            for (String str : args) {
                add(str);
            }
            next();
        }

        void add(String str) {
            inputs.get(now).put(innerNext++, str);
        }

        void next() {
            inputs.put(++now, new HashMap<>());
            innerNext = 1;
        }

        String getString(int i, int j) {
            return inputs.get(i).get(j);
        }

        int getInt(int i, int j) {
            return Integer.parseInt(getString(i, j));
        }

        double getDouble(int i, int j) {
            return Double.parseDouble(getString(i, j));
        }

        List<Integer> getIntLine(int i) {
            return inputs.get(i).entrySet().stream().map(e -> Integer.parseInt(e.getValue()))
                    .collect(Collectors.toList());
        }

        List<Integer> getIntVerticalLine(int line, int start, int size) {
            List<Integer> list = new ArrayList<>();
            for(int i = start; i < start + size; i++) {
                list.add(getInt(i, line));
            }
            return list;
        }
    }
}


Measured memory_bytes: 21076
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<String, Integer> blue = new HashMap<>();
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			if (blue.containsKey(s)) {
				blue.replace(s, blue.get(s) + 1);
			} else {
				blue.put(s, 1);
			}
		}

		int m = sc.nextInt();
		Map<String, Integer> red = new HashMap<>();
		for (int i = 0; i < m; i++) {
			String s = sc.next();
			if (red.containsKey(s)) {
				red.replace(s, red.get(s) + 1);
			} else {
				red.put(s, 1);
			}
		}

		int max = 0;
		for (Map.Entry<String, Integer> entry : blue.entrySet()) {
			int i = 0;
			if (red.containsKey(entry.getKey()))  {
				i = red.get(entry.getKey());
			}
			if (entry.getValue() > i) {
				max = Math.max(max, entry.getValue() - i);
			}
		}

		System.out.println(max);


		sc.close();

	}

}


Measured memory_bytes: 35628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * YAML
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		Main main = new Main();

		StringTokenizer query = new StringTokenizer(br.readLine(), ".");
		List<String> yaml = new ArrayList<>();
		Obj[] objs = new Obj[50_000];

		//read
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			yaml.add(line);
		}

		//parse
		for (int i = 0; i < yaml.size(); i++) {
			String line1 = yaml.get(i);

			//parent
			int n = 0;
			for (int j = 0; j < line1.length(); j++) {
				if (line1.charAt(j) == ' ') n++;
				else break;
			}
			if (objs[n] == null) {
				objs[n] = main.new Obj();
			}

			//prop
			words = line1.substring(n).split(":");
			if (words.length == 1) {
				//prop: object
				String line2 = yaml.get(i + 1);
				//self
				int m = 0;
				for (int j = 0; j < line2.length(); j++) {
					if (line2.charAt(j) == ' ') m++;
					else break;
				}
				if (objs[m] == null) {
					objs[m] = main.new Obj();
				}
				String key = words[0];
				objs[n].props.put(key, main.new Prop<Obj>(objs[m]));
			} else {
				//prop: string
				String key = words[0];
				String string = words[1].substring(1);
				objs[n].props.put(key, main.new Prop<String>(string));
			}
		}

		Obj obj = objs[0];
		Prop prop = null;
		while (query.hasMoreTokens()) {
			if ((prop = obj.get(query.nextToken())) != null) {
				if (prop.value instanceof Obj) {
					obj = (Obj) prop.value;
				} else {
					if (query.hasMoreTokens()) {
						prop = null;
						break;
					}
				}
			}
		}

		String ans = "";
		if (prop == null) {
			ans = "no such property";
		} else if (prop.value instanceof String) {
			ans = "string \"" + prop.value + "\"";
		} else if (prop.value instanceof Obj) {
			ans = "object";
		}
		System.out.println(ans);

	} //end main


	class Obj {
		Map<String, Prop> props;

		Obj() {
			props = new HashMap<>();
		}

		Prop get(String key) {
			return props.get(key);
		}
	}

	class Prop<T> {
		T value;

		Prop(T value) {
			this.value = value;
		}
	}
}

Measured memory_bytes: 26040
#include <stdio.h>

int main(){
	int n;
	int a[10000];
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
	}
	for(int j = n;j >= 1;j--){
		if(j == 1){
			printf("%d",a[j]);
			printf("%s","\n");
		}else{
			printf("%d ",a[j]);
		}
		/*printf("%c"," ");**/
	}
	return 0;
}
/*mohankaitou
5
1 2 3 4 5

5 4 3 2 1

8
3 3 4 4 5 8 7 9

9 7 8 5 4 4 3 3


10
838 758 113 515 51 627 10 419 212 86

86 212 419 10 627 51 515 113 758 838
*/


Measured memory_bytes: 2624
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

int main(){
	int a[5], r[5], ans=0;
	for(int i=0; i<5; i++){
		cin >> a[i];
		if(a[i]%10==0) r[i]=0;
		else r[i]=10-a[i]%10;
		ans+=a[i];
	}
	sort(r, r+5);
	ans+=r[0]+r[1]+r[2]+r[3];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

vector<lint> biedge[100050]; // MAX_V
lint V;
lint bicolor[100050]; // MAX_V

bool bidfs(lint v,lint c){
    bicolor[v]=c;
    rep(i,biedge[v].size()){
        if(bicolor[biedge[v][i]]==c) return false;
        if(bicolor[biedge[v][i]]==0 && !bidfs(biedge[v][i],-c)) return false;
    }
    return true;
}

bool bicheck(int n){
    V=n;
    rep(i,V) if(bicolor[i]==0) if(!bidfs(i,1)) return false;
    return true;
}


lint d[300][300]; // MAX_V
void warshallfloyd(int v){
  rep(i,v) rep(j,v) rep(k,v) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
  return;
}

int main(void){
    int N;
    cin >> N;
    string S[N];
    rep(i,N) cin >> S[i];
    rep(i,N) rep(j,N){
        if(S[i][j]=='1') biedge[i].push_back(j),d[i][j]=1;
        else d[i][j]=INF;
        if(i==j) d[i][j]=0;
    }
    bool che=bicheck(N);
    if(!che) cout << -1 << endl;
    else{
        warshallfloyd(N);
        lint ans=0;
        rep(i,N) rep(j,N){
            ans=max(ans,d[i][j]+1);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end());
    cout << v[N / 2] - v[N / 2 - 1] << endl;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
flag=[0]*n
wa=0
ac=0

for i in range(m):
  p,s = input().split()
  p=int(p)-1
  #print(ac,wa,flag)
  if flag[p]!='AC':
    if s=='WA':
      #wa+=1
      flag[p]+=1
    else:
      ac+=1
      wa+=flag[p] #ACになったときにwaを加算する
      flag[p]='AC'
print(ac, wa)

Measured memory_bytes: 3828
#include <stdio.h>

int main (void){
    int count=0;
    int i;
    int memory[100000];
    while(1){
        scanf("%d",&memory[count]);
        if(memory[count]==0){
            break;
        }
        else{
            count++;
        }
    }

    for(i=0;i<count;i++){
        printf("Case %d: %d\n",i+1,memory[i]);
    }
    return 0;
}


Measured memory_bytes: 2088
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '(L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int n,k,d;

int main(){
 
    cin >>n;
    cin>>k;
    int sum=0;
    REP(i,n){
        cin>>d;
        sum+=2*min(d,k-d);
    }

    cout<<sum<<endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <utility>
using namespace std;

pair<int, int> make_pair(int x, int y){
	pair<int, int> tmp;
	tmp.first = x;
	tmp.second = y;
	return tmp;
}

int main(){
	int N;
	cin >> N;
	vector<long> A(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int left = A[N-1], right = A[0];
	vector<pair<int, int>> ans(N-1);
	for(int i=1;i<N-1;i++){
		if(A[i] < 0){
			ans[i-1] = make_pair(left, A[i]);
			left -= A[i];
		}
		else{
			ans[i-1] = make_pair(right, A[i]);
			right -= A[i];
		}
	}
	ans[N-2] = make_pair(left, right);
	cout << left - right << endl;
	for(int i=0;i<N-1;i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

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

int GCD(int a, int b) {
   if (b == 0) return a;
   return GCD(b, a%b);
}


int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int>left(n+1,0);
    vector<int>right(n+1,0);
    int max=0;
    int min=0;
    
    for(int i=0;i<n;i++) left[i+1]=GCD(left[i],a[i]);
    for(int i=n-1;i>=0;i--) right[i]=GCD(right[i+1],a[i]);
    
    for (int i=0;i<n;i++) if(GCD(left[i],right[i+1])>min) min=GCD(left[i],right[i+1]);
    
    cout<<min<<endl;
}



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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "yes"
#define FALSE__ "no"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#define INF 1e9

int a[100000];
bool ch[100000];
int cnt;

int main()
{
	int N;
	cin >> N;
	rep(i, N) {
		cin >> a[i];
		a[i]--;
	}
	int pos = 0;	
	while (!ch[pos]) {
		if (pos == 1) {
			cout << cnt << endl;
			return 0;
		}
		ch[pos] = true;
		pos = a[pos];
		cnt++;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e9;
void read(int &xxxxx){scanf("%d",&xxxxx);}

int main()
{
    int n;double t,a;cin>>n>>t>>a;
    double h[10000];rep(i,0,n) scanf("%lf",&h[i]);
    rep(i,0,n) h[i]=abs(t-h[i]*0.006-a);
    int ans=0;
    rep(i,1,n){
        if(h[i]<h[ans]) ans=i;
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,n) for(h=0;h<n;h++)in(v[h]);
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define cf(n) printf("%I64d\n",n)
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,n) for(h=0;h<n;h++)pr(v[h]); lin
#define ck printf("continue\n")
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define N 1005
typedef long long int ll;
int main()
{
    int a,n;
    in(n);
    a=n%100;
    n/=100;
    if(a<13 & n<13 & a>0 & n>0)
        cout << "AMBIGUOUS";
    else if(a<13 & a>0)
        cout << "YYMM";
    else if(n<13 & n>0)
        cout << "MMYY";
    else
        cout << "NA";
    lin;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_X = 200;

int main(void){
    int a[2],K,X[MAX_X];
    for(int i = 0; i<2; i++){
        cin >> a[i];
    }
    K = a[1];
    int MIN,MAX;
    MIN = K - a[0] + 1;
    MAX = K + a[0] - 1;
    X[0] = MIN;

    for(int j = 0; j < (MAX - MIN + 1); j++){
        if (j) cout << " ";
        X[j] = MIN + j;
        cout << X[j] ;
    }
    cout << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

#include<deque>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

ll N, M;
ll D = 1e9+7;

ll factorial(ll n) {
    if (n == 1) return 1;
    return (factorial(n-1) * n) % D;
} 

int main() {
    cin >> N >> M;
    if (M < N) swap(N,M);
    //N <= M
    if (M - N > 1) {
        cout << 0 << endl;
    } else if (M - N == 1){
        cout << factorial(N) * factorial(M) % D << endl;
    } else {
        cout << 2 * factorial(N) * factorial(M) % D << endl;
    }

}

Measured memory_bytes: 1792
#if 0
????????£????????????1.5h
??¢?????????????????§??????????????¢??°????????£????????????sum????¨??????¨????????????????????£????????§?????????
???????????¢??????????????§????????????????????????????????????"-1"???????????????????????????????????§?°???????????????????
#endif

#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int P[10000+10];

void init(int N){
	for(int i=0;i<=N;++i) P[i]=i;
}
int root(int a){
	if(P[a]==a)return a;
	else return(P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
	return root(a)==root(b);
}
void unite(int a,int b){
	P[root(a)]=root(b);
}
int main(){
	int N;
	cin>>N;
	int A[N][N];
	
	for(int i=0; i<N;i++){
		for(int j=0;j<N;j++){
			cin>>A[j][i]; //???????????\???
		}
	}

	int M = 0; 
	int cost[N*N],src[N*N],dst[N*N];
	for (int r=0; r<N;r++)
		for (int c=0; c<r;c++) //r<c???????§?????????????
			if (A[r][c] > -1) {
				cost[M] = A[r][c];
				src[M] = r;
				dst[M] = c;
				M += 1;
			}
	pair<int,int> edges[100000+10];
	for(int i=0;i<M;i++)
		edges[i]=make_pair(cost[i],i); //first???????????????second???ID
	sort(edges,edges+M);
	
	//for(int i=0;i<M;++i)
		//cout<<edges[i].first<<endl;

	init(N);
	int sum=0;
	for(int i=0;i<M;i++){
		if(is_same_set(src[edges[i].second],dst[edges[i].second])==false){
			unite(src[edges[i].second],dst[edges[i].second]);
			sum+=edges[i].first;
		}
	}
		cout<<sum<<endl;
}

Measured memory_bytes: 3888
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll S;
    cin >> S;
    ll X1 = 0, Y1 = 0;
    ll X2 = 1000000000, Y2 = 1;
    ll Y3 = (S + 999999999) / 1000000000, X3 = 1000000000 * Y3 - S;
    cout << X1 << ' ' << Y1 << ' ' << X2 << ' ' << Y2 << ' ' << X3 << ' ' << Y3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   
    ll n;
    cin >> n;
    vector <ll> v;
    for (ll i=0;i<n;i++){
        ll d;
        cin >> d;
        v.push_back(d);
    }
    sort(v.begin(), v.end());
    cout << v[n/2] - v[n/2-1] << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define Joe ios::sync_with_stdio(0); cin.tie(NULL); ios_base::sync_with_stdio(0); cout.tie(NULL);//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define INF 1e9+7
const long long N =1e5+5;
using namespace std;
int height[100500];
long long dp[100500];;
int n,k;
long long solve(int ind){

	if(dp[ind]!=INF)
		return dp[ind];
	for(int i=1;i<=k;i++){
		if(ind-i<0) break;
		solve(ind-i);
		dp[ind]=min(dp[ind],abs(height[ind]-height[ind-i])+dp[ind-i]);
	}
	return dp[n-1];
}
int main(){
	Joe
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>height[i];
		dp[i]=INF;
	}
	dp[0]=0;
	cout<<solve(n-1)<<endl;
	return 0;
}


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

int main()
{
    string w;
    cin >> w;

    for(char c='a'; c<='z'; c++){
        int cnt = 0;
        rep(i, w.length()){
            if(w[i] == c) cnt++;
        }
        if(cnt%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{ 
   string s,d;
   cin>>s>>d;
   int count=0;
   for(int i=0;i<s.length();i++){
       if(s[i]!=d[i]){
           count++;
       }
   }
   cout<<count;
    return 0; 
}

Measured memory_bytes: 3788
A,B = map(int,input().split())

#8% -> A円, 10% -> B円 の追加


n_max_fromA = 100*(A+1) // 8
n_min_fromA = 100*A // 8

n_max_fromB = 100*(B+1) // 10
n_min_fromB = 100*B // 10

ans_min = max(n_min_fromA, n_min_fromB)
ans_max = min(n_max_fromA, n_max_fromB)

ans_tmp = ans_min
ans = -1
while ans_tmp <= ans_max:
    tax_8 = int(ans_tmp*0.08)
    tax_10 = int(ans_tmp*0.1)

    if tax_8 == A and tax_10 == B:
        ans = ans_tmp
        break

    ans_tmp += 1

print(ans)


Measured memory_bytes: 3060
def main():
    N = int(input())
    book = [input().split() for i in range(N)]
    for i, j in enumerate(book):
        j[1] = int(j[1])
        j.append(i + 1)

    book.sort(key=lambda x: x[1], reverse=True)
    book.sort(key=lambda x: x[0])

    for i in book:
        print(i[2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, H);
    IN(ll, N);
    A2IN(ll, A, ll, B, N);
    vi dp(H + 1, INF);
    dp[0] = 0;
    REP(i, N)
    {
        REP1(j, H)
        {
            CH(min, dp[j], dp[max(0LL, j - A[i])] + B[i]);
        }
    }
    OUT(dp[H]);
}

Measured memory_bytes: 384
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 51;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;

vector<vector<ll>>dp(max_n, vector<ll>(max_n, 0));
vector<ll> a(max_n);
vector<ll> b(max_n);
vector<ll> c(max_n);
vector<ll> d(max_n);
ll N, M, Q;

ll dfs(ll v, vector<ll> &array){
    ll score = 0;
    if(array.size()==N){
        rep(i, Q){
            if(array[b[i]] - array[a[i]] == c[i]){
                score += d[i];
            }
        }
    }else{
        for(ll i=v;i<=M;i++){
            array.push_back(i);
            score = max(score, dfs(i, array));
            array.pop_back();
        }
    }
    return score;
}


void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll x;
    sll(N);
    sll(M);
    sll(Q);
    rep(i, Q){
        sll(x);
        x --;
        a[i] = x;
        sll(x);
        x --;
        b[i] = x;
        sll(x);
        c[i] = x;
        sll(x);
        d[i] = x;
    }


    vector<ll> s;
    ll ans = dfs(1, s);

    printf("%lld\n", ans);


    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 3256
function floor_sum(n, m, a, b)
  ans = 0
  if a >= m
    ans += (n - 1) * n * (a ÷ m) ÷ 2
    a %= m
  end
  if b >= m
    ans += n * (b ÷ m)
    b %= m
  end
  y_max = (a * n + b) ÷ m
  x_max = (y_max * m - b)
  if y_max == 0; return ans; end
  ans += (n - (x_max + a - 1) ÷ a) * y_max
  ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
  return ans
end
for i=1:parse(Int,readline())
  println(floor_sum(parse.(Int,split(readline()))...))
end

Measured memory_bytes: 205352
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

A, B, T = MAP()

t = 0
ans = 0


while t + A < T+0.5 :
	ans += B
	t += A

print(ans)

Measured memory_bytes: 13596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll dx[4] = {1, 0, -1, 0};
    ll dy[4] = {0, 1, 0, -1};
    ll H, W;
    string fi[110];
    ll dist[110][110];

    cin >> H >> W;
    ll wnum = 0;
    rep(i, 0, H) {
        cin >> fi[i];
        rep(j, 0, W) if (fi[i][j] == '.') wnum++;
    }

    memset(dist, -1, sizeof(dist));
    dist[0][0] = 1;
    queue<pair<ll, ll>> que;
    que.push(pair<ll,ll>(0, 0));
    while(!que.empty()) {
        auto cur = que.front();
        que.pop();
        ll x = cur.first, y = cur.second;
        rep(dir, 0, 4) {
            ll nx = x + dx[dir];
            ll ny = y + dy[dir];
            if(nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
            if(fi[nx][ny] == '#') continue;
            if(dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push(pair<ll, ll>(nx, ny));
            }
        }
    }
    if (dist[H-1][W-1] == -1) cout << -1 << endl;
    else cout << wnum - dist[H-1][W-1] << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	VI h, w;
	while (true) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		h.PB(x); w.PB(y);
	}
	rep(i, SZ(h)) {
		int x = h[i], y = w[i];

		rep(j, x) {
			rep(k, y) {
				if (j == 0 || k == 0 || j == x - 1 || k == y - 1)cout << "#";
				else cout << ".";
			}
			puts("");
		}
		puts("");
	}
}


Measured memory_bytes: 3120
#include <algorithm>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define cerr                                                                   \
  if (false)                                                                   \
  cerr

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

ull mod = 1000000007;
ull list[100100];

void solve(long long N, vector<long long> A) {
  map<int, ull> m;
  REP(i, N) { list[A[i]]++; }

  ull ans = 1;
  for (int i = N % 2 == 0; i <= N - 1; i += 2) {
    ull x = list[i] == 2 ? list[i] : 0;
    if (i == 0) {
      ans *= list[i];
    } else {
      ans *= list[i] == 2 ? list[i] : 0;
    }
    ans %= mod;
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  solve(N, A);
  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main()
{  int a,b,c,x;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b){
    x=a;
  a=b;
  b=x;}
  if(b>c){
    x=b;
  b=c;
  c=x;}
  if(a>b){
    x=a;
  a=b;
  b=x;}
  printf("%d %d %d\n",a,b,c);
  return 0;
}

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


public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i]=sc.nextInt();
        }
        long sum = 0;
        int count = 0;
        Arrays.sort(a);
        n=n-1;/*最初に配置する分*/
        sum = a[n];
        n=n-1;
        int cn=n;

        for(int i=0;i<cn;i++){
            sum+=a[n];
            count++;
            if(count==2){
                n--;
                count=0;
            } 
        }
        System.out.println(sum);
    }
}

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

using namespace std;

int arr[100005];
int main() {
    int n,k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    sort(arr+1,arr+n+1);
    int mx = INT_MAX;
    int i = 1;
    int j = i + k - 1;

    while (i <= n && j <= n) {
        if (mx > (arr[j] - arr[i])) {
            mx = arr[j] - arr[i];
        }
        i++;
        j++;
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 640
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	x := nextInt()
	s := make([]int, n)

	count := 1
	idx := 0
	for i := range s {
		s[i] = nextInt()
		idx += s[i]
		if idx <= x {
			count++
		} else {
			break
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", count)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640