akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    int n,q;
    cin>>n>>q;
    if(!n)break;
    vector<tuple<int, int, string>> v;
    REP(i,n){
      string name;
      int era, western;
      cin>>name>>era>>western;
      v.emplace_back(western, era, name);
    }
    sort(begin(v),end(v));
    REP(i,q){
      int year;
      cin>>year;
      int ue,uw;
      string un;
      auto itr = upper_bound(begin(v),end(v),make_tuple(year,0,string()));
      if (itr == end(v)) {
        cout << "Unknown" << endl;
        continue;
      }
      tie(uw,ue,un) = *itr;
      if (year <= uw - ue)
        cout << "Unknown" << endl;
      else
        cout << un << ' ' << ue - (uw - year) << endl;
    }
  }
  return 0;
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}
map<pair<int,int>,int > mp;
pair<int,int> inp[100010];
ll ans[15];
int main(){

    ll h,w;
    cin>>h>>w;

    ll tot = (h-2)*(w-2);

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        mp[mk(a,b)]=1;
        inp[i]=mk(a,b);
    }

    for(int i=0;i<n;i++){
        int a,b;
        a=inp[i].ff;
        b=inp[i].ss;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a-j>=1 && b-k>=1 && a-j<=(h-2) && b-k<=(w-2)){
                    int cnt = 0;
                    for(int x=a;x<a+3;x++){
                        for(int y=b;y<b+3;y++){
                            if(mp[mk(x-j,y-k)]){
                               cnt++;
                            }
                        }
                    }
                    ans[cnt]++;
                }
            }
        }
        for(int i=0;i<=9;i++){
            //cout<<ans[i]<<" ";
        }
        //cout<<endl;
    }
    ans[0]=tot;

    for(int i=1;i<=9;i++){
        ans[i]=ans[i]/i;
        ans[0]-=ans[i];
    }
    for(int i=0;i<10;i++){
        cout<<ans[i]<<endl;
    }

}



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

struct UnionFind {
  vector<int> par, weight;
  UnionFind(int n) : par(n,-1), weight(n) {}
  void unite(int x, int y, int w = 0) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (par[x] > par[y]) swap(x, y), w = -w;
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) {
    if(par[x] < 0) return x;
    int r = find(par[x]);
    return par[x] = r;
  }
  int sizeOf(int x) { return -par[find(x)]; }
};

