akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
//想定解に時間計算量O(NlogN)のsort関数が必要でなので、C++で書きます。C言語だと面倒
long long max(long long a,long long b){return (a > b ? a : b);}
int  main(){
    long long N,P,Q;
    scanf("%lld%lld%lld", &N,&P,&Q);
    
    long long c[500000+ 1] = {};
    long long uprange[500000 + 1] = {};
    long long sum = 0;
    for(int i = 0; i < N; ++i){
        scanf("%lld",c+i);
        sum += c[i];
    }
    for(int i = 0; i < N; ++i){
        uprange[i] = -c[i] + (Q - i) * P;
    }
    //sort
    std::sort(uprange,uprange + N,std::greater<>());
    
    
    long long ans = sum;
    long long crt = sum;
    long long tq = 0; // tq日自炊すると考える
    for(int i = 0; i < N; ++i){
        crt += uprange[i] + tq * P * 2LL;
        ans = max(ans,crt);
        ++tq;
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 11104
import numpy as np
n, m = map(int, input().split())

if m == 0:
    print(0)

ppp_min = 0
ppp_sum = 0
ppm_min = 0
ppm_sum = 0
pmp_min = 0
pmp_sum = 0
pmm_min = 0
pmm_sum = 0
mpp_min = 0
mpp_sum = 0
mpm_min = 0
mpm_sum = 0
mmp_min = 0
mmp_sum = 0
mmm_min = 0
mmm_sum = 0

cakes = []
for cake_index in range(n):
    x, y, z = map(int, input().split())
    cakes.append((x, y, z))

values = []

cakes.sort(key = lambda x: x[0] + x[1] + x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k += cake[0]
    o += cake[1]
    n += cake[2]

values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: x[0] + x[1] - x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k += cake[0]
    o += cake[1]
    n -= cake[2]
values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: x[0] - x[1] + x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k += cake[0]
    o -= cake[1]
    n += cake[2]
values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: x[0] - x[1] - x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k += cake[0]
    o -= cake[1]
    n -= cake[2]
values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: -x[0] + x[1] + x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k -= cake[0]
    o += cake[1]
    n += cake[2]
values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: -x[0] + x[1] - x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k -= cake[0]
    o += cake[1]
    n -= cake[2]
values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: -x[0] - x[1] + x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k -= cake[0]
    o -= cake[1]
    n += cake[2]
values.append(abs(k) + abs(o) + abs(n))

cakes.sort(key = lambda x: -x[0] - x[1] - x[2], reverse=True)
choised_cakes = cakes[:m]
k = 0
o = 0
n = 0
for cake in choised_cakes:
    k -= cake[0]
    o -= cake[1]
    n -= cake[2]
values.append(abs(k) + abs(o) + abs(n))

if not m == 0:
    print(max(values))

Measured memory_bytes: 12548
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

s = 0
for line in stdin:
    n = 0
    for c in line:
        if c.isdigit():
            n = n * 10 + int(c)
        elif n:
            s += n
            n = 0

print(s)

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    ll X; cin>>X;
    for(int i=-118; i<120; i++){
        for(int j=-119; j<119; j++){
            ll A=pow(i, 5.0), B=pow(j, 5.0);
            if(A-B==X){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>> res;
    for(ll i=2; i*i <=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1)res.emplace_back(n,1);
    return res;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    //ll now = A[0];
    map<ll,ll> mp;
    REP(i,0,N){
        auto v = factorize(A[i]);
        for(auto& p:v){
            ll e = p.first;
            ll n = p.second;
            mp[e] = max(mp[e], n);
        }
        //now = __gcd(now,A[i]);
        //now %= mo;
    }
    mint div = 1;
    for(auto& p:mp){
        mint e = p.first;
        ll n = p.second;
        div *= e.pow(n);
    }
    mint ans = 0;
    rep(i,N){
        ans += div/mint(A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4256
<>;
@S=<>=~/./g;
$"='';
$_[$_+1]="@S[$_-1,$_]"=~AC+$_[$_]for 1..$#S;
/ /,print$_[$']-$_[$`-1]-($`>1&&"@S[$`-2,$`-1]"=~AC),$/for<>


Measured memory_bytes: 30336
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
 
string s;
 
int main() {
  cin>>s;
  int L=s.size();
  int ans=753;
  rep(i,L-2) {
    string k=s.substr(i,3);
    int n=stoi(k);
    ans=min(ans,abs(n-753));
  }
  cout<<ans<<endl;
  return 0;
}

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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 18, INF = 1e9;
int a[N][2];
pair<int, int> w[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

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

    int ans = INF;

    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            w[j] = {a[j][(i >> j) & 1], j};
        }

        sort(w, w + n);

        int c[2] = {0, 0};

        bool ok = true;

        vector<pair<int, int>> z[2];

        int last = -1;

        for (int j = 0; j < n; j++) {
            z[(w[j].second & 1) ^ ((i >> w[j].second) & 1)].push_back({w[j].second, w[j].first});
            c[j & 1]++;

            if (j + 1 == n || w[j + 1].first != w[j].first) {
                if (c[0] != z[0].size()) {
                    ok = false;
                    break;
                }

                sort(all(z[0]));
                sort(all(z[1]));

                for (int k = j; k > last; k--) {
                    w[k] = {z[k & 1].back().second, z[k & 1].back().first};
                    z[k & 1].pop_back();
                }

                c[0] = c[1] = 0;
                last = j;
            }
        }

        if (ok) {
            int cur = 0;
            for (int j = 0; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    // if (i == 3) {
                    //     cout << w[j].second << " " << w[k].second << "\n";
                    // }
                    if (w[j].second > w[k].second) {
                        cur++;
                    }
                }
            }

            // if (cur == 2) {
            //     cout << i << "\n";
            // }
            // if (i == 3)
            // for (int j = 0; j < n; j++) {
            //     cout << w[j].first << " " << w[j].second << "\n";
            // }

            ans = min(ans, cur);
        }
    }

    cout << (ans == INF ? -1 : ans);

    return 0;
}   

Measured memory_bytes: 384
k, n = map(int, input().split())
a = list(map(int, input().split()))
#aを1直線状のリストと考える
a.append(k+a[0])
#k+a[0]はkを超えた後のa[0]
d = 0

for i in range(n):
    d = max(d, a[i+1]-a[i])
    
print(k-d)

Measured memory_bytes: 32168
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));


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

	int H,W;
	cin >> H>>W;
	int cnt = 0;
	REP(i, H) {
		REP(j, W) {
			char S;
			cin >> S;
			if (S == '#')cnt++;
		}
	}
	if (cnt == H + W -1)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}




















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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define DUMP(v) REP(i,(v).size()){cout<<v[i];if(i!=v.size()-1)cout<<" ";else cout<<endl;}
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int a, b;
	REP(i, s.size()) {
		if (s[i] == 'A') {
			a = i;
			break;
		}
	}
	RREP(i, s.size()) {
		if (s[i] == 'Z') {
			b = i;
			break;
		}
	}
	cout << b - a + 1 << endl;
	return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int odd(int n, int k, int a[])
{
    int count = 0;
    for(int i = 0;i<n;i++)
    {
        if(a[i]>=k)
            count++;
    }
    return count;
}
int main()
{
    int n,k,res,a[100000];
    cin>>n>>k;
    for(int i = 0;i<n;i++)
        cin>>a[i];
    res = odd(n,k,a);
    cout<<res;
    return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())

E = [[] for _ in range(N)]
rE = [0] * N

for _ in range(M):
    x, y = map(int, input().split())
    E[x - 1].append(y - 1)
    rE[y - 1] += 1

dp = [0] * N

Q = [x for x in range(N) if not rE[x]]

while Q:
    v = Q.pop()
    memo = dp[v] + 1
    for u in E[v]:
        dp[u] = max(dp[u], memo)
        rE[u] -= 1
        if not rE[u]:
            Q.append(u)

print(max(dp))

Measured memory_bytes: 59168
import math
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
d1=0
d2=0
d3=0
D1=[]
for i in range(n):
    d1+=abs(x[i]-y[i])
print(f'{d1:.6f}')
for i in range(n) :
    d2+=abs(x[i]-y[i])**2
print(f'{math.pow(d2,1/2):.6f}')
for i in range(n):
    d3+=abs(x[i]-y[i])**3
print(f'{math.pow(d3,1/3):.6f}')
for i in range(n):
    D1.append(abs(x[i]-y[i]))
print(f'{max(D1):.6f}')


Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b,n;
	cin >> a >> b >> n;
	if(n<b){
		cout << 1ll*a*n/b-1ll*(n/b)*a;
	}
	else{
	//现在n以及大于等于n了
	//需要进行选择
	//一个是(b-1)*
		ll minn = 0;
		minn = 1ll*a*(b-1)/b;//这个最大的
		if(n%b==0){
			n=n-1;//先减再说，管你这么多 
		}
		minn = max(minn,a*n/b-(n/b)*a);
		cout << minn; 
	}
	return 0;
} 

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=998244353;
const int MAX=200001;
int fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

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

int powMOD(int n,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(n,r/2)*powMOD(n,r/2)%MOD;
    if(r%2==1)return powMOD(n,r-1)*n%MOD;
}

void add(int &x,int y){
    x+=y;
    x%=MOD;
}
int divup(int x,int y){
    if(x%y==0)return x/y;
    else return x/y+1;
}

signed main(){
    COMinit();
    int n;cin>>n;
    int sum=0;
    int a[n];
    REP(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    vector<vector<int>>dp(n+1,vector<int>(sum+1,0));
    vector<vector<int>>ex(n+1,vector<int>(sum+1,0));
    dp[0][0]=ex[0][0]=1;
    REP(i,n){
        REP(j,sum+1){
            add(dp[i+1][j],dp[i][j]*2);
            add(ex[i+1][j],ex[i][j]);
            if(j-a[i]>=0){
                add(dp[i+1][j],dp[i][j-a[i]]);
                add(ex[i+1][j],ex[i][j-a[i]]);
            }
        }
    }
    int ans=powMOD(3,n);
    for(int i=divup(sum,2);i<=sum;i++){
        ans-=dp[n][i]*3;
        ans%=MOD;
    }
    if(sum%2==0)ans+=ex[n][sum/2]*3%MOD;
    ans%=MOD;
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 428480
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

a = sys.stdin.buffer.readline().decode().rstrip()
b = sys.stdin.buffer.readline().decode().rstrip()[:-1]
if a==b:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 27020
#include<iostream>

int main() 
{
  std::string nyuroku;
  std::cin >> nyuroku;
  
  int sakujo = 1111;
  std::string kotae = "aaa";
  for(int joutai=0;joutai<(1<<(int)nyuroku.size());joutai++)
    {
      std::string mozi="";
      for(int koko=0;koko<nyuroku.size();koko++)
	{
	  if( (joutai>>koko) & 1 ) 
	    mozi += nyuroku[koko];
	}
      if( mozi.size() <= 1 ) continue;
      if( mozi[0] != 'A' ) continue;
      if( mozi[(int)mozi.size()-1] != 'Z' ) continue;
      int _114514 = 1919;
      char AZ = 'A';
      for(int koko=0;koko<mozi.size();koko++)
	{
	  if( mozi[koko] != AZ ) 
	    {
	      _114514 = -1214;
	      break;
	    }
	  if( AZ == 'A' ) AZ = 'Z';
	  else            AZ = 'A';
	}
      int nagasa = (int)nyuroku.size() - (int)mozi.size();
      if( _114514 == 1919 && sakujo > nagasa )
	{
	  sakujo = nagasa;
	  kotae = mozi;
	}
    }
  if( kotae == "aaa" ) std::cout << -1 << std::endl;
  else                 std::cout << kotae << std::endl;
  return 0;
}

Measured memory_bytes: 1196
// B - Five Dishes

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
// #define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, d, e, h, n, w, ans = 0, count = 0;

  vlli g, f;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  g.pb(a);
  g.pb(b);
  g.pb(c);
  g.pb(d);
  g.pb(e);
  rep(i, 0, 5)
  {
    // cin >> g[i];
    string s = to_string(g[i]);
    lli k = s[s.size() - 1] - '0';
    if (k != 0)
    {
      ans += 10 - k;
      f.pb(k);
    }
    ans += g[i];
  }
  if (f.size() > 0)
  {
    count = f[0];
    rep(i, 0, f.size())
    {
      count = min(count, f[i]);
    }
    w = ans - (10 - count);
    cout << w << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
void dfs(int src,vector<int>v[],vector<bool>&vis)
{
	vis[src]=true;
	for(int it:v[src])
	{
		if(!vis[it])dfs(it,v,vis);
	}
}
int main()
{
	int n,m;cin>>n>>m;
	vector<int>v[n+1];
	for(int i=0;i<m;i++)
	{
		int a,b;cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int cnt=0;
	vector<bool>vis(n+1,false);
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			cnt++;
			dfs(i,v,vis);
		}
	}
	cout<<cnt-1;
}

Measured memory_bytes: 9964
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n, m;
int gcd(int a, int b){
	if(!b) return a;
	return gcd(b, a%b);
}
int main(){
	while(~scanf("%d %d",&n, &m)){
		printf("%d\n", gcd(n,m));
	}
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
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++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

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

	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
	{
		cout << "YES\n";
	}
	else 
		cout << "NO\n";
	return (0);
}

Measured memory_bytes: 256
n, y = map(int, input().split())
flag = False
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            flag = True
    if flag == True:
        break
if flag == False:
    print("-1 -1 -1")

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

using namespace std;

int main(){
int N; cin>> N;
  vector<int> A(N); for(int i = 0; i < N; i++){ cin >> A[i];}
  
  multiset<int> mp;
  
  for(int i = 0; i  <N; i ++){
   auto c = mp.lower_bound( A[i]);
    if( c != mp.begin()){  c--; mp.erase(c);}
                 mp.insert( A[i]);}
                          
                          
                      cout << mp.size() << endl; return 0;}
    
    

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

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

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

bool pal(string s){
    ll c = 0, n = s.length() -1;
    while(c < n){
        if(s[c] != s[n]) return false;
        c++;
        n--;
    }
    return true;
}

int main() {
    string s;
    bool flag  = true;
    cin >> s;
    ll len = s.length(), l1 = (len - 1)/2, l2 = (len + 3)/2;
    if(!pal(s)) flag =  false;
    string ss, sss;
    ss = s.substr(0, l1);
    sss = s.substr(l2 -1, len);
    //cout << ss << " " << sss << endl;
    if(!pal(ss)) {
        //cout << "false at 1"<< endl;
        flag = false;
    }
    if(!pal(sss)) {
        //cout << "false at 2" << endl;
        flag  = false;
    }
    if(flag) cout << "Yes";
    else cout << "No";
    return 0;
}
/*
         ,--"""",--.__,---[],-------._
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________

*/


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

int main(){

    int n,i;
    cin >> n;

    pair< pair<string, int>, int> pr[110];

    string str;
    int val;

    for(i=0;i<n;i++){
        cin >> str >> val;
        pr[i] = make_pair(make_pair(str, -val), i+1);
    }

    sort(pr, pr+n);

    for(i=0;i<n;i++)
        cout << pr[i].second << endl;

    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;


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

   if(N==M){
     System.out.println("Yes");
   }else{
     System.out.println("No");
   }
 
 }
}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
int main() {
  int H, W;
  ins(H, W);

  rep(i, H) rep(j, W) {
    string s; cin >> s;
    if (s == "snuke") {
      cout << (char)('A' + j) << i+1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
import math
def resolve():
    A,B,H,M=pin()
    #dosuMde harino kakudowo dasu
    a=(60*H+M)/2
    b=(M)*6
    #print(a,b)
    c=abs(a-b)
    if c>180:c=360-c
    #print(c)
    #using cosine formula
    cos_c=math.cos(math.radians(c))
    #print(math.radians(c))
    #print(cos_c)
    C2=A**2+B**2-2*A*B*cos_c
    print(math.sqrt(C2))
#%%submit!
resolve()


Measured memory_bytes: 62552
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p1 = new int[n];
        int[] pn = new int[n];
        for(int i = 0; i < k; i++){
            int a1 = sc.nextInt();
            int a2 = sc.nextInt();
            if(a1 == 1){
                p1[a2-1]++;
            }else if(a2 == n){
                pn[a1-1]++;
            }
        }
        for(int i = 1; i < n-1; i++){
            if(p1[i] + pn[i] == 2){
                System.out.println("POSSIBLE");
                return;
            }
        }
        System.out.println("IMPOSSIBLE");
    }
}

Measured memory_bytes: 96020
#include <bits/stdc++.h>
#define ll long long
#define en "\n"
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n,k,len,tm,ans=0;
    cin>>n>>k;
    k--;
    for(int i=0;i<n;i++)
    {
        cin>>tm;
        if(tm==1)len=i;
    }
    ans+=(len/k+(n-len-1)/k);
    if(len%k+(n-len-1)%k<=k&&len%k+(n-len-1)%k)ans++;
    else if(len%k+(n-len-1)%k>k)ans+=2;

    cout<<ans<<en;
    return 0;
}


Measured memory_bytes: 256
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  int n,t; ll ans; scanf("%d%d",&n,&t);
  int cur=0;
  REP(i,n){
    int x; scanf("%d",&x);
    ans+=t;
    if(x<cur) ans-=cur-x;
    cur=x+t;
  }  
  printf("%lld\n",ans);
  return 0;
}


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


int main(){
  ll N,M;cin>>N>>M;
  vll a(M),b(M);
  rep(i,M){cin>>a[i]>>b[i];a[i]--,b[i]--;}
  int sec=0;
  vector<pair<int,int>> v;
  rep(i,M) v.emplace_back(a[i],b[i]);
  sort(all(v),[&](auto const& a,auto const& b){ return a.second<b.second;});
  ll cnt=1;
  sec = v[0].second-1;
  rep(i,M){
    if(v[i].first<=sec) continue;
    sec = v[i].second-1;
    cnt++;    
  }
  cout << cnt << endl;
}

Measured memory_bytes: 2936
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.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;
}

set<string> words;

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

    string prev;
    cin >> prev;
    words.insert(prev);

    for (int i = 1; i < N; i++) {
        string word;
        cin >> word;
        if (words.find(word) != words.end()) {
            cout << "No" << endl;
            return 0;
        }
        if (prev[(int) prev.size() - 1] != word[0]) {
            cout << "No" << endl;
            return 0;
        }
        words.insert(word);
        prev = word;
    }
    
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}

