akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    char c;
    int flag=0;
    for(int i=0; i<N; i++)
    {
        scanf("%c",&c);
        if(c=='Y')  flag=1;
    }
    if(flag)  printf("Four");
    else   printf("Three");
    return 0;
}

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

using namespace std;

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

    vector<vector<int>> F(N, vector<int>(10));
    for (int s = 0; s < N; s++) {
        for (int dt = 0; dt < 10; dt++) {
            cin >> F[s][dt];
        }
    }

    vector<vector<long long>> P(N, vector<long long>(11));
    for (int s = 0; s < N; s++) {
        for (int dt = 0; dt < 11; dt++) {
            cin >> P[s][dt];
        }
    }

    long long tp_max = 1LL << 63;
    for (int day_time_pattern = 1; day_time_pattern < 1 << 10; day_time_pattern++) {
        vector<int> day_times;
        for (int i = 0; i < 10; i++) {
            if (day_time_pattern >> i & 1) {
                day_times.push_back(i);
            }
        }
        long long tp = 0;
        for (int s = 0; s < N; s++) {
            int shop_open_day_time_count = 0;
            for (int dt: day_times) {
                shop_open_day_time_count += F[s][dt];
            }
            tp += P[s][shop_open_day_time_count];
        }
        tp_max = max(tp, tp_max);
    }

    cout << tp_max << endl;
    return 0;
};


Measured memory_bytes: 256
n, q = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  adj[a-1].append(b-1)
  adj[b-1].append(a-1)
c = [0] * n
for _ in range(q):
  p, x = map(int, input().split())
  c[p-1] += x
parent = list(range(n))
stack = [0]
while stack:
  vertex = stack.pop()
  value = c[vertex]
  taboo = parent[vertex]
  for child in adj[vertex]:
    if child != taboo:
      c[child] += value
      parent[child] = vertex
      stack.append(child)
print(' '.join(map(str, c)))

Measured memory_bytes: 66864
#include <iostream>
 
 
using namespace std;
 
  
 
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
    else if (c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    int n,d,x;
    int a[101];

    cin >> n;
    cin >> d >> x;

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

    int day;
    int choco = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= d; j++) {
            day = a[i] * j + 1;
            if (day > d) {
                break;
            }
            choco++;
        }
    }

    choco += x;

    cout << choco << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S = in<string>();
    vector<bool> A(S.size());
    REP(i,S.size()){
        if(S[i] == S[S.size()/2])A[i] = 1;
    }
    int cut = -1;
    RREP(i,S.size()/2){
        if(A[i] == 0 || A[S.size()-i-1] == 0){
            cut = i;
            break;
        }
        cut = -1;
    }
    cout << S.size()-cut-1 << "\n";
}

Measured memory_bytes: 512
/*  -*- coding: utf-8 -*-
 *
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_H = 30, MAX_W = 30;

/* typedef */

typedef int bdt[MAX_H][MAX_W];

/* global variables */

bdt bs, cs;

/* subroutines */

void print_bd(int h, int w, bdt &bs) {
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) printf("%d", bs[y][x]);
    putchar('\n');
  }
}

void drop(int h, int w, bdt &bs) {
  for (int x = 0; x < w; x++)
    for (int y = h - 1, y0 = y; y >= 0; y--) {
      if (y0 > y) y0 = y;
      for (; y0 >= 0 && bs[y0][x] == 0; y0--);
      if (y0 < 0) break;
      if (bs[y][x] == 0) swap(bs[y][x], bs[y0][x]);
    }
}

int erase(int h, int w, bdt &bs, int k) {
  int cnt = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w;) {
      int x0 = x + 1;
      for (; x0 < w && bs[y][x0] == bs[y][x]; x0++);
      if (bs[y][x] > 0 && x0 - x >= k) {
	cnt += (x0 - x) * bs[y][x];
	for (int x1 = x; x1 < x0; x1++) bs[y][x1] = 0;
      }
      x = x0;
    }
  }
  return cnt;
}

/* main */

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  for (int y = 0; y < h; y++) {
    string s;
    cin >> s;
    for (int x = 0; x < w; x++) bs[y][x] = s[x] - '0';
  }

  int maxc = 0;
  for (int y = 1; y < h; y++)
    for (int x = 0; x < w; x++) {
      memcpy(cs, bs, sizeof(bs));
      cs[y][x] = 0;
      drop(h, w, cs);
      //printf("y=%d,x=%d\n", y, x); print_bd(h, w, cs);

      int c = 0;
      for (int bi = 1;; bi <<= 1) {
	int m = erase(h, w, cs, k);
	if (m == 0) break;
	c += bi * m;
	drop(h, w, cs);
      }

      if (maxc < c) maxc = c;
    }

  printf("%d\n", maxc);
  return 0;
}


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

const int INF = 1001001001;