long n, m, a, b;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n >> m;
  UnionFind uf(n * 2);
  for(int i = 0; i < m; ++i) {
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b + n);
    uf.unite(b, a + n);
  }
  if(uf.same(0, n)) {
    cout << (n * (n-1) >> 1) - m << endl;
  } else {
    int cnt = 0;
    for(int i = 0;i < n; ++i) {
      if(uf.same(0, i)) ++cnt;
    }
    cout << cnt * (n - cnt) - m;
  }
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
using ll = long long;

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

    int N, A1, A2;
    queue<int> A;
    cin >> N;
    A1 = A2 = 0;
    for (int i=0; i<N; i++) {
        int a;
        cin >> a;
        A.push(a);
        if (a >= A1) {
            A2 = A1;
            A1 = a;
        }
        else if (a >= A2) {
            A2 = a;
        }
    }
    for (int i=0; i<N; i++) {
        int a_i = A.front();
        A.pop(); 
        if (a_i == A1) {
            cout << A2 << endl;
        }
        else{
            cout << A1 << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string S, T;
	cin >> S >> T;
	cout << T << S << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int n,T,c,t,ans = 1010;
cin >> n >> T;
rep(i,n){
    cin >> c >> t;
    if (t<=T)
    {
        ans = min(ans,c);
    }
    
}

if (ans == 1010)
{
    cout << "TLE" << endl;
}else
{
    cout << ans << endl;
}




//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#import sys
#import numpy as np
import fractions
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=fractions.gcd(ans,a[i])
print(ans)

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

using namespace std;
int main(){

    string S;
    string prev="";
    string buff="";
    cin >> S;
    long l = 0;
    long cnt = 0;

    for(long l = 0; l < S.size();l++){
        buff+=S[l];
        if(prev.compare(buff)==0){
            
        }else{
            prev=buff;
            cnt++;
            buff="";
        }
    }
    cout << cnt <<endl;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> c;
    if ('a' <= c  && c <= 'z') {
        cout << "a" << endl;
       } else {
           cout << "A" << endl;
       }
    return 0;
}


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

int main() {
  using namespace std;

  int N;
  cin >> N;

  vector<int> a;
  for (int i=0; i<N; i++) {
    int n;
    cin >> n;
    a.push_back(n);
  }

  sort(a.begin(), a.end(), [](int a1, int a2) { return a2 < a1; });

  int alice = 0, bob = 0;
  for (int i=0; i<N; i++) {
    if (i % 2 == 0) alice += a[i];
    else            bob += a[i];
  }

  cout << alice - bob << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string day[8]={"SUN","SAT","FRI","THU","WED","TUE","MON","SUN"};
  string str;
  cin>>str;
  int i=1;
  while(str!=day[i]){
    i++;
  }
  cout<<i<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;

int A[111111];
vector<int> ans;

int main(){
    int n,l;
    LL sum=0;

    scanf("%d %d",&n,&l);
    for(int i=1;i<=n;i++) scanf("%d",&A[i]);

    for(int i=1;i<n;i++){
        if(A[i]+A[i+1]>=l){
            printf("Possible\n");
            for(int j=1;j<i;j++) printf("%d\n",j);
            for(int j=n-1;j>i;j--) printf("%d\n",j);
            printf("%d",i);

            return 0;
        }
    }

    printf("Impossible");

    return 0;
}


Measured memory_bytes: 1152
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}



const ll N=2e5+5;

ll b[N];


struct cmp{
bool operator()(ll i,ll j)const
{
return b[i]>b[j];
}
};



int main()
{ 

IOS;

ll n;cin>>n;

ll m;cin>>m;

vl a(n+1);

multiset<ll,cmp>s;

FOR(i,n)cin>>a[i+1]>>b[i+1];

vl lim[m+1];

ll ans=0;


for(int i=1;i<=n;i++){
  ll temp=m-a[i];
  if(temp<0)continue;
  lim[temp].pb(i);
}

for(int x=m-1;x>=0;x--){
 for(auto d:lim[x]){
  s.insert(d);
 }
 if(s.empty())continue;
auto it=s.begin();
ans+=b[(*it)];
//cout<<(*it)<<endl;
s.erase(it);
}

/*for(auto x:s){
  d2(x,b[x]);
}*/

cout<<ans;



//end_routine();

return 0;
 
 }

Measured memory_bytes: 12972
import re
N,Q=[int(s) for s in input().split()]
S=input()
table=[1 if S[0:2] == "AC" else 0]
for i in range(1, N-1):
    table.append(table[i-1]+(1 if S[i:i+2] == "AC" else 0))
table.append(table[-1])
for i in range(Q):
    (li, ri)=[int(s) for s in input().split()]
    print(table[ri-2]-(table[li-2] if li > 1 else 0))

Measured memory_bytes: 7916
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int m = Integer.parseInt(br.readLine());
		int[] d = new int[m];
		long[] c = new long[m];
		for (int i = 0; i < m; i++) {
			String[] sa = br.readLine().split(" ");
			d[i] = Integer.parseInt(sa[0]);
			c[i] = Long.parseLong(sa[1]);
		}
		br.close();

		long ans = 0;
		long val = 0;
		for (int i = 0; i < m; i++) {
			ans += c[i];
			val += d[i] * c[i];
			ans += val / 9;
			val %= 9;
		}
		ans--;
		if (val == 0) {
			ans--;
		}
		System.out.println(ans);
	}
}


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

#define MAXN 200000

int n, m;
set<int> adj[MAXN+10];
string s;

int dimension[2][MAXN+10];
int cnt;

