akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<pair<int,pii>>X(N);
  for(int i=0;i<N;i++){
    int x,y,h;
    cin>>x>>y>>h;
    X[i]={h,{x,y}};
  }
  sort(rng(X));
  reverse(rng(X));
  int b=X[0].first-100;
  for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
      int x0=X[0].second.first;
      int y0=X[0].second.second;
      ll h0=X[0].first;
      ll h=h0+abs(x0-x)+abs(y0-y);
      bool ok=true;
      for(int i=0;i<N;i++){
        int nx=X[i].second.first;
        int ny=X[i].second.second;
        ll nh=X[i].first;
        if(max(h-abs(nx-x)-abs(ny-y),0ll)!=nh){
          ok=false;
          break;
        }
      }
      if(ok){
        cout<<x<<" "<<y<<" "<<h<<endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, l) = readLine().split(' ').map(_.toInt)
  lazy val sum: Int = n * l + (1 until n).sum
  val result = (n, l) match {
    case (_n, _l) if _l > 0 =>
      sum - _l
    case (_n, _l) if _l <= 0 && _l > -_n =>
      sum
    case (_n, _l) =>
      sum - (_l + _n - 1)
  }
  println(result)
}

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

L = [i for i in range(1, N+1)]
M = []
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

for i in range(N):
    if digitSum(L[i]) >= A and digitSum(L[i]) <= B:
        M.append(L[i])
        

        
print(sum(M))

Measured memory_bytes: 73556
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,M,K,l[200030],r[200300],res=0;
string str;


int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M>>K;
    if((-N-M-K+3*max({N,M,K}))%2==0){
        cout<<(-N-M-K+3*max({N,M,K}))/2<<endl;
    }else{
        
        cout<<(-N-M-K+3*max({N,M,K}))/2+2<<endl;
    }
    
}    


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(' ')))
A = sorted(A,reverse=True)
ans = A[0]
cnt = 1
i = 1
while cnt < N:
    for j in range(2):
        cnt += 1
        if cnt >= N:
            break
        ans += A[i]
    i += 1
print(ans)

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

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

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

using namespace std;

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

    if(a == b && b == c){
        cout << "No" << endl;
    }else if(a == b || b == c || a == c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

void Main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int a[10005],b[10005],cnt;
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			if((n&1)&&j!=n-i||((n&1)^1)&&j!=n+1-i)
				a[++cnt]=i,b[cnt]=j;
		}
	cout<<cnt<<endl;
	for(int i=1;i<=cnt;i++) cout<<a[i]<<' '<<b[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	long long box, x;
	long long a[100000];
	long long cnt = 0;
	long long tmp;

	cin >> box;
	cin >> x;

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

	for(long long i = 1; i < box; i++) {
		if(a[i] + a[i-1] > x)	{
			tmp = a[i] + a[i-1] - x;
			if(a[i] > tmp){
				a[i] -= tmp;
			}
			else {
				a[i-1] = tmp - a[i];
				a[i] = 0;
			}
			cnt += tmp;
		}
	}

	cout << cnt;
	return 0;

}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < s.size(); ++i) {
    if(i % 2 == 1 && s[i] == 'g') {
      ans++;
    } else if(i % 2 == 0 && s[i] == 'p') {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 1e5 + 5;

vector < vector < int > > adj (N);
vector < int > side (N, -1);
int cnt0 = 0, cnt1 = 0;

bool check_bipartite () {
  side[1] = 0;
  queue < int > q;
  q.push (1);
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (auto to : adj[u]) {
      if (side[to] == -1) {
        side[to] = side[u] ^ 1;
        q.push (to);
      } else if (side[u] == side[to]) {
        return false;
      }
    }
  }

  return true;
}

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back (v);
    adj[v].push_back (u);
  }

  if (check_bipartite ()) {
    for (int i = 1; i <= n; i++) {
      if (side[i]) cnt1++;
      else cnt0++;
    }
    ll ans = (ll)cnt0 * cnt1;
    cout << max ((ll)0, ans - m) << '\n';
  } else {
    ll ans = ((ll)n * (n - 1)) / 2;
    cout << max ((ll)0, ans - m) << '\n';
  }
}


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

l=10**(n-1)
if n==1:
    l=0
for i in range(l,10**n):
    flag=True
    s=str(i)
    for x,y in a:
        if s[x-1]!=str(y):
            flag=False
    if flag==True:
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3064
#include <cstdint>
#include <vector>

using namespace std;

#define TREE_SIZE 100000

struct node_t {
  int32_t parent;
  int32_t left_child;
  int32_t right_sibling;
};

static node_t trees[TREE_SIZE];

