akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class FManySlimes {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      int s = 1<<n;
      vector<int> a(s);
      multiset<int, greater<>> st; // from
      multiset<int, greater<>> st2; // to

      rep(i, s) {
        int a; cin >> a;
        st.insert(a);
      }

      auto it = st.begin();
      st2.insert(*it);
      it = st.erase(it);

      for(int i=0; i<n; i++) {
        int t = 1<<i;
        auto it = st.begin();
        vector<int> v;

        for(auto e: st2) {
          while(it != st.end()) {
            if (*it < e) break;
            it++;
          }
          if (it == st.end()) {
            cout << "No" << endl;
            return;
          }
          debug(e, *it);
          v.push_back(*it);
          it = st.erase(it);
        }

        for(auto e: v) {
          st2.insert(e);
        }
      }
      cout << "Yes" << endl;
    }
};

signed main() {
  FManySlimes solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 14328
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int main(int argc, char* argv[])
{
    char str[5]={0};
    scanf("%s", str);
    str[0]++;
    printf("%s\n", str);

    return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    string o, e;
    cin >> o >> e;
    int m = o.length(), n = e.length();
    char t[m + n];
    for (int i = 0; i < m + n; i++)
    {
        if (i % 2 == 0) t[i] = o[i / 2];
        else t[i] = e[i / 2];
        cout << t[i];
    }
}

Measured memory_bytes: 3616
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int s; std::cin >> s;
  std::vector<int> v;
  v.push_back(s);
  int n = s;
  int m = 1;
  while (true) {
    if (n % 2 == 0) { // even
      n = n / 2;
    } else { // odd
      n = 3 * n + 1;
    }

    for (int a : v) {
      if (a == n) {
        std::cout << m + 1 << std::endl;
        return 0;
      }
    }

    v.push_back(n);
    ++m;
  }
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define int long long
#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define ROF(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _c = c; a < _c; ++a)
#define VEC(a, b) for(auto &a : b)
#define ii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))

template <class T> void Max(T &x, T y) { x = (x > y) ? x : y;}
template <class T> void Min(T &x, T y) { x = (x < y) ? x : y;}

#define debug(x) cerr << #x << '=' << x << '\n'
#define debugn(a, n) FOR(i, 1, n) cerr << a[i] << ' '
#define debugv(a) VEC(v, a) cerr << v << ' '

const int N = 4005;
int n;
string s;

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> s;
  s = ' ' + s;
  int x = 0, y = 0, z = 0;
  FOR(i, 1, n) {
    if(s[i] == 'R') x++;
    if(s[i] == 'G') y++;
    if(s[i] == 'B') z++;
  }
  int ans = x * y * z;
  FOR(i, 1, n) {
    FOR(j, i + 1, n) {
        int dis = j - i;
        int k = i + 2 * dis;
        if(k > n) continue;
        bool ok1 = 0, ok2 = 0, ok3 = 0;
        if(s[i] == 'R' || s[j] == 'R' || s[k] == 'R') ok1 = 1;
        if(s[i] == 'G' || s[j] == 'G' || s[k] == 'G') ok2 = 1;
        if(s[i] == 'B' || s[j] == 'B' || s[k] == 'B') ok3 = 1;
        ans -= (ok1 & ok2 & ok3);
    }
  }
  cout << ans << '\n';
}


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

#define sd(x) scanf("%d", &(x))
#define ll long long
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>

#define TRACE

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

const int N = 4e6 + 10;
bitset<N> B;
int A[2005];
int main(){
	int n;
	sd(n);
	int sm = 0;
	B.set(0);
	for(int i = 1; i <= n; i++){
		sd(A[i]);
		sm += A[i];
		B |= (B << A[i]);
	}
	B[0] = 0;
	int mid = (sm + 1) / 2;
	for(; mid < N; mid++) if(B[mid]){
		printf("%d\n", mid);
		return 0;
	}
}	

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
#A = np.array(input().split(), dtype=np.int64)
A = list(map(int, input().split()))


S = sum(A)
divisors = []

