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

const int N = 2003;
int n, x, y, a[N], d[N];

void nadm(int gw) {
	for(int j = 1; j <= n; ++j) d[j] = 0;
	d[gw] = 1;
	queue<int> q;
	q.push(gw);
	while(q.size()) {
		int dg = q.front();
		++a[d[dg] - 1];
		q.pop();
		if(dg > 1 && d[dg - 1] == 0) {
			d[dg - 1] = d[dg] + 1;
			q.push(dg - 1);
		}
		if(dg < n && d[dg + 1] == 0) {
			d[dg + 1] = d[dg] + 1;
			q.push(dg + 1);
		}
		if(dg == x && d[y] == 0) {
			 d[y] = d[x] + 1;
			 q.push(y);
		}
		if(dg == y && d[x] == 0) {
			d[x] = d[y] + 1;
			q.push(x);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> x >> y;
	for(int i = 1; i <= n; ++i) {
		nadm(i);
	}
	for(int k = 1; k < n; ++k) {
		cout << a[k] / 2 << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
v = gets.chomp
value = v.split("\s")
w = value[0].to_i
a = value[1].to_i
b = value[2].to_i

if a + w <= b
    ans = b - (a + w)
elsif a > b && b + w < a
    ans = a - (b + w)
else
    ans = 0
end
print(ans, "\n")


Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	string S; cin >> S;
	int Q; cin >> Q;

	while (Q--) {
		int k; cin >> k;
		ll D = 0, M = 0, val = 0, ans = 0;
		rep(i,N) {
			if (S[i]=='D') D++;
			if (S[i]=='M') {
				val += D;
				M++;
			}
			if (S[i]=='C') ans += val;
			if (i+1 >= k) {
				if (S[i+1-k]=='D') {
					D--;
					val -= M;
				}
				if (S[i+1-k]=='M') M--;
			}
		}

		cout << ans << ln;
	}
}


Measured memory_bytes: 1948
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
r,s,p = readInts()
T = list(input())
ans = 0
for i in range(n):
    if k <= i:
        if T[i] == T[i-k]:
            T[i] = '0'
    if T[i] == 's':
        ans += r
    if T[i] == 'p':
        ans += s
    if T[i] == 'r':
        ans += p
print(ans)


Measured memory_bytes: 11360
import java.io.*;
public class Main{
    public static void main(String[] args){
     BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
         double S;
         double l;
     try{
         String line = reader.readLine();
         double r = Double.parseDouble(line);
         S = Math.PI * r * r;
         l = 2 * Math.PI * r;
         System.out.printf("%f %f",S,l);
     }catch(IOException e){
         System.out.println(e);
     }catch(NumberFormatException e){
         System.out.println("数値が正しくありません");
     }
    }
}


Measured memory_bytes: 24676
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e3+5;
char S[N][N];
int f[N][N],dr[4][2]={{1,0},{-1,0},{0,1},{0,-1}},que[N*N],s,t;
int main(){
	int h,w,sx,sy,tx,ty;scanf("%d%d%d%d%d%d",&h,&w,&sx,&sy,&tx,&ty);
	for(int i=0;i<h;i++){
		scanf("%s",S[i]);
		for(int j=0;j<w;j++)f[i][j]=S[i][j]=='#';
	}
	f[--sx][--sy]=1;tx--,ty--;
	que[t++]=sx*N+sy;
	while(s<t){
		int s1=s;
		while(s<t){
			int x=que[s++],y=x%N;x/=N;
			for(int i=0;i<4;i++){
				int x1=x+dr[i][0],y1=y+dr[i][1];
				if((unsigned)x1>=h||(unsigned)y1>=w||f[x1][y1])continue;
				f[x1][y1]=f[x][y];que[t++]=x1*N+y1;
			}
		}
		while(s1<s){
			int x=que[s1++],y=x%N;x/=N;
			for(int i=-2;i<3;i++){
				for(int j=-2;j<3;j++){
					int x1=x+i,y1=y+j;
					if((unsigned)x1>=h||(unsigned)y1>=w||f[x1][y1])continue;
					f[x1][y1]=f[x][y]+1;que[t++]=x1*N+y1;
				}
			}
		}
	}
	printf("%d",f[tx][ty]?f[tx][ty]-1:-1);
	return 0;
}


Measured memory_bytes: 10572
import sys

for i in sys.stdin.readlines()[:-1]:
    h,w = map(int,i.strip().split())
    for i in range(h):
        for j in range(w):
            if (i+j) % 2 == 0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()

Measured memory_bytes: 8992
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

int a[N][4],dp[N][4];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++){
            scanf("%d",&a[i][j]);
        }
    }
    dp[1][1]=a[1][1],dp[1][2]=a[1][2],dp[1][3]=a[1][3];
    for(int i=2;i<=n;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=3;k++){
                if(j==k) continue;
                dp[i][j]=max(dp[i-1][k]+a[i][j],dp[i][j]);
            }
        }
    }
    int ans=0;
    for(int i=1;i<=3;i++){
        ans=max(dp[n][i],ans);
    }
    printf("%d\n",ans);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}