void rooted_tree_init()
{
  for (uint32_t i = 0; i < TREE_SIZE; i++) {
    trees[i].parent = -1;
    trees[i].left_child = -1;
    trees[i].right_sibling = -1;
  }
}

void rooted_tree_add(int32_t index, vector<int32_t> children)
{
  if (children.size() > 0) {
    trees[index].left_child = children[0];

    for (uint32_t i = 0; i < children.size(); i++) {
      trees[children[i]].parent = index;
      if (i + 1 < children.size()) {
        trees[children[i]].right_sibling = children[i + 1];
      }
    }
  }
}

void rooted_tree_info(int32_t index, int32_t &parent, vector<int32_t> &children, size_t &depth)
{
  parent = trees[index].parent;

  int32_t child = trees[index].left_child;
  if (child != -1) {
    children.push_back(child);
    int32_t sibling = trees[child].right_sibling;
    while (sibling != -1) {
      children.push_back(sibling);
      sibling = trees[sibling].right_sibling;
    }
  }

  depth = 0;
  int32_t p = parent;
  while (p != -1) {
    depth++;
    p = trees[p].parent;
  }
}

#if !defined(TEST)
#include <iostream>
int32_t main()
{
  rooted_tree_init();

  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    int32_t index, size;
    cin >> index >> size;

    vector<int32_t> children;
    for (uint32_t j = 0; j < size; j++) {
      int32_t val;
      cin >> val;
      children.push_back(val);
    }
    rooted_tree_add(index, children);
  }

  for (uint32_t i = 0; i < num; i++) {
    int32_t parent;
    size_t depth;
    vector<int32_t> children;
    rooted_tree_info(i, parent, children, depth);
    cout << "node " << i << ": parent = " << parent << ", depth = " << depth << ", ";

    if (parent == -1) {
      cout << "root, [";
    } else if (children.size() == 0) {
      cout << "leaf, [";
    } else {
      cout << "internal node, [";
    }

    for (uint32_t j = 0; j < children.size(); j++) {
      if (j != 0) cout << ", ";
      cout << children[j];
    }
    cout << "]" << endl;
  }
  return 0;
}
#endif

Measured memory_bytes: 4712
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=list(map(int,input().split()))
b.sort(reverse=True)
c=list(map(int,input().split()))
c.sort(reverse=True)
d=[i+j for i in a for j in b]
d.sort(reverse=True)
e=[i+j for i in c for j in d[:k]]
e.sort(reverse=True)
for i in range(k):
    print(e[i])

Measured memory_bytes: 207520
using System;

namespace _0173
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 9; i++)
            {
                string[] x = Console.ReadLine().Split();
                int morning = int.Parse(x[1]);
                int afternoon = int.Parse(x[2]);
                Console.WriteLine(x[0] + " " + (morning + afternoon) + " " + (morning * 200 + afternoon * 300));
            }
        }
    }
}

Measured memory_bytes: 9088
#include<stdio.h>


#include<stdlib.h>


#include<string.h>


int main(void)


{


char num_str[1002];


int num;


long sum = 0;


int i;


char tmp;


while (1)


{


fgets(num_str,sizeof(num_str),stdin);


if (num_str[0] == '0') break;


for (i = 0; i < strlen(num_str)-1; i++)


{


tmp = num_str[i];


num = atoi(&tmp);


sum = sum + num;


}


printf("%ld\n",sum);


sum = 0;


memset(num_str,1002,0);


}


return 0;


}