for i in range(1, S):
    if S < i * i:
        break

    if S % i == 0:
        divisors.append(i)
        divisors.append(S // i)


def check(x):
    modX = [a % x for a in A if a % x != 0]
    modX.sort()

    L = len(modX)
    rtn = False

    for i in range(L):
        cnt = 0
        minus = modX[:i]
        plus = modX[i:]

        cnt_minus = sum(minus)
        cnt_plus = x * (L - i) - sum(plus)

        if cnt_minus <= K and cnt_plus <= K:
            rest = abs(cnt_minus - cnt_plus)
            if rest % x == 0:
                rtn = True
                break

    return rtn


ans = 1
for x in divisors:
    if check(x):
        ans = max(x, ans)

print(ans)


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

int main(){
  int outc, runc, point, n, i, f;
  char event[8];
  scanf("%d", &n);
  f = 0;
  outc = runc = point = 0;
  while(f < n){
    scanf("%s", event);
    if(strcmp(event, "HIT") == 0){
      if(runc == 3)point++;
      else runc++;
    }else if(strcmp(event, "HOMERUN") == 0){
      point += runc + 1;
      runc = 0;
    }else if(strcmp(event, "OUT") == 0){
      outc++;
    }

    if(outc >= 3){
      printf("%d\n", point);
      f++;
      outc = runc = point = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 2e5 + 5;
const int mod = 1e9 + 7;



signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
	#endif
	IOS;
	int n, a, b;
	cin >> n >> a >> b;
	int x = 0, y = 0, z = 0;
	for(int i = 1; i <= n; i++){
		int p;	cin >> p;
		if(p <= a)	x++;
		else if(p > b)	y++;
		else	z++;
	}
	cout << min({x, y, z});
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll n;cin>>n;
  vil v(n);
  for(int i=0;i<n;i++)
  cin>>v[i];
  ll ans=0;
  ll maxi=v[0];
  for(int i=1;i<n;i++){
      if(v[i]<maxi) ans+=maxi-v[i];
      maxi=max(maxi,v[i]);
  }
  cout<<ans;
}



  

Measured memory_bytes: 4784
#include <iostream>
using namespace std;
string w[]={"Sunny","Cloudy","Rainy"},s;
int main(void){
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<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 a = sc.nextInt();
        String s = sc.next();
        int b = sc.nextInt();
        if (s.equals("+"))
            System.out.println(a + b);
        else
            System.out.println(a - b);
    }
}

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

list<int> li[200000];

int main() {

    int n,m,a,b;

    cin >> n >> m;

    for(int i=0;i<m;i++){
        scanf(" %d %d",&a,&b);
        li[a-1].push_back(b-1);
    }

    list<int>::iterator itr;

    for(itr = li[0].begin();itr!=li[0].end();itr++){
        a = *itr;
        list<int>::iterator itr2;
        for(itr2 = li[a].begin();itr2!=li[a].end();itr2++){
            if(*itr2 == n-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	private void calc(){
		Scanner scanner = new Scanner(System.in);
		short i=1;
		while(true){
			int x=scanner.nextInt();
			
			if(x==0)break;
			
			System.out.println("Case "+i+": "+x);
			i++;
			
		}
		
	}
	
	public static void main(String[] args) {
		Main run =new Main();
		run.calc();

	}
}

Measured memory_bytes: 33292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, T;
    cin >> N >> T;
    int c, t;
    int ans = 10000;
    rep(0, i, N)
    {
        cin >> c >> t;
        if (t > T)
        {
            continue;
        }
        ans = min(ans, c);
    }
    if (ans == 10000)
    {
        cout << "TLE" << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(a, n) for (int i = a; i < n; i++)
#define per(a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef double db;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
	string s,t;
	cin>>s>>t;
	int lenS = s.length();
	int lenT = t.length();
	int ans = lenS;
	for(int i=0;i<=lenS-lenT;i++){
		int cnt = 0;
		for(int j=0;j<lenT;j++){
			if(t[j] != s[i+j]){
				cnt++;
			}
		}
		ans = min(ans,cnt);
	}
	cout<<ans;
}

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

using namespace std;

const int INF = 999999;
int N, M_a, M_b;
int dp[41][401][401];
int a[41];
int b[41];
int c[41];
int ans = INF;
int s, t;

int gcd (int x, int y) {
  if(x < y) swap(x,y);
  while(y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

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

 
  for(int i = 0; i < N; i++) {
    
    cin >> a[i] >> b[i] >> c[i];
    s += a[i];
    t += b[i];
  }

  for(int i = 0; i <= N; i++) {
    for(int j = 0; j < s+1; j++) {
      for(int k = 0; k < t+1; k++) {
	dp[i][j][k] = INF;
      }
    }
  }
 

  dp[0][0][0] = 0;
  
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < s+1; j++) {
      for(int k = 0; k < t+1; k++) {
	if(dp[i][j][k] == INF) continue;
	dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
	dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k] + c[i]);
      }
    }
  }
  
  for(int i = 1; i < s+1; i++) {
    for(int j = 1; j < t+1; j++) {
      //cout <<"dp["<<i<<"]["<<j<<"] = "<<dp[N][i][j]<<endl;
      if((i * M_b) == (j * M_a)) {
	ans = min(ans,dp[N][i][j]);
      }
    }
  }
  if(ans == INF) cout <<"-1"<<endl;
  else cout << ans <<endl;
}


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

using namespace std;

int main(){
  int w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;
  if(w - r >= x && r <= x && h - r >= y && r <= y){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
H,W=gets.chomp.split(' ').map{|n| n.to_i}
A = Array.new(H)
0.upto(H-1){|d|
	A[d]=gets.chomp.split(' ').map{|n| n.to_i}
}
arr = []
A.each_with_index{|r,i|
	r.each_with_index{|a,j|
		if(a%2!=0)
			if(j<W-1)
				A[i][j]-=1
				A[i][j+1]+=1
				arr << "#{i+1} #{j+1} #{i+1} #{j+1+1}"
			else
				if(i<H-1)
					A[i][j]-=1
					A[i+1][j]+=1
					arr << "#{i+1} #{j+1} #{i+1+1} #{j+1}"
				end
			end
		end
	}
}
puts arr.size
puts arr


Measured memory_bytes: 18684
N, K= map(int, input().split())

import math
Ans = 0

if K < N:
    for X in range(1, K+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    Ans = Ans + (N-K)/N
    print(Ans)

if K == N:
    for X in range(1, K+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    print(Ans)
    
if K > N:
    for X in range(1,N+1):
        R = math.log(K/X, 2)
        S = math.ceil(R)
        Ans = Ans + (0.5**S / N)
    print(Ans)

Measured memory_bytes: 3064
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
int main()
{
	int N,W;cin>>N>>W;
	vector<pair<int,int>> items(N);
	for(int i=0;i<N;i++) cin>>items[i].F>>items[i].S;

	int maxVal = 1e5+5;
	vector<int> dp1(maxVal,1e9+8);
	vector<int> dp2(maxVal,1e9+8);
	dp2[0]=0; 
	for(int j=0;j<N;j++)
	{
		dp1[0]=0;
		for(int i=1;i<maxVal;i++) if(items[j].S<=i) dp1[i]=min(dp1[i],dp2[i-items[j].S]+items[j].F);
		dp2=dp1;
	} 

	int ans = 0;
	for(int i=1;i<maxVal;i++) if(dp2[i]<=W) ans=i;
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 4048
def Digitsum(n):
    sum = 0
    while(n > 0):
        sum += (n % 10)
        n = int(n / 10)
    return sum

N = int(input())
n = N
ans = 0
while(True):
    if (n % 10 >= 2):
        #10のべき乗ではない
        ans = Digitsum(N)
        break
    elif (n % 10 == 1 and n >= 10):
        #10のべき乗ではない
        ans = Digitsum(N)
        break
    n = int(n / 10)
    if (n == 1):
        ans = 10
        break

print(ans)


Measured memory_bytes: 3064
N = int(input())
S = input()

ret = 0
cursor = 0
for s in S:
  if cursor == 0:
    if s == 'A':
      cursor = 1
  elif cursor == 1:
    if s == 'B':
      cursor = 2
    elif s == 'A':
      cursor = 1
    else:
      cursor = 0
  else:
    if s == 'C':
      ret += 1
      cursor = 0
    elif s == 'A':
      cursor = 1
    else:
      cursor = 0
      
print(ret)


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

string str;

string print(int a,int b) {
	string str2;
	str2 = str.substr(a, b - a + 1);
	return str2;
}

string reverse(int a, int b) {
	string str2;
	str2 = str.substr(a, b - a + 1);
	int len = str2.length();
	string str3 = str2;
	for (int i = 0;i < len;i++) {
		str2[i] = str3[len - 1 - i];
	}
	str2 = str.replace(a, len, str2);
	return str2;
}

string replace(int a, string s) {
	string str2;
	int len = s.length();
	str2 = str.replace(a, len, s);
	return str2;
}

int main() {
	int n, a, b;
	string cmd,s;
	cin >> str >> n;
	for (int i = 0;i < n;i++) {
		cin >> cmd >> a >> b;
		if (cmd == "print") {
			cout << print(a, b) << endl;
		}
		if (cmd == "reverse"){
			str = reverse(a, b);
		}
		if (cmd == "replace") {
			cin >> s;
			str = replace(a, s);
		}
	}
	return 0;
}

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

int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    string S;
    cin >> S;
    int ans = 0;
    int mark = 0;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'A' || S[i] == 'G' || S[i] == 'T' || S[i] == 'C'){
            mark++;
            ans = max(ans, mark);
        }else{
            ans = max(ans, mark);
            mark = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000			 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする

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

//int dy[5] = { 0,0,1,-1,0 };
//int dx[5] = { 1,-1,0,0,0 };

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

struct edge
{
	int to;
	double cost;
};

int main(void)
{

	int x, a;
	cin >> x >> a;
	if(x<a){
		cout << 0 << endl;
	}else{
		cout << 10 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll a, b, k;
	cin >> k>>a >> b;
	FOR(i, a, b + 1) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;

		}
	}
	cout << "NG" << endl;
}
 

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

int main(){
	int w,h,n,res = 0,px,py;
	cin >> w >> h >> n >> px >> py;
	for(int i = 1;i < n;i++){
		int x,y;
		cin >> x >> y;
		if((x >= px && y >= py) || (px >= x && py >= y)) res += max(abs(x - px),abs(y - py));
		else res += abs(x - px) + abs(y - py);
		px = x;
		py = y;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (int)(n); i++)
 
int main() {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if (a>=k){
        cout<<k<<endl;
    }
    else if (a+b>=k){
        cout<<a<<endl;
    }
    else{
        cout<<(a-(k-(a+b)))<<endl;
    }
}

Measured memory_bytes: 3556
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 1e13;

ll n, a[100050],b[100050];

int isOK(int mid) {
    /*mid降った時が条件を満たすかどうかを判定(今回は小さくなるか)*/
    b[0] = 2 * mid;
    for(ll i = 1; i < n; i++) {
        b[i] = 2 * a[i - 1] - b[i - 1];
    }
    ll suma = 0, sumb = 0;
    for(ll i = 0; i < n;i++){
        suma += a[i];
        sumb += b[i];
    }
    if(suma == sumb) return 2;
    if(suma > sumb) return 1;
    else
        return 0;
}

void binary_search() {
    int ng = 2+min(a[0], a[n - 1]);
    int ok = -1;
    //okとngの初期値によって最大値だけでなく最小値も求められる.
    //ng=-1の時はkey以上の数値の最小値

    while(abs(ok - ng) > 0) {
        int mid = (ok + ng) / 2;
        int x = isOK(mid);
        if(x == 2)
            return;
        else if(x==1)
            ok = mid;
        else
            ng = mid;
    }

    return;
}

int main() {
    ll i, j, k, m, h;
    cin >> n;
    for ( i = 0; i < n; i++){
        cin >> a[i];
    }
    binary_search();
    for(i = 0; i < n;i++){
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main(void) {
  int i;
  char text[3][3];
    scanf("%s",text[0]);
    scanf("%s",text[1]);
    scanf("%s",text[2] );
  printf("%c%c%c\n",text[0][0],text[1][1],text[2][2] );

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	char S[4];
	int y = 700;
	int i;
	
	scanf("%s",S);
	for(i = 0; i < 4; i++) {
	
		if(S[i] == 'o') {
			y = y + 100;
		}
	}
	
	printf("%d\n",y);
	
	return 0;
}

Measured memory_bytes: 128
while True:
    q=int(input())
    if q==-1:
        break
    x=q/2
    a=0.00001*q
    while abs(x**3-q)>=a:
        b=x**3-q
        c=3*x**2
        x-=b/c
    print(f'{x:6f}')


Measured memory_bytes: 5684
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 5000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
    int n, q;
    cin >> n >> q;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
	Query queries[q];
    for(int i = 0; i < q; i++)
    {
        cin >> queries[i].l >> queries[i].r;
        queries[i].idx = i;
        queries[i].l--;
        queries[i].r--;
    } 
	// queries[0].l = 0; 
	// queries[0].r = 4; 
	// queries[0].idx = 0; 
	// queries[1].l = 1; 
	// queries[1].r = 3; 
	// queries[1].idx = 1; 
	// queries[2].l = 2; 
	// queries[2].r = 4; 
	// queries[2].idx = 2; 
	// int q = sizeof(queries)/sizeof(queries[0]); 
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 

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

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

    vector<long> 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.begin(), A.end());
    sort(F.begin(), F.end(), greater<long>());

    long left = 0L, right = 1e18L;
    while (left < right) {
        long mid = (left + right) >> 1, need = 0L;
        for (int i = 0; i < N; ++i)
            need += max(A[i] - mid / F[i], 0L);
        if (need > K)
            left = mid + 1;
        else
            right = mid;
    }
    cout << left << endl;
}



Measured memory_bytes: 3456
#include <iostream>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdio.h> 
#include <map>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include <sstream>
#include <vector>
#include <algorithm>

typedef long long ll;
using namespace std;

int main() {
	string s;
	cin>>s;
	if(s[0]==s[1] && s[1]==s[2]) {
		cout << "No";
	} else {
		cout << "Yes";
	}
	
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val x1 = Math.ceil(a / 0.08).toInt()
    val x1m = x1 + 12 - if ((a / 0.08).mod(1) > 0.0) {
        1
    } else {
        0
    }
    val x2 = Math.floor(b / 0.1).toInt()
    val x2m = x2 + 9

    if (x1 in x2..x2m) {
        println(x1)
    } else if (x1 <= x2 && x2m <= x1m) {
        println(x2)
    } else if (x2 in x1..x1m) {
        println(x2)
    } else {
        println(-1)
    }
}


Measured memory_bytes: 37880
#include<stdio.h>

int main (void) {
	char f, e, i;
	int len;
	f = getchar();
	i = f;
	len = 0;
	do {
		e = i;
		len++;
		i = getchar();
	} while(i != '\n');

	if (f == e) len--;
	if(len & 1) printf("First\n");
	else printf("Second\n");

	return 0;
}

Measured memory_bytes: 128
// DivGame.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

long long n;
vector<long long> primes;
int powerCount = 0, moves = 0;

vector<long long> primeFactorize(long long n) {
    vector<long long> factorization;
    long long j = n;
    for (long long i = 2; i < (long long)sqrt(j); i++) {
        while (n % i == 0) {
            n /= i;
            factorization.push_back(i);
        }
    }
    if (n > 1) {
        factorization.push_back(n);
    }
    return factorization;
}

int numMoves(int count) {
    int i = 1;
    int moves = 0;
    while (count >= i) {
        moves++;
        count -= i;
        i++;
    }
    return moves;
}

int main()
{
    cin >> n;
    primes = primeFactorize(n);
    vector<int> counts;
    if (n > 1) {
        counts.push_back(1);
        for (int i = 1; i < (int)primes.size(); i++) {
            if (primes[i] == primes[i - 1]) {
                counts[counts.size() - 1]++;
            }
            else {
                counts.push_back(1);
            }
        }
    }
    for (int i = 0; i < (int)counts.size(); i++) {
        moves += numMoves(counts[i]);
    }
    cout << moves << "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
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;}
#define MOD 1000000007 //998244353

vp e[100100];// <F:V,  S:length>
vl ans(100100);

//多分これが想定解
void dfs(ll root, ll now, ll sum){
    ans[now] = sum;
    for(auto x:e[now]) {
        if(x.F != root) {
            dfs(now, x.F, (sum+x.S)%2);
        }
    }
}

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

    // solution comes here

    ll N;
    cin >> N;
    
    rep(i, N-1) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--;v--;//0-indexed
        e[u].PB({v,w});
        e[v].PB({u,w});
    }

    dfs(0,0,0);

    rep(i, N) cout << ans[i] << nl;
}


Measured memory_bytes: 10240
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
たぶんAC
*/

ll k,a,b,ans=0;

int main(void){
	cin>>k>>a>>b;
	if(a+1>=b){
		//k回叩く
		ans=k+1;
	}else{
		//k/2回ABをセットで行う
		if(k<=a){
			//k回叩く
			ans=k+1;
		}else{
			//AB
			k-=a-1;
			ans+=a+k/2*(b-a);
			ans+=k%2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::{self, Read};
use std::cmp;

macro_rules! input {
    ($it: expr) => ($it.next().unwrap().parse().unwrap());
    ($it: expr, $T: ty) => ($it.next().unwrap().parse::<$T>().unwrap());
}

fn main() {
    let mut buf = String::new();
    let mut it = {
        io::stdin().read_to_string(&mut buf).unwrap();
        buf.split_whitespace()
    };

    let n: usize = input!(it);
    let m: usize = input!(it);
    let x: u64 = input!(it);
    let (c, a) = {
        let mut c: Vec<u64> = vec![0; n];
        let mut a: Vec<Vec<u64>> = vec![vec![0; m]; n];
        for i in 0..n {
            c[i] = input!(it);
            for j in 0..m {
                a[i][j] = input!(it)
            }
        }
        (c, a)
    };

    let mut ans: u64 = 1 << 60;
    for s in 0..(1 << n) {
        let mut cost = 0;
        let mut sum: Vec<u64> = vec![0; m];
        for i in 0..n {
            if s & (1 << i) == 0 {
                continue;
            }
            cost += c[i];
            for j in 0..m {
                sum[j] += a[i][j];
            }
        }

        if sum.iter().all({ |v| *v >= x }) {
            ans = cmp::min(ans, cost);
        }
    }

    if ans == 1 << 60 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

Measured memory_bytes: 2116
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string s; char c;
vector<string> parse(string str) {
	vector<string> ret; string t; str += " ";
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == ' ') ret.push_back(t), t = "";
		else t += str[i];
	}
	return ret;
}
int main() {
	while (cin >> n, n) {
		map<string, int> d;
		for (int i = 0; i < n; i++) {
			s = "";
			while (s == "") getline(cin, s);
			vector<string> v = parse(s);
			for (int j = 0; j < v.size(); j++) d[v[j]]++;
		}
		cin >> c;
		vector<pair<int, string> > r;
		for (map<string, int>::iterator i = d.begin(); i != d.end(); i++) {
			string t = (*i).first;
			if (t[0] == c) r.push_back(make_pair(-(*i).second, t));
		}
		sort(r.begin(), r.end());
		for (int i = 0; i < r.size() && i < 5; i++) {
			if (i) cout << ' ';
			cout << r[i].second;
		}
		if (!r.size()) cout << "NA";
		cout << endl;
	}
}

Measured memory_bytes: 3132
n = int(input())
h = list(map(int, input().split()))
h[0] -= 1
for i in range(1, n):
    if h[i]-h[i-1] < 0:
        print('No')
        exit()
    if h[i] - h[i-1] > 0:
        h[i] -= 1
print('Yes')

Measured memory_bytes: 14396
#include <iostream>

int main() {
  int n, m;
  std::cin >> n >> m;
  char a[n][n], b[m][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      std::cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      std::cin >> b[i][j];
    }
  }

  bool imageFound;
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      imageFound = true;
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          if (a[i + k][j + l] != b[k][l]) {
            imageFound = false;
          }
        }
      }
      if (imageFound) {
        break;
      }
    }
    if (imageFound) {
        break;
      }
  }

  if (imageFound) {
    std::cout << "Yes" << "\n";
  } else {
    std::cout << "No" << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i){
    cin>>a[i];
    s+=a[i];
  }
  if(s%10){cout<<s<<"\n"; return 0;}
  for(int i=0;i<n;++i)if(a[i]%10==0)a[i]=0;
  sort(a.begin(),a.end());
  auto l=upper_bound(a.begin(),a.end(),0);
  if(l==a.end())cout<<"0\n";
  else cout<<s-*l<<"\n";
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = [False for _ in range(K+1)]
dp[0] = False
for i in range(1, K+1):
    for a in A:
        if i - a >= 0:
            if not dp[i-a]:
                dp[i] = True
                break
if dp[K]:
    print("First")
else:
    print("Second")


Measured memory_bytes: 44784
#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int tree[maxn],a[maxn][3],s[maxn],w[maxn];
int b[3];
int inv[2],flip[2];
int i,j,k,l,t,n,m,now;
bool czy;
int lowbit(int x){
	return x&-x;
}
void change(int x,int v){
	while (x>0){
		tree[x]+=v;
		x-=lowbit(x);
	}
}
int query(int x){
	int t=0;
	while (x<=n){
		t+=tree[x];
		x+=lowbit(x);
	}
	return t;
}
int main(){
	scanf("%d",&n);
	fo(j,0,2)
		fo(i,1,n) scanf("%d",&a[i][j]);
	fo(i,1,n){
		fo(j,0,2) b[j]=a[i][j];
		sort(b,b+3);
		if (b[1]!=b[0]+1||b[2]!=b[1]+1||b[2]%3!=0||a[i][1]!=b[1]){
			printf("No\n");
			return 0;
		}
		if (a[i][0]>a[i][2]) inv[i%2]^=1;
		s[i]=b[2]/3;
		if ((i-s[i])%2){
			printf("No\n");
			return 0;
		}
	}
	fo(i,1,n) w[s[i]]=i;
	for(i=1;i<=n;i+=2){
		now=w[i]+2*query(w[i]);
		flip[1]=(flip[1]+abs(i-now)/2)%2;
		change(w[i],1);
	}
	fo(i,0,n) tree[i]=0;
	for(i=2;i<=n;i+=2){
		now=w[i]+2*query(w[i]);
		flip[0]=(flip[0]+abs(i-now)/2)%2;
		change(w[i],1);
	}
	czy=1;
	if (inv[0]!=flip[1]||inv[1]!=flip[0]) czy=0;
	if (czy) printf("Yes\n");else printf("No\n");
}

Measured memory_bytes: 2560
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;



int main(){
     
    long a,b,x;
    
    cin>>a>>b>>x;
    if(a%x==0)cout<<b/x-a/x+1<<endl;
    else cout<<b/x-a/x<<endl;
    
     
    return 0;
}
 

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

int main() {
    int c[3][3];
    int a[3], b[3];
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    for(int i = 0; i <= 100; i++) {
        a[0] = i;
        for(int j = 0; j < 3; j++) {
            b[j] = c[0][j] - a[0];
        }
        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];
        bool ok = true;
        for(int j = 1; j <= 2; j++) {
            for(int k = 1; k <= 2; k++) {
                if(a[j] + b[k] != c[j][k]) ok = false;
            }
        }
        if(ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


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

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=0;

int N,A,B;

vi f(int a, int b) {
	vi v; v.clear();
	int n = B-1;
	if(N == A) {
		if(B != 1) return v;
		else FOR(i,1,N+1) v.pb(i);
		return v;
	}
	if(N == B) {
		if(A != 1) return v;
		else FOR(i,1,N+1) v.pb(i);
		return v;
	}
	int h = (N-A) / n;
	int m = (N-A) % n;
	if(h == 0) return v;
	if(m == 0) if(h   > A) return v;
	if(m  > 0) if(h+1 > A) return v;
	FOR(i,N-A+1,N+1) v.pb(i);
	int cur = N-A+1;
	FOR(i,0,n) {
		if(cur <= h) h = cur-1;
		cur -= h;
		if(m) v.pb(cur-1);
		FOR(j,0,h) v.pb(cur+j);
		if(m) cur--, m--;
	}
	return v;
}

int main() {
	ri(N),rii(A,B);
	if(A > N || B > N) {
		printf("-1\n");
		return 0;
	}
	if(A == 1) {
		if(B != N) printf("-1");
		else FORR(i,N,0) printf("%d ",i);
		printf("\n");
		return 0;
	}
	if(B == 1) {
		if(A != N) printf("-1");
		else FOR(i,1,N+1) printf("%d ",i);
		printf("\n");
		return 0;
	}
	vi V = f(A,B);
	if(V.empty()) printf("-1");
	else FOR(i,0,V.size()) printf("%d ",V[i]);
	printf("\n");
}


Measured memory_bytes: 3440
a,b,c,d = map(int,input().split())
x = [a,b]
y = [c,d]

if a * b < 0:
    x.append(-1)
    x.append(1)
    
if c * d < 0:
    y.append(-1)
    y.append(1)
    
ans = - (10 ** 20)
    
for i in x:
    for j in y:
        ans = max((i*j),ans)
        
print(ans)

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

void Main()
{
  int K, A, B;
  cin >> K;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    if (i%K == 0) {cout << "OK" << endl; return;}
  }
  cout << "NG" << endl;
}

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


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, q, cmd, i, l, r;
    char c;
    string s;
    cin >> n >> s;
    vector<set<int>> pos(26, set<int>());
    for(int i = 0; i < s.size(); i++) {
        pos[s[i]-'a'].insert(i);
    }
    cin >> q;
    while (q--) {
        cin >> cmd;
        if (cmd == 1) {
            cin >> i >> c;
            if (s[--i] != c) {
                pos[s[i]-'a'].erase(i);
                pos[c-'a'].insert(i);
                s[i] = c;
            }
        } else if (cmd == 2) {
            cin >> l >> r;
            l--; r--;
            int ans = 0;
            for(int i = 0; i < 26; i++) {
                auto it = pos[i].lower_bound(l);
                if (it != pos[i].end() && *it >= l && *it <= r)
                    ans += 1;
            }
            cout << ans << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 24220
N = int(input())
D = [None] * N
for i in range(N):
    D[i] = list(map(int, input().split()))

a = 0
b = 0
for d in D:
    if d[0] == d[1]:
        a += 1
        b = max(a, b)
    else:
        a = 0
        b = max(a, b)

if b >= 3:
    ans = "Yes"
else:
    ans = "No"
print(ans)


Measured memory_bytes: 9124
n = int(input())

ans = ''
while n > 0:
    if n % 26 == 0:
        ans = chr(ord('a') + 25) + ans
        n = n // 26 - 1
    else:
        ans = chr(ord('a') + (n % 26) - 1) + ans
        n //= 26
print(ans)


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

int main(){
	string s;
	cin>>s;
	int flag=0;
	if(s[0]!=s[1]){
		flag=1;
	}
	if(s[2]!=s[1]){
		flag=1;
	}
	if(flag==1){
		cout<<"Yes"<<endl;
	}
	if(flag==0){
		cout<<"No"<<endl; 
	}
	return 0;
} 

Measured memory_bytes: 256
namespace ABC128.A
{
    using System.Collections.Generic;
    using System.Linq;
    using static System.Console;
    public class Program
    {
        public static void Main(string[] args)
        {
            var l = ReadInputsAsInt().ToList();

            var A = l[0];
            var B = l[1];
            WriteLine((3 * A + B) / 2);
        }

        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));
    }
}

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

using namespace std;

std::string replaceAll(std::string &replacedStr, std::string from, std::string to) {
  int pos = replacedStr.find(from);
  int toLen = to.length();

  if (from.empty()) {
    return replacedStr;
  }

  while ((pos = replacedStr.find(from, pos)) != std::string::npos) {
    //cout << pos << endl;
    replacedStr.replace(pos, from.length(), to);
    pos += toLen;
  }
  return replacedStr;
}

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

  replaceAll(s, "BC", "D");
  //cout << s << endl;

  // Aを数え上げる
  // Dが来たらtempsumへ足す
  // B,Cが来たらtempsumリセット

  long long sum = 0;
  long long tempsum = 0;

  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'A'){
      tempsum++;
    } else if(s[i] == 'D'){
      sum += tempsum;
    } else {
      tempsum = 0;
    }
    //cout << "i = " << i << endl;
    //cout << "tempsum = " << tempsum << endl;
    //cout << "sum = " << sum << endl;
   
  }
  cout << sum << endl;

  
  
}


Measured memory_bytes: 644
N = int(input())
S = input()

east_to_west = [0]*len(S)
west_to_east = [0]*len(S)

e = 0
w = 0
for i, s in enumerate(S):
  west_to_east[i] = e
  if s == 'W':
    e += 1

index = len(S) - 1
for i, s in enumerate(reversed(list(S))):
  east_to_west[index] = w
  index -= 1
  if s == 'E':
    w += 1

ans = 3*(10**5)
for n in range(N):
  sum = west_to_east[n] + east_to_west[n]
  if sum < ans:
    ans = sum
    
print(ans)

Measured memory_bytes: 21836
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#define MAX 1000000000000000000LL

using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=c-a;
    int y=d-b;
    for(int i=0; i<y; i++){
        cout<<"U";
    }
    for(int i=0; i<x; i++){
        cout<<"R";
    }
    for(int i=0; i<y; i++){
        cout<<"D";
    }
    for(int i=0; i<x+1; i++){
        cout<<"L";
    }
    for(int i=0; i<y+1; i++){
        cout<<"U";
    }
    for(int i=0; i<x+1; i++){
        cout<<"R";
    }
    cout<<"DR";
    for(int i=0; i<y+1; i++){
        cout<<"D";
    }
    for(int i=0; i<x+1; i++){
        cout<<"L";
    }
    cout<<"U"<<endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int t, h, m, s;
    cin >> t;
    h = t / 3600;
    t = t % 3600;
    m = t / 60;
    s = t % 60;
   
    cout << h <<":"<< m << ":" << s << endl;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int ans = 0;
    rep(i, N){
        int a; cin >> a;
        ans = __gcd(ans, a);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	vector< int > a( 4 );
	for ( int i = 0 ; i < 4 ; ++ i )
		scanf( "%d", &a[ i ] );
	sort( a.begin(), a.end() );
	cout << ( ( vector< int >( { 1, 4, 7, 9 } ) == a ) ? "YES" : "NO" ) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};



int32_t main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif 

int n,m,k;
cin>>n>>m>>k;

vector<int>v(n),x(m);

for(int i=0;i<n;i++)
{
    cin>>v[i]; if(i)v[i]+=v[i-1];
}

for(int i=0;i<m;i++)
{
    cin>>x[i]; if(i)x[i]+=x[i-1];
}


int ans=0;
int val=0;
for(int i=0;i<n;i++)
{ 
   int cnt=i+1;
   if(v[i]>k)break;
   int z=k-v[i];
auto it=upper_bound(x.begin(),x.end(),z);
it--;
   cnt+=it-x.begin()+1;
   ans=max(ans,cnt);
   
} 

for(int i=0;i<m;i++)
{
    if(x[i]>k)break;
    int z=k-x[i];
    int cnt=i+1;
    auto it=upper_bound(v.begin(),v.end(),z);
    it--;
   cnt+=it-v.begin()+1;
   ans=max(ans,cnt);
}
cout<<ans<<"\n";



}






Measured memory_bytes: 6364
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 1000 - (n % 1000);
    if (ans == 1000) {
      ans = 0;
    }
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 35500