akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <climits>
#include <cfloat>
#include <algorithm>
using namespace std;

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

    vector<int> s(n), t(n);
    for(int i=0; i<n; ++i)
        cin >> s[i] >> t[i];

    vector<int> p(m);
    for(int i=0; i<m; ++i)
        cin >> p[i];
    sort(p.begin(), p.end());

    vector<long long> sum(m+1, 0);
    for(int i=0; i<m; ++i){
        if(i % 2 == 0)
            sum[i+1] = p[i];
        else
            sum[i+1] = -p[i];
        sum[i+1] += sum[i];
    }

    long long ret = 0;
    for(int i=0; i<n; ++i){
        int a = lower_bound(p.begin(), p.end(), s[i]) - p.begin();
        int b = lower_bound(p.begin(), p.end(), t[i]) - p.begin();
        if(s[i] < t[i]){
            -- b;
            if((b - a + 1) % 2 == 1){
                t[i] = p[b];
                -- b;
            }
            if(a % 2 == 0){
                ret += t[i] - s[i] + (sum[b+1] - sum[a]);
            }else{
                ret += t[i] - s[i] - (sum[b+1] - sum[a]);
            }
        }else{
            swap(a, b);
            -- b;
            if((b - a + 1) % 2 == 1){
                t[i] = p[a];
                ++ a;
            }
            if(b % 2 == 0){
                ret += s[i] - t[i] - (sum[b+1] - sum[a]);
            }else{
                ret += s[i] - t[i] + (sum[b+1] - sum[a]);
            }
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2860
#include <stdio.h>
#include <stdlib.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

int compare(const void *x, const void *y);

long long a[100005];

int main()
{
	long long n;
	long long max1, max2;
	max1 = max2 = 0;
	
	scanf("%lld", &n);
	for (long long i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	qsort(a, n, sizeof(long long), compare);

	for (long long i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) {

			if (max1 <= a[i]) {
				max2 = max1;
				max1 = a[i];
				i++;
			}
		}
	}

	printf("%lld\n", max1 * max2);

	return 0;
}

int compare(const void *x, const void *y)
{
	if (*(long long *)x > *(long long *)y) {
		return 1;
	} else if (*(long long *)x == *(long long *)y) {
		return 0;
	} else {
		return -1;
	}
}


Measured memory_bytes: 1788
from operator import itemgetter
n, t = list(map(int, input().split()))
ctl = [list(map(int, input().split())) for _ in range(n)]

ctl2 = [ct for ct in ctl if ct[1]<=t]
ctl2.sort(key=itemgetter(0))
if ctl2 == [] :
    print("TLE")
else :
    print(ctl2[0][0])

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#define __DEBUG__
#define MOD 998244353

using namespace std;
typedef long long ll;

ll factorial[4005];

ll &m(ll &x){
    x %= MOD;
    return x;
}

void init(){
    factorial[0]=1;
    for(int i = 1; i < 4005;i++){
        factorial[i]=(factorial[i-1]*i)%MOD;
    }
}

ll powm(ll x,ll n){
    ll ret = 1;
    ll temp = x;
    while(n>0){
        if(n&1){
            ret *= temp;
            m(ret);
        }
        temp *= temp;
        m(temp);
        n>>=1;
    }
    return ret;
}

ll inv(ll x){
    return powm(x,MOD-2);
}



ll combination(ll a, ll b)//aCb
{
    if(a<b){
        return 0;
    }
    if(b<0){
        return 0;
    }
    ll ret = factorial[a];
    ll div = factorial[b]*factorial[a-b];
    m(div);
    ret *= inv(div);
    return m(ret);
}

ll small[2005];

int main(){
    ll K,N;
    cin>>K>>N;
    init();
    for(int i = 2;i <= K+1 ;i++){
        ll ans = 0;
        if(i%2==1){
            ll jmax = (i-1)/2;
            for(int j=0;j<=jmax;j++){
                ll temp = combination(K-i+N,N-j);
                temp *= powm(2,j),m(temp);
                temp *= combination(jmax,j),m(temp);
                ans+=temp;
                m(ans);
            }
        }else{
            ll jmax = (i-2)/2;
            for(int j=0;j<=jmax;j++){
                ll temp = combination(K+N-i-1,N-j-1);
                temp += combination(K+N-i,N-j),m(temp);
                temp *= powm(2,j),m(temp);
                temp *= combination(jmax,j),m(temp);
                ans+=temp;
                m(ans);
            }
        }
        small[i]=ans;
        cout<<ans<<endl;
    }
    for(int i = K;i >= 2 ;i--){
        cout<<small[i]<<endl;
    }
}


Measured memory_bytes: 384
N = int(input())
All = [list(map(int, input().split())) for _ in range(N)]
t = [row[0] for row in All]
x = [row[1] for row in All]
y = [row[2] for row in All]
pre_x = 0
pre_y = 0
pre_t = 0

can = True
for n in range(N):
    can2 = False
    T  = abs(t[n] - pre_t)
    dx = abs(x[n] - pre_x)
    dy = abs(y[n] - pre_y)
    # print(T,dx,dy)
    if dx + dy == 0 and T % 2 == 0:
        can2 = True
        # print("成功")
    elif dx + dy == 0 and T % 2 != 0:
        can2 = False
        # print("失敗")
        break

    if (T % (dx + dy)) == 0:
        can2 = True
        # print("成功")

    if can2 == False:
        can = False
        # print("失敗")
        break

    pre_t = t[n]
    pre_x = x[n]
    pre_y = y[n]

if can == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 29792
class Fermat:
    
    def __init__(self, size, mod):
        self.size = size
        self.mod = mod
        self.factorial = [1]
        self.inverse = [1]
        pre_f = 1
        for i in range(1, self.size+1):
            pre_f = (pre_f * i) % self.mod
            self.factorial.append(pre_f)
            self.inverse.append(pow(pre_f, self.mod-2, self.mod))
    
    def comb(self, n, r):
        if n < r:
            return 0
        else:
            return (self.factorial[n] * self.inverse[r] * self.inverse[n-r]) % self.mod
        
    def perm(self, n, r):
        if n < r:
            return 0
        else:
            return (self.factorial[n] * self.inverse[n-r]) % self.mod
      
if __name__ == "__main__":
    Fermat = Fermat(1000, 10**9+7)
    n, k = [int(i) for i in input().split()]
    print(Fermat.perm(k, n))


Measured memory_bytes: 5620
int main()
{
  char name[20];
  int cnt = -1;
  long n;
  scanf("%ld",&n);
  while(n)
  {
    int r = (n-1) % 26;
   	name[++cnt] = 'a' + r;
    n = (n-1) / 26;
  }
  for(int i = cnt ; i >= 0 ; i--)
    printf("%c",name[i]);
}


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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N;
    cin >> N;
    map<string, int> m;
    for (int i=0; i<N; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        m[s] ++;
    }

    long long ans = 0;
    for (auto it=m.begin(); it!=m.end(); ++it) {
        if (2 <= it->second) {
            ans += (long long)it->second * ((long long)it->second - 1) / 2;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;
 
signed main(){
    int N;cin>>N;
    int A[N],B[N];
    REP(i,N)cin>>A[i];
    REP(i,N)cin>>B[i];
    int lA[N],rB[N];
    REP(i,N){
        if(i==0){
            lA[i]=A[i];
            rB[i]=B[N-1-i];
        }
        else{
            lA[i]=lA[i-1]+A[i];
            rB[i]=rB[i-1]+B[N-1-i];
        }
    }
    int ans=0;
    REP(i,N){
        ans=max(lA[i]+rB[N-1-i],ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#define ll long long
#define INF 100000000000
#define N 10000000
using namespace std;

int main(){
    ll n;
    cin>>n;
    vector<ll> data;
    for(ll i=0; i<n; i++){
        ll p;
        cin>>p;
        data.push_back(p);
    }
    
    sort(data.begin(),data.end());
    ll ans=data[n-1];
    ll p=n-2;
    
    for(ll i=1; i<n-1; i++){
        ans+=data[p];
        if(i%2==0) p--;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 5372
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
int main()
{
	int max = 1;
	std::map<std::string, int> m;
	{
		int n;
		std::cin >> n;
		for (int i = 0; i < n; ++i)
		{
			std::string val;
			std::cin >> val;
			if (m.find(val) == m.end())
			{
				m.insert(std::make_pair(val, 1));
			}
			else
			{
				int current = ++m[val];
				max = std::max(max, current); // 最大登場回数を保持
			}
		}
	}

	for (auto &el : m)
	{
		if (el.second == max)
		{
			std::cout << el.first << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 25216
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a;
 
double sum(vector<int> a) {
  double result = 0;
  for_each(begin(a), end(a), [&](auto x) {
    result += x;
  });
 
  return result;
}
 
void solve() {
  sort(begin(a), end(a), greater<int>());
  double s = sum(a);
 
  if (a[m-1] >= s / (4*m) ) {
    cout << "Yes"s;
  } else {
    cout << "No"s;
  }
}
 
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    a.push_back(ai);
  }
 
  solve();
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n, p = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    has_odd = False
    for v in a:
        if v % 2 != 0:
            has_odd = True
            break
    if p == 0:
        if has_odd:
            print(2 ** (n - 1))
        else:
            print(2 ** n)
    else:
        if has_odd:
            print(2 ** (n - 1))
        else:
            print(0)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

int main(void){
  double x,h;
  while(cin >> x >> h,x&&h)
    printf("%.6f\n",x*x + sqrt((x*x)/4+h*h) *x *2);

  return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	ss := []rune(s)
	st := []rune(t)

	var ok int

	for i := 0; i < len(ss); i++ {
		if string(ss[i]) == string(st[i]) {
			ok++
		}
	}

	fmt.Println(ok)
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 511;
int n;
int t[MAX][MAX];
int sum_z[MAX][MAX];
int sum_do[MAX][MAX];
int dp[MAX][MAX];
const int inf = 1e15;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  int all = 0;
  R(i,n)R(j,n){
    if(i != j){
      cin >> t[i][j];
      all += t[i][j];
    }
  }
  R(i,n)for(int j = i; j>=0;j--){
    sum_z[i][j] = sum_z[i][j + 1] + t[i][j];
  }
  R(i,n)R(j,n){
    sum_do[i][j+1] = sum_do[i][j] + t[j][i];
  }
  R(i,n){
    R(ko,i+1)R(po,ko+1){
      dp[ko][po] += sum_z[i][po] + sum_do[i][ko];
      maxi(dp[i+1][ko], dp[ko][po]);
    }
    
  }
  int res = 0;
  R(i,n){
    maxi(res, dp[n][i]);
  }
  cout << all - res << "\n";
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  
  int n,m;cin>>n>>m;
  
  vector<pair<ll,ll>> vec(n);
  
  rep(i,n) {
    ll a,b;cin>>a>>b;
    pair<ll, ll> sample = {a,b};
    vec[i]=sample;
  }
  
  sort(vec.begin(),vec.end());
  
  ll ans=0;
  ll hon=0;
  rep(i,n) {
    if (hon+vec[i].second<m) {
      hon+=vec[i].second;
      ans+=vec[i].first*vec[i].second;
    }
    else {
      ans+=vec[i].first*(m-hon);
      break;
    }
  }
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 1792
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int,ss_raw()))


poss = []
for i in range(5):
    p = int_raw()
    poss.append(p)

def main(t,flags):
    if not (False in flags):
        return t
    ot = ((t+9)//10)*10
    mint = 10**10
    for i in range(5):
        if flags[i]==False:
            f = list(flags)
            f[i]=True
            mint = min(mint,main(ot+poss[i],f))
    return mint

print(main(0,[False]*5))


Measured memory_bytes: 3064
n, x, m = map(int, input().split())
ans = 0
if x == 0:
    print(0)
    exit()
elif x == 1:
    print(n)
    exit()

flag = [False]*m
a = []
while not flag[x]:
    flag[x] = True
    a.append(x)
    x = pow(x, 2, m)
loop_start_idx = a.index(x)
loop_len = len(a) - loop_start_idx
loop_count = (n - loop_start_idx)//loop_len
loop_amari = (n-loop_start_idx)%loop_len
ans = sum(a[:loop_start_idx])
ans += sum(a[loop_start_idx:])*loop_count
ans += sum(a[loop_start_idx: loop_start_idx + loop_amari])
print(ans)


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

int main(){
	string s;
	cin>>s;
	int ans=1e9;
	for(int i=0;i<2;i++){
		int cnt=0;
		for(int j=0;j<s.size();j++){
			if(s[j]!=(char)('0'+(j+i)%2))cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d", &W);
	scanf("%d", &H);
	scanf("%d", &x);
	scanf("%d", &y);
	scanf("%d", &r);

	if ((x - r >= 0) && (x + r <= W) && (y - r >= 0) && (y + r <= H))
	{
		printf("Yes\n");
	}

	else
	{
		printf("No\n");
	}

	return 0;
}


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

int main(void)
{
    vector<int> vec(5);

    for (int i = 0; i < 5; i++)
    {
        cin >> vec[i];
        if (vec[i] == 0)
        {
            cout << i+1 << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3596
count = Hash.new(0)

1.upto(100) do |x|
  1.upto(100) do |y|
    1.upto(100) do |z|
      count[x * x + y * y + z * z + x * y + y * z + z * x] += 1
    end
  end
end

n = gets.to_i
1.upto(n) do |i|
  puts count[i]
end


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

using namespace std;

struct Card {
  int n;
  char c;
  Card(int n, int c): n(n), c(c) {}
};

int T;
 
int main(){

  cin >> T;
  vector<Card> cs(9, Card(0, '0'));
  while (T-- > 0) {
    for (int i = 0; i < 9; i++) {
      cin >> cs[i].n;
    }

    for (int i = 0; i < 9; i++) {
      cin >> cs[i].c;
    }

    int res = 0;
    int order[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
    do {
      bool flg = true;
      for (int i = 0; i < 9; i += 3) {
        if (cs[order[i]].c == cs[order[i + 1]].c && cs[order[i]].c == cs[order[i + 2]].c) {
          int n1 = cs[order[i]].n, n2 = cs[order[i + 1]].n, n3 = cs[order[i + 2]].n;
          if ( (n1 == n2 && n2 == n3) || ( (n2 - n1) == 1 && (n3 - n2) == 1) ) {

          } else {
            flg = false;
            break;
          }
        } else {
          flg = false;
          break;
        }
      }

      if (flg) {
        res = 1;
        break;
      }

    } while (next_permutation(order, order + 9));

    cout << res << endl;

  }

 
  return 0;
}

Measured memory_bytes: 908
N,M=map(int,input().split())
import copy
a=[0]*M
b=[0]*M
for i in range(M):
    a[i],b[i]=map(int,input().split())
D=[[1]]
def route(D):
    E=[]
    D1=copy.deepcopy(D)
    for j in range(len(D)):
        x=D[j][-1]
        for i in range(M):

            if a[i]==x:
                if not b[i] in D1[j]:
                    D[j]=copy.deepcopy(D1[j])
                    D[j].append(b[i])
                    E.append(D[j])
            elif b[i]==x:
                if not a[i] in D1[j]:
                    D[j]=copy.deepcopy(D1[j])
                    D[j].append(a[i])
                    E.append(D[j])
    return E
for i in range(N-1):
    D=copy.deepcopy(route(D))
print(len(D))

    

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

int main(){
    map<int,int> path;
    for(int i=0;i<4;i++){
        path[i]=0;
    }
    for(int i=0;i<3;i++){
        int a,b;cin>>a>>b;a--;b--;
        path[a]++;
        path[b]++;
    }
    for(int i=0;i<4;i++){
        if(path[i]==3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;


public class Contest
{
	public static void Main()
	{

/*
		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) MyRead.Array(out e[i]);

		int[] a;
		MyRead.Array(out a);

        long a,b,c,d,e,f;
        MyRead.Multi(out a, out b, out c, out d, out e, out f);

		Console.WriteLine(string.Join(' ', Array.ConvertAll(ans, x => x.ToString())));
*/

        int a,b,c;
		MyRead.Multi(out a, out b, out c);



		long ans = c-(a-b);
		if(ans<0) ans = 0;

		Console.WriteLine(ans);
	}


}

public static class MyRead
{
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
	                                  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	                                  : eq<T, double>() ? ct<T, double>(double.Parse(s))
	                                  : eq<T, char>()   ? ct<T, char>(s[0])
	                                                    : ct<T, string>(s);
	public static string[] Array<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 												
		a = System.Array.ConvertAll(ar, new Converter<string,T>(cv<T>));
		return ar;
	}										
	public static string[] Multi<T>(out T a) {
		var ar = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] Multi<T, U>(out T a, out U b) {
		var ar = Multi<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] Multi<T, U, V>(out T a, out U b, out V c) {
		var ar = Multi<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = Multi<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = Multi<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = Multi<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}
}




Measured memory_bytes: 13268
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 305;

int n;
char c[2 * MAXN][2 * MAXN];
int dp[2 * MAXN][2 * MAXN];
int dp2[2 * MAXN][2 * MAXN];

int main() { 

  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%c", &c[i][j]);
    }
    scanf("\n");
  }
  for (int i = 0; i < 2 * n; i++) {
    for (int j = 0; j < 2 * n; j++) {
      if (c[i][j] != 0) {
        continue;
      }
      c[i][j] = c[i % n][j % n];
    }
  }

  for (int i = 0; i < 2 * n; i++) {
    for (int j = 0; j < 2 * n; j++) {
      dp[i][j] = 1;
      int li = i, lj = j;
      int ri = i, rj = j;
      while (true) {
        li++; lj--;
        ri--; rj++;
        if (li >= 2 * n || lj < 0 || ri < 0 || rj >= 2 * n) {
          break;
        }
        if (c[li][lj] != c[ri][rj]) {
          break;
        }
        dp[i][j]++;
      }
    }
  }

  for (int i = 0; i < 2 * n; i++) {
    for (int j = 0; j < 2 * n; j++) {
      dp2[i][j] = 0;
      int li = i, lj = j;
      int ri = i - 1, rj = j + 1;
      while (true) {
        if (li >= 2 * n || lj < 0 || ri < 0 || rj >= 2 * n) {
          break;
        }
        if (c[li][lj] != c[ri][rj]) {
          break;
        }
        dp2[i][j]++;
        li++; lj--;
        ri--; rj++;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int si = i, sj = j;
      int len = 1;
      int dl = 1;
      bool good = true;

      for (int k = 0; k < 2 * n - 1; k++) {
        if (k % 2 == 0) {
          if (2 * dp[si][sj] - 1 < len) {
            good = false;
            break;
          }
        } else {
          if (2 * dp2[si][sj] < len) {
            good = false;
            break;
          }
        }
        if (k % 2 == 0) {
          si++;
        } else {
          sj++;
        }
        if (len == n) {
          dl = -1;
        }
        len += dl;
      }

      if (good) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

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

      sc.nextLine();

      String line = sc.next();

      int[] results = new int[n + 1];
      for (int i = 0; i < line.length() - 1; i++) {
        if (line.charAt(i) == 'A' && line.charAt(i + 1) == 'C') {
          results[i + 1] = results[i] + 1;
        } else {
          results[i + 1] = results[i];
        }
      }

      for (int i = 0; i < q; i++) {
        int l = sc.nextInt();
        int r = sc.nextInt();
        System.out.println(results[r - 1] - results[l - 1]);
      }
    }
  }
}

Measured memory_bytes: 69948
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    G = [[0] * N for _ in range(N)]

    for _ in range(N):
        v, k, *U = il()
        for u in U:
            G[v - 1][u - 1] += 1

    for g in G:
        print(*g)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7912
#include <iostream>
using namespace std;
int main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  if(a==0||b==0){
    if(a==0&&b==0){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          cout<<0;
        }
        cout<<endl;
      }
    }else if(a==0){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(i<b){
            cout<<0;
          }else{
            cout<<1;
          }
        }
        cout<<endl;
      }
    }else{
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(j<a){
            cout<<0;
          }else{
            cout<<1;
          }
        }
        cout<<endl;
      }
    }
  }else{
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(i<b&&j<a){
          cout<<0;
        }else if(i<b){
          cout<<1;
        }else if(j<a){
          cout<<1;
        }else{
          cout<<0;
        }
      }
      cout<<endl;
    }
  }
  return 0;
}


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


void topology(vector<int > adj[],int n,int visited[],stack<int>& s,int v)
{
	visited[v] = 1;
	for(int i=0;i<adj[v].size();i++)
	{
		if(visited[adj[v][i]] == 0)
			topology(adj,n,visited,s,adj[v][i]);
	}
	s.push(v);
}
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> adj[n+1];
	memset(adj,0,sizeof(adj));
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
	}
	stack <int> s;
	int visited[n+1];
	memset(visited,0,sizeof(visited));
	for(int i=1;i<=n;i++)
	{
		if(visited[i] == 0)
			topology(adj,n,visited,s,i);

	}



	int dis[n+1];
	memset(dis,0,sizeof(dis));
	while(!s.empty())
	{
		int u = s.top();
		s.pop();
		for(int v=0;v<adj[u].size();v++)
		{
			//cout<<adj[u][v]<<" "<<u<<" "<<endl;
			if(dis[adj[u][v]] < dis[u] + 1)
			{
				dis[adj[u][v]] = dis[u] + 1;
			}
		}
	}
	int ans = 0;
	for(int i = 1;i<=n;i++)
	{
		ans = max(ans,dis[i]);
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 9216
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static String ans = "keyence";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        if (str.contains(ans)) {
            System.out.println("YES");
            return;
        }
        int count = 0;
        for (int i = 0; i < 7; i++) {
            if (str.charAt(i) == ans.charAt(i)) {
                count++;
            }
        }
        String left = ans.substring(count);
        String le = str.substring(str.length() - 7 + count);
        if (left.equals(le)) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 23124
def tokyo():
    t = float(sum(station_lis)) / (v1 + v2)
    x = v1 * t
    total = 0
    for index, length in enumerate(station_lis):
        total += length
        if x <= total:
            print index+1
            break

while True:
    try:
        input_line = [int(char) for char in raw_input().split(',')]
        station_lis = input_line[:10]
        v1 = input_line[-2]
        v2 = input_line[-1]
        tokyo()
    except EOFError:
        break

Measured memory_bytes: 4220
#include <iostream>

using namespace std;

int main() {
    long long int N;
    cin >> N;
    
    long long int s=0;
    long long int n=N;
    while(n!=0) {
        s += n%10;
        n /= 10;
    }
    
    if(N%s) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,k;
  cin>>n>>k;
  vector<long long int> p(n);
  for(long long int i=0; i<n; i++){
    cin>>p.at(i);
  }
  sort(p.begin(),p.end());
  long long int ans=0;
  for(long long int i=0; i<k; i++){
    ans+=p.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int ex = Integer.parseInt(sc.next());
		int[] teki = new int[n];
		for(int i = 0; i < n; i++){
			teki[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(teki);
		n -= ex;
		long res = 0L;
		for(int i = 0; i < n; i++){
			res += teki[i];
		}
		System.out.println(res);
	}
	
}

Measured memory_bytes: 60708
N,Y=map(int,input().split())
judge=False
for i in range(N+1):
    for j in range(N+1-i):
        S=i*10000+j*5000+(N-i-j)*1000
        if S==Y:
            judge=True
            break
    if judge:break

if judge:print(i,j,N-i-j)
else:print(-1,-1,-1)

Measured memory_bytes: 3060
import math


def is_integer(p1, p2):
    total = 0
    for i, j in zip(p1, p2):
        total += (i - j) ** 2
    if math.sqrt(total) * 10 % 10 == 0:
        return True
    else:
        return False


def cnt_integer(points):
    cnt = 0
    size = len(points)

    for i in range(size):
        for j in range(i):
            if is_integer(points[i], points[j]):
                cnt += 1

    return cnt


def main():
    points = []
    N, D = map(int, input().split())

    for _ in range(N):
        points.append(list(map(int, input().split())))

    print(cnt_integer(points))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    ll N;
    cin >> N;
    vs S(N);

    map<string, ll> map;
    for(ll i=0; i<N; i++){
        cin >> S.at(i);
        map[S.at(i)] += 1;
    }

    cout << map.size() << endl;


}

Measured memory_bytes: 23112
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <climits>
#include <cmath>
#include <stdio.h>

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> v(n); 
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    long long ans = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (v[i] > v[i + 1]) 
        {
            ans += v[i] - v[i + 1], v[i + 1] = v[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4056
s = input().split(" ")
st = []
for i in range(len(s)):
    if s[i] == "+":
        a = st.pop()
        b = st.pop()
        st.append(a+b)
    elif s[i] == "-":
        a = st.pop()
        b = st.pop()
        st.append(b-a)
    elif s[i] == "*":
        a = st.pop()
        b = st.pop()
        st.append(a*b)
    else:
        st.append(int(s[i]))
print(st[0])

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

int main(){
 int A,B;
 cin >> A >> B;

 if (A == 1) A = 14;
 if (B == 1) B = 14;


 if (A > B)cout << "Alice" << endl;
 else if (A < B)cout << "Bob" << endl;
 else cout << "Draw" << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long INF = 1LL << 60;
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(){
    ll d ;cin>>d;
    vector<ll> c(26);rep(i,26)cin>>c[i];
    vector<vector<ll>> s(d,vector<ll>(26));
    vector<ll> x(26);
    vector<ll> bai(26); //何倍のcを追加するかのチェック

    ll ans = 0;

    rep(i,d){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    //vector<ll> t(d);rep(i,d)cin>>t[i];

    rep(i,d){
        vector<P> lans(26);


        rep(j,26){
            ll tmpans =ans;
            vector<ll> tmpbai = bai;
            tmpans+=s[i][j];
            tmpbai[j]=i+1;


            rep(k,26){
                tmpans-=c[k]*(i+1-tmpbai[j]);
               // cout<<tmpans<<endl;
            }
            P p(tmpans,j);
            lans[j]=p;

        }
        sort(lans.begin(),lans.end());
        cout<<lans[25].second+1<<endl;
        bai[lans[25].second]=i+1;
        ans =lans[25].first;
    }


}

Measured memory_bytes: 3724
Q, H, S, D = map(int, input().split())
N = int(input())

values = [(Q * 8, Q, 0.25), (H * 4, H, 0.5), (S * 2, S, 1), (D, D, 2)]
values.sort()

sum_v = 0
sum_cost = 0
idx = 0
while sum_v < N and idx < 4:
    v = values[idx][2]
    n = (N - sum_v) // v
    sum_v += n * v
    sum_cost += int(values[idx][1] * n)
    idx += 1

print(sum_cost)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    ll n,m,x;
    cin >>n>>m>>x;
    vector<ll> c(n,0);
    ll A[n][m]={0,0};
    
    ll ans=INF;
    REP(i,n){
        cin >>c[i];
        REP(j,m){
            cin>>A[i][j];
        }
    }

  for(ll i=0;i<(1<<n);i++){
    vector<ll> skill(m,0);
    ll cost=0;
        for(ll j=0;j<n;j++){
            if(i>>j&1){
                REP(k,m) skill[k]+=A[j][k];
                cost+=c[j];
            }
        }
        REP(j,m){
            if(skill[j]<x){
                cost=INF;
                break;
            }
        }
        ans = min(ans,cost);
    }
    if (ans==INF) cout <<-1<<endl;
    else cout <<ans<<endl;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  double n,t,a,x=1000,y;
  cin>>n>>t>>a;
  vector<double> v(n);
  rep(i,n) cin>>v[i];
  rep(i,n){
    if(abs(a-(t-v[i]*0.006))<x){
      x=abs(a-(t-v[i]*0.006));
      y=i;
    }
  }
  cout<<y+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int s, i=1;
  cin>>s;
  while(s!=4 && s!=2 && s!=1){
    if(s%2==0)
      s=s/2;
    else
      s=3*s+1;
    i++;
  }
  cout<<i+3<<endl;
}

Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int64 N,K; cin >> N >> K;
    vector<int> to(N);
    REP(i,N) cin >> to[i], to[i]--;

    const int I = 60;
    vector<vector<int>> DP(N,vector<int>(I));
    REP(i,N) DP[i][0] = to[i];
    for(int step = 1; step < I; step++){
        REP(i,N){
            DP[i][step] = DP[DP[i][step-1]][step-1];
        }
    }

    int ans = 0;
    int i = 0;
    while(K>0){
        if(K&1){
            ans = DP[ans][i];
        }
        i++;
        K/=2;
    }
    cout << ans + 1 << endl;
}

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

bool comp(pair<int,int> a,pair<int,int> b){
    return a.second < b.second;
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<int,int> > v(M);
    for(int i=0;i<M;i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end(),comp);
    int tmp=0;
    int cnt=0;
    for(int i=0;i<M;i++){
        if(tmp<=v[i].first){
            tmp=v[i].second;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
/*
	watch me go
*/

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define inf (int)LLONG_MAX
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1=998244353;
int const mod=1000000007;
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// *** Using PBDS ***
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// *** Using PBDS ***
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}
bool comp(pii a,pii b)
{
    if(a.first==b.first)
    return a.second<b.second;
    return a.first>b.first;
    
}

signed main() 
{
    haha
    int n,t,m,i,f=0,j,k,x,r;
    int ans=0;
    cin >> n >> k ;
    if(n==1)
    {
        if(k==1) cout << 3 ;
        else cout << 1 ;
        return 0 ;
    }
    int temp;
    for(i=k;i<=n+1;++i)
    {
        temp = (i*(n+1-i)+1)%mod ;
        //cout << temp << endl ;
        //temp++;
        //temp%=P;
        ans=(ans+temp)%mod;
        //cout << ans << endl ;
        
    }
    cout << ans%mod ;
    
    
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(' ')
	const int INF = 0x3f3f3f3f;
	typedef long long LL;
	typedef double DB;
	inline char gchar() {
		char ret = getchar();
		for(; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF; ret = getchar());
		return ret; }
	template<class T> inline void fr(T &ret, char c = ' ', int flg = 1) {
		for(c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar());
		if (c == '-') { flg = -1; c = getchar(); }
		for(ret = 0; '0' <= c && c <= '9'; c = getchar())
			ret = ret * 10 + c - '0';
		ret = ret * flg; }
	inline int fr() { int t; fr(t); return t; }
	template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
	template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
	template<class T> inline char wr(T a, int b = 10, bool p = 1) {
		return a < 0 ? pc('-'), wr(-a, b, 0) : (a == 0 ? (p ? pc('0') : p) : 
			(wr(a/b, b, 0), pc('0' + a % b)));
	}
	template<class T> inline void wt(T a) { wn(a); }
	template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
	template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
	template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
	template<class T> inline T gcd(T a, T b) {
		return b == 0 ? a : gcd(b, a % b); }
	template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
		for(; i; i >>= 1, b = b * b % _m)
			if(i & 1) r = r * b % _m;
		return r; }
};
using namespace my_header;

int a[1111111];

int main() {
#ifdef lol
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	int n;
	n = fr() * 3;
	for (int i = 1; i <= n; ++i)
		a[i] = fr();
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	long long ans = 0;
	for (int i = 2; i <= 2 * (n / 3); i += 2) {
		ans += a[i];
	}
	wt(ans);


	return 0;
}

Measured memory_bytes: 1408
x_1, y_1, x_2, y_2 = map(int, input().split())

x_length = x_2 - x_1
y_length = y_2 - y_1

x_3 = x_2 - y_length
y_3 = y_2 + x_length
x_4 = x_1 - y_length
y_4 = y_1 + x_length

print(x_3, y_3, x_4, y_4)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int Mod=1e9+7;
int n,k,a[110],f[110][100010],s[110][100010];
void upd(int &x,int v)
{
	x=(x+v)%Mod;
}
int ask(int x,int l,int r)
{
	int res=s[x][l];
	if (r>=0)
	{
		upd(res,Mod-s[x][r]);
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&k);
	f[0][0]=1;
	for (int i=0;i<=k;i++)
	{
		s[0][i]=1;
	}
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=k;j++)
		{
			upd(f[i][j],ask(i-1,j,j-a[i]-1));
			s[i][j]=(s[i][j-1]+f[i][j])%Mod;
			//cerr<<f[i][j]<<" ";
		}
		//cerr<<endl;
	}
	cout<<f[n][k]<<endl;
	return 0;
}


Measured memory_bytes: 84224
S = list(input())
N = len(S)
K = int(input())
if len(set(S)) == 1:
    print((N*K)//2)
    exit()

cnt = 0
tmpS = S*1
for i in range(N-1):
    if tmpS[i] == tmpS[i+1]:
        cnt += 1
        tmpS[i+1] = '!'

if S[N-1] == S[0]:
    a = 1
    while a <= N-1 and S[a-1] == S[a]:
        a += 1
    b = 1
    while b <= N-1 and S[N-b] == S[N-b-1]:
        b += 1
    print(cnt*K-(a//2+b//2-(a+b)//2)*(K-1))
else:
    print(cnt*K)

Measured memory_bytes: 9144
/*
 * Code be weshen zyk :'(
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define F first
#define S second

using ll = long long;
using ii = pair<int, int>;
using db = long double;

#ifdef ONLINE_JUDGE
#define cerr if(0)cerr
#endif

template<class C> void amin(C &a4, C b4) {
	a4 = min(a4, b4);
}
template<class C> void amax(C &a4, C b4) {
	a4 = max(a4, b4);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
	os << "[";
	for (auto vv : V)
		os << vv << ",";
	return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}

const int N = 1e5 + 5;
int n, m;
ll dp[N];
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	int n, c;
	cin >> n >> c;
	fill(dp,dp+N,c+1);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		int w, v;
		cin >> w >> v;
		for(int j = N - 1; j >= v; --j){
			dp[j] = min(dp[j], dp[j-v] + w);
		}
	}

	for(int i = N-1; i >= 0; --i){
		if(dp[i] <= c){
			cout << i << '\n';
			return 0;
		}
	}

	return 0;
}


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

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];
int max_len;
int memo[MAX_N][MAX_N][4];

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

int rec(int y, int x, int d)
{
    if (memo[y][x][d] >= 0)
        return memo[y][x][d];

    int nx = x + dx[d];
    int ny = y + dy[d];

    if (nx < 0 || nx >= n || ny < 0 || ny >= n)
        return 1;
    if (grid[ny][nx] == '0')
        return 1;

    return memo[y][x][d] = (rec(ny, nx, d) + 1);
}

int main()
{
    while (cin >> n, n) {
        max_len = 0;
        for (int i = 0; i < n; i++) 
            cin >> grid[i];

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
                for (int k = 0; k < 4; k++)
                    memo[i][j][k] = -1;

        for (int y = 0; y < n; y++) 
            for (int x = 0; x < n; x++) 
                if (grid[y][x] == '1') {
                    for (int k = 0; k < 4; k++) {
                        int nx = max_len * dx[k] + x;
                        int ny = max_len * dy[k] + y;
                        if (nx < 0 || nx >= n || ny < 0 || ny >= n)
                            continue;
                        if (grid[ny][nx] != '1')
                            continue;
                        max_len = max(max_len, rec(y, x, k));
                    }
                }

        cout << max_len << endl;
    }

    return 0;
}

Measured memory_bytes: 2352
/*Distinct subsequence with maximum length*/

#include<bits/stdc++.h>
#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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t

inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}



int main() 
{ 
	fast();
	string s;
	cin>>s;
	lli n=s.length();
	lli arr[n];
	rep(i,0,n)
		arr[i] = s[i] - 48;
		
	//cout<<maxLen(arr, n); 
	stack<lli> st;
	for(auto it:arr)
	{
		if(st.empty())
			st.push(it);
		else
		{
			if((st.top()+it)==1)
			{
				st.pop();
			}
			else
				st.push(it);
		}
	}
	cout<<n-st.size();
	return 0; 
} 



Measured memory_bytes: 2000