akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

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

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

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    LL N;
    cin >> N;
    int s = 0;
    while (N != 0) {
        s += N % 10;
        N /= 10;
    }
    if (s == 1) s = 10;
    cout << s << "\n";
}


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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  vector<long long> dp(n, 1e18);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= i + k and j < n; ++j) {
      dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n - 1];

  return 0;
}

Measured memory_bytes: 1408
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        k: u64,
    }
    let mut a = 7;
    let mut m = 0;
    for i in 0..2_000_000 {
        m += a;
        m %= k;
        if m == 0 {
            println!("{}", i + 1);
            return;
        }
        a *= 10;
        a %= k;
    }
    println!("-1");
}


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

int main(){
  int N,temp1=0,temp2;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  for(int j=0;j<=vec.at(N-1);j++){
    temp1=0;
    for(int h=0;h<N;h++){
      temp1+=((vec.at(h)-j)*(vec.at(h)-j));
    }
    if(j==0) temp2=temp1;
    if(temp1<=temp2) temp2 = temp1;
  }
  
  cout << temp2 << endl;
  return 0;
}


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

int main()
{
    long long int input,i,move_point;
    cin>>input;
    
    for(i = (int) sqrt((float) input); i>0; i--)
    {
        if(input % i == 0) break;
    }

    move_point = i + input / i - 2;
    cout<<move_point<<endl;
}

Measured memory_bytes: 3636
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() - i - 1;
    }
    Arrays.sort(A);
    int m;
    if(N%2 == 0){
      m = (A[N/2] + A[(N - 1)/2])/2;
    }else{
      m = A[N/2];
    }
    long result = 0;
    for(int i = 0; i < N; i++){
      result += Math.abs(A[i] - m);
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 87424
import sys
import math
import heapq


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())

    D = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(D, (a, b))
    ans = 0
    while M > 0:
        a, b = heapq.heappop(D)
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += M * a
            print(ans)
            exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 80724
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
l = [None]*n
for i in range(n):
    l[i] = input()
from collections import Counter
c = Counter(l)
for k in ("AC", "WA", "TLE", "RE"):
    print("%s x %s" % (k, c[k] if k in c else 0))

Measured memory_bytes: 75720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long l;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int n,m;
    cin>>n>>m;
    if(n == m)cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        long[] gl = new long[n], gr = new long[n];

        gl[0] = a[0]; gr[0] = a[n - 1];
        for (int i = 1; i < n; i++) {
            gl[i] = gcd(gl[i - 1], a[i]);
            gr[i] = gcd(gr[i - 1], a[n - i - 1]);
        }
        debug(gl);
        debug(gr);
        long ans = Math.max(gl[n - 2], gr[n - 2]);
        for (int i = 1; i < n - 1; i++) {
            ans = Math.max(ans, gcd(gl[i - 1], gr[n - i - 2]));
        }
        System.out.println(ans);
    }

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

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 64320
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
set<int> E[101010];
set<int> RE[101010];
int in[101010];
int par[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N-1+M) {
		cin>>x>>y;
		E[x].insert(y);
		RE[y].insert(x);
	}
	
	FOR(i,N) if(RE[i+1].empty()) {
		E[0].insert(i+1);
		RE[i+1].insert(0);
	}
	
	queue<int> Q;
	Q.push(0);
	while(Q.size()) {
		x=Q.front();
		Q.pop();
		FORR(e,E[x]) {
			RE[e].erase(x);
			if(RE[e].empty()) {
				par[e]=x;
				Q.push(e);
			}
		}
	}
	
	for(i=1;i<=N;i++) cout<<par[i]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 20480
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    n %= 10;
    if(n == 3){
        printf("bon");
    } else if(n == 0 || n == 1 || n == 6 || n == 8){
        printf("pon");
    } else {
        printf("hon");
    }
    
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int N;
int A[100000],h[100000];
int main(){
    cin>>N;
    for(int i=1 ; i<=N ; i++){
        cin>>h[i];
    }
    A[2] = abs(h[2]-h[1]);
    for(int i=3 ; i<=N ; i++){
        A[i] = min(A[i-1] + abs(h[i]-h[i-1]), A[i-2] + abs(h[i]-h[i-2]));
    }
    cout<<A[N];
}

Measured memory_bytes: 1024
#include<stdio.h>
#define d_flag 0
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)<(b)?(b):(a))
#define abs(a) max(a,-(a))

