akhauriyash/Code-Regression huggingface dataset:
# バックトラック法
#   http://sevendays-study.com/algorithm/ex-day4.html

class Queen

  N = 8
  EMPTY = '-'
  FULL = '.'
  QUEEN = 'Q'

  def initialize
    @board = Array.new(N){ Array.new(N){ EMPTY } } # 盤面情報
    @rows = Array.new(N){ EMPTY } # 各行が埋まっているかどうか
    @cols = Array.new(N){ EMPTY } # 各列が埋まっているかどうか
    @history = [] # バックトラック用の履歴
  end

  def put(x, y)
    # return 置ける場合はtrue, 置けない場合はfalse

    return false if @board[x][y] != EMPTY

    save(x, y)

    #
    @rows[y] = FULL
    @cols[x] = FULL

    # 行列方向
    0.upto(N-1) do | a |
      @board[x][a] = FULL
      @board[a][y] = FULL
    end

    # Queen
    @board[x][y] = QUEEN

    # 斜め方向
    [[1,1], [1,-1], [-1,1], [-1,-1]].each do | direction_x, direction_y |
      _x, _y = x + direction_x, y + direction_y
      while 0<=_x && _x<=7 && 0<=_y && _y<=7
        @board[_x][_y] = FULL
        _x, _y = _x + direction_x, _y + direction_y
      end
    end
    return true
  end

  def solve(x_start, y_start)
    x_start.upto(N-1) do | x |
      if @cols[x] == EMPTY
        could = false # 該当行に置けたか
        y_start.upto(N-1) do | y |
          if put(x, y)
            could = true
            break
          end
        end
        y_start = 0
        unless could
          x, y = rollback
          solve(x, y+1)
        end
      end
    end
  end

  def print
    @board.each{|r| puts r.join('').gsub('-', '.')}
  end

  def debug_print
    puts '----'
    p @history
    @board.each{|r| puts r.join('').gsub('-', '.')}
  end

  private
  def save(x, y)
    @history << [deep_copy, @rows.clone, @cols.clone, x, y]
  end
  def rollback
    @board, @rows, @cols, x, y = @history.pop
    return x, y
  end
  def deep_copy
    new_board = Array.new(N){ Array.new(N){ EMPTY } }
    0.upto(N-1) do | x |
      0.upto(N-1) do | y |
        new_board[x][y] = @board[x][y]
      end
    end
    return new_board
  end
end

q = Queen.new

n = gets.to_i
n.times do
  x, y = gets.split.map(&:to_i)
  q.put(x, y)
end
q.solve(0, 0)
q.print



Measured memory_bytes: 6948
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
	int n;
	int a[100];
	scanf("%d",&n);
	int sum=0;
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	int fg=0;
	bool ans[50];
	memset(ans,0,sizeof(ans));
	a[0]=a[1]-1;
	for(int i=1;i<n;++i){
	
		if(a[i]!=i) {
			fg++;		ans[i+1]=1;
			
			if(fg>2) break;
		}
	}
//	cout<<endl;
	if(fg>2) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
K=[0 for i in range(N)]
for i in range(N):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(N) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
if len(res)==N:
    print(-1)
else:
    print(0)



Measured memory_bytes: 3436
import numpy as np

H,W = map(int,input().split())
maze = [list(input())for _ in range(H)]
for i in range(H):
  for j in range(W):
    if maze[i][j]=="#":
      maze[i][j]=0
    else:
      maze[i][j]=float('INF')
maze = np.array(maze)
      
for i in range(1,H):
  maze[i,:]=np.minimum(maze[i-1,:]+1,maze[i,:])
for i in range(H-2,-1,-1):
  maze[i,:]=np.minimum(maze[i+1,:]+1,maze[i,:])
for i in range(1,W):
  maze[:,i]=np.minimum(maze[:,i-1]+1,maze[:,i])
for i in range(W-2,-1,-1):
  maze[:,i]=np.minimum(maze[:,i+1]+1,maze[:,i])
  
print(int(np.max(maze)))


Measured memory_bytes: 52560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));

    int cnt=1;
    int ans=0;
    int c2=0;
    rep(i,n-1){
        if(a[i]==a[i+1]) cnt++;
        else{
            if(cnt%2==1) ans++;
            else c2++;
            cnt=1;
        }
    }
    if(cnt==1) ans++;
    else{
        if(cnt%2==1) ans++;
        else c2++;
    }

    if(c2%2==0) ans+=c2;
    else ans+=c2-1;

    cout<<ans<<endl;

} 