Measured memory_bytes: 532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	ll n,a,b;cin>>n>>a>>b;
	if(a>b||(n==1&&a<b)) cout<<0<<endl;
	else{
		ll ans=(b*n+a-b)-(a*n+b-a)+1;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;cin>>s;
  if(s=="SUN")
    cout<<7<<endl;
  else if(s=="MON")
    cout<<6<<endl;
  else if(s=="TUE")
    cout<<5<<endl;
  else if(s=="WED")
    cout<<4<<endl;
  else if(s=="THU")
    cout<<3<<endl;
  else if(s=="FRI")
    cout<<2<<endl;
  else 
    cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long a, b;

int main(){
    scanf("%ld%ld", &a, &b);
    if(a < b){
        for(int i = 0; i < b; i++){
            printf("%ld", a);
        }
    }else{
        for(int i = 0; i < a; i++){
            printf("%ld", b);
        }
    }
    printf("\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

ll n,ans;
vector<ll> dp,num;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		ans=-inf;
		dp=vector<ll>(n);
		num=vector<ll>(n);
		for(int i=0;i<n;i++) cin>>num[i];
		dp[0]=num[0];
		for(int i=0;i<n-1;i++) dp[i+1]=max(num[i+1],num[i+1]+dp[i]);
		for(int i=0;i<n;i++) ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
}

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

#define int long long

int n, m, d;
double ans;

main(void) {
	cin >> n >> m >> d;
	if(d == 0) {
		ans = (m - 1) * (double)(1. / n);
		printf("%.12lf\n", ans);
	}
	else {
		ans = (m - 1) * 2 * (double) (1.0 / n) * (n - d) * (double) (1.0 / n);
		printf("%.12lf\n", ans);
	}
}

Measured memory_bytes: 256
main = do
  [a,b,c,x,y] <- fmap (map read . words) getLine
  print (solve a b c x y)


solve :: Int -> Int -> Int -> Int -> Int -> Int
solve a b c x y =
  minimum [buyAB, buyC, buyAC, buyBC]
  where
    buyAB  = a*x + b*y
    buyC   = (max x y)*2*c
    buyAC  = 2*c*x + b*(max 0 (y-x))
    buyBC  = a*(max 0 (x-y)) + 2*c*y

Measured memory_bytes: 508
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define N 10000000
#define INF 9999999
typedef struct{
    int dis;
    int e;
}Load;
typedef struct{
    int pos;
    int rest;
}Data;
Data queue[N];
int head,num;
void enqueue(int pos,int rest){
    if(num<N){
        queue[(head+num)%N].pos=pos;
        queue[(head+num)%N].rest=rest;
        num++;
    }else{
        printf("エラー");
        exit(1);
    }
}
Data dequeue(int cost[100][101]){
    int index=head;
    int min=cost[queue[head].pos][queue[head].rest];
    for(int i=head+1;i<head+num;i++){
        if(min>cost[queue[i%N].pos][queue[i%N].rest]){
            min=cost[queue[i%N].pos][queue[i%N].rest];
            index=i%N;
        }
    }
    Data tmp=queue[head]; queue[head]=queue[index]; queue[index]=tmp;
    Data d={-1,-1};
    if(num>0){
        d=queue[head];
        head=(head+1)%N;
        num--;
    }
    return d;
}
int main(void){
    while(1){
        int n,m,L;
        scanf("%d%d%d",&n,&m,&L);
        if(n+m+L==0) break;
        Load dist[100][100]={0};
        int cost[100][101];
        rep(i,100) rep(j,101) cost[i][j]=INF;
        rep(i,m){
            int a,b,d,e;
            scanf("%d%d%d%d",&a,&b,&d,&e);
            a--; b--;
            dist[a][b].dis=dist[b][a].dis=d;
            dist[a][b].e=dist[b][a].e=e;
        }
        head=num=0;
        cost[0][L]=0;
        enqueue(0,L);
        while(1){
            Data tmp=dequeue(cost);
            int pos=tmp.pos,rest=tmp.rest;
            if(pos==n-1) continue;
            if(pos==-1) break;
            for(int i=0;i<n;i++){
                if(pos==i||dist[pos][i].dis==0) continue;
                if(rest<dist[pos][i].dis){
                    if(cost[i][rest]>cost[pos][rest]+dist[pos][i].e){
                        cost[i][rest]=
                        cost[pos][rest]+dist[pos][i].e;
                        enqueue(i,rest);
                    }
                }
                else{
                    if(cost[i][rest-dist[pos][i].dis]>
                       cost[pos][rest]){
                        cost[i][rest-dist[pos][i].dis]=
                        cost[pos][rest];
                        enqueue(i,rest-dist[pos][i].dis);
                    }
                    if(cost[i][rest]>cost[pos][rest]+dist[pos][i].e){
                        cost[i][rest]=
                        cost[pos][rest]+dist[pos][i].e;
                        enqueue(i,rest);
                    }
                }
            }
        }
        /*for(int i=0;i<n;i++){
            for(int j=0;j<=L;j++){
                printf("%5d ",cost[i][j]);
            }puts("");
        }puts("");*/
        int min=INF;
        for(int i=0;i<=L;i++){
            if(min>cost[n-1][i]) min=cost[n-1][i];
        }
        printf("%d\n",min);
    }
}



Measured memory_bytes: 2104
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		long sum=0,n=stdIn.nextLong();
		for(int i=0;i<n;i++) sum+=stdIn.nextLong();
		System.out.println(sum/n);
	}
}

Measured memory_bytes: 12000
n, k, q = map(int, input().split())
a = []
for i in range(q):
    a.append(int(input()))

score = [k - q] * n
for ai in a:
    score[ai - 1] += 1

print("\n".join(map(lambda x: "Yes" if x > 0 else "No", score)))

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

