akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll num[MAX];



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


  cin >> n;
  rep(i, n) {
    cin >> tmp;
    num[tmp]++;
  }
  ll cur = 0;
  rep(i, MAX) {
    cur += num[i];
    if (cur == n / 2) ans++;
  }
  cout << ans << endl;




  return 0;
}

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

int main(){
	int a,b,c,n,r;
	while(cin>>a>>b>>c,a|b|c){
		cin>>n;
		if(a>b)swap(a,b);
		if(b>c)swap(b,c);
		while(n--){
			cin>>r;
			cout<<(a*a+b*b<4*r*r?"OK":"NA")<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  vector<vector<int>> a(3, vector<int>(3));
  vector<vector<bool>> ans(3, vector<bool>(3, false));
  
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int b;
    cin >> b;
    
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(b == a.at(i).at(j)) ans.at(i).at(j) = true;
      }
    }
  }
  
  if(ans.at(0).at(0) == true && ans.at(0).at(1) == true && ans.at(0).at(2) == true) cout << "Yes" << endl;
  else if(ans.at(1).at(0) == true && ans.at(1).at(1) == true && ans.at(1).at(2) == true) cout << "Yes" << endl;
  else if(ans.at(2).at(0) == true && ans.at(2).at(1) == true && ans.at(2).at(2) == true) cout << "Yes" << endl;
  else if(ans.at(0).at(0) == true && ans.at(1).at(0) == true && ans.at(2).at(0) == true) cout << "Yes" << endl;
  else if(ans.at(0).at(1) == true && ans.at(1).at(1) == true && ans.at(2).at(1) == true) cout << "Yes" << endl;
  else if(ans.at(0).at(2) == true && ans.at(1).at(2) == true && ans.at(2).at(2) == true) cout << "Yes" << endl;
  else if(ans.at(0).at(0) == true && ans.at(1).at(1) == true && ans.at(2).at(2) == true) cout << "Yes" << endl;
  else if(ans.at(0).at(2) == true && ans.at(1).at(1) == true && ans.at(2).at(0) == true) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
  
}

Measured memory_bytes: 3616
X,K,D = map(int,input().split())
ans = 0
if abs(X) > K * D:
    ans = abs(abs(X) - K * D)