Measured memory_bytes: 3788
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    string s;
    cin>>s;
    long long a;
    cin>>a;
    long long ansnum=0;
    rep(i,s.size()){
        int k;
        k=(s.at(i)-'0');
        if(k==1){
            if(a==i+1){
                cout<<1<<endl;
                break;
            }
        }
        else{
            cout<<k<<endl;
            break;
        }
    } 
}



Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

vector<vector<lli> > adj;
lli n,m;
lli dp[100005];
lli ans;

lli dfs(lli in){
    if(dp[in]!=-1) return dp[in];

    lli i,j=0;
    for(i=0;i<adj[in].size();i++){
        j=max(j,dfs(adj[in][i]));
    }
    if(adj[in].size()==0) return dp[in]=0;
    else return dp[in]=1+j;
}


int main(){
    cin>>n>>m;
    lli i,j,l;
    lli in[n+1]={0};
    memset(dp,-1,sizeof(dp));
    adj.resize(n+1);
    for(i=0;i<m;i++){
        lli x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        in[y]++;
    }
    for(i=1;i<=n;i++){
        if(in[i]==0){
            ans=max(ans,dfs(i));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11904
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define MOD 1000000007
typedef long long ll;
using namespace std;

struct UnionFind{
  vector<int> par;

  UnionFind(int N) : par(N){
    for(int i=0;i<N;i++) par[i] = i;
  }

  int root(int x){
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int main(){
  int N,K,L; cin >> N >> K >> L;
  UnionFind road(N);
  UnionFind rail(N);
  for(int i=0;i<K;i++){
    int p,q; cin >> p >> q;
    p--; q--;
    road.unite(p,q);
  }
  for(int i=0;i<L;i++){
    int r,s; cin >> r >> s;
    r--; s--;
    rail.unite(r,s);
  }

  map<pair<int,int>,int> mp;
  for(int i=0;i<N;i++) mp[{road.root(i),rail.root(i)}]++;
  for(int i=0;i<N;i++){
    if(i > 0) cout << " ";
    cout << mp[{road.root(i),rail.root(i)}];
  }
  cout << endl;
  return 0;

}

Measured memory_bytes: 13568
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    int i,len;
    char input[101],word[101],tmp[201],text[201];
    char *re;
     
    scanf("%s",text);
    strcpy(tmp,text);
    strcat(text,tmp);
     
    scanf("%s",word);
     
    if((re=strstr(text,word))!=NULL){
        puts("Yes");
    }
    else puts("No");
 
return 0;
}


Measured memory_bytes: 2104
import itertools
import math

N = int(input())
List=[list(map(int,input().split())) for i in range(N)]
roots = list(itertools.permutations(range(N)))
sum_length = 0
for root in roots:
    first_city = 100 # 存在しない
    for city in root:
        if first_city == 100:
            first_city = city
            continue
        x = List[first_city][0] - List[city][0]
        y = List[first_city][1] - List[city][1]
        sum_length += math.sqrt(pow(x,2)+pow(y,2))
print(sum_length/len(roots))

Measured memory_bytes: 46828
from operator import mul

n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
print(max(sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)) for g in range(1, 1024)))


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

int main() {
  int s, w;
  cin >> s >> w;
  
  if (w >= s)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;

  return 0;
}


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

int main() {
    
    string s;
    cin >> s;
    if(s=="Sunny") cout << "Cloudy" << endl;
    else if(s=="Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    
    
	return 0;
}

Measured memory_bytes: 3508
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int now,n,d;

int main(){
  int ans=0;
  cin >> n >>d;
  d=2*d+1;
  ans=(n+d-1)/d;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,mini,ans;
  cin>>N;
  mini=200000;
  ans=0;
  for(int i=0;i<N;i++){
    int tmp;
    cin>>tmp;
    if(tmp<=mini){
      ans++;
    }
    if(mini>tmp){
      mini=tmp;
    }

  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong
const double PI=3.14159265358979323846;

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

int dp[100010];

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    for(int i=0;i<100010;i++){
        dp[i] = INT_INF;
    }
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    
}

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

const int DIM = 105;

int arr[DIM];

int main(void) {
	int n, x; cin >> n >> x;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i]; }
	sort(arr + 1, arr + n + 1);
	int nr = 0;
	for (int i = 1; i <= n; ++i) {
		if (x >= arr[i]) {
			++nr; x -= arr[i]; } }
	if (nr == n and x) {
		--nr; }
	cout << nr;
	return 0; }


Measured memory_bytes: 256
import { readFileSync } from 'fs'

function main(input: string) {
  const [header, cards, ...lines] = input.split('\n').map(v => v.split(' ').map(Number))

  cards.sort((a, b) => a - b)
  lines.sort(([, a], [, b]) => b - a)

  let currentIndex = 0
  let currentCount = 0

  const getNextEnchant = (): number => {
    const value = lines[currentIndex]

    if (value == null) return 0

    const [maxCount, v] = value

    if (currentCount < maxCount) {
      ++currentCount
      return v
    }

    ++currentIndex
    currentCount = 0
    return getNextEnchant()
  }


  for (let i = 0, len = cards.length; i < len; ++i) {
    const enchant = getNextEnchant()
    if (enchant <= cards[i]) break

    cards[i] = enchant
  }

  const result = cards.reduce((sum, v) => sum + v, 0)

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


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

int main() {
	char s[4];
  	cin >> s;
  	if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
    	cout << "Yes" << endl;
    }
  	else{
    	cout << "No" << endl;
    }
}



Measured memory_bytes: 3624
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)

# def input(): return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999

n = int(input())
A = [-INF] + get_nums_l()

# log(n)
# log(A)

edges = [ [] for _ in range(n+1) ]
for _ in range(n-1):
#for line in map(lambda s: s.strip(), sys.stdin.readlines()):
    line = input().strip()
    # log(line)
    u,v = map(int, line.split())
    edges[u].append(v)
    edges[v].append(u)

def dfs(dp, u, p=None):

    # log(u)
    # log(dp)

    # dpの中でA[u]以上の値が入っている最小のindex
    i = bisect_left(dp, A[u])

    old = dp[i]
    dp[i] = A[u]

    # 有効値(INF以外)が入っている最大のindex
    ans[u] = bisect_left(dp, INF) - 1

    for v in edges[u]:
        if v == p:
            continue
        dfs(dp, v, u)

    # 巻き戻し
    dp[i] = old

# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)

# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF

dfs(dp, 1, None)

for i in range(1, n+1):
    print(ans[i])


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    if (count(A.begin(), A.end(), 0)) {
        cout << 0 << '\n';
        return;
    }
    ll ans = 1;
    rep(i, N) {
        ll a = A[i];
        if (1000000000000000000 / ans >= a) {
            ans *= a;
        } else {
            cout << -1 << '\n';
            return;
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3940
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int W,H,N;
int X1[5000];int X2[5000];
int Y1[5000];int Y2[5000];
int field[4001][4001];
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
bool FX[1000005];bool FY[1000005];
int Num_X[5000];int Num_Y[5000];
queue<pair<int,int> >que;
int main()
{
	while(true){
		for(int i=0;i<4001;i++)for(int j=0;j<4001;j++)field[i][j]=0;
		scanf("%d%d",&W,&H);
		if(W==0&&H==0)return 0;
		scanf("%d",&N);
		for(int i=0;i<N;i++)scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
		for(int i=0;i<N;i++){
			X1[i]++;X2[i]++;Y1[i]++;Y2[i]++;
			if(X1[i]!=1)FX[X1[i]-1]=true;
			FX[X1[i]]=true;
			if(X2[i]!=W+1)FX[X2[i]]=true;
			FX[X2[i]-1]=true;
			FY[Y1[i]]=true;
			if(Y1[i]!=1)FY[Y1[i]-1]=true;
			if(Y2[i]!=H+1)FY[Y2[i]]=true;
			FY[Y2[i]-1]=true;
		}
		int cou1=0,cou2=0;
		for(int i=0;i<=W+1;i++){
			if(FX[i]){
				Num_X[cou1]=i;
				cou1++;
				
			}
		}
		for(int i=0;i<=H+1;i++){
			if(FY[i]){
				Num_Y[cou2]=i;
				cou2++;
				
			}
		}
		//for(int i=0;i<cou1;i++)printf("%d:%d\n",i,Num_X[i]);
		//for(int i=0;i<cou2;i++)printf("%d:%d\n",i,Num_Y[i]);
		for(int i=0;i<N;i++){
			for(int j=0;j<cou1;j++){
				if(Num_X[j]==X1[i])X1[i]=j;
				if(Num_X[j]==X2[i])X2[i]=j;
			}
			if(X2[i]>=cou1)X2[i]=cou1+1;
			for(int j=0;j<cou2;j++){
				if(Num_Y[j]==Y1[i])Y1[i]=j;
				if(Num_Y[j]==Y2[i])Y2[i]=j;
			}
			if(Y2[i]>=cou2)Y2[i]=cou2+1;
		}
		for(int i=0;i<N;i++){
			field[X1[i]][Y1[i]]++;
			field[X2[i]][Y2[i]]++;
			field[X1[i]][Y2[i]]--;
			field[X2[i]][Y1[i]]--;
			//printf("%d\n",i);
		}
		for(int i=1;i<cou1;i++){
			for(int j=0;j<cou2;j++){
				field[i][j]+=field[i-1][j];
			}
		}
		for(int i=0;i<cou1;i++){
			for(int j=1;j<cou2;j++){
				field[i][j]+=field[i][j-1];
			}
		}
		
		
		/*for(int i=0;i<cou2;i++){
			for(int j=0;j<cou1;j++){
				printf("%d ",Field[j][i]);
			}
			printf("\n");
		}*/
		int ans=0;
		for(int i=0;i<cou1;i++){
			for(int j=0;j<cou2;j++){
				que.empty();
				if(field[i][j]>0)continue;
				ans++;
				que.push(make_pair(i,j));
				while(!que.empty()){
					pair<int,int> P=que.front();que.pop();
					int pf=P.first;int ps=P.second;
					if(field[pf][ps]>0)continue;
					field[pf][ps]=1;
					for(int k=0;k<4;k++){
						if(pf+dx[k]<0)continue;
						if(pf+dx[k]>=cou1)continue;
						if(ps+dy[k]<0)continue;
						if(ps+dy[k]>=cou2)continue;
						if(field[pf+dx[k]][ps+dy[k]]>0)continue;
						que.push(make_pair(pf+dx[k],ps+dy[k]));
					}
				}
			}
		}
		printf("%d\n",ans);
		
	}
	return 0;
}

Measured memory_bytes: 63832
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] A = new int[N + 1];
        int[] B = new int[N];
        for (int i = 0; i < N + 1; i++) {
            A[i] = in.nextInt();
        }
        for (int i = 0; i < N; i++) {
            B[i] = in.nextInt();
        }

        long r = 0, d = 0;
        for (int i = 0; i < N; i++) {
            int a = A[i];
            int b = B[i];

            d = Math.min(a, d);

            r += d;
            a -= d;

            r += Math.min(a, b);
            d = Math.max(0, b - a);
        }
        r += Math.min(A[N], d);

        out.println(r);
    }
}