ll test[1234][1234];
signed main() {
	ll n, m, k, a, b, c = 0, d = 0, cnt = 0, ans = 0;
	string s, t;
	cin >> n;
	for (int h = 1; h <= n; h++) {
		cin >> a;
		if (h % 2 == 1 && a % 2 == 1) { cnt++; }
	}
	cout << cnt << endl;
	return 0;
}

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

int main(){
  long long int n, k;
  cin >> n >> k;
  n = n + 1;
  long long int ans = 0;
  long long int maxa,mina;
  long long int a;
  for(long long int i=k; i<=n; i++){
    mina = (i-1) * i / 2;
    maxa = mina + (n-i)*i;
    ans += maxa - mina + 1;
    if(ans >= 1000000007){
      ans = ans % 1000000007;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3588
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	namespace impl
	{
		struct max_t
		{
			template<class T>constexpr T operator()(T&& lhs, T&& rhs)const
			{
				return std::max(lhs, rhs);
			}
		};
		struct min_t
		{
			template<class T>constexpr T operator()(T&& lhs, T&& rhs)const
			{
				return std::min(lhs, rhs);
			}
		};
	}
	constexpr impl::max_t max;
	constexpr impl::min_t min;

	template<class T>auto orderby(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min(); 

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

constexpr double pi = 3.14159265358979323846264;
void Main()
{
	double A, B, H, M;
	std::cin >> A >> B >> H >> M;
	auto s = 2 * pi * std::abs((60 * H + M) / (12 * 60) - M / 60);
	auto t = std::min(s, 2 * pi - s);
	auto a = A * A;
	auto b = B * B;
	auto z = 2 * A * B * std::cos(t);
	std::cout << std::sqrt(a + b - z) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int GetMax(int *pVal, int cnt)
{
    int max = *pVal;
    for (int *p = pVal + 1; p < (pVal + cnt); p++)
    {
        if (*p > max)
        {
            max = *p;
        }
    }
    return max;
}

int main(void)
{
    int val[3];
    cin >> val[0] >> val[1] >> val[2];

    int cnt = 0;
    while (val[0] != val[1] || val[1] != val[2] && val[0] != val[2])
    {
        int max = GetMax(val, 3);
        int rest = 0;
        
        for (int i = 0; i < 3; i++)
        {
            if (val[i] != max)
            {
                rest++;
            }
        }
        
        if (rest == 1)
        {
            for (int i = 0; i < 3; i++)
            {
                if (val[i] != max)
                {
                    val[i] += 2;
                }
            }
        }
        else if (rest == 2)
        {
            for (int i = 0; i < 3; i++)
            {
                if (val[i] != max)
                {
                    val[i]++;
                }
            }
        }

        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long a, long long b){
    cout << a * b << endl;
}


signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

#define K 600001

int n, m;
int a[K];
vector<int> nxt[K];

LL ret = 0;
int k = 0;

vector<int> sub;
vector<int> poll;

int dfs[K];

void du(int u) {
	dfs[u] = 1;
	sub.pb(a[u]);
	
	for (auto v : nxt[u]) {
		if (!dfs[v]) {
			du(v);
		}	
	}
}

void dd(int u) {
	sub.clear();
	k++;
	
	du(u);	
	
	sort(sub.begin(), sub.end());

	ret += sub[0];
	FOR(i, 1, sub.size()) poll.pb(sub[i]);
}

int main() {
	scanf("%d%d", &n, &m);
	FOE(i, 1, n) scanf("%d", &a[i]);
	FOE(i, 1, m) {
		int u, v; scanf("%d%d", &u, &v);
		u++; v++;
		nxt[u].pb(v);
		nxt[v].pb(u);	
	}
	
	FOE(i, 1, n) if (!dfs[i]) dd(i);
	
	if (k == 1) {
		puts("0");
		return 0;	
	}
	
	int needed = k - 2;
	
	if ((int)poll.size() < needed) {
		puts("Impossible");
		return 0;	
	}
	
	sort(poll.begin(), poll.end());
	
	FOR(i, 0, k - 2) ret += poll[i];
	
	printf("%lld\n", ret); 
}

Measured memory_bytes: 22232
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



signed main() {
    fio();
    string s;
    cin >> s;
    if (s[2] == s[3] and s[4] == s[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int D;
    cin >> H >> W >> D;
    vector<vector<int>>grid(H,vector<int>(W));
    for(auto &&h : grid)for(auto &&e : h) cin >> e;
    map<int,pii>memo;
    map<int,int>dis;
    rep(i,H)rep(j,W)memo[grid[i][j]] = make_pair(i,j);
    int Q;
    for(int i = 1; i <= H*W; ++i){
        if(dis[i])continue;
        int crt = (i ? i:D);
        while(crt + D <=H*W){
            dis[crt + D] = dis[crt] + abs(memo[crt].first - memo[crt+D].first) + abs(memo[crt].second - memo[crt+D].second);
            crt = crt + D;
        }
    }
    cin >> Q;
    rep(_,Q){
        int l,r;
        cin >> l >> r;
        int root = r % D;
        cout << dis[r] - dis[l] << endl;
    }
}




Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string w;
  cin >>w;
  string ans="Yes";
  for (char m='a';m<='z';m++){
    int sum=0;
    for (int i=0;i<w.length();i++){
      if (w[i]==m){
        sum+=1;
      }
    }
    if (sum%2==1)ans="No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
l = [0]*5
for i in range(n):
    a = input()
    if a[0] == "M":
        l[0] += 1
    elif a[0] == "A":
        l[1] += 1
    elif a[0] == "R":
        l[2] += 1
    elif a[0] == "C":
        l[3] += 1
    elif a[0] == "H":
        l[4] += 1
    
    
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += l[i]*l[j]*l[k]
print(ans)
  
  


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

int main(){
	int n;
	int a[110][110];
	cin>>n;
	rep(i,0,n)rep(j,0,n)cin>>a[i][j];
	ll ans=0;
	rep(i,0,n)rep(j,0,i){
		ans+=min(a[i][j],a[j][i]);
	}
	print(ans);
}


Measured memory_bytes: 3148
is_able_make = [False]*2000

input()

A = [ int( val ) for val in input().rstrip().split( ' ' ) ]
q = int(input())
M = [ int( val ) for val in input().rstrip().split( ' ' ) ]

for i in A:
    for j in range(2000-i,0,-1):
        if is_able_make[j] == True:
            is_able_make[i+j] = True
    is_able_make[i] = True

for x in M:
    if(is_able_make[x] == True):
        print('yes')
    else:
        print('no')

Measured memory_bytes: 7716
#include <bits/stdc++.h>
const int maxn=1e5+10,mod=1e9+7;
typedef long long ll;
using namespace std;
int n,m,k,t;
int a[maxn];
int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    while(m--)
    {
        char op[10];
        scanf("%d%s",&j,op);
        if(strcmp(op,"AC")==0)
        {
            if(a[j]!=1)k++;
            t+=max(0,a[j]-1);
            a[j]=1;
        }
        else
        {
            if(a[j]!=1)
            {
                if(!a[j])a[j]=2;
                else a[j]++;
            }
        }
    }
    printf("%d %d\n",k,t);
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i=1; i <= n-1;i++) {
		cnt +=(n-1)/i;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
char a[10001];
int main(){
cin>>a+1;
int M=strlen(a+1);
    for(int i=1;i<=M;i++){
        for(int j=i;j<=M;j++){
        if(a[i]=='C'&&a[j]=='F'){
            puts("Yes");
            return 0;
        }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 

int main() {
    int n, l_min = 1001, r_min = 1001, a[10];
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d", a+i);
    }
    for(int i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (a[i] == 0 && tmp < r_min) r_min = tmp;
        else if (a[i] == 1 && tmp < l_min) l_min = tmp;
    }
    if (l_min > 1000 || r_min > 1000) puts("0");
    else printf("%d\n", l_min + r_min);
}



Measured memory_bytes: 2088
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	vector<string> ss = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	int n, i, j, ans;
	string s;
	cin >> s;
	for (i = 0; i < ss.size(); i++) {
		if (ss[i] == s) ans = 7 - i;
	}
	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

const int max_n = 1e6 + 9;
const int nax = 1e6 + 1;

void solve() {
    vector<int> spf(nax);
    for (ll i = 2; i < nax; ++i) {
        if (!spf[i]) {
            spf[i] = i;
            for (ll j = i * i; j < nax; j += i) {
                if (!spf[j]) spf[j] = i;
            }
        }
    }
    int n; cin >> n;
    int pc = 1, sc = 0;
    bitset<nax> f;
    vector<int> v;
    auto fail = [&] (int x) {
        v.clear();
        while (x > 1) {
            int t = spf[x];
            // cout << t << ' ';
            if (f[t]) return 1;
            v.emplace_back(t);
            x /= t;
        }
        for (auto p : v) f[p] = 1;
        return 0;
    };
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        // cout << i << ": ";
        if (fail(a)) pc = 0;
        sc = __gcd(sc, a);
        // cout << '\n';
    }
    if (pc) cout << "pairwise coprime\n";
    else if (sc == 1) cout << "setwise coprime\n";
    else cout << "not coprime\n";
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();

    return 0;
}


Measured memory_bytes: 11068
// 5

#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 ALL(v) (v).begin(), (v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;

const bool debug = 0;

int n;
string s;

int cnt[10], ba;

int main() {
	while (cin >> n, n) {
		cin >> s;
		
		memset(cnt, 0, sizeof(cnt));
		ba = 0;
		
		int turn = 0;
		REP(i, s.size()) {
			cnt[turn]++;
			
			switch (s[i]) {
				case 'M': // 男
					break;
				case 'S': // 坊主
					ba += cnt[turn];
					cnt[turn] = 0;
					break;
				case 'L': // 姫
					cnt[turn] += ba;
					ba = 0;
					break;
			}
			
			turn = (turn + 1) % n;
		}
		
		sort(cnt, cnt + n);
		REP(i, n) printf("%d ", cnt[i]);
		printf("%d\n", ba);
		
	}
	return 0;
}

Measured memory_bytes: 3320
/* AOJ 0020 Capitalize */

#include <stdio.h>
#include <string.h>

int
main(void)
{
    char s[BUFSIZ];
    int len;
    int width = 'A' - 'a';
    int i;

    fgets(s, BUFSIZ, stdin);
    len = strlen(s);

    for (i = 0; i < len; i++) {
        if ('a' <= s[i] && s[i] <= 'z') s[i] += width;
    }

    fputs(s, stdout);

    return 0;
}

Measured memory_bytes: 520