else:
    if (K - (abs(X) // D)) % 2 == 0:
        ans = abs(abs(X) - (abs(X) // D) * D)
    else:
        ans = abs(abs(X) - (abs(X) // D + 1) * D)
print(ans)


Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int x = sc.nextInt();
            int y = sc.nextInt();

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

            if (x < y)
                System.out.println(x + " " + y);
            else
                System.out.println(y + " " + x);
        }
    }
}



Measured memory_bytes: 36148
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	if (k != 1) cout << n - k << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import math
n,h=map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
A.sort(reverse=True)
B.sort(reverse=True)
amax=A[0]
while B[-1]<amax:
    B.pop()
S=0
if sum(B)>=h:
    for i in range(n):
        S+=B[i]
        if S>=h:
            print(i+1)
            break
else:
    h-=sum(B)
    print(math.ceil(h/amax)+len(B))


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

int main(){
  int N;
  cin >> N;
  string S[N];
  rep(i, N){
    cin >> S[i];
  }
  rep(i, N){
    sort(S[i].begin(), S[i].end());
  }
  long long ans = 0;
  map<string, long long> X;
  rep(i, N){
    X[S[i]]++;
  }
  for (auto x : X){
    long long n = x.second;
    ans += (n * (n-1) / 2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 14516
MAXN = 123456 * 2
sieve = [1 for i in range(MAXN+1)]
sieve[0] = sieve[1] = 0
n = 2
while n*n <= MAXN:
    if sieve[n] == 1:
        for nn in range(2*n,MAXN+1,n):
            sieve[nn] = 0
    n += 1
cums = [0]
for s in sieve:
    cums.append(cums[-1] + s)

while True:
    N = int(input())
    if N == 0: break
    ans = cums[2*N+1] - cums[N+1]
    print(ans)

Measured memory_bytes: 17252
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#define llint long long int

int main(void){
  int q;
  std::cin >> q;

  std::multiset<llint> lower;
  std::multiset<llint> upper;
  llint center = 1e12;

  llint a_distance = 0;
  llint b_total = 0;
  for(int i=0; i<q; i++){
    llint patt;
    std::cin >> patt;
    if(patt==1){
      llint a, b;
      std::cin >> a >> b;
      b_total+=b;
      
      if(center==1e12){
	center = a;
      }else if(center < a){
	a_distance += a-center;
	upper.insert(a);
      }else{
	a_distance += center-a;
	lower.insert(a);
      }

      
      if(upper.size() > lower.size() + 1){
	llint prev_center = center;
	lower.insert(center);
	center = *(upper.begin());
	upper.erase(upper.begin());
	a_distance += (center-prev_center)*(lower.size() - 1 - upper.size());
      }else if(upper.size() < lower.size()){
	llint prev_center = center;
	upper.insert(center);
	center = *(lower.rbegin());
	lower.erase(std::prev(lower.end()));
	a_distance += (prev_center-center)*(upper.size() - lower.size() - 1);
      }

    }else{
      // output
      std::cout << center << " " << a_distance+b_total << std::endl;
      //std::cout << a_distance << " " << b_total << std::endl;
    }

  }
  return 0;

}



Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int f[100005],h[100005];
int main(){
	int n;
	cin>>n;;
	for(int i=1;i<=n;i++){
	    cin>>h[i];
	}
	f[1]=0;
	f[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
	    f[i]=min(f[i-2]+abs(h[i]-h[i-2]),f[i-1]+abs(h[i]-h[i-1]));
	}
	cout<<f[n];
}


Measured memory_bytes: 4368
N,M,K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(N):
	A[i+1] += A[i]
for i in range(M):
	B[i+1] += B[i]

b = M
r = 0
for i,a in enumerate(A):
	if a > K:
		break
	while a+B[b]>K and b>=0:
		b -= 1
	r = max(r, i+b)

print(r)

Measured memory_bytes: 114268
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
ll n,p;
 
int main(){
	cin>>n>>p;
	ll res=1;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}
	for(ll i=2;i*i<=p;i++) if(p%i==0){
		ll t=0;
		while(p%i==0){
			p/=i;
			t++;
		}
		for(int j=0;j<t/n;j++) res*=i;
	}
	cout<<res<<endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

// const ll N = 3e5 + 10, MOD = 998244353*1e9, A = 100;
const ll N = 3e5 + 10, MOD = 998244353, A = ll(1e18) % MOD;
ll Apow[N];

const ll HALF = (MOD+1)/2;

vl transform(vl A, bool inverse = false) {
	ll N = sz(A);
	vl B(N,0);
	for(ll p = 1; p < N; p *= 2){
		FOR(i,0,N)B[i] = (((i&p)?-A[i]:A[i]) + A[i^p]) % MOD;
		if(inverse) FOR(i,0,N) B[i] = (B[i] * HALF)%MOD;
		swap(A,B);
	}
	return A;
}

vl multiply(vl p, vl q) {
	int N = 1;
	while(N < max(sz(p), sz(q))) N *= 2;
	p.resize(N, 0);
	q.resize(N, 0);
	p = transform(p),	q = transform(q);
	vector<ll> pq(N);
	FOR(i,0,N) pq[i] = (p[i] * q[i]) % MOD;
	return transform(pq, true);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	Apow[0] = 1;
	FOR(i,1,N) Apow[i] = A*Apow[i-1] % MOD;

	ll n; cin >> n;
	
	ll N = 1;
	while (N < n) N *= 2;

	vl u(N);
	u[0] = 1;
	
	FOR(dim,0,3) {
		ll m; cin >> m;
		vvl adj(n);
		while (m--) {
			ll a, b;
			cin >> a >> b;
			a--, b--;
			if (a > b) swap(a,b);
			adj[a].pb(b);
		}
	
		vl col(n);
		FORD(i,0,n) {
			set<ll> s;
			for (ll j: adj[i]) s.insert(col[j]);
			while (s.count(col[i])) col[i]++;
		}

		vl v(N);
		FOR(i,0,n) v[col[i]] = (v[col[i]] + Apow[i+1]) % MOD;
		
		u = multiply(u,v);

		// cerr << u[0] << " " << u[1] << endl;
	}

	ll res = u[0];
	if (res < 0) res += MOD;
	cout << res << endl;
}



Measured memory_bytes: 15664
N,M=map(int,input().split())
X=[int(i) for i in input().split()]
X.sort()
count=[]
sum=0
if N<M:
  for i in range(M):
    if i != 0:
      count.append(X[i]-get)
      sum+=count[i-1]
    get=X[i]
  count.sort(reverse=True)
  
  for i in range(N-1):
    sum-=count[i]
print(sum)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  int min_cnt = H[0];
  rep(i, N) {
    mins(min_cnt, H[i]);
  }
  int answer {min_cnt};
  if (H[0] > min_cnt) {
    answer += H[0] - min_cnt;
  }
  srep(i, 1, N) {
    if (H[i] > H[i-1]) {
      answer += H[i] - H[i-1];
    }
  }
  cout << answer << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

typedef int INT;
set <INT> S;
const int SIZE = 16777216;
bool HA[SIZE];

inline INT get( char c ) {
    char T[5] = "ACGT";
    for ( INT i = 0; i < 4; ++ i ) {
        if ( c == T[i] ) return i + 1;
    }
    return 0;
}

inline INT get( char *s ) {
    INT n = strlen( s );
    INT sum = 0;
    INT t = 1;
    for ( INT i = 0; i < n; ++ i ) {
        sum += get( s[i] ) * t;
        t *= 4;
    }
    return sum;
}

inline void insert( char *s ) {
    S.insert( get( s ) );
}

inline bool find( char *s ) {
    return S.count( get( s ) ) > 0;
}

int main() {
    INT n, sum, t, c;
    while ( scanf("%d", &n) != EOF ) {
        for ( register INT i = 0; i < SIZE; ++ i ) HA[i] = false;
        while ( getchar() != '\n' );
        S.clear();
        for ( register INT i = 0; i < n; ++ i ) {
            sum = 0;
            t = 1;
            bool flag = getchar() == 'i';
            while ( ( c = getchar() ) != ' ' );
            while ( ( c = get( getchar() ) ) != 0 ) {
                sum += c * t;
                t *= 4;
            }
            if ( flag ) {
                S.insert( sum );
            } else {
                puts( S.count( sum ) ? "yes" : "no" );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 23000
from sys import exit, stdin

A, B = [int(_) for _ in stdin.readline().rstrip().split()]

def oddsolve(x):
    return int((x+1)/2)%2

def solve(x):
    if x % 2 == 1:
        return oddsolve(x)
    else:
        return oddsolve(x+1) ^ (x+1)

print(solve(B) ^ solve(A-1))

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

using namespace std;

int main(void)
{
	vector<int>H;
	vector<int>Road;
	
	int N, M;

	cin >> N >> M;

	for (int i = 0; i < N; i++)
	{
		int x;
		cin >> x;
		H.push_back(x);
	}

	vector<int>Flag(N, 1);

	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		if (H[a-1] <= H[b-1])
		{
			Flag[a-1] = 0;
		}

		if (H[b-1] <= H[a-1])
		{
			Flag[b-1] = 0;
		}
	}


	int sum=0;

	for (auto x : Flag) 
	{
		if (x == 1)sum++;
		//cout << x;
	}

	cout << sum << endl;

}

Measured memory_bytes: 4184
n=int(input())
t,a=map(int,input().split())
h=[int(i) for i in input().split()]
ans=float("inf")
for i in range(len(h)):
    if ans>abs(a-t+h[i]*0.006):
        ans=abs(a-t+h[i]*0.006)
        anss=i
print(anss+1)

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, m, a, b, br = 0;
	bool provera;
	cin >> n >> m;
	vector<int> nadmorskaVisina(n);
	vector<vector<int>> v(n);
	for (int i = 0; i < n; i++)
		cin >> nadmorskaVisina[i];
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
	{
		provera = true;
		for (auto x : v[i])
			if (nadmorskaVisina[x] >= nadmorskaVisina[i])
			{
				provera = false;
				break;
			}
		if (provera)
			br++;
	}
	cout << br;
}


//freopen("testcases/17.in", "r", stdin);
//freopen("output.txt", "w", stdout);


Measured memory_bytes: 8752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <iomanip>


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

	std::string str = "";

	while (n != 0) {
		int r = n % 2;
		if (r < 0) {
			r += 2;
		}

		n = (n - r) / (-2);

		str += (char)('0' + r);
	}

	std::reverse(str.begin(), str.end());

	if (str == "") {
		str = "0";
	}

	std::cout << str << std::endl;

	return 0;
}

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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

void solve(int &test) {
    int n;
    cin >> n;
    int cur = 0;
    for(int i = 0; i < n-1; i++){
        int u, v;
        cin >> u >> v;
        if(u > v)swap(u, v);
        v = n-v+1;
        cur += v*u;
    }
    int tot = 0;
    for(int i = 1; i <= n; i++){
        int j = n-i+1;
        tot += (j+1)*j/2;
    }
    cout << tot-cur << endl;
}

signed main(){

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

    int t = 1;

    start = clock(); 

    cout << fixed << setprecision(2);
    
   
     
    for(int i = 1; i <= t; ++i){
        solve(i);
    }
    cerr << time(start);
    return 0;
}

Measured memory_bytes: 3816
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

string S, T;

int check(int i) {
	int result = 0;
	for (int j=0; j<T.size(); j++) {
		if (S[i+j] != T[j]) result++;
	}
	return result;
}

int main() {

	cin >> S >> T;

	int ans = INF;

	for (int i=0; i<=S.size() - T.size(); i++) {
		ans = min(ans, check(i));
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> K(M);
    vector<vector<int>> S(M, vector<int>(N));
    vector<int> P(M);
    for (int i = 0; i < M; i++) {
        cin >> K[i];
        for (int j = 0; j < K[i]; j++) cin >> S[i][j];
    }
    for (int i = 0; i < M; i++) cin >> P[i];

    bool exist = false;
    int ans = 0;
    for (int bit = 0; bit < (1 << N); bit++) { //2^n通りの全探索
        int sum = 0;
        vector<int> res = {};
        for (int i = 0; i < N; i++) {
            if (bit & (1 << i)) res.push_back(i + 1);
            else res.push_back(0);
        }
        for (int i = 0; i < M; i++) {
            int cnt = 0;
            for (int j = 0; j < K[i]; j++) {
                auto result = find(res.begin(), res.end(), S[i][j]);
                if (result != res.end()) cnt++;
            }
            if (cnt % 2 == P[i]) sum++;
            
        }
        if (sum == M) ans++;
    }

    cout << ans << endl;
}

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 max = -1;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            if( max<tmp ) max = tmp;
            sum+= tmp;
        }
        System.out.println( max<sum-max? "Yes" : "No");
    }
}


Measured memory_bytes: 21844
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1e9;

int f(string& s, string& t){
  for(int i=min(SZ(t),SZ(s));i>=1;--i){
	if(t.substr(0,i) == s.substr(SZ(s)-i,i)){
	  return i;
	}
  }
  return 0;
}

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

  int N;
  while(cin >> N,N){
	VS vs, vs_(N);
	REP(i,N) cin >> vs_[i];
	vector<bool> use(N, true);
	REP(i,N){
	  REP(j,N){
		if(i == j) continue;
		if(vs_[i].find(vs_[j], 0) != string::npos){
		  use[j] = false;
		}
	  }
	}
	REP(i,N) if(use[i]) vs.PB(vs_[i]);
	N = SZ(vs);

	int G[20][20];
	for(int i=0;i<N;++i){
	  for(int j=0;j<N;++j){
		if(i == j) continue;
		G[i][j] = f(vs[i], vs[j]);
	  }
	}

	VVI dp(1<<N, VI(N, -INF));
	for(int i=0;i<N;++i)
	  dp[1<<i][i] = 0;
	for(int b=1;b<(1<<N);++b){
	  for(int i=0;i<N;++i){
		if(b >> i & 1){
		  for(int j=0;j<N;++j){
			if(b >> j & 1) continue;
			dp[b|(1<<j)][j] = max(dp[b|(1<<j)][j], dp[b][i] + G[i][j]);
		  }
		}
	  }
	}

	int ans = 0;
	for(int i=0;i<N;++i)
	  ans = max(ans, dp[(1<<N)-1][i]);
	REP(i,N) ans -= SZ(vs[i]);
	cout << -ans << endl;
  }
  return 0;
}

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

int main(){
    int d[100000];
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        scanf("%d",&d[i]);
    }
    sort(d, d + n);

    cout << d[n/2]-d[n/2-1] << endl;

}

Measured memory_bytes: 640
from math import ceil
N = int(input())
S = input()
ans = [0]*1000
one = [0]*10
two = [0]*100

for s in S:
    s = int(s)
    for i in range(10):
        for j in range(10):
            if two[i*10+j]//1:
                ans[i*100+j*10+s] = 1 
            else:
                if one[i]//1 and two[i*10+s] == 0:
                    two[i*10+s] = 0.5
                elif one[s] == 0:
                    one[s] = 0.5        
    one = list(map(lambda x: ceil(x), one))
    two = list(map(lambda x: ceil(x), two))

print(sum(ans))    

Measured memory_bytes: 81920
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include <map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


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

	vector<int> dp(n + 1, 0);
	for (int x = 1; x < 143; x++) {
		for (int y = 1; y < 143; y++) {
			for (int z = 1; z < 143; z++) {
				int a = x * x + y * y + z * z + x * y + y * z + z * x;
				if (a <= n) {
					dp[a]++;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << dp[i] << endl;
	}

}


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


int check(const int& m, const int& N, const std::vector<int>& a)
{
    std::map<int, int> mp;
    for (int i = 1; i < N; i++) {
        if (a.at(i - 1) < a.at(i)) {
            continue;
        }
        if (m == 1) {
            return false;
        }
        int pos = a.at(i);
        while (true) {
            if (mp[pos] < m - 1) {
                mp[pos]++;
                mp.erase(mp.upper_bound(pos), mp.end());
                break;
            }
            pos--;
            if (pos == 0) {
                return false;
            }
        }
    }
    return true;
}

int main(void)
{
    int N;
    std::cin >> N;
    std::vector<int> as(N);
    for (int i = 0; i < N; i++) {
        std::cin >> as.at(i);
    }
    int l = 0, r = N;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m, N, as)) {
            r = m;
        } else {
            l = m;
        }
    }
    std::cout << r << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll ans=0;
    int i;
    for(i=0;i<(int)s.size();i++){
        ans+=s[i]-'0';
    }
    if(ans%9==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3756
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

a.sort(reverse = True)

if n % 2 == 0:
    print((sum(a[:n//2-1]) - sum(a[n//2+1:]))*2 + a[n//2-1] - a[n//2])
else:
    print(max((sum(a[:n//2]) - sum(a[n//2+2:]))*2 - sum(a[n//2:n//2+2]), (sum(a[:n//2-1]) - sum(a[n//2+1:]))*2 + sum(a[n//2-1:n//2+1])))


Measured memory_bytes: 7444
N = int(input())
P = list(map(int,input().split()))
"""
1以上前提
配列番号(j<=i)であるとき
配列要素がi<=jとなる個数

1~iまでで中身が降順であるかどうか
すなわち、探索範囲での先頭が最小かどうかを調べればいい。

問題文3行目より、必ずj,iは1番目を探索しなければならない。
"""
res = 0
before = 10**9 
for i in range(N):
    if P[i] < before:
        before = P[i]
        res += 1
else:
    print(res)


Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define REPI(i, a, n)	for(ll (i)=(a);(i)<(int)(n);(i++))
#define REP(i,n) REPI(i,0,n)
#define REP1(i,n) for(ll (i)=1;(i)<=(n);(i++))
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;
 
	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
 
template<typename T>
int contains(std::vector<T> vec, int number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll fact(ll n) {
	ll m;
	if (n == 0) {
		return 1;
	}
	m = fact(n - 1);
	return n * m;
}
 
ll Combination(unsigned long long n, unsigned long long r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
 
struct vec {
	ll x, y;
 
	bool operator == (const vec &v) const{
		return x == v.x && y == v.y;
	}
 
};
 
namespace std {
	template<>
	class hash<vec> {
	public:
		size_t operator () (const vec& p) const { return p.x%SIZE_MAX; }
	};
}

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int t = A / D + (A % D == 0 ? 0 : 1);
	int a = C / B + (C % B == 0 ? 0 : 1);
	if(a > t){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
ll gcd( ll a, ll b ) {
  if ( b == 0 ) return a;
  return gcd( b, a % b );
}
 
int main() {
  ll a,b;
  while ( cin >> a >> b ) {
  ll ans = gcd(a,b);
  ll ans2 = a * b / ans;
  cout << ans << " " << ans2 << endl;
  }
  return 0;
}

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

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

  int a = 1;
  for (int i = 0; i < N; i++) {
    if (a < K) {
      a *= 2;
    } else {
      a += K;
    }
  }
  cout << a << endl;
}


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
//		String[] tmpArray = input.split(" ");
//		int n = Integer.parseInt(tmpArray[0]);
//		int a = Integer.parseInt(tmpArray[1]);
//		int b = Integer.parseInt(tmpArray[2]);
		char[] array = input.toCharArray();
		array[3]++;
		
		System.out.println(array);
	}

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vi a(N);
    in(N,a);
    int k = 1;
    int ans = 0;
    
    rep(i,N) {
        if(a[i] == k) k++;
        else ans++;
    }
    
    if(ans == N) cout << -1 << endl;
    else cout << ans << endl;
    
    

    return 0;
}


Measured memory_bytes: 3988
from collections import deque

y = [1,1,1,0,0,-1,-1,-1]
x = [-1,0,1,-1,1,-1,0,1]

def main():
    w,h = 0,0
    c = []

    def check(i,j):
        return 0<=i and i<h and 0<=j and j<w

    def bfs(a,b):
        d = deque()
        d.append([a,b])
        while len(d):
            i,j = d.popleft()
            if not check(i,j):continue
            if c[i][j]==0:continue
            c[i][j]=0
            for k in range(8):
                d.append([i+y[k],j+x[k]])

    while True:
        w,h = map(int,input().split())
        if w==0 and h==0: break
        c = []
        res = 0
        for _ in range(h):
            c.append(list(map(int,input().split())))
        for i in range(h):
            for j in range(w):
                if c[i][j]==1:
                    bfs(i,j)
                    res+=1
        print(res)

if __name__ == '__main__':
    main()




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

int main(){
    int N;
    cin>>N;
    
    map<int,int> A;
    ll sum=0;
    rep(i,N){
        int a;
        cin>>a;
        
        sum+=a;
        ++A[a];
    }
    
    int Q;
    cin>>Q;
    rep(q,Q){
        int b,c;
        cin>>b>>c;
        
        sum+=A[b]*(c-b);
        A[c]+=A[b];
        A[b]=0;
        
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 8056
def solve():
    n, m = map(int, input().split())
    if m == 0:
        if n == 1:
            return 0
        else:
            return 10 ** (n-1)

    nums = [-1] * n
    for _ in range(m):
        s, c = map(int, input().split())
        if nums[s-1] != -1 and nums[s-1] != c:
            return -1
        else :
            nums[s-1] = c
    
    if nums[0] == 0 and n != 1:
        return -1
    
    start, end = 0, 10 ** (n)-1
    if n != 1:
        start = 10 ** (n-1)
        
    for v in range(start, end + 1):
        s = str(v)
        for i in range(n):
            if nums[i] != -1 and nums[i] != int(s[i]):
                break
        else :
            return v
    return -1

print(solve())

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{long long n;
cin>>n;
vector <char> c(26);
for(int i =1;i<26;i++)
c[i] = 'a'+i-1;
c[0] = 'z';
// for(auto i:)
string s;
while(n>0)
{    n--;
    int temp = n%26;
    s=(char)(temp+'a')+s;
    n/=(long long)26;
//    cout<<c[temp];

}
cout<<s<<endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n;cin >> n;
  vll a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll ans = 0;
  REP(i, 30) {
    ll tmp = 0;
    vll c(n);
    REP(j, n) {
      c[j] = b[j] % (1ll<<(i+1));
    }
    sort(ALL(c));

    REP(j, n) {
      ll atmp = a[j] % (1 << (i+1));
      tmp += (lower_bound(ALL(c), 2*(1ll<<i) - atmp) - lower_bound(ALL(c), (1ll<<i) - atmp)) +
             (lower_bound(ALL(c), 4*(1ll<<i) - atmp) - lower_bound(ALL(c), 3*(1ll<<i) - atmp));
      tmp %= 2;
    }
    if(tmp) ans += 1ll<<i;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4992
object Main extends App {

  import scala.io.StdIn.readLine
  val arr = readLine().trim.split("")
  var n = 0
  var w = 0
  var s = 0
  var e = 0
  arr.foreach { a =>
    if (a == "N") n = n + 1
    else if (a == "W") w = w + 1
    else if (a == "S") s = s + 1
    else if (a == "E") e = e + 1
    else ()
  }

  if (((n == 0 && s == 0) || (n != 0 && s != 0)) && ((e == 0 && w == 0) || (e != 0 && w != 0))) {
    println("Yes")
  } else {
    println("No")
  }

}


Measured memory_bytes: 21448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

template<typename T>
vector<T> lis(vector<T> a) {
  vector<T> b;
  b.eb(a[0]);
  rep3(i, 1, sz(a)) {
    int it = lb(b, a[i]);
    if (it == sz(b)) {
      b.eb(a[i]);
    } else {
      b[it] = a[i];
    }
  }
  return b;
}

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n + 1);
  cin >> a;
  ll A = accumulate(all(a), 0LL);
  vector<ll> b(n);
  cin >> b;

  rep(i, n + 1) {
    ll c;
    if (i) {
      c = min(a[i], b[i - 1]);
      a[i] -= c;
    }
    if (i != n) {
      c = min(a[i], b[i]);
      a[i] -= c;
      b[i] -= c;
    }
  }
  ll B = accumulate(all(a), 0LL);
  cout << A - B << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;

inline int read()
{
	int x=0,w=1;char f=getchar();
	while((f<'0' || f>'9') && f!='-')f=getchar();
	if(f=='-'){w=-1;f=getchar();}
	while(f>='0' && f<='9') {x=x*10+f-'0';f=getchar();}
	return x*w;
}

int main()
{
	int n,num=0;
	n=read();
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(x%2) 
		{
			printf("first\n");
			return 0;
		}
	}
	printf("second\n");
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def isprime(n):
  for i in range(2,int(n**0.5)+1):
    if n%i == 0:
      return False
  return True
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
from fractions import gcd
def coprime(a, b):
    return gcd(a, b) == 1


def solve():
  a,b = (int(i) for i in input().split())
  ad = make_divisors(a)
  bd = make_divisors(b)
  act = []
  bct = []
  for i in ad:
    if isprime(i):
      act.append(i)
  for j in bd:
      if isprime(j):
        bct.append(j)
  ct = 0
  for i in act:
    if i in bct:
      ct += 1
  print(ct)
solve()


Measured memory_bytes: 5552
#include<bits/stdc++.h>
#include"atcoder/all"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using namespace atcoder;
int main(){
  int K,i;cin >> K;
  for(i=0;i<K;i++) cout << "ACL";
  cout << "\n";
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
#define INF 1e9
#define INFL 1e12
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int n; cin >> n;
    int k=1;
    while(k<=n){
        int x = k;
        if(x%3==0){
            cout << " " << x;
        }else{
            while(x>0){
                if(x%10 == 3){
                    cout << " " << k;
                    break;
                }
                x /= 10;
            }
        }
        k++;
    }
    printf("\n");
    return 0;}


Measured memory_bytes: 3088
N = int(input())
C, S, F =[], [] ,[]
for i in range(N-1):
  c,s,f=map(int,input().split())
  C+= [c]
  S+= [s]
  F+= [f]

for i in range(N-1): #i+1駅に最初にいる
  t=0
  for j in range(i,N-1):#j+1駅にいる
    if t<=S[j]: t = S[j]
    else: t = F[j]*(t//F[j] + (t%F[j]!=0))
    t+=C[j]
  print(t)
print(0)

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

int main()
{
	int N;
	int A[105];
	int point[2] = {};
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	sort(A, A + N, greater <>());
	for ( int i = 0; i < N; i++ ) {
		point[i % 2] += A[i];
	}
	cout << point[0] - point[1] << endl;
	return ( 0 );
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

char field[21][21];
int direction_x[] = {1, -1, 0, 0};
int direction_y[] = {0, 0, 1, -1};
int w, h;
int lx = 0, ly = 0;
int cnt = 0;

void set_data(int w, int h){
    for(int i=0; i < h; i++){
        for(int j=0; j < w; j++){
            cin >> field[i][j];
            if(field[i][j] == '@'){
                ly = i;
                lx = j;
            }
        }
    }
}

void count(int x, int y){
    field[y][x] ='#';
    cnt++;
    int nx = 0, ny = 0;

    for(int i=0; i<4; i++){
        nx = x + direction_x[i];
        ny = y + direction_y[i];

        if(nx < 0 || nx >= w){
            continue;
        }
        if(ny < 0 || ny >= h){
            continue;
        }
        if(field[ny][nx] != '.'){
            continue;
        }
        count(nx,ny);
    }

}

int main(void){

    while(1){
        cnt = 0;
        cin >> w >> h;
        if(w==0 || h==0){
            break;
        }

        set_data(w,h);
        count(lx,ly);

        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3020
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		run();
	}

	static boolean isPrime(int x){
		if(x == 2){
			return true;
		}else if(x < 2 || x % 2 == 0){
			return false;
		}
		int i = 3;
		while(i <= Math.sqrt(x)){
			if(x % i == 0){
				return false;
			}
			i= i + 2;
		}
		return true;
	}
	
	static void run(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x;
		int count;
		count = 0;
		boolean judge;
		for(int i = 0; i < n; i++){
			x = scan.nextInt();
			judge = isPrime(x);
			if(judge) count++;
			judge = false;
		}
		System.out.println(count);
	}
}

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


public class Main {
	public static void main(String[] args) throws IOException{


		// 読み込み
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] temp;

		line=br.readLine();
		temp=line.split(" ");

		int x = Integer.valueOf(temp[0]);

		if(x <1200){
			System.out.println("ABC");
		}else{
			System.out.println("ARC");
		}


	}
}


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

int main() {

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    s[k-1] = tolower(s[k-1]);

    cout << s << endl;

    return 0;
}

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

typedef long long ll;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int N,K;
  cin >> N >> K;
  mint sum=0;
  for(int i=K; i<=N+1; i++) {
    sum += (mint)(N - i + 1) * (mint)(i) + 1;
  }
  cout << (int)(sum.x) << endl;
  return 0;
}




Measured memory_bytes: 3580
c=list(map(int,input().split()))
bunsi=c[0]
bunbo=c[1]
n=c[2]
k=n//bunbo
d=[n]
if k>=1:
    d.append(bunbo-1)
    d.append(bunbo*k-1)
#dの中には候補となるxが入った
def floor(x):
    return ((bunsi*x)//bunbo)-(bunsi*(x//bunbo))
if len(d)>=2:
    print(max(floor(d[0]),floor(d[-1]),floor(d[-2])))
if len(d)==1:
    print(floor(d[0]))

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N,D,X;
  cin>>N>>D>>X;
  int A[N];
  for (int i=0; i<N; i++) {
    cin>>A[i];
  }
  int ans=0;
  for (int i=0; i<N; i++) {
    int k=1;
    ans++;
    while (k*A[i]+1<=D) {
      ans++;
      k++;
    }
  }
  cout<<ans+X<<endl;
  return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] S = sc.next().toCharArray();
        int ans = 3 * 100000;
        int[] nbW = new int[N];

        nbW[0] = 0;
        if(S[0] == 'W'){
            nbW[0] = 1;
        }

        for(int i=1; i<N; i++){
            if(S[i] == 'W'){
                nbW[i] = nbW[i-1]+1;
            } else {
                nbW[i] = nbW[i-1];
            }
        }


        for(int i=0; i<N; i++){
            int left = 0;
            if(i != 0){
                left = nbW[i-1];
            }
            int right = (N-(i+1)) - (nbW[N-1] - nbW[i]);
            int count = left + right;
            ans = Math.min(ans, count);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 30788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int N;
vector<int> X, L;

struct P
{
	int L;
	int R;
	bool operator < (const P &x)const{
		return R < x.R;
	}
};


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

	vector<P> vec(N);
	rep(i,N){
		vec[i].L = X[i] - L[i];
		vec[i].R = X[i] + L[i];
	}
	sort(vec.begin(), vec.end());

	int cnt = N;
	int maxR;
	for(int i = 0; i<N; i++){
		if(i==0){
			maxR = vec[0].R;
		}else{
			if(maxR > vec[i].L) cnt--;
			else maxR = vec[i].R;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

const int mx=100010;
const ll mod=1e9+7;

int n,m;

int main(){
  cin >> n >> m;
  vector<int> teki(n);

  rep(i,m){
    int a,b;
    cin >> a >> b;
    teki[b-1] = max(a,teki[b-1]);
  }
  
  int ans=0,las=0;
  rep(i,n){
    if(teki[i] > las){
      ans++;
      las = i;
    }  
  }
  cout << ans << endl;
  return 0;  
}

Measured memory_bytes: 640