bool visited[MAXN+10];

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);

    cin>>n>>m;
    cin>>s;

    s="!"+s;

    int i;
    for(i=0; i<m; i++)
    {
        int x, y;
        cin>>x>>y;

        if(adj[x].find(y)==adj[x].end())
        {
            dimension[s[y]-'A'][x]++;
            dimension[s[x]-'A'][y]++;

            adj[x].insert(y);
            adj[y].insert(x);
        }

    }
    cnt=n;

    //for(i=1; i<=n; i++) cout<<i<<" : "<<dimension[0][i]<<" "<<dimension[1][i]<<endl;

    queue<int> Q;

    for(i=1; i<=n; i++) if(dimension[0][i]==0 || dimension[1][i]==0)
    {
        Q.push(i);
    }

    //cout<<"======================"<<endl;

    while(!Q.empty())
    {
        int now=Q.front();
        Q.pop();

        if(visited[now]) continue;

        visited[now]=true;
        cnt--;

        //cout<<now<<" : "<<dimension[0][now]<<" "<<dimension[1][now]<<endl;

        set<int>::iterator it;
        for(it=adj[now].begin(); it!=adj[now].end(); it++)
        {
            if(visited[*it]) continue;
            //cout<<"=> "<<*it<<endl;
            dimension[s[now]-'A'][*it]--;
            if(dimension[0][*it]==0 || dimension[1][*it]==0)
            {
                Q.push(*it);
            }
        }
    }

    //cout<<cnt<<endl;

    if(cnt!=0) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 29736
import math
MOD = 1000000007

def solve(N, ABs):
    groups = {}
    zero_count = 0
    for a, b in ABs:
        if a == 0 and b == 0:
            zero_count += 1
            continue
        if a == 0:
            k = (0, 1)
        elif b == 0:
            k = (1, 0)
        else:
            g = math.gcd(abs(a), abs(b))
            a //= g
            b //= g
            if a * b < 0:
                k = (abs(a), -abs(b))
            else:
                k = (abs(a), abs(b))
        groups.setdefault(k, 0)
        groups[k] += 1

    visited = set()
    possibles = []
    for k, v in groups.items():
        if k in visited:
            continue
        p = 0
        p += pow(2, v, MOD)
        if k[1] == 0:
            m = (0, 1)
        elif k[0] == 0:
            m = (1, 0)
        else:
            if k[1] < 0:
                m = (-k[1], k[0])
            else:
                m = (k[1], -k[0])


        if m in groups.keys() and m not in visited:
            p += pow(2, groups[m], MOD)
            visited.add(m)
            p -= 1
        visited.add(k)
        possibles.append(p % MOD)

    ans = 1
    for p in possibles:
        ans *= p
        ans %= MOD

    if zero_count:
        ans += zero_count
        ans %= MOD
    return (ans - 1) % MOD


def slow_solve(N, ABs):
    import itertools
    ans = 0
    for k in range(1, 2**N):
        b = ("{:0" + str(N) + "b}").format(k)
        taken = []
        for i, c in enumerate(b):
            if c == "1":
                taken.append(ABs[i])

        if len(taken) == 1:
            ans += 1
        elif all(comb[0][0] * comb[1][0] + comb[0][1] * comb[1][1] != 0
                 for comb in itertools.combinations(taken, 2)):
            ans += 1
    return ans % MOD



if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, ABs))


Measured memory_bytes: 86492
import numpy as np
from numpy import array


n, m, x = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a = array(a)

c_min = 0
flag = False

for i in range(1, 2 ** n ):
    b = np.zeros(m+1)

    for k in range(n):
        if ((i >> k) & 1):
            b += a[k]
    
    if np.all(b[1:] >= x):
        if flag == False:
            c_min = b[0]
            flag = True
        else:
            c_min = min(c_min, b[0])
        

c_min = int(c_min)

if flag == False:
    c_min = -1

print(c_min)



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

using namespace std;