Measured memory_bytes: 64052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		sc.close();

		int min = x[0];
		int max = x[0];
		for(int i = 0; i < n; i++) {
			min = Math.min(x[i], min);
			max = Math.max(x[i], max);
		}
		int ans = Integer.MAX_VALUE;
		for(int i = min; i <= max; i++) {
			int cost = 0;
			for(int j = 0; j < n; j++) {
				cost += (x[j] - i) * (x[j]-i);
			}
			ans = Math.min(cost, ans);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	while(cin >> n){
		cout << stop[n] << endl;
		c++;
	}
	while(c>=50){};
	
}

Measured memory_bytes: 0
use std::io::*;


fn main() {
    let mut strs = String::new();
    let stdin = stdin();
    let mut stdinlock = stdin.lock();
    stdinlock.read_line(&mut strs).unwrap();
    let nindex = strs.trim().as_bytes();
    let a = (nindex[0] - 48u8) as i32;
    let b = (nindex[1] - 48u8) as i32;
    let c = (nindex[2] - 48u8 )as i32;
    let d = (nindex[3] - 48u8) as i32;

   if (a + b + c + d) as i32 == 7i32 {
       println!("{}+{}+{}+{}=7", a, b, c, d);
   } else if  (a + b + c - d )as i32 == 7i32 {
       println!("{}+{}+{}-{}=7", a, b, c, d);
   } else if (a+b-c+d)as i32 == 7i32 {
       println!("{}+{}-{}+{}=7", a, b, c, d);
   } else if (a+b-c-d)as i32 == 7i32 {
       println!("{}+{}-{}-{}=7", a, b, c, d);
   } else if (a-b+c+d)as i32 == 7i32 {
       println!("{}-{}+{}+{}=7", a, b, c, d);
   } else if (a-b+c-d)as i32 == 7i32 {
       println!("{}-{}+{}-{}=7", a, b, c, d);
   } else if (a-b-c+d)as i32 == 7i32 {
       println!("{}-{}-{}+{}=7", a, b, c, d);
   } else {
       println!("{}-{}-{}-{}=7", a, b, c, d);
   }
}