Measured memory_bytes: 5888
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		long w = sc.nextInt();
		long h = sc.nextInt();
		long x = sc.nextInt();
		long y = sc.nextInt();

		double s = w *h;

		System.out.println(s/2);

		if(w<2 || h<2){
			System.out.println(0);
		}else if(w/2 == x && w%2 == 0 && h/2 == y && h%2 == 0){
			System.out.println(1);
		}else{
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(void)
{
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 636
#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>
 
using namespace std;
 
int main(){
 int N;
 cin >> N;
 int p[N];
 int i;
 int count = 0;
 for(i=0;i<N;++i){
   cin >> p[i];}
 for(i=0;i<N;++i){
 if(p[i]!=i+1)count++;}
 if(count>2){
 cout << "NO" << endl;}
 else{
   cout << "YES" << endl;}
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, m; cin>>n>>m;
    int a[n][m];
    int cnt[m];
    fill(cnt, cnt+m, 0);
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
            a[i][j]--;
            if(j == 0) cnt[a[i][j]]++;
        }
    }

    int ans=1000;
    int cntmax=0;
    int maxspo;
    for(int i=0; i<m; i++){
        if(cntmax < cnt[i]){
            cntmax = cnt[i];
            maxspo = i;
        }
    }

    bool used[m];
    fill(used, used+m, false);
    used[maxspo] = true;
    chmin(ans, cntmax);

    for(int k=0; k<m-2; k++){
        fill(cnt, cnt+m, 0);

        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(!used[a[i][j]]){
                    cnt[a[i][j]]++;
                    break;
                }
            }
        }

        cntmax=0;
        for(int i=0; i<m; i++){
            if(cntmax < cnt[i]){
                cntmax = cnt[i];
                maxspo = i;
            }
        }

        used[maxspo] = true;
        chmin(ans, cntmax);
    }

    cout << ans << endl;
}

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

int main(){
    int s,ans=0;
    cin>>s;
    vector<int> a(s);
    for(int i=0;i<s;i++){
        cin>>a[i];
    }
    for(int i=1;i<(s-1);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<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
   int r, c;                 // input; 1<=r,c<=100
   int data[101][101]={0};   // output; answer data matrix
   int i, j;                 // loop index;


   scanf("%d %d", &r, &c);
   for(i=0;i<r;i++){
      for(j=0;j<c;j++){
         scanf("%d", &data[i][j]);
         data[i][c] += data[i][j];
         data[r][j] += data[i][j];
         printf("%d ", data[i][j]);
      }
      printf("%d\n", data[i][c]);
      data[r][c] += data[i][c];
   }
   for(j=0;j<c;j++){
      printf("%d ", data[r][j]);
   }
   printf("%d\n", data[r][c]);

   return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define reps(i,b,n) for(int i=b;i<n;++i)
#define rep(i,n) reps(i,0,n)
#define INF (1 << 30)
#define MAX_N 100001
int n,mas[MAX_N],cost[MAX_N];

int no__over(int a){
  return max(0,min(n-1,a));
}

int bfs(){
  fill_n(cost,n,INF);
  queue<int> que;
  que.push(0);
  cost[0] = 0;
  while( !que.empty() ){
    for(int i = 1 ; i <= 6 ; i++ ){
      int java = no__over(que.front()+i) , c = cost[que.front()] + 1;
      while( mas[java] && cost[java] > c ){
        cost[java] = c;
        java = no__over( java+mas[java] );
      }
      if( !mas[java] && cost[java] > c ){
        cost[java] = c;
        que.push(java);
      }
    }
    que.pop();
  }
  return cost[n-1];
}

int main(){
  cin >> n;
  rep(i,n) cin >> mas[i];
  cout << bfs() << endl;
}

Measured memory_bytes: 2000
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int K = scn.nextInt();
		scn.nextLine();
		char[] ch = scn.nextLine().toCharArray();
		if(ch.length > K) {
			for(int i = 0;i < K;i++) {
				System.out.print(ch[i]);
			}
			System.out.print("...");
		}else {
			for(int i = 0;i < ch.length;i++) {
				System.out.print(ch[i]);
			}
		}
	}

}


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

int main(){
    int tmp;
    vector<int> args;

    for(int i = 0; i < 6; i++){
        cin >> tmp;
        args.push_back(tmp);
    }
    int k = args[5];
    bool find = false;

    for(int i = 0; i < 4; i++){
        for(int j = i+1; j < 5; j++){
            find = find || (args[j]-args[i] > k);
            if(find) break;
        }
        if(find) break;
    }

    if(find) cout << ":(" << '\n';
    else cout << "Yay!" << '\n';

    return 0;
}

Measured memory_bytes: 504
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
h,w = LI()
a,b = LI()
y = h//a
x = w//b
ans = h*w-a*y*b*x
print(ans)

#B
"""
def m(x,y):
    if x == y:
        return "T"
    if x == "F":
        return "T"
    return "F"
n = I()
p = input().split()
ans = p[0]
for i in range(1,n):
    ans = m(ans,p[i])
print(ans)
"""

