akhauriyash/Code-Regression huggingface dataset:
long i;main(n,k){for(scanf("%d%d",&n,&k);i<n;i++)k+k-1>n?i=n,puts("-1"):printf("%d %d %d\n",(n+1)*i/2%n+k,(n*i+n+i)/2%n+n+k,k+n+n+i);}

Measured memory_bytes: 2176
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>

#define INT unsigned long long int
#define FORN(n) for(int i=0;i<n;i++)
#define PINT(d) printf("%d\n", d);
#define PDOUBLE(lf) printf("%lf\n", lf);
#define PSTR(s) printf("%s\n", s);
#define N 1000000007
#define MAX_N 500000

using namespace std;

main(){
    int a,b;
    int ans;
 
    scanf("%d %d", &a, &b);
    
    if(a<= 0 && b >= 0){
        ans = 0;
    }else if((b-a)%2){
        ans = 1;
    }else{
        if(b > 0){
            ans = 1;
        }else{
            ans = -1;
        }
    }
 
    printf("%s", ans > 0 ? "Positive" : ans < 0 ? "Negative" : "Zero");   
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
c_cnt = [1 for i in range(N)]

def count(A, B, b_cnt):
    B.append(-1)
    a_cnt = [0 for i in range(N)]
    i, j = 0, 0
    while i < N:
        if A[i] < B[j]:
            a_cnt[i] += b_cnt[j]
            j += 1
        else:
            i += 1
            if 1 <= i < N:
                a_cnt[i] = a_cnt[i-1]
    return a_cnt

b_cnt = count(B, C, c_cnt)
a_cnt = count(A, B, b_cnt)
print(sum(a_cnt))

Measured memory_bytes: 25140
N=int(input())
L=list(map(int,input().split()))

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [0]*N
for i in range(N):
    S[L[i]-1]+=1

init=0
for j in range(N):
    tmp=S
    if tmp[j]>=2:
        init+=(tmp[j]*(tmp[j]-1))//2




for i in range(N):
    ans=init
    R=S[L[i]-1]
    if R>=2:
        print(ans-(R-1))
    else:
        print(ans)

Measured memory_bytes: 24996
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll ans = 0;
    rep(i, 3) {
        if(s[i] == '1') {
            ans++;
        }
    }
    out(ans);
    
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}

int32_t main()
{
    //freopen("C:/Users/Joe/Desktop/tests/in11.txt", "r", stdin);
    //freopen("C:/Users/Joe/Desktop/tests/out11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    int t=1;
    //cin >> t;
    while(t--)
    {
        int n,m;
        cin >> n >> m;
        if(n==1 || m==1)
            return cout << 1 << endl,0;
        cout << ((n+1)/2)*((m+1)/2)+(n/2)*(m/2) << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  // int s[m][n];
  vector<vector<int> > s(m, vector<int>(n, -1));
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    bool all = true;
    for (int i = 0; i < m; ++i) {
      vector<int> vec;
      for (int j = 0; j < n; ++j) {
        if (s[i][j] != -1) {
          vec.push_back(s[i][j]);
        }
      }
      int cnt = 0;
      for (int j = 0; j < vec.size(); ++j) {
        if (bit >> vec[j] & 1) {
          cnt++;
        }
      }
      if (cnt % 2 != p[i]) all = false;
    }
    if (all) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    std::vector<int> w;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        w.push_back(tmp);
    }
    
    int min = 100 * 100;
    std::vector<int>::iterator itr = w.begin();
    for(int i=0; i<n-1; i++){
        ++itr;
        int sum1 = std::accumulate(w.begin(), itr, 0);
        int sum2 = std::accumulate(itr, w.end(), 0);
        min = std::min(min, abs(sum2-sum1));
        //cout << sum1 << "," << sum2 << "," << min << endl;
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll a, b, c , k;
        cin >> a >> b >> c >> k;
        if(k <= a){
            cout << k;
        }
        else if(k <= a + b){
            cout << a ;
        }
        else{
            k-=(a+b);
            cout << a - k;
        }
    }
}


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