Measured memory_bytes: 4352
// 解き直し.
// http://agc005.contest.atcoder.jp/data/agc/005/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int io[202020], oi[202020];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N){
        scanf("%d", &io[i]);
        oi[io[i]] = i + 1;
    }
    
    // 2. l, r を 計算(※解説参照).
    LL ans = 0;
    set<int> s;
    s.insert(0);
    s.insert(N + 1);
    // ※ 解説上, N, N - 1, N - 2, ... の 順で, l, r を 求めていくと説明されているが, 
    // 上手く行かなかったので, 1, 2, ... の 順で, l, r を 求めていくように実装している.
    repx(i, 1, N + 1){
        // i の 出現位置.
        int at = oi[i];
        
        // 検索.
        set<int>::iterator it;
        it = s.lower_bound(at);
        int r = *it;
        int l = *(--it);
        // printf("at=%d l=%d r=%d\n", at, l, r);
        
        // 加算.
        ans += (LL)io[at - 1] * (LL)(at - l) * (LL)(r - at);
        
        // 登録.
        s.insert(at);
    }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 14576
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
    char a, b;
    cin>>a>>b;
    if(a==b){
        cout<<"H"<<endl;
    }
    else{
        cout<<"D"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

class UGrouping {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;

        auto a = make_v<int>(N, N);
        REP(i, N) REP(j, N) cin >> a[i][j];

        auto score = vector<int>(1 << (N + 4));
        for (int k = 0; k < 1 << N; k++) {
            int res = 0;
            for (int l = 0; l < N; l++) {
                if ((k & (1 << l)) == 0) continue;
                for (int r = l + 1; r < N; r++) {
                    if ((k & (1 << r)) == 0) continue;
                    res += a[l][r];
                }
            }
            score[k] = res;
        }

        auto dp = vector<int>(1 << (N + 4));
        for (int j = 0; j < 1 << N; j++) {
            int sub = ((1 << N) - 1) ^ j;
            for (int k = sub; k > 0; k--) {
                k &= sub;
                dp[j | k] = max(dp[j | k], dp[j] + score[k]);
            }
        }
        cout << dp[(1 << N) - 1] << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    UGrouping solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 16640
import sys

sys.setrecursionlimit(int(1e6))


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def get_sum(self, i):
        ret = 0
        while i > 0:
            ret += self.data[i]
            i -= (i & -i)
        return ret

    def add(self, i, w):
        if i == 0:
            return
        while i <= self.n:
            self.data[i] += w
            i += (i & -i)


def dfs(u, cnt):
    cnt += 1
    l[u] = cnt
    for c in tree[u]:
        cnt = dfs(c, cnt)
    cnt += 1
    r[u] = cnt
    return cnt


n = int(input())
l, r = [0] * n, [0] * n
tree = [set(map(int, input().split()[1:])) for _ in range(n)]

bit = BIT(dfs(0, 1))

q = int(input())
for _ in range(q):
    line = list(map(int, input().split()))
    if line[0]:
        print(bit.get_sum(r[line[1]] - 1))
    else:
        bit.add(l[line[1]], line[2])
        bit.add(r[line[1]], -line[2])



Measured memory_bytes: 143728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        char[] seq = f.readLine().toCharArray();
        int sum = 0;
        for (int i = 0; i < seq.length; i++) {
            sum += seq[i] - '0';
        }

        if (sum % 9 == 0) {
            out.println("Yes");
        } else {
            out.println("No");
        }

        out.close();
    }
}