int main(){
  int n;
  scanf("%d",&n);
  int i,h[n],dp[n];
  
  scanf("%d%d",&h[0],&h[1]);

  if(d_flag)
    printf("max(%d,%d)=%d,abs(-5)=%d\n",h[0],h[1],max(h[0],h[1]),abs(-5));

  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(i=2;i<n;i++){
    scanf("%d",&h[i]);
    dp[i]=min( dp[i-2]+abs(h[i-2]-h[i]) , dp[i-1]+abs(h[i-1]-h[i]));
  }
  if(d_flag){
    for(i=0;i<n;i++)
      printf(" %d",dp[i]);
    printf("\n");
    printf("dp[0]=h[0]=%d,\ndp[1]=abs(%d-%d)=%d,\n",dp[0],h[0],h[1],dp[1]);
    for(i=2;i<n;i++){
      printf("dp[%d]=min(%d+%d,%d+%d)=min(%d,%d)=%d\n",i,dp[i-2],abs(h[i-2]-h[i]) , dp[i-1],abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]) , dp[i-1]+abs(h[i-1]-h[i]));
    }
  }
  
  printf("%d",dp[n-1]);
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(){
    int n,q,count=0;
    cin>>n;
    int A[n+1];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    cin>>q;
    
    for(int i=0;i<q;i++){
        int key;
        cin>>key;
        A[n]=key;
        for(int j=0;j<n;j++){
            if (A[j]==key){
                count++;
                break;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3100
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
from collections import Counter
dp=[0]*(n+1)
for x in a:
    if x!=1 and dp[x-1]!=0:
        dp[x]=dp[x-1]
    elif x!=1:
        dp[x]=x
    else:
        dp[1]=1

c=Counter(dp)
_, most=c.most_common()[0]

print(n-most)

Measured memory_bytes: 88784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    int N, M;
    cin >> N >> M;
    int min_n = 0, max_n = 100000;
    for(int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        min_n = max(a, min_n);
        max_n = min(b, max_n);
    }
    cout << max(max_n - min_n + 1, 0) << endl;
}

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

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int gx, gy; cin >> gx >> gy;
        int k; cin >> k;
        int vert[16][16] = {0}, hori[16][16] = {0}; //軸の取り方は下に向かってx軸とするのに注意
            for(int j = 0; j < k; j++){
            int a, b, c, d; cin >> a >> b >> c >> d;
            if(a < c) vert[a][b] = 1; //(a, b)から下(x)方向に移動できないので1
            else if(a > c) vert[c][d] = 1; //(c, d)から下方向に動けない
            if(b < d) hori[a][b] = 1; //(a, b)から横(y)方向に移動できないので1
            else if(b > d) hori[c][d] = 1;
        }
        int dp[17][17] = {0};//dp[i][j]は(i, j)に到達可能な経路の数。求めるのはdp[gx][gy]
        dp[0][0] = 1; //(0, 0)はスタート地点なので1にする
        for(int l = 0; l < 16; l++){
            for(int m = 0; m < 16; m++){
                if(hori[l][m] == 0) dp[l][m+1] += dp[l][m]; //左から右に移動可能
                if(vert[l][m] == 0) dp[l+1][m] += dp[l][m]; //上から下に移動可能  
            }
        }
        if(dp[gx][gy] == 0) cout << "Miserable Hokusai!" << endl;
        else cout << dp[gx][gy] << endl;
    }
}


Measured memory_bytes: 2992
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
	int N;
	cin >> N;
	unordered_map <int, bool> uniques;
	int a, count = 0;
	for (int i = 0; i < N; i++) {
		cin >> a;
		
		if (uniques[a] == false) {
			uniques[a] = true;
		} else {
			count += 1;
		}
	}
	
	int result;
	if (count % 2 == 0) {
		result = N - count;
	} else {
		result = N - count - 1;
	}
	
	cout << result;
	
	return 0;
}