int main() {
    int x, y;
    cin >> x >> y;
    if(y % 2 == 0 && 2 * x <= y && y <= 4 * x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

double calc(auto i, auto j, auto k, auto &dp, auto &N)
{
  if (dp[i][j][k] != -1) return dp[i][j][k];
  if (i+j+k == 0) return dp[0][0][0] = 0.0;
  if (i == 1 && j == 0 && k == 0) return dp[1][0][0] = N;
  double y1 = 0.0, y2 = 0.0, y3 = 0.0;
  if (k != 0) y3 = (1.0 + calc(i, j+1, k-1, dp, N)) * (double)k/N;
  if (j != 0) y2 = (1.0 + calc(i+1, j-1, k, dp, N)) * (double)j/N;
  if (i != 0) y1 = (1.0 + calc(i-1, j, k, dp, N)) * (double)i/N;
  return dp[i][j][k] = N*(y3+y2+y1)/(double)(i+j+k) + (double)(N-i-j-k)/(double)(i+j+k);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  double N;
  cin >> N;
  vector<double> a(N);
  INPUT(a);
  int ct_1 = 0, ct_2 = 0, ct_3 = 0;
  REPx(x, a)
  {
    if (x == 1) ct_1++;
    if (x == 2) ct_2++;
    if (x == 3) ct_3++;
  }
  vector<vector<vector<double>>> dp(N+1, vector<vector<double>>(ct_2+ct_3+1, vector<double>(ct_3+1, -1.0)));
  cout << setpre(10) << calc(ct_1, ct_2, ct_3, dp, N) << endl;

  return 0;
}

Measured memory_bytes: 216960
//	created : 16/03/13
// 	author   : Rp7rf
#include <iostream>
#include <vector>
#include <queue>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF 1e9
#define MAX 100000

class Edge{
public:
	int t,w;
	Edge() {};
	Edge(int t,int w):t(t),w(w){}
};

vector<Edge> G[MAX];
int n,d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s){
	rep(i,n)d[i] = INF;
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;
	while(!Q.empty()){
		u = Q.front(); Q.pop();
		rep(i,G[u].size()){
			Edge e = G[u][i];
			if(d[e.t] == INF){
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

void solve(){
	bfs(0);
	int maxv = 0;
	int tgt = 0;
	rep(i,n){
		if(d[i] == INF)continue;
		if(maxv < d[i]){
			maxv = d[i];
			tgt = i;
		}
	}

	bfs(tgt);
	maxv = 0;
	rep(i,n){
		if(d[i] == INF)continue;
		maxv = max(maxv,d[i]);
	}

	cout<<maxv<<endl;
}

int main(void){
	int s,t,w;
	cin>>n;

	rep(i,n-1){
		cin>>s>>t>>w;
		G[s].push_back(Edge(t,w));
		G[t].push_back(Edge(s,w));
	}
	solve();


}

Measured memory_bytes: 7996
import java.util.*;

public class Main {
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
        int b = sc.nextInt();
      	if (a >= 10 || b >= 10) {
        	System.out.println(-1);
        } else {
        	System.out.println(a * b);
        }
    }
}

Measured memory_bytes: 35664
#24 ABC127C
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
x=[0 for _ in range(n+1)]
for l,r in lr:
	x[l-1]+=1
	x[r]-=1
for i in range(1,n+1):
	x[i]+=x[i-1]
res=0
for t in x:
	if t==m:
		res+=1
print(res)

Measured memory_bytes: 66520
import numpy as np
N,M = map(int, input().split())
p, S = [], []
for i in range(M):
  tmp = input().split()
  p.append(int(tmp[0]))
  S.append(tmp[1])

answer = np.zeros([N,2], dtype=int)
for i in range(M):
  if S[i] == 'AC' and answer[p[i]-1][0] == 0:
    answer[p[i]-1][0] += 1
  elif S[i] == 'WA' and answer[p[i]-1][0] == 0:
    answer[p[i]-1][1] += 1

total = [0, 0]
for i in range(N):
  if answer[i][0] == 1:
    total[0] += answer[i][0]
    total[1] += answer[i][1]
print(total[0], total[1])

Measured memory_bytes: 23956
#include <vector>
#include <iostream>

using namespace std;

#define int long long

const int N = 2e5 + 10;

bool vis[N];
vector<int> g[N];

void dfs(int x) {
  vis[x] = 1;
  for (int &v : g[x]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int n, m;
  cin >> n >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      ++ans;
      dfs(i);
    }
  }
  cout << ans - 1;
  return 0;
}

Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
int n,a[3][105],dp[3][105];
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=2;++i)
        for (int j=1;j<=n;++j) {
            int x;scanf("%d",&x);
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+x;
        }
    printf("%d\n",dp[2][n]);
    return 0;
}


Measured memory_bytes: 3752
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

n=int(input())
v=list(map(int,input().split()))
v.sort(reverse=1)
tmp=1
for i in range(n-1):
    tmp*=2
    ans+=v[i]/tmp
ans+=v[n-1]/tmp
print(ans)


Measured memory_bytes: 38256
package main

import (
	"fmt"
	"math"
)



const (
	INF = 1000000000000000000
)

// 配るDP
func main() {

	var n, k int
	fmt.Scan(&n, &k)

	h := make([]int, n+10)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	dp := make([]int, n + 10)
	for i := 0; i <n ;i++ {
		dp[i] = INF
	}
	dp[0] = 0
	// dp[1] = abs(h[1] - h[0])
	// if n > 2 {
	// 	dp[2] = abs(h[0] - h[2])
	// }

	for i := 0; i < n; i++ {
		for j := 1 ; j <= k; j++ {
			if i + j  > n {
				break
			}
			dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
		}
	}
	fmt.Println(dp[n-1])
}

func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 6312
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int n; cin>>n;
    int arr[n];
    for(int i=1;i<=n;i++) cin>>arr[i];
    int ans = 0;
    int a,b,c;
    for(int i=2;i<n;i++)
    {
      vector<int> vec;
      a = arr[i-1],b = arr[i],c = arr[i+1];
      vec.pb(a); vec.pb(b); vec.pb(c);
      sort(vec.begin(),vec.end());
      if(b == vec[1]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int a[100010];
int s[100010];
static bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    int q; cin >> q;
    for(int i=3;i<=100000;++i){
        if(IsPrime(i) && IsPrime((i+1)/2)) a[i] = 1;
    }
    for(int i=0;i<100010;++i) s[i+1] = s[i] + a[i];
    for(int i=0;i<q;++i){
        int l,r; cin >> l >> r;
        ++r;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n, m;
    while (cin >> n >> m, n) {
        vector<P> v(n); // p, d
        rep(i, n) {
            cin >> v[i].second >> v[i].first;
        }
        sort(all(v));
        reverse(all(v));
        v.emplace_back(0, 1e9);
        int ans = 0;
        for (auto pa : v) {
            int safe = min(m, pa.second);
            m -= safe;
            ans += pa.first * (pa.second - safe);
        }
        cout << ans << endl;
    }
}

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

struct data {
  int num, p;
};

bool operator<(const data &l, const data &r) {
  if(l.num != r.num) return l.num < r.num;
  return l.p < r.p;
}
bool operator!=(const data &l, const data &r) {
  return l.num != r.num || l.p != r.p;
}
bool operator==(const data &l, const data &r) {
  return l.num == r.num && l.p == r.p;
}

int h, w, s;
vector<vector<int>> u, sum;
data dummy, ans;
data dp[40][40][40][40];

void resetdp();
int calcsum(int down, int up, int left, int right);
data solve(int down, int up, int left, int right);

int main() {
  dummy = {-1, -1};
  while(1) {
    cin >> h >> w >> s;
    if(h + w + s == 0) break;
    u.assign(h, vector<int>(w, 0));
    sum.assign(h, vector<int>(w, 0));
    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j) cin >> u[i][j];
    resetdp();
    ans = solve(0, h - 1, 0, w - 1);
    cout << ans.num << " " << ans.p << endl;
  }
  return 0;
}

void resetdp() {
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < h; ++j)
      for(int k = 0; k < w; ++k)
        for(int l = 0; l < w; ++l) dp[i][j][k][l] = dummy;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j) {
      sum[i][j] = u[i][j];
      if(i != 0) sum[i][j] += sum[i - 1][j];
      if(j != 0) sum[i][j] += sum[i][j - 1];
      if(i != 0 && j != 0) sum[i][j] -= sum[i - 1][j - 1];
    }
}