Measured memory_bytes: 36956
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: 9412
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int K = stdIn.nextInt();

		System.out.println((K/2)*((K+1)/2));

	}

}


Measured memory_bytes: 35584
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define INF 2<<29

int main(){
  int a,b,t;
  scanf("%d %d %d",&a,&b,&t);
  printf("%d\n",(t/a)*b);
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int n;
vector<vector<int>> G;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    G.resize(n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < n; j++) {
            if (s[j] == '1') {
                G[i].push_back(j);
            }
        }
    }
    int ans = -1;
    for (int i = 0; i < n; i++) {
        vector<int> d(n, INF);
        d[i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &e : G[v]) {
                if (d[e] == INF) {
                    d[e] = d[v] + 1;
                    q.push(e);
                }
            }
        }
        int ma = 0;
        bool f = true;
        for (int j = 0; j < n; j++) {
            chmax(ma, d[j]);
            for (auto &e : G[j]) {
                if (d[e] != d[j] + 1 && d[e] != d[j] - 1) {
                    f = false;
                    break;
                }
            }
        }
        if (f) {
            chmax(ans, ma + 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
! 2019.11.16
!
      program answer
      implicit none
      integer :: N
      double precision,allocatable,dimension(:) :: x,y
      integer :: i,j
      double precision :: ans
      intrinsic dsqrt,dble
!
      read(*,*) N
      allocate(x(N),y(N)) 
!
      ans = 0.0d0
!
      do i=1,N
        read(*,*) x(i),y(i)
      end do
!
      do i=1,N-1
        do j=i+1,N
          ans = ans + dsqrt((x(i)-x(j))**2+(y(i)-y(j))**2)
        end do
      end do
!
      ans = ans * 2 / N
      write(*,*) ans
      end program answer


Measured memory_bytes: 256
import bisect
A,B,Q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]
for q in range(Q):
    x=int(input())
    i=bisect.bisect_right(S,x)
    j=bisect.bisect_right(T,x)
    d=INF
    for s in [S[i-1],S[i]]:
        for t in [T[j-1],T[j]]:
            d1=abs(s-x)+abs(s-t)
            d2=abs(t-x)+abs(s-t)
            d=min(d,d1,d2)
    print(d)

Measured memory_bytes: 17592
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<int> e[maxn];
int in[maxn], pi[maxn];
int main(){
  int n, m; cin >> n >> m;
  for(int i = 0; i < n - 1 + m; i++){
    int x, y; cin >> x >> y;
    in[y]++;
    e[x].push_back(y);
  }
  queue<int> q;
  for(int i = 1; i <= n; i++) if(in[i] == 0) q.push(i);
  while(!q.empty()){
    int u = q.front(); q.pop();
    for(int nxt : e[u]) if(--in[nxt] == 0) {
      pi[nxt] = u;
      q.push(nxt);
    }
  }
  for(int i = 1; i <= n; i++) cout << pi[i] << endl;
  return 0;
}

Measured memory_bytes: 7040
#include <iostream>
using namespace std;
int main(void) {
	int r, c, a[200][200] = {};
	cin >> r >> c;
	for (int b = 1; b <= r; b++) {
		for (int d = 1; d <= c; d++) {
			cin >> a[b][d];
			a[r + 1][d] += a[b][d];
			a[b][c + 1] += a[b][d];
		}
	}
	for (int b = 1; b <= r; b++) {
		a[r + 1][c + 1] += a[b][c + 1];
	}
	for (int b = 1; b <= r + 1; b++) {
		for (int d = 1; d <= c; d++) {
			cout << a[b][d] << " ";
		}
		cout << a[b][c + 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1324
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define INF2 100000000000
#define LLINF 1000000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
  int a;
  string b;
  cin >> a >> b;
  b[b.length() - 3] = '0';
  int d = stoi(b);
  // NNNN0II
  int k = d%100;
  d/=1000;
  d*=100;
  d += k;
  cout << (a*d)/100 << endl;
}


Measured memory_bytes: 3632
N, M = list(map(int, input().split()))
tenbodai = [H for H in list(map(int, input().split()))]
tenbodai_trail = [set() for i in range(len(tenbodai))]
 
for _ in range(M): #展望台と繋がる道のリストを作成
    trail = list(map(int, input().split()))
    tenbodai_trail[trail[0] - 1].add(trail[1] - 1)
    tenbodai_trail[trail[1] - 1].add(trail[0] - 1)
    
count = 0
for i in range(len(tenbodai)): #全探索
    flag = True
    for trail in tenbodai_trail[i]: # i:現在の展望台の番号, trail:繋がる展望台の番号
        if tenbodai[i] <= tenbodai[trail]:
            flag = False
            break
    if flag:
        count += 1
print(count)

Measured memory_bytes: 45948
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
 long long N;
 string str;
 cin >> N >>str;
 long long num[N+2];
 long long i;
 num[0]=0;
 for(i=1;i<N+1;i++){
   if (str[i-1]=='W'){
     num[i]=num[i-1]+1;
   }else{
     num[i]=num[i-1];
   }
 }
 long long ans=N;
 long long tmp;
 for (i=1;i<N+1;i++){
   tmp=num[i-1]+N-num[N]-i+num[i];
   if (tmp<ans){
     ans=tmp;
   }
 }
 cout << ans;
 return 0;
}

Measured memory_bytes: 2948
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 2e5 + 20;

int n, q;
int a[MAXN], b[MAXN], t[MAXN], r[MAXN], p[MAXN], x[MAXN], csum[MAXN] = {};
unordered_set<int> graph[MAXN];
int vis[MAXN] = {};

int tt;
void dfs(int i) {
	t[i] = tt;
	vis[i] = 1;
	for(auto x : graph[i]) {
		if(!vis[x]) {
			tt++;
			dfs(x);
		}
	}
	r[t[i]] = tt;
}

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

    cin >> n >> q;
    for(int i = 0; i < n - 1; i++) {
    	cin >> a[i] >> b[i];
    	graph[a[i]].insert(b[i]);
    	graph[b[i]].insert(a[i]);
    }
    for(int i = 0; i < q; i++) 
    	cin >> p[i] >> x[i];
    tt = 1;
    dfs(1);

    for(int i = 0; i < q; i++) {
    	csum[t[p[i]]] += x[i];
    	csum[r[t[p[i]]] + 1] -= x[i];
    }
    for(int i = 1; i <= n; i++) {
    	csum[i] += csum[i - 1];
    }
    for(int i = 1; i <= n; i++) {
    	cout << csum[t[i]] << endl;
    }


    return 0;
}











Measured memory_bytes: 47744
n, x = gets.chomp.split.map(&:to_i)
n.downto(0) do |i|
  (n-i).downto(0) do |j|
    if i * 10000 + j * 5000 + (n - i - j) * 1000 == x
      puts "#{i} #{j} #{n - i - j}"
      exit
    end
  end
end
puts "-1 -1 -1"

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

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

		while(sc.hasNext())
		{
			int n = sc.nextInt();
			if(n==0)
				return;
			boolean a[] = new boolean[n+1];
			Arrays.fill(a, true);
			a[0]=a[1]=false;

			for(int i=2;i*i<=n; i++)
			{
				if(!a[i]) //falseだったら
					continue;
				for(int j=i+i; j<=n; j+=i)
				{
					a[j] = false;
				}

			}
			int x=0;
			int y=0;
			boolean flag=false;
			for(int i =n; i>=0; i--)
			{
				if(a[i])
				{
					x =i;
				}
				else
					continue;

				for(int j=i-1; j>=0; j--)
				{
					if(a[j])
					{
						y=j;
						if(x-y==2)
						{
							System.out.println(y+" "+x);
							flag = true;
							break;
						}
					}
				}

				if(flag)
					break;
			}
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include<string>
#include<map>

using namespace std;
int main(void){
    long long N,Y;
    cin>>N>>Y;
    int M,S;
    M=Y/10000;
    int T;
    for(int i=0;i<=M;i++){
       int K;
       K=(Y-10000*i)/5000;
       for(int j=0;j<=K;j++){
           
           T=(Y-10000*i-5000*j)/1000;
           if(i+j+T==N){
               cout<<i<<' '<<j<<' '<<T<<endl;
               return 0;
           }
           T=-1;
       }
    }    
    if(T==-1) {
       cout<<-1<<' '<<-1<<' '<<-1<<endl; 
    }  
   
    
     
    
    
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] x = new long[n];
        long[] l = new long[n];
        long[][] xl = new long[n][2];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextLong();
            l[i] = sc.nextLong();
            xl[i][0] = x[i] - l[i];
            xl[i][1] = x[i] + l[i];
        }
        Arrays.sort(xl, Comparator.comparingLong(a -> a[1]));
        int cnt = 1;
        long prev = xl[0][1];
        for (int i = 1; i < n; i++) {
            if (prev > xl[i][0]) {
                continue;
            }
            cnt++;
            prev = xl[i][1];
        }
        System.out.println(cnt);
    }

}