int h, w, k;
bool s[10][1000];
int ans = 1e8;

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

    cin >> h >> w >> k;

    for (int i = 0; i < h; i++)
    {
        string st;
        cin >> st;
        for (int j = 0; j < w; j++)
            s[i][j] = (st[j] == '1');
    }

    for (int i = 0; i < (1 << (h - 1)); i++)
    {
        int curr = __builtin_popcount(i);
        vector<int> v(__builtin_popcount(i) + 1, 0);

        for (int j = 0; j < w - 1; j++)
        {
            bool z = false;
            int nxt = 0;
            int vc = 0;
            for (int t = 0; t < h; t++)
            {
                v[vc] += s[t][j];
                nxt += s[t][j + 1];
                if (v[vc] + nxt > k && !z)
                {
                    curr++;
                    z = true;
                }
                if ((i >> t) & 1)
                {
                    vc++;
                    nxt = 0;
                }
            }
            bool broken = false;
            if (z)
            {
                for (int t = 0; t <= __builtin_popcount(i); t++)
                {
                    if (v[t] > k)
                    {
                        broken = true;
                        curr = 1e8;
                    }
                    v[t] = 0;
                }
            }
            if (broken)
                break;
        }
        ans = min(ans, curr);
    }

    cout << ans;

    return 0;
}


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

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

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

int gcd(int a, int b) {
    int t;
    if (a < b) {
        t = a;
        a = b;
        b = t;
    }
    while (b != 0) {
        t = a;
        a = b;
        b = t % b;
    }
    return a;
}

int main() {
    int k;
    long long s = 0;
    cin >> k;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int r = 1; r <= k; r++) {
                s += gcd(r, gcd(i, j));
            }
        }
    }
    cout << s << endl;
}



Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
int main(void){
  char b[1];
  scanf("%s",b);

  if(strcmp(b,"A")==0) printf("T");
  if(strcmp(b,"T")==0) printf("A");
  if(strcmp(b,"C")==0) printf("G");
  if(strcmp(b,"G")==0) printf("C");

    return 0;
}

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

using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> costs(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    costs[i] = x;
  }
  vector<int> dp(n, INT_MAX);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 2; j++) {
      if (i + j < n) {
        int cost = dp[i] + abs(costs[i] - costs[i + j]);
        dp[i + j] = min(dp[i + j], cost);
      }
    }
  }
  cout << dp[dp.size() - 1] << endl;
}


Measured memory_bytes: 4048
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();

        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
        	arr[i] = sc.nextInt();
        }

        int rightCnt = 0;
        int totalCnt = 0;
        for(int i = 0; i < n; i++) {
        	for(int j = 0; j < n; j++) {
        		if(arr[j] < arr[i]) {
        			totalCnt++;
        			if(j > i)
        				rightCnt++;
        		}
        	}
        }
        
        int MOD = 1000000007;
        
        long kk = k * (k - 1) / 2 % MOD; 
        
        long asn = ((totalCnt * kk % MOD) + (k * rightCnt % MOD)) % MOD;
        System.out.println(asn);
    }
}


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

template <class T>
using lim = numeric_limits<T>;

const int N = 500;
bool grid[N+1][N+1];

struct answer{
	int a, b, c, d;
	
	answer(int w, int x, int y, int z){
		a = w;
		b = x;
		c = y;
		d = z;
	}
	
	void show(){
		printf("%d %d %d %d\n",a,b,c,d);
	}
};

struct coord{
	int x, y;
	bool isOdd;
	
	coord(){
		x=y=isOdd=0;
	}
	coord(int a, int b, bool c){
		x = a;
		y = b;
		isOdd = c;
	}
};

queue<answer> ans;
int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	int h, w;
	cin >> h >> w;
		
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			int temp; cin >> temp;
			grid[i][j] = temp&1;
		}
	}
	
	
	coord arr[h*w];
	int index = 0;
	for (int i = 1; i <= h; i++){
		if (i&1){
			for (int j = 1; j <= w; j++){
				arr[index++] = coord(i,j,grid[i][j]);
			}
		}
		else{
			for (int j = w; j > 0; j--){
				arr[index++] = coord(i,j,grid[i][j]);
			}
		}
	}
	
	for (int i = 0; i < index-1; i++){
		coord curr = arr[i];
		coord next = arr[i+1];
		if (curr.isOdd){
			ans.push(answer(curr.x,curr.y,next.x,next.y));
			arr[i+1].isOdd = !arr[i+1].isOdd;
		}
	}
	
	cout << ans.size() << endl;
	while(!ans.empty()){
		ans.front().show();
		ans.pop();
	}
}


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

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr ll INF = 1LL << 60;