int calcsum(int down, int up, int left, int right) {
  int nans = 0;
  nans = sum[up][right];
  if(down != 0) nans -= sum[down - 1][right];
  if(left != 0) nans -= sum[up][left - 1];
  if(left != 0 && down != 0)
    nans += sum[down - 1][left - 1];
  return nans;
}

data solve(int down, int up, int left, int right) {
  if(dp[down][up][left][right] != dummy)
    return dp[down][up][left][right];
  data nowans = {1, s - sum[h - 1][w - 1] +
                        calcsum(down, up, left, right)};
  if(nowans.p < 0) return dummy;
  for(int i = down; i < up; ++i) {
    data now1 = solve(down, i, left, right),
         now2 = solve(i + 1, up, left, right);
    if(now1 == dummy || now2 == dummy) continue;
    now1.num += now2.num;
    now1.p = min(now1.p, now2.p);
    nowans = max(now1, nowans);
  }
  for(int i = left; i < right; ++i) {
    data now1 = solve(down, up, left, i),
         now2 = solve(down, up, i + 1, right);
    if(now1 == dummy || now2 == dummy) continue;
    now1.num += now2.num;
    now1.p = min(now1.p, now2.p);
    nowans = max(now1, nowans);
  }

  return dp[down][up][left][right] = nowans;
}


