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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define isIn(A,B) (0<=A&&A<H&&0<=B&&B<W)

int H,W;
char S[500][500];
bool mk[500][500];
queue<piii> nxt;
ll ct[255];
int gotx[] = {1, 0, -1, 0};
int goty[] = {0, 1, 0, -1};
ll i,j, k,ans;
int main(){
    scanf("%d%d", &H, &W);
    fornum(i,0,H){
        scanf("%s", S[i]);
    }
    fornum(i,0,H){
        fornum(j,0,W){
            if(mk[i][j])
                continue;
            mk[i][j] = true;
            nxt.push(mp(S[i][j],mp(i, j)));
            ct[(int)'.']=0;
            ct['#']=0;
            ct[S[i][j]]++;
            while(!nxt.empty()){
                auto ps = nxt.front();
                nxt.pop();
                fornum(k,0,4){
                    int x = ps.second.first+gotx[k];
                    int y = ps.second.second+goty[k];
                    if(isIn(x,y)&&!mk[x][y]&&ps.first!=S[x][y]){
                        ct[(int)S[x][y]]++;
                        nxt.push(mp(S[x][y],mp(x, y)));
                        mk[x][y] = true;
                    }
                }
            }
            ans+=ct['.']*ct['#'];
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 640
n = int(input())
d = [int(x) for x in input().split()]
m = int(input())
t = [int(x) for x in input().split()]

from collections import Counter

t = dict(Counter(t))
d = dict(Counter(d))
for i in t.keys():
    if d.get(i)==None or d.get(i)<t.get(i):
        print("NO")
        break
else:
    print("YES")

Measured memory_bytes: 131788
def main():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    parent = list(range(n+1))
    rank = [0]*(n+1)
    cnt = 0
    
    def root(x):
        if parent[x] == x:
            return x
        parent[x] = root(parent[x])
        return parent[x]
    
    def unite(x, y):
        x = root(x)
        y = root(y)
        if x != y:
            if rank[x] < rank[y]:
                parent[x] = y
            elif rank[x] > rank[y]:
                parent[y] = x
            else:
                parent[y] = x
                rank[x] += 1

    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i, pi in enumerate(p, 1):
        if root(i) == root(pi):
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14008
def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b
        nfld = fld.map{ |ar| ar.dup }
        nfld[y][x], nfld[y][x+1] = nfld[y][x+1], nfld[y][x]
        return true if search(adjust(nfld.transpose.map{|ar| ar.reverse} ))
      end
    end
  end
  false
end
  
def search(fld)
  return true if fld.flatten.all?{ |v| !v }
  ret_x = count(fld, $w)
  ret_y = count(fld.transpose, $h)
  return false if ret_x.size == 0 && ret_y.size == 0
  ret_x.each do |y, x|
    $n.times{ |i| fld[y][x + i] = nil }
  end
  ret_y.each do |y, x|
    $n.times{ |i| fld[x + i][y] = nil }
  end
  search(adjust(fld))
end
  
def count(fld, r)
  ret = []
  r.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next unless ar[0]
      ret << [y, x] if ar.all?{|v| v == ar[0] }
    end
  end
  ret
end
  
def adjust(fld)
  $w.times do |x|
    fld[x].map! { |v| v if /[A-Z]/ =~ v }.compact!
  end
  fld.map!{|ar| ar.fill(nil, ar.size...$h) }
end
  
$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('').map{ |v| v if /[A-Z]/ =~ v } }
puts solve(fld) ? 'YES' : 'NO'

Measured memory_bytes: 10384
def xor_sum(n):
    ret = 0
    if n%4 == 0:
        return n
    if n%4 == 1:
        return 1
    if n%4 == 2:
        return n+1
    if n%4 == 3:
        return 0

A,B = map(int,input().split())
# print(xor_sum(A-1), xor_sum(B))
print(xor_sum(B)^xor_sum(A-1))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector < ll > v[100010];
ll dp[100010];

ll rec(ll x){
	if(v[x].size() == 0) return 0;
	if(dp[x] != -1) return dp[x];
	
	
	for(ll i = 0; i < v[x].size(); i++){
		dp[x] = max(dp[x], rec(v[x][i]) + 1);
	}
	
	return dp[x];
}
int main (){
	memset(dp,-1,sizeof dp);
	int n,m;
	cin >> n >> m;
	for(ll i = 1; i <= m; i++){
		ll a,b;
		cin >> a >> b;
		v[a].push_back(b);
	}
	
	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		ll res = rec(i);
		ans = max(ans, res);	
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 8576
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
ans=10**10
for i in range(N-K+1):
  l=A[i]
  r=A[i+K-1]
  if (l<0 and r<0) or (l>0 and r>0):
    ans=min(ans,max(abs(l),abs(r)))
  else:
    ans=min(ans,min(abs(l),abs(r))*2+max(abs(l),abs(r)))
print(ans)
    

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

int main(){
  int fact=0;
  int all;
  cin>>all;
  for(int i=0;i<all;i++){
    int n;
    cin>>n;
    if(n%2==0){
      if(n%3!=0 && n%5!=0){
        fact=1;
        }
      }
    }
  if(fact==1){
    cout<<"DENIED"<<endl;
    }else{
    cout<<"APPROVED"<<endl;
    }
  }

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(n));
    for(i = 0;i < n;++i){
        rep(j,n){
            cin >> a.at(i).at(j);
        }
    }
    ll k;
    ll ans = 0;
    rep(k,n){
        for(i = 0;i < n;++i){
            bool flag = true;
            rep(j,n){
                if(a.at(i).at(j) > a.at(i).at(k) + a.at(k).at(j)){
                    cout << -1 << endl;
                    return 0;
                }else if(i != j && j != k && k != i){
                    if(a.at(k).at(i) == a.at(k).at(j) + a.at(j).at(i)){
                        flag = false;
                    }
                }
            }
            if(flag) ans += a.at(k).at(i);
        }
    }
    cout << ans/2 << endl; 
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
c_ls = []
cnt = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    cnt += 1
  else:
    cnt = 0
  if cnt == 3:
    c_ls.append(a[i])
  if (a[i] == a[i+1]) and(a[i] not in c_ls):
    c_ls.append(a[i])
  if len(c_ls) == 2:
    print(c_ls[0]*c_ls[1])
    exit()
print(0)

Measured memory_bytes: 14252
#include <stdio.h>

int main(void)
{
	int ta, ti;
	double ka, ki;

	scanf("%d %d", &ta, &ti);

	ka = ta;
	ki = ti;

	printf("%d\n", ta / ti);
	printf("%d\n", ta % ti);
	printf("%.5lf\n", ka / ki);

	return 0;
}

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

const int mod=1e9+7;
const int nax=404;
int a[nax];
int b[nax];
ll p[nax][nax];
int n,c;
ll dp[nax][nax];

ll pre[nax][nax];

ll ask(ll po,ll lo,ll hi)
{
    ll res=pre[po][hi]-pre[po][lo-1];
    if(res<0) res+=mod;
    return res;
}

int main()
{
    cin>>n>>c;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=1;i<=400;i++) p[i][0]=1;
    for(int i=1;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
        {
            p[i][j]=p[i][j-1]*i;
            p[i][j]%=mod;
        }
    }
    for(int i=0;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
        {
            pre[i][j]=pre[i][j-1]+p[j][i];
            pre[i][j]%=mod;
        }
    }
    for(int i=0;i<=c;i++)
    {
        ll sum=0;
        for(int j=a[n];j<=b[n];j++)
        {
            sum+=p[j][i];
            if(sum>=mod) sum-=mod;
        }
        dp[n][i]=sum;
    }
    for(int i=n-1;i>=1;i--)
    {
        for(int j=0;j<=c;j++)
        {
            for(int akt=0;akt<=j;akt++)
            {
                ll ans=ask(akt,a[i],b[i]);
                ans*=dp[i+1][j-akt];
                ans%=mod;
                dp[i][j]+=ans;
                dp[i][j]%=mod;
            }
        }
    }
    cout<<dp[1][c];
    return 0;
}


Measured memory_bytes: 4096
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll n,m,k,d,q;

int b[maxn],a[maxn];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<=n-3;i++)
    {
        for(int j=i+1;j<=n-2;j++)
        {
            int sum=a[i]+a[j];
            if((lower_bound(a,a+n,sum)-a)==n)
                ans+=n-j-1;
                else
            ans+=(lower_bound(a,a+n,sum)-a-j-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int y,m,d;
	while(scanf("%d %d %d",&y,&m,&d)!=EOF){
		if(y<1868||(y==1868&&m<9)||(y==1868&&m==9&&d<8)){
			printf("pre-meiji\n");
		}else{
			if(y<1912||(y==1912&&m<7)||(y==1912&&m==7&&d<30)){
				printf("meiji %d %d %d\n",y-1867,m,d);
			}else{
				if(y<1926||(y==1926&&m<12)||(y==1926&&m==12&&d<25)){
					printf("taisho %d %d %d\n",y-1911,m,d);
				}else{
					if(y<1989||(y==1989&&m<1)||(y==1989&&m==1&&d<8)){
						printf("showa %d %d %d\n",y-1925,m,d);
					}else{
						printf("heisei %d %d %d\n",y-1988,m,d);
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 608
n,m=map(int,input().split())
a=[0]*n
dp=[[0 for i in range (m)]for j in range (n)]
dp[0][0]=1
MOD=int(1e9+7)

for i in range (n):
    a[i]=input()

for i in range (n):
    for j in range (m):
        if a[i][j]=='.':
            if i>0:
                dp[i][j]+=dp[i-1][j]
            if j>0:
                dp[i][j]+=dp[i][j-1]
            dp[i][j]%=MOD

print(dp[n-1][m-1])

Measured memory_bytes: 78180
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s1 = sc.next();
    String s2 = sc.next();
    String s3 = sc.next();
    String s = s1.substring(0, 1) + s2.substring(0, 1) + s3.substring(0, 1);
    System.out.println(s.toUpperCase());
  }
}


Measured memory_bytes: 21716
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll const mod = 1000000007;

void prvll(vvll& mp) {
  printf("    ");
  for (size_t j = 0; j < mp[0].size(); j++)
    printf("%4lu%c", j, ((j == mp[0].size() - 1) ? '\n' : ' '));
  for (size_t i = 0; i < mp.size(); i++) {
    printf("%2lu: ", i);
    for (size_t j = 0; j < mp[i].size(); j++)
      printf("%4lld%c", mp[i][j], ((j == mp[i].size() - 1) ? '\n' : ' '));
  }
  cout << endl;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll h, w;
  cin >> h >> w;
  vector<string> mp(h);
  rep(i, h) cin >> mp[i];

  vvll sayu(h, vll(w, 0)), joge(h, vll(w, 0));
  rep(i, h) rep(j, w) {
    if (mp[i][j] == '#') continue;
    ll tmp = 1;
    ll psx = j;
    ll px = j + 1;
    while (px < w && mp[i][px] == '.') {
      tmp++;
      px++;
    }
    repLRE(jj, psx, px - 1) sayu[i][jj] = tmp;
    j = px-1;
  }
  rep(j, w) rep(i, h) {
    if (mp[i][j] == '#') continue;
    ll tmp = 1;
    ll psy = i;
    ll py = i + 1;
    while (py < h && mp[py][j] == '.') {
      tmp++;
      py++;
    }
    repLRE(ii, psy, py - 1) joge[ii][j] = tmp;
    i = py-1;
  }

  //prvll(sayu);
  //prvll(joge);

  ll ans = 0;
  rep(i, h) rep(j, w) {
    ll tmp = sayu[i][j] + joge[i][j] - 1;
    chmax(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 67072
-- Build Stairs
import Data.List
 
data YesNo = Yes | No deriving Show
 
upDownMap :: [Int] -> Bool
upDownMap (x1:(x2:xs))
  | x1 - x2 >= 0 = True && upDownMap(x2:xs)
  | x1 - x2 >= -1 = True && upDownMap((min x1 x2):xs)
  | x1 - x2 < -1  = False
upDownMap(x1:[]) = True 
upDownMap([]) = True
 
main::IO()
main = do
  n <- words <$> getLine
  h <- words <$> getLine
  let heights = map(\e -> read e :: Int) h
  case upDownMap $ reverse $ heights of
    True -> print Yes
    False -> print No

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

char getGrade(int m, int f, int r){
    int sum = m + f;
    char grade;
    if ( m == -1 || f == -1 ) {
        grade = 'F';
    } else if ( 80 <= sum ) {
        grade = 'A';
    } else if ( 65 <= sum && sum < 80 ){
        grade = 'B';
    } else if ( 50 <= sum && sum < 65 ){
        grade = 'C';
    } else if ( 30 <= sum && sum < 50 ){
        if ( 50 <= r ) grade = 'C';
        else grade = 'D';
    } else if ( sum < 30 ){
        grade = 'F';
    }
    
    return grade;
}

int main(){
    int m, f, r;
    while(1){
        cin >> m >> f >> r;
        if ( m == -1 && f == -1 && r == -1 ) break;
        cout << getGrade(m, f, r) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3072
template<class T> inline void chmin(T & a, const T b) { if (a > b) a = b; }

#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const int MAX_N = 110000;

int main(void) {
	int N; cin >> N;
	vector<int> dp(MAX_N, INF);
	dp[0] = 0;

	// 配るDP
	for (int n = 0; n <= N; n++) {
		for (int pow6 = 1; n + pow6 <= N; pow6 *= 6) {
			chmin(dp[n + pow6], dp[n] + 1);
		}
		for (int pow9 = 1; n + pow9 <= N; pow9 *= 9) {
			chmin(dp[n + pow9], dp[n] + 1);
		}
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 640
n,k = map(int, input().split())
s = input()

bad = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        bad += 1

if bad > k*2:
    ans = (n-1) - bad + (k*2)
else:
    ans = n-1

print(ans)


Measured memory_bytes: 3316
N,K = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)

minval=1e20
(0..N-K).each do |i|
    s=a[i]
    e=a[i+K-1]
    if s*e>=0
        t=[s.abs, e.abs].max
    else
        t=[s.abs, e.abs].min*2 + [s.abs, e.abs].max
    end
    minval=t if minval>t
end

puts minval



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

using namespace std;

const int MOD = 1e9 + 7;
const int maxf = 1e5 + 5;
vector<int> f(maxf, 0);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  if (abs(N - M) > 1) {
    cout << 0 << '\n';
  } else {
    f[0] = 1;
    for (int i = 1; i < maxf; i++) {
      f[i] = 1LL * i * f[i - 1] % MOD;
    }
    int sign = (N - M == 0 ? 2 : 1);
    cout << 1LL * sign * f[N] * f[M] % MOD << '\n';
  }
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

using namespace std;
using int64 = long long;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  int n = 0;
  string ans = "";
  vector<int> od_row_idx;
  for (int i = 0; i < H; i++) {
    vector<int> od_idx;
    for (int j = 0; j < W; j++) {
      if (a[i][j] % 2 == 1) {
        od_idx.push_back(j);
      }
    }
    debug(od_idx);
    if ((int)od_idx.size() == 0) continue;
    for (int j = 0; j < (int)od_idx.size() - 1; j += 2) {
      for (int k = od_idx[j]; k < od_idx[j + 1]; k++) {
        ans += to_string(i + 1) + ' ' + to_string(k + 1) + ' ' +
               to_string(i + 1) + ' ' + to_string(k + 2) + '\n';
        n++;
      }
    }
    if ((int)od_idx.size() % 2 == 1) {
      for (int k = od_idx.back(); k < W - 1; k++) {
        ans += to_string(i + 1) + ' ' + to_string(k + 1) + ' ' +
               to_string(i + 1) + ' ' + to_string(k + 2) + '\n';
        n++;
      }
      od_row_idx.push_back(i);
    }
  }
  if ((int)od_row_idx.size() > 1) {
    for (int j = 0; j < (int)od_row_idx.size() - 1; j += 2) {
      for (int k = od_row_idx[j]; k < od_row_idx[j + 1]; k++) {
        ans += to_string(k + 1) + ' ' + to_string(W) + ' ' + to_string(k + 2) +
               ' ' + to_string(W) + '\n';
        n++;
      }
    }
  }
  cout << n << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6332
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<ll> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(ll i=0;i<n;i++)
#define for1(i,n)        for(ll i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	ll n,m;
	cin>>n>>m;
	vi a(n),b(n),c(m),d(m);
	for0(i,n)cin>>a[i]>>b[i];
	for0(i,m)cin>>c[i]>>d[i]; 
	
	for0(i,n){
		ll x,pos,mn =1000000000;
		for0(j,m){
			x = abs(a[i]-c[j]) + abs(b[i]-d[j]);
			if(x<mn){
				mn = x;
				pos=j;
				}
			}
		cout<<pos+1<<nw;
		}
	return 0;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())

for i in range(K):
    if i % 2 == 0:
        if A % 2 != 0:
            A -= 1
        A = A // 2
        B += A
    else:
        if B % 2 != 0:
            B -= 1
        B = B // 2
        A += B

print(A, B)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>

using namespace std;

int dp1[1000010]={0};
int dp2[1000010]={0};
int List[200];

void setpolloc(){
	int i,j,li;
	for(i=1;i*(i+1)*(i+2)/6<=1000000;i++){
		List[i]=i*(i+1)*(i+2)/6;
		dp1[i*(i+1)*(i+2)/6]=1;
		if((i*(i+1)*(i+2)/6)%2) dp2[i*(i+1)*(i+2)/6]=1;
	}
	List[i]=i*(i+1)*(i+2)/6;
	for(i=1;i<=1000000;i++){
		if(dp2[i]) continue;
		for(j=1;List[j]<=i-1;j+=2)if(!dp2[i] || dp2[List[j]]+dp2[i-List[j]] < dp2[i]) dp2[i]=dp2[List[j]]+dp2[i-List[j]];
		if(dp1[i]) continue;
		for(j=1;List[j]<=i-1;j++) if(!dp1[i] || dp1[List[j]]+dp1[i-List[j]] < dp1[i]) dp1[i]=dp1[List[j]]+dp1[i-List[j]];
	}
}


int main(){
	int n;
	setpolloc();
	while(cin>>n,n){
		cout << dp1[n] << ' ' << dp2[n] << endl;
	}
	return 0;
}

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

int n;
double r;

struct point {
    double x, y;
} p[100005], o;

inline double sqr(double x) { return x * x; }

inline double dis(point a, point b) {
    return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}

inline bool cmp(double a, double b) { return fabs(a - b) < 1e-8; }

point geto(point a, point b, point c) {
    double a1, a2, b1, b2, c1, c2;
    point ans;
    a1 = 2 * (b.x - a.x), b1 = 2 * (b.y - a.y),
    c1 = sqr(b.x) - sqr(a.x) + sqr(b.y) - sqr(a.y);
    a2 = 2 * (c.x - a.x), b2 = 2 * (c.y - a.y),
    c2 = sqr(c.x) - sqr(a.x) + sqr(c.y) - sqr(a.y);
    if(cmp(a1, 0)) {
        ans.y = c1 / b1;
        ans.x = (c2 - ans.y * b2) / a2;
    } else if(cmp(b1, 0)) {
        ans.x = c1 / a1;
        ans.y = (c2 - ans.x * a2) / b2;
    } else {
        ans.x = (c2 * b1 - c1 * b2) / (a2 * b1 - a1 * b2);
        ans.y = (c2 * a1 - c1 * a2) / (b2 * a1 - b1 * a2);
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
        scanf("%lf%lf", &p[i].x, &p[i].y);
    for(int i = 1; i <= n; i++)
        swap(p[rand() % n + 1], p[rand() % n + 1]);
    o = p[1];
    for(int i = 1; i <= n; i++) {
        if(dis(o, p[i]) < r || cmp(dis(o, p[i]), r))
            continue;
        o.x = (p[i].x + p[1].x) / 2;
        o.y = (p[i].y + p[1].y) / 2;
        r = dis(p[i], p[1]) / 2;
        for(int j = 2; j < i; j++) {
            if(dis(o, p[j]) < r || cmp(dis(o, p[j]), r))
                continue;
            o.x = (p[i].x + p[j].x) / 2;
            o.y = (p[i].y + p[j].y) / 2;
            r = dis(p[i], p[j]) / 2;
            for(int k = 1; k < j; k++) {
                if(dis(o, p[k]) < r || cmp(dis(o, p[k]), r))
                    continue;
                o = geto(p[i], p[j], p[k]);
                r = dis(o, p[i]);
            }
        }
    }
    printf("%.20f\n", r);
    return 0;
}


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

int main() {
  int A,B;
  cin >> A;
  cin >> B;
  
 if(A%2==B%2) {
 cout << (A+B)/2 << endl;
 }
 else {
   cout  << "IMPOSSIBLE" << endl;
 }

 
return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
main=do
    n<-readLn
    abs<-reverse <$> replicateM n (unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine)
    print $ sol 0 abs
sol c [] = c
sol c ([a,b]:abs)
    | (a+c)`mod`b == 0 = sol c abs
    | otherwise = sol (c+ ((a+c+b)`div`b)*b-(a+c)) abs

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

int main() {
	// your code goes here
	int n;//a+b=x;2*a + 4*b=y;
	cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
      cin>>a[i];
    sort(a,a+n);
   // if(a[0]==1) cout<<0<<endl;
    int fre[1000002]={0};
    for(int i=0;i<n;i++)
      fre[a[i]]++;
    int ans=0;
    int fact[1000002]={0};
    for(int i=1;i<=1000000;i++)
     {
       for(int j=2*i;j<=1000000;j+=i)
       {
          if(fre[i]!=0 && fre[j]!=0 )
             fact[j]++;
       }
     }
  
   for(int i=1;i<=1000000;i++)
      if(fre[i]==1 && fact[i]==0)
         ans++;
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12184
using System;
using System.IO;

class Solve{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var answer = int.MaxValue;
        for (int i = 0; i < N; i++){
            var ai = A[i];
            var count = 0;
            while ((ai & 1) == 0){
                ai >>= 1;
                count++;}
            answer = count < answer ? count : answer;
            if (answer == 0) break;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27828
#include <stdio.h>

#define max 3001

int main(void)
{
	int r,g,b,n;
	
	scanf("%d %d %d %d",&r,&g,&b,&n);
	
	int i,j,count = 0;
	
	
	
	for(i = 0;i < max ;i++){
		for(j = 0;j < max;j++){
			int remain = n - (r*i+g*j);
			if(remain < 0){
				break;
			}
			if(remain % b == 0 || remain == 0){
				count = count + 1;
			}
			
		}
	}
	
	printf("%d\n",count);
	
	return 0;
	
}

Measured memory_bytes: 128
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	
	static int n, m;
	static int[] taro, hanako;
	
	static void start()
	{
		int ttotal = 0;
		for(int i = 0;i < n;i++) ttotal += taro[i];
		
		int htotal = 0;
		for(int i = 0;i < m;i++) htotal += hanako[i];
		
		for(int tc = 0;tc < n;tc++)
		{
			for(int hc = 0;hc < m;hc++)
			{
				int tt = ttotal - taro[tc] + hanako[hc];
				int hh = htotal + taro[tc] - hanako[hc];
				if(tt == hh)
				{
					System.out.printf("%d %d\n", taro[tc], hanako[hc]);
					return;
				}
			}
		}
		
		System.out.println("-1");
	}
	
	public static void main(String[] args)
	{
		
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			n = sca.nextInt();
			m = sca.nextInt();
			if(n == 0) break;
			
			taro = new int[n];
			for(int i=0;i < n;i++) taro[i] = sca.nextInt();
			
			hanako = new int[m];
			for(int i=0;i < m;i++) hanako[i] = sca.nextInt();
			
			start();
		}
	}
}

Measured memory_bytes: 21060
include Math
 
n = gets.to_i
 
n.times do
    x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f)

    a = ((x3 - x2) ** 2 + (y3 - y2) ** 2) ** 0.5
    b = ((x1 - x3) ** 2 + (y1 - y3) ** 2) ** 0.5
    c = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5

    cosA = (-a ** 2 + b **2 + c ** 2) / (2 * b * c)
    cosB = (a ** 2 - b **2 + c ** 2) / (2 * a * c)
    cosC = (a ** 2 + b **2 - c ** 2) / (2 * a * b)

    sin2A = 2 * sin(acos(cosA)) * cosA
    sin2B = 2 * sin(acos(cosB)) * cosB
    sin2C = 2 * sin(acos(cosC)) * cosC

    px = (sin2A * x1 + sin2B * x2 + sin2C * x3) / (sin2A + sin2B + sin2C)
    py = (sin2A * y1 + sin2B * y2 + sin2C * y3) / (sin2A + sin2B + sin2C)
    r = ((px - x1) ** 2 + (py - y1) ** 2) ** 0.5

    puts "%.3f %.3f %.3f" % [px, py, r]
end

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

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
const int mod = (int)1e9+7;
typedef long long int ll;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,w;
	cin>>n>>w;
	ll dp[n+5][w+5],wt[n+5],val[n+5]; 
	for(int i=0;i<n;i++)	
		cin>>wt[i]>>val[i];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=w;j++){
			if(i==0 or j==0)
				dp[i][j]=0;
			else if(j>=wt[i-1])
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-wt[i-1]]+val[i-1]);
			else
				dp[i][j] = dp[i-1][j];
		}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 80640
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int []a=new int[4];
        int c=0;
        for(int i=0;i<4;i++){
            a[i]=sc.nextInt();
        }
        for(int i=0;i<=a[0];i++){
            for(int j=0;j<=a[1];j++){
                for(int k=0;k<=a[2];k++){
                    if(a[3]==500*i+100*j+50*k){
                        c++;
                    }
                }
            }
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 21972
S =input()
T =input()

min = 1000
for i in range(len(S)-len(T)+1):
    count = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            count += 1
        if count > min:
            break
    if count < min:
        min = count

print(min)

Measured memory_bytes: 9080
import java.util.Scanner;

	class Main{
		public static void main(String[]args){
            
            
        Scanner sc=new Scanner(System.in);
            int a,b,c,i,j,count=0;
            a=sc.nextInt();
            b=sc.nextInt();
            c=sc.nextInt();
              for(j=a;j<=b;j++)if(c%j==0)count++;
            System.out.println(count);
        }
    }


Measured memory_bytes: 26224
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int n, q;
	string s;
	cin >> n >> q >> s;
	s = " " + s;
	vector < int > pref(n + 1);
	for (int i = 2; i <= n; ++i) {
		if (s.substr(i - 1, 2) == "AC") {
			++pref[i];
		}
		pref[i] += pref[i - 1];
	}
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << pref[r] - pref[l] << "\n";
	}
}

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

int main(){
  int64_t n;
  cin >>n;
  int64_t ans=0;
  for(int64_t i=1;i<=n;i++){
    for(int64_t j=i;j<=n;j+=i){
      ans+=j;
    }
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int a,b; cin>>a>>b;
	cout<<a-b+1<<endl;
	return 0;
}

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

using namespace std;
typedef long long Int;

#define KIND 26
Int D;
Int c[KIND];
Int s[400][KIND];
Int last[KIND];
Int calc_score(vector<Int> t)
{
    Int score = 0;
    fill(last, last + 26, -1);
    for (int d = 0; d < D; d++) {
        score += s[d][t[d]];
        last[t[d]] = d;
        for (int i = 0; i < KIND; i++) {
            score -= c[i] * (d - last[i]);
        }
        // cout << score << endl;
    }
    return score;
}

int main()
{
    cin >> D;
    for (Int i = 0; i < KIND; i++) {
        cin >> c[i];
    }
    for (Int d = 0; d < D; d++) {
        for (Int i = 0; i < KIND; i++) {
            cin >> s[d][i];
        }
    }

    vector<Int> t(D);
    for (auto &elem : t) {
        cin >> elem;
        elem--;
    }
    Int current_score = calc_score(t);

    Int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        Int d, q;
        cin >> d >> q;
        d--;
        q--;
        int old = t[d];
        t[d] = q;
        Int new_score = calc_score(t);
        cout << new_score << endl;
        /*        if (new_score < current_score) {
                    t[d] = old;
                }
                else {
                    current_score = new_score;
                    }*/
        current_score = new_score;
    }

    return 0;
}

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

typedef long long ll;

int main() {
  ll a;
  double b;
  cin >> a >> b;
  // 0.01 * 100 = 0.9999999...
  // 0.01 * 100 = 1.0000000...
  // のどちらかに誤差が出る
  // 0.5を足すことで1.05..., 1.05....になって切り捨てで1.00になる。
  ll b_ll = b * 100 + 0.5;
  a *= b_ll;
  a /= 100;
  cout << a << endl;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(int argc, char **argv)
{
    char s[16];
    scanf("%s", s);

    int cur = 0;
    char v[16] = "";
    for (int i = 0; s[i] != '\0'; ++i) {
        if (s[i] == 'B') {
            if (cur != 0) {
                cur--;
            }
        } else {
            v[cur] = s[i];
            cur++;
        }
    }
    v[cur] = '\0';

    printf("%s\n", v);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

struct union_find {
    vector<int> data;

    union_find(int size) {data.resize(size,-1);}

    int find(int x) {
        if (data[x] < 0) return x;
        return data[x] = find(data[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) {return false;}
        if (data[x] > data[y]) swap(x,y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int size(int x) {return -data[x];}
};

template<class T> 
struct edge {int from, to; T cost;};

template<class T>
T kruskal(vector<edge<T>> &edges, int V) {
    sort(edges.begin(),edges.end(),[](const edge<T> &edge1, const edge<T> &edge2) {
        return edge1.cost < edge2.cost;}
    );
    union_find uf(V);
    T res = 0;
    for (edge<T> &e: edges) if (uf.unite(e.from,e.to)) res += e.cost;
    return res;
}

struct cood {int x, y, label;};

bool comp_x(const cood &co1, const cood &co2) {return co1.x < co2.x;}
bool comp_y(const cood &co1, const cood &co2) {return co1.y < co2.y;}

int main() {
    int n;
    cin >> n;
    vector<cood> co;
    vector<edge<int>> edges;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        co.push_back(cood{a,b,i});
    }
    sort(co.begin(),co.end(),comp_x);
    rep(i,n-1) {
        edges.push_back(edge<int>{co[i].label,co[i+1].label,co[i+1].x-co[i].x});
    }
    sort(co.begin(),co.end(),comp_y);
    rep(i,n-1) {
        edges.push_back(edge<int>{co[i].label,co[i+1].label,co[i+1].y-co[i].y});
    }
    cout << kruskal(edges,n) << endl;
}

Measured memory_bytes: 6004
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) {return log(b) / log(a);}

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	int n, maxW;
	cin >> n >> maxW;
	vector<int> w(n), v(n);
	rep(i, n) {
		cin >> w[i] >> v[i];
	}
	vector<vector<ll>> a(n);
	rep(i, n) {
		a[i].resize(100001);//value
	}
	ll ans = 0;
	rep(i, n) {
		if (i == 0) {
			rep(j, 100001) {
				if (j == 0) {
					a[i][j] = 0;
				}
				else if (j == v[0]) {
					a[0][v[0]] = w[0];
				}
				else {
					a[0][j] = 1000000001;
				}
			}
			continue;
		}
		rep(j, 100001) {
			if (j == 0) {
				a[i][j] = 0;
			}
			else {
				if (j - v[i] >= 0) {
					a[i][j] = min(a[i - 1][j], a[i - 1][j - v[i]] + w[i]);
				}
				else {
					a[i][j] = a[i - 1][j];
				}
			}
		}
	}
	rrep(j, 100001) {
		rep(i, n) {

			if (a[i][j] <= maxW) {
				cout << j << endl;
				return 0;
			}
		}
	}
	cout << 0 << endl;
}


Measured memory_bytes: 78592
<?php
fscanf(STDIN, "%d%d%d", $N, $M, $Q);
for($i = 0; $i <= $N; ++$i){
  for($j = 0; $j <= $N; ++$j){
    $map[$i][$j] = 0;
  }
}
for($i = 0; $i < $M; ++$i){
  fscanf(STDIN, "%d%d", $L, $R);
  $map[$L][$R] += 1;
}
for($i = 1; $i <= $N; ++$i){
  for($j = 1; $j <= $N; ++$j){
    $map[$i][$j] = $map[$i][$j] + $map[$i][$j-1];
  }
}
for($i = 1; $i <= $Q; ++$i){
  fscanf(STDIN, "%d%d", $L, $R);
  if(!isset($q[$L][$R])){
    $sum = 0;
    for($j = $L; $j <= $R; ++$j){
      $sum += $map[$j][$R] - $map[$j][$L-1];
    }
    $q[$L][$R] = $sum;
  }
  echo $q[$L][$R],"\n";
}

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

int main() {

    string S, T;

    cin >> S >> T;

    if (T.substr(0,S.size()) == S && T.size() == S.size()+1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3604
#include<iostream>

using namespace std;

int main(void)
{
	int a[5];
	for(int i=0;i<5;i++){
		cin>>a[i];
	}
	for(int i=0;i<5;i++)
	{
		int max=i;
		for(int j=i+1;j<5;j++)
		{
			if(a[max]<a[j])
			{
				max=j;
			}
		}
		int tmp=a[i];
		a[i]=a[max];
		a[max]=tmp;
	}
	cout<<a[0];
	for(int i=1;i<5;i++)
	{
		cout<<" "<<a[i];
	}
	cout<<endl;
}

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

vector<vector<int>> g;
vector<int> it;
int n = 0;
int cou = 0;
int ans = 0;

int f(int x){
	it.at(x) = 1;
	cou++;
	if(cou == n) ans++;
	rep(i, g.at(x).size()){
		if(it.at(g.at(x).at(i)) == 0) f(g.at(x).at(i));
	}
	it.at(x) = 0;
	cou--;
	return 0;
}

int main(){
	int m;
	cin >> n >> m;
	g = vector<vector<int>>(n, vector<int>(0));
	it = vector<int>(n);
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
	f(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200050
using namespace std;
int n,T;
int t[maxn];
int main(){
//	freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;i++) scanf("%d",&t[i]);
	int ans=0;
	for(int i=2;i<=n;i++){
		if(t[i]-t[i-1]<T) ans+=t[i]-t[i-1];
		else ans+=T;
	}
	printf("%d\n",ans+T);
	return 0;
}

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

ll N, A, B;

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

  ll set = N / (A + B);  //操作回数
  cout << set * A + min(N - set * (A+B), A) << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll A[N], B[N];
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  ll s = 0;
  for (int i = 0; i < N; i++) {
    s += min(A[i], B[i]);
    B[i] -= min(A[i], B[i]);
    A[i] -= min(A[i], B[i]);
    s += min(A[i + 1], B[i]);
    A[i+1] -= min(A[i + 1], B[i]);
  }
  cout << s << "\n";
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, int> A;
	rep(i, n) {
		A[a[i]]++;
	}

	ll tot = 0;
	for (int i = 1; i <= n; i++) {
		auto itr = A.find(i);
		if (itr != A.end()) {
			int j = itr->second;
			tot += (ll)j * (j - 1) / 2;
		}
	}

	rep(i, n) {
		int j = A[a[i]];
		if (j < 2) cout << tot << endl;
		else {
			cout << tot - (j - 1) << endl;
		}
	}

}

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

using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b and a!=c)
    cout << "Yes";
  else if(b==c and b!=a)
    cout << "Yes";
  else if(c==a and c!=b)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int N;
void solve() {
    cin >> N;
    vector<long long> a(3 * N);
    for (int i = 0; i < (3 * N); i++) {
        cin >> a.at(i);
    }
    vector<long long> front(3 * N + 1);
    priority_queue<long long, vector<long long>, greater<long long>>f_que;
    for (int i = 0; i < (3 * N); i++) {
        long long b = 0;
        f_que.push(a[i]);
        if (f_que.size() >= (N + 1)) {
            b = f_que.top();
            f_que.pop();
        }
        front[i + 1] = front[i] + a[i] - b;
    }
    vector<long long> back(3 * N + 1);
    priority_queue<long long>b_que;
    for (int i = (3 * N) - 1; i > -1; i--) {
        long long b = 0;
        b_que.push(a[i]);
        if (b_que.size() >= (N + 1)) {
            b = b_que.top();
            b_que.pop();
        }
        back[i] = back[i + 1] + a[i] - b;
    }
    long long ans = -INFL;
    for (int i = N; i < (2 * N) + 1; i++) {
        ans = max(ans, front[i] - back[i]);
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 9588
from collections import deque


def main():
    N, M = map(int, input().split())
    G = [set() for _ in range(N)]
    for i in range(M):
        A, B = map(lambda x: int(x) - 1, input().split())
        G[A].add(B)
        G[B].add(A)

    vis = [-1] * N
    vis[0] = 0
    q = deque([0])

    while q:
        v = q.popleft()
        for n in G[v]:
            if vis[n] != -1:
                continue
            vis[n] = v
            q.append(n)

    print('Yes')
    print("\n".join(map(lambda x: str(x + 1), vis[1:])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 127216
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100];
vector < pair<int, int> > b[100];
int main(){
  int n;
  while(cin>>n){
    if(n==2){
        cout<<2<<" "<<2<<endl;
        cout<<1<<" "<<2<<" "<<0<<endl;
        cout<<1<<" "<<2<<" "<<1<<endl;
        continue;
    }
    int mx=0;
    --n;
    for(int i=19; i>=0; --i){
        if((1<<i)&n){
            a[i]=1;
            mx=max(mx, i);
        }
        else
            a[i]=0;
    }
    int cnt=0;
//    b[1].push_back(mk(2,0));
    for(int i=1; i<=mx; ++i){
        b[i].push_back(mk(i+1, (1<<(mx-i))));
        b[i].push_back(mk(i+1, 0));
        cnt+=2;
    }
    int tmp=0;
    for(int i=mx; i>=0; --i){
        if(a[i]){
            tmp+=(1<<i);
            int nxt=mx+1;
            for(int j=i-1; j>=0; --j){
                if(a[j]){
                    nxt=mx-j+1;
                    break;
                }
            }
            b[1].push_back(mk(nxt, tmp));
            ++cnt;
        }
    }
    cout<<mx+1<<" "<<cnt<<endl;
    for(int i=1; i<=mx+1; ++i){
        for(int j=0; j<b[i].size(); ++j){
            cout<<i<<" "<<b[i][j].fs<<" "<<b[i][j].sc<<endl;
        }
    }
  }
  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] pnums = new int[55555];
		int[] resnums = new int[n];

		int cnt = 0;
		int pcnt = 0;
		int num = 2;

		while(true) {
			boolean addflg = true;
			for(int i = 0; i < pcnt; i++) {
				if( (num % pnums[i]) == 0 ) {
					// 素数ではない
					addflg = false;
					num++;
					break;
				}
			}
			if(addflg == false)
				continue;
			pnums[pcnt] = num;
			pcnt++;

			if(num % 5 == 1) {
				resnums[cnt] = num;
				cnt++;
			}

			num++;

			if(cnt == n)
				break;
		}

		for(int i = 0; i < n; i++) {
			if(i != 0)
				System.out.print(" ");
			System.out.print(resnums[i]);
		}
		System.out.print("\n");
	}
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int H,W,N;
int A[111111],B[111111];

int id(int y,int x){
    if(y==0)return x;
    if(x==W)return W+y;
    if(y==H)return W+H+(W-x);
    return W+H+W+(H-y);
}

signed main(){
    cin>>H>>W>>N;
    memset(A,-1,sizeof(A));
    rep(i,N){
        int y1,x1,y2,x2;
        cin>>y1>>x1>>y2>>x2;


        if(y1!=0&&y1!=H&&x1!=0&&x1!=W)continue;
        if(y2!=0&&y2!=H&&x2!=0&&x2!=W)continue;
        A[i]=id(y1,x1);
        B[i]=id(y2,x2);
    }

    vpint ev;
    rep(i,N){
        if(A[i]==-1)continue;
        if(A[i]>B[i])swap(A[i],B[i]);
        ev.pb({A[i],i});
        ev.pb({B[i],i-INT_MAX});
    }
    sort(all(ev));
    stack<int>stk;
    for(auto &w:ev){
        if(w.se<0){
            w.se+=INT_MAX;
            if(stk.size()==0||stk.top()!=w.se){
                cout<<"NO"<<endl;
                return 0;
            }
            stk.pop();
        }
        else{
            stk.push(w.se);
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 8048