Measured memory_bytes: 4388
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=2e2+10;
int n,m,num;
int costl[maxn][maxn],costs[maxn][maxn];
int dp[1005][maxn];
int a[1005];
int main()
{
    while(scanf("%d%d",&n,&m)&&n&&m)
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                if(i==j)
                {
                    costl[i][j]=costs[i][j]=0;
                }
                else
                {
                     costl[i][j]=costs[i][j]=inf/3;
                }
            }
        for(int i=1;i<=m;i++)
        {
            char s[2];
            int x,y,val;
            scanf("%d%d%d%s",&x,&y,&val,s);
            if(s[0]=='L')
            {
                costl[x][y]=costl[y][x]=min(val,costl[x][y]);
            }
            else
            {
                costs[x][y]=costs[y][x]=min(val,costs[x][y]);
            }
        }
        scanf("%d",&num);
        for(int i=1;i<=num;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int k=1;k<=n;k++)
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                {
                    costs[i][j]=min(costs[i][j],costs[i][k]+costs[k][j]);
                    costl[i][j]=min(costl[i][j],costl[i][k]+costl[k][j]);
                }
        memset(dp,0x3f,sizeof(dp));
        dp[1][a[1]]=0;
        for(int i=2;i<=num;i++)
            for(int j=1;j<=n;j++)
            {
                dp[i][j]=min(dp[i][j],dp[i-1][j]+costl[a[i-1]][a[i]]);
                for(int k=1;k<=n;k++)
                {
                    //dp[i][k]=min(dp[i][k],dp[i-1][j]+costl[a[i-1]][j]+costs[j][k]+costl[k][a[i]]);
                    dp[i][j]=min(dp[i][j],dp[i-1][k]+costl[a[i-1]][k]+costs[k][j]+costl[j][a[i]]);
                }
            }
        int ans=inf;
        for(int i=1;i<=n;i++)
        {
            ans=min(ans,dp[num][i]);
        }
        printf("%d\n",ans);
    }
}

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

void solve(string s)
{
    for (size_t i = 0; i < s.length(); i++)
    {
        if (s[i] == '1')
        {
            cout << 9;
        }
        else if (s[i] == '9')
        {
            cout << 1;
        }
        else
        {
            cout << s[i];
        }
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    string s;
    cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 384
from functools import reduce
from decimal import *
from operator import mul

def main():
    h, w = input_list()
    masu = []
    for _ in range(h):
        line = list(input())
        masu.append(line)
    rows = [False] * h
    cols = [False] * w
    for i, m in enumerate(masu):
        for j, v in enumerate(m):
            if v == "#":
                rows[i] = True
                cols[j] = True
    for i, m in enumerate(masu):
        if rows[i] is False:
            continue
        a = ''
        for j, v in enumerate(m):
            if cols[j] is False:
                continue
            a += v
        print(a)

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


Measured memory_bytes: 72724
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    scanner.nextLine();

    ArrayList<Restaurant> restaurants = new ArrayList<Restaurant>();
    for (int i = 1; i <= N; i++) {
      String[] tmp = scanner.nextLine().split(" ");
      String city = tmp[0];
      int score = Integer.parseInt(tmp[1]);
      restaurants.add(new Restaurant(city, score, i));
    }

    restaurants.sort((a, b) -> a.city.compareTo(b.city));

    String prevCity = "";
    ArrayList<Restaurant> sameCityRestaurants = new ArrayList<>();

    for (Restaurant restaurant : restaurants) {
      if (prevCity.equals("")) {
        prevCity = restaurant.city;
        sameCityRestaurants.add(restaurant);
      } else {
        if (restaurant.city.equals(prevCity)) {
          sameCityRestaurants.add(restaurant);
        } else {
          sameCityRestaurants.sort((a, b) -> b.score - a.score);
          for (Restaurant r : sameCityRestaurants) {
            System.out.println(r.index);
          }
          sameCityRestaurants.clear();
          sameCityRestaurants.add(restaurant);
          prevCity = restaurant.city;
        }

      }
    }
    sameCityRestaurants.sort((a, b) -> b.score - a.score);
    for (Restaurant r : sameCityRestaurants) {
      System.out.println(r.index);
    }
  }
}

class Restaurant {
  String city;
  int score;
  int index;

  Restaurant(String city, int score, int index) {
    this.city = city;
    this.score = score;
    this.index = index;
  }
}

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

#define ll long long
const ll N = 998244353;
const ll MAX = 100000000000;

int main()
{
ios_base::sync_with_stdio(false);
string s;
cin>>s;
bool checker = true;
if (s[0]!='A') checker = false;
int n = s.length();
int counter = 0;
for (int i = 2; i<=n-2; i++) if (s[i]=='C') counter++;
if (counter!=1) checker = false;
counter = 0;
for (int i = 0; i<n; i++) if ('a'<=s[i]&&s[i]<='z') counter++;
if (counter!=n-2) checker = false;
if (checker) cout<<"AC";
else cout<<"WA";
}

Measured memory_bytes: 256
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K=map(int,input().split())
div=10**9+7

for i in range(K):
    if N-K<i:
        print(0)
    else:
        print(comb(K-1,i)*comb(N-K+1,i+1)%div)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int dp[n + 1] = {};
    int p;
    REP(i,n){
        cin >> p;
        dp[p] = max(1, dp[p - 1] + 1);
    }
    int mx = 0;
    for(int i = 1; i <= n; i++){
        mx = max(mx, dp[i]);
    }
    cout << n - mx << endl;
    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] times = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
        Arrays.sort(times);
        System.out.println(times[0] + times[1]);
    }
}

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