Measured memory_bytes: 96472
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1<<30
const int mod = 1e9+7;

int main(){
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    vl bit(60,0);
    vl sum(n+1,0);
    rep(i,n){
        sum[i+1] = (sum[i]%mod + a[i]%mod)%mod;
        rep(j,60){
            if(a[i]<(1LL<<j)) break;
            if(a[i]&(1LL<<j)) bit[j]++;
        }
    }
    ll ans = 0;
    rep(i,n-1){
        vl bit2(60,0);
        rep(j,60){
            if(a[i]<(1LL<<j)) break;
            if(a[i]&(1LL<<j)){
                bit[j]--; bit2[j]++;
            }
        }
        ll tmp = sum[n]-sum[i+1];
        while(tmp<0) tmp += mod;
        ans += tmp;
        ans %= mod;
        rep(j,60){
            if(bit2[j]){
                ll t = n-i-1-bit[j]-bit[j];
                if(t>=0) ans += (((1LL<<j)%mod)*t)%mod;
                else{
                    ll x = (((1LL<<j)%mod)*(-t))%mod;
                    x %= mod;
                    ans -= x;
                    while(ans<0) ans += mod;
                }
                ans %= mod;
            }
        }
    }
    cout << ans%mod << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int n,m;
    cin>>n>>m;
    
    vector<int> x(n);
    map<int,int> mp;
    rep(i,n) {
        cin>>x[i];
        mp[x[i]]++;
    }
    
    vector<pair<int,int>> vec(m,make_pair(0,0)); //vec[i]->(mod mがiになるxの個数,その中の同じ整数のペアの個数)のpair
    rep(i,n){
        vec[x[i]%m].first++;
        if(mp[x[i]]>1){
            vec[x[i]%m].second+=mp[x[i]]/2;
            mp[x[i]]=0;
        }
    }
    
    //for(auto p:vec) cout<<p.first<<" "<<p.second<<endl;
    
    int ans=0;
    ans+=vec[0].first/2;
    if(m%2==0) ans+=vec[m/2].first/2;
    
    FOR(i,1,(m-1)/2){
        auto a=vec[i];
        auto b=vec[m-i];
        
        if(a>=b){
            ans+=b.first;
            ans+=min((a.first-b.first)/2,a.second);
        }
        else{
            ans+=a.first;
            ans+=min((b.first-a.first)/2,b.second);
        }
        
    }
    
    cout<<ans<<endl;
    
}