#C
"""
s = [[1]*8 for i in range(4)]
for i in range(4):
    s.insert(2*i,[1,0,1,0,1,0,1,0])
for j in range(8):
    for i in range(1,8):
        s[j][i] += s[j][i-1]
for j in range(8):
    for i in range(1,8):
        s[i][j] += s[i-1][j]
s.insert(0,[0,0,0,0,0,0,0,0,0])
for i in range(1,9):
    s[i].insert(0,0)
q = I()
for _ in range(q):
    a,b,c,d = LI()
    print(s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1])
"""

#D
"""
n = I()
a = LI()
dp = [float("inf") for i in range(n)]
b = [[] for i in range(n)]
ind = [0 for i in range(100001)]
for i in range(n):
    k = bisect.bisect_left(dp,a[i])
    dp[k] = a[i]
    b[k].append(a[i])
    ind[a[i]] = max(i,ind[a[i]])
for i in range(n):
    if dp[i] == float("inf"):break
    b[i].sort()
    b[i] = b[i][::-1]
i -= 1
ans = b[i][0]
now_ind = ind[b[i][0]]
now_v = b[i][0]
while i >= 0:
    for j in b[i]:
        if ind[j] < now_ind and j < now_v:
            ans += j
            now_ind = ind[j]
            now_v = j
    i -= 1
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T



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

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

  if (S.at(0) == 'R' && S.at(1) == 'R' && S.at(2) == 'R')
  {
    cout << 3 << endl;
  }
  else if (S.at(0) == 'R' && S.at(1) == 'R' || S.at(1) == 'R' && S.at(2) == 'R')
  {
    cout << 2 << endl;
  }
  else if (S.at(0) == 'R' || S.at(1) == 'R' || S.at(2) == 'R')
  {
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll X, Y, A, B, C;
  scanf("%lld %lld %lld %lld %lld", &X, &Y, &A, &B, &C);

  vector<ll> a_list(A);
  for (ll i = 0; i < A; i++) {
    ll v;
    scanf("%lld", &v);
    a_list[i] = v;
  }

  vector<ll> b_list(B);
  for (ll i = 0; i < B; i++) {
    ll v;
    scanf("%lld", &v);
    b_list[i] = v;
  }

  vector<ll> c_list(C);
  for (ll i = 0; i < C; i++) {
    ll v;
    scanf("%lld", &v);
    c_list[i] = v;
  }

  sort(a_list.rbegin(), a_list.rend());
  sort(b_list.rbegin(), b_list.rend());
  sort(c_list.rbegin(), c_list.rend());

  vector<ll> all_list;

  for (ll i = 0; i < X; i++) {
    all_list.emplace_back(a_list[i]);
  }
  for (ll i = 0; i < Y; i++) {
    all_list.emplace_back(b_list[i]);
  }
  sort(all_list.begin(), all_list.end());

  ll all_index = 0;
  for (ll i = 0; i < C; i++) {
    if (all_index > all_list.size()) {
      break;
    }
    ll c_value = c_list[i];

    if (all_list[all_index] < c_value) {
      all_list[all_index] = c_value;
    } else {
      break;
    }
    all_index++;
  }

  ll ans = 0;

  for (auto e : all_list) {
    ans += e;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4724
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


int ara[MX];
pll calc(int at, bool cond)
{
	if(cond){
		for(int K=at; K>0; K--){
			if(ara[K]<ara[K-1]){
				pll res = calc(K-1, 0);
				//cout << "K = " << K << " ara[K] = " << ara[K] << "\n";
				ll money = res.fi;
				ll num = money / ara[K];
				money = num * ara[K];
				//cout << "at = " << at << ' ' << '{' << res.fi-money << ' ' << num << '}' << "\n";
				return MP(res.fi-money, num);
			}
		}
		
		//cout << "at = " << at << ' ' << '{' << 1000-ara[0]*((int)1000/ara[0]) << ' ' << (int)1000/ara[0] << "}\n";
		return MP(1000-ara[0]*((ll)1000/ara[0]), (ll)1000/ara[0]);
	}
	else{
		for(int K=at; K>0; K--){
			if(ara[K]>ara[K-1]){
				pll res = calc(K-1, 1);
				//cout << "K = " << K << " ara[K] = " << ara[K] << "\n";
				ll money = res.fi + ara[K]*res.se;
				//cout << "at = " << at << ' ' << '{' << money << ' ' << 0 << '}' << "\n";
				return MP(money, 0);
			}
		}
		
		//cout << "at = " << at << ' ' << '{' << 1000 << ' ' << 0 << '}' << "\n";
		return MP(1000, 0);
	}
}
void task()
{
    //code here...
    
    int n;
    
    cin >> n;
    for(int K=0; K<n; K++) cin >> ara[K];
    
    pll ans = calc(n-1, 0); // 0 for sell..
    
    cout << ans.fi << "\n";
}


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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}


Measured memory_bytes: 3620
INF=float('inf')
n,m=map(int,input().split())
a=[0]*m
c=[0]*m
for i in range(m):
    a[i],_=map(int,input().split())
    c[i]=sum(map(lambda x:2**(int(x)-1),input().split()))
dp=[INF]*(2**n)
dp[0]=0
for i in range(m):
    for j in range(2**n):
        dp[c[i]|j]=min(dp[c[i]|j],dp[j]+a[i])
print(-1 if dp[-1]==INF else dp[-1])

Measured memory_bytes: 46424
#include <stdio.h>


int main(void)
{
    char str[101];
    gets(str);

    int len = 0;
    while(str[len]) len++;

    int cnt = 0;
    for (int i=0; i < len; i++){
        if (i == len - i -1) ;
        else if (str[i] != str[len-i-1]) cnt++;
    }

    printf("%d\n", cnt/2);



    return 0;
} 



Measured memory_bytes: 128
#include<iostream>
#include<math.h>

using namespace std;

bool IsPrimeNumber(int num){
    if(num==2) return true;

    if(num < 2 || num % 2 == 0) return false;

    for(int i=3;i<=sqrt(num);i=i+2){
        if(num % i == 0) return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    int number;
    int count = 0;
    for(int i=0;i<n;i++){
        cin >> number;
        if(IsPrimeNumber(number)) count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
using namespace std;
 
struct ice{
	int money;
	double v;
	double ms;
}a[4];
 
bool cmp(ice a, ice b)
{
	return a.ms<b.ms;
}
 
int main()
{
	int q, h, s, d;
	double n;
	cin >> q >> h >> s >> d >> n;
	a[0].v = 0.25, a[0].money = q, a[0].ms = q*1.0/0.25;
	a[1].v = 0.5, a[1].money = h, a[1].ms = h*1.0/0.5;
	a[2].v = 1, a[2].money = s, a[2].ms = s*1.0/1.0;
	a[3].v = 2, a[3].money = d, a[3].ms = d*1.0/2.0;
	sort(a, a+4, cmp);
	long long sum = 0;
		for(int i=0; i<4; i++)
		{
			if(a[i].v>n||n-a[i].v<0)
				continue;
			int mid = n/a[i].v;
			while(mid--)
			{
				sum += a[i].money;
				n -= a[i].v;
			}
		}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] x = new int[n];

    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
    }

    int ans = Integer.MAX_VALUE;

    for (int i = 0; i <= n-k; i++) {
      int start = x[i];
      int end = x[i+k-1];
      if ((start > 0 && end < 0) || (start < 0 && end > 0)) {
        start = Math.abs(start);
        end = Math.abs(end);
        ans = Math.min(ans, Math.min(start, end) * 2 + Math.max(start, end));
      } else {
        start = Math.abs(start);
        end = Math.abs(end);
        ans = Math.min(ans, Math.max(start, end));
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 50120
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int A, B;
  cin >> A >> B;
  if (B % A == 0) {
    cout << A + B << endl;
  } else {
    cout << B - A << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define pb push_back
#define fo(i,n) for(int i=0; i<n; i++)
#define foa(i, a, n) for(int i=a; i<=n; i++)
#define show(v) for(auto abc:v){cout<<abc<<" ";}
#define mod 1000000007
#define mod2 998244353
#define all(v) v.begin(), v.end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
using namespace std;
int expm(int x, int y, int p){if(y==0) return 1;if(x==0) return 0;if(y&1) return ((expm(x,y/2,p)*expm(x,y/2,p)%p)*x)%p;else return expm(x,y/2,p)*expm(x,y/2,p)%p;} 
int exp(int x, int y){if(y==0) return 1;if(x==0) return 0;if(y&1) return ((exp(x,y/2)*exp(x,y/2))*x);else return exp(x,y/2)*exp(x,y/2);} 
int gcd(int a,int b){if(!b)return a;return gcd(b, a % b);}

int dp[100005];

int f(int a[], int i, int n){
  if(i==n-1)return 0;
  if(i>=n)return INT_MAX;
  if(dp[i]!=-1)return dp[i];

  return dp[i]=min(abs(a[i]-a[i+2])+f(a, i+2, n), abs(a[i]-a[i+1])+f(a, i+1, n));
}

int32_t main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t=1;
  // cin>>t;
  while(t--){
    memset(dp, -1, sizeof dp);
    int n;cin>>n;
    int a[n+1];
    fo(i, n)cin>>a[i];
    cout<<f(a, 0, n)<<endl;
	}
}

Measured memory_bytes: 13052
import heapq
N, M = map(int, input().split())
Adj = [[] for n in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  Adj[a - 1].append([b - 1, c, i])
  Adj[b - 1].append([a - 1, c, i])
E = [1 for m in range(M + 1)]
def Dijkstra(s):
  L = [[10 ** 7, n, 0] for n in range(N)]
  L[s] = [0, 0, 0]
  Q = []
  heapq.heappush(Q, [0, s, M])
  while Q:
    q = heapq.heappop(Q)
    if L[q[1]][2] == 0:
      L[q[1]][2] = 1
      E[q[2]] = 0
      for adj in Adj[q[1]]:
        if q[0] + adj[1] < L[adj[0]][0]:
          L[adj[0]][0] = q[0] + adj[1]
          heapq.heappush(Q, [q[0] + adj[1], adj[0], adj[2]])
for n in range(N):
  Dijkstra(n)
print(sum(E))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

void fin(){
	freopen("test.txt", "r", stdin);
}

bool formula(const string &s){
	rep(i,2){
		if(s[0] == "FT"[i]) return i;
	}

	if(s[0] == '-'){
		return !formula(s.substr(1));
	}

	int lidx = 1, llen, ridx, rlen;
	char ope;
	int nest = 0;
	rep(i, s.size()){
		if(s[i] == '(') nest++;
		if(s[i] == ')') nest--;
		if(nest != 1) continue;
		rep(j, 3) if(s[i] == "*+>"[j]){
			ope = s[i];
			llen= i-1-(s[i] == '>');
			ridx = i+1;
			rlen = s.size()-ridx-1;
			goto next;
		}
	}
next:
	bool lhs = formula(s.substr(lidx, llen));
	bool rhs = formula(s.substr(ridx, rlen));
	
	if(ope == '+') return lhs|rhs;
	if(ope == '*') return lhs&rhs;
	if(lhs&(!rhs)) return false;
	return true;
}

bool equation(string &s){
	rep(i, s.size()){
		if(s[i] != '=') continue;
		return formula(s.substr(0, i)) == formula(s.substr(i+1, s.size()));
	}
	return false;
}

string replace(const string &s, const char from, const char to){
	string res = s;
	rep(i, res.size()){
		if(res[i] == from) res[i] = to;
	}
	return res;
}

bool include(const string &s, const char c){
	rep(i, s.size()){
		if(s[i] == c) return true;
	}
	return false;
}

string val = "abcdefghijk";
bool dfs(string &s, int i = 0){
	if(i == val.size()) return equation(s);
	if(!include(s, val[i])) return dfs(s, i+1);
	rep(j, 2){
		string rs = replace(s, val[i], "TF"[j]); 
		if(!dfs(rs, i+1)) return false;
	}
	return true;
}

int main(){
//	fin();
	string s;
	while(cin >> s){
		if(s[0] == '#') break;
		cout << (dfs(s)?"YES":"NO") << endl;
	}

	return 0;
}

Measured memory_bytes: 1820
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll dp[100100][3];

int main(){
  ll n,k;
  cin>>n>>k;
  ll rr,ss,pp;
  cin>>rr>>ss>>pp;
  string s;
  cin>>s;
  vector<vector<ll> > vv(k,vector<ll>());
  rep(i,0,s.sz){
    if(s[i]=='r'){
      vv[i%k].pb(0);
    }
    if(s[i]=='s'){
      vv[i%k].pb(1);
    }
    if(s[i]=='p'){
      vv[i%k].pb(2);
    }
  }
  ll ans = 0;
  rep(i,0,k){
    ll n = vv[i].sz;
    rep(j,0,n+10)rep(l,0,3)dp[j][l] = 0;
    if(vv[i][0]==0){
      dp[0][2] = pp;
    }
    if(vv[i][0]==1){
      dp[0][0] = rr;
    }
    if(vv[i][0]==2){
      dp[0][1] = ss;
    }
    rep(j,1,vv[i].sz){
      ll a = vv[i][j];
      if(a==0){
        dp[j][0] = max(dp[j][0],max(dp[j-1][1],dp[j-1][2])); 
        dp[j][1] = max(dp[j][1],max(dp[j-1][0],dp[j-1][2])); 
        dp[j][2] = max(dp[j][2],max(dp[j-1][0],dp[j-1][1])+pp); 
      }
      if(a==1){
        dp[j][0] = max(dp[j][0],max(dp[j-1][1],dp[j-1][2])+rr); 
        dp[j][1] = max(dp[j][1],max(dp[j-1][0],dp[j-1][2])); 
        dp[j][2] = max(dp[j][2],max(dp[j-1][0],dp[j-1][1]));         
      }
      if(a==2){
        dp[j][0] = max(dp[j][0],max(dp[j-1][1],dp[j-1][2])); 
        dp[j][1] = max(dp[j][1],max(dp[j-1][0],dp[j-1][2])+ss); 
        dp[j][2] = max(dp[j][2],max(dp[j-1][0],dp[j-1][1]));         
      }
    }
    ans += max(dp[vv[i].sz-1][0],max(dp[vv[i].sz-1][1],dp[vv[i].sz-1][2]));
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int west[n], east[n];
  west[0] = 0, east[0] = 0;
  rep(i,n){
  	if(s.at(i) == 'W'){
  		west[i+1] = west[i] + 1;
  		east[i+1] = east[i];
  	}else{
  		west[i+1] = west[i];
  		east[i+1] = east[i] + 1;
  	}
  }
  
  int ans = INF;
  rep(i,n){
  	ans = min(ans, west[i] + east[n] - east[i+1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
int main(void){
	int i,j,a=0,b=0,c=0,yama;
	
	for(i=0;i<=9;i++){
		scanf("%d",&yama);
		
		if(a<yama){
			
			c=b;
			b=a;
			a=yama;
			
		}else if(b<yama){
			
			c=b;
			b=yama;
			
		}else if(c<yama){
			
			c=yama;
			
		}
	}
	
	printf("%d\n%d\n%d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 2728
using System;
using System.Linq;

namespace arc094_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int sum = 0;
            for (int i = 0; i < 3; i++)
            {
                sum += x.Max() - x[i];
            }
            Console.WriteLine(sum % 2 == 0 ? sum / 2 : (sum + 3) / 2);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int n, m; cin >> n >> m;
    vector<vi> ab(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }

    vi next(n, -1);
    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int v = q.front();
        q.pop();

        for (int nv : ab[v]) {
            if (next[nv] != -1) continue;

            next[nv] = v;
            q.push(nv);
        }
    }

    rep (i, n) {
        if (next[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    rep (i, n) {
        if (i == 0) continue;
        cout << next[i] + 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 10040
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define _ "\n"
#define sz(x) (int)x.size();
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;


void solve(){
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));

}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <atcoder/string>
#include <string>
#include <vector>

using namespace std;
using namespace atcoder;

int main() {
    static char buf[500'001];
    scanf("%s", buf);
    string s = buf;
    vector<int> sa = suffix_array(s);
    long long answer = 1LL * s.size() * (s.size() + 1) / 2;
    for (auto x: lcp_array(s, sa)){
      answer -= x;
      //printf("%lld\n", x);
    }
    printf("%lld\n", answer);
    return 0;
}


Measured memory_bytes: 15744
#include <stdio.h>
typedef long long ll;

ll n;
ll a[100005];

int main()
{
    scanf("%lld", &n);
    for (ll i = 0; i < n; i++) {
        scanf("%lld", a + i);
    }

    ll i = 0;
    while (i < n && a[i] % 2 == 0) {
        i++;
    }

    if (i == n) {
        puts("second");
    }
    else {
        puts("first");
    }

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 999;
    for (int i = 0; i + 2 < s.size(); i++)
    {
        int x = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0';
        if (abs(x - 753) < ans)
            ans = abs(x - 753);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=1e9;

main(){
  int N,A,B;
  cin >> N >> A >> B;
  int P[N];
  for(int ii=0;ii<N;ii++){
    cin >> P[ii];
  }
  sort(P,P+N);
  int ans=INF;
  int cnt=0,cnt2=0,cnt3=0;
  for(int ii=0;ii<N;ii++){
    if(P[ii]<=A)cnt++;
    if(A+1<=P[ii] && P[ii]<=B)cnt2++;
    if(B+1<=P[ii])cnt3++;
  }
  ans=min(ans,cnt);
  ans=min(ans,cnt2);
  ans=min(ans,cnt3);
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t { as swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    auto count = 0;
    for (auto c : s) {
        if (c == 'o') count++;
    }
    auto mutch = 700 + 100 * count;
    cout << mutch << endl;

}



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

const int INF = 1e9 + 10;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
  int H, W; cin >> H >> W;
  vector<vector<bool>> maze(H + 2, vector<bool>(W + 2, false));
  rep(i, H) rep(j, W) {
    char S; cin >> S;
    if (S == '.') maze[i + 1][j + 1] = true;
  }

  auto bfs = [&](int sh, int sw) {
    vector<vector<int>> d(H + 2, vector<int>(W + 2, INF));
    d[sh][sw] = 0;
    queue<pair<int, int>> q;
    q.emplace(sh, sw);
    int res;
    while (!q.empty()) {
      int h, w;
      tie(h, w) = q.front(); q.pop();
      rep(k, 4) {
        int nh = h + dx[k], nw = w + dy[k];
        if (maze[nh][nw] && d[nh][nw] == INF) {
          q.emplace(nh, nw);
          res = d[nh][nw] = d[h][w] + 1;
        }
      }
    }
    return res;
  };

  int ans = 0;
  rep(i, H + 1) rep(j, W + 1) {
    if (maze[i][j]) ans = max(ans, bfs(i, j));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
void solve() {
	cout << setprecision(50) << fixed;
	int n;
	cin >> n;
	vector<int> v(n + 1);
	long double lg = 1;
	int ans = 1;
	bool check = true;
	double limit = 18.0;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		if (v[i] == 0) {
			check = false;
		}
	}
	if (!check) {
		cout << 0 << endl;
		return;
	}
	for (int i = 1; i <= n; i++) {
		lg *= (1.0) * v[i];
		ans *= v[i];
		if (lg > 1e18) {
			cout << -1 << endl;
			return;
		}
	}
	cout << ans << endl;
}
int32_t main() {
	solve();
}

Measured memory_bytes: 4052
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  ll n,c,k,x;
  cin>>n>>c>>k;
  vector<ll> t;
  for(int i=0;i<n;i++){
    cin>>x;
    t.pb(x);
  }
  ll res,st,num;
  sort(t.begin(),t.end());
  st=t[0];num=1;res=1;
  for(int i=1;i<n;i++){
    if(st+k<t[i] || num==c){
      st=t[i];
      num=1;
      res++;
    }
    else num++;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	if (!S.compare("RRR")){
		cout<<3<<endl;
		return 0;
	}
	if (!S.compare("RRS") || !S.compare("SRR")){
		cout<<2<<endl;
		return 0;
	}
	if (!S.compare("RSS") || !S.compare("SRS") ||  !S.compare("SSR") ||  !S.compare("RSR")){
		cout<<1<<endl;
		return 0;
	}
	if (!S.compare("SSS")){
		cout<<0<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <utility>
#include <vector>

#define rep(i, n) for (auto i = 0; i < (n); i++)
#define MOD 1e9 + 7
typedef long long ll;

using namespace std;

int main() {
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, K;
  cin >> N >> K;
  int d[K];
  for (int i = 0; i < K; i++) cin >> d[i];

  int n;
  for (n = N; n < MAX; n++) {
    bool flag = true;
    int n2 = n;
    while (n2) {
      int tmp = n2 % 10;
      for (int i = 0; i < K; i++) if (d[i] == tmp) {
        flag = false;
      }
      n2 /= 10;
    }
    if (flag) break;
  }

  // 解答
  cout << n << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = str(input())
T = str(input())

if M > N:
	M, N = N, M
	S, T = T, S

import math
G = N*M//math.gcd(N, M)

A = []
B = []

C = N//math.gcd(N,M)
D = M//math.gcd(N,M)

for i in range (0, math.gcd(N,M)):
	if S[i*C] != T[i*D]:
		print(-1)
		exit()

print(G)

Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  int count=0;
  vector <int> keiro (N,0);
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      if(i+1<=X && j+1<=Y)
        keiro.at(min(j-i, X-i+Y-j-1))++;
      if(i+1<=X && j+1>Y)
        keiro.at(min(j-i, X-i+j+1-Y))++;
      if(i+1>X && j+1<=Y)
        keiro.at(min(j-i, i+1-X+1+Y-j-1))++;
      if(i+1>X && j+1>Y)
        keiro.at(min(j-i, i+1-X+1+j+1-Y))++;
    }
  }
  for (int l=1;l<N;l++){
    cout << keiro.at(l) << endl;
  }
}

Measured memory_bytes: 256
/*
 * ID: ITP1_9_D
 * Problem: a card game
 */

#include <stdio.h>
#include <string.h>

int main(void)
{
    char taro[100 + 1];
    char hanako[100 + 1];
    int n;
    scanf("%d", &n);

    int p_taro = 0, p_hanako = 0;
    for (int i = 0; i < n; i ++) {
        scanf("%s %s", taro, hanako);
        int cmp;
        if ((cmp = strcmp(taro, hanako)) > 0) {
            p_taro += 3;
        } else if (cmp < 0) {
            p_hanako += 3;
        } else {
            p_taro += 1;
            p_hanako += 1;
        }
    }
    printf("%d %d\n", p_taro, p_hanako);

    return 0;
}



Measured memory_bytes: 2048
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

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

const int N = 2e5+5;

ll x,k,d;

void solve(){
	cin>>x>>k>>d;
	x=abs(x),d=abs(d);
	if(x/d>=k){
		cout<<x-k*d;
	}
	else{
		ll l=0,r=k,ans=k;
		while(l<=r){
			ll m=(l+r)/2;
			if(x/d<=m){
				ans=m;
				r=m-1;
			}
			else l=m+1;
		}
		ll res=1e18;
		if((k-ans+1)%2==0){
			res=min(res,abs(x-d*(ans-1)));
		}
		else{
			res=min(res,abs(x-d*(ans-1)+d));
		}
		if((k-ans)%2==0){
			res=min(res,abs(ans*d-x));
		}
		else res=min(res,abs(ans*d-x+d));
		cout<<res<<'\n';
	}

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while (T--)solve();
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void){
	int t,a[30],q;
	for(t=0;t<30;t++){
		a[t]=1;
	}
	for(t=0;t<28;t++){
		scanf("%d",&q);
		a[q-1]=0;
	}
	for(t=0;t<30;t++){
		if(a[t]){
			printf("%d\n",t+1);
		}
	}
return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int k = sc.nextInt();
        
        int amari = k % 2;
        int value = (k - amari) / 2;
        
		// 出力
		System.out.println(value * (value + amari));
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n;
    cin >> n;
    vi v(n);
    unordered_map<int, int> freq; 
    long long res = 0;
    for(auto& x : v)
    {
        cin >> x;
        freq[x]++;
    }
    
    for(const auto& x : freq) {
        long long qnt = static_cast<long long>(x.second);
        if(qnt >= 2) {
            long long inc = (qnt * (qnt - 1) ) / 2ll;
            res += inc;
        }
    }

    for(const auto& x : v) {
        long long contrib = freq[x] - 1;
        cout << res - contrib << '\n';
    }

    return 0;
}



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

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

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int X[1010], Y[1010];

	cin >> N;
	int modv = -1;
	rep(i, 0, N)
	{
		cin >> X[i] >> Y[i];
		if (modv == -1)
		{
			modv = (abs(X[i]) + abs(Y[i])) % 2;
		}
		else if (modv != -2)
		{
			if ((abs(X[i]) + abs(Y[i])) % 2 != modv)
			{
				modv = -2;
			}
		}
	}

	if (modv == -2)
	{
		cout << -1 << endl;
		return 0;
	}

	vector<int> d;
	rrep(i, 0, 31)d.push_back(1LL << i);
	if (modv == 0)d.push_back(1LL);

	cout << SZ(d) << endl;
	rep(i, 0, SZ(d))
	{
		cout << d[i];
		if (i < SZ(d) - 1)
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}

	rep(i, 0, N)
	{
		int tx = 0, ty = 0;
		rep(j, 0, SZ(d))
		{
			if (abs(tx - X[i]) >= abs(ty - Y[i]))
			{
				if (tx < X[i])
				{
					tx += d[j];
					cout << "R";
				}
				else
				{
					tx -= d[j];
					cout << "L";
				}
			}
			else
			{
				if (ty < Y[i])
				{
					ty += d[j];
					cout << "U";
				}
				else
				{
					ty -= d[j];
					cout << "D";
				}
			}
		}
		cout <<endl;
	}

	return 0;
}

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

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

    int n;
    bool flag = false;
    cin >> n;
    while(n) {
        int d = n % 10;
        if (d == 7) {
            flag = true;
            break;
        }
        n /= 10;
    }
    if (flag)
        cout << "Yes";
    else
        cout << "No";
}   

Measured memory_bytes: 3648
#include<stdio.h>
int main(){
  int a,b,c,i,j;
  while(scanf("%d %d %d",&a,&b,&c),a){
    int d[10010]={};
    d[--c]=1;
    while(--a>1){//printf("%d\n",a);
      //for(i=0;i<8;i++)printf("%d ",d[i]);printf("\n");
      c=(c+b-1)%a;
      for(i=j=0;j<=c;j+=1-d[i++]);//printf("%d ",j+1-d[i]);printf(":%d %d\n",c,i);
      d[i-1]=1;
    }
    //for(i=0;i<8;i++)printf("%d ",d[i]);
    for(i=0;d[i];i++);
    printf("%d\n",i+1);
  }
  return 0;
}

Measured memory_bytes: 644
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
 
using namespace std;
typedef long long ll;

int gCount = 0;
string list[120000];

void addChar(string str, int level, int n){
	if(str.length() == n){
		list[gCount] = str;
		gCount++;
	}else{
		for(int i = 0; i < level + 2; i++){
			addChar(str + (char)(97+i), i > level ? i : level, n);
		}	
	}
}

int main()
{
	int N;
	scanf("%d", &N);
	
	string s = "a";
	
	addChar(s, 0, N);
	
	sort(list, list+gCount);
	
	for(int i = 0; i < gCount; i++){
		printf("%s\n", list[i].c_str());
	}
	return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  map<string,int> mp;
  int cnt=0;
  for(int i=0;i<n;i++){
    cin>>s[i];
    mp[s[i]]++;
    cnt=max(cnt,mp[s[i]]);
  }
  for(auto i=mp.begin();i!=mp.end();i++){
    if(i->second==cnt){
      cout<<i->first<<endl;
    }
  }
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> vx(n);
	for (auto& x : vx) {
		cin >> x;
	}

	vector<int> copyvx = vx;

	sort(vx.begin(), vx.end());
	int center1 = vx[n / 2 - 1];
	int center2 = vx[n / 2];

	for (auto& x : copyvx) {
		if (x <= center1) {
			cout << center2 << endl;
		}
		else {
			cout << center1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>

int main(){
	int n, m;
	int a[105];
	int i, sum = 0;
	int reg, cnt = 0;

	scanf("%d %d", &n, &m);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
		sum += a[i];
	}

	reg = sum / (4*m);
	if(sum % (4*m) != 0){
		reg++;
	}
	for(i=0; i<n; i++){
		if(a[i] >= reg){
			cnt++;
		}
	}

	if(cnt < m){
		printf("No");
	}else{
		printf("Yes");
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
 template<class T> inline bool chmax(T&a,T&b){if(a<b){a=b;return true;}return false;}
 template<class T> inline bool chmin(T&a,T&b){if(a>b){a=b;return true;}return false;}
 const ll INF = 1LL<<60;
 const ll M = 1000000007;
 ll mpow(ll a,ll b) {ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
 ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
 */

int main(){
    int a[4]={};
    string s[4]={
        "AC", "WA", "TLE", "RE"
    };
    string str;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        for(ll j=0;j<4;j++){
            if(str==s[j])a[j]++;
        }
    }
    for(ll i=0;i<4;i++){
        cout<<s[i]<<" x "<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632