class UnionFind {
    public:
    int n;
    vector<int> par, rank, size;  //親, 深さ, その木の要素数

    UnionFind(int n): n(n) {
        for(int i=0;i<n;++i){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
    }

    //根を求める
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            int p = find(par[x]);
            size[x] = size[p];
            return par[x] = p;
        }
    }

    //xとyの属する集合の併合
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        size[x] += size[y];
        size[y] = size[x];
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //同じ集合に属するか否か
    bool is_same(int x, int y){
        return find(x) == find(y);
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }

    UnionFind uf = UnionFind(n);
    int x, y;
    for(int i=0;i<m;++i){
        cin >> x >> y;
        uf.unite(x, y);
    }

    int n_cluster = 0;
    vector<int> pars;
    for(int i=0;i<n;++i) {
        if(uf.find(i) == i) {
            pars.push_back(i);
            ++n_cluster;
        }
    }

    int n_need = 2 * (n_cluster - 1);
    if(n_need > n) {
        cout << "Impossible" << endl;
        return 0;
    } else if(n_need == 0) {
        cout << 0 << endl;
        return 0;
    }

    
    vector<ll> min_a(n, INF), min_i(n, -1);
    for(int i=0;i<n;++i) {
        int p = uf.find(i);
        if(min_a[p] > a[i]) {
            min_a[p] = a[i];
            min_i[p] = i;
        }
    }
    for(int i=0;i<n;++i) {
        if(min_i[i] != -1) {
            a[min_i[i]] = INF;
        }
    }
    ll ans = 0LL;
    for(int i=0;i<n;++i) if(min_a[i] != INF) ans += min_a[i];
    int ans_cnt = n_cluster;
    vector<int> cluster_cnt(n, 1);

    vector<Pll> nodes;
    for(int i=0;i<n;++i) if(a[i] != INF) nodes.emplace_back(a[i], i);
    sort(nodes.begin(), nodes.end());

    
    for(int i=0;i<nodes.size()&&ans_cnt<n_need;++i) {
        if(cluster_cnt[uf.find(nodes[i].second)] >= n_need/2) continue;
        ans += nodes[i].first;
        ++cluster_cnt[uf.find(nodes[i].second)];
        ++ans_cnt;
    }

    cout << ans << endl;   
}


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

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

        final int[][] dpTable = new int[n][h + 1];
        final int a1 = scanner.nextInt();
        final int b1 = scanner.nextInt();
        dpTable[0][Math.min(a1, h)] = b1;
        for (int j = 0; j < h; j++) {
            if (dpTable[0][j] != 0) {
                dpTable[0][Math.min(j + a1, h)] = dpTable[0][j] + b1;
            }
        }

        for (int i = 1; i < n; i++) {
            final int attack = scanner.nextInt();
            final int magic = scanner.nextInt();
            for (int j = 0; j <= h; j++) {
                dpTable[i][j] = dpTable[i - 1][j];
            }

            int tmp = Math.min(attack, h);
            if (dpTable[i][tmp] == 0) {
                dpTable[i][tmp] = magic;
            } else {
                dpTable[i][tmp] = Math.min(dpTable[i][tmp], magic);
            }
            for (int j = 1; j <= h; j++) {
                if (dpTable[i][j] != 0) {
                    final int y = Math.min(j + attack, h);
                    if (dpTable[i][y] == 0) {
                        dpTable[i][y] = dpTable[i][j] + magic;
                    } else {
                        dpTable[i][y] = Math.min(dpTable[i][y], dpTable[i][j] + magic);
                    }
                }
            }
        }

        System.out.println(dpTable[n - 1][h]);
    }
}


Measured memory_bytes: 82416
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b = map(str, input().split())
if(a < b):
    print(a * int(b))
else:
    print(b * int(a))



Measured memory_bytes: 68908
#include <stdio.h>
#include <ctype.h>
#define rep(i,n) for ((i)=0; (i)<(n); (i)++)