int main(){
  int n;
  string s;
  cin >> n;
  cin >>s;
  string a ;
  string b ;
  if(n%2 == 1){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<n/2;i++){
    a.push_back(s.at(i)); 
  }
  for(int i=(n/2);i<n;i++){
    b.push_back(s.at(i));
  }
  if(a==b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,A;
    cin >> N;
    vector<pair<ll, ll> > pairs;
    REP(i,N){
        cin >> A;
        pairs.push_back(make_pair(A,i+1));
    }
    sort(pairs.begin(),pairs.end());
    REP(i,N){
        cout << pairs[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 2544
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int n,x,l[100000],sum=0,cun=0;
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  for(int i=0;i<n;i++){
    sum+=l[i];
    if(sum<=x){
      cun++;
    }
  }
  cout<<cun+1<<"\n";
  return(0);
}


Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

r = _I()

print(3*r**2)


Measured memory_bytes: 64364
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[100000];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int c=0;
        sort(a,a+n);
        for(int i=0;i<n;)
        {
            if(a[i]==a[i+1])
            {
                c+=2;
                i=i+2;
            }
            if(a[i]!=a[i+1])
            {
                i++;
            }
        }
        printf("%d\n",n-c);
    }
    return 0;
}


Measured memory_bytes: 640
import math

a,b,c=map(int,input().split())
x=a+b-c

if x>=0:
    print("No")
else:
    y=a**2+b**2+c**2+2*(a*b-b*c-c*a)-4*a*b
    if y > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
int main()
{
  string A;
  cin >> A;
  int N = A.size();
  // cout << N << endl;
  int counter = 0;
  char a=A[0];
  bool skipped = false;
  REP(i, N - 1){
    if((skipped == false)&&(A[i + 1] == A[i])){
      i ++;
      counter ++;
      skipped = true;
      // cout << counter<< endl;
    }else{
      skipped = false;
    }
  }
  cout << N - counter << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n, h[100000], an = 0, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (i != 0 && h[i] <= h[i - 1]) {
			an++;
		}
		else {
			if (an > ans)ans = an;
			an = 0;
		}
	}
	if (an > ans)ans = an;
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>

using namespace std;

#define MAXN 200000

int a[MAXN + 1],x[MAXN + 1];

int main(){
    int N;

    scanf("%d",&N);

    for(int i = 1;i <= N;++i)
        scanf("%d",&a[i]);

    int M = 0;

    for(int i = N;i >= 1;--i){
        int aux = 0;

        for(int j = 2 * i;j <= N;j += i)
            aux ^= x[j];

        aux ^= a[i];
        x[i] = aux;
        M += aux;
    }

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

    for(int i = 1;i <= N;++i)
        if(x[i] == 1)
            printf("%d ",i);

    printf("\n");

    return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		String str = sc.next();
		char ch1[] = str.toCharArray();

		for (int i = 0; i < ch1.length; i++) {
			if ((ch1[i] + num) > 90)
				ch1[i] = (char) ((ch1[i] + num) % 90 + 64);
			else
				ch1[i] = (char) ((ch1[i] + num));
			System.out.print(ch1[i]);
		}
	}
}

Measured memory_bytes: 25812
from math import gcd

N = int(input())
A = list(map(int, input().split()))

if N == 2:
    print(max(A))
else:
    r = max(gcd(A[0], A[1]), gcd(A[1], A[2]), gcd(A[2], A[0]))
    a = gcd(A[0], gcd(A[1], A[2]))

    for i in range(3, N):
        r = max(gcd(A[i], r), a)
        a = gcd(A[i], a)
        
    print(r)

Measured memory_bytes: 20780
N = int(input())
H = input().split()
x = []
for i in H:
    x.append(int(i))
ans = 1
flag = 0
for i in range(1, N):
    for j in range(i):
        if x[j] > x[i]:
            flag = 1
    if flag == 0:
        ans += 1
    flag = 0
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>


using namespace std;

typedef int64_t llong;


llong mod(llong a, llong b) {
    llong res = a % b;
    if (res >= 0) {
	return res;
    } else {
	return res + b;
    }
}

llong gcd(llong a, llong b) {
    if (b == 0) {
	return a;
    } else {
	return gcd(b, mod(a, b));
    }
}

llong parse(const string& s) {
    llong i = 0;
    llong r = 0;
    while (s[i] != '.' && i < s.size()) {
	llong d = s[i] - '0';
	r = 10*r + d;
	++i;
    }
    llong r0 = 1000'000'000*r;
    ++i;
    r = 0;
    llong cnt = 0;
    while (i < s.size()) {
	llong d = s[i] - '0';
	r = 10*r + d;
	++i;
	++cnt;
    }
    while (cnt < 9) {
	r = 10*r;
	++cnt;
    }
    return r0 + r;
}

llong index(const llong& a, const llong& p) {
    llong res = 0;
    llong temp = a;
    while (mod(temp, p) == 0) {
	temp /= p;
	++res;
    }
    return res;
}       

