akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,k;
vl a,b;
int main(){FAST;
cin>>n>>k;
for(int i=1;i<=n;i++){
	ll x;cin>>x;
	a.pb(x);
}
for(int i=1;i<=n;i++){
	ll x;cin>>x;
	b.pb(x);
}
sort(all(b));
sort(rall(a));
vll T;
for(ll i=0;i<n;i++){
	T.pb({a[i]*b[i],b[i]});
}
sort(all(T));
ll lo = 0,hi = T.back().first;
while(lo<hi){
	ll mid = (lo+hi)>>1LL;
	ll need = 0;
	for(int i=0;i<n;i++){
		if(T[i].first>mid){
			need+=(T[i].first-mid+T[i].second-1)/T[i].second;
		}
	}
	if(need<=k){
		hi=mid;
	}
	else{
		lo=mid+1;
	}
}
cout<<lo;
return 0;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

const ll MOD = 1e9+7;

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

    int n; cin >> n;
    vector<pii> v(n);
    FOR(i, n){
        cin >> v[i].F >> v[i].S;
    }

    sort(all(v));

    ll mini, maxi;

    if(n%2 == 1) mini = v[n/2].F;
    else mini = v[n/2-1].F + v[n/2].F;

    sort(all(v), [](pii& a, pii& b){
        return a.S < b.S;
    });

    if(n%2 == 1) maxi = v[n/2].S;
    else maxi = v[n/2-1].S + v[n/2].S;

    if(n%2 == 1) cout << maxi-mini+1 << '\n';
    else cout << maxi-mini+1 << '\n';

    return 0;
}


Measured memory_bytes: 6364
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
#define MAX 200000
int main()
{
  int i,j;
  int b[MAX]={0};
  b[0]=b[1]=1;
  for(i=2;i*i<=MAX;i++)if(!b[i])for(j=i+i;j<=MAX;j+=i)b[j]=1;

  vector<int> p;
  for(i=2;i<=MAX;i++)if(!b[i])p.push_back(i);

  int N,P;
  while(cin>>N>>P,N!=-1&&P!=-1){
    multiset<int> ms;
    multiset<int>::iterator it;
    int n;
    for(n=0;n<p.size();n++)if(p[n]>N)break;
    for(i=n;i<=n+P;i++)for(j=i;j<=n+P;j++)ms.insert(p[i]+p[j]);
    it=ms.begin();
    advance(it,P-1);
    cout<<*it<<endl;
  }
}

Measured memory_bytes: 1892
import itertools
import numpy as np

n, m, x = map(int, input().split())
c = []
a = []
for i in range(n):
    cu, *au = list(map(int, input().split()))
    c.append(cu)
    a.append(au)
c = np.array(c)
a = np.array(a)
    
pmin = 10000000
for e in itertools.product([0, 1], repeat=n):
    e = np.array(e)
    results = np.dot(e, a)
    if results.min()>=x:
        p = np.dot(e, c)
        if p < pmin:
            pmin = p

pmin = -1 if pmin==10000000 else pmin
print(pmin)

Measured memory_bytes: 27280
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

void cout_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

vector<int> D(13,0);
int search(vector<int> vec, int n){
    if(n==13){
        int ret=12;
        sort(vec.begin(), vec.end());
        int a=vec.size();
        for(int i=0; i<a; i++){
            ret=min(ret,abs(vec[(i+1)%a]-vec[i]));
            ret=min(ret,24-abs((vec[(i+1)%a]-vec[i])));
        }
        //cout_vec(vec);
        //cout << ret << endl;
        return ret;
    }
    if(D[n]==1){
        vec.push_back(n);
        int b = search(vec, n+1);
        vec.pop_back();
        vec.push_back(24-n);
        int c = search(vec, n+1);
        vec.pop_back();
        return max(b,c);
    }
    return search(vec, n+1);
}