int main(void){
    int n;
    cin >> n;
    
    int a[100000];
    int i;
    for(i = 0; i < n; i++){
        cin >> a[i];
        if((a[i] + n) % 2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    sort(a, a + n);
    
    i = 0;
    if(n % 2 == 1){
        if(a[0] != 0){
            cout << 0 << endl;
            return 0;
        }
        i++;
    }
    
    for( ; i < n; i += 2){
        if(!(a[i] == a[i + 1] && a[i] == i + 1)){
            cout << 0 << endl;
            return 0;
        }
    }
    
    long long ans = 1;
    for(i = 1; i <= n / 2; i++){
        ans *= 2;
        ans %= 1000000000 + 7;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

		int n = sc.nextInt();

		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			if ("AC".equals(s)) {
				ac++;
			} else if ("WA".equals(s)) {
				wa++;
			} else if ("TLE".equals(s)) {
				tle++;
			} else if ("RE".equals(s)) {
				re++;
			}
		}
		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);
	}
}

Measured memory_bytes: 58204
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<ll,ll>

struct sequence_
{
    static const int N=2e5+10;
    int n,m,h[N],b[N],a[N];
    
    sequence_(int n_, int m_) : n(n_), m(m_){}
    
    bool add(int x, int index)
    {
        a[index] = x;
        int y=x-h[x];
        y=max(1,y);
        b[y]++;
        h[x]++;
        if(b[y] > 1)
        {
            return true;
        }
        return false;
    }
    
    int swap(int x, int y)
    {
        int ans = 0;
        h[a[x]]--;
        int z=a[x]-h[a[x]];
        z=max(z,1);
        b[z]--;
        if(b[z]==0) ans++;
        z=y-h[y];
        z=max(z,1);
        if(b[z]==0) ans--;
        b[z]++;
        h[y]++;
        a[x]=y;
        return ans;
    }
};


int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    sequence_ s(n,m);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        if(s.add(x, i))
        {
            ans++;
        }
    }
    while(m--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        ans += s.swap(x, y);
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

ll kai[200001];
ll mokai[200001];

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret*x%MOD;
        x = x*x%MOD;
        y /= 2;
    }
    return ret;
}

void init (int _n) {
    kai[0] = 1;
    for (int i = 1; i <= _n; i++) kai[i] = kai[i-1]*i%MOD;
    for (int i = 0; i <= _n; i++) mokai[i] = mod_pow(kai[i],MOD-2);
}

ll conb (ll x, ll y) {
    ll z = x-y;
    if (z < 0) return 0;
    ll ret = kai[x]*mokai[y]%MOD;
    ret = ret*mokai[z]%MOD;
    return ret;
}

ll n, m, k;
ll ans = 0;

int main() {
    cin >> n >> m >> k;
    init(200000);
    {
        ll tmp = conb(n*m-2, k-2);
        tmp = tmp * m % MOD; tmp = tmp * m % MOD;
        ll sum = 0;
        for (ll d = 1; d < n; d++) {
            sum = (sum + (n-d) * d) % MOD;
        } 
        ans = tmp * sum % MOD;
    }
    {
        ll tmp = conb(n*m-2, k-2);
        tmp = tmp * n % MOD; tmp = tmp * n % MOD;
        ll sum = 0;
        for (ll d = 1; d < m; d++) {
            sum = (sum + (m-d) * d) % MOD;
        } 
        ans = (ans + tmp * sum) % MOD;
    }
    cout << ans << endl;
}


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


int main() {
	long N;
	cin >> N;
	long long AC = 0, WA = 0, TLE = 0, RE = 0;
	rep(i, N) {
		string a;cin >> a;
		if(a == "AC") AC++;
		if(a == "WA") WA++;
		if(a == "TLE") TLE++;
		if(a == "RE") RE++;
	}
	cout << "AC x " << AC << endl; 
	cout << "WA x " << WA << endl; 
	cout << "TLE x " << TLE << endl; 
	cout << "RE x " << RE<< endl; 
}

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