int main() {
    llong n = LLONG_MIN;
    cin >> n;
    vector<llong> a(n);
    vector<vector<llong>> data(19, vector<long>(19));

    for (llong i = 0; i < n; ++i) {
	string s;
	cin >> s;
	a[i] = parse(s);
    }

    llong d9 = 1000000000;
    llong d18 = d9*d9;
    llong res = 0;

    for (auto e: a) {
//	cout << e << " " << index(e, 2) << "\n";
	llong i2 = min(index(e, 2), llong(18));
	llong i5 = min(index(e, 5), llong(18));
	data[i2][i5] = data[i2][i5] + 1;
	llong key = d18 / gcd(d18, e);
	if (mod(e, key) == 0) {
	    res -= 1;
	}
    }


    for (int i = 0; i <= 18; ++i) {
	for (int j = 0; j <= 18; ++j) {
	    for (int i1 = 0; i1 <= 18; ++i1) {
		for (int j1 = 0; j1 <= 18; ++j1) {
		    if (i + i1 >= 18 && j + j1 >= 18) {
			res += data[i][j]*data[i1][j1];
		    }
		}
	    }
	}
    }
    cout << res / 2 << "\n";
	    
	    
}


Measured memory_bytes: 4744
#include <iostream>
#include <string>
using namespace std;
int main() {
	string S, T;
	cin >> S >> T;

	int samecount = 0;

	for (int i = 0; i < S.size(); i++) {
		if (S.at(i) == T.at(i)) {
			samecount++;
		}
	}

	cout << S.size() - samecount << endl;
}

Measured memory_bytes: 3856
#include <iostream>
#include <cmath>
#include <stdio.h> 
using namespace std;
int main(){
  int n;
  int x[8],y[8];
  double sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
  cin>>x[i]>>y[i];
  }
  for(int i=0;i<n;i++){
   for(int j=i+1;j<n;j++){
   sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
   }
  }
  printf("%.10f",sum*2/n);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e5+10;
int vis[maxn];
int a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        if(vis[x]==0)
        {
            sum++;
            vis[x]=1;
        }
    }
    if(sum%2==0)
        printf("%d\n",sum-1);
    else
        printf("%d\n",sum);
}


Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextInt();
		long M = scan.nextInt();
		String S = scan.next();
		String T = scan.next();
		scan.close();
		if(S.charAt(0) != T.charAt(0)) {
			System.out.println(-1);
			System.exit(0);
		}
		if(N == M) {
			if(S.equals(T)) {
				System.out.println(N);
			}else {
				System.out.println(-1);
			}
			System.exit(0);
		}
		long l = lcm(N, M);
		long g = gcd((long)N, (long)M);
		if(g == 1) {
			System.out.println(l);
			System.exit(0);
		}
		int L = (int)l;
		Map<Long, Integer> map1 = new HashMap<Long, Integer>();
		Map<Long, Integer> map2 = new HashMap<Long, Integer>();
		for(long i = 1; i < N; i++) {
			Long t = i * (L / N) + 1;
			map1.put(t, (int)i);
		}
		for(long i = 1; i < M; i++) {
			Long t = (long)i * (L / M) + 1;
			map2.put(t, (int)i);
		}

		for(long k : map1.keySet()) {
			if(map2.containsKey(k)) {
				int t1 = map1.get(k);
				int t2 = map2.get(k);
				if(S.charAt(t1) != T.charAt(t2)) {
					System.out.println(-1);
					System.exit(0);
				}
			}
		}

		System.out.println(L);


	}
	static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}
}

Measured memory_bytes: 56924
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/

void test(int r)
{
	ll x;
	cin>>x;
	ll a,b,c;
	int f=0;
	for(a=-120;a<=120;a++)
	{
		for(b=a+1;b<=121;b++)
		{
			if(pow(b,5)-pow(a,5)==x)
			{
				f=1;
				break;
			}
		}
		if(f)
			break;
	}
	// cout<<pow(2,5)-pow(-1,5);
	cout<<b<<" "<<a;
}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
#define N 1000000007
using namespace std;

long long n;
vector<long long> c;
long long memo[200005] = {0};
long long dp[200005] = {0};

long long solve();

int main() {
  int bf = -1;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if(a == bf) continue;
    c.push_back(a);
    bf = a;
  }
  n = c.size();
  cout << solve() << endl;
  return 0;
}

long long solve() {
  dp[1] = 1;
  for(int i = 0; i < 200001; ++i) memo[i] = -1;
  memo[c[0]] = 0;
  for(int i = 1; i < n; ++i) {
    dp[i + 1] = dp[i];
    if(memo[c[i]] != -1) dp[i + 1] += dp[memo[c[i]] + 1];
    dp[i + 1] %= N;
    memo[c[i]] = i;
  }
  return dp[n];
}