Measured memory_bytes: 15880
using System;
class Program
{
  static void Main(string[] args)
  {
    string S = Console.ReadLine();
    int ans = 700;
    for(int i = 0; i < 3; i++)
    {
      string check = S[i].ToString();
      if (check == "o")
      {
        ans += 100;
      }
    }
  Console.WriteLine(ans);
  }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

long long int count(char *S, int len)
{
	long long int cnt = 0;
	for (int i = 0; i < len;){
		char prev = S[i]; int j;
		for (j = i + 1; j < len; j++){
			if (prev != S[j]){
				break;
			}
		}
		cnt += (j - i) / 2;
		i = j;
	}

	return cnt;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	char S[200]; scanf("%s", S);
	long long int K; scanf("%lld", &K);

	int len = strlen(S);
	long long int ret = 0;

	if (S[0] == S[len - 1]){
		int left = 0;
		for (; left < len; left++){
			if (S[left] != S[0]){
				break;
			}
		}
		int right = len - 1;
		for (; right >= 0; right--){
			if (S[right] != S[len - 1]){
				break;
			}
		}
		if (len == left){
			ret = ((long long int)len * K) / 2;
		}
		else{
			ret += count(S + left, right - left + 1)*K;
			ret += ((left + len - right - 1) / 2)*(K - 1) + left / 2 + (len - right - 1) / 2;
		}
	}
	else{
		ret += count(S, len)*K;
	}

	printf("%lld", ret);


	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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


using namespace std;


struct node {
	node *prnt, *left, *right;
	int key;
};
int n;
node *nil = NULL, *root = NULL;


void Init() {
	nil = (node *)malloc(sizeof(node));
	nil->left = nil;
	nil->right = nil;
	nil->prnt = nil;

}

void preWark(node *me) {

	if (me == NULL) return;
	printf(" %d", me->key);
	preWark(me->left);
	preWark(me->right);
}


void inWark(node *me) {

	if (me == NULL) return;
	inWark(me->left);
	printf(" %d", me->key);
	inWark(me->right);
}



void insert(node *z) {
	node *y = NULL;
	node *x = root;

	while (x != NULL)
	{
		y = x;
		if (z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->prnt = y;

	if (y == NULL) root = z;
	else if (z->key < y->key) y->left = z;
	else y->right = z;

}



int main() {



	int  key, rt;
	string ord;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> ord;

		if (ord[0] == 'i') {
			cin >> key;

			node *nd = new node;
			nd->key = key;
			nd->prnt = nd->left = nd->right = NULL;

			insert(nd);
		}
		else if (ord[0] == 'p') {
			inWark(root);
			printf("\n");
			preWark(root);
			printf("\n");
		}

	}


	return 0;
}




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

#define endl '\n'
#define PI acos(-1.0)
#define F first
#define S second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	
	string a, b;
	cin >> a >> b;
	
	for(size_t i = 0; i < a.size(); ++i) {
		if(a[i] != b[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


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

#define MAX 36
#define TRUE 1
#define FALSE 0

typedef struct{
  char mark;
  int num;
}trump;

void BubbleSort(trump *,int);
void SelectionSort(trump *,int);
int isStable(trump *,trump *,int);

int main(){
  trump card1[MAX],card2[MAX];
  int i,N;
  char data[MAX][MAX];

  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%s",data[i]);
    card1[i].mark = data[i][0];
    card2[i].mark = data[i][0];
    card1[i].num = atoi(&data[i][1]);
    card2[i].num = atoi(&data[i][1]);
  }

  BubbleSort(card1,N);
  printf("Stable\n");
  SelectionSort(card2,N);
  if(isStable(card1, card2, N) == TRUE) printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}

void BubbleSort(trump *card,int N){
  int i,flag,swap;
  char temp[MAX];


  flag = 1;
  while(flag){
    flag = 0;
    for(i=N-1; i>=1; i--){
      if(card[i].num < card[i-1].num){
	*temp = card[i].mark;
	card[i].mark = card[i-1].mark;
	card[i-1].mark = *temp;
	swap = card[i].num;
	card[i].num = card[i-1].num;
	card[i-1].num = swap;
	flag = 1;
      }
    }
  }

  for(i=0; i<N; i++){
    printf("%c%d",card[i].mark,card[i].num);
    if(i==N-1) break;
    printf(" ");
  }
  printf("\n");

}

void SelectionSort(trump *card, int N){
  int i,j,minj,swap;
  char temp[MAX];

  for(i=0; i<N; i++){
    minj = i;
    for(j=i; j<N; j++){
      if(card[j].num < card[minj].num) minj = j;
    }
    if(i!=minj){
      *temp = card[i].mark;
      card[i].mark = card[minj].mark;
      card[minj].mark = *temp;
      swap = card[i].num;
      card[i].num = card[minj].num;
      card[minj].num = swap;
    }
  }
  for(i=0; i<N; i++){
    printf("%c%d",card[i].mark,card[i].num);
    if(i==N-1) break;
    printf(" ");
  }
  printf("\n");

}

int isStable(trump *card_bef, trump *card_aft, int N){
  int i,j; 
  for(i=0; i<N; i++){
    if(card_bef[i].mark != card_aft[i].mark || card_bef[i].num != card_aft[i].num) return FALSE;
    }
  return TRUE;
}



Measured memory_bytes: 2100
s=input()
flg = 0
cnt = 0
if s == "SSS":
    print(0)
    exit()
if s[1] == "S":
    flg = 1
for i in range(3):
    if s[i] == "R":
        cnt += 1
if cnt >= 2 and flg == 1:
    print(cnt -1)
else:
    print(cnt)

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


int main()
{
	int a, b, c, d, n, x;
	c = 0;
	n = 1;
	cin >> a;
	cin >> b;
	d = b;
	while (d >= 10) {
		d = d / 10;
		n += 1;
	}
	x = std::pow(10, n) * a + b;
	for (int i = 1; i < (x / 2); i++) {
		if (i * i == x) {
			c = 1;
		}
	}
	if (c == 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG

using namespace std;

const int N = 1e5+7;
const int INF = 1e9;

int n, res;

struct Node
{
    int l, r;
    friend bool operator < (const Node &x, const Node &y) { return x.l < y.l; }
} a[N];


int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].l >> a[i].r;
    }
    sort(a+1, a+n+1);
    reverse(a+1, a+n+1);
    int rr = 1;
    for (int i = 1; i <= n; ++i) {
        if (a[i].r < a[rr].r) rr = i;
    }
    if (1 == rr) {
        for (int i = 2; i <= n; ++i) {
            res = max(res, a[i].r-a[i].l+1);
        }
        res += a[1].r-a[1].l+1;
        cout << res << endl;
        return 0;
    }
    int minr = a[1].r;
    for (int i = 2; i <= n; ++i) {
        if (i == rr) continue;
        res = max(res, max(0, a[rr].r-max(a[i].l, a[rr].l)+1)+max(0, minr-a[1].l+1));
        res = max(res, max(0, a[rr].r-a[1].l+1)+a[i].r-a[i].l+1);
        minr = min(minr, a[i].r);
    }
    res = max(res, max(0, minr-a[1].l+1)+a[rr].r-a[rr].l+1);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1152
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };

    let n = s.len();
    let mut count = 0;
    for i in 0..n {
        if i == n / 2 {
            break;
        }
        let start = s.chars().nth(i).unwrap();
        let end = s.chars().nth(n - i - 1).unwrap();

        if start != end {
            count += 1;
        }
    }
    println!("{}", count);
}


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

int main() {
    int A[3][3];
    bool c[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
            c[i][j] = false;
        }
    }
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        int b;
        cin >> b;
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(A[j][k] == b){
                    c[j][k] =true;
                }
            }
        }
    }

    bool ok = false;
    for(int i=0; i<3; i++){
        if(c[i][0] && c[i][1] && c[i][2]){
            ok = true;
        }
        if(c[0][i] && c[1][i] && c[2][i]){
            ok = true;
        }
        if(c[0][0] && c[1][1] && c[2][2]){
            ok = true;
        }
        if(c[2][0] && c[1][1] && c[0][2]){
            ok = true;
        }
    }

    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main()
{
char ch[6];
int i;
for(i=0;i<6;i++)
{
	cin>>ch[i];
}
if(ch[0]==ch[5]&&ch[1]==ch[4]&&ch[2]==ch[3])
{
  cout<<"YES"<<endl;
}
else 
  cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  int n, k; cin>>n>>k;
  string s; cin>>s;
  vector<int> a;

  a.emplace_back(0);
  if (s[0] == '0') a.emplace_back(0);

  int cur = 1;
  REP(i, 1, n) {
    if (s[i] == s[i-1]) ++cur;
    else {
      a.emplace_back(cur);
      cur = 1;
    }
  }
  a.emplace_back(cur);
  rep(i, 3*k) a.emplace_back(0);
  rep(i, a.size()-1) a[i+1] += a[i];

  int ans = 0;
  for (int i = 1; i+2*k < a.size(); i += 2) {
    ans = max(ans, a[i+2*k] - a[i-1]);
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 2548
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string O, E;
    string pass;
    cin >> O >> E;
/*    
    O = "abcde";
    E = "1234";
*/    
    
    for (int i=0; i<O.length(); i++){
        pass = pass + O.substr(i,1) + E.substr(i,1);
    }
    cout << pass;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();
        
        int maxMatch = 0;
        int slen = s.length();
        int tlen = t.length();
        for(int i=0; i+tlen <= slen; i++) {
            String ssub = s.substring(i, i+tlen);
            int match = 0;
            for(int j=0; j<tlen; j++) {
                if(t.charAt(j) == ssub.charAt(j)) {
                    match++;
                }
            }
            maxMatch = Math.max(maxMatch, match);
        }
        System.out.println(tlen - maxMatch);
    }
}


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

