akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int n, i, j, rank[52];
    char suit[52];
    int SR[13] = {0}, HR[13] = {0}, CR[13] = {0}, DR[13] = {0};
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%s %d", &suit[i], &rank[i]);
    }
  
    for (j = 0; j < n; j++){
        switch(suit[j]){
            case 'S':
                SR[rank[j]-1] = 1;
                break;
            case 'H':
                HR[rank[j]-1] = 1;
                break;
            case 'C':
                CR[rank[j]-1] = 1;
                break;
            case 'D':
                DR[rank[j]-1] = 1; 
                break;
        }
    }
  
    for (i = 0; i < 13; i++){
        if (SR[i] == 0){
            printf("S %d\n", i+1);
        }   
    }
    for (i = 0; i < 13; i++){
        if (HR[i] == 0){
            printf("H %d\n", i+1);
        }   
    }
    for (i = 0; i < 13; i++){
        if (CR[i] == 0){
            printf("C %d\n", i+1);
        }   
    }
    for (i = 0; i < 13; i++){
        if (DR[i] == 0){
            printf("D %d\n", i+1);
        }   
    }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=21;
int a[N];
int main()
{
	int n;init(n);
	for(int i=1;i<=n;++i) init(a[i]);
	int ans=0;
	for(int i=2;i<n;++i) if((a[i]<a[i-1]&&a[i]>a[i+1])||(a[i]<a[i+1]&&a[i]>a[i-1])) ++ans;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}

long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}


long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn=1, Kr=1, Knr=1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	long long int N, M, K;
	cin >> N >> M >> K;

	const long long int MOD = 1000000007;

	long long int S1, S2;

	S1 = 0;
	for (int i = 1; i <= N-1; i++)
	{
		S1 += i * (N - i);
		S1 %= MOD;
	}
	S1 *= M;
	S1 %= MOD;
	S1 *= M;
	S1 %= MOD;

	S2 = 0;
	for (int i = 1; i <= M-1; i++)
	{
		S2 += i * (M - i);
		S2 %= MOD;
	}
	S2 *= N;
	S2 %= MOD;
	S2 *= N;
	S2 %= MOD;

	long long int ans = ModCombi(N*M - 2, K - 2, MOD);
	ans *= S1 + S2;
	ans %= MOD;

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define MAX_N 100
#define MAX_M 100

int n,m,dif;
int Sn[MAX_N];
int Sm[MAX_M];
bool a;

bool input(){
  cin>>n>>m;
  dif=0;
  a=false;
  REP(i,n){
    cin>>Sn[i];
    dif+=Sn[i];
  }
  REP(i,m){
    cin>>Sm[i];
    dif-=Sm[i];
  }
  return(n!=0);
}

void solve(){
  REP(i,n){
    REP(j,m){
      if((Sn[i]-Sm[j])*2==dif){
        cout<<Sn[i]<<' '<<Sm[j]<<endl;
        a=true;
        break;
      }
    }
    if(a)break;
  }
  if(a!=true)cout<<-1<<endl;
}

int main(){
  dif=0;
  a=false;
  REP(i,MAX_N)Sn[i]=0;
  REP(i,MAX_M)Sm[i]=0;
  while(input()){
    solve();
  }
  return 0;
}

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

struct node{
  struct node *right; 
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node *Node;
Node root;

void insert(int);
void preprint();
void inprint();

int main(){
  int i, m, k;
  char c[7];

  scanf("%d",&m);
  for(i = 0; i < m; i++){
    scanf("%s",c);
    if(c[0] == 'i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(c[0] == 'p'){
      inprint(root);
      printf("\n");
      preprint(root);
      printf("\n");
    }
  }

  return 0;
}

void insert(int k){
  Node x = root, y = NULL, z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NULL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void preprint(Node p){
  if(p != NULL){
    printf(" %d",p->key);
    if(p->left != NULL) preprint(p->left);
    if(p->right != NULL) preprint(p->right);
  }
}

void inprint(Node i){
  if(i != NULL){
    if(i->left != NULL) inprint(i->left);
    printf(" %d",i->key);
    if(i->right != NULL) inprint(i->right);
  }
}

Measured memory_bytes: 24040
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;

int lx[Max][2], ly[Max][2];

int main()
{
	int x, y, n;
	cin >> x >> y >> n;
	while(n--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		if (c == 1)lx[a][0] = 1;
		if (c == 2)lx[a][1] = 1;
		if (c == 3)ly[b][0] = 1;
		if (c == 4)ly[b][1] = 1;
	}
	int trx = x, tlx = 0, ty = y, tly = 0;
	for (int i = 1; i <= max(x,y); i++)
	{
		if (lx[i][0])tlx = max(tlx, i);
		if (lx[i][1])trx = min(trx, i);
		if (ly[i][0])tly = max(tly, i);
		if (ly[i][1])ty = min(ty, i);
	}
	if (tlx >= trx || tly >= ty)cout << 0 << endl;
	else cout << (trx - tlx) * (ty - tly) << endl;
}

Measured memory_bytes: 3136
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++)
	{
		if((a*i)%b==c)
		{
			cout<<"YES\n";
			return 0;
		}
	}
	cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = unsigned long long;

ll sumarr(int a[], int n) {
  ll s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
  }
  return s;
}