Measured memory_bytes: 5104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  string s;
  cin>>s;

  string day[7]={ "SUN","MON","TUE","WED","THU","FRI","SAT"};

  for(int i=0;i<7;i++){
    if(s==day[i]){
      cout<<7-i<<endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;



ll a, b;
int main()
{
        ll n;
        cin >> n;
        ll ans = n-1;
        for(ll i = 1 ; i*i <= n;i++) {
                if(n%i == 0) {
                        ll x=i;
                        ll y=n/i;
                        ans = min(x-1 + y-1 , ans);
                }
        }
        cout << ans << endl;
        return 0;
}


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

int f(int n){
	return (n%10)*((n/10)%10);
}

int main(){
	
	int n , d;
	cin >> n >> d;
	int cnt = 0;
	
	for(int i = 1 ; i <= n ; i++){
		for(int j = 22 ; j <= d ; j++){
			if(j%10<2 or (j/10)%10 < 2)
				continue ;
				
			if(f(j)==i)
				cnt ++;
		}
	}
	cout << cnt << endl;
	
	return 0;
}


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

using namespace std;
typedef long long int ll;

#define INF (1e9)

int N, K;

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

    vector<int> h(N), dp(N, INF);

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

    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int k = 1; k <= K and i + k < N; k++) {
            int cost = abs(h[i] - h[i + k]);
            if (dp[i + k] > dp[i] + cost)
                dp[i + k] = dp[i] + cost;
        }
    }

    cout << dp[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
N,M=map(int,input().split())
cnt=[0]*N
for i in range(M):
    a,b=map(lambda x:int(x)-1,input().split())
    if a>b:
        a,b=b,a
    if a==0:
        cnt[b]+=1
    else:
        cnt[a]+=1
        cnt[b]+=1
for i in range(1,N):
    if cnt[i]%2:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 75316
var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");
  i = 0;
  while (input[i] != 0) {
    arr = input[i].split(" ");
    if (arr[0] == -1 && arr[1] == -1 && arr[2] == -1) {
      break;
    }
    if (arr[0] == -1 || arr[1] == -1) {
      console.log("F");
      i++;
      continue;
    }

    sum = parseInt(arr[0], 10) + parseInt(arr[1], 10);
    if (sum >= 80) {
      console.log("A");
    } else if (sum >= 65) {
      console.log("B");
    } else if (sum >= 50) {
      console.log("C");
    } else if (sum >= 30) {
      if (arr[2] >= 50) {
        console.log("C");
      } else {
        console.log("D");
      }
    } else {
      console.log("F");
    }
    i++;
  }
});

