akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX_N 1000
#define MAX_M 10000
#define MIN_T 540
#define MAX_T 1260

int main() {
	static int a[MAX_M][MAX_T + 1];
	for (int N, M; cin >> N >> M&&N;) {
		memset(a, 0, sizeof(a));

		int r; cin >> r;
		for (int i = 0; i < r; i++) {
			int t, n, m, s; cin >> t >> n >> m >> s;
			if (s == 1) {
				for (int j = t; j <= MAX_T; j++) {
					a[m][j]++;
				}
			}
			else {
				for (int j = t; j <= MAX_T; j++) {
					a[m][j]--;
				}
			}
		}
		int q; cin >> q;
		for (int i = 0; i < q; i++) {
			int ts, te, m; cin >> ts >> te >> m;
			int cnt = 0;
			for (int j = ts; j < te; j++) {
				//cout << j << " " << a[m][j] << endl;
				if (a[m][j] > 0)cnt++;
			}
			cout << cnt << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 50424
#include <iostream>
#include <sstream>
using namespace std;
int main(){
	int x,y,z,d = 0;
	cin>>x>>y>>z;
	for(int i=1;i<=x;i++){
		int r = i;
		int c = 0;
		while(r>0){
			c = c + (r%10);
			r = r / 10 ;
		}
		if(c>=y && c<=z){
			d  = d + i;
		}
	}
	cout<<d<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
char map[101][101];
int flag[100][100];
int main() {
	while(1) {
		int i, j, H, W;
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i = 0; i < H; ++ i) for(j = 0; j < W; ++ j) flag[i][j] = 0;
		for(i = 0; i < H; ++ i) scanf("%s", map[i]);
		int x = 0, y = 0;
		while(1) {
			if(flag[y][x]) {
				printf("LOOP\n");
				break;
			}
			flag[y][x] = 1;
			if(map[y][x] == '>') {
				x ++;
			} else if(map[y][x] == '<') {
				x --;
			} else if(map[y][x] == '^') {
				y --;
			} else if(map[y][x] == 'v') {
				y ++;
			} else {
				printf("%d %d\n", x, y);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 664
#include <iostream>
//typedef long long l1;
using namespace std;

int main() {
	int A, B, C, D,r1,r2,r3,r4,r;
	cin >> r;
	r1 = (r - (r % 1000)) / 1000;
	r -= r1*1000;
	r2 = (r-(r%100)) / 100;
	r -= r2*100;
	r3 = (r - (r % 10)) / 10;
	r -= r3*10;
	r4 = r;
	A = r1;
	B = r2;
	C = r3;
	D = r4;
	for (int i=0;i <= 8;i++) {
		switch (i) {
		case 1:
			if (A - B - C - D == 7) {
				cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
				goto l1;
			}
		case 2:
			if (A - B - C + D == 7) {
				cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
				goto l1;
			}
		case 3:
			if (A - B + C - D == 7) {
				cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
				goto l1;
			}
		case 4:
			if (A - B + C + D == 7) {
				cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
				goto l1;
			}
		case 5:
			if (A + B - C - D == 7) {
				cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
				goto l1;
			}
		case 6:
			if (A + B - C + D == 7) {
				cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
				goto l1;
			}
		case 7:
			if (A + B + C - D == 7) {
				cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
				goto l1;
			}
		case 8:
			if (A + B + C + D == 7) {
				cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
				goto l1;
			}
			}
		}
l1:	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(s == "Cloudy"){
    cout << "Rainy" <<endl;
  }
  else if(s == "Rainy"){
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
main = do
  line <- getLine
  let input = map read $ words line :: [Int]
      judge [w,h,x,y,r]
        | 0 <= (x-r) && 0 <= (y-r) && (x+r) <= w && (y+r) <= h  = "Yes"
        | otherwise                                             = "No"
    in putStrLn $ judge input



Measured memory_bytes: 3648
l, r = map(int, input().split())

flag = False
if l % 2019 == 0 or r // 2019 - l // 2019 != 0:
    flag = True

if flag:
    print(0)
else:
    lmod = l % 2019
    rmod = r % 2019

    ans = 10**5
    for i in range(lmod, rmod):
        for j in range(i+1, rmod+1):
            ans = min((i * j) % 2019, ans)
    print(ans)

Measured memory_bytes: 40940
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], h = tmp[1];

    int[] a = new int[n], b = new int[n];
    foreach (i; 0 .. n) {
        tmp = readln.split.to!(int[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }

    zip(a, b).sort!((x, y) => x[0] > y[0]);
    int amax = a[0], bmax = b[0];
    a.popFront, b.popFront;
    if (!b.empty) zip(a, b).sort!((x, y) => x[1] > y[1]);

    int cnt;

    while (h > 0) {
        if (h <= max(amax, bmax)) {
            h -= max(amax, bmax);
        } else if (b.empty || amax > b[0]) {
            cnt += min((h+amax-1)/amax, (h-bmax+amax-1)/amax+1);
            break;
        } else {
            h -= b[0];
            b.popFront;
        }
        ++cnt;
    }

    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4092
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	ll ans = 0;
	vector<ll> a(n);
	vector<ll> suf(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	suf[n - 1] = a[n - 1];
	for(int i = n - 2; i > -1; i--) suf[i] = (suf[i + 1] + a[i]) % MOD;
	for(int i = 0; i < n - 1; i++) ans = (ans + a[i] * suf[i + 1] % MOD) % MOD;
	cout << ans;

	return 0;
}

Measured memory_bytes: 6348
import java.util.*;

public class Main{
	public static int[][] solve(int[][] map, Set<List<Integer>> bomb){
		while( bomb.size() != 0 ){
			Set<List<Integer>> temp = new HashSet<List<Integer>>();
			for(List<Integer> list : bomb){
				map[list.get(1)][list.get(0)] = 0;
				int st_l = ( list.get(1)-3 < 0 ) ? 0 : list.get(1)-3;
				int fin_l = ( list.get(1)+3 > 7 ) ? 7 : list.get(1)+3;
				int st_w = ( list.get(0)-3 < 0 ) ? 0 : list.get(0)-3;
				int fin_w = ( list.get(0)+3 > 7 ) ? 7 : list.get(0)+3;
				for(int i = st_l; i <= fin_l; i++){
					if( map[i][list.get(0)] == 1 ){
						List<Integer> point = new ArrayList<Integer>();
						point.add(list.get(0)); point.add(i);
						temp.add(point);
					}
				}
				for(int i = st_w; i <= fin_w; i++){
					if( map[list.get(1)][i] == 1 ){
						List<Integer> point = new ArrayList<Integer>();
						point.add(i); point.add(list.get(1));
						temp.add(point);
					}
				
				}				
			}
			bomb.clear();
			bomb = new HashSet<List<Integer>>(temp);
		}
		return map;
	}
	
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		List<int[][]> ans = new ArrayList<int[][]>();
		int T = stdIn.nextInt();
		
		for(int i = 0; i < T; i++){
			String[] s = new String[8];
			for(int j = 0; j < 8; j++){
				s[j] = stdIn.next();
			}
			int[][] map = new int[8][8];
			for(int j = 0; j < 8; j++){
				for(int k = 0; k < 8; k++){
					map[j][k] = Integer.parseInt(Character.toString(s[j].charAt(k)));
				}
			}
			int x = stdIn.nextInt(), y = stdIn.nextInt();
			Set<List<Integer>> bomb = new HashSet<List<Integer>>();
			List<Integer> list = new ArrayList<Integer>();
			list.add(x-1); list.add(y-1);
			bomb.add(list);
			int[][] result = new int[8][8];
			result = solve(map,bomb);
			ans.add(result);
		//	System.out.println("Data " + (i+1) + ":");
		/*	for(int[] z : result){
				for(int w : z){
					System.out.print(w);
				}
				System.out.println();
			}*/
		}
		for(int i = 1; i <= T; i++){
			System.out.println("Data " + i + ":");
			for(int[] a : ans.get(i-1)){
				for(int b : a){
					System.out.print(b);
				}
				System.out.println();			
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int h;
int fun(int x){
 if(x == 1)return 1;
 if(x == 0)return 1;
 int l = fun(x/2);
 return 2*l + 1;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>h;
cout<<fun(h)<<endl;

}



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

int main(){
  int A, B, C, D, P;
  cin >> A >> B >> C >> D >> P;
  int X = A * P;
  int Y = B + D * max(0, P - C);

  cout << min(X, Y) << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  char p='a';
  string a,b,c;
  cin>>a>>b>>c;
  while(1){
    if(p=='a'){
      if(a.size()==0){
        cout<<"A";
        break;
      }
      p=a.at(0),a.erase(0,1);
    }
    else if(p=='b'){
      if(b.size()==0){
        cout<<"B";
        break;
      }
      p=b.at(0),b.erase(0,1);
    }
    else if(p=='c'){
      if(c.size()==0){
        cout<<"C";
        break;
      }
      p=c.at(0),c.erase(0,1);
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
# D - 高橋君と見えざる手
# https://atcoder.jp/contests/abc047/tasks/arc063_b

from collections import Counter
N,T=map(int,input().split())
A=list(map(int,input().split()))

mini=10**9
maxi=0
m = [0]*N
M = [0]*N
z = [0]*N
for i in range(N):
    mini=min(mini,A[i])
    maxi=max(maxi,A[i])
    m[i]= mini
    M[i]= maxi
    z[i]= A[i]-mini
k=Counter(z)
l=sorted(k,reverse=True)
#print(l)
print(k[l[0]])

Measured memory_bytes: 27648
N = int(input())
cs = list(input())

ans = 0
sorted = N - 1
for i in range(N):
  if cs[i] == "W":
    for j in range(sorted, i, -1):
      sorted = j - 1
      if cs[j] == "R":
        cs[i], cs[j] = cs[j], cs[i]
        ans += 1
        break
  if (i + 1) > sorted:
    break
print(str(ans))

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

int main()
{
	int k;	
	int ans = 1;	
	cin >> k;
	int mod_k = 7 % k;
	set<int> mod_k_rec;

	while (mod_k_rec.count(mod_k) == 0) {		
		if (mod_k == 0) {
			cout << ans << endl;
			return 0;
		}
		mod_k_rec.insert(mod_k);
		ans++;
		mod_k = (10 * mod_k + 7) % k;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 50484
n = int(input())
l = list(map(float, input().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
# dp[i][j]: 最初のi枚のコインを投げたとき、表がj枚になる確率
dp[0][0] = 1.0
for i in range(n):
  for j in range(i+1):
    dp[i+1][j+1] += dp[i][j] * l[i]
    dp[i+1][j] += dp[i][j] * (1-l[i])
    
ans_ = 0
for i in range(0, n//2+1):
  ans_ += dp[n][i]
print(1-ans_)

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


int main()
{
   ll n;
   cin>>n;
   ll arr[n];
   ll sum1{0};
   for(ll i=0;i<n;i++)
   {
      cin>>arr[i];
      sum1 += arr[i];
   }
   ll ans{LONG_MAX};
   ll sum2{};
   for(ll i=0;i<n;i++)
   {
      sum2 += arr[i];
      sum1 -= arr[i];
      ans = min(ans,abs(sum1 - sum2));
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 3528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < k; i++) {
			set.add(p[i]);
		}

		int ans = 1;
		for (int i = k; i < n; i++) {
			set.add(p[i]);
			if (set.first() != p[i - k] || set.last() != p[i]) {
				ans++;
			}
			set.remove(p[i - k]);
		}

		int overK = 0;
		int cnt = 1;
		for (int i = 1; i < n; i++) {
			if (p[i - 1] < p[i]) {
				cnt++;
				if (cnt == k) {
					overK++;
				}
			} else {
				cnt = 1;
			}
		}
		System.out.println(ans - Math.max(overK - 1, 0));
	}
}


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


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

  vector<int> P(N);
  rep(i,N)cin >> P.at(i); 
  
  int ans=0;
  int mn=P.at(0);
  rep(i,N){
    
    mn=min(mn,P.at(i));
    if(mn == P.at(i)) ans++;
  }
  
  cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K; 
  cin >> N >> K;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  int ans = 0;
  REP(i, N){
    if(K == A[i] || (K > A[i] && i != N-1)){
      ans++; K -= A[i];
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  char c;
  cin >> c;
  if (string("aeiou").find(c) != string::npos) cout << "vowel" << endl;
  else cout << "consonant" << endl;

  return 0;
}


Measured memory_bytes: 3580
s = input()

cnt = 0
ans = 0
tmp = 0
check = 0
for x in s:
    cnt += 1
    if x == '<':
        if check != cnt - 1:
            ans -= tmp * (cnt - check - 1)
            tmp = 0
        tmp += 1
        ans += tmp
        check = cnt
    else:
        tmp -= 1
        ans += tmp
        if tmp < 0:
            ans += (cnt -  check + 1)
            tmp += 1

print(ans)


Measured memory_bytes: 9804
a, b, k = map(int, input().split())

if ((b-a)+1 >= 2*k):
   c1 = [print(x) for x in range(a, a+k)]
   c2 = [x for x in reversed(range(b+1-k, b+1))]
   c2.sort()
   for i in c2:
      print(i)
else:
   c = [print(x) for x in range(a, b+1)]


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

#define ll long long
#define met(a, x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
#define ull unsigned long long
#define mp make_pair

using namespace std;
const int mod = 998244353;
const int N = 3e5 + 10;
const int M = 1e6 + 10;
ll a[100];

bool cmp(ll x, ll y) {
    return x > y;
}

ll C[300][300];

void init() {
    met(C, 0);
    C[0][0] = 1;
    for (int i = 1; i <= 50; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    int n, l, r;
    while (cin >> n >> l >> r) {
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        sort(a + 1, a + 1 + n, cmp);
        double ans=0;
        for(int i=1;i<=l;i++){
            ans+=a[i]*1.0;
        }
        ans/=l;
        int num=0,cnt=0;
        for(int i=1;i<=n;i++){
            if(a[i]==a[l]){
                num++;
                if(i<=l){
                    cnt++;
                }
            }
        }
        ll sum=0;
        if(cnt==l){
            for(int i=l;i<=r;i++){
                sum+=C[num][i];
            }
        }else{
            sum+=C[num][cnt];
        }
        cout<<fixed<<setprecision(10)<<ans<<endl<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	getline(cin, S);
	while (S != ".") {
		stack<int> st; //[]をカウント。(が出たら新しい値を積む
		st.push(0);
		bool ans = true;
		int n = 0;
		REP(i, SZ(S)) {
			switch (S[i])
			{
			case '[':
				if (SZ(st) == 0) {
					ans = false;
					break;
				}
				n = st.top();
				st.pop();
				st.push(n + 1);
				break;
			case ']':
				if (SZ(st) == 0) {
					ans = false;
					break;
				}
				if (st.top() == 0) {
					ans = false;
					break;
				}
				n = st.top();
				st.pop();
				st.push(n - 1);
				break;
			case '(':
				st.push(0);
				break;
			case ')':
				if (SZ(st) <= 1) {
					ans = false;
					break;
				}
				if (st.top()!= 0) {
					ans = false;
					break;
				}
				st.pop();
				break;
			default:
				break;
			}
			if (!ans)break;
		}
		
		if (SZ(st) != 1) {
			ans = false;
		}
		else {
			if (st.top() != 0) {
				ans = false;
			}
		}
		if (ans) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
		getline(cin, S);
	}
	return 0;
}



Measured memory_bytes: 3192
// A Dynamic Programming based 
// C# program to find minimum 
// number operations to 
// convert str1 to str2 
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{

    public static void Main()
    {
        var input = int.Parse(Console.ReadLine());
        var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        CC2(input, arr);

    }

    static void CC2(int n, int[] arr)
    {

        int sum = 0;

       for(int i=0;i<n;i++)
        {
            while(arr[i]%2==0)
            {
                arr[i] = arr[i] / 2;
                sum++;
            }
        }

        Console.Write(sum);
    }



}



Measured memory_bytes: 12128
# coding: utf-8


def main():
    _ = int(input())
    tmp = 1
    ans = 'Yes'
    H = list(map(int, input().split()))

    for h in H:
        if tmp < h:
            tmp = h - 1
        elif tmp > h:
            ans = 'No'
            break

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20680
#include <iostream>
#include <cstdio> 
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#ifndef typeof
#define typeof __typeof__
#endif // typeof
 
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); i++)
#define repby(i, a, b, step) for(typeof(b) i = (a); i < (b); i += (step))
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

int gcd(int a, int b) {
  if (a < b)
    return gcd(b, a);

  int m = a % b;
  if (m == 0)
    return b;
  else
    return gcd(b, m);
}

int main(int argc, char **argv)
{
  int a, b;

  while (cin >> a >> b) {
    int g = gcd(a, b);
    cout << g << " " << a/g*b << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),m=in.nextInt(),x=in.nextInt();
		int[][] arr=new int[n][m+1];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=m;j++)
			{
				arr[i][j]=in.nextInt();
			}
		}
		int ans=1000000007;
		for(int i=1;i<(1<<n);i++)
		{
			boolean f=true;
			int[] ar=new int[m];
			int sum=0;
			for(int j=0;j<n;j++)
			{
				if((1&(i>>j))==1)
				{
					sum+=arr[j][0];
					for(int k=1;k<=m;k++)
					{
						ar[k-1]+=arr[j][k];
					}
				}
			}
			for(int j=0;j<m;j++)
			{
				if(ar[j]<x)
					f=false;
			}
			if(f)
			{
				ans=Math.min(ans,sum);
			}

		}
		if(ans==1000000007)
		{
			System.out.println(-1);
		}
		else
		{
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 37392
#include<bits/stdc++.h>
//typedef long long int ll;
using namespace std;
#define sz 29
#define mod 1000000007
int t,n,m,i,j,k,l,arr[sz],brr[sz],crr[sz],x,y,z;
char c[sz][sz];
int main()
{
   // printf("%d\n",(6>>1)&1);
    scanf("%d %d %d",&n,&m,&y);
    for(i=0;i<n;i++)
        scanf("%s",&c[i]);
   for(i=0;i<(1<<n);i++)
   {
       for(j=0;j<(1<<m);j++)
       {
           x=0;
           for(k=0;k<n;k++)
           {
               for(l=0;l<m;l++)
               {
                  if((((i>>k)&1)==0) && (((j>>l)&1)==0) && c[k][l]=='#')
                    x++;
               }
           }
           if(x==y)
            z++;
       }
   }
   printf("%d\n",z);
    return 0;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main(){
    int n;
    cin >> n;
    vector<modint> a(n);
    vector<modint> sum(n+1);
    rep(i, n){
        cin >> a.at(i);
        if(i != 0)sum.at(i) = sum.at(i-1) + a.at(i);
        else sum.at(i) = a.at(i);
    }
    modint ans = 0;
    rep(i, n){
        ans += a.at(i) * (sum.at(n-1) - sum.at(i));
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 4836
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, t;
    cin >> n >> t;
    vector<Pii> dishes(n);
    for(int i=0;i<n;++i){
        cin >> dishes[i].first >> dishes[i].second;
    }
    sort(dishes.begin(), dishes.end());

    int dp[n+1][t+3001];
    fill_n(dp[0], (n+1)*(t+3001), -1);
    dp[0][0] = 0;
    for(int i=0;i<n;++i) {
        for(int j=0;j<t+3001;++j) {
            dp[i+1][j] = dp[i][j];
        }
        for(int j=0;j<t;++j) {
            if(dp[i][j] == -1) continue;
            dp[i+1][j+dishes[i].first] = max(dp[i+1][j+dishes[i].first], dp[i][j] + dishes[i].second);
        }
    }

    cout << *max_element(dp[n]+0, dp[n]+(t+3001)) << endl;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
int n,k;
cin>>n>>k;
int a[n],f[n];
for(int i=0;i<n;i++)cin>>a[i];

for(int i=0;i<n;i++)cin>>f[i];
sort(a,a+n);sort(f,f+n);
int ok=a[0]*f[n-1];
for(int i=1;i<n;i++)ok=max(ok,a[i]*f[n-1-i]);
int ng=-1,mid,c;
while(abs(ok-ng)>1){
  mid=(ok+ng)/2;
  c=0;
  for(int i=0;i<n;i++)c+=max(0LL,a[i]-mid/f[n-1-i]);
  if(c<=k)ok=mid;
  else ng=mid;
}
cout<<ok;
return 0;


}


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

using namespace std;

template <typename T>
struct Tree{
	vector<vector<pair<T,int> > > edge;
	int size;

	Tree(int v){
		size = v;
		edge.resize(v);
	}

	void add_edge(int s,int e){
		edge[s].push_back(make_pair(1,e));
		edge[e].push_back(make_pair(1,s));
	}

	void add_edge(T d,int s,int e){
		edge[s].push_back(make_pair(d,e));
		edge[e].push_back(make_pair(d,s));
	}

	int shortpath(int s,int t){
	    int i,j;
			vector<int> mini(size,INT_MAX);
	    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
	    q.push(make_pair(0,s));
	    while(!q.empty()){
	        pair<int,int> p = q.top();
	        q.pop();
	        if(mini[p.second] != INT_MAX){
	            continue;
	        }
	        mini[p.second] = p.first;
	        for(i = 0;i < edge[p.second].size();i++){
	            if(mini[edge[p.second][i].second] == INT_MAX){
	                q.push(make_pair(p.first+edge[p.second][i].first,edge[p.second][i].second));
	            }
	        }
	    }
	    return mini[t];
	}

	vector<vector<pair<T,int> > > oneside(int p){
		vector<vector<pair<T,int> > > onesideedge(size);
		vector<int> visited(size,0);
		queue<int> q;
		visited[p] = 1;
		q.push(p);
		while(!q.empty()){
			p = q.front();q.pop();
			for(int i = 0;i < edge[p].size();i++){
				if(visited[edge[p][i].second] == 0){
					onesideedge[p].push_back(edge[p][i]);
					q.push(edge[p][i].second);
				}
			}
		}
		return onesideedge;
	}

	vector<int> cul_all_distance(int r){
	    vector<int> d(size,-1);
	    d[r] = 0;
	    queue<int> q;
	    q.push(r);
	    while(!q.empty()){
            int p = q.front(); q.pop();
            for(int i = 0;i < edge[p].size();i++){
                if(d[edge[p][i].second] == -1){
                    d[edge[p][i].second] = d[p] + 1;
                    q.push(edge[p][i].second);
                }
            }
	    }
	    return d;
	}

	int maxlength(){
	    vector<int> deepth = cul_all_distance(0);
	    int ma=0,mi=0;
	    for(int i = 0;i < size;i++) if(deepth[i] > ma) { ma = deepth[i]; mi = i;}
	    deepth = cul_all_distance(mi);
	    ma = 0;
	    for(int i = 0;i < size;i++) if(deepth[i] > ma) ma = deepth[i];
	    return ma;
	}
};

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    Tree<int> t(n);
    int a,b;
    for(int i = 0;i < n-1;i++){
        cin >> a >> b;
        t.add_edge(a-1,b-1);
    }
    long long ans = t.maxlength();
    if(ans%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 15088
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn z_algorithm<T: Eq>(s: &[T]) -> Vec<usize> {
    let len = s.len();
    let mut a = vec![0; len];
    a[0] = len;
    let mut i = 1;
    let mut j = 0;
    while i < len {
        while i + j < len && s[j] == s[i + j] {
            j += 1;
        }
        a[i] = j;
        if j == 0 {
            i += 1;
            continue;
        }
        let mut k = 1;
        while i + k < len && k + a[k] < j {
            a[i + k] = a[k];
            k += 1;
        }
        i += k;
        j -= k;
    }
    a
}

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        a: [u32; n],
        b: [u32; n],
    }
    let mut x = Vec::with_capacity(n);
    let mut y = Vec::with_capacity(n);
    for a in [(&mut x, &a), (&mut y, &b)].iter_mut() {
        for (p, q) in a.1.iter().zip(a.1.iter().cycle().skip(1)) {
            a.0.push(*p ^ *q);
        }
    }
    let mut c = Vec::with_capacity(3 * n + 1);
    c.extend_from_slice(&y);
    c.push(std::u32::MAX);
    c.extend_from_slice(&x);
    c.extend_from_slice(&x);
    let z = z_algorithm(&c);
    for k in 0..n {
        if z[n + 1 + k] >= n {
            let x = a[k] ^ b[0];
            writeln!(out, "{} {}", k, x).ok();
        }
    }
}

fn main() {
    run();
}


Measured memory_bytes: 25720
N, A, B = map(int, input().split())

diff = B - A

_a, mod = divmod(diff, 2)

is_diff_even = (mod == 0)

if is_diff_even:
    print(diff // 2)
else:
    left = A
    right = B

    # distance
    if (left - 1) < (N - right):
        print((left - 1) + 1 + ((right - ((left - 1) + 1) - 1) // 2))
    else:
        # 右のほうが近い
        print((N - right) + 1 + ((N - (left + (N-right+1))) // 2))

Measured memory_bytes: 3064
#include<stdio.h>
#define MAXN 1001

int book[101];
struct desk
{
    int num;
    int b[31];
}d[11];
struct student
{
    int cur;
    int num;
    int b[51];
}s[101];
int q[1001];
int m,c,n,elapse;

int main(void)
{
    int i, j, k, t, maxbook, maxtime, cur_book, take_book;
    while(scanf("%d %d %d",&m,&c,&n), m||c||n)
    {
        k=0;elapse=0;
        for(i=1;i<=m;i++)
            d[i].num=0;
        for(i=0;i<=100;i++)
            book[i]=m+1;
        for(i=0;i<n;i++)
        {
            scanf("%d",&s[i].num);
            for(j=0;j<s[i].num;j++)
                scanf("%d",&s[i].b[j]);
            s[i].cur=0;
            if(s[i].num)
                q[k++]=i;
        }
        j=0;
        while(j!=k)
        {
            cur_book = s[q[j]].b[s[q[j]].cur++];
            elapse += book[cur_book];
            if(book[cur_book]!=m+1)
            {
                t=book[cur_book];
                for(i=0; i<d[t].num; i++)
                    if(d[t].b[i]==cur_book)
                        break;
                for( ; i<d[t].num; i++)
                    d[t].b[i]=d[t].b[i+1];
                d[t].num--;
            }
            if(d[1].num==c)
            {
                i=2;
                while(i<=m && d[i].num==c)
                    i++;
                if(i>m)
                    book[cur_book]=m+1,elapse=elapse+m+1;
                else
                    d[i].b[d[i].num++]=cur_book, book[cur_book]=i, elapse+=i;
                take_book=d[1].b[0];
                for(i=0; i<d[1].num; i++)
                    d[1].b[i]=d[1].b[i+1];
                elapse++;
                d[1].num--;
                i=2;
                while(i<=m && d[i].num==c)
                    i++;
                if(i>m)
                    book[take_book]=m+1, elapse=elapse+m+1;
                else
                    d[i].b[d[i].num++]=take_book, book[take_book]=i, elapse+=i;
                elapse += book[cur_book];
                if(book[cur_book]!=m+1)
                    d[book[cur_book]].num--;
            }
            d[1].b[d[1].num++]=cur_book;
            book[cur_book]=1;
            elapse++;
            if(s[q[j]].cur<s[q[j]].num)
                q[k]=q[j], k=(k+1)%MAXN;
            j=(j+1)%MAXN;
        }
        printf("%d\n",elapse);
    }
    return 0;
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



int main(){

  int n,k;
  cin >> n >> k;
  set<int> d;
  int td;
  rep(i,k){
    cin >> td;
    d.insert(td);
  }
  //  cout << d[0] << endl;
  vector<int> d2;
  rep(i,10){
    if(d.count(i)==0)  d2.pb(i);
  }
  int ans = INT_MAX;
  rep(l1,10-k) rep(l2,10-k) rep(l3,10-k) rep(l4,10-k) rep(l5,10-k){
    int t=d2[l1]+d2[l2]*10+d2[l3]*100+d2[l4]*1000+d2[l5]*10000;
    //    cout << t << endl;
    if(n<=t) ans = min(t,ans);
  }
  rep(l1,10-k) rep(l2,10-k) rep(l3,10-k) rep(l4,10-k){
    int t=d2[l1]+d2[l2]*10+d2[l3]*100+d2[l4]*1000;
    //    cout << t << endl;
    if(n<=t) ans = min(t,ans);
  }
  rep(l1,10-k) rep(l2,10-k) rep(l3,10-k){
    int t=d2[l1]+d2[l2]*10+d2[l3]*100;
    if(n<=t) ans = min(t,ans);
  }
  rep(l1,10-k) rep(l2,10-k){
    int t=d2[l1]+d2[l2]*10;
    if(n<=t) ans = min(t,ans);
  }
  rep(l1,10-k){
    int t=d2[l1];
    if(n<=t) ans = min(t,ans);
  }
  

  
  
  cout << ans << endl;
  
    
  
  return 0;

}


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

mod = 10**9+7

cnt = [0]*60
bt = [0]*60

for a in A:
    for i in range(60):
        cnt[i] += (a>>i)&1

ans = 0
for i in range(60):
    x = cnt[i]
    y = x*(N-x)%mod
    ans += y*2**i
    ans %= mod

print(ans)

Measured memory_bytes: 117988
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int a,b,t;
    cin>>a>>b>>t;
    OUT(b*(t/a));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    vector<int> a(n),b(n);
    vector<int> cnt(n+1);
    vector<vector<int>> p(n+1);
    int cnt_a[n+1]={};
    int cnt_b[n+1]={};
    int r[n+1]={};
    int now[n+1]={};
    int sum[n+1]={};
    int rum[n+1]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        cnt_a[a[i]]++;
        //rum[a[i]]++;
        cnt[a[i]]++;
        p[a[i]].push_back(i);
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        cnt_b[b[i]]++;
        //sum[b[i]]++;
        cnt[b[i]]++;
    }
    for(int i=0;i<=n;i++){
        if(cnt[i] > n){
            cout << "No\n";
            return 0;
        }
    }
    priority_queue<array<int,2>> pq1;
    priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>>> pq2;
    for(int i=1;i<=n;i++){
        if(n-cnt[i] == n)continue;
        pq1.push({n-cnt[i],i});
        pq2.push({n-cnt[i],i});
        now[i] = n - cnt[i];
    }
    for(int i=0;i<n;i++)b[i] = 0;
    while(pq2.size()){
        array<int,2> t = pq2.top();
        //cerr << t[0] << " " << t[1] << endl;
        pq2.pop();
        if(t[0] != now[t[1]])continue;
        if(sum[t[1]] == cnt_b[t[1]])continue;
        vector<array<int,2>> v;
        while(pq1.size()){
            // cerr<<"a" << endl;
            array<int,2> y = pq1.top();
            pq1.pop();
            if(y[0] != now[y[1]])continue;
            if(rum[y[1]] == cnt_a[y[1]])continue;
            if(y[1] == t[1]){
                v.push_back(y);
                continue;
            }
            //cerr << "y " << y[0] << " " << y[1] << endl;

            b[p[y[1]][r[y[1]]]] = t[1];
            r[y[1]]++;
            now[y[1]]++;
            now[t[1]]++;
            sum[t[1]]++;
            rum[y[1]]++;
            pq2.push({t[0]+1, t[1]});
            pq1.push({t[0]+1, t[1]});
            pq1.push({y[0]+1, y[1]});
            pq2.push({y[0]+1, y[1]});
            break;
        }
        for(auto i:v){
            pq1.push(i);
        }
    }
    cout << "Yes\n";

    for(int i=0;i<n;i++){
        cout << b[i] << " ";
        assert(a[i] != b[i]);
    }
    cout << endl;

}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/
/*prime_test=================================================*/
bool prime_test(int num) {
    if (num < 2) return false;           // 0 と 1 除く
    else if (num == 2) return true;      //2はtrue
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    int sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0) return false;  // 素数ではない
    }
    // 素数である
    return true;
}

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    int t = 0;
    for(int i = 11; i <= 55555; i += 5) {
        if(t==n) return 0;
        if(prime_test(i)) {
            ++t;
            cout << i << (t==n ? '\n' : ' ');
        }
    }
}

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

int main()
{
    int n,i,sum=0;
    int a[105]={0},b[105]={0},c[105]={0};
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];

    for(i=0;i<n;i++)
        cin>>b[i];

    for(i=0;i<n;i++)
        c[i]=a[i]-b[i];

    sort(c,c+n);
    for(i=n-1;i>=0;i--)
    {
        if((c[i]+sum)>sum)
            sum+=c[i];
        else
            break;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  H , W ;
  cin >> H >> W;
  vector <bool> gyou(H,false) , retu(W, false);
  vector <string> s(H) ;
  for ( int i=0 ; i<H ; i++ ){
    cin >> s[i] ;
  }
  for ( int i=0 ; i<H ; i++){
    for (int j= 0 ; j <W ;j++){
      if (s.at(i).at(j) == '#' ) {
        gyou.at(i) = true ;
        retu.at(j) = true ;
      }
    }
  }
    for ( int i=0 ; i<H ; i++){
    for (int j= 0 ; j <W ;j++){
      if ( gyou.at(i) && retu.at(j)) {
      cout << s.at(i).at(j)  ;
      }
    }
      cout << endl;
  }
}

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

int main(){
  int a[3] ;
  cin >> a[0] >> a[1] >> a[2];

  int num[110] = {0};
  for(int i = 0 ; i <3  ; i ++){
    num[a[i]]++;
  }

  int sum = 0 ;
  for(int i = 0 ; i< 110; i++){
    if(num[i]) ++sum;
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        long n = nl(), m = nl();
 
        long ans = 0;
 
        long simple = Math.min(n, m / 2);
        ans += simple;
        n -= simple;
        m -= simple * 2;
 
        ans += m / 4;
 
        out.println(ans);
    }
 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;
    cin >> n;
    cout << fixed << setprecision(10) << (n-(n/2))/(float)n << endl;
    return 0;
}	

Measured memory_bytes: 256
/* Nested Controls II */
#include <stdio.h>

int main(void) {

int n, x;
int i, j, k;

while (1) {
scanf("%d %d", &n, &x);

if ( n == 0 && x == 0) break;

int conb = 0;

for ( i = 1    ; i <= n - 2; i++) {
for ( j = i + 1; j <= n - 1; j++) {
for ( k = j + 1; k <= n    ; k++) {
        if ( i + j + k == x) conb++;
/*      printf("%d %d %d %d\n", i, j, k, x); */
}}}
printf("%d\n", conb);
}
return 0;
}

Measured memory_bytes: 600