int main() {
  const int nmax = 200000;
  int n;
  int a[nmax];
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  ll all = sumarr(a, n);
  ll half0, half1;

  if (all %2 == 0) {
    half0 = all / 2;
    half1 = all / 2;
  } else {
    half0 = all / 2;
    half1 = all / 2 + 1;
  }

  ll tmp = 0;

  int i;
  for (i = 0; i < n; i++) {
    tmp += a[i];
    if (half1 <= tmp) break;
  }

  ll diff0 = half0 - (tmp - a[i]);
  ll diff1 = tmp - half1;

  ll target;

  if (diff0 < diff1) {
    target = tmp - a[i];
  } else {
    target = tmp;
  }

  ll rest = all - target;

  if (target < rest) {
    cout << rest - target << endl;
  } else {
    cout << target - rest << endl;
  }
}


Measured memory_bytes: 1024
main = do
  (n:p:xs) <- (map read) . words <$> getLine
  putStrLn . show $ solve n p


solve :: Integer -> Integer -> Integer
solve num p = calcFactors num p primeList
  where
    calcFactors :: Integer -> Integer -> [Integer] -> Integer
    calcFactors n 1 primes = 1
    calcFactors n prod (pr:primes) =
      let nd = nDiv prod pr
      in if pr * n > prod || (pr^2 > p) then (if n == 1 then prod else 1) else
        (pr ^ (nd `div` n)) * (calcFactors n (prod `div` (pr^nd)) primes)

nDiv x pr = if x `mod` pr == 0 then 1 + (nDiv (x `div` pr) pr) else 0

--primeList :: Integral a => a
primeList = 2 : prime'
prime' = 3 : 5 : 7 : (siege 3 prime')
siege m (a:b:xs) = [n|n<-[a^2,a^2+2..b^2-2],gcd n m<2] ++ (siege (m*b) (b:xs))


Measured memory_bytes: 7932
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;


int main(void) {
    ll X,K,D;
    cin >> X >> K >> D;
    
    X = abs(X);
    if (X/D > K) {
        cout << X - (K * D) << endl;
    }else{
        ll e = (X / D);
        K -= e;
        X -= e * D;
        if (K % 2 == 0)
            cout << X << endl;
        else
            cout << abs(X - D) << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <cmath>
#include <functional>
#include <map>
#include <cstdio>
#include <stack>
using namespace std;
typedef long long ll;

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

int main(){
    int w;
    string str;
    string ans = "";
    cin >> str;
    cin >> w;
int cnt=0;
if(str.length()%w != 0){
    rep(i, str.length()/w+1){
        cnt++;
        
            ans += str[i*w];
        
    }
}else{
    rep(i, str.length()/w){
        cnt++;
        
            ans += str[i*w];
        
    }
}
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 0
tmp = 100000

for i in range(N):
  if tmp > abs(A - (T - 0.006*H[i])):
        tmp = abs(A - (T - 0.006*H[i]))
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  double a, b, h, m;
  cin >>a>>b>>h>>m;
  double deg=abs(h*30+0.5*m-6*m)/360*2*PI;
  double ans = sqrt(a*a+b*b-2*a*b*cos(deg));
  printf("%.10f\n", ans);
  return 0;
}

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

int main() {
  int N; //city
  int M; //road
  cin >> N >> M;

  int RoadFrom[M], RoadTo[M];

  rep(i, 0, M) {
    cin >> RoadFrom[i] >> RoadTo[i];
  }

  int AnsRoad[N] = {};

  rep(i, 0, M) {
    AnsRoad[ RoadFrom[i]-1 ] += 1;
    AnsRoad[   RoadTo[i]-1 ] += 1;
  }

  rep(i, 0, N) {
    cout << AnsRoad[i] << endl;
  }
}


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

enum {
	MAX_BUFFER = 1024,		/* 読込バッファの最大サイズ */
	NUM_STATION = 10			/* 区間の数 */
};

int l[10];
int v[2];

int FuncSearchPlaceNow(void);



int main(void)
{
	char buf[MAX_BUFFER];
	int now;

	while (fgets(buf, sizeof(buf), stdin) != NULL) {
		sscanf(buf, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
					 &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9],
					 &v[0], &v[1]);

		now = FuncSearchPlaceNow();
		printf("%d\n", now);
	}

	return 0;
}

int FuncSearchPlaceNow(void)
{
	int d = 0;
	int i;
	
	for (i = 0; i < NUM_STATION; i++) {
		d += l[i];
	}
	d = (int)(d * (double)v[0] / (double)(v[0] + v[1]));
	for (i = 0; i < NUM_STATION; i++) {
		d -= l[i];
		if (d <= 0) break;
	}
	
	return (i + 1);
}

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

int main()
{
    int n;
    cin>>n;
    int arr[100000][3];
    for(int i=0;i<n;i++)
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    
    int dp[n][3];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        dp[i][j]=0;
    }
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            int temp=0;
            for(int k=0;k<3;k++)
            {
                if(j!=k)
                {
                    temp=max(temp,dp[i-1][k]);
                }
            }
            dp[i][j]=temp+arr[i][j];
        }
        
    }
    cout<<max({dp[n-1][2],dp[n-1][1],dp[n-1][0]})<<"\n";
}