int main()
{
    ll a,b,c,d,flag=0;
    cin>>a>>b;
    vector<ll>v(a,0);
    set<ll>s;
    pair<ll,ll>p[b];
    for(int i=0; i<b; i++)
    {
        cin>>c>>d;
        p[i].first=c;
        p[i].second=d;
        if(c==1 && d==0 && a>1)
        {
            flag=1;
        }
        if(v[c-1]!=0 && d!=v[c-1])
        {
            flag=1;
        }
        else
        {
            v[c-1]=d;
        }
    }
    sort(p,p+b);
    if(flag==0)
    {
        for(int i=0; i<b-1; i++)
        {
            if(p[i].first==p[i+1].first && p[i].second!=p[i+1].second)
            {
                flag=1;
                break;
            }
        }
    }
    if(v[0]==0 && a>1)
    {
        v[0]=1;
    }
    //cout<<v[0]<<" "<<v[1]<<endl;
    if(flag==1 || (a>1 && v[0]==0))
    {
        cout<<-1<<endl;
    }
    else
    {
        for(int i=0; i<a; i++)
        {
            cout<<v[i];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    c = a + b
    ab.append((a, b, c))
ab = sorted(ab, key=itemgetter(2), reverse=True)
taka = 0
ao = 0
for i in range(n):
    if i % 2 == 0:
        taka += ab[i][0]
    else:
        ao += ab[i][1]
print(taka - ao)

Measured memory_bytes: 22972
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, x) = listOfInt()
    val mm = IntArray(n){nextInt()}

    val xLeft = x - mm.sum()

    println(n + (xLeft / mm.min()!!))
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 38004
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var h, w int
	fmt.Sscan(getNextLine(scanner), &h, &w)
	var costs [10][]int
	for i := 0; i < 10; i++ {
		costs[i] = getIntList(scanner)
	}
	var updated [10]int
	NotFound := -1
	updated[1] = 1
	for {
		index := NotFound
		min := NotFound
		for i := 0; i < 10; i++ {
			if updated[i] == 1 {
				continue
			}
			if min == NotFound || min > costs[i][1] {
				min = costs[i][1]
				index = i
			}
		}
		if index == NotFound {
			break
		}
		updated[index] = 1
		for i := 0; i < 10; i++ {
			cost := costs[i][index] + costs[index][1]
			if costs[i][1] > cost {
				costs[i][1] = cost
			}
		}
	}

	ans := 0
	for hi := 0; hi < h; hi++ {
		nums := getIntList(scanner)
		for wi := 0; wi < w; wi++ {
			if nums[wi] == NotFound {
				continue
			}
			ans += costs[nums[wi]][1]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1792
N, M = map(int,input().split())
C=[0 for _ in range(M)]
count = [0 for _ in range(N)]
for i in range(M):
  p,y = map(int,input().split())
  C[i] = [i, p, y, 0]

C.sort(key = lambda x:x[2])
for i in C:
  count[i[1]-1] +=1
  i[3] = count[i[1]-1]
for i in sorted(C,key = lambda x:x[0]):
  print("{:06d}{:06d}".format(i[1],i[3]))




Measured memory_bytes: 30536
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,k,s = readInts()
MAXV = 10**9
if s == MAXV:
    print(*([s]*k + [1]*(n-k)))
else:
    print(*([s]*k + [MAXV]*(n-k)))


Measured memory_bytes: 11652
#include<stdio.h>
    int main(){
      int a,b;
      scanf("%d %d",&a,&b);
      
      if((a==1 && b==2) || (a==2 && b==1)){
        printf("3");
        return 0;
      }
      else if((a==1 && b==3) || (a==3 && b==1)){
        printf("2");
        return 0;
      }
      else{
        printf("1");
        return 0;
      }
    }

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=205,MAXM=5e4+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
struct Edge{int to,next,w;}edges[MAXM];
int head[MAXN],cur[MAXN],d[MAXN],S,T,cnt;
inline void Init(){memset(head,0,sizeof(head)),cnt=1;}
inline void add(int x,int y,int w){
	edges[++cnt]=(Edge){y,head[x],w},head[x]=cnt;
	edges[++cnt]=(Edge){x,head[y],0},head[y]=cnt;
}
inline bool bfs(){
	queue<int>q;q.push(S),memset(d,0,sizeof(d)),memcpy(cur,head,sizeof(head)),d[S]=1;
	for(int x;!q.empty();q.pop()){
		x=q.front();
		for(int i=head[x],y;i;i=edges[i].next)	
			if(edges[i].w&&!d[y=edges[i].to])d[y]=d[x]+1,q.push(y);
	}return d[T];
}
int dfs(int x,int dist){
	if(x==T||!dist)return dist;int z=0;
	for(int&i=cur[x],y,k;i;i=edges[i].next)if(edges[i].w&&d[y=edges[i].to]==d[x]+1){
		k=dfs(y,min(dist,edges[i].w)),edges[i].w-=k,edges[i^1].w+=k,z+=k,dist-=k;
		if(!dist)break;
	}return z;
}
inline int Dinic(){int ans=0;for(;bfs();)ans+=dfs(S,1e9);return ans;}
int n,m,A[MAXN][MAXN],B[MAXN][MAXN],C[MAXN][MAXN],O[MAXN];queue<int>Q[MAXN][MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read(),S=0,T=2*n+1;
	Rep(i,1,n)Rep(j,1,m)A[i][j]=read(),Q[i][(A[i][j]-1)/m+1].push(A[i][j]);
	Rep(o,1,m){
		Init();Rep(i,1,n)add(S,i,1),add(i+n,T,1);
		Rep(i,1,n)Rep(j,1,n)if(Q[i][j].size())add(i,j+n,1);
		if(Dinic()!=n)return puts("-1"),0;
		Rep(i,1,n)for(int j=head[i];j;j=edges[j].next)if(!edges[j].w)
			B[i][o]=Q[i][edges[j].to-n].front(),Q[i][edges[j].to-n].pop();
	}Rep(i,1,n){Rep(j,1,m)cout<<B[i][j]<<" ";cout<<"\n";}
	Rep(i,1,m){Rep(j,1,n)O[j]=B[j][i];sort(O+1,O+n+1);Rep(j,1,n)C[j][i]=O[j];}
	Rep(i,1,n){Rep(j,1,m)cout<<C[i][j]<<" ";cout<<"\n";}
	return 0;
}




Measured memory_bytes: 32340
def insertion_sort(nums,n,g):
    global count
    
    for i in range(g,n):
        v=nums[i]
        j=i-g
        
        while (j>=0 and nums[j]>v):
            nums[j+g]=nums[j]
            j=j-g
            count+=1
        nums[j+g]=v


def shell_sort(nums,n):
    global count
    count=0
    m=-1
    test=0
    while test<=n:
        test=test*3+1
        m+=1
    G=[]
    h=0
    for i in range(m):
        h=h*3+1
        G.append(h)
    G.reverse()
    for i in range(m):
        insertion_sort(nums,n,G[i])
    return m,G,count,nums

def show(num):
    for i in range(len(num)):
        if i!=len(num):
            print(num[i],end=' ')
            
        else:
            print(num[i])

n=int(input())
nums=[int(input()) for j in range(n)]
answer_m,answer_G,answer_count,answer_nums=shell_sort(nums,n)
print(answer_m)
show(answer_G)
print()
print(answer_count)
for j in range(len(answer_nums)):
    print(answer_nums[j])



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

int main(void){
  int i=0,ans[100];
  char a[10];
  while(1){
    scanf("%s",a);
    if(a[0]=='+'){
      ans[i-1]=ans[i-1]+ans[i];
      i--;
    }
    else if(a[0]=='-'){
      ans[i-1]=ans[i-1]-ans[i];
      i--;
    }
    else if(a[0]=='*'){
      ans[i-1]=ans[i-1]*ans[i];
      i--;
    }
    else if(a[0]>='0' && a[0]<='9'){
      i++;
      ans[i]=atoi(a);
    }
    if(getchar()=='\n') break;
  }
  printf("%d\n",ans[1]);
  return 0;
}



Measured memory_bytes: 2104
# -*- coding: utf-8 -*-
from pprint import pprint
import math
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2:
        return []

    primes = [i for i in range(x)]
    primes[1] = 0  # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x):
            break
        if prime == 0:
            continue
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

primes_list = set(primes(10**5+1))
list2017 = [i for i in primes_list if i%2 == 1 and (i+1)//2 in primes_list]
list2017.sort()

def search(n):
    s = 0
    e = len(list2017) - 1
    i = 0
    if n < list2017[s]:
        return 0
    if list2017[e] <= n:
        return len(list2017)
    while s < e:
        i = (s + e)//2
        if list2017[i] == n:
            return i+1
        elif list2017[i] < n:
            s = i
        else:
            e = i

        if s + 1 == e:
            return s + 1


for l,r in lr:
    # pprint([a for a in list2017 if l<=a<=r])
    lidx = search(l-1)
    ridx = search(r)
    # print(ridx)
    # print(lidx)
    print(ridx - lidx)


Measured memory_bytes: 79064
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 200005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
char S[MAX_N];
int prefix_white[MAX_N];
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");
	
	int N;
	scanf("%d %s", &N, S);
	memset(prefix_white, 0, sizeof(prefix_white));
	if (S[0] == '.') prefix_white[0]++;
	for (int i = 1; i < N; i++) {
		prefix_white[i] = prefix_white[i - 1];
		if (S[i] == '.') prefix_white[i]++;
		eprintf("{%d}\n", prefix_white[i]);
	}
	int res = INT_MAX;
	for (int i = 0; i < N; i++) {
		int left_black = 0;
		if (i > 0) left_black = i - prefix_white[i - 1];
		int right_white = prefix_white[N - 1] - prefix_white[i];
		eprintf("%d => {%d %d}\n", i, left_black, right_white);
		res = min(res, left_black + right_white);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;

typedef long long ll;

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

ll N,T;

ll c[100010];

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

    rep(i,N) {
        ll l,r;
        cin >> l >> r;
        c[l]++;
        c[r]--;
    }

    rep(i,T) {
        c[i+1] += c[i];
    }

    ll ans = 0;
    rep(i,T+1) {
        ans = max(ans,c[i]);
    }

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



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

using namespace std;

int main() {
    string w;
    cin>>w;
    int len = w.length();
    int a[26] = {0};
    int flag = 0;
    for(int i = 0; i < len; i++) {
        a[w[i]-'a']++;
    }
    for(int i = 0; i < 26; i++) {
        if(a[i]%2 == 1){
            flag = 1;
            break;
        }
    }
    if(!flag) {
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3600
N = int(input())
A = list(map(int, input().split()))
s = 0
if N==1:
  print(0)
  exit()

for i,a in enumerate(A):
  if i==0:
    continue
  
  tmp = A[i-1] - a
  if tmp>0:
    A[i] = A[i-1]
    s += tmp

print(s)


Measured memory_bytes: 32000
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, a[4], b[4], hit=0, blow=0;

	while(scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) != EOF){

		for(i=0; i<4; i++){
			if(b[i] == a[i])
				hit++;
			else if(b[i] == a[0] || b[i] == a[1] || b[i] == a[2] || b[i] == a[3])
				blow++;
		}
		printf("%d %d\n", hit, blow);
		hit=0;
		blow=0;
	}
	return 0;
}
		

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int x, y;
    std::cin >> x >> y;
    if (x<10 && y<10){
        std::cout << x*y << std::endl;
    }
    else{
        std::cout << -1 << std::endl;
    }
    return 0;
}
 */

/*
int main() {
    int N;
    std::cin >> N;
    for(int i=1; i<10; i++){
        if(N%i==0){
            if(N/i<10){
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}
 */

int main() {
    long long int n, N;
    std::cin >> N;
    n = int(sqrt(N));
    for(int i=n; i>0; i--){
        if(N%i==0){
            std::cout << i+(N/i)-2 << std::endl;
            return 0;
        }
    }

    return 0;
}


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

x = [0]*8
god = 0
for a in A:
    for i in range(8):
        if a < 400*(i+1):
            x[i] = 1
            break
    else:
        god += 1

res = sum(x)
print(max(res, 1), res+god)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int q;
    cin >> q;
    int k;
    while (q--) {
        cin >> k;
        auto p = lower_bound(ALL(a), k);
        if (p == a.end()) cout << n << endl;
        else cout << distance(a.begin(), p) << endl;
    }
}



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

int main(){
    int N;
    string X;
    cin >> N >>X;
    int count = 0;
    for(int i = 0; i < N -2; i++){
        if(X.at(i) == 'A' && X.at(i + 1) == 'B' && X.at(i + 2) == 'C'){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    string s,t;
    cin >> s >> t;
    int n=s.length();
    int m=t.length();
    string c="{";
    rep(i,n-m+1){
        string ss=s;
        rep(j,m){
            if(s[i+j]!='?' && s[i+j]!=t[j])break;
            ss[i+j]=t[j];
            if(j==m-1){
                rep(k,n){
                    if(ss[k]=='?')ss[k]='a';
                }
                chmin(c,ss);
            }
        }
    }
    if(c=="{")cout << "UNRESTORABLE";
    else cout << c;

}

/*



 */



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


int main()
{

    int a, b;

    cin >> a >> b;

    int ans = 1;
    int res = 0;
    while(ans < b)
    {
        ans--;
        ans += a;
        res++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
int N, A, B;
vector<ll> v;





//サブ関数
//入力
void input()
{
	cin >> N >> A >> B;
	v.resize(N);
	REP(i, N)cin >> v[i];
}

int count(ll num) {
	int res = 0;
	while (num > 0) {
		res += (num & 1);
		num >>= 1;
	}
	return res;
}

ll sum(const vector<ll>& v, ll num)
{
	ll res = 0;
	int i = 0;
	do {
		if (num & 1)res += v[i];
		num >>= 1; 
		i++;
	} while (num > 0);
	return res;
}

vector<pair<ll,ll>> accumulate(const vector<ll>& v) {
	int siz = v.size();
	vector<pair<ll, ll>> res(siz + 1);//score,num
	REP(i, (1 << siz)) {
		int id = count(i);
		ll score = sum(v, i);
		if (score > res[id].first)res[id] = { score, 1ll };
		else if (score == res[id].first)res[id].second++;
	}
	return res;
}

ld abs2(ld res) {
	return (res > 0 ? res : -res);
}

//計算
void calc()
{
	constexpr ld EPS = 1e-6;
	const int lNum = N / 3;
	const int cNum = N / 3;
	const int rNum = N - lNum - cNum;
	auto lsum = accumulate(vector<ll>(v.begin(), v.begin() + lNum));
	auto csum = accumulate(vector<ll>(v.begin() + lNum, v.begin() + lNum + cNum));
	auto rsum = accumulate(vector<ll>(v.begin() + lNum + cNum, v.end()));

	pair<ld, ll> best;
	REP(i, lNum + 1)REP(j, cNum + 1)REP(k, rNum + 1) {
		if (i + j + k < A || B < i + j + k)continue;
		ld tmpScore = (ld)(lsum[i].first + csum[j].first + rsum[k].first) / (i + j + k);
		ll tmpNum = lsum[i].second * csum[j].second * rsum[k].second;
		if (tmpScore > best.first + EPS) best = { tmpScore,tmpNum };
		else if (abs2(tmpScore - best.first) < EPS)best.second += tmpNum;
	}
	cout << fixed << setprecision(6) << best.first << endl << best.second << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	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(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(double k){return Point(x*k,y*k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{
    return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
  }
  double dot(Point p){return x*p.x+y*p.y;}
  double det(Point p){return x*p.y-y*p.x;}
};
struct Line{
  Point p1,p2;
  Line(){}
  Line(Point p1, Point p2):p1(p1),p2(p2){}
};
int ccw(Point a,Point b,Point c){
  Point t1=b-a,t2=c-a;
  if(t1.det(t2)> eps) return 1;//counter clockwise
  if(t1.det(t2)< -eps) return -1;//clockwise
  if(t1.dot(t2)< -eps) return 2;//c-a-b online
  if(t1.norm()<t2.norm()) return -2;//a-b-c online
  return 0;//a-c-b online
}
bool intersectSS(Point a,Point b,Point c,Point d){
  return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}
bool intersectSS(Line l1,Line l2){
  return intersectSS(l1.p1,l1.p2,l2.p1,l2.p2);
}
bool isOrthogonal(Point a,Point b){
  return fabs(a.dot(b))<eps;
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}
bool isParallel(Point a,Point b){
  return fabs(a.det(b))<eps;
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}
Point CrossPoint(Line l1,Line l2){
    double a=(l1.p2-l1.p1).det(l2.p2-l2.p1);
    double b=(l1.p2-l1.p1).det(l1.p2-l2.p1);
    if(fabs(a)<eps&&fabs(b)<eps) return l2.p1;
    return l2.p1+(l2.p2-l2.p1)*(b/a);
}
Point project(Line l,Point p){
  Point base=l.p2-l.p1;
  double r=(p-l.p1).dot(base)/base.norm();
  return l.p1+base*r;
}
Point reflect(Line l,Point p){
  return p+(project(l,p)-p)*2.0;
}
int main(){
    int q;
    double xp0,yp0,xp1,yp1,xp2,yp2;
    cin>>xp1>>yp1>>xp2>>yp2;
    Point p1(xp1,yp1),p2(xp2,yp2);
    Line l(p1,p2);
    cin>>q;
    while(q--){
        cin>>xp0>>yp0;
        Point p0(xp0,yp0);
        Point ans=project(l,p0);
        cout<<fixed<<setprecision(10)<<ans.x<<" "<<ans.y<<endl;
    }
    return 0;
}


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


int main()
{
	int n;
	int a[100];

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

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


Measured memory_bytes: 3084
n = int(input())
l = list(map(int,input().split()))
l = [0]+l+[0]
sum_l = 0
s = 0
for i in range(n+2):
    g = l[i]
    sum_l += abs(g-s)
    s = g
for i in range(1,n+1):
    ans = sum_l +abs(l[i+1]-l[i-1])-(abs(l[i]-l[i-1])+abs(l[i+1]-l[i]))
    print(ans)

Measured memory_bytes: 13920
#include <iostream>

using namespace std;

int fib(int n);

int memo[45];
int main() {
  int n;

  //入力
  cin >> n;

  // 出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n){
  if(n==1){
    return 1;
  }else if(n==0){
    return 1;
  }else if(memo[n]!=0){
    return memo[n];
  }else{
    return memo[n]=fib(n-1)+fib(n-2);
  }
}


Measured memory_bytes: 3116
process.stdin.resume();
process.stdin.setEncoding('utf-8');
 
let inputString = '';
let currentLine = 0;
 
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
 
process.stdin.on('end', _ => {
    inputString = inputString.split(/\n/);
    main();    
});
 
function readLine() {
    return inputString[currentLine++];
}

const mod = Math.pow(10, 9) + 7
function main() {
  const s = Number(readLine())
  let maxLength = Math.floor(s / 3)
  let result = 0
  const { fac, finv } = comInit(s)
  for (let l = 1; l <= maxLength; l++) {
    const remain = s - l * 3
    result += com(remain + l - 1, l - 1, fac, finv)
    result %= mod
  }
  console.log(result)
}

function comInit(l) {
  let fac = [1n, 1n]
  let finv = [1n, 1n]
  let inv = [0n, 1n]
  const biMod = BigInt(mod)
  for (let i = 2; i <= l; i++){
    const biI = BigInt(i)
    fac[i] = fac[i - 1] * biI % biMod;
    inv[i] = biMod - inv[biMod % biI] * (biMod / biI) % biMod;
    finv[i] = finv[i - 1] * inv[i] % biMod;
  }
  return { fac, finv }
}

function com(n, k, fac, finv){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  const biMod = BigInt(mod)
  return Number(fac[n] * (finv[k] * finv[n - k] % biMod) % biMod);
}

Measured memory_bytes: 30704
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s == "Sunny")cout << "Cloudy" << endl;
  if(s == "Cloudy")cout << "Rainy" << endl;
  if(s == "Rainy")cout << "Sunny" << endl;
  }

Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()

mae = s[0]
cnt = 0
happy = 0

if mae == "R":
    if n>=2:
        if s[1]=="R":
            happy += 1

for i in range(1,n):
    now = s[i]

    if now=="L":
        if mae=="L":
            happy += 1
    if now=="R":
        if i<n-1:
            if s[i+1]=="R":
                happy+=1


    if now != mae:
        cnt += 1

    mae = now

n_set = cnt//2
n_amari = cnt%2

if k <= n_set:
    happy += k*2
else:
    happy += n_set*2+n_amari

print(happy)

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

int main()
{
    string s,t;
    cin>>s>>t;
    int dp[s.size() + 1][t.size() + 1];
    memset (dp , 0 , sizeof(dp));
    
    for(int i = 1 ; i <= (int) s.size() ; i++ ){
        for(int j = 1 ;  j <= (int) t.size() ; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
            }else{
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }
        }
    }
    
    
    string ans;
    int i = s.size() , j = t.size();
    
  
    while( i > 0 && j > 0){
 
            if(s[i-1] == t[j-1])
            {
                ans.push_back(s[i-1]);
                i--;
                j--;
            }
            
            else if(dp[i-1][j] > dp[i][j-1])
                i--;
            else
                j--;
    }
    

    reverse(ans.begin() , ans.end());
    cout<<ans;

    
    return 0;
}

Measured memory_bytes: 35456
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
$i=0;
$pre=$a[0];
$ans=0;
while($i<$n){
  if($a[$i]<$pre){
    $ans+=$pre-$a[$i];
  }else{
    $pre=$a[$i];
  }
  ++$i;
}
echo $ans;

Measured memory_bytes: 31988
#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) 
using namespace std; 
typedef long long ll;
ll a,b,t;
int main(){
	hh;
	cin>>a>>b>>t;
	cout<<(t/a)*b<<endl;
	return 0;
}

Measured memory_bytes: 256