Measured memory_bytes: 6144
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int c = Integer.parseInt(scanner.next());

        long answer = IntStream.range(a, b + 1).filter(value -> (c % value == 0)).count();

        System.out.println(answer);
    }
}

Measured memory_bytes: 32412
s = input()
if s[0] != "A":
    print("WA")
    exit(0)

c_cnt = 0
for ch in s[2:-1]:
    if ch == "C":
        c_cnt += 1

if c_cnt != 1:
    print("WA")
    exit(0)

s = s[1:]
s = s.replace("C", "")
if s.lower() != s:
    print("WA")
    exit(0)

print("AC")


Measured memory_bytes: 3060
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let a = scan.read::<usize>();
    let b = scan.read::<usize>();
    let c = scan.read::<usize>();
    println!("{}", if a<b && a<c && c<b || b<a && b<c && c<a {"Yes"} else {"No"});
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
    //write code  here
    long X;
    cin >> X;

    long num = 100;
    long i;
    for (i=0; num < X; ++i) {
        num += (num/100);
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstdint>

int main()
{
  int n, k;
  std::cin >> n >> k;
  std::vector<uint64_t> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a.at(i);
  }
  std::vector<uint64_t> s;
  for (int first = 0; first < n; first++) {
    uint64_t sum = 0;
    for (int last = first; last < n; last++) {
      sum += a.at(last);
      s.push_back(sum);
    }
  }
  uint64_t result = 0;
  for (uint64_t filter = 1ULL << 62ULL; 1 <= filter; filter = filter >> 1) {
    int cnt = 0;
    for (auto x : s) {
      if (((result | filter) & x) == (result | filter)) {
        cnt++;
        if (k <= cnt) {
          result = result | filter;
          break;
        }
      }
    }
  }
  std::cout << result << '\n';
  return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
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(a>b){a=b; return true;} return false;}