int main(void) {
    char S[1200];
    int i = 0;
    scanf("%[^\n]", S);

    while(S[i] != 0) {
        if ('A' <= S[i] && S[i] <= 'Z') {
           S[i] = tolower(S[i]);
        } else if ('a' <= S[i] && S[i] <= 'z') {
            S[i] = toupper(S[i]);
        }
        i++;
    }
    i = 0;
    while(S[i] != 0) {
        printf("%c", S[i]);
        i++;
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

int main(){
  std::stack<int>S1;
  std::stack<std::pair<int, int> >S2;
  char ch;
  int sum = 0;
  for (int i = 0; std::cin >> ch; i++){
    if (ch == '\\') S1.push(i);
    else if (ch == '/' && S1.size() > 0){
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j){
        a += S2.top().second;
        S2.pop();
      }
      S2.push(std::make_pair(j, a));
    }
  }

  std::vector<int>ans;
  int t = 0;
  while (S2.size() > 0){
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  std::cout << sum << "\n";
  std::cout << ans.size();
  for (int i = 0; i < ans.size(); i++){
    std::cout << " ";
    t += ans[i];
    std::cout << ans[i];
  }std::cout << "\n";

  return 0;
}



Measured memory_bytes: 3212
import java.util.Scanner;

public 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: 21844
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int l[m]={};
    int r[m]={};
    int lmax=0,rmin=1000000;
    for(int i=0;i<m;i++){
        cin >>l[i] >> r[i];
        lmax=max(l[i],lmax);
        rmin=min(r[i],rmin);
    }
    if(rmin-lmax+1>=0){
        cout << rmin-lmax+1;
    }else{
        cout <<0;
    }

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll X[100100];
int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    REP(i,N){
        ll x;
        cin >> x;
        X[i] = x;
    }

    ll loc = X[0];
    ll ans = 0;
    for(int i = 1; i < N; i++){
        ll next = X[i];
        ll diff = next - loc;
        ans += min(diff*A, B);
        loc = next;
    }

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


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n, m, v, p, a[100005];
long long pre[100005];

int main() {
	read(n), read(m), read(v), read(p);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	std::sort(a + 1, a + 1 + n, std::greater<int>());
	long long sum = a[p];
	int ans = p;
	for (int i = p + 1; i <= n; ++i) {
		if (a[i] + m >= a[p] && 1ll * (a[i] + m) * (i - p) - sum >= 1ll * m * (v - n + i - p)) {
			++ans;
		}
		sum += a[i];
	}
	print(ans);
}


Measured memory_bytes: 5008
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;


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

	int v[N];

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

	sort(v, v + N);

	double sum = v[0];
	for(int i=1;i<N;i++){
		sum = (sum + v[i])*0.5;
	}

	cout << sum <<endl;

}



Measured memory_bytes: 256
N = gets.to_i
flag = 0

if N > 81
    puts "No"
else
    9.times do |i|
        9.times do |j|
            if (i + 1) * (j + 1) == N
                flag = 1
                break
            end
        end
    end
    if flag == 1
        puts "Yes"
    else
        puts "No"
    end
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

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

    int n;
    while (cin >> n)
    {
        if (n == 0)
            break;
        vector<int> v;
        for (int i = 0; i < n; ++i)
        {
            int a;
            cin >> a;
            v.push_back(a);
        }
        sort(v.begin(), v.end());

        ll ans = 0;
        ll sum = 0;
        for (int i = 0; i < n; ++i)
        {
            ans += sum;
            sum += v[i];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, k;
    cin >> n >> k;

    bool snuke[105];
    memset(snuke, false, sizeof(snuke));
    fo(i, k) {
        int d;
        cin >> d;

        fo(j, d) {
            int x;
            cin >> x;

            snuke[x] = true;
        }
    }

    int cont = 0;
    fo(i, n) {
        if ( !snuke[i + 1] ) cont++;
    }

    cout << cont << endl;

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n,m;
int vis[100000+5],ans[100000+5];
int main() {
    cin>>n>>m;
    vector< vector <int > > adj(n+2);
    for(int i=0;i<m;++i) {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);

    }
    queue<int> q;
    q.push(1);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        vis[u] = 1;
        for(int i=0;i<adj[u].size();++i) {
            if(!vis[adj[u][i]]) {
                ans[adj[u][i]] = u;
                vis[adj[u][i]] = 1;
                q.push(adj[u][i]);

            }

        }

    }
    int flag = 0;
    for(int i=1;i<=n;++i) {
        if(!vis[i]) {
            flag = 1;
            break;

        }

    }
    if(flag) {
        cout<<"No";

    } else {
        cout<<"Yes\n";
        for(int i=2;i<=n;++i) {
            cout<<ans[i]<<"\n";

        }

    }
    return 0;

}


Measured memory_bytes: 10620
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> A(N);

    for(int i = 0; i < N; i ++){
        cin >> A[i];
    }
    double bunbo = 0;

    for(int i = 0; i < N; i ++){
        bunbo += 1.0 / A[i];
    }
    cout << fixed;
    cout << setprecision(6) << 1.0 / bunbo << endl;
}

