akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!

class Node:
    def __init__(self, id):
        self.parent = -1
        self.id = id
        self.left = -1
        self.right = -1


def preorder(nodes, cur_id, result):
    node = nodes[cur_id]
    result.append(node.id)
    if node.left >= 0:
        preorder(nodes, node.left, result)
    if node.right >= 0:
        preorder(nodes, node.right, result)
    
    return


def inorder(nodes, cur_id, result):
    node = nodes[cur_id]
    if node.left >= 0:
        inorder(nodes, node.left, result)
    result.append(node.id)
    if node.right >= 0:
        inorder(nodes, node.right, result)
    
    
def postorder(nodes, cur_id, result):
    node = nodes[cur_id]
    if node.left >= 0:
        postorder(nodes, node.left, result)
    if node.right >= 0:
        postorder(nodes, node.right, result)
    result.append(node.id)


N = int(input())
nodes = [Node(i) for i in range(N)]
for i in range(N):
    id, left, right = [int(i) for i in input().split()]
    nodes[id].left, nodes[id].right = left, right
    if left >= 0:
        nodes[left].parent = id
    if right >= 0:
        nodes[right].parent = right

root = 0
for i in range(N):
    if nodes[i].parent == -1:
        root = i
        break

print('Preorder')
result = []
preorder(nodes, root, result)
print('', *result)

print('Inorder')
result = []
inorder(nodes, root, result)
print('', *result)

print('Postorder')
result = []    
postorder(nodes, root, result)
print('', *result)



Measured memory_bytes: 5624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n;
VVI egs;
void first(){
  cout<<"First"<<endl;
  exit(0);
}
void second(){
  cout<<"Second"<<endl;
  exit(0);
}
in dfs(in u, in pr){
  in avc=0;
  forv(i,egs[u]){
    if(egs[u][i]==pr)
      continue;
    avc+=dfs(egs[u][i],u);
  }
  if(avc>=2)
    first();
  if(avc==0)
    return 1;
  return 0;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n;
  egs.resize(n);
  in ta,tb;
  forn(z,n-1){
    cin>>ta>>tb;
    --ta;
    --tb;
    egs[ta].PB(tb);
    egs[tb].PB(ta);
  }
  if(dfs(0,0)){
    first();
  }
  second();
  return 0;
}


Measured memory_bytes: 6400
#include <cstdio>

using namespace std;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int diff = b - a;
    int origin_b = 0;
    for (int i = 1; i <= diff; i++) {
        origin_b += i; 
    } 
    printf("%d\n", origin_b - b);
    return 0;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int h, w;
    cin >> h >> w;
    char ary[h][w] = {};
    rep(i, h) {
        rep(j, w) { cin >> ary[i][j]; }
    }

    // 処理
    // 出力
    for (int i = 0; i < h * 2; i++) {
        for (int j = 0; j < w; j++) {
            cout << ary[i / 2][j];
        }
        cout << endl;
    }

    return 0;
}


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