using namespace std;
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

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

    vector<bool> arr(A.back() + 1, false);
    int ans = 0;
    for (int i : A) {
        if (!arr[i]) {
            if (cnt[i] == 1)
                ++ans;
            for (int j = i; j <= A.back(); j += i)
                arr[j] = true;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 13544
n,T=map(int,input().split())
t=list(map(int,input().split()))
ts=[]
tf=[]
ts.append(t[0])
tb=t[0]
for i in t:
  if(i>tb+T):
    tf.append(tb+T)
    ts.append(i)
  tb=i
tf.append(t[-1]+T)
time=0
#print(ts)
#print(tf)
for i in range(len(ts)):
  time+=tf[i]-ts[i]
print(time)


Measured memory_bytes: 26836
<?php

class Simulator
{
    public $queue = array();
    public $n_processes;
    public $quantum;
    public $dll2;

    public function __construct()
    {
        fscanf(STDIN, '%d', $n);
        $dll = new \SplDoublyLinkedList();
        for ($i = 0; $i < $n; $i++) {
            $line = trim(fgets(STDIN));
            if ($line[0] === 'i') {
                $dll->unshift(substr($line, 7));
            } elseif ($line[6] === 'F') {
                $dll->shift();
            } elseif ($line[6] === 'L') {
                $dll->pop();
            } else {
                $check = substr($line, 7);
                foreach ($dll as $key => $val) {
                    if ($val === $check) {
                        $dll->offsetUnset($key);
                        break;
                    }
                }
            }
        }
        $this->dll2 = $dll;
    }

    public function getAnswer()
    {
        $str = array();
        $dll = $this->dll2;
        while (true) {
            try {
                $val = $dll->shift();
                $str[] = $val;
            } catch (Exception $e) {
                echo implode(' ', $str), PHP_EOL;
                break;
            }
        }
    }
}

$answer = new Simulator();
$answer->getAnswer();



Measured memory_bytes: 136152
import sys

S = input()[::-1]

c = [0] * 2019
c[0] = 1

num = 0
d = 1

for a in S:
    num += int(a) * d
    num %= 2019
    d *= 10
    d %= 2019
    c[num] += 1

a = 0
for i in c:
    a += i * (i - 1) // 2

print(a)



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

int main(){
  string S;
  int l,i,count,max;
  count=0;
  max=0;
  cin >> S;
  l=S.size();
  for(i=0;i<l;i++){
    if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      count++;
    }
    else if(count>max){
      max=count;
      count=0;
    }
    else{
      count=0;
   }
  }
  if(count>max){
    max=count;
  }
    cout << max << endl;
   }

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    a1 = a1*t1;
    a2 = a2*t2;
    b1 = b1*t1;
    b2 = b2*t2;
    if (a1+a2 == b1+b2) {
        cout << "infinity\n";
        return 0;
    }
    //assume a1 < b1
    if (a1 > b1) {
        swap(a1,b1);
        swap(a2,b2);
    }
    if (a1+a2 < b1+b2) {
        //never going to happen
        cout << 0 << '\n';
    }
    else {
        ll ans = 1;
        ll diff = b1-a1;
        ll diff2 = (a1+a2)-(b1+b2);
        ll add = 2*(diff%diff2==0?diff/diff2-1:diff/diff2);
        ans += add;
        if (diff%diff2==0) ans++;
        cout << ans << '\n';
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[200001]={};
int main()
{
	scanf("%d",&n);
	int aa;
	for (int i=2;i<=n;i++)
	{
		scanf("%d",&aa);
		a[aa]++;
	}
	for (int i=1;i<=n;i++) printf("%d\n",a[i]);
}

Measured memory_bytes: 4496
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String S = sc.next();
    	int Znum = 0;
    	for (int i = S.length()-1; 0 < i; i--) {
    		if (S.charAt(i) == 'Z') {
    			Znum = i;
    			break;
    		}
    	}
    	System.out.println(Znum - S.indexOf("A")+1);
    }
}