int main(){
    int N;
    cin >> N;
    
    vector<int> clock(1,0);
    for(int i=0; i<N; i++){
        int d;
        cin >> d;
        D[d]++;
        if(D[d]>=3){
            cout << 0 << endl;
            return 0;
        }else if(D[d]==2){
            clock.push_back(d);
            clock.push_back(24-d);
        }
    }
    int ans=search(clock,0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double W;
    double H;
    double x;
    double y;
    
    int can=0;
    
    cin>>W>>H>>x>>y;
    double tate;
    double yoko;
    
    if(H-y>y)tate=y;
    if(H-y<y)tate=H-y;
    if(H-y==y)tate=y;
    //cout<<tate<<endl;
    
    if(W-x>x)yoko=x;
    if(W-x<x)yoko=H-x;
    if(W-x==x)yoko=x;
    //cout<<yoko<<endl;
    
    int kekka;
    if(tate*W<H*yoko)kekka=H*yoko;
    if(tate*W>H*yoko)kekka=H*yoko;
    if(tate*W==H*yoko){kekka=H*yoko;can=1;}
   // cout<<kekka<<endl;
    
    if(H-y==y && W-x==x)can=1;
    
    can=0;
    
    double max=0.5*W*H;
    
    if(2*x==W && 2*y==H)can=1;
    
    cout<<max<<" "<<can<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

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

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    cout << N / 2 + N % 2 << "\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {	
			String a = in.next();
			String b = in.next();
			String c = in.next();
			out.print(a.toUpperCase().charAt(0));
			out.print(b.toUpperCase().charAt(0));
			out.println(c.toUpperCase().charAt(0));
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 21460
N = int(input())
A = [int(x) for x in input().split()]
kosuu = [0]*(N+1)
for i in range(N):
    kosuu[A[i]] += 1

base = 0
for i in kosuu:
    base += i*(i-1)//2
for i in range(N):
    print(base-(kosuu[A[i]]-1))

Measured memory_bytes: 25644
import sys
input = sys.stdin.readline
INF = 10**16

H, W, K = map(int, input().split())
state = [list(map(int, list(input().rstrip()))) for _ in range(H)]

ans = INF
for bit in range(1<<(H-1)):
    zones = []
    tmp = [0]
    for h in range(H-1):
        if bit&(1<<h):
            zones.append(tmp)
            tmp = [h+1]
        else:
            tmp.append(h+1)
    zones.append(tmp)
    L = len(zones)
    Scores = [0]*L
    tmp_point = L-1
    for w in range(W):
        out = False
        C = []
        for l, z in enumerate(zones):
            p = 0
            for i in z:
                if state[i][w]:
                    p += 1
            C.append(p)
            if p + Scores[l] > K:
                out = True
            Scores[l] += p
        if max(C) > K:
            tmp_point = INF
            break
        if out:
            tmp_point += 1
            Scores = C[:]
    if tmp_point < ans:
        ans = tmp_point

print(ans)

Measured memory_bytes: 46684
from collections import deque

n = int(input())
nums = [3, 5, 7]

d = deque([0])

count = 0
while True:
    if len(d) == 0:
        break
    x = d.popleft()
    if x > n:
        continue
    else:
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            count += 1
        for num in nums:
            d.append(x * 10 + num)
print(count)

Measured memory_bytes: 42352
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<pair<string, pair<int, int>>> v;
    for(int i = 0; i < n; i++)
    {
        string s; int p;
        cin >> s >> p;
        v.push_back(make_pair(s, make_pair(-p, i)));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++)
    {
        cout << v[i].second.second + 1<< endl;
    }
    return 0;
}



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

typedef long long ll;

main() {
    int n,q;
    string s;
    cin >> n >> s >> q;
    vector<int> list,sumd(n+1,0),summ(n+1,0);
    for (int i = 0;i < n;++i) {
        if (s[i] == 'D') sumd[i+1]++;
        else if (s[i] == 'M') summ[i+1]++;
    }
    for (int i = 0;i < n;++i) {
        sumd[i+1] += sumd[i];
        summ[i+1] += summ[i];
    }

    //for (int i = 0;i <= n;++i) cout << sumd[i] << " ";
    //cout << endl;
    //for (int i = 0;i <= n;++i) cout << summ[i] << " ";
    //cout << endl;

    for (int l = 0;l < q;++l) {
        int k;
        cin >> k;
        ll dm = 0,ans = 0;
        for (int i = 0;i < n;++i) {
            if (i >= k && s[i-k] == 'D') dm -= summ[i]-summ[i-k];
            if (s[i] == 'M') dm += sumd[i+1]-sumd[max(0,i-k+1)];
            else if (s[i] == 'C') ans += dm;
            //cout << dm << " ";
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 11268
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    char c;
    cin >> c;
    c++;
    cout << c << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
signed main()
{
  int a,b;
  while(1){
    cin>>a>>b;
    if(a==0&&b==0){
      break;
    }
    if(a<b){
      cout<<a<<" "<<b;
    }
    else{
      cout<<b<<' '<<a;
    }
    cout<<"\n";
  }
  return(0);
}



Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  int cnt = 0;
  int tmp;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    if (tmp >= K) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
s    = gets.chomp

ans = 0

if m == 2 || m == 5
  
  n.times{ |i| (s[i].ord - 48 )%m == 0 && ans+=(i+1) }

else
  
  h = Hash.new(0)
  h[0] = 1
  
  cur = 0
  p10 = 1
  
  s.reverse.chars do |c|
    cur = ( cur + ( c.ord - 48) * p10 ) % m
    ans += h[cur]
    h[cur] += 1
    p10 = p10 * 10 % m
  end
end

puts ans

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;
ll cnt[9] = {1,1,2,3,5,8,13,21,34};
ll dp[105][10];

ll trans(ll W, ll a, int d) //左からa本目 d:向き(0:左 1:下 2:右)
{
	if (d == 0) return cnt[a-2] * cnt[W-a];
	if (d == 1) return cnt[a-1] * cnt[W-a];
	if (d == 2) return cnt[a-1] * cnt[W-a-1];
}

int main()
{
	ll H,W,K;
	cin >> H >> W >> K;
	dp[0][1] = 1;
	rep(i,H)
	{
		for(int j = 1; j <= W; ++j)
		{
			if (j-1 > 0) dp[i+1][j-1] = (dp[i+1][j-1] + trans(W,j,0) * dp[i][j] % MOD) % MOD;
			dp[i+1][j] = (dp[i+1][j] + trans(W,j,1) * dp[i][j] % MOD) % MOD;
			if (j+1 <= W) dp[i+1][j+1] = (dp[i+1][j+1] + trans(W,j,2) * dp[i][j] % MOD) % MOD;
		}
	}
	/*
	rep(i,H+1)
	{
		for (int j = 1; j <= W; ++j)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << dp[H][K] << endl;
	return 0;
}

Measured memory_bytes: 256
N,M=map(int, input().split())
SC=[list(map(int, input().split())) for _ in range(M)]
num=[-1]*N

for sc in SC:
	s,c=sc[0],sc[1]
	
	if s==1 and c==0 and N>1:
		print(-1)
		exit()
	elif num[s-1]==c or num[s-1]==-1:
		num[s-1]=c
	else:
		print(-1)
		exit()

if N==3:
	if num[0]==-1:
		num[0]=1
	if num[1]==-1:
		num[1]=0
	if num[2]==-1:
		num[2]=0
	print(num[0]*100+num[1]*10+num[2])
elif N==2:
	if num[0]==-1:
		num[0]=1
	if num[1]==-1:
		num[1]=0
	print(num[0]*10+num[1])
else:
	if num[0]==-1:
		num[0]=0
	print(num[0])

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    ll k;
    cin>>k;
    cout<<50<<endl;
    vector<int>a(50,0);
    int x=k % 50;
    int y = k / 50;
    for (int i = 0; i < 50; i++)
    {
        a[i]+=49 + y;
    }
    for (int i = 0; i < x; i++)
    {
        a[i]+=50;
        for(int j=0;j<50;j++){
            if(i!=j) a[j]--;
        }
    }
    for (int i = 0; i < 50; i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    
    return 0;
}

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

string mDec(int a){
	string ret;
	while(a){
		int t = a%(-10);
		if(t < 0){
			t += 10;
			a-=10;
		}
		a/=(-10);
		ret += '0'+t;	
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
int main(){
	int n;
	while(cin >> n , n){
		cout << mDec(n) << endl;
	}
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k,h,w;
    cin >> h >> w;
    string s[h];
    for(auto &x:s){
        cin >> x;
    }
    ll cnt = 0;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(s[i][j]=='.')cnt++;
        }
    }
    vector<vector<int>> cost(h,vector<int>(w,MOD));
    cost[0][0]=1;
    queue<pair<ll,ll>>que;
    que.push({0,0});
    ll dx[]={-1,1,0,0};
    ll dy[]={0,0,-1,1};
    while(!que.empty()){
        auto now = que.front();
        que.pop();
        for(i=0;i<4;i++){
            ll ddx = now.second+dx[i];
            ll ddy = now.first+dy[i];
            if(ddx<0 || ddx>=w)continue;
            if(ddy<0 || ddy>=h)continue;
            if(s[ddy][ddx]=='#')continue;
            if(cost[ddy][ddx]>cost[now.first][now.second]+1){
                que.push({ddy,ddx});
                cost[ddy][ddx]=cost[now.first][now.second]+1;
            }
        }
    }
    if(cost[h-1][w-1]==MOD)cout << -1 << endl;
    else cout << cnt-cost[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

ll imos[1000][1000];
int main() {
  int n, m, q;
  cin >> n >> m >> q;

  REP(i, m) {
    ll l, r;
    cin >> l >> r;
    imos[l][r]++;
  }
  REP(i, n + 1) {
    REP(j, n + 1) { imos[i + 1][j] += imos[i][j]; }
  }

  REP(i, n + 1) {
    REP(j, n + 1) { imos[i][j + 1] += imos[i][j]; }
  }

  REP(i, q) {
    ll l, r;
    cin >> l >> r;
    cout << imos[r][r] - imos[l - 1][r] - imos[r][l - 1] + imos[l - 1][l - 1]
         << endl;
  }
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
int main() {
	ll x; cin >> x;
	ll cnt = 0;
	if (x <= 6) {
		cnt = 1;
	}
	else if (x <= 11) {
		cnt = 2;
	}
	else if (x > 11) {
		cnt = (x / 11) * 2;
		if (x % 11 == 0) {
		}
		else if (x % 11 > 6) {
			cnt += 2;
		}
		else {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

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

int main() {
  int N; cin >> N;
  
  int ans; cin >> ans;
  for(int i = 1; i < N; i++){
    int a; cin >> a;
    ans = gcd(ans, a);
  }
  cout << ans << endl;
  
}

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

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

using namespace std;

int main() {
  int n, c;
  cin >> n >> c;

  vector<vector<int>> p(c);
  vector<int> ls(n), rs(n);
  for (int i = 0; i < n; i++) {
    int u;
    cin >> ls[i] >> rs[i] >> u;
    p[u - 1].push_back(i);
  }

  vector<int> imos(202020);

  for (int k = 0; k < c; k++) {
    sort(p[k].begin(), p[k].end(), [&](int i, int j) { return ls[i] < ls[j]; });
    int i = 0;
    while (i < p[k].size()) {
      int j = i;
      while (i + 1 < p[k].size() && rs[p[k][i]] == ls[p[k][i + 1]]) {
        i++;
      }
      imos[ls[p[k][j]] * 2]++;
      imos[rs[p[k][i]] * 2 + 1]--;
      i++;
    }
  }

  int ans = 0;
  for (int i = 0; i + 1 < 202020; i++) {
    imos[i + 1] += imos[i];
    ans = max(ans, imos[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 2432
#include <stdio.h>

int main(void)
{
  int way[31];
  int i;
  int n;

 way[1] = 1;
 way[2] = 2;
 way[3] = 4;

 for (i = 4; i <= 30; i++){
     way[i] = way[i - 1] + way[i - 2] + way[i - 3];
 }

 while (scanf("%d", &n) && n){
   printf("%d\n", (way[n] + 3649) / 3650);
 }
 return (0);
}

Measured memory_bytes: 600
X=int(input())
sig=[[1,1],[1,-1],[-1,1],[-1,-1]]
f=False
for i in range(200):
    for j in range(200):
        for s in sig:
            A=s[0]*i
            B=s[1]*j
            if A**5-B**5==X:
                f=True
                break
        if f:
            break
    if f:
        break
print(A,B)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n, D;
  cin >> n >> D;
  if (n % (2*D+1) > 0)
    cout << n / (2 *D+1) + 1 << endl;
  else
    cout << n / (2 *D+1) << endl;
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int digit(int n) {
  int ret = 0;
  while (true) {
    n /= 10;
    ret++;
    if (n < 1) break;
  }
  return ret;
}

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

  int res = 0;
  FOR(i, 1, N + 1) {
    int d = digit(i);
    if (d % 2) res++;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD (LL)(1e9+7)

int N, A[50], B[50], C[50];
int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
		A[i]--;
	}
	for(int i=0; i<N; i++){
		cin >> B[i];
	}
	for(int i=0; i<N-1; i++){
		cin >> C[i];
	}

	int ans = B[A[0]];
	for(int i=1; i<N; i++){
		if(A[i-1]+1 == A[i]) ans += C[A[i-1]];
		ans += B[A[i]];
	}
	cout << ans << endl;
}

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

int main(){
  int N;
  int S;
  
  cin>>N;
  
  for(int i=1;i<=N;i++){
    int l,r;
    cin>>l>>r;
    int a;
    a=r-l+1;
    S=S+a;
  }
  
  cout<<S<<endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc074/tasks/arc083_b

import copy

N = int(input())
A = []
for _ in range(N):
    row = list(map(int, input().split()))
    A.append(row)

A2 = copy.deepcopy(A)
for k in range(N):
    for i in range(N):
        for j in range(N):
            A2[i][j] = min(A2[i][j], A2[i][k] + A2[k][j])

for i in range(N):
    for j in range(N):
        if A[i][j] != A2[i][j]:
            print(-1)
            exit()

result = 0
for i in range(N):
    for j in range(N):
        flag = True
        if i == j:
            continue
        for k in range(N):
            if i == k or j == k:
                continue
            if A2[i][j] == A[i][k]+A[k][j]:
                flag = False
                break
        if flag:
            result += A[i][j]

print(result//2)


Measured memory_bytes: 77128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().abc102_b();
        }

        public void Solve()
        {

            string s = Console.ReadLine();
            bool Flag = true;
            bool Cflag = false;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == 0)
                {
                    if (s[0] != 'A') Flag = false;
                }
                else if(2 <= i && i < s.Length - 1)
                {
                    if (('a' <= s[i] && s[i] <= 'z'))
                    {
                        continue;
                    }
                    else if(s[i] == 'C' && Cflag==false)
                    {
                        Cflag = true;
                        continue;
                    }

                    Flag = false;
                }
                else
                {
                    if (('a' <= s[i] && s[i] <= 'z')) continue;
                    Flag = false;
                }
            }

            if (Flag && Cflag) Console.WriteLine("AC");
            else Console.WriteLine("WA");
        }

        public void abc102_b()
        {
            int n = int.Parse(Console.ReadLine());

            List<int> a = Console.ReadLine().Split().Select(int.Parse).ToList();

            Int32 Amax = 0;
            Int32 Amin = Int32.MaxValue;

            for (int i = 0; i < n; i++)
            {
                Amax = Math.Max(Amax, a[i]);
                Amin = Math.Min(Amin, a[i]);
            }

            Console.WriteLine(Amax - Amin);
        }
    }

}


Measured memory_bytes: 11220
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
kill,surplus = 0,0

for i in range(n):
    tmp = min(a[i],surplus)
    kill += tmp
    a[i] -= tmp
    if b[i] > a[i]:
        kill += a[i]
        surplus = b[i]-a[i]
    else:
        kill += b[i]
        surplus = 0
tmp = min(a[n],surplus)
kill += tmp
print(kill)   

Measured memory_bytes: 18476
using System;
using System.Linq;
class Program {
  static long[] a;
  static int[] d;
  static long[] s;
  static long minGap;
  static void Main() {
    Console.ReadLine();
    a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    d = new[] { 1, 2, 3, a.Length };
    s = new[] { a[0], a[1], a[2], a.Skip(3).Sum() };
    FlattenSums(2, 2, 3);
    minGap = s.Max() - s.Min();
    for (var i = 3; i < a.Length - 1; i++)
      SolveMin(i);
    Console.WriteLine(minGap);
  }

    static void SolveMin(int center) {
        s[1] += a[d[1]];
        s[2] -= a[d[1]];
        d[1] = center;
        FlattenSums(0, 0, 1);
        FlattenSums(2, 2, 3);
        var gap = s.Max() - s.Min();
        if (gap < minGap) minGap = gap;
    }

    static void FlattenSums(int di, int si1, int si2) {
        if (s[si1] >= s[si2]) return;
        for (var i = d[di] + 1; i < d[di + 1]; i++)
        {
            var s1 = s[si1] + a[d[di]];
            var s2 = s[si2] - a[d[di]];
            if (s1 <= s2)
            {
                s[si1] = s1;
                s[si2] = s2;
                d[di] = i;
            }
            else
            {
                if (s1 - s2 < s[si2] - s[si1])
                {
                    s[si1] = s1;
                    s[si2] = s2;
                    d[di] = i;
                }
                break;
            }
        }
    }
}


Measured memory_bytes: 35036
package main

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

// {{{
// source: https://github.com/raahii/algo
func MaxInts(nums []int) (int, int) {
	var maxIdx, maxVal int
	for i, e := range nums {
		if i == 0 || e > maxVal {
			maxIdx = i
			maxVal = e
		}
	}
	return maxVal, maxIdx
}

func MinInts(nums []int) (int, int) {
	var minIdx, minVal int
	for i, e := range nums {
		if i == 0 || e < minVal {
			minIdx = i
			minVal = e
		}
	}
	return minVal, minIdx
}

func SumInts(nums []int) int {
	s := 0
	for _, v := range nums {
		s += v
	}
	return s
}

func ReverseInts(nums []int) []int {
	rnums := make([]int, len(nums))
	for i := 0; i < len(nums); i++ {
		rnums[len(nums)-1-i] = nums[i]
	}
	return rnums
}

func ExtendInts(nums1 []int, nums2 []int) []int {
	for _, v := range nums2 {
		nums1 = append(nums1, v)
	}
	return nums1
}

func Ints2d(n_rows, n_cols int) [][]int {
	ints := make([][]int, n_rows)
	for i := 0; i < n_rows; i++ {
		ints[i] = make([]int, n_cols)
	}
	return ints
}

func MemsetInts1d(nums []int, val int) {
	for i := range nums {
		nums[i] = val
	}
}

func MemsetInts2d(nums [][]int, val int) {
	for i := range nums {
		for j := range nums[i] {
			nums[i][j] = val
		}
	}
}

func ContainsInt(nums []int, num int) bool {
	sort.Ints(nums)

	s, e := 0, len(nums)
	for {
		if s >= e {
			break
		}

		m := (e + s) / 2
		if nums[m] == num {
			return true
		} else if num > nums[m] {
			s = m + 1
		} else {
			e = m
		}
	}

	return false
}

func ReadInt(f *os.File) int {
	var n int
	fmt.Fscanf(f, "%d", &n)
	return n
}

func ReadInts(f *os.File, n int) []int {
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%d", &nums[i])
	}
	return nums
}

func ReadLines(f *os.File, n int) []string {
	var lines []string
	reader := bufio.NewReader(f)
	for i := 0; i < n; i++ {
		bytes, _, err := reader.ReadLine()
		if err != nil {
			break
		}
		lines = append(lines, string(bytes))
	}

	return lines
}

func ReadWords(f *os.File, n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%s", &strs[i])
	}
	return strs
}

func Pow(a, n int) int {
	c := 1
	for i := 0; i < n; i++ {
		c *= a
	}
	return c
}

// }}}

func main() {
	N := ReadInt(os.Stdin)

	c := 0.0
	ins := ReadLines(os.Stdin, N)
	for _, line := range ins {
		es := strings.Split(line, " ")
		v, _ := strconv.ParseFloat(es[0], 64)
		k := es[1]
		if k == "JPY" {
			c += float64(v)
		} else {
			c += float64(v * 380000)
		}
	}

	fmt.Printf("%f\n", c)
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		String str[]=new String[a];
		int x[]=new int[a];
		for(int i=0;i<a;i++) {
			str[i]=scan.next();
			x[i]=scan.nextInt();
		}
		int b[][]=new int[a][2];
		for(int i=0;i<a;i++) {
			String stri=str[i];
			int z=x[i];
			int an=1;
			for(int j=0;j<a;j++) {
				String s=str[j];
				if(stri.compareTo(s)>0) {
					an++;
				}
				if(stri.equals(s)) {
					if(z<x[j]) {
						an++;
					}
				}
			}
			b[i][0]=an;
			b[i][1]=i;
		}
		Arrays.sort(b,(q, y)->Integer.compare(q[0],y[0]));
		for(int i=0;i<a;i++) {
			System.out.println(b[i][1]+1);
		}
	}
}


Measured memory_bytes: 28244
#include<bits/stdc++.h>
using namespace std;
int n,prime[1010],primecou=0;
int abc[1010];

int main()
{
	int i,j;
	
//	for(i=1;i<1000;i++) abc[i]++;
	scanf("%d",&n);
	int flag;
	for(i=2;i<=1000;i++)
	{
		flag = 0;
		for(j=0;j<primecou;j++)
		{
			if(i%prime[j]==0)
			{
				flag = 1;
			}
		}
		if(flag==0)
		{
			prime[primecou] = i;
			primecou++;
		}
		
	}
	
//	for(i=0;i<primecou;i++)
//	{
//		printf("%d\n",prime[i]);
//	}
	
	int num;
	for(i=1;i<=n;i++)
	{
		num = i;
		for(j=0;j<primecou;j++)
		{
			while(num % prime[j] == 0)
			{
				num /= prime[j];
	//			printf("i=%d  j=%d   abc[%d]++\n",i,j,prime[j]);
				abc[prime[j]]++;
			}
		}		
	}	
		
	long long ans=1;
	for(i=1;i<=1000;i++)
	{
	//	printf("abc[%d] = %d\n",i,abc[i]);
		//for(j=0;j<abc[i];j++)
	//	{
		if(abc[i] > 0)
		{
			ans *= (abc[i]+1);
			ans %= 1000000007;
		}
			
	//	}
	}
	printf("%lld\n",ans);
	
}

Measured memory_bytes: 3796
import java.io.*;

public class Main {

	public static void main(String[] args) {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		try {
			int k = Integer.valueOf(r.readLine());
			
			int[] T = new int[65536];
			
			for(int i=0;i<k;i++){
				//read N and string
				int N = Integer.valueOf(r.readLine());
				String str = r.readLine();
				
				//convert string into 2-dimension array w/ 0/1
				int[][] book = new int[N+1][2];
				if(str.charAt(0)=='Y'){
					book[0][0]=1;
				}
				if(str.charAt(2*N)=='Y'){
					book[0][1]=1;
				}
				for(int j=1;j<N;j++){
					if(str.charAt(j*2-1)=='Y'||str.charAt(j*2)=='Y'){
						book[j][0] = 1;
					} else {
						book[j][0] = 0;
					}
					if(str.charAt(j*2-1+2*N)=='Y'||str.charAt(j*2+2*N)=='Y'){
						book[j][1] = 1;
					} else {
						book[j][1] = 0;
					}
				}
				if(str.charAt(2*N-1)=='Y'){
					book[N][0]=1;
				}
				if(str.charAt(4*N-1)=='Y'){
					book[N][1]=1;
				}
				
				int hpos=0, vpos=0, cost=0;
				
				while(hpos<N){
					if(vpos==0){
						if(book[hpos][0]==1 && book[hpos][1]==1){
							cost += 2;
							
							int temp = hpos+1;
							while(temp<N){
								vpos = 0;
								if(book[temp][0]==1||book[temp][1]==1){
									vpos = 1;
									break;
								}
								temp++;
							}
						}
						if(book[hpos][0]==1 && book[hpos][1]==0){
							cost++;
							vpos = 1;
						}
						if(book[hpos][0]==0 && book[hpos][1]==1){
							cost+=2;
							vpos = 1;
						}
					} else if(vpos==1){
						if(book[hpos][0]==0 && book[hpos][1]==1){
							cost++;
							vpos = 1;
						}
						if(book[hpos][0]==1 && book[hpos][1]==1){
							cost += 2;
							
							int temp = hpos+1;
							while(temp<N){
								vpos = 0;
								if(book[temp][0]==1||book[temp][1]==1){
									vpos = 1;
									break;
								}
								temp++;
							}
						}
						if(book[hpos][0]==1 && book[hpos][1]==0){
							cost += 1;
							
							int temp = hpos+1;
							while(temp<N){
								vpos = 0;
								if(book[temp][0]==1||book[temp][1]==1){
									vpos = 1;
									break;
								}
								temp++;
							}
						}
					}
					hpos++;
					cost++;
				}
				
				if(book[N][1]==1){
					cost+=2;
				} else if (book[N][0]==1){
					cost++;
				}
				System.out.println(cost);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 28156
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, r;
	while (cin >> n >> r, n){
		vector<int> card(n);
		REP(i, n)
			card[i] = n-i;
		REP(i, r){
			int l, m;
			cin >> l >> m;
			l--;
			vector<int> card2(m);
			copy(card.begin() + l, card.begin() + l + m, card2.begin());
			card.erase(card.begin() + l, card.begin() + l + m);
			card2.insert(card2.end(), card.begin(), card.end());
			card = card2;
		}
		cout << card[0] << endl;
	}
}

Measured memory_bytes: 3092
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    mod=10**9+7
    s=readline().strip()
    n=len(s)

    convert=[[0]*13 for i in range(13)]
    for a in range(13):
        for b in range(10):
            convert[a][(10*a+b)%13]=1

    convert=np.array(convert,dtype=np.int64)
    dp=np.zeros(13,dtype=np.int64)
    dp[0]=1
    for i in range(n):
        if s[i]=="?":
            tmp=np.dot(dp,convert)
        else:
            x=int(s[i])
            tmp=np.zeros(13,dtype=np.int64)
            for j in range(13):
                tmp[(j*10+x)%13]=dp[j]
        tmp%=mod
        dp=tmp

    print(dp[5])
    
if __name__=="__main__":
    main()

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

class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        string Sr = string.Join("", S.Reverse());
        if (S != Sr)
        {
            Console.WriteLine("No");
            return;
        }
        int N = S.Length;
        string S1 = S.Substring(0, (N - 1) / 2);
        string S1r = string.Join("", S1.Reverse());
        if (S1 != S1r)
        {
            Console.WriteLine("No");
            return;
        }
        string S2 = S.Substring(((N + 3) / 2) - 1, N - ((N + 3) / 2) + 1);
        string S2r = string.Join("", S2.Reverse());
        if (S2 != S2r)
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }    
  modint pow(unsigned long long i){
    if(i == 0) return 1;
    if(i & 1){
      return (*this) * (this->pow(i-1));
    }
    modint<mod>hpow = (this->pow(i>>1));
    return hpow * hpow;
  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};

using mint = modint<1000000007>;

int main(){
  int n,k; cin >> n >> k;
  vector<int> v(n); cin >> v;
  mint ans(0);
  for(int i = 0; i < n; ++i){
    mint x = 0;
    mint y = 0;
    for(int j = 0; j < n; ++j){
      if(v[i] > v[j]){
	x++;
	if(i < j)y++;
      }
    }
    ans += k * y + x * k * (k-1) / 2;
  }
  cout << ans << endl;
  return 0;
}


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

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 2333;
int dfn[N], low[N], dfs_clock = 0;
int S[N], top = 0, scc_cnt = 0, sccno[N];
int c[N], d[N], a[N][N];
int n, m, ans[N * N];
vector<int> g[N];

inline void tarjan(int u, int fat) {
  dfn[u] = low[u] = ++ dfs_clock;
  S[++ top] = u;
  for (int v : g[u]) {
    if (!dfn[v]) {
      tarjan(v, u);
      low[u] = min(low[u], low[v]);
    }
    else if (!sccno[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    ++ scc_cnt;
    for (;;) {
      int v = S[top --];
      sccno[v] = scc_cnt;
      if (v == u) break;
    }
  }
}

inline void dfs1(int u, int cl) {
  if (c[u]) return ;
  c[u] = cl;
  for (int v : g[u])
    dfs1(v, cl);
}

inline void dfs2(int u, int cl) {
  if (d[u]) return ;
  d[u] = cl;
  for (int v : g[u])
    dfs2(v, cl);
}

main(void) {
  read(n); read(m);
  for (int i = 1; i <= m; i ++) {
    int x, y; read(x); read(y);
    a[x][y] = i; g[x].push_back(y);
  }
  for (int i = 1; i <= n; i ++)
    if (!dfn[i]) tarjan(i, 0);
  // for (int i = 1; i <= n; i ++)
  //   cout << sccno[i] << " "; puts("");
  for (int i = 1; i <= n; i ++) {
    memset(c, 0, sizeof c); 
    sort(g[i].begin(), g[i].end());
    c[i] = i;
    for (int v : g[i])
      dfs1(v, v);
    
    memset(d, 0, sizeof d);
    reverse(g[i].begin(), g[i].end());
    d[i] = i;
    for (int v : g[i])
      dfs2(v, v);
    
    // cout << i << "qwq\n";
    // for (int v = 1; v <= n; v ++)
    //   cout << c[v] << " "; puts("");
    // for (int v = 1; v <= n; v ++)
    //   cout << d[v] << " "; puts("");
    for (int v : g[i])
      ans[a[i][v]] = (sccno[i] == sccno[v]) ^ (c[v] != d[v]);
  }
  for (int i = 1; i <= m; i ++)
    puts(ans[i] ? "diff" : "same");
}


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

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }


int main(){
    ll X,A,B;
    cin >> X >> A >> B;
    cout << (X - A) % B << endl;
}


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

 int main() {
   int X, Y, Z;
   cin >> X >> Y >> Z;
   cout << Z << " " << X << " " << Y << endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && B == C && C == A) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
dict = {}
dict["AC"] = 0
dict["WA"] = 0
dict["TLE"] = 0
dict["RE"] = 0
for _ in range(n):
    s = input()
    dict[s] = dict.get(s, 0) + 1
print("AC x {}".format(dict["AC"]))
print("WA x {}".format(dict["WA"]))
print("TLE x {}".format(dict["TLE"]))
print("RE x {}".format(dict["RE"]))

Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		int x = A;
		int y = 0;
		
		while(T + 0.5 > x){
			x += A;
			y += B;
		}
		System.out.println(y);
	}
}


Measured memory_bytes: 21972
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split()))

def f(m, a):
	sa = set(a)
	seen = set()
	r = []
	for n in a[::-1]:
		if n not in seen:
			r.append(n)
			seen.add(n)
	for i in range(m):
		if (i+1) not in sa:
			r.append(i+1)
	return r

def isSorted(a):
	for i in range(1, len(a)):
		if a[i-1] > a[i]:
			return False
	return True

n, m = reads()
q = read()
a = reads()

r = f(m, a)
count = [0] * (m+1)
count[0] = n

table = [-1] * (m+1)
for i in range(len(r)):
	table[r[i]] = i

for aa in a[::-1]:
	index = table[aa]
	if 0 < count[index]:
		count[index] -= 1
		count[index+1] += 1

to = m
for i in range(m):
	if 0 < count[i]:
		to = i
		break

if isSorted(r[to:]):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 21216
#include <iostream>
#include <cmath>
#define endl '\n'
using namespace std;

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

	int N, M, a, total = 0;
    cin >> N >> M;

    while(M--){
        cin >> a;
        total += a;
    }
    if(total > N){
        cout << "-1";
    }else{
        cout << N - total;
    }

    return 0;
}



Measured memory_bytes: 3652