Measured memory_bytes: 7640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long l,r;
    cin >> l >> r;
    long long ans = 2020;
    if((r-l)>=2100){
        cout << 0 << endl;
        return 0;
    }
    else{
        for(long long i = l;i<r;i++){
            for(long long j = i+1;j<=r;j++){
                ans = min(ans,(i*j)%2019);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;

int a[10010];
int b[10010];

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) read(a[i]);
	for(int i=1; i<=n; ++i) read(b[i]);
	
	vector<ll> v;
	for(int i=1; i<=n; ++i) if(a[i]!=b[i]) v.pb(a[i]-b[i]);
	
	while(true){
		ll ps = 0; ll ns = 0;
		for(ll t:v) if(t>0) ps += t; else ns += t;
		if(!ps || ps >= -ns) break;
		vector<ll> vn;
		for(ll x:v) if(x<0){
			ll heru = (-x)/2;
			heru = min(heru, ps);
			x += heru*2; ps -= heru;
			vn.pb(x);
		}
		if(ps > 0){
			int s = vn.size();
			for(ll& x:vn) x += (ps/s)*2;
			ps %= s;
			for(ll& x:vn) if(ps){ --ps; x+=2; }
		}
		v = vn;
	}
	for(ll x:v) if(x>0) puts("No"), exit(0);
	puts("Yes");
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

long long memo[20];

long long get_add(long long input);

long long get_add2(long long count,int count2) {
	long long result;
	if(memo[count2]>0)return memo[count2]-1;
	result=get_add(count-1);
	memo[count2]=result+1;
	return result;
}

long long get_add(long long input) {
	long long result=0;
	long long input2;
	long long input3;
	long long count;
	int count2;
	if(input<=0)return 0;
	for(input2=input,count=1,count2=0;
		input2>=10;
		input2/=10,count*=10,count2++);
	input3=input2;
	if(input2>=4){result+=count;input3--;}
	if(input2>=6){result+=count;input3--;}
	result+=get_add(input-input2*count);
	result+=get_add2(count,count2)*input3;
	return result;
}

int main(void) {
	long long input;
	long long n_add,p_add;
	while(1) {
		scanf("%lld",&input);
		if(input==0)break;
		p_add=0;
		while((n_add=get_add(input))>p_add) {
			input+=n_add-p_add;
			p_add=n_add;
		}
		printf("%lld\n",input);
	}
	return 0;
}

Measured memory_bytes: 408
<?php
while ($input = fgets(STDIN)) {
    $input = array_map('intval', explode(" ", trim($input)));
    $H = $input[0];
    $W = $input[1];
    
    if (($H === 0) && ($W === 0)) {
        exit;
    }
    
    for ($i = 1; $i <= $H; $i++) {
        for ($j = 1; $j <= $W; $j++) {
            if (($i === 1) || ($i === $H)) {
                echo "#";
            } elseif (($j === 1) || ($j === $W)) {
                echo "#";
            } else {
                echo ".";
            }
        }
        echo PHP_EOL;
    }
    echo PHP_EOL;
}
?>


Measured memory_bytes: 9220
#include "bits/stdc++.h"
using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N+2];


void solve()
{
      int n, k;
      cin >> n >> k;

      int ans = abs(n-k);
      ans = min(ans, abs(ans-k));
      if( n <= k )
      {
            cout << ans;
            return;
      }
      else
      {
            int x = n/k;
            ans = n - x*k;
            ans = abs(ans-k);
            ans = min(ans, abs(ans-k));
            cout << ans ;
      }
      

      
}

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

      int test = 1;
      // cin >> test;

      // cout << setprecision(9) << fixed;
      // clock_t z = clock();
      while(test--)solve();
      // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 256
(let* ((n (read))
       (lst (loop :repeat n :collect (read)))
       (m (read))
       (lst-a (loop :repeat m :collect (cons (read) (read)))))
  (mapcar (lambda (cs)
            (let* ((j (copy-list lst)))
              (setf (nth (1- (car cs)) j) (cdr cs))
              (print (reduce #'+ j)))) lst-a))

Measured memory_bytes: 7264
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll ans = 0;

  rep(i, 100) {
    ll num = i * 2 + 1;
    if (num > n)break;
    ll cnt = 0;
    for (int j = 1; j <= num; ++j) {
      if (num % j == 0) ++cnt;
    }
    if (cnt == 8) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==25)cout<<"Christmas"<<endl;
    else if(n==24) cout<<"Christmas Eve"<<endl;
    else if(n==23)cout<<"Christmas Eve Eve"<<endl;
    else {
        cout<<"Christmas Eve Eve Eve"<<endl;
    }

}


Measured memory_bytes: 3628
{-# LANGUAGE OverloadedStrings #-}
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe
import Data.String
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as BS
---------------------------------------------------------------------------------
main = do
  getLine'
  s <- sort . BS.lines <$> getContents'
  print $ count [] s 0
  
  
count _ [] c = c
count [] (y:ys) c = count [y] ys (c+1)
count (x:xs) (y:ys) c
  |y==x = count (y:x:xs) ys c
  |y/=x = count (y:x:xs) ys (c+1)

  
  
---------------------------------------------------------------------------------

{-ByteString関連-}
--IO
getLine' = BS.getLine
getContents' = BS.getContents
getInt' = fst . fromJust . BS.readInt <$> getLine'
getIntListw' = map (fst . fromJust. BS.readInt) .BS.words <$> getLine'
getIntListl' = map (fst . fromJust. BS.readInt) .BS.lines <$> getContents'
getInteger' = fst . fromJust. BS.readInteger <$> getLine'
putStr' = BS.putStr
putStrLn' = BS.putStrLn
--演算子
bs1 |++| bs2 = BS.append bs1 bs2
chr |:+| bs2 = BS.cons chr bs2
bs1 |+:| chr = BS.snoc bs1 chr

{-elem関連-}
--elemの第一引数をリストにしたもの。
--elemList "abc" "atcoder" -> [True,False,True]
elemList [] _ = []
elemList (x:xs) list  = elem x list : elemList xs list

--elemIndexの第一引数をリストにしたもの。
elemIndexList [] list = []
elemIndexList (x:xs) list  = elemIndex x list : elemIndexList xs list

--elemIndicesの第一引数をリストにしたもの。
elemIndicesList [] list = []
elemIndicesList (x:xs) list  = elemIndices x list : elemIndicesList xs list

Measured memory_bytes: 56016
#include <cstdio>

template<typename T>
T gcd(T a, T b)
{
	if (a < b) return gcd(b, a);
	T r;
	while (r = a % b)
	{
		a = b;
		b = r;
	}
	return b;
}

int main()
{
  int a, b, k;
  scanf("%d %d %d", &a, &b, &k);
  
  int g = gcd(a, b);
  
  int c = 0;
  for (int i = g; i > 0; --i)
  {
    if (a % i == 0 && b % i == 0)
    {
      ++c;
      if (c == k)
      {
        printf("%d\n", i);
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
import math

N,L=map(int,input().split())
T=[int(input()) for i in range(N)]

ANSX=ANSY=0

for i in range(N-1):
    for j in range(i+1,N):
        ANSX+=math.cos((T[i]+T[j])*math.pi/L)*(N-(j-i+1))
        ANSY+=math.sin((T[i]+T[j])*math.pi/L)*(N-(j-i+1))

        ANSX+=math.cos((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)
        ANSY+=math.sin((T[i]+T[j])*math.pi/L+math.pi)*(j-i-1)

print(ANSX/(N*(N-1)*(N-2)//6),ANSY/(N*(N-1)*(N-2)//6))

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

int main() {
    int H,N;
    cin >> H >> N;
    vector<int> A(N),B(N);
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];

    vector<int> dp(H+1,1000000000);//モンスターの体力をi減らすのに必要な魔法の最小値
    dp[0] = 0;

    for(int i=0;i<H+1;i++){
        for(int j=0;j<N;j++){
            int next = min(i+A[j],H);
            dp[next] = min(dp[next],dp[i]+B[j]);
        }
    }

    cout << dp[H] << endl;


    return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
i=0
while a>0 or b>0:
    print("#"*b)
    for i in range(a-2):
        print("#",end='')
        for j in range(b-2):
            print(".",end='')
        print("#")
    print("#"*b)
    print()
    a,b=map(int,input().split())
    


Measured memory_bytes: 6992
#include <stdio.h>

int main(void)
{
    int i, j;

    int n;
    scanf("%d", &n);

    float x[4], y[4];
    float slope1, slope2;

    for (i = 0; i < n; i++) {
        for (j = 0; j < 4; j++) {
            scanf("%f %f", &x[j], &y[j]);
        }
        slope1 = (y[1] - y[0]) / (x[1] - x[0]);
        slope2 = (y[3] - y[2]) / (x[3] - x[2]);

        if (slope1 == slope2) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}

Measured memory_bytes: 616
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = 0, cnt = 0;
    rep(i,n){
        if(cnt < h[i]){
            ans += h[i] - cnt;
            cnt = h[i];
        }
        else{
            cnt = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	string str;
	int joi, ioi;
	
	while(getline(cin, str)){
		joi = 0; ioi = 0;
		for(int i = 1; i < str.size() - 1; i++){
			if(str[i] == 'O' && str[i + 1] == 'I'){
				if(str[i - 1] == 'J') joi++;
				else if(str[i - 1] == 'I') ioi++;
			}
		}
		
		cout << joi << endl << ioi << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;

    int plus = 0;
    int minus = 0;

    rep(i,4){
        if(s[i] == '-') minus++;
        else plus++;
    }

    cout << plus - minus << endl;
    
}

   

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
  int n,p,a;
  long dp[101][2]={};
  scanf("%d %d",&n,&p);
  dp[0][1]=0;
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    dp[i+1][0]=dp[i][0];
    dp[i+1][1]=dp[i][1];
    if(a%2==1){
      dp[i+1][0]+=dp[i][1];
      dp[i+1][1]+=dp[i][0];
    }
    else{
      dp[i+1][0]+=dp[i][0];
      dp[i+1][1]+=dp[i][1];
    }
  }
  printf("%ld\n",dp[n][p]);
}
  

Measured memory_bytes: 128
N = int(input())
Cs = list(map(int, input().split()))
adj = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)

under_col = [0] * N
ans = [0] * N


def tri(n):
    return n * (n + 1) // 2


def go(curr, fro):
    col = Cs[curr] - 1
    prev_under = under_col[col]
    deg = 1
    for n in adj[curr]:
        if n == fro:
            continue
        curr_under = under_col[col]
        ch_deg = yield go(n, curr)
        diff_under = under_col[col] - curr_under
        ans[col] += tri(ch_deg - diff_under)
        deg += ch_deg
    under_col[col] = prev_under + deg
    return deg


def tramp(gen):
    stack = [gen]
    val = None
    while stack:
        try:
            stack.append(stack[-1].send(val))
            val = None
        except StopIteration as e:
            stack.pop()
            val = e.value
    return val


tramp(go(0, -1))
for i in range(N):
    ans[i] += tri(N - under_col[i])
    print(tri(N) - ans[i])


Measured memory_bytes: 209780
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int n,ans;
		while((n = scn.nextInt())!= 0) {
			n /=100;
			ans = 100000000;
			for(int c = 0;c <= n/5;c++) {
				for(int b = 0;b <= (n-5*c)/3;b++) {
					if((n - (5*c + 3*b))%2 == 0){
						int a = (n-(5*c + 3*b))/2;
						ans = (int)Math.min(a/5*380*0.8*5 + a%5*380 + b/4*550*0.85*4+b%4*550+c/3*850*0.88*3+c%3*850,ans);
					}else {
						continue;
					}
				}
			}
			System.out.println(ans);
		}
		scn.close();
	}
}



Measured memory_bytes: 25708
#include <cstdio>
#include <vector>
#include <limits>
#include <string.h>

using namespace std;

namespace {
// workspace for Merge.
size_t L[250001] = {0};
size_t R[250001] = {0};

static size_t Merge(size_t* A, size_t left, size_t mid, size_t right) {
  const size_t n1 = mid - left;
  const size_t n2 = right - mid;

  // When sorting large arrays, allocating L and R in heap for
  // each Merge call makes a bit the program slower.
  //
  // In the real application, we should use std::vectors instead of
  // fixed sized arrays, though.
  memset(L, 0, n1 + 1);
  memset(R, 0, n2 + 1);
  // vector<size_t> L(n1+1);
  // vector<size_t> R(n2+1);

  for (size_t i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (size_t i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }

  static const size_t kInf = numeric_limits<size_t>::max();
  L[n1] = kInf;
  R[n2] = kInf;

  size_t i = 0;
  size_t j = 0;
  for (size_t k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  return right - left;
}

static size_t MergeSortInternal(size_t* A, size_t left, size_t right) {
  if (left + 1 >= right) return 0;

  const size_t mid = (left + right) / 2;
  size_t ret = MergeSortInternal(A, left, mid);
  ret += MergeSortInternal(A, mid, right);
  return ret + Merge(A, left, mid, right);
}

static size_t MergeSort(size_t* A, size_t n) {
  return MergeSortInternal(A, 0, n);
}
} // namespace

int main() {
  size_t n;
  size_t S[500000];
  scanf("%lu", &n);
  for (size_t i = 0; i < n; ++i) {
    scanf("%lu", &S[i]);
  }

  const size_t swapped = MergeSort(S, n);
  for (size_t i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%lu", S[i]);
  }
  printf("\n");
  printf("%lu\n", swapped);

  return 0;
}

Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

const double PI = acos(-1.0);

#define EPS 1.0e-8
#define INF 1.0e12
typedef complex<double> P;
namespace std{bool operator<(const P& a, const P& b){
  return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
}}
double inP(const P& p, const P& q){ return real(conj(p)*q); } //dot
double outP(const P& p, const P& q){ return imag(conj(p)*q); } //cross
struct L : public vector<P> {
  L(const P& a, const P& b){ push_back(a); push_back(b); }
};
typedef vector<P> G;
int ccw(P a, P b, P c){
  b-=a; c-=a;
  if(outP(b,c)>0) return +1; //counter clockwise
  if(outP(b,c)<0) return -1; //clockwise
  if(inP(b,c)<0) return +2; //c-a-b on line
  if(norm(b)<norm(c)) return -2; //a-b-c on line
  return 0;
}

G convex_hull(vector<P> &ps){
  int n=ps.size(),k=0;
  sort(ps.begin(),ps.end());
  vector<P> ch(2*n);
  for(int i=0;i<n;ch[k++]=ps[i++])
    while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
  for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--])
    while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<= 0)--k;
  ch.resize(k-1);
  return ch;
}

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

  map<vector<int>, int> memo;
  vector<P> ps;
  rep(i,N){
    int x, y;
    cin >> x >> y;
    x += 10000000;
    y += 10000000;
    ps.push_back(P(x,y));
    memo[{x,y}] = i;
  }
  
  G ch = convex_hull(ps);
  vector<double> ret(N,0);
  int M = ch.size();
  rep(i,M){
    int x = (int)(real(ch[i])+0.5), y = (int)(imag(ch[i])+0.5);
    int id = memo[{x,y}];

    double x_prev = real(ch[(i-1+M)%M]), y_prev = imag(ch[(i-1+M)%M]);
    double x_next = real(ch[(i+1)%M]), y_next = imag(ch[(i+1)%M]);
    
    double r1 = atan2((double)(y-y_prev), (double)(x-x_prev)) - PI/2.0;
    while(r1<-PI) r1 += 2*PI;
    while(PI<r1) r1 -= 2*PI;
    double r2 = atan2((double)(y_next-y), (double)(x_next-x)) - PI/2.0;
    while(r2<-PI) r2 += 2*PI;
    while(PI<r2) r2 -= 2*PI;

    //cout << id << "\t" << r1 << "\t" << r2 << endl;

    double range = 0;
    if(r1>=0 && r2>0) range = r2-r1;
    else if(r1<0 && r2>=0) range = -r1+r2;
    else if(r1>=0 && r2<0) range = (PI-r1)+(PI+r2);
    else range = r2-r1;
    
    ret[id] = range/(2*PI);
  }
  rep(i,N){
    printf("%.20lf\n", ret[i]);
  }

  return 0;
}


Measured memory_bytes: 256
import Data.List
import Control.Monad

main = do
    [n,a,b,c] <- map read . words <$> getLine :: IO [Int]
    ls <- join <$> replicateM n (map read . words <$> getLine) :: IO [Int]
    print $ foldl (\x y -> min x $ solve ls y [a,b,c] + y*10) (maxBound :: Int) [0..n-3]

solve :: [Int] -> Int -> [Int] -> Int 
solve ls i ts = minimum . map (\x -> minimum $ cand2Scr x ts) $ makeCand i ls

cand2Scr :: [Int] -> [Int] -> [Int]
cand2Scr ps ts = [ sum . map abs $ zipWith (-) p ts | p <- permutations ps] 

makeCand :: Int -> [Int] -> [[Int]]
makeCand 0 ls = [ls]
makeCand n ls = join [ makeCand (n-1) $ merge p | p <- ps ]
    where
        ps = comb 2 ls
        merge = \p -> (sum p):(myDel p ls) 
        dbg = [ join . makeCand (n-1) $ merge p | p <- ps ] 

comb :: Int -> [a] -> [[a]]
comb 0 xs = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

myDel :: [Int] -> [Int] -> [Int]
myDel [] ls = ls
myDel (p:ps) ls = myDel ps (Data.List.delete p ls)


Measured memory_bytes: 2428
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, k, x, y;
    cin >> n >> k >> x >> y;
    k = min(n, k);

    cout << k * x + (n - k) * y << endl;
    
    return 0;
}


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

int main(){
  int N,L,i,sum,a,A;
  cin >> N >> L;
  i=0;
  a=L;
  L=L+N-1;
  sum = a+L;
  A=sum*N/2;
  if(a>=0){
   cout << A-a << endl;
  }
  else if(L<=0){
  cout << A-L << endl;
  }
  else{
    cout << A << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string s;
  cin >> s;
  ll gcnt = 0, pcnt = 0;
  REP(i, s.length()) {
    if (s[i] == 'g') {
      gcnt++;
    } else {
      pcnt++;
    }
  }

  cout << (gcnt - pcnt) / 2;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include<vector>
#include<map>
#include <set>
#include<string>
#include <queue>
#include <stack>
#include <random>
#define INF 1000000001
#include<iostream>
#include<vector>
using ll = long long;

int GCD(const int x, const int y){
    if(x % y == 0){
        return y;
    }
    return GCD(y, x%y);
}

int main()
{    

    int A, B, K;
    std::cin >> A >> B >> K ;
    std::vector<int> devided;
    const int gcd = GCD(A,B);
    devided.push_back(1);
    bool square = false;
   for(int i = 2; i < gcd; ++i){
    if(gcd % i != 0) continue;
    if(gcd / i < i) break;
    devided.push_back(i);
    if(gcd / i == i ){
        square = true;
        break;
    } 
   }

   
   const int size = square ? devided.size() -1 : devided.size();
   for(int i = 1; i <= size; ++i){
    devided.push_back(gcd / devided[size - i]);
   }
   // for(int i = 0; i < devided.size(); ++i){
   //  std::cout << devided[i] << std::endl;
   // }
   std::cout << devided[devided.size() - K] << std::endl;
   return 0;
    
}



Measured memory_bytes: 256
S = input()
T = input()

ls = len(S)
lt = len(T)

if ls < lt:
    print('UNRESTORABLE')
    exit()

diff = ls - lt

candidates = []
for i in range(diff+1):
    string = S[i:i+lt]

    for j in range(lt):
        if string[j] == T[j] or string[j] == '?':
            continue
        else:
            break

    else:
        candidate = S[:i] + T + S[i+lt:]
        candidate = candidate.replace('?', 'a')
        candidates.append(candidate)

if not candidates:
    print('UNRESTORABLE')
    exit()

ans = min(candidates)
print(ans)


Measured memory_bytes: 3064
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = [inpl() for i in range(n)]
a.sort(key=lambda x:x[1])
a.sort()
z = []
# pprint.pprint(a)
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        z.append((a[i][0]-a[j][0], a[i][1]-a[j][1]))
c = Counter(z)
# pprint.pprint(c)
if n == 1:
    print(1)
else:
    print(n-c.most_common()[0][1])
# print(n-c.most_common()[0][1])



Measured memory_bytes: 39280
n = int(input())
h = [int(i) for i in input().split()]

dp = [10**10]*(n)
dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2,n):
    a = dp[i-2] + abs(h[i]-h[i-2])
    b = dp[i-1] + abs(h[i]-h[i-1])

    if a < b:
        dp[i] = a
    else:
        dp[i] = b

print(dp[n-1])

Measured memory_bytes: 13924
if __name__ == "__main__":
    i = 0
    while True:
        v = map( int, raw_input().split())
        if v[0] == 0:
            if v[1] == 0:
                break
        i += 1
        if v[0] > v[1]:
            print "{0} {1}".format(v[1],v[0])
        else:
            print "{0} {1}".format(v[0],v[1])

Measured memory_bytes: 6440
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;

int main(){
    int n,k; cin >> n >> k;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    ll ans = 0;
    vector<ll> sub;
    for(int i = 0; i <= n-1;i++){
        if(i > k) continue;
        if(i) sub.push_back(v[i-1]);
        for(int j = 0; j <= n-i;j++){
            if(i+j > k) continue;
            vector<ll> s = sub;
            for(int x = 1;x <= j;x++) s.push_back(v[n-x]);
            sort(ALL(s));
            ll value = 0;
            rep(x,s.size())value += s[x];
            for(int x = 0; x < k-i-j;x++){
                if(x < s.size() && s[x] < 0) value -= s[x];
            }
            ans = max(ans,value);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  vector<int> a(5);
  int min_a = 10;
  int tmp = 0;
  REP(i, 5){
    cin >> a[i];
    if (a[i] % 10 != 0) {
      min_a = min(min_a, a[i] % 10);
      tmp += 10 + a[i] - (a[i] % 10);
    } else {
      tmp += a[i];
    }
  }
  tmp -= 10 - min_a;
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 256