Measured memory_bytes: 26528
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int b[n-1];
    REP(i,n-1)cin >> b[i];
    int answer = 0;
    answer+=b[0];
    answer+=b[n-2];
    REP(i,n-2){
        answer += min(b[i],b[i+1]);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i = 0;i < (int)s.size();i++){
    cout << (char)(((s[i] - 'A') + n) % 26 + 'A');
  }
  cout << endl;
}

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

struct Combination {
  vector<ModInt<>> _fact, _rfact, _inv;
  Combination(long long nsize = 5000000)
      : _fact(nsize + 1), _rfact(nsize + 1), _inv(nsize + 1) {
    _fact[0] = _rfact[nsize] = _inv[0] = 1;
    for (int i = 1; i <= nsize; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[nsize] /= _fact[nsize];
    for (int i = nsize - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for (int i = 1; i <= nsize; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
  inline ModInt<> fact(int k) const { return _fact[k]; }

  inline ModInt<> rfact(int k) const { return _rfact[k]; }

  inline ModInt<> inv(int k) const { return _inv[k]; }

  ModInt<> P(int n, int r) const {
    if (r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  ModInt<> C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
  // n types,choose r
  ModInt<> H(int n, int r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int n;
vector<int> x;

ModInt<> solve();

int main() {
  cin >> n;
  x.resize(n);
  for (auto &p : x) cin >> p;
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res = 1;
  int now = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    ++cnt;
    if (now >= x[i])
      res *= cnt--;
    else
      now += 2;
  }
  while (cnt) res *= cnt--;
  return res;
}


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

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

    int n, m;
    cin >> n >> m;
    vector<int> H(n);
    for(int i = 0; i < n; i++){
        cin >> H[i];
    }

    vector<int> M(n, -1); // 展望台iが1本道でいける展望台のうち、最大の展望台の標高の高さ
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        M[a] = max(M[a], H[b]);
        M[b] = max(M[b], H[a]);
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += (H[i] > M[i]);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    string n;
    cin >> n;
    ll res = 0;
    rep(i,n.size()) {
        int a = n.at(i) - '0';
        res += a;
    }
    if (res % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int Dis(int x,int k){
    
    return 2*min(x,k-x);
}

int main(void){
   
   int N,K,x,ans=0;
   cin >> N >> K;
   
   for(int i=0;i<N;i++) {
       cin >> x;
       ans += Dis(x,K);
   }
   cout << ans << endl;
}

Measured memory_bytes: 3632
# 066_a
a, b, c = map(int, input().split())
if (1 <= a & a <= 10000) & (1 <= b & b <= 10000) & (1 <= c & c <= 10000):
    p_ab = a + b
    p_bc = b + c
    p_ac = a + c
    print(min(p_ab,p_bc,p_ac))


Measured memory_bytes: 9160
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n,ta,c,t;
	cin >> n >> ta;
	int res = 0;
	int max = 1001;
	
	for (int i = 0; i < n; i++){
		cin >> c >> t;
		if(ta >= t && c < max) max = c;
	}
	if (max != 1001) cout << max << endl;
	else cout << "TLE" << endl;
}

Measured memory_bytes: 256
fun a024(args: Array<String>) {
    val (A, B, C, K) = args[0].split(" ").map { it.toLong() }
    println(if (K % 2 == 0L) A - B else B - A)
}

fun main(args: Array<String>) {
    a024(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 38012
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		long a,b;
 
		Scanner sc = new Scanner(System.in);
 
		a = sc.nextLong();
		b = sc.nextLong();
 
		long ans = 2018;
 
		if (b - a >= 2018) {
			ans = 0;
		} else {
 
			for (long i = a; i < b; ++i) {
				for (long j = i+1; j <= b; ++j) {
					ans = Math.min(ans, (i * j) % 2019);
				}
 
			}
  
		}
 
			System.out.println(ans);
  
	}
  
}

Measured memory_bytes: 22612
n = int(input())
co = {}
co["AC"]=0
co["WA"]=0
co["TLE"]=0
co["RE"]=0
for i in range(n):
	st = input()
	co[st]+=1
print("AC x",co["AC"])
print("WA x",co["WA"])
print("TLE x",co["TLE"])
print("RE x",co["RE"])


Measured memory_bytes: 69836
import sys
from collections import Counter

class UnionFindTree:
    def __init__(self, n: int) -> None:
        self.par = list(range(n))
        self.rank = [0] * n

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


def resolve(in_):
    N, M = map(int, next(in_).split())
    AB = tuple(tuple(map(int, line.split())) for line in in_)

    tree = UnionFindTree(N + 1)
    for a, b in AB:
        tree.unite(a, b)
    
    c = Counter(tree.find(i) for i in range(1, N + 1))
    return c.most_common(1)[0][1]
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45660
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	input := nextLine()
	answer := 0
	inputs := strings.Split(input, "")
	for _, r := range inputs {
		if r == "+" {
			answer = answer + 1
		} else {
			answer = answer - 1
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; For(i, n){ Cin(T, x); map[x] ++; }
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Couty(cond) Cout((cond) ? "Yes" : "No")
#define CoutY(cond) Cout((cond) ? "YES" : "NO")

using namespace std;
using ll = long long;

int main(void){
  Cin(int, h);
  Cin(int, w);
  Cinss(char, h, w, s);
  For(i, h){
    For(j, w){
      if(s[i][j] == '.'){
        s[i][j] = '0';
        for(int a : {-1, 0, 1}) for(int b : {-1, 0, 1}){
          if(i+a >= 0 && i+a < h && j+b >= 0 && j+b < w && s[i+a][j+b] == '#'){
            s[i][j] ++;
          }
        }
      }
      cout << s[i][j];
    }
    cout << "\n";
  }  
}


Measured memory_bytes: 256
import itertools

N, Y = (int(x) for x in input().split())
for x, y in itertools.product(range(N+1), range(N+1)):
  z = N - x - y
  if 0 <= z and 10000*x + 5000*y + 1000*z == Y:
    print('{} {} {}'.format(x, y, z))
    break
if not(x + y + z == N and 10000*x + 5000*y + 1000*z == Y):      
  print('-1 -1 -1')

Measured memory_bytes: 3188
n,m=map(int,input().split())
cnt=[0 for i in range(n)]
done=[False for i in range(n)]
ac, pen = 0, 0
for i in range(m):
  p,s=input().split()
  p=int(p)
  p-=1
  if done[p]:
    continue
  elif s=='AC':
    done[p]=True
    ac += 1
    pen += cnt[p]
  else:
    cnt[p] += 1
print('{} {}'.format(ac,pen))
  
    
  

Measured memory_bytes: 4656
#include<stdio.h>
#include<algorithm>
using namespace std;

int main ()
{
	int m,n,l[100];
	while(scanf("%d %d",&m,&n)!=EOF)
	{
		long long i,sn=0,k=0;
		for(i=0;i<m;i++)
			scanf("%d",&l[i]);
		sort(l,l+m);
		for(i=0;i<n;i++)
			sn+=l[m-i-1];
		printf("%lld\n",sn);
	}
}

Measured memory_bytes: 128
import java.util.*;
import java.util.Map.Entry;



public class Main{

	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt(),X=sc.nextInt(),Y=sc.nextInt();
	 long cost1=0;
	 int tmpX=X;
	 int tmpY=Y;
	
	 cost1+=Math.min(X, Y)*2*C;
	 tmpX-=Math.min(X, Y);
	 tmpY-=Math.min(X, Y);
	 if(tmpX==0) {
		cost1+=tmpY*B;
	 }else if(tmpY==0) {
		 cost1+=tmpX*A;
	 }
	 
	 tmpX=X;
	 tmpY=Y;
	 long cost2=(Math.max(X, Y)*2*C);
	 
	 
	 long cost3=A*X+B*Y;
	 
	 long cost = Math.min(Math.min(cost1, cost2), cost3);
	 
	 System.out.println(cost);
	 
 }
	


}



Measured memory_bytes: 24148