const lint mod = 998244353;
const lint INF = mod*mod;
const int MAX = 100010;

int n, m, deg[MAX];
vector<int> G[MAX], u;
bool ok;

void dfs(int v, int pv, int start){
    if(pv>=0 && v==start){
        ok=true;
        return;
    }
    for(int nv: G[v])if(nv!=pv && (nv==start || deg[nv]<4)) dfs(nv, v, start);
}

int main(){
    scanf("%d%d", &n, &m);
    rep(i, n) deg[i]=0;
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
        ++deg[a]; ++deg[b];
    }
    bool flag=false;
    rep(i, n){
        if(deg[i]%2){
            printf("No\n");
            return 0;
        }
        if(deg[i]>=4){
            u.push_back(i);
            if(deg[i]>=6) flag=true;
        }
    }
    if(flag || u.size()>=3){
        printf("Yes\n");
        return 0;
    }
    if(u.size()<=1){
        printf("No\n");
        return 0;
    }
    ok=false;
    for(int v: u) dfs(v, -1, v);
    printf("%s\n", ok ? "Yes" : "No");
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[4<<17],i;
int main(){
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	make_heap(a,a+n);
	for(i=0;i<n;i++){
		cout<<" "<<a[i];
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 5024
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

S, W = MII_split()

print('unsafe' if W >= S else 'safe')

Measured memory_bytes: 9228
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datW, datH, datN) = readLine.split(" ").map(_.toInt)
    val data = for(i <- 1 to datN) yield (readLine.split(" ").map(_.toInt) match {case Array(a, b, c) => (a, b, c)})
    val rule1 = data.filter(_._3 == 1); val rule1OfX = if (rule1.isEmpty) 0    else rule1.map(_._1).max
    val rule2 = data.filter(_._3 == 2); val rule2OfX = if (rule2.isEmpty) datW else rule2.map(_._1).min
    val rule3 = data.filter(_._3 == 3); val rule3OfY = if (rule3.isEmpty) 0    else rule3.map(_._2).max
    val rule4 = data.filter(_._3 == 4); val rule4OfY = if (rule4.isEmpty) datH else rule4.map(_._2).min
    val ans =
      if((rule2OfX > rule1OfX) && (rule4OfY > rule3OfY)) (rule2OfX - rule1OfX) * (rule4OfY - rule3OfY)
      else 0

    println(ans)
  }
}


Measured memory_bytes: 25508
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;

bool cmp(P a, P b)
{
  return a.second < b.second;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<P> vc(M);
  for (int i = 0; i < M; i++)
    cin >> vc[i].first >> vc[i].second;

  int ans = 0;
  int cur = 0;
  sort(vc.begin(), vc.end(), cmp);
  for (int i = 0; i < M; i++)
  {
    if (cur <= vc[i].first)
    {
      cur = vc[i].second;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024