int main() {
  vector<int> dp(100005, 0);
  dp[100] = 1;
  dp[101] = 1;
  dp[102] = 1;
  dp[103] = 1;
  dp[104] = 1;
  dp[105] = 1;
  for (int i = 0; i < 100005; i++) {
    if (dp[i]) {
      for (int j = 0; j <= 5; j++) {
        dp[i + 100 + j] = 1;
      }
    }
  }
  int x;
  cin >> x;
  if (dp[x]) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N = 0;
  int M = 0;
  std::cin >> N >> M;
  std::string str;  //今回は15文字入力と予めわかっている
  std::vector<int> j_row(M, 0);
  std::vector<std::vector<int>> v(N, j_row);
  int K[40];

  std::vector<int> a_row(40, 0);
  std::vector<std::vector<int>> A(40, j_row);

  for (int i = 0; i < N; i++) {
    cin >> K[i];
    for (int j = 0; j < K[i]; ++j) {
      cin >> A[i][j];
    }
  }
/*
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < A[i].size(); j++) {
      std::cout << A[i][j] << " ";
    }
    std::cout << std::endl;
  }
  */

  int counter_2 = 0;
  for (int m = 0; m < M; m++) {
    int counter = 0;
    for (int i = 0; i < N; i++) {
      auto itr = std::find(A[i].begin(), A[i].end(), m+1);
      //  最初の要素5へのイテレータを返す
      if (itr != A[i].end()) {
        counter += 1;
      }
    }

    if (counter == N) {
      // std::cout << m << std::endl;
      counter_2 += 1;
    }
  }

  std::cout << counter_2 << std::endl;
  return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[110];
bool dp[100010];

int main(void){
	          int i,j;

	          cin.tie(0);  ios_base::sync_with_stdio(false);

	          int N,K;
	          cin >> N >> K;

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

	          dp[0]=false;
	          for(i=1;i<=K;i++){
	        	  dp[i]=false;
	        	  REP(j,N){
	        		  dp[i] |=a[j]<=i && !dp[i-a[j]];
	        	  }
	          }

	          if(dp[K]) cout << "First" << endl;
	          else cout << "Second" << endl;


	          return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;
xy_t P[110];

double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

int main() {
    int N;
    scanf("%d", &N);
    double x, y;
    int index = 0;
    while(~scanf("%lf %lf", &x, &y)) {
        P[index++] = xy_t(x,y);
    }

    double sum = 0.0;
    for(int i = N-1; i-1>0; i--) {
        xy_t a=P[0], b=P[i], c=P[i-1];
        sum += cross_product(b-a,c-a)/(double)2;
    }
    printf("%.1f\n", abs(sum));
    
    return 0;
}


Measured memory_bytes: 2688
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
import collections

visi_point = collections.defaultdict(list)

posi = 1
for i in range(K):
    next_posi = A[posi]
    if len(visi_point[next_posi]) >= 2:
        break
    visi_point[next_posi].append(i+1)
    posi = next_posi
# print(visi_point)

for k, v in visi_point.items():
    if K in v:
        print(k)
        break
    if len(v) >= 2:
        if (K - v[0]) % (v[1] - v[0]) == 0:
            print(k)
            break

Measured memory_bytes: 113532
#include <cstdio>
#include <algorithm>

int main()
{
  int n, k;
  scanf("%d%d", &n, &k);
  int x[50], y[50];
  for (int i = 0; i < n; ++i)
  {
    scanf("%d%d", x + i, y + i);
  }
  long long ans = 9e18;
  for (int a = 1; a < n; ++a)
  {
    for (int b = 0; b < a; ++b)
    {
      for (int c = 1; c < n; ++c)
      {
        for (int d = 0; d < c; ++d)
        {
          if (c == d) continue;
          int top = std::max(y[a], y[b]);
          int bottom = y[a] + y[b] - top;
          int left = std::min(x[c], x[d]);
          int right = x[c] + x[d] - left;
          int cnt = 0;
          for (int i = 0; i < n; ++i)
          {
            if (left <= x[i] && x[i] <= right && bottom <= y[i] && y[i] <= top)
            {
              ++cnt;
            }
          }
          if (cnt >= k)
          {
            if (ans > (long long)(right - left) * (long long)(top - bottom))
            {
              ans = (long long)(right - left) * (long long)(top - bottom);
            }
          }
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

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

    int64_t ans = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                int t = gcd(a, b);
                t = gcd(t, c);
                ans += t;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a; 
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

///////////////////////////////////

int main(){
  lint x,k,d; cin>>x>>k>>d;
  x = abs(x);
  
  if(1000000000000000/d < k){
    if(k%2==0){
      k = 10 + 1000000000000000/d;
      if(k%2==1) k++;
    }else{
      k = 10 + 1000000000000000/d;
      if(k%2==0) k++;
    }
  }
    
  if(x - d*k > 0){
    x -= d*k;
    k=0;
    // cout << x << endl;
  }
  else{
    lint tmp = x/d;
    x -= d*tmp;
    k -= tmp;
  }
  /*
  while(k>0 && x>=d){
    x -= d;
    k--;
  }
  */
  if(k%2==0) cout << x << endl;
  else cout << d-x << endl;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[6005];
int num[6005];
int pa[3005],tot;
int pb[3005];
struct str{
	char v[6005];
	int l;
	void pb(char x){
		v[l++]=x;
		v[l]=0;
	}
	str operator +(str b){
		str c=*this;
		for(int i=0;i<=b.l;i++)c.v[l+i]=b.v[i];
		c.l=l+b.l;
		return c;
	}
	bool operator >(str b){
		for(int i=0;i<=min(l,b.l);i++)if(v[i]!=b.v[i])return v[i]>b.v[i];
		return false;
	}
};
str f[3005];
str v[3005];
int t[3005],lst[3005];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=2*n;i++)if(s[i]=='a')pa[++tot]=i,num[i]=tot;
	tot=0;
	bool ok=0;
	for(int i=1;i<=2*n;i++)if(s[i]=='b'){
		pb[++tot]=i;
		num[i]=tot;
		if(pa[tot]>i)ok=1;
	}
	pa[n+1]=2*n+2;pb[n+1]=2*n+1;
	for(int i=1;i<=n;i++)if(pa[i]>pb[i]){
		int cnt=1,j=pb[i];
		v[i].pb(s[j]);
		while(cnt!=0){
			j++;
			while(s[j]=='a'&&num[j]<i)j++;
			if(s[j]=='a')cnt--;
			else cnt++;
			v[i].pb(s[j]);
		}
		t[i]=j;
		/*
		printf("%d\n",v[i].l);
		puts(v[i].v);
		*/
	}
	for(int i=n;i>=1;i--){
		f[i]=f[i+1];
		lst[i]=lst[i+1];
		if(pa[i]>pb[i])
			for(int j=i+1;j<=n+1;j++)if(pa[j]>pb[j])
				if(pb[j]>t[i]){
					// printf("%d\n",j);
					if(v[i]+f[j]>f[i])f[i]=v[i]+f[j],lst[i]=(j==n+1?t[i]:lst[j]);
					break;
				}
		// printf("%d %d\n",lst[i],f[i].l);
		// puts(f[i].v);
	}
	printf("%s",f[1].v);
	for(int i=1,p=lst[1];i<=n;i++)if(pa[i]>p){p=pb[i]; printf("ab");}
	puts("");
	return 0;
}

Measured memory_bytes: 35328
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    s = S()
    n = len(s)
    s1 = s[:(n-1)//2]
    s2 = s[((n+3)//2)-1:][::-1]
    if len(s1) % 2 == 0:
        s11 = s1[:len(s1)//2]
    else:
        s11 = s1[:(len(s1)-1)//2]
    s12 = s1[((len(s1)+3)//2)-1:][::-1]
    if s1 == s2 and s11 == s12:
        print('Yes')
    else:
        print('No')
    return


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
  string t;
  int ans = 0;

  cin >> t;
  for (int i = 0; i < t.size();i++){
    if(t[i]=='?'){
      t[i] = 'D';
    }
  }
  cout << t << endl;
  return 0;
}

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

using namespace std;

int solve(const string& s) {
    int zeroes = 0;
    int ones = 0;

    for (auto c : s) {
        zeroes += (c == '0' ? 1 : 0);
        ones += (c == '1' ? 1 : 0);
    }

    auto ans = min(zeroes, ones)*2;
    return ans;    
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    string cubes;

    cin >> cubes;

    auto count = solve(cubes);

    cout << count << endl;

    return 0;
}

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

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

int f = stoi(S.substr(0, 2));
int b = stoi(S.substr(2, 2));

if (f >= 1 && f <= 12) {
    if (b >= 1 && b <= 12) {
        cout << "AMBIGUOUS" << endl;
    } else {
        cout << "MMYY" << endl;
    }
} else {
    if (b >= 1 && b <= 12) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
}

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while (true) {
			String[] str = br.readLine().split(" ");
			int H = Integer.parseInt(str[0]);
			int W = Integer.parseInt(str[1]);
			if (H == 0 && W == 0) {
				break;
			}
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (i == 0 || j == 0 || i == H -1 || j == W - 1) {
						sb.append("#");
					} else {
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 25176
#include<iostream>
#include<map>
#include<queue>
using namespace std;

typedef pair<string,int> P;

int main(){
  int h,w,d;
  string tmp,g;
  int dx[] = {0,1,0,-1}, dy[] = {-1,0,1,0};
  bool f;
  map<string,int> m;
  P p;

  while(cin >> h >> w, h||w){
    g = "";
    for(int i=0;i<h;i++){
      cin >> tmp;
      g += tmp;
    }

    m.clear();
    deque<P> q;
    q.push_back(P(g,1));

    f = false;
    while(!q.empty()){
      p = q.front(); q.pop_front();
      g = p.first; d = p.second;
      if(m[g])continue;
      m[g] = d;

      int y,x;
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  if(g[i*w+j] == '@'){
	    y = i; x = j; break;
	  }
	}
      }

      for(int i=0;i<4;i++){
	int sy = y+dy[i], sx = x+dx[i];
	if(g[sy*w+sx] == '#' || g[sy*w+sx] == 'w')continue;
	if(g[sy*w+sx] == 'E'){
	  cout << d << endl;
	  f = true; break;
	}
	if(g[sy*w+sx] == '.'){
	  tmp = g;
	  tmp[y*w+x] = '.';
	  tmp[sy*w+sx] = '@';
	  q.push_back(P(tmp,d+1));
	}
	if(g[sy*w+sx] == 'c'){
	  tmp = g;
	  tmp[sy*w+sx] = '.';
	  for(;;){
	    sy += dy[i]; sx += dx[i];
	    if(tmp[sy*w+sx] == '#' || tmp[sy*w+sx] == 'c'){
	      tmp[(sy-dy[i])*w+(sx-dx[i])] = 'c';
	      break;
	    }
	    if(tmp[sy*w+sx] == 'w'){
	      tmp[sy*w+sx] = '.';
	      break;
	    }
	  }
	  q.push_front(P(tmp,d));
	}
      }
      if(f)break;
    }
    if(!f)cout << -1 << endl;
  }
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#define l long 
#define ll long long 
#define ld long double 
#define INF 1000000000000000
#define MOD 1000000007
#define MAX_N 100006
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULLL);
using namespace std;
vector<vector<l>> adj(MAX_N);
vector<ll> dp1(MAX_N),dp2(MAX_N);
vector<bool> vis(MAX_N,false);
void dfs_solver(l pos)
{
    vis[pos]=true;
    dp1[pos]=1;
    dp2[pos]=1;
    for(l i=0;i<adj[pos].size();i++)
    {
        if(!vis[adj[pos][i]])
        {
            dfs_solver(adj[pos][i]);
            dp1[pos]=(dp1[pos]*(dp1[adj[pos][i]]+dp2[adj[pos][i]]))%MOD;
            dp2[pos]=(dp2[pos]*dp1[adj[pos][i]])%MOD;
        }
    }
    return;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    l n,x,y;
    cin>>n;
    for(l i=0;i<n-1;i++)
    {
        cin>>x>>y;
        x--;
        y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs_solver(0L);
    ll ans=(dp1[0]+dp2[0])%MOD;
    if(ans<0)
    ans+=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 14560
#include <stdio.h>
#define max(a, b) ((a)<(b) ? (b) : (a))

int q;
int a[51], b[51], c[51], d[51];
int ans = 0;

void dfs(int array[], int m, int n){
  if(array[0] == n){
    int sum = 0;
    for(int i=0; i<q; i++){
      if(array[b[i]]-array[a[i]] == c[i]){
	sum = sum + d[i];
      }
    }
    ans = max(ans, sum);    
    return;
  }
  int start = (array[0]==0 ? 1 : array[array[0]]);
  for(int i=start; i<=m; i++){
    array[++array[0]] = i;
    dfs(array, m, n);
    array[0]--;
  }
}

int main(){
  int array[12] = {0};
  int n, m;  scanf("%d%d%d", &n, &m, &q);
  for(int i=0; i<q; i++){
    scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
  }
  dfs(array, m, n);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1704
N, Q = map(int, input().split())
S = input()

t = [0] * (N + 1)

for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
import math
a, b, C = [int(_) for _ in input().split()]

C_rad = C * math.pi / 180

S = a * b * math.sin(C_rad) / 2
Csq = a ** 2 + b ** 2 - 2 * a * b * math.cos(C_rad)
L = a + b + Csq ** 0.5
h = b * math.sin(C_rad)

print(S)
print(L)
print(h)



Measured memory_bytes: 5732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,c,d;
    string p;
    cin>>p;
    a=p[0]-'0';
    b=p[1]-'0';
    c=p[2]-'0';
    d=p[3]-'0';
    if(a+b+c+d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a-b-c-d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
     else if(a+b+c-d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }
    else if(a+b-c+d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a+b-c-d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
     else if(a-b-c+d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a-b+c-d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }
    else if(a-b+c+d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }


}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define llong long long
int n,m;
int pos[200200];
int nxt[200200];
llong K;

bool vis[200200];
int sta[200200],top;

double ans[100100];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&pos[i]),nxt[i]=i;
    for(int i=n;i;--i)pos[i]-=pos[i-1];
    scanf("%d%lld",&m,&K);
    int xx;
    for(int i=1;i<=m;++i)
        scanf("%d",&xx),swap(nxt[xx],nxt[xx+1]);
    for(int i=1;i<=n;++i)
        if(!vis[i])
        {
            xx=i; top=0;
            while(!vis[xx]) vis[xx]=1,sta[top++]=xx,xx=nxt[xx];
            for(int j=0;j<top;++j)
                ans[sta[j]]=pos[sta[(K+j)%top]];
        }
    for(int i=1;i<=n;++i)
    {
        ans[i]+=ans[i-1];
        printf("%.1lf ",ans[i]);
    }
    puts("");
    return 0;
}


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

using namespace std;

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

    long long ans;
    int n, k, cnt = 0;
    cin >> n >> k;

    cnt = n / k;
    ans = 1ll * cnt * cnt * cnt;

    if (k % 2 == 0)
        cnt = (n + k / 2) / k, ans += 1ll * cnt * cnt * cnt;

    cout << ans << '\n';

    return 0;
}


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

#define S_MAX 101

int main(void){
  int i;

  char s[S_MAX];
  scanf("%s", s);

  for(i=0; i<strlen(s); i++){
    if(i%2 == 0){
      if(s[i] == 'L'){
        printf("No\n");
        return 0;
      }
    }else{
      if(s[i] == 'R'){
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");

  return 0;
}


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

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

  vector<int64_t> data2(N);
  vector<int64_t> data1(N);
  for(int i=0; i<N; i++){
    cin >> data2.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> data1.at(i);
  }

  int64_t sum2= 0;
  int64_t sum1= 0;
  int64_t cnt2= 0;
  int64_t cnt1= 0;
  for(int i=0; i<N; i++){
    sum2+= data2.at(i);
    sum1+= data1.at(i);

    int64_t diff= data1.at(i)- data2.at(i);
    if(diff < 0){
      cnt1+= -diff;
    }
    else if(diff % 2==0){
      cnt2+= diff/2;
    }
    else{
      cnt2+= (diff+1)/ 2;
      cnt1++;
    }
  }
  int64_t Nop= sum1- sum2;
  string ans= (cnt1 <= Nop && cnt2 <= Nop) ? "Yes"
                                           : "No";

  cout << ans << endl;
}

Measured memory_bytes: 3756
#include<stdio.h>
#include<iostream>
#include<math.h>
int main()
{
    double a,b,h,m,x,y;
    // 整数の入力
    scanf("%lf %lf %lf %lf", &a, &b, &h, &m);

	double t = fabs((h+ m/60.0)/12.0 - m/60.0) * 2 * M_PI;

	if(t == 0){
    printf("%.11f\n",(fabs(a-b)));
	return 0;

	}
	if(t == M_PI){
	    printf("%.11f\n",(fabs(a+b)));
		return 0;
	}

	double d;
	if(t < M_PI/2 || M_PI*3/2 < t){
		x = (a - b*fabs(cos(t)));
		y =  (b * fabs(sin(t)));
	}
	else {
		x = (a + b*fabs(cos(t)));
		y =  (b * fabs(sin(t)));

	}
	d = sqrt(x*x + y*y);

    // 出力
    printf("%.17f\n",d);
    return 0;
}


Measured memory_bytes: 4168
import java.util.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int c = 0;
        int[] a= new int[100];
        for(int i=2; i<=2000; i++){
            for(int j=2; (i%j!=0 && j<i)||j==i; j++){
                if(j==i&&i%5==1){
                    a[c]=i;
                    c++;
                }
            }
        }
        for(int j=0;j<N;j++){
                 System.out.print(a[j]+" ");
        }
    }
}

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

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

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N, 0), B(N, 0), C(N, 0);
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, N)
    {
        cin >> B[i];
    }
    REP(i, N)
    {
        cin >> C[i];
    }

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sort(B.begin(), B.end());
    reverse(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());

    ll combA[N] = {0}, combB[N] = {0};
    // A の各要素に対して選ぶことのできるB の要素の数を調べる
    int indexB = 0;
    REP(i, N)
    {
        ll a = A[i];
        if (i > 0)
        {
            if (a == A[i -1])
            {
                combA[i] = combA[i - 1];
                continue;
            }
        }
        if (indexB < N)
        {
            for (int j = indexB; j < N; ++j)
            {
                if (a >= B[j])
                {
                    break;
                }
                else
                {
                    indexB++;
                }
            }
        }
        combA[i] = indexB;
    }
    // B の各要素に対して選ぶことのできるC の要素の数を調べる
    int indexC = 0;
    REP(i, N)
    {
        ll b = B[i];
        if (i > 0)
        {
            if (b == B[i -1])
            {
                combB[i] = combB[i - 1];
                continue;
            }
        }
        if (indexC < N)
        {
            for (int j = indexC; j < N; ++j)
            {
                if (b >= C[j])
                {
                    break;
                }
                else
                {
                    indexC++;
                }
            }
        }
        combB[i] = indexC;
    }

    // combBの部分和を先頭から計算しておく
    ll sumCombB[N];
    sumCombB[0] = combB[0];
    for (int i = 1; i < N; ++i)
    {
        sumCombB[i] = sumCombB[i -1] + combB[i];
    }

    ll ans = 0;
    REP(i, N)
    {
        if (combA[i] != 0)
        {
            ans += sumCombB[combA[i] - 1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5504
unittest
{
	assert( [ "rng gorilla apple" ].parse.expand.solve == "YES" );
	assert( [ "yakiniku unagi sushi" ].parse.expand.solve == "NO" );
	assert( [ "a a a" ].parse.expand.solve == "YES" );
	assert( [ "aaaaaaaaab aaaaaaaaaa aaaaaaaaab" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split;
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( string a, string b, string c )
{
	return ( a[ $ - 1 ] == b[ 0 ] && b[ $ - 1 ] == c[ 0 ] ) ? "YES" : "NO";
}


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

using namespace std;

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

#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=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, n;
	cin>>n>>h>>w;
	cout<<(n-h+1)*(n-w+1)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;


#define int ll

int cost[maxn], k[maxn], c[1001][50];
int d[5001][2];

void solve () {
	int n, m; cin >> n >> m;
	for (int i = 1; i <= m; i ++) {
		cin >> cost[i] >> k[i];
		for (int j = 1; j <= k[i]; j ++) {
			cin >> c[i][j];	
			c[i][j] --;
		}
	}


	for (int mask = 0; mask < (1 << n); mask ++)
		for (int j = 0; j <= n; j ++)
		d[mask][j] = d[mask][j] = linf; 
	d[0][0] = 0;

	for (int i = 1; i <= m; i ++) {
		for (int mask = 0; mask < (1 << n); mask ++)
			d[mask][i] = d[mask][i-1];
		
		for (int mask = 0; mask < (1 << n); mask ++) {
			int mask2 = mask; for (int j = 1; j <= k[i]; j ++) mask2 |= (1 << c[i][j]);
			d[mask2][i] = min (d[mask2][i], d[mask][i-1] + cost[i]);		
		}
	}


	int res = d[(1 << n)-1][m];

	if (res == linf) res = -1;
	cout << res;
}

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

Measured memory_bytes: 4088
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll d ; cin >> d ;
	vll c(26) ;
	for(auto &i:c) cin >> i ;
	vvll di(d,vll(26)) ;
	for(int i=0;i<d;i++) for(int j=0;j<26;j++) cin >> di.at(i).at(j) ;
	vll last(26,-1) ;
	ll sum = 0 ;
	for(int i=0;i<d;i++){
		ll mx = -INF ;
		ll contest = -1 ;
		ll dec = 0 ;
		for(int j=0;j<26;j++){
			dec += c.at(j)*(i-last.at(j)) ;
		}
		for(int j=0;j<26;j++){
			if(ll tmp=di.at(i).at(j)-dec+c.at(j)*(i-last.at(j));tmp>=mx){
				contest = j ;
				mx = tmp ;
			}
		}
		cout << contest+1 << endl ;
		sum += mx ;
		// ll t ; cin >> t ;
		// t-- ;
		// last.at(t) = i ;
		// sum += di.at(i).at(t) ;
		// for(int j=0;j<26;j++){
			// sum -= c.at(j)*(i-last.at(j)) ;
		// }
		//cout << sum << endl ;
	}
}

Measured memory_bytes: 3728
N = int(input())
A = list(map(int, input().split()))

b = {}
for i in range(N):
    if A[i] not in b:
        b[A[i]] = 1
    else:
        b[A[i]] += 1

total = 0
for v in b.values():
    total += v*(v-1)/2

for k in range(N):
    n = b[A[k]]
    ans = int(total - n*(n-1)/2 + (n-1)*(n-2)/2)
    print(ans)


Measured memory_bytes: 26140
#include <stdio.h>
#define N 100
#define INF 1000000000
#define TRUE 1
#define FALSE 0

int Queue[N];

int head = 0,tail = 0;

int n,G[N][N];

int d[N];

int isEmpty(void){
  if(head == tail) return TRUE;
  return FALSE;
}

void enqueue(int key){
  Queue[tail] = key;
  tail = (tail + 1)%N;
}

int dequeue(void){
  int tmp;
  tmp  = Queue[head];
  head = (head + 1)%N; 
  return tmp;
}

void intialize(void){
  for(int i = 0; i < n; i++){
    d[i] = INF;
    for(int j = 0; j < n; j++){
      G[i][j] = 0;
    }
  }
}

void BFS(int s){
  enqueue(s);
  d[s] = 0;
  int u;
  while(isEmpty() != TRUE){
    u = dequeue();
    for(int v = 0; v < n; v++){
      if(G[u][v] == 0) continue;
      if(d[v] != INF) continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }
  for(int i = 0; i < n; i++){
    printf("%d ",i+1);
    if(d[i] == INF) printf("%d\n",-1);
    else printf("%d\n",d[i]);
  }
}
  
  

int main()
{
  int u,k,v;
  scanf("%d",&n);
  intialize();
  for(int i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(int j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }
  
  BFS(0);

  return 0;
}
      



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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	double q;
	while (cin >> q, q != -1) {
		double x = q / 2;
		while (abs(x*x*x - q) >= (1e-5)*q) {
			x = (x - (x*x*x - q) / (3 * x*x));
		}
		cout << fixed <<  x << endl;
	}
	return 0;
}

Measured memory_bytes: 3276
#include <stdio.h>

class Dice2{
public:
	Dice2(){
		number = new int[6];
		relative = new int[55];
		relative[31] = relative[43] = relative[24] = relative[12] = 0;
		relative[3] = relative[20] = relative[52] = relative[35] = 1;
		relative[1] = relative[40] = relative[54] = relative[15] = 2;
		relative[4] = relative[10] = relative[51] = relative[45] = 3;
		relative[2] = relative[30] = relative[53] = relative[25] = 4;
		relative[21] = relative[42] = relative[34] = relative[13] = 5;
 	};
	~Dice2(){
		delete[] number;
		delete[] relative;
	};

	void setNumber(int index,int num){
		number[index] = num;
	};

	int returnRight(int top,int front){
		int top_index,front_index;
		for(int i = 0; i < 6; i++){
			if(number[i] == top)
				top_index = i;
			if(number[i] == front)
				front_index = i;
		}
		return number[relative[10*top_index+front_index]];
	}
private:
	int* number;
	int* relative;
};

int main(){
	Dice2 dice2;
	int x,q,top,front;
	for(int i = 0; i < 6; i++){
		scanf("%d",&x);
		dice2.setNumber(i,x);
	}
	scanf("%d",&q);
	for(int i = 0; i < q; i++){
		scanf("%d %d",&top,&front);
		printf("%d\n",dice2.returnRight(top,front));
	}
}



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

int main(){

	string N;
  cin>>N;
  bool d=false;
  rep(i,3){
    if(N[i]=='7') d=true; 

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

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

string s;
int Q;

int main(){
  cin >> s >> Q;
  bool flag = true; //
  string left = "", right = "";
  rep(i, Q){
    int q;;
    cin >> q;
    if(q == 1){
      flag = !flag;
      continue;
    }
    int f; char c; 
    cin >> f >> c;
    if(flag){
      if(f == 1){
        left.push_back(c);
      }else{
        right.push_back(c);
      }
    }else{
      if(f == 1){
        right.push_back(c);
      }else{
        left.push_back(c);
      }
    }
  }
  reverse(left.begin(), left.end());
  string res = left + s + right;
  if(!flag) reverse(res.begin(), res.end());
  cout << res << endl;
}


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

#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
#define DEBUG(x) cerr << #x << " = " << x << endl

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 100005;
int r[N], c[N];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	int n, m, x, y;

	cin >> n >> m;
	REPU(i, 1, N) r[i] = 1, c[i] = 0;
	c[1] = 1;
	REPU(_, 0, m) {
		cin >> x >> y;
		if (c[x]) c[y] = 1;
		r[x]--, r[y]++;
		if (r[x] == 0) c[x] = 0;
	}

	int ans = 0;
	REPU(i, 1, n + 1) if (c[i] && r[i]) {
		ans++;
	}
	cout << ans << endl;
	
	return 0;
}

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

int l, r;
long long ans = 50000;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif  // ONLINE_JUDGE
  cin >> l >> r;
  r = min(l + 5000, r);
  for (int i = l; i <= r; ++i) {
    for (int j = i + 1; j <= r; ++j) {
      ans = min(ans, (1LL * i * j) % 2019);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;
    //旅館の数
    cin>>N;
    int H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int Max=H[0];
    int count=1;
    for(int i=1;i<N;i++){
        if(Max<=H[i]){
            count=count+1;
            Max=H[i];
        }
    }
    cout<<count<<endl;
    return 0;
}

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

vector<vector<int>> input_matrix(int h, int w) {
	vector<vector<int>> res(h, vector<int>(w));
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> res[i][j];
		}
	}
	return res;
}

int main() {
	int H, W;
	cin >> H >> W;

	const auto a = input_matrix(H, W);
	const auto b = input_matrix(H, W);

	int h, w;
	cin >> h >> w;
	const auto c = input_matrix(h, w);

	int ans = INT_MIN;
	for(int i = 0; i < H - h + 1; ++i) {
		for(int j = 0; j < W - w + 1; ++j) {
			int sum = 0;
			for(int k = 0; k < h; ++k) {
				for(int l = 0; l < w; ++l) {
					if(b[i + k][j + l] != c[k][l]) goto unmatch;
					sum += a[i + k][j + l];
				}
			}
			ans = max(ans, sum);

		unmatch:;
		}
	}

	if(ans == INT_MIN) puts("NA");
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1240
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<iterator>
#include<algorithm>
#include<iomanip>
#include <string.h>
#include<set>

#define ll long long int
using namespace std;



int main(){
        ll n,k;
        cin >> n;
        cin >> k;
        ll sum=1,s=0;
        for(int i=1;i<=n;i++){
            if(sum <= k){
                sum = sum*2;
            }
            else{
                sum += k;
            }
          //  cout << sum << " "; //for tasting error
        }
        cout << sum  << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
  int n;cin >> n;
  int m;cin >> m;
  if(n % m == 0){
    cout << 0 << endl;
  }else{
    cout << n - m  << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

int n, m;
long long x[1010], y[1010], z[1010], sum[1010];
int main() {
	std::cin >> n >> m;
	for (int i = 0; i < n; ++i)
		std::cin >> x[i] >> y[i] >> z[i];

	long long ans = 0;
	for (int s = 0; s < (1 << 4); ++s) {
		for (int i = 0; i < n; ++i) {
			sum[i] = 0;
			if (s & 1)
				sum[i] -= x[i];
			else
				sum[i] += x[i];

			if ((s >> 1) & 1)
				sum[i] -= y[i];
			else
				sum[i] += y[i];

			if ((s >> 2) & 1)
				sum[i] -= z[i];
			else
				sum[i] += z[i];
		}
		std::sort(sum, sum + n, std::greater<long long>());

		long long res = 0;
		for (int i = 0; i < m; ++i)
			res += sum[i];
		ans = std::max(ans, res);
	}
	std::cout << ans << std::endl;
	return 0;
}


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

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

	int ans = 0;

	for (int i = 0; i < s.size(); i++) {

		if (s.at(i) == '+') ans++;
		else ans--;
	}
	
	cout << ans << endl;

	return 0;
}

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

int main()
{
    int n;
    std::cin >> n;

    std::vector<std::vector<int>> a(n, std::vector<int>(n - 1));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            std::cin >> a[i][j];
            a[i][j]--;
        }
        std::reverse(a[i].begin(), a[i].end());
    }

    std::vector<std::pair<int, int>> q;
    auto check = [&](int player) {
        if (a[player].empty()) {
            return;
        }

        int opponent = a[player].back();
        if (a[opponent].empty()) {
            return;
        }

        if (a[opponent].back() != player) {
            return;
        }

        if (player > opponent) {
            std::swap(player, opponent);
        }

        q.push_back(std::make_pair(player, opponent));
    };

    for (int i = 0; i < n; i++) {
        check(i);
    }

    long long day = 0;
    while (q.size()) {
        day++;
        std::sort(q.begin(), q.end());
        q.erase(std::unique(q.begin(), q.end()), q.end());

        std::vector<std::pair<int, int>> past_q;
        std::swap(q, past_q);
        for (auto p : past_q) {
            int first = p.first, second = p.second;

            a[first].pop_back();
            a[second].pop_back();
        }
        for (auto p : past_q) {
            int first = p.first, second = p.second;

            check(first);
            check(second);
        }
    }

    for (auto elem : a) {
        if (elem.size()) {
            std::cout << -1 << std::endl;
            return 0;
        }
    }

    std::cout << day << std::endl;
}


Measured memory_bytes: 4224
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int[] t = new int[N];
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++){
            t[i] = input.nextInt();
            x[i] = input.nextInt();
            y[i] = input.nextInt();
        }
        int nx,ny,nt;
        nx = 0;
        ny = 0;
        nt = 0;
        String res = "Yes";
        for (int i = 0; i < N; i++){
            int dx = Math.abs(x[i]-nx);
            int dy = Math.abs(y[i]-ny);
            int dt = Math.abs(t[i]-nt);
            if (dt-(dx+dy) >= 0){
                if ((dt-(dx+dy))%2 == 0){
                    continue;
                } else{
                    res = "No";
                    break;
                }
            } else{
                res = "No";
                break;
            }
        }
        System.out.println(res);
    }
}



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

const int maxn = 110;
string s, t;

int main() {
	getline(cin, s);
	getline(cin, t);
	for (int i = 0; i < s.size(); i++) {
		if (s == t) {
			puts("Yes");
			return 0;
		}
		char ch = t[t.size() - 1];
		for (int j = t.size() - 1; j > 0; j--) {
			t[j] = t[j - 1];
		}
		t[0] = ch;
	}
	puts("No");
	return 0;
}

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

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

    // stringからintに変換
    int s_f = (s[0]-'0')*10 + (s[1]-'0');
    int s_s = (s[2]-'0')*10 + (s[3]-'0');

    if(s_f>0 && s_f<=12 && s_s>0 && s_s<=12){
        cout << "AMBIGUOUS" << endl;
        return 0;
    }
    if(s_s>0 && s_s<=12){
        cout << "YYMM" << endl;
        return 0;
    }
    if(s_f>0 && s_f<=12){
        cout << "MMYY" << endl;
        return 0;
    }
    cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {

	int N, K;
	scanf("%d%d", &N, &K);

	if (N%K == 0) {
		printf("%d", 0);
	}
	else {
		printf("%d", 1);
	}

	
	return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int N;
    cin >> N;
    long long p = 1;
    double b = 0;
    long long max = 1000'000'000'000'000'000;
    bool r = false;
    long long a;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        if (a == 0)
        {
            cout << 0;
            return 0;
        }
        if (!r)
        {
            b += log10(a);
            if (b > 18.01)
            {
                r = true;
            }
            else
            {
                p *= a;
                if (p > max)
                {
                    r = true;
                }
            }
        }
    }
    if (r)
    {
        cout << -1;
    }
    else
    {
        cout << p;
    }
    return 0;
}

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

using namespace std;
int n,k;
char s[100005];

int main()
{
    scanf("%d%d\n",&n,&k);
    scanf("%s",s);
    int hp=0,np=0;
    for(int i=0;i<n;++i){
        if(i==0||s[i-1]!=s[i])++np;
        else ++hp;
    }
    np-=1;
    hp += min(np,2*k);
    printf("%d\n",hp);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;






int main(){
    string s,t;
    cin>>s>>t;
    string ans="UNRESTORABLE";
    if(s.size()<t.size())cout<<"UNRESTORABLE"<<endl;
    else{
      for(int i=0;i<=s.size()-t.size();++i){
            bool han=true;
          for(int j=0;j<t.size();++j){

              if(s[i+j]!=t[j]&&s[i+j]!='?'){
                  han=false;
                  break;
              }
            }
            if(han){
                string ans2=s;
                for(int j=0;j<t.size();++j){
                    ans2[i+j]=t[j];
                }
                for(int j=0;j<ans2.size();++j){
                    if(ans2[j]=='?')ans2[j]='a';
                }
                if(ans=="UNRESTORABLE"||ans2<ans)ans=ans2;

          }
      }  
              cout<<ans<<endl;

    }
}



Measured memory_bytes: 256
import heapq
n, m = map(int,input().split())

a = [-i for i in list(map(int, input().split()))]

heapq.heapify(a)

for _ in range(m):
    tmp = heapq.heappop(a)
    heapq.heappush(a,int(tmp/2))

print(abs(sum(a)))

Measured memory_bytes: 14180
import numpy as np
N = int(input())
A = np.array([list(map(int, input().split())) for _ in range(N)])

for i in range(N):
    A[i][i] = 10 ** 9

ans = 0
for i in range(N):
    for j in range(i+ 1, N):
        dp = np.min(A[i] + A[j])
        if A[i][j] < dp:
            ans += A[i][j]
        elif A[i][j] > dp:
            print (-1)
            exit()

print (ans)


Measured memory_bytes: 16340
#include <iostream>
#include <string>
using namespace std;
int main(void){
	string str;
	int i;
	cin>>str;
	for (i=0;i<str.size();i++)
	{
		if (str[i]<'D'){
			str[i]=str[i]+23;
		}else{
			str[i]=str[i]-3;
		}
	}
	cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 3120
#!/usr/bin/env python3

def solve(n,y):
  billUnit = (10000,5000,1000)
  for i in range(0,y//billUnit[0]+1):
    for j in range(0,y//billUnit[1]+1):
      rest = y - billUnit[0] * i - billUnit[1] * j
      k = n - i - j
      if billUnit[2] * k == rest and k >= 0:
        return i,j,k
  return -1,-1,-1



def main():
  N,Y = map(int,input().split())
  print(*solve(N,Y))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9116
#include <stdio.h>

int main(void)
{
  int A, B;
  scanf("%d%d", &A, &B);
  if(A + 1 < B){
  	printf("%d", 2*B-1);
  } else if(B + 1 < A){
    printf("%d", 2*A-1);
  } else {
    printf("%d", A+B);
  }
  return 0;
}

Measured memory_bytes: 128