Measured memory_bytes: 256
# C - Average Length

N = int(input())
P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

D = []
for i in range(N):
    for j in range(i + 1, N):
        dist = (((P[i][0] - P[j][0]) ** 2) +
                ((P[i][1] - P[j][1]) ** 2)) ** (1 / 2)
        D.append(dist)

print(sum(D) / len(D) * (N - 1))


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, 0, S.size()) {
        if (S[i] != T[i]) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3896
#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 ? 1e9: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){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
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 a; cin >> a;
    rep(i,10000){
        rep(j,10000){
            if(i*4 + j*7 == a)return puts("Yes")*0;
        }
    }
    cout << "No" << endl;
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char a;
  scanf("%c",&a);
  if(a == 'A')
    printf("T");
  if(a == 'T')
    printf("A");
  if(a == 'C')
    printf("G");
  if(a == 'G')
    printf("C");

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long

 
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n&1)
		cout<<0<<"\n";
    else
	{
        ll res=0;
        ll tmp=10;
        while(tmp<=n)
        {
            res+=n/tmp;
            tmp*=5;
        }
        cout<<res<<"\n";
    }
}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int uno = a + b;
	int dos = b + c;
	int tres = min(c + a, dos);
	cout << min(tres, uno);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <bitset>

#define INF 0x7fffffff
#define REP(i,j,k) for(int i = j;i <= k;i++)
#define squr(x) (x) * (x)
#define lowbit(x) (x&(-x))
#define readInOne(x) scanf("%d", &(x))
typedef long long LL;

using namespace std;

const int MAXN = 300;

int n;
int l[MAXN];
int ans;

