akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    int Sum=0;
    Sum=ceil((n-1.0)/(k-1.0));
    cout<<Sum<<endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n) cin >> a[i+1];
    vi b(n+1);
    for(int i = n; i >= 1; i--) {
        int sum = 0;
        for(int j = i+i; j <= n; j+=i) {
            sum ^= b[j];
        }
        sum ^= a[i];
        b[i] = sum;
    }
    vi ans;
    rep(i, n+1) if(b[i]) ans.push_back(i);
    cout << ans.size() << endl;
    for(auto x : ans) cout << x << endl;

    return 0;
}


Measured memory_bytes: 5432
n = int(input())
s = list(input())

r = s.count('R')
g = s.count('G')
b = s.count('B')

all_comb = r*g*b

reduce_cnt = 0
for i in range(n):
    for k in range(i+2,n):
        if (i+k)%2 == 1: continue
        j = (i+k)//2
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]: reduce_cnt += 1

print(all_comb-reduce_cnt)

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

int main() {
    string s;
    cin >> s;
    int a = 0, b = s.size() - 1;
    while(s[a] != 'A') a++;
    while(s[b] != 'Z') b--;
    cout << b - a + 1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int x=0;
  char s[11];
  scanf("%s",s);
  
  while(s[x]!=NULL){
    x++;
  }
  
  int p,i;
  p=1;
  i=0;
  if(x%2==1){
    printf("No");
  }else{
    for(i=0;i<=x-1;i++){
      if(i%2==0&&s[i]!='h'){
        p=0;
      }
      if(i%2==1&&s[i]!='i'){
        p=0;
      }
    }
    if(p==0){
      printf("No");
    }else{
      printf("Yes");
    }
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

int main() {
  int m, n, sum = 0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(ALL(a), greater<int>());
  if (a[m - 1] * 4 * m < sum)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
graph = N.times.map{ [] }
$<.each_with_index{|s, i|
  from, to = s.split.map(&:to_i).map &:pred
  graph[from] << [i, to]
  graph[to] << [i, from]
}


start = graph.index(graph.max_by &:size)
ans = [0] * (N - 1)

st = [start]
while !st.empty?
  from = st.pop
  color = 0
  used_colors = graph[from].map{|idx, to| ans[idx] }.select{|color| color != 0 }
  graph[from].each{|idx, to|
    next if ans[idx] != 0
    color += 1
    color += 1 while used_colors.include?(color)
    ans[idx] = color
    st << to
  }
end

p ans.max
p *ans


Measured memory_bytes: 30716
#include <stdio.h>
#define MAX 101
#define N 1048576
#define W -1
#define G 0
#define B 1


int C[MAX][MAX];

void search(int n,int *d){
  int u,v,i,j,m,a[MAX],b[MAX];

  for(i=0;i<n;i++){
    b[i]=W;
    d[i]=N;
  }

  d[0]=0;
  b[0]=G;

  while(1){
    m=N;
    u=-1;

    for(i=0;i<n;i++){
      if(m>d[i]&&b[i]!=B){
	u=i;
	m=d[i];
      }
    }

    if(u==-1) break;

    b[u]=B;

    for(v=0;v<n;v++){
      if(b[v]!=B&&C[u][v]!=N){
	  if(d[v]>C[u][v]+d[u]){
	    d[v]=C[u][v]+d[u];
	    b[v]=G;
	  }
	}
      }
    }

    return;

  }

  int main(void){
    int i,j,n,k,s,x,d[MAX];

    scanf("%d",&n);
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	C[i][j]=N;
      }
    }

    for(i=0;i<n;i++){
      scanf("%d%d",&x,&k);
      for(j=0;j<k;j++){
	scanf("%d",&s);
	scanf("%d",&C[i][s]);
      }
    }

    search(n,d);

    for(j=0;j<n;j++){

      printf("%d ",j);

      if(d[j]==N)
	printf("%d",-1);

      else printf("%d\n",d[j]);

    }
    return 0;
  }



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

using namespace std;

int main(void){
  int n,m;
  
  while(cin >> n >> m,n|m){
    vector<int>v(n+m);
    for(int i=0;i<n+m;i++)cin >> v[i];
    sort(v.begin(),v.end());
    int ans=v[0];
    for(int i=0;i<v.size()-1;i++)ans=max(ans,v[i+1]-v[i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <iostream>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if (a%b == 0) return b;
    else gcd(b, a%b);
}

ll N;
ll A[100001];

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

    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    ll ans = 1000000000;
    for (int i = 1; i < N; i++) ans = min(ans, gcd(A[i-1], A[i]));
    
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[][] array = new int[num][4];
        int[][] tenant = new int[12][10];
        
        for(int i = 0; i < num; i++){
            for(int j = 0; j < 4; j++){
                array[i][j] = sc.nextInt();
            }
            int floor = (array[i][0] - 1) * 3 + array[i][1] - 1;
            int room = array[i][2] - 1;
            tenant[floor][room] += array[i][3];
            if(tenant[floor][room] < 0){
                tenant[floor][room] = 0;
            }
            
        }
        
        for(int i = 0; i < 12; i++){
            if(i != 0 && i % 3 == 0){
                System.out.println("####################");
            }
            for(int j = 0; j < 10; j++){
                System.out.print(" " + tenant[i][j]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 30000
#include <bits/stdc++.h>
using namespace std;
long long dp[55][5100];
int main(){
    int n,a;
    cin >> n >> a;
    int x[n];
    for(int i = 0; i < n; i++){
        cin >> x[i];
        x[i]-=a;
    } 
    memset(dp, 0, sizeof(dp));
    dp[0][2500] = 1;  
    for(int i=1;i<=n;i++){
        for(int j=0;j<=5000;j++){
          dp[i][j] = dp[i-1][j];
          if(0<=j-x[i-1]&&j-x[i-1]<=5000) dp[i][j]+=dp[i-1][j-x[i-1]];
        }
    }
    cout << dp[n][2500]-1 << endl;
}


Measured memory_bytes: 2432
#include <stdio.h>

int main(void)
{
    int D;
    
    scanf("%d",&D);
    
    switch(D)
    {
        case 25:
            printf("Christmas\n");
            break;
            
        case 24:
            printf("Christmas Eve\n");
            break;
            
        case 23:
            printf("Christmas Eve Eve\n");
            break;
            
        case 22:
            printf("Christmas Eve Eve Eve\n");
            break;
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  char x[1000];
  int sum,i,j;

  while(1){
    sum=0;

    //配列xに文字として１文字ずつ代入していく
    for(i=0;;i++){
      scanf("%c",&x[i]);
      if(x[i]=='\n'){
	break;
      }
    }

    //文字を数値に変換してsumに足していく
    for(j=0;j<i;j++){
      sum+=x[j]-'0';
    }

    if(sum==0){
      break;
    }

    //表示
    printf("%d\n",sum);


  }

  return 0;

}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    int a, b;
    cin >> a >> b;

    char ca, cb;
    ca = (char)('0' + a);
    cb = (char)('0' + b);

    string caa = "";
    string cbb = "";
    for (size_t i = 0; i < a; i++)
    {
        cbb += cb;
    }
    for (size_t i = 0; i < b; i++)
    {
        caa += ca;
    }

    if (caa < cbb)
    {
        cout << caa << endl;
    }
    else
    {
        cout << cbb << endl;
    }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	vector<long long int>v(M);
	for (auto &i : v)cin >> i;
	if (accumulate(v.begin(), v.end(), 0LL) < N)cout << "No\n";
	else cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <memory.h>
int a[15][15];
int i,j;
void f(int n){
  if(i>=n)
    i=0;
  if(j<0)
    j=n-1;
  if(j>=n)
    j=0;
  if(a[i][j]){
    i++;
    j--;
  }
}
int main(void){
  int n,c;
  while(scanf("%d",&n),n){
    c=1;
    memset(a,0,sizeof(a));
    i=n/2+1;
    j=n/2;
    while(c<=n*n){
      while(!(0<=i&&i<=n-1&&0<=j&&j<=n-1&&a[i][j]==0)){
	f(n);
      }
      a[i][j]=c;
      c++;
      i++;
      j++;
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	printf("%4d",a[i][j]);
      }
      putchar('\n');
    }
  }
  return 0;
}

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

int main(){
  
  int a[3];
  
  cin >> a[1] >> a[2] >> a[3];
  
  int total = a[1] + a[2] + a[3];
  
  if(total < 22)
    cout << "win" << endl;
  else
    cout << "bust" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define int long long
using namespace std;

typedef int Weight;
const int INF = (int)1e18;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // ネットワークフロー時の逆辺
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

Weight blockingFlow(Graph &g, vector<int> &l, int v, int t, Weight f){
    if(v == t) return f;
    EACH(i, g[v]){
        if(i -> weight > 0 && l[v] < l[i -> to]){
            Weight d = blockingFlow(g, l, i -> to, t, min(f, i -> weight));
            if(d > 0){
                i -> weight -= d;
                g[i -> to][i -> rev].weight += d;
                return d;
            }
        }
    }
    return 0;
}
Weight dinitz(Graph &g, int s, int t){
    int n = g.size();
    Weight flow = 0;
    vector<int> l(n, -1);
    for(;;){
        queue<int> Q;
        fill(ALL(l), -1);
        l[s] = 0;
        Q.push(s);
        while(!Q.empty()){
            int v = Q.front(); Q.pop();
            EACH(i, g[v])if(i -> weight > 0 && l[i -> to] < 0){
                l[i -> to] = l[v] + 1;
                Q.push(i -> to);
            }
        }
        if(l[t] < 0) return flow;
        Weight f;
        while((f = blockingFlow(g, l, s, t, INF)) > 0) flow += f;
    }
}

signed main(){
	int N;
	cin >> N;
	vector<int> a(N+1);
	Graph g(N + 2);
	int sum = 0;
	for(int i = 1; i <= N; ++i) {
		cin >> a[i];
		if(a[i] < 0) {
			addFlowEdge(g, 0, i, -a[i]);
		} else if (a[i] > 0) {
			sum += a[i];
			addFlowEdge(g, i, N+1, a[i]);
		}
	}
	for(int i = 1; i <= N; ++i) {
		for(int j = i * 2; j <= N; j+=i) {
			addFlowEdge(g, i, j, INF);
		}
	}
	int res = sum - dinitz(g, 0, N + 1);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#-------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------

from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[j - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] =  j
    return pi

def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else '0' * (length - len(y)) + y


def solve(N, A):
    ans = 0
    for i in range(1, N):
        if A[i] <= A[i - 1]:
            ans += abs(A[i - 1] - A[i])
            A[i] += abs(A[i - 1] - A[i])
    #print(A)
    return ans


N = int(input())
A = list(map(int, input().split()))
print(solve(N, A))


Measured memory_bytes: 95544
#include <cstdio>
#include <cstring>
typedef int ___;
#define int long long
const int N = 2e6+100;
char str[N];
int len;

int replace()
{
	int ans = 0;
	int actr = 0;
	for (int i=0; i+1 < len; ++i) {
		if (str[i] == 'A') ++actr;
		else if (str[i] == 'B' && str[i+1]=='C'){
			++i;
			ans += actr;
		} else actr = 0;
	}
	return ans;
}

___ main()
{
	while (scanf("%s", str) != EOF) {
		len = strlen(str);
		int ans = 0, tmp;
		/*(
		do {
			tmp = replace(str);
			ans += tmp;
		} while (tmp);
		*/
	 ans = replace();
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, M, X;
	cin >> N >> M >> X;
	vector<int> memo(N + 1, 0);
	REP(i, M) {
		int A;
		cin >> A;
		memo[A]++;
	}
	int cost0 = 0, costN = 0;
	REP(i, X) cost0 += memo[i];
	FOR(i, X + 1, N + 1) costN += memo[i];
	cout << min(cost0, costN) << "\n";

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def max_heapify(heap, i)
  left = 2 * i + 1
  right = 2 * i + 2
  largest = i
  heap_size = heap.size - 1

  if left <= heap_size && heap[i] < heap[left]
    largest = left
  else
    largest = i
  end

  if right <= heap_size && heap[largest] < heap[right]
    largest = right
  end

  unless largest == i
    heap[i], heap[largest] = heap[largest], heap[i]
    max_heapify(heap, largest)
  end
end

def build_max_heap(heap)
  ((heap.size - 1) / 2).downto(0) do |i|
    max_heapify(heap, i)
  end
end

n = gets.to_i
keys = gets.split.map(&:to_i)
build_max_heap(keys)
print " "
puts keys.join(" ")

Measured memory_bytes: 61372
#include <stdio.h>
#define NUM 10
  
void drop(int puz[][5], int i, int j){
  
int k;
  
for(k=i; k>0; k--)
puz[k][j]=puz[k-1][j];
  
puz[0][j]=0;
  
}
  
  
  
int main(void){
  
  
  
  
int score=0;
int tscore=0;
int count=0;
int h, i, j;
int puz[NUM][5]={0};

replay:
  
while(1){
  
  
  
scanf("%d", &h);
  
if(h==0)
break;
  
  
  
  
  
for(i=0; i<h; i++){
 for(j=0; j<5; j++){
scanf("%d", &puz[i][j]);
  }
}
  
  
 while(1){
  
  
for(i=0; i<h; i++){
  
 for(j=0; j<4; j++){
  
 if(puz[i][j]==puz[i][j+1])
  count++;
 else if(count==2){
  score=score+(3*puz[i][j]);
  puz[i][j]=0;
  puz[i][j-1]=0;
  puz[i][j-2]=0;
  count=0;}
 else if(count==3){
  score=score+(4*puz[i][j]);
  puz[i][j]=0;
  puz[i][j-1]=0;
  puz[i][j-2]=0;
  puz[i][j-3]=0;
  count=0;}
 else
  count=0;
 
  
   }
  
 if(count==2){
  score=score+(3*puz[i][j]);
  puz[i][j]=0;
  puz[i][j-1]=0;
  puz[i][j-2]=0;
  count=0;}
 else if(count==3){
  score=score+(4*puz[i][j]);
  puz[i][j]=0;
  puz[i][j-1]=0;
  puz[i][j-2]=0;
  puz[i][j-3]=0;
  count=0;}
 else if(count==4){
  score=score+(5*puz[i][j]);
  puz[i][j]=0;
  puz[i][j-1]=0;
  puz[i][j-2]=0;
  puz[i][j-3]=0;
  puz[i][j-4]=0;
  count=0;}
  else
  count=0;
  
  
 }

 
   
  
for(i=0; i<h; i++){
 for(j=0; j<5; j++){
  
 if(puz[i][j]==0)
 drop(puz, i, j);
   
 }
}
 
  
if(score==0){
 printf("%d\n", tscore);
 tscore=0;
 goto replay;
}
  
  
tscore=tscore+score;
score=0;

 }
  
 
 }

 return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}


int main() {
    int H,W,N; cin >> H >> W >> N;
    int y,x; cin >> y >> x;
    string S,T; cin >> S >> T;

    int p,q;
    p = x;

    for(int i = 0; i < N; ++i){
        if(S[i]=='R') p++;
        if(W<p) {
            cout << "NO" << endl;
            return 0;
        }
        q = (W%2==0?W/2+1:W/2+2);
        if(T[i]=='L'&& q<=p) p--;
    }

    p = x;
    for(int i = 0; i < N; ++i){
        if(S[i]=='L') p--;
        if(p<1) {
            cout << "NO" << endl;
            return 0;
        }
        q = (W%2==0?W/2:W/2);
        if(T[i]=='R'&&p <= q) p++;
    }

    p = y;
    for(int i = 0; i < N; ++i){
        if(S[i]=='D') p++;
        if(H<p) {
            cout << "NO" << endl;
            return 0;
        }
        q = (H%2==0?H/2+1:H/2+2);
        if(T[i]=='U'&&q<=p) p--;
    }
    p = y;
    for(int i = 0; i < N; ++i){
        if(S[i]=='U') p--;
        if(p<1) {
            cout << "NO" << endl;
            return 0;
        }
        q = (H%2==0?H/2:H/2);
        if(T[i]=='D'&&p <= q) p++;
    }

    cout << "YES" << endl;

  
	return 0;
}


Measured memory_bytes: 776
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type section struct {
	start, end, maxspeed int
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	L := make([]section, N+2)

	for i := 1; i <= N; i++ {
		L[i].start = L[i-1].end
		L[i].end = L[i-1].end + scanInt()*2
	}
	T := L[N].end
	L[N+1].start, L[N+1].end = T, T

	for i := 1; i <= N; i++ {
		L[i].maxspeed = scanInt()
	}

	v := make([]float64, T+1)
	for t := 0; t <= T; t++ {
		nowSpeed := 10000.0
		for _, l := range L {
			var tmpSpeed float64
			if t < l.start {
				tmpSpeed = float64(l.maxspeed) + float64(l.start-t)/2
			} else if l.end < t {
				tmpSpeed = float64(l.maxspeed) + float64(t-l.end)/2
			} else {
				tmpSpeed = float64(l.maxspeed)
			}
			nowSpeed = math.Min(nowSpeed, tmpSpeed)
		}
		v[t] = nowSpeed
	}

	ans := 0.0
	for t := 1; t <= T; t++ {
		ans += (v[t] + v[t-1]) / 4
	}

	fmt.Println(ans)
}


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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

int main() {
  int2(sx,sy);
  int2(tx,ty);
  int x=tx-sx;
  int y=ty-sy;
  string ret="";
  //ret.reserve(100);

  //if(tx-sx<2 || ty-sy<2){
    repi(y){
      ret+="U";
    }
    repi(x){
      ret+="R";
    }
    repi(y){
      ret+="D";
    }
    repi(x){
      ret+="L";
    }

    ret+="L";
    repi(y+1){
      ret+="U";
    }
    repi(x+1){
      ret+="R";
    }
    ret+="D";

    ret+="R";
    repi(y+1){
      ret+="D";
    }
    repi(x+1){
      ret+="L";
    }
    ret+="U";
    prln(ret);
    return 0;
    //}
    /*
  repi(y+1){
    ret+="U";
  }
  repi(x){
    ret+="R";
  }
  repi(y+2){
    ret+="D";
  }
  repi(x){
    ret+="L";
  }
  ret+="U";
  
  ret+="R";
  repi(y){
    ret+="U";
  }
  repi(x-1){
    ret+="R";
  }
  
  ret+="R";
  repi(y+2){
    ret+="D";
  }
  repi(x+2){
    ret+="L";
  }
  ret+="UUR";
  prln(ret);
  return 0;*/
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (a % 2)
            continue;
        if (a % 3 && a % 5)
        {
            cout << "DENIED\n";
            return 0;
        }
    }
    cout << "APPROVED\n";
}

Measured memory_bytes: 764
# coding: utf-8
# Your code here!

N=int(input())
A = list(map(int,input().split()))

a=sorted(A)
#print(a)
d=a[N//2]
c=a[N//2 -1]

for i in A:
    if i >= d:
        print(str(c))
    else:
        print(str(d))


Measured memory_bytes: 26016
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

vector<pair<int,int>> e[100005];
vector<int> node[100005];
int color[100005];

int main(){
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a>> b;
        a--;b--;
        node[a].push_back(i);
        node[b].push_back(i);
        e[i].push_back(mp(a,b));
    }
    int m=0;
    rep(i,n){
        int l=node[i].size();
        cerr<<'l'<<l<<endl;
        int c=1;
        set<int> ss;
        rep(j,l){
            int r=node[i][j];
            if(color[r]){
                ss.insert(color[r]);
            }
        }
        rep(j,l){
            int r=node[i][j];
            if(color[r]==0){
                while(ss.find(c)!=ss.end()){
                    c++;
                }
                color[r]=c;
                ss.insert(color[r]);
            }
        }
        m=max(m,c);
    }
    cout<<m<<endl;
    rep(i,n-1){
        cout<<color[i]<<endl;
    }
    return 0;
}

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

int main()
{
    char ch[20];
    int i,price,count1=0;
    scanf("%s", ch);

    for(i = 0;i < 3;i++){
        if(ch[i]=='o')
            count1++;
    }
    price = 700 + 100*count1;
    printf("%d\n", price);


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int A,B,C;
    cin>>A>>B>>C;
    int min=A,max=A;
    int P[3]={A,B,C};
    for (int i=0;i<3;i++){
        if(P[i]<min)
            min=P[i];
        if(P[i]>max){
            max=P[i];
        }
    }
    cout<<max-min<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
#if !defined(ONLINE_JUDGE)
#include "debugging.h"
#endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 55;
int const M = 105;
int const inf = 2e16;

int dp[N][N*M];

vector<pair<int, pii> > adj[N];
int c[N] , d[N];

void solve(){  
    int i,j;
    int n,m,s;
    cin>>n>>m>>s;
    for(i=0;i<m;i++){
        int u,v,a,b;
        cin >> u >> v >> a>>b;
        adj[u].pb({v,{a,b}});
        adj[v].pb({u,{a,b}});
    }
    for(i=1;i<=n;i++){
        cin>>c[i]>>d[i];
    }

    for(i=0;i<=n;i++){
        for(j=0;j<N*M;j++){
            dp[i][j] = inf;
        }
    }

    s = min(s , N*M - 1);

    dp[1][s] = 0;

    priority_queue<pair<int, pii> > pq;

    pq.push({0 , {1,s}});

    while(!pq.empty()){
        int x,y;
        x = pq.top().second.first;
        y = pq.top().second.second;

        pq.pop();

        for(auto pp:adj[x]){
            int to = pp.first;
            int co = pp.second.first;
            int ti = pp.second.second;

            if(y >= co){
                if(dp[to][y-co] > dp[x][y] + ti){
                    dp[to][y-co] = dp[x][y] + ti;
                    pq.push({-1*dp[to][y-co] , {to , y-co}});
                }
            }
        }

        if(y + c[x] < N*M){
            if(dp[x][y+c[x]] > dp[x][y] + d[x]){
                dp[x][y+c[x]] = dp[x][y] + d[x];
                pq.push({-1*dp[x][y+c[x]] , {x,y+c[x]}});
            }
        }
    }

    int ans = inf;

    for(i=2;i<=n;i++){
        ans = inf;
        for(j=0;j<N*M;j++){
            ans = min(ans, dp[i][j]);
        }
        cout<<ans<<endl;
    }
}           

int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*

*/

Measured memory_bytes: 11628
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

bool check(int *p, int n)
{
    REP(i, n-1) if (p[i] > p[i+1]) return false;
    return true;
}

int main()
{
    int N; cin >> N;
    int P[N]; REP(i, N) cin >> P[i];

    bool ret = check(P, N);

    REP(i, N-1)
    {
        FOR(j, i+1, N)
        {
            swap(P[i], P[j]);
            ret |= check(P, N);
            swap(P[i], P[j]);
        }
    }

    cout << (ret ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

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

	// SUN, MON, TUE, WED, THU, FRI, or SAT.


	 if(s == "SAT"){
		cout <<"1"<<endl;
	}
	else if(s == "FRI"){
		cout <<"2"<<endl;
	}
	else if(s == "THU"){
		cout <<"3"<<endl;
	}
	else if(s == "WED"){
		cout <<"4"<<endl;
	}
	else if(s == "TUE"){
		cout <<"5"<<endl;
	}
	else if(s == "MON"){
		cout <<"6"<<endl;
	}
	else if(s == "SUN"){
		cout <<"7"<<endl;
	}

  return 0;
}


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

ll N;
vector<ll> A;

int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];

    map<ll, ll> mp;
    rep(i, N) {
        mp[A[i]]++;
    }

    string ans = "YES";
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        if (iter->second > 1) {
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int n;
   cin >> n;
   
   cout << n*n*n << endl;
   
   
   return 0;
}

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

public class Main {
	//よく使う定数
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int N = fs.nextInt(), K = fs.nextInt();
		int A[] = fs.nextIntArray(N);
		
		long sum = 0;
		Set<Long> candidates = new HashSet<>();
		for(int i=0;i<N;i++) sum += A[i];
		for(long i=1;i*i<=sum;i++) {
			if(sum%i==0) {
				candidates.add(i);
				candidates.add(sum/i);
			}
		}
		
		long ans = 1;
		//各候補値について、何回で全てをXの倍数にできるか
		for(long x :candidates) {
			long t[] = new long[N];
			for(int i=0;i<N;i++)t[i] = A[i]%x;
			Arrays.sort(t);
			long subSum = 0;
			for(int i=0;i<N;i++)subSum += t[i];
			long r = subSum/x; //右からいくつをxにするか。（左からは0にする）
			long res = 0;
			for(int i=0;i<r;i++) {
				res += (x - t[N-1-i]);
			}
			if(res <= K) ans = Math.max(ans, x);
		}
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

int n, pos[60];
ll p[60];
ll a[100005], b[100005];
ll sum = 0, occ = 0, ans = 0;
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%lld", a + i), sum ^= a[i], occ |= a[i];

    int m = 0;
    for (int i = 59; i >= 0; --i) {
        if ((~occ >> i) & 1)
            continue;
        else if ((sum >> i) & 1) {
            ans |= 1LL << i;
            continue;
        }

        pos[m] = i;
        for (int j = 0; j < n; ++j)
            if ((a[j] >> i) & 1) b[j] |= 1LL << m;
        ++m;
    }
    memset(p, -1, sizeof p);
    for (int i = 0; i < n; ++i) {
        for (int k = 0; k < m; ++k) {
            if ((~b[i] >> k) & 1) continue;
            if (p[k] == -1) {
                p[k] = b[i];
                break;
            }
            b[i] ^= p[k];
        }
    }
    ll cur = 0;
    for (int i = 0; i < m; ++i) {
        if (((~cur >> i) & 1) && p[i] != -1) cur ^= p[i];
        if ((cur >> i) & 1) ans += 1LL << (pos[i] + 1);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1920
#include <iostream>
#include <climits>
using namespace std;
int s[5010];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(!i)s[i] = a;
      else{
	s[i] = max(a, a + s[i-1]);
      }
      ans = max(ans, s[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
    int A,B;
    cin >> A >> B;
    if(A > 8 || B > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if(A1+A2+A3>=22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    return 0;
}





Measured memory_bytes: 3132
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int H,W;
char S[22][22];

int DFS(int x, int y, int max){

    return 0;
}


int main(void) {
    int R; cin>>R;

    if(R<1200){
        cout<<"ABC"<<endl;
    }else if(R<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

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

int main() {
  int N;
  while (1) {
    cin >> N;
    if (N == 0) {
      break;
    }
    int ans = 0;
    bool prev = false;
    pair<bool, bool> pos = mp(false, false);
    for (int i = 0; i < N; i++) {
      string act;
      cin >> act;

      if (act[0] == 'l') {
        if (act[1] == 'u') {
          pos.first = true;
        } else {
          pos.first = false;
        }
      } else {
        if (act[1] == 'u') {
          pos.second = true;
        } else {
          pos.second = false;
        }
      }

      if (prev && pos == mp(false, false)) {
        ans++;
        prev = false;
      } else if (!prev && pos == mp(true, true)) {
        ans++;
        prev = true;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<int> A(N);
	map<int, int> Map;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		Map[A[i]]++;
	}
	unsigned long long int longSide = 0;
	unsigned long long int shortSide = 0;
	bool isLongOK = false;
	map<int, int>::reverse_iterator rit = Map.rbegin();
	while (rit != Map.rend())
	{
		if (rit->second >= 2)
		{
			if (isLongOK)
			{
				shortSide = rit->first;
				break;
			}
			else
			{
				longSide = rit->first;
				if (rit->second >= 4)
				{
					shortSide = rit->first;
					break;
				}
				isLongOK = true;
			}
		}
		++rit;
	}
	cout << longSide * shortSide << endl;
}

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

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

int main(){
	
	int w,n;
	int a,b;
	char c;
	int temp;
	int x[31]={};
	
	cin >> w >> n ;
	
	for( int i=1 ; i<=w ; i++ ) x[i]=i;
	
	for( int i=0 ; i<n ; i++ ){
		cin >> a >> c >> b ;
		
		temp=x[a];
		x[a]=x[b];
		x[b]=temp;
	}
	
	for( int i=1 ; i<=w ; i++ ) cout << x[i] << endl ;
	
return 0;
}

Measured memory_bytes: 1160
S = input()
T = input()
s = len(S)
t = len(T)
C = 100000
for i in range(t):
    for j in range(i, s - t + 1 + i):
        if S[j] == T[i]:
            c = i
            for k in range(1, t - i):
                if S[j + k] != T[i + k]:
                    c += 1
            C = min(C, c)
if C == 100000:
    C = t
print(C)

Measured memory_bytes: 67744
n = int(input())
c = input()
col = [0,0]
ans = 0
for l in c:
  if l=='R':
    col[0] += 1
  else:
    col[1] += 1
ans = min(col)
cnt = 1
new_c = 'R'*col[0]+'W'*col[1]
for a,b in zip(c,new_c):
  if a!=b:
    cnt += 1
print(min(cnt//2,ans))

Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int v = 100005,e;
int c = 0;
vector<vector<int>> graph(v,vector<int>());
vector<bool> seen(v,false);
vector<int> ord(v);
vector<int> low(v);
vector<bool> isart(v,false);

void dfs(int i,int par=-1){
    seen[i] = true;
    ord[i] = low[i] = c++;
    int count = 0;

    for(int j:graph[i]){
        if(!seen[j]){
            dfs(j,i);
            ++ count;
            low[i] = min(low[i],low[j]);
            if(par != -1 && ord[i] <= low[j]) isart[i] = true;
        }else if(j!=par){
            low[i] = min(low[i],ord[j]);
        }
    }

    if(par==-1 && count>1) isart[i] = true;
    return;
}

int main(){
    cin >> v >> e;
    rep(i,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
        graph[t].push_back(s);
    }
    dfs(0);
    rep(i,v){
        if(isart[i]) cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 7588
nums = list(map(int, input().split()))

odd = 0
even = 0

for n in nums:
    if n % 2 == 0:
        even += 1
    else:
        odd += 1

ans = 0

if odd != 3 and even != 3:
    for i in range(3):
        if odd > even and nums[i] % 2 == 1:
            nums[i] += 1
        elif even > odd and nums[i] % 2 == 0:
            nums[i] += 1
    ans += 1

m = max(nums)
for n in nums:
    ans += (m - n) // 2

print(ans)


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

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

using namespace std;

long long A[2000];

long long absolute(long long x) {
  if (x < 0) {
    return -x;
  }
  return x;
}

long long dp[2000][2001];

int main() {
  int N;
  cin >> N;
  REP(i, N) cin >> A[i];

  vector<pair<long long, int>> v;
  REP(i, N) v.push_back({-A[i], i});
  sort(v.begin(), v.end());

  dp[0][0] = -v[0].first * (N - 1 - v[0].second);
  dp[0][1] = -v[0].first * v[0].second;
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j <= i; ++j) {
      // right
      dp[i][j] = max(dp[i][j], dp[i - 1][j] + -v[i].first * (N - 1 - (i - j) - v[i].second));
      // left
      dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + -v[i].first * absolute(v[i].second - j));
    }
  }
  long long ans = 0;
  REP(i, N + 1) if (ans < dp[N - 1][i]) ans = dp[N - 1][i];
  cout << ans << endl;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int N;cin>>N;
  int tmp = 0;
  for (auto c:to_string(N)) tmp+=c-'0';
  (N%tmp==0) ? OUT("Yes") : OUT("No");

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////

//あらかじめソートすることでc1>=c2>=,,,,>=cNとしてよい
//それらの辺とその端点からなるTの部分グラフをUとするUは森になるのでk+1個以上の頂点を持つ
//したがってk本の辺に書き込まれる整数のうち最小のものはck+1以下になる。
//この考察により各辺に書き込まれる整数をx1,,,xN-1するとxi<=ci+1となることがわかる
//したがってスコアは常にc2+,,,cN以下
//またスコアはc2+,,,,+cNとなるように構成できる
//Tの辺を選んで両端にc1,c2をそれぞれ書き込む
//k=2,,,,N-1に対して次の操作を繰り返す
//e1,,ekとその端点からなるTの部分グラフが連結になるようにTの辺ekを選ぶことができる

int N;
vector<vector<int>>V;
vector<int>c;
vector<pii>key;
int ans[10010];
bool visited[10010];
int cnt = 0;
void dfs(int a) {
	if (visited[a])return;
	ans[a] = c[cnt];
	cnt++;
	visited[a] = true;
	for (int x : V[a]) {
		dfs(x);
	}
}
int main() {
	cin >> N;
	V.resize(N);
	int sum = 0;
	REP(i, N - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	key.resize(N);
	for (int i = 0; i < N; ++i) {
		key[i] = { V[i].size(),i };
	}
	sort(key.begin(), key.end(), greater<pii>());
	c.resize(N);
	REP(i, N) {
		cin >> c[i];
		sum += c[i];
		visited[i] = false;
	}
	sort(c.begin(), c.end(),greater<int>());
	sum -= c[0];
	cout << sum << endl;
	dfs(0);
	REP(i, N)cout << ans[i] << " ";
	return 0;
}


Measured memory_bytes: 1280