int N, A[1 << 18], B[1 << 18];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) { cin >> A[i]; B[i] = A[i]; }
	sort(B, B + N);
	for (int i = 0; i < N; i++) {
		if (A[i] == B[N - 1]) cout << B[N - 2] << endl;
		else cout << B[N - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
t = [int(input()) for i in range(5)]
k=int(input())
n_1=0
n_2=0
for i in reversed(range(5)):
    for j in range(0,i):
        if k<(t[i] - t[j]):
            n_1=n_1+1
if n_1>0:
    print(':(')
else:
    print('Yay!')
        

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N,K;
  cin>>N>>K;
  int arr[N];
  
  for(int i=0;i<N;i++)
  {
   cin>>arr[i];
    }
   sort(arr,arr+N);
  long long int sum=0;
  for(int i=0;i<N-K;i++)
{
  sum=sum+arr[i];}
  cout<<sum;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n;
    cin >> n;
    cout << n*(n-1)/2;
    return 0;
}

Measured memory_bytes: 256
#AGC011A

n,c,k=map(int,raw_input().split())
ll=[]
for i in xrange(n):
 temp=int(raw_input())
 ll.append(temp)
l=sorted(ll)

cnt=0
i=0
r=0
while i<n:
 if l[i]-l[r]>k:
  cnt+=1
  r=i
  i+=1
 elif i-r>=c:
  cnt+=1
  r=i
  i+=1
 else:
  i+=1

print cnt+1


Measured memory_bytes: 7104
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int MOD = 1000000007;

int main() {
  IN(N);

  bool is_prime[1001];
  REP(i, 1001)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;

  REP(i, N+1) {
    if (!is_prime[i])
      continue;
    for (int j = i * 2; j <= N; j += i)
      is_prime[j] = false;
  }
  ll ans = 1;
  REP(i, N+1) {
    if (!is_prime[i])
      continue;
    int j = i, count = N / j;
    while (N / j > 0) {
      j *= i;
      count += N / j;
    }
    ans *= count + 1;
    ans %= MOD;
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 


 
int main(){
	//in_o();
	int n;
	VI a;
	cin>>n;
	FOR(i,0,n){
		int x;
		cin>>x;
		a.PB(x);
	}
	int l=0,r=0;
	FOR(i,0,n){
		l=min(l,a[i]),r=max(r,a[i]);
	}
	int ans=INT_MAX;
	FOR(i,l,r+1){
		int p=0;
		FOR(j,0,n){
			p+=SQ(a[j]-i);
		}
		ans=min(ans,p);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s;
        
        while((s=br.readLine())!=null){
            String[] str = s.split(" ");
            
            int n = Integer.parseInt(str[0]);
            int x = Integer.parseInt(str[1]);
            
            if(n==0 && x==0) break;
            
            int count=0;
            
            for(int i=1; i<n; ++i){
                for(int j=i; j<n; ++j){
                    
                    if(i==j) continue;
                    
                    int num = x - (i+j);
                    if(num<1) break;
                    if(num<j) break;
                    if(i != num && j != num && num <= n) count++;
                    num = 0;
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 24324
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())

vector<ll> r(100000);//反転時間の個数、最大10^5個
vector<ll> t(100000);//問われる時間を保存する配列 指定するクエリ個数、
vector<ll> init(100000);//初期に砂入ってる量を保存する配列 指定するクエリと同じ個数


//reference : http://arc082.contest.atcoder.jp/submissions/1565659

void solve(){
  ll x,n;//砂の量の最大量,反転回数
  cin >> x >> n;
  rep(i,n)cin >> r[i];

  ll tt;
  cin >> tt;//クエリの数
  rep(i,tt){ cin >> t[i] >> init[i];}


  ll a = 0;
  ll val_a = 0;//一番小さい値
  ll b = x;
  ll val_b = x;//一番大きい値
  ll dir = -1;//現在は増えるのか減るのか
  ll ptr = 0; //クエリの番号

  rep(i,n+1){//反転回数がiのあとの動作
    while(ptr < tt && (i==n || t[ptr] <= r[i])){//クエリが残ってある、クエリに問われる時間が次の反転時間以下のとき
      ll now = -1;
      //＿／￣の3区間に分類
      if(init[ptr] <= a) now = val_a;//＿の部分
      else if(b<=init[ptr]) now = val_b; //￣の部分
      else now = val_a+(init[ptr]-a);  //／の部分で、a<init[ptr]<b
    

      now +=(t[ptr]-(i==0 ? 0:r[i-1]))*dir;//時間*増減方向*(1val/s)
      now = max(now,(ll)0);//負なら0
      now = min(now,x);//最大値超えらたx
      cout << now << endl;

      ptr++;
    }
  
    //反転r[i]の処理
    if(i<n){
      int pass = r[i]-(i==0?0:r[i-1]);//経過した時間
      //dir:減るか増えるか
      //dir*pass = この空間の増減量
      val_a += dir*pass;
      val_b += dir*pass;

      if(val_b < 0){//全てが0
	a = 0;
	val_a =0;
	b = 0;
	val_b = 0;
      }
      else if(x<val_a){//全てが最大
	a = 0;
	val_a = x;
	b = 0;
	val_b = x;
      }else {//[a,b]の更新
	if(val_a<0){
	  a-=val_a;//aを右にずらす
	  val_a=0;
	}
	if(x<val_b){
	  //val_b-x分、上限xを超えている。
	  //b-=超えた分をずらす
	  b-=val_b-x;//bを左にずらす
	  val_b=x;
	}
	//a,bの変更がない場合val_a,val_bは既に経過時間分変更してある。
      }
      dir = -dir;//増減を回転
    }
  }
  cout << flush;
}


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

  solve();
  
  return 0;
}


Measured memory_bytes: 3584
n = gets.to_i
pys = []
n.times do
  pys << gets.split.map(&:to_i)
end

i = 0
res = 'No'

while i < n
 	if pys[i][0]%2 == (pys[i][1]+pys[i][2])%2 && pys[i][0] >= (pys[i][1]+pys[i][2])
 		res = 'Yes'
 	else
 		res = 'No'
 		break
 	end
 	i += 1
 end

 puts res

Measured memory_bytes: 9596
# coding: utf-8

inputchar = raw_input()
answer = ""
delta = ord('a') - ord('A')

for c in inputchar:
	if ord(c) >= ord('a') and ord(c) <= ord('z'):
		new_c = chr(ord(c) - delta)
		answer += new_c
	else:
		answer += c

print(answer)


Measured memory_bytes: 4640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

char change(int a,int b,char c){
    return c==' '?c:(a*(c-'a')+b)%26+'a';
}

void run(){
    int n;
    cin>>n;
    cin.ignore();
    while(n--){
        string s;
        getline(cin,s);
        REP(i,3,27){
            if(i==2||i==13||i==26)continue;
            REP(j,1,27){
                string ans=s;
                rep(k,s.length()){
                    ans[k]=change(i,j,s[k]);
                }
                if(ans.find("this")!=string::npos||ans.find("that")!=string::npos){
                    cout<<ans<<endl;
                    goto BR;
                }
            }
        }
        BR:;
    }
}


Measured memory_bytes: 3172
n, m = map(int, input().split())
A, B = [list(map(int, input().split())) for r in range(n)], [list(map(int, input().split())) for r in range(m)]
for i in range(n):
    Ci = 0
    for j in range(m):
        Ci += A[i][j] * B[j][0]
    print(Ci)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int a, b;
    cin >> a >> b;
    int amin = ceil(a * 12.5);
    int amax = (a+1) * 12.5;
    int bmin = ceil(b * 10);
    int bmax = (b+1) * 10;
    if(bmin < amax && amin < bmax) cout << max(amin, bmin) << endl;
    else cout << -1 << endl;
}


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

namespace flow{
	const int _ = 1e6 + 7 , __ = 1e7 + 7;
	struct Edge{int end , upEd , f;}Ed[__];
	int head[_] , dep[_] , cur[_] , cntEd = 1 , S , T;

	void addEd(int a , int b , int c){Ed[++cntEd] = (Edge){b , head[a] , c}; head[a] = cntEd;}
	void addE(int a , int b , int c){addEd(a , b , c); addEd(b , a , 0);}
	
	queue < int > q;
	bool bfs(){
		memset(dep , 0 , sizeof(int) * (T + 1)); while(!q.empty()) q.pop();
		dep[S] = 1; q.push(S);
		while(!q.empty()){
			int t = q.front(); q.pop();
			for(int i = head[t] ; i ; i = Ed[i].upEd)
				if(Ed[i].f && !dep[Ed[i].end]){
					dep[Ed[i].end] = dep[t] + 1;
					if(Ed[i].end == T){memcpy(cur , head , sizeof(int) * (T + 1)); return 1;}
					q.push(Ed[i].end);
				}
		}
		return 0;
	}

	int dfs(int x , int mn){
		if(x == T) return mn;
		int sum = 0;
		for(int &i = cur[x] ; i ; i = Ed[i].upEd)
			if(Ed[i].f && dep[Ed[i].end] == dep[x] + 1){
				int t = dfs(Ed[i].end , min(mn - sum , Ed[i].f));
				sum += t; Ed[i].f -= t; Ed[i ^ 1].f += t;
				if(sum == mn) break;
			}
		return sum;
	}

	int Dinic(int s , int t){int sum = 0; S = s; T = t; while(bfs()) sum += dfs(s , 1e9); return sum;}
}using namespace flow;

int read(){
	int a = 0; char c = getchar();
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)){a = a * 10 + c - 48; c = getchar();}
	return a;
}

int N , pos[200003] , E[200003][2]; vector < int > id[200003];

int main(){
	N = read();
	for(int i = 2 ; i <= N ; ++i) addE(0 , i , 1);
	for(int i = 1 ; i < N ; ++i){
		addE(N + i , N + N , 1);
		for(int p , x = read() ; x ; --x){addE(p = read() , i + N , 1); id[p].push_back(i);}
	}
	if(Dinic(0 , N + N) != N - 1){puts("-1"); return 0;}
	for(int i = 2 ; i <= N ; ++i)
		for(int j = head[i] ; j ; j = Ed[j].upEd)
			if(Ed[j].end > N && !Ed[j].f){pos[Ed[j].end - N] = i; break;}
	queue < int > q; q.push(1);
	while(!q.empty()){
		int t = q.front(); q.pop();
		for(auto x : id[t]) if(pos[x]){E[x][0] = t; E[x][1] = pos[x]; q.push(pos[x]); pos[x] = 0;}
	}
	for(int i = 1 ; i < N ; ++i) printf("%d %d\n" , E[i][0] , E[i][1]);
	return 0;
}

Measured memory_bytes: 30464
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner in = new Scanner(System.in);
        int [] hs = new int[10];
        for(int i=0;i<10;i++){
            hs[i] = in.nextInt();
        }
        Arrays.sort(hs);
        for(int i=0;i<3;i++){
            System.out.println(hs[10-i-1]);
        }
    }
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a<b){
        cout << "a < b" <<endl ;
    }else if(a>b){
        cout << "a > b"<< endl;       
    }else{
        cout << "a == b"<< endl;
    }
    return 0;
}

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

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