Measured memory_bytes: 2560
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<cstdio>
#include<algorithm>
#include<bitset>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 16;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
bitset<6500> dp1[81];
int main() 
{
	fread(ci, 1, cm, stdin);
	int H, W;
	H = getint(), W = getint();
	char AB[80][80];
	rep(i, H) rep(j, W) 
		AB[i][j] = getint();
	rep(i, H) rep(j, W) 
		AB[i][j] = abs(AB[i][j] - getint());
	dp1[0][0] = true;
	for (int hw = 0; hw <= H + W - 2; hw++)
		for (int w = min(hw, W - 1); w >= max(0, hw - H + 1); w--) {
			int h = hw - w;
			dp1[w] |= dp1[w] << AB[h][w] * 2;
			rep1(i, AB[h][w]) dp1[w][AB[h][w] + i] = (dp1[w][AB[h][w] + i] | dp1[w][AB[h][w] - i]);
			dp1[w] >>= AB[h][w];
			dp1[w + 1] |= dp1[w];
		}
	rep(i, 81)
		if (dp1[W - 1][i]) {
			printf("%d", i);
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int n,m;
vvi a;//a[i][j]はiにつながる頂点の配列.
vi dp;//dp[i]はiまでの有向パスの最長の長さ.

int f(int i){
	if(dp[i]!=0) return dp[i];
	REP(j,a[i].size()){
		dp[i]=max(dp[i],f(a[i][j])+1);//再帰.終端はa[i].size()が0のとき.
	}
	return dp[i];
}

int main(){
	cin>>n>>m;
	
	a.resize(n+1);//point.reserveとは違う.
	REP(i,m){
		int x,y;
		scanf("%d%d",&x,&y);
		a[y].push_back(x);
	}
	
	dp.resize(n+1,0);//point.
	//fill(ALL(dp),0);//resizeと相性良い?
	for(int i=1;i<=n;++i){
		REP(j,a[i].size()){
			dp[i]=max(dp[i],f(a[i][j])+1);
		}
	}
	
	int ans=0;
	for(int i=1;i<=n;++i){
		ans=max(ans,dp[i]);
	}
	
	cout<<ans<<endl;
}//解答参考.

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

#define fmm(x) cerr << "[!] " << #x << " e " << x << "\n";
using ll = long long;

using namespace std;

const int MAX = 100005;

int main(){
  // ENGAGE MODUL RACHETĂ ᕦ(ò_ó)ᕤ
  ios::sync_with_stdio(false);
  cin.tie(0);

  #ifdef ACAS_LA_SEFU
//  freopen("valoare.in", "r", stdin);
  #endif

  int x, y, z; cin >> x >> y >> z;
  swap(x, y); swap(x, z);
  cout << x << " " << y << " " << z;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main ()
{
    char a[200][200];
    int i,j,m,n,k,l;
    cin>>m>>n;
    k=m+2;
    l=n+2;
    for(i=0;i<k;i++)
    {
        for(j=0;j<l;j++)
        {
            a[i][j]='#';
        }
    }


    for(i=1;i<=m;i++)
    {
        for(j=1;j<=n;j++)
        {
           cin>>a[i][j];
        }
    }
    for(i=0;i<k;i++)
    {
        for(j=0;j<l;j++)
        {
           cout<<a[i][j];
        }
        puts(" ");
    }
    puts(" ");

}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++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(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll mod = 1e9+7;
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H+1, vector<char>(W+1, '#'));
    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++) cin >> a[i][j];

    vector<vector<int>> dp(H+1, vector<int>(W+1));
    dp[1][1] = 1;
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(a[i][j] != '#' && !(i==1 && j==1))
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
        }
    }

    // for(int i=1; i<=H; i++){
    //     for(int j=1; j<=W; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[H][W] << endl;
    return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  ll n,a[100010];

  cin>>n;
  rep(i,n)cin>>a[i];
  sort(a,a+n);


  ll start=0,ans=0;
  while(start<n){
    ll tmp=1;
    while(a[start]==a[start+1]&&start<n){
      tmp++;
      start++;
    }
    if(tmp%2==1)ans++;
    start++;
  }

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


Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi l(n);
    rep(i, n) cin >> l[i];
    sort(all(l), greater<ll>());
    ll sum = 0;
    rep(i, k) sum += l[i];
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n-1],b[n-1];
    vector<vector<int>>pas(n);
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i];
        pas[a[i]-1].push_back(b[i]-1);
        pas[b[i]-1].push_back(a[i]-1);
    }
    int root[n];
    int check[n]={};
    check[n-1]=1;
    queue<int>q;
    q.push(n-1);
    while(q.front()){
        int f=q.front();
        q.pop();
        for(int i=0;i<pas[f].size();i++){
            int next=pas[f][i];
            if(check[next]==0){
                check[next]=1;
                q.push(next);
                root[next]=f;
            }
        }
    }
    int x=0;
    vector<int>v;
    while(x!=n-1){
        x=root[x];
        v.push_back(x);
    }
    for(int i=0;i<n;i++)check[i]=0;
    check[v[v.size()/2]]=1;
    check[0]=1;
    int ter=1;
    while(q.size())q.pop();
    q.push(0);
    while(q.size()){
        int f=q.front();
        q.pop();
        for(int i=0;i<pas[f].size();i++){
            int next=pas[f][i];
            if(check[next]==0){
                check[next]=1;
                q.push(next);
                ter++;
            }
        }
    }
    if(ter>n-ter)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    return 0;
}