int main(int argc, const char * argv[]) {
    readInOne(n);
    REP(i, 1, 2 * n) {
        readInOne(l[i]);
    }
    sort(l + 1, l + 1 + 2 * n);
    REP(i, 1, 2 * n) {
        if (i % 2 == 1) {
            ans += l[i];
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

ll d;
vector<vl> s;
vl c(26);

void eval(vl &t, vl &v) {
  vl last(26, -1);
  ll score = 0;
  rep(i, d) {
    last[t[i]] = i;
    score += s[i][t[i]];
    rep(j, 26) score -= c[j] * (i - last[j]);
    v[i] = score;
  }
}

int main() {
  cin >> d;
  rep(i, 26) cin >> c[i];
  s.resize(d, vl(26));
  rep(i, d) rep(j, 26) cin >> s[i][j];

  // for B
  vl t(d), v(d);
  rep(i, d) {
    cin >> t[i];
    t[i]--;
  }
  eval(t, v);
  rep(i, d) cout << v[i] << '\n';
}

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

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;

int len, n, m, d[100005];

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

  while (cin >> len, len) {
    fill(d, d + 100005, INF);
    cin >> n >> m;
    for (int i = 1; i < n; ++i) {
      cin >> d[i];
    }

    d[0] = 0;
    d[n] = len;
    sort(d, d + n + 1);

    int ans = 0;
    for (int i = 0; i < m; ++i) {
      int k, l = 0, r = n + 1;
      cin >> k;

      while (1 <= r - l) {
	int j = (l + r) / 2;

	if (d[j] <= k && k <= d[j + 1]) {
	  if (abs(k - d[j]) < abs(k - d[j + 1]))
	    l = j;
	  else
	    l = j + 1;
	  break;
	}

	if (k < d[j])
	  r = j;
	else
	  l = j + 1;
      }

      ans += abs(k - d[l]);
    }

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

Measured memory_bytes: 1992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _001_FindingMissingCards
{

    class Program
    {
        static void Main()
        {
            var givenNum = Convert.ToInt32(Console.ReadLine());
            var tmp1 = Console.ReadLine().Split(' ');
            var sample1 = new double[givenNum];
            for (int i = 0; i < tmp1.Length; i++)
            {
                sample1[i] = Convert.ToDouble(tmp1[i]);
            }
            var tmp2 = Console.ReadLine().Split(' ');
            var sample2 = new double[tmp2.Length];
            for (int i = 0; i < tmp2.Length; i++)
            {
                sample2[i] = Convert.ToDouble(tmp2[i]);
            }
            double d1 = 0;
            for (int i = 0; i < sample1.Length; i++)
            {
                d1 += Math.Abs(sample1[i] - sample2[i]);
            }
            Console.WriteLine(d1);

            double d2 = 0;
            for (int i = 0; i < sample1.Length; i++)
            {
                d2 += Math.Pow(Math.Abs(sample1[i] - sample2[i]),2.0);
            }
            d2 = Math.Sqrt(d2);
            Console.WriteLine(d2);

            double d3 = 0;
            for (int i = 0; i < sample1.Length; i++)
            {
                d3 += Math.Pow(Math.Abs(sample1[i] - sample2[i]), 3.0);
            }
            d3 = Math.Pow(d3,1.0/3.0);
            Console.WriteLine(d3);

            double d4 = 0;
            for (int i = 0; i < sample1.Length; i++)
            {
                double a = Math.Abs(sample1[i] - sample2[i]);
                if (d4 < a)
                {
                    d4 = a;
                }
            }
            Console.WriteLine(d4);
        }
    }
}

Measured memory_bytes: 9580
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m
       then upper_bound m r p
       else upper_bound l m p

let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  Array.sort compare as_;
  Printf.printf "%d\n" @@ succ @@ upper_bound (-1100000000000000000) 1100000000000000000 @@ fun p ->
    let somme = Array.fold_left ( + ) 0 @@ Array.init n @@ fun i ->
      if 0 <= as_.(i) then
        upper_bound 0 (i + 1) @@ function
          | 0 -> true
          | n -> as_.(i) * as_.(n - 1) <= p
      else
        ( - ) i @@ lower_bound (-1) i @@ fun n ->
          if n = i
          then true
          else as_.(i) * as_.(n) <= p in
    somme < k

Measured memory_bytes: 21412
#include <iostream>
using namespace std;
int max(int a, int b) {
    if(a > b) return a;
    else return b;
}


int main(int argc, const char * argv[]) {
    int a, b, c, m;
    cin >> a >> b >> c;
    m = max( max (a, b), c);
    cout << a + b + c - m << endl;
    return 0;
}

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

const int MAX = 10010;
const int INF = INT_MAX;

int n;
int dist[MAX];
typedef pair<int, int> VC;
typedef pair<int, int> VD;
vector< vector<VC> > G;

void dijkstra(int s)
{
  priority_queue<VD, vector<VD>, function<bool(VD, VD)>> que(
    [](VD a, VD b) { return a.second >= b.second; }
  );

  dist[s] = 0;
  que.push(make_pair(s, dist[s]));
  while (!que.empty()) {
    VD vd= que.top(); que.pop();
    int u = vd.first, d = vd.second;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].first, c = G[u][i].second;
      if (dist[v] > d + c) {
        dist[v] = d + c;
        que.push(make_pair(v, dist[v]));
      }
    }
  }
}

int main()
{
  cin >> n;

  fill(dist, dist+n, INF);
  G = vector< vector<VC> >(n);

  for (int i = 0; i < n; i++) {
    int u, k; cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c; cin >> v >> c;
      G[u].push_back(make_pair(v, c));
    }
  }

  dijkstra(0);

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

  return EXIT_SUCCESS;
}




Measured memory_bytes: 7856