ll a, b;
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll cal(ll x) { return b / x - (a - 1) / x; }

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

  ll c, d;
  cin >> a >> b >> c >> d;
  ll all = b - a + 1;
  ll z = lcm(c, d);
  cout << all - (cal(c) + cal(d) - cal(z)) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int max1,max2;
        if(a[0]<=a[1]){
            max1 = 1;
            max2 = 0;
        }else{
            max1 = 0;
            max2 = 1;
        }
        for(int i=2;i<n;i++){
            if(a[max1] <= a[i]){
                max2 = max1;
                max1 = i;
            }else if(a[max2] <=a[i]){
                max2 = i;
            }
        }
        for(int i=0;i<n;i++){
            if(i==max1){
                System.out.println(a[max2]);
            }else{
                System.out.println(a[max1]);
            }

        }
    }

}

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int d[1000];
  set<string> num;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }

  for(int i = 1; i <= n/10 + 1; i++){
    for(int j = 0; j < n-i+1; j++){
      string str;
      for(int k = 0; k < i; k++)
        str.append(to_string(d[j+k]));
      num.insert(str);
    }
  }


  for(int i = 0; i < 1000; i++){
    if(num.find(to_string(i)) == num.end()){
      cout << i << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 18860
s = input()

if(s == 'hi'):
    print('Yes')
elif(s == 'hihi'):
    print('Yes')
elif(s == 'hihihi'):
    print('Yes')
elif(s == 'hihihihi'):
    print('Yes')
elif(s == 'hihihihihi'):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
/**
 *    author:  tourist
 *    created: 08.10.2017 15:27:37       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    mp[x]++;
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int y;
    scanf("%d", &y);
    if (mp[y] == 0) {
      puts("NO");
      return 0;
    }
    mp[y]--;
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 9600
h, w, m = map(int, input().split())
memo_h = [0 for _ in range(h)]
memo_w = [0 for _ in range(w)]

where = []
for _ in range(m):
    x, y = map(int, input().split())
    where.append((x-1, y-1))
    memo_h[x-1] += 1
    memo_w[y-1] += 1

from collections import Counter
h_cnt = Counter(memo_h)
w_cnt = Counter(memo_w)
h_max = max(memo_h)
w_max = max(memo_w)

ans = h_max + w_max
tmp = 0
for x, y in where:
    if memo_h[x] + memo_w[y] == ans:
        tmp += 1

if tmp == h_cnt[h_max] * w_cnt[w_max]:
    print(ans - 1)
else:
    print(ans)

Measured memory_bytes: 117860
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    int N,K;
    cin >> N >> K;
    int ans = 0;
    REP(i,0,N){
        int x;
        cin >> x;
        ans += min(x,K-x);
    }
    cout << ans * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
int modpow(int X,int Y){
  int sum=X,cnt=1;
  vi A;
  while(cnt<=Y){
    cnt*=2;
    A.pb(sum);
    sum*=sum;
    sum%=MOD;
  }
  int M=A.size();
  int ret=1;
  REP(i,1,M){
    if((1ll<<M-i)<=Y){
      Y-=(1ll<<M-i);
      ret*=A[M-i];
      ret%=MOD;
    }
  }
  return ret;
}
int fac[500000],finv[500000];
void COMinit(){
  fac[0]=fac[1]=finv[0]=finv[1]=1;
  rep(i,2,500000){
    finv[i]=finv[i-1]*modpow(i,MOD-2)%MOD;
    fac[i]=fac[i-1]*i%MOD;
  }
}
int COM(int n,int k){
  if(n<k||n<0||k<0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}
signed main(){
  COMinit();
  int H,W,A,B; cin>>H>>W>>A>>B;
  int ans=COM(H-A-1+B,B)*COM(W-B-1+A,A)%MOD;
  rep(i,B+1,W){
    ans+=(COM(H-A-1+i,i)+MOD-COM(H-A-2+i,i-1))%MOD*COM(W-i-1+A,A)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 8064
d, g = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(d)]

lst1 = list()
for k, pair in enumerate(lst):
    lst1.append([pair[0], pair[1], (k+1)*100, (k+1)*100*pair[0]+pair[1]])
lst = lst1

string = '0' + str(d) + 'b'
str_lst = []
for i in range(0, 2**d):
    str_lst.append(format(i, string))
    
min_count = 10 ** 100
for str1 in str_lst:
    count = 0
    pt = 0
    remain = list()
    for k, qua in enumerate(lst):
        if str1[k] == '1':
            count += qua[0]
            pt += qua[3]
        else:
            remain.append(qua)
    if pt < g:
        qua = remain[-1]
        for i in range(qua[0]-1):
            count += 1
            pt += qua[2]
            if pt >= g:
                break
    if pt >= g:
        if min_count > count:
            min_count = count
            
print(min_count)

Measured memory_bytes: 3064
from sys import stdin
n,k = map(int,stdin.readline().rstrip().split())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
print(len(Base_10_to_n(n,k)))

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

int main(){
  int n; cin >> n;
  int a[100010];
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  int64_t b[100010];
  b[0] = 0;
  for (int i = 0; i < n; i++){
    b[0] += a[i] * (i % 2 ? -1 : 1);
  }
  for (int i = 1; i < n; i++){
    b[i] = 2 * a[i - 1] - b[i - 1];
  }
  for (int i = 0; i < n; i++){
    cout << b[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    vector<int> A(3);
    for ( int i = 0; i < 3; i++ ) {
        cin >> A[i];
    }
    sort( A.begin(), A.end() );

    cout << A[2]*10 + A[1] + A[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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


class P{
	public:
	int a,b,c;
	P(){}
	P(int a,int b,int c):a(a),b(b),c(c){}
};

int main(){
	
	const int N = 20;
	const int B = 2;
	string m[2][N];
	
	P dp[4];
	dp[0]=P(0,0,0);
	dp[1]=P(1,-1,0);
	dp[2]=P(0,-1,0);
	dp[3]=P(1,-1,1);
	
	
	int dx[4]={1,0,-1,0};
	int dy[4]={0,1,0,-1};
	string ds="RDLU";
	
	rep(i,B){
		m[0][i]=m[1][i]="00000000000";
		m[0][i+9/2+B]=m[1][i+9/2+B]="00000000000";
	}
	rep(i,9){
		string s;
		cin>>s;
			
		if(i%2==0){
			m[0][i/2+B]="00"+s+"00"; 
		}
		else{
			m[1][i/2+B]="00"+s+"00";
		}
	}
	
	int x = B;
	int y = B;
	int dir = 0;
	string ans = "";
	while(1){
		if(x==B && y==B && dir==0 && ans.size()!=0)break;
		
		//printf("%d %d %d  [%s]%d\n",x,y,dir,ans.c_str(),ans.size());
		if(ans.size()>50)break;
		
		P right = dp[dir];
		P front = dp[(dir+3)%4];
		
		ans += ds[dir];
		
		if(m[front.a][y+front.b][x+front.c]=='1'){
			dir=(dir+3)%4;	
		}else	if(m[right.a][y+right.b+dy[dir]][x+right.c+dx[dir]]=='0'){
			
			P nr = dp[dir];
			while(m[nr.a][y+nr.b+dy[dir]][x+nr.c+dx[dir]]=='0'){
				x+=dx[dir];
				y+=dy[dir];
				dir=(dir+1)%4;
				nr=dp[dir];
			} 
			x+=dx[dir];
			y+=dy[dir];
		}else{
			x+=dx[dir];
			y+=dy[dir];
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<functional>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int n, x,cnt=0;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int i = 0;
	while (i<n-1) {
		if (x >= a[i]) {
			x -= a[i];
			i++;
			cnt++;
		}else break;
	}
	if (x == a[i]) {
		cnt++;
	}
	cout << cnt << endl;
}

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

int main(void)
{
  int n,q;
  int *S,*T;
  int C=0;
  int i,j;

  scanf("%d",&n);
  S = (int*)malloc(sizeof(int)*n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  T = (int*)malloc(sizeof(int)*q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }

  for(i=0; i<q; i++){
    for(j=0; j<n; j++){
      if(T[i] == S[j]){
	C++;
	break;
      }
    }
  }

  printf("%d\n",C);

  free(S);
  free(T);
  
  return(0);
}

Measured memory_bytes: 632