Measured memory_bytes: 7932
#include <iostream>
using namespace std;
int main(){
	int d,n;
	cin >> d >> n;
	int k = 1;
	for(int i = 0;i < d;i++){
		k *= 100;
	}
	if(n != 100){
		cout << k * n << endl;
	}else{
		cout << k * 101 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
main() {
    ll a,b,c,d,n,ans;
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);
    b = min(b,a*2);
    c = min(c,b*2);
    d = min(d,c*2);
    ans = 0;
    ans += (n/2)*d;
    if(n&1) ans += c;
    printf("%lld",ans);
}


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


const int INF = 1000000000;

int N,A,B,C;
int L[10];

// 合成パターンを全列挙
// コスト最小のものを返す
// count 何個めまで使ったか。
int rec(int count, int a, int b, int c){
	if(count==N){
		if(min(a,min(b,c))>0) // 全部一個は使う。使ってなければ不適
		return abs(A-a) + abs(B-b) + abs(C-c) - 30; // 最初の一個はコスト無し
		else return INF; 
	}
	// L[i]をA~Cのために使う。もしくは使わない。
	int na = rec(count+1,a+L[count],b,c) + 10;
	int nb = rec(count+1,a,b+L[count],c) + 10;
	int nc = rec(count+1,a,b,c+L[count]) + 10;
	int nd = rec(count+1,a,b,c);
	// count 番目のたけをどこにも加えない。
	return min(na , min(nb , min(nc,nd)));
}


int main()
{
	cin >> N >> A >> B >> C;
	for(int i=0;i<N;++i) cin >> L[i];
	
	cout << rec(0,0,0,0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
 
	vector<int> v(5);
	rep(i,5) scanf("%d", &v[i]);
	
	int min=9, ind=0;
	rep(i,5){
 
		if (v[i]%10!=0 and v[i]%10 <= min){
			min = v[i]%10;
			ind = i;
		}
	}
	int ans = v[ind];
	v.erase(v.begin()+ind);
 
	for (auto i : v){
		if (!(i%10)) ans += i;
		else ans += i + (10 -(i%10));
	}
 
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3776
#include<iostream>

#include <math.h>
using namespace std;

typedef  long long ll;

int main(){
	
  	int N;
  	cin >> N;
  	int H,min;
  	int cont = 0;
  	for(int i = 0; i< N ;i++){
      	cin >> H;
      	if(i==0)min = H;
  		if(min<=H){
        	cont++;
        	min = H;
        }

    }
  cout << cont << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string x;
  cin>>x;
  for(int i=0;i<x.size();i++)
  {
  	if(i%2==0)
  	{
  		if(x[i]=='L')
  		return printf("No"),0;
	}
	else 
	{
		if(x[i]=='R')
		return printf("No"),0;
	}
  }
  printf("Yes");

  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    if( b / a >= c ) cout << c << endl;
    else cout << b / a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long double ld;
const int maxn = 200000 + 10;
const long double pi = acos(-1);

int Sx, Sy, Tx, Ty, n, f[maxn];
struct anode{
  int x, y;
  anode() {}
  anode(int _x, int _y):x(_x), y(_y) {}
}a[maxn];

inline bool cmp1(anode a, anode b) {
  return a.x < b.x;
}

int main() {
	scanf("%d%d%d%d%d", &Sx, &Sy, &Tx, &Ty, &n);
	int d1, d2;
	d1 = (Sx < Tx) ? (1) : (- 1);
	d2 = (Sy < Ty) ? (1) : (- 1);
	Sx *= d1; Tx *= d1;
	Sy *= d2; Ty *= d2;
	for(int i = 1;i <= n;i ++) {
	  int x, y;
	  scanf("%d%d", &x, &y);
	  x *= d1;
	  y *= d2;
	  a[i] = anode(x,y);
	}
	sort(a + 1,a + n + 1,cmp1);
	int top = 0;
	for(int i = 1;i <= n;i ++) {
		if(a[i].x > Tx || a[i].y > Ty || a[i].x < Sx || a[i].y < Sy) continue;
		if(top == 0 || f[top] < a[i].y) f[++ top] = a[i].y;
		else {
	    int tmp = lower_bound(f + 1,f + top + 1,a[i].y) - f;
	    f[tmp] = a[i].y;
	  }
	}
	ld ans = (ld)100.0 * (Tx - Sx + Ty - Sy);
	ans = (ld)ans - (20 - 5.0 * pi) * top;
	if(top == min(Tx - Sx + 1,Ty - Sy + 1)) ans += (ld)5.0 * pi;
	printf("%.10Lf\n", ans);
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    ll A,B,K;
    map<ll,int> ans;
    cin >> A >> B >> K;

    lrep(i,K) {
        if(A+i <= B) { 
            ans[A+i] = 1;
        }
        if(B-i >= A) { 
            ans[B-i] = 1;
        }
    }
    
    for(auto k : ans) {
        cout << k.first << endl;
    }

    return 0;
}
    



Measured memory_bytes: 256
#include <stdio.h>
int main() {int RB[3]={1,0,0};char Tex[5];while (scanf("%s",&Tex)!=EOF) if (RB[Tex[0]-'A']!=RB[Tex[2]-'A']) RB[Tex[0]-'A']+=RB[Tex[2]-'A'],RB[Tex[2]-'A']=RB[Tex[0]-'A']-RB[Tex[2]-'A'],RB[Tex[0]-'A']-=RB[Tex[2]-'A']; if (RB[0]) puts("A"); else if (RB[1]) puts("B"); else puts("C");return 0;}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    int a=0, b=0;
    bool same = true;
    for(int i = 0; i < 4; i++){
        if(i==0)a++;
        else{
            if(s[0] == s[i])a++;
            else if(!b)b = i;
            else if(s[i] != s[b])same = false;
        }
    }
    if(a == 2 && same)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

@edge = Array.new(n+1) {[]}
m.times do
    x, y = gets.split.map(&:to_i)
    @edge[x] << y
end

@memo = Array.new(n+1)
@memo[0] = 0

def calc(i)
    return @memo[i] if @memo[i]

    m = 0
    @edge[i].each do |e|
        x = calc(e) + 1
        m = x if m < x
    end

    @memo[i] = m
end

1.upto(n) {|i| calc(i)}
p @memo.max

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<ll> va(n + 1);
    vector<ll> vb(n);

    rep(i, n + 1) cin >> va[i];
    rep(i, n) cin >> vb[i];

    ll ans = 0;
    rep(i, n){
        int j = i;
        if(0 <= va[j] - vb[i]){
            ans += vb[j];
        }else{
            vb[i] -= va[j];
            ans += va[j];
            if(0 <= va[j + 1] - vb[i]){
                ans += vb[i];
                va[j + 1] -= vb[i];
            }else{
                ans += va[j + 1];
                va[j + 1] = 0;
            }
        }
    }
    OP(ans);
}


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

bool is_prime(long long _Num){
    if(_Num < 2)return false;
    if(_Num % 2 == 0){
        if(_Num == 2)return true;
        else return false;
    }
    bool prime = true;
    for(long long i = 3; i <= sqrt(_Num); i += 2){
        if(_Num % i == 0){
            prime = false;
            break;
        }
    }
    return prime;
}

vector<int> memo(100005, 0);

int main(void) {

  int q;
  cin >> q;

  for (int i = 1; i <= 100001; i += 2) {
    if (is_prime(i) && is_prime((i + 1) / 2)) memo[i] = 1;
  }

  for (int i = 2; i <= 100001; i++) {
    memo[i] += memo[i - 1];
  }
  
  int ans[q];
  rep (i, q) {
    int l, r;
    cin >> l >> r;
    ans[i] = memo[r] - memo[l - 1];
  }

  rep (i, q) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))


def calc(l, to):
    cost = 0
    for i in l:
        cost += (i-to)**2
    return cost


ans = 10**9
for i in range(-100, 101):
    ans = min(ans, calc(a, i))
print(ans)


Measured memory_bytes: 2940
n, a, b = map(int, input().split())
ans = 0
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
for i in range(1, n+1):
    if a <= digitSum(i) <= b:
        ans += i
print(ans)

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

int main() {
  int S;
  int S1, S2, S3;

  cin >> S;
  
  S1 = S / 100;
  S2 = (S - S1 * 100) / 10;
  S3 = (S - S1 * 100 - S2 * 10);
  
  cout << S1 + S2 + S3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int r, g, b;
    cin >> r >> g >> b;

    int A = 100 * r + 10 * g + b;
    if (A % 4 == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int hit = 0;
	int x;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			return (0);
		}
		n = n / 4;
		for (i = 0; i < n; i++){
			scanf("%d", &x);
			hit += x;
		}
		printf("%d\n", hit);
		hit = 0;
	}
}

Measured memory_bytes: 600
#pragma comment(linker, "/STACK:500000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

#define y0 y0ChloeGraceMoretz
#define y1 y1ChloeGraceMoretz
typedef long long ll;
int nextInt() { int n; scanf("%d", &n); return n; }
ll nextLong() { ll n; scanf("%lld", &n); return n; }
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = (ll)1e18 + 9;
const int MOD = (int)1e9 + 7;

int a[2009];
int precalc[2009][2009];

int main() {
	//freopen("in.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	int n, x;
	scanf("%d %d", &n, &x);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		precalc[i][0] = a[i];
	}
	for (int i = 1; i <= n; ++i) {
		for (int k = 1; k < n; ++k) {
			int j = i - k;
			if (j <= 0) {
				j += n;
			}
			precalc[i][k] = min(precalc[i][k - 1], a[j]);
		}
	}
	ll res = INF;
	for (int k = 0; k < n; ++k) {
		ll cur = (ll)x * k;
		for (int i = 1; i <= n; ++i) {
			cur += precalc[i][k];
		}
		res = min(cur, res);
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 16000
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[21];
	int i;
	
	while (scanf("%s", str) != EOF){
		scanf("%s", str);
		for (i = strlen(str); i >= 0; i--){
			if ((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')){
				printf("%c", str[i]);
			}
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> P(N), dp(N + 1, 0);
    rep(i, N) cin >> P[i];

    rep(i, N) {
        dp[P[i]] = dp[P[i] - 1] + 1;
    }

    int nax = 0;
    rep(i, N) chmax(nax, dp[i + 1]);
    cout << N - nax << endl;
    return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict

n = int(input())
a = list(map(int,input().split()))

d = defaultdict(int)
for ai in a:
    d[ai] += 1

ans = 0
pair = 0
for k,v in d.items():
    if(v==0):
        continue
    if(v%2==1):
        ans += 1
    else:
        pair += 1

ans += 2*(pair//2)
print(ans)

Measured memory_bytes: 98648
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<int> L;

int main() {
	cin >> N;
	L.resize(N + 2);
	for (int n = 1; n <= N; n++) {
		cin >> L[n];
	}
	L[0] = 0;
	L[N + 1] = 1000 + 1;
	sort(L.begin(), L.end(), [](int a, int b) {
		return a < b;
	});
	long long ans = 0;
	for (int a = 1; a <= N; a++) {
		for (int b = a + 1; b <= N; b++) {
			int bs = b, be = N + 1;
			while (be - bs > 1) {
				int m = (be + bs) / 2;
				if (L[m] > L[b] - L[a])be = m;
				else bs = m;
			}
			int us = b, ue = N + 1;
			while (ue - us > 1) {
				int m = (ue + us) / 2;
				if (L[m] < L[a] + L[b])us = m;
				else ue = m;
			}
			ans += (us - bs);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
  int n, h, w;
  int a[1000]={};
  int b[1000]={};
  int iCnt = 0;
  cin >> n >> h >> w;
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    if(a[i]>=h && b[i]>=w)iCnt++;
  }

  cout << iCnt << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static int calc(int x) {
		int ret = 0;
		while(x % 100 == 0) {
			x/=100;
			ret++;
		}
		return ret;
		
	}
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int d = stdIn.nextInt();
		int n = stdIn.nextInt();
		int cnt = 0;
		int val = 0;
		while(cnt < n) {
			val++;
			if(calc(val) == d) {
				cnt++;
			}
		}
		System.out.println(val);
		
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int num,a,b,c,d;
    cin>>num;
    a = num/500;
    b = a*1000;
    c = num%500;
    c = c/5;
    d = c*5;
    cout<<b+d<<endl;
    return 0;
}


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

using namespace std;

int main() {
	int pos, start;
	string input, tmp;

	while (true) {
		getline(cin, input);
		if (input == "END OF INPUT") {
			break;
		}
//		cout << input << "_out" << endl;
		start = 0;
		pos = input.find(" ", start);
		while (pos != string::npos) {
			tmp = input.substr(start, pos - start);
			//cout << "tmp:" << tmp << endl;
			cout << tmp.size();
			start = pos + 1;
			while (input[start] == ' ') {
				++start;
			}
			while (start - pos != 1) {
				cout << "0";
				++pos;
			}
			pos = input.find(" ", start);
		}
		tmp = input.substr(start, pos - start);
		cout << tmp.size() << endl;
	}
	
	return 0;
}



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

public class Main{
	public static void main(String[] args) {
		int a,b;
		int n,cnt = 0;
		ArrayList<Integer> keta = new ArrayList<Integer>();
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		for(int i = a; i <= b; ++i){
			n = i;
			for(int j = 0; j < 5; ++j){
				keta.add(n % 10);
				n /= 10;
			}
			if(keta.get(0) == keta.get(4) && keta.get(1) == keta.get(3)){
				++cnt;
			}
			keta.clear();
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22836
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000005
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define PI M_PI
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}






void solve()
{  
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  c=c*60 + d;
  a=a*60 + b;
  c=c-e;
  cout << max(c-a,0LL);
}

signed main()
{ boost
  int test=0,t;
    //cin >> t ;
    t=1;
   while(test++ <t){
	  //cout<<"Case #"<<test<<": ";
	   solve();}
  
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
    int n,i,k;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        k=i;
        if(k%3==0)printf(" %d",k);
        else{
            while(k){
                if(k%10==3){
                    printf(" %d",i);
                    break;
                }
                k=k/10;
            }
        }
    }
        printf("\n");
        return 0;
    }



Measured memory_bytes: 2120
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String s = sc.nextLine();
    sc.close();
    if (n % 2 == 1) {
      System.out.println("No");
      return;
    }
    for (int i = 0; i < n / 2; i++) {
      char c1 = s.charAt(i);
      char c2 = s.charAt(i + n / 2);
      if (c1 != c2) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 21844
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int rept = in.nextInt();
		for(int loop=0; loop<rept; loop++){
			String train = in.next();
			HashSet<String> set = new HashSet<String>();
			int n = train.length();
			for(int i=1; i<n; i++){
				String pre = train.substring(0,i);
				String post= train.substring(i);
				String rpre = new StringBuffer(pre).reverse().toString();
				String rpost = new StringBuffer(post).reverse().toString();
				set.add(pre.concat(post));
				set.add(pre.concat(rpost));
				set.add(rpre.concat(post));
				set.add(rpre.concat(rpost));
				set.add(post.concat(pre));
				set.add(post.concat(rpre));
				set.add(rpost.concat(pre));
				set.add(rpost.concat(rpre));
			}
			System.out.println(set.size());
		}
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

int a[3];

void solve() {
	for (int i = 0; i < 3; i++) cin >> a[i];
	sort(a, a + 3);
	int ans = a[2] - a[1];
	if ((a[2] - (a[0] + ans)) % 2 == 0) {
		ans += (a[2] - (a[0] + ans)) / 2;
	}
	else {
		ans += (a[2] - (a[0] + ans)) / 2 + 2;
	}
	cout << ans << endl;
}


int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for i in range(h)]
c=[[0]*w for i in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      if 0<j:c[i][j-1]=1
      if j<w-1:c[i][j+1]=1
      if 0<i:c[i-1][j]=1
      if i<h-1:c[i+1][j]=1

ok=True
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
        if c[i][j]!=1:ok=False
print("Yes") if ok else print("No")





Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long



signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k,s;
  while(1){
    cin>>n>>k>>s;
    if(n==0 && k==0 && s==0) break;
    int dp[25][25][160]={0};
    dp[0][0][0]=1;
    repi(i,1,n+1){
      rep(j,k+1){
	rep(l,s+1){
	  if(l-i >= 0 && j!=0) dp[i][j][l]+=dp[i-1][j-1][l-i];
	  dp[i][j][l]+=dp[i-1][j][l];
	}
      }
    }
    cout<<dp[n][k][s]<<endl;
  }
      
    

  return 0;
}



Measured memory_bytes: 3988
import numpy as np

def acinput():
    return list(map(int,input().split(" ")))


N,L=acinput()


aji=L+np.arange(1,N+1)-1
sm=np.sum(aji)

arg=np.argmin(np.abs(aji))
if aji[arg]>=0:
        print(sm-aji[arg])
else:
        print(sm-aji[arg])


Measured memory_bytes: 12404
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	map<string, int> mp;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		if (mp[S] == 0) ans++;
		mp[S]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string a;
  cin >> a;
  if(count(all(a),'a')==1&&count(all(a),'b')==1&&count(all(a),'c')==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <string>

constexpr int MAX_NL = 100;

int main(){
    int N, L;
    std::string str[MAX_NL];
    std::cin >> N >> L;
    for(int i = 0; i < N; ++i){
        std::cin >> str[i];
    }
    std::sort(str, str + N);
    for(int i = 0; i < N; ++i){
        std::cout << str[i];
    }
    std::cout << std::endl;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
int a,b,c;
lint mo=1000000007;
lint ap[214514],bp[214514],sp[214514],ka[252521],rk[252521];
lint co(int a,int b){
	if(a<0 || b<0 || a<b) return 0;
	return (ka[a]*rk[b])%mo*rk[a-b]%mo;
}
int main()
{
	int n,a,b,c;cin>>n>>a>>b>>c;
	ka[0]=1;
	rep(i,252500) ka[i+1]=(ka[i]*(i+1))%mo;
	rep(i,252500) rk[i]=invMod(ka[i],mo);
	ap[0]=bp[0]=sp[0]=1;
	rep(i,214510) ap[i+1]=(ap[i]*a)%mo,bp[i+1]=(bp[i]*b)%mo,sp[i+1]=(sp[i]*(a+b))%mo;
	lint out=0;
	rep(i,n){
		//a*n,b*i
		out+=(((ap[n]*bp[i])%mo*invMod(sp[n+i],mo))%mo*co(n+i-1,i))%mo*(n+i);out%=mo;
		//a*i,b*n
		out+=(((ap[i]*bp[n])%mo*invMod(sp[n+i],mo))%mo*co(n+i-1,i))%mo*(n+i);out%=mo;
	}
	out*=invMod(a+b,mo);out%=mo;out*=100;out%=mo;
	cout<<out<<endl;
}


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    cout << 2 * b - a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

void solve(){
    string s;
    cin >> s;
    cout << s.substr(0, 3) << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3640
import collections
N=int(input())
S=[]
for i in range(N):
  s=str(input())
  S +=[s]
T=collections.Counter(S)
answer=T.most_common()
A=[]
for i in range(len(T)):
  if answer[i][1]==answer[0][1]:
    A +=[answer[i][0]]
  else:
    break
A=sorted(A)
for a in A:
  print(a)

Measured memory_bytes: 49396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,j,k) for(ll i=j;i<k;i++)


int main(){

  ll N,K,ans = -1000000000000000000LL;
  cin >> N >> K;
  vector<ll> P(N+1),C(N+1);
  rep(i,1,N+1) cin >> P[i];
  rep(i,1,N+1) cin >> C[i];
  rep(i,1,N+1){
    vector<pair<ll,ll>> did(N+1,{0,0});
    ll ind = i;
    ll x=0,y=0;
    while(P[ind]!=i){
      ind = P[ind];
      x += C[ind];
      y++;
    }
    y++;
    x += C[i];

    if(K<=y || x<=0){
      ll sc = 0;
      ll k=K;
      ind = i;
      while(k){
        k--;
        ind = P[ind];
        sc += C[ind];
        ans = max(ans,sc);
        if(ind==i && x<0)break;
      }
    }else if(x>=0){
      ll rote = K / y;
      ll do_rote = max(0LL,rote-1);
      ll sc = x * do_rote;
      ll k = K - do_rote * y;
      ind = i;
      while(k){
        k--;
        ind = P[ind];
        sc += C[ind];
        ans = max(ans,sc);
      }
    }
  }
  cout << ans << endl;
}



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

int calc(int h1,int m1,int h2,int m2){
    return 60*(h2-h1)+(m2-m1);
}

int main(){
    int n;
    cin>>n;
    int t;
    cin>>t;
    int sh[n],sm[n],eh[n],em[n];
    string s[n+1];
    for(int i=0;i<n;i++){
        scanf(" %d:%d",&sh[i],&sm[i]);
        cin>>s[i];
        scanf(" %d:%d",&eh[i],&em[i]);
        cin>>s[i+1];
    }
    vector<pair<string,int>> ans;
    for(int i=0;i<n-1;++i){
        if(calc(eh[i],em[i],sh[i+1],sm[i+1])>=t){
            ans.push_back({s[i+1],calc(eh[i],em[i],sh[i+1],sm[i+1])});
        }
    }
    cout<<ans.size()<<endl;
    for(auto e : ans){
        cout<<e.first<<" "<<e.second<<endl;
    }

}


Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

int N,M,Res;
bitset<8> memo;
vector< vector<int> > el;

void dfs(int now) {
	if (memo.count() == N) {
		++Res;
		return;
	}
	for (int i = 0; el[now][i] >= 0; ++i) {
		if (!memo[el[now][i]]) {
			memo.set(el[now][i]);
			dfs(el[now][i]);
			memo.reset(el[now][i]);
		}
	}
	return;
}

int main(void) {
	cin >> N >> M;
	el = vector< vector<int> >(N,vector<int>(N,-1));
	vector<int> ind(N,0);
	for (int i = 0; i < M; ++i) {
		int u,v;
		cin >> u >> v;
		el[u-1][ind[u-1]] = v-1;
		++ind[u-1];
		el[v-1][ind[v-1]] = u-1;
		++ind[v-1];
	}
	Res = 0;
	memo = bitset<8>(1);
	dfs(0);
	cout << Res << endl;
	return 0;
}


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

int main(){
    int summ = 0;
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    int k;
    int y;
    int r[m];
    for(int i = 0; i < m; i++){
        cin >> k;
        for (int j = 0; j < k; j++){
            cin >> y;
            s[i].push_back(y);
        }
    }
    for (int i = 0; i < m; i++){
        cin >> r[i];
    }
    int mask = (1<<n);
    int w[n];
    int pup;
    for (int i = 0; i < mask;i++){
        for(int j = 0;j<n;j++){
            if(i&(1<<j)){
                w[j] = 1;
            }
            else{
                w[j] = 0;
            }
        }
        bool po = 1;
        for (int j = 0; j < m; j++){
            pup = 0;
            for (int a = 0 ; a < s[j].size(); a++){
                pup += w[s[j][a] - 1];
            }
            if (pup % 2 != r[j]){
                po = 0;
                break;
            }
        }
        if (po == 1){
            summ++;
        }
    }
    cout << summ;
}


Measured memory_bytes: 256