akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int n;

class UnionFind
{
    int par[100007];
    int rank[100007];
public:
    void initialize(){
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int i){
        if(par[i] == i){
            return i;
        }
        return par[i] = find(par[i]);
    }
    
    void unite(int i, int j){
        i = find(i);
        j = find(j);
        if(i == j){
            return;
        }
        if(rank[i] < rank[j]){
            par[i] = j;
        }
        else{
            par[j] = i;
            if(rank[i] == rank[j]){
                rank[i]++;
            }
        }
    }
    
    bool same(int i, int j){
        return find(i) == find(j);
    }
};

int main()
{
    int m;
    cin >> n >> m;
    int p[100007];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf;
    uf.initialize();
    int x[100007], y[100007];
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        uf.unite(x[i], y[i]);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(uf.same(i, p[i])){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2176
A = int(input())
B = int(input())
C = int(input())
x = int(input())

ans = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a+100*b+50*c == x:
        ans += 1

print(ans)
      

Measured memory_bytes: 3060
import numpy as np
H,W = (int(X) for X in input().split())
A = np.zeros((H,W),dtype=bool)
for TH in range(0,H):
    A[TH,:] = np.array([True if X=='.' else False for X in input()])
    Row = [TH for TH in range(0,H) if np.all(A[TH,:])==True]
for TW in range(0,W):
    Column = [TW for TW in range(0,W) if np.all(A[:,TW])==True]

A = np.delete(np.delete(A,Row,0),Column,1)
for THD in range(0,H-len(Row)):
    Disp = ['.' if X==True else '#' for X in A[THD,:]]
    print(''.join(Disp))

Measured memory_bytes: 27284
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int mo=1e9+7,maxn=2e3+5;
int i,j,n,k,f[maxn][maxn];
int qs(int x,int y){
	if (y<0) return 1;
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if (y&1) s=(ll)s*x%mo;
	return s;
}
void mod(int &x){
	x-=(x>mo)?mo:0;
}
int main(){
	scanf("%d%d",&n,&k);
	f[n+1][0]=1;
	fd(i,n+1,3){
		int sum=0;
		fd(j,n,0) if (f[i][j]){
			int s=f[i][j];
			mod(sum+=s);
			mod(f[i-1][j+1]+=s);
			mod(f[i-1][j]+=sum);
		}
	}
	printf("%d\n",(ll)f[2][n-k]*qs(2,n-k-1)%mo);
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
int n,y;//10000 5000 1000
int xx,yy,zz;
bool flag;
int main()
{
	scanf("%d%d",&n,&y);
	for(int i=0;i<=n;++i)
	{
		for(int j=0;j<=n;++j)
		{
			int k=n-i-j;
			if(k<0) continue;
			if(10000*i+5000*j+1000*k==y)
			{
				if(i>=0 && j>=0 && k>=0)
				{
					xx=i;
					yy=j;
					zz=k;
					flag=1;
					break;
				}
			}
		}
		if(flag) break;
	}
	if(!xx && !yy && !zz) printf("-1 -1 -1\n");
	else printf("%d %d %d\n",xx,yy,zz);
	
	return 0;
}


Measured memory_bytes: 256
(function(input) {
    var a = input.split('\n');
    var s = a.shift();
    var n = Number(a.shift());
    var i = 0;
    while (i++ < n) {
        var c = a.shift().split(' ');
        s = command(s, c);
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function command(s, c) {
    var com = c.shift();
    switch (com) {
        case 'print':
            var a = Number(c.shift());
            var b = Number(c.shift());
            console.log(s.slice(a, b + 1));
            break;
        case 'reverse':
            var a = Number(c.shift());
            var b = Number(c.shift());
            s = s.slice(0, a)
            + s.slice(a, b + 1).split('').reverse().join('')
            + s.slice(b + 1, s.length);
            break;
        case 'replace':
            var a = Number(c.shift());
            var b = Number(c.shift());
            var p = c.shift();
            s = s.slice(0, a)
            + p
            + s.slice(b + 1, s.length);
    }
    return s;
}

Measured memory_bytes: 7648
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000, mod = 998244353, inv2 = (mod + 1) / 2;
int n, m, s, w, d, w2, ans;
int fac[maxn + 10], ifac[maxn + 10], inv[maxn + 10];

inline int add(int x, int y) {
	x += y; return x < mod ? x : x - mod;
}
inline int dec(int x, int y) {
	x -= y; return x < 0 ? x + mod : x;
}
inline int mul(int x, int y) {
	return 1ll * x * y % mod;
}

void prework() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= maxn; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = i == 1 ? 1 : dec(0, mul(mod / i, inv[mod % i]));
		ifac[i] = mul(ifac[i - 1], inv[i]);
	}
}

int comb(int x, int y) {
	return y < 0 || y > x ? 0 : mul(fac[x], mul(ifac[y], ifac[x - y]));
}

int f(int x, int y) {
	return comb(x + y, x);
}

int main() {
	prework();
	scanf("%d%d", &n, &m);
	w = comb(n + m - 1, n); w2 = comb(n + m - 1, m); d = 1;
	s = add(s, add(w, w2));
	for (int i = m - 2; i >= -n - 1; --i) {
		ans = add(ans, mul(s, inv[d]));
		++d;
		if (d & 1) {
			w = add(w, mul(f(i + d / 2, n - d / 2), f(m - (i + d / 2) - 2, d / 2)));
			w2 = add(w2, mul(f(m - d / 2, n - (d - d / 2)), f(d / 2, d - d / 2 - 2)));
		} else {
			w = dec(w, mul(f(i + d / 2, n - d / 2), f(m - (i + d / 2) - 1, d / 2 - 1)));
			w2 = dec(w2, mul(f(m - d / 2, n - (d - d / 2)), f(d / 2 - 1, d - d / 2 - 1)));
		}
		s = add(s, add(w, w2));
	}
	printf("%d", mul(ans, mul(ifac[n + m], mul(fac[n], fac[m]))));
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int a[2][n];
  REP(i,2) {
    REP(j,n) cin >> a[i][j];
  }

  int s1[n+1], s2[n+1];
  s1[0]=0; s2[0]=0;
  REP(i,n) {
    s1[i+1] = s1[i]+a[0][i];
    s2[i+1] = s2[i]+a[1][i];
  }

  ll ans = 0;
  REP(i,n) {
    ll x = s1[i+1] - s1[0] + s2[n] - s2[i];
    ans = max(ans,x);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
#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);

  while(1) {
    int n, k, m; cin >> n >> k >> m;
    if(n == 0) break;
    vi a(n);
    REP(i, n) {
      a[i] = i+1;
    }
    int pos = m-1;
    REP(i, n-1) {
      a.erase(a.begin() + pos);
      pos = (pos + k - 1) % (n-1-i);
    }
    cout << a[0] << endl;
  }
}



Measured memory_bytes: 3112
N = int(input())
def divisor(n):
    fac = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            fac.append(i)
            if i * i != n:
                fac.append(n // i)
    return sorted(fac)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
L = divisor(N)
count = 0
for i in L[1::]:
    if len(factorization(i))==1:
        if N % i == 0:
            N = N/i
            count+=1
print(count)

Measured memory_bytes: 9528
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	string tiles;
	cin >> tiles;

	int sz = tiles.size();
	string tile_white = "", tile_black = "";
	for (int i = 1; i <= sz / 2; ++i) {
		tile_white += "01";
		tile_black += "10";
	} 

	if (sz & 1) {
		tile_white.push_back('0');
		tile_black.push_back('1');
	}

	int paint_1 = 0, paint_2 = 0;
	for (int i = 0; i < sz; ++i) {
		if (tiles[i] != tile_white[i]) {
			++paint_1;
		}
		if (tiles[i] != tile_black[i]) {
			++paint_2;
		}
	}

	cout << min(paint_1, paint_2) << "\n";

	return 0;

}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
using Int = int;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec  8 12:23:25 PST 2019
 **/

template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

constexpr Int K = 80 * 160;
signed main() {
    Int H = in(), W = in();
    auto a = make_vec<Int>(H, W, 0);
    auto b = make_vec<Int>(H, W, 0);
    REP(i, H) REP(j, W) cin >> a[i][j];
    REP(i, H) REP(j, W) cin >> b[i][j];
    auto c = make_vec<Int>(H, W, 0);
    REP(i, H) REP(j, W) c[i][j] = abs(a[i][j] - b[i][j]);
    auto dp = make_vec<Int>(H, W, K, 0);
    dp[0][0][c[0][0]] = true;
    REP(i, H) {
        REP(j, W) {
            REP(k, K) {
                if (!dp[i][j][k]) continue;
                if (i + 1 < H) {
                    dp[i + 1][j][k + c[i + 1][j]] = true;
                    dp[i + 1][j][abs(k - c[i + 1][j])] = true;
                }
                if (j + 1 < W) {
                    dp[i][j + 1][k + c[i][j + 1]] = true;
                    dp[i][j + 1][abs(k - c[i][j + 1])] = true;
                }
            }
        }
    }
    REP(k, K) {
        if (dp[H - 1][W - 1][k]) {
            cout << k << endl;
            return 0;
        }
    }
}


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

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

    int count = 0;

    for(int X = 0;X <= K;X++){
        for(int Y = 0;Y <= K;Y++){
            if(X + Y <= S){
                if(X + Y + K >= S) count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
using namespace std;
const int MAXN=2e5+50;
const int inf=0x3f3f3f3f;
const int M=5000*4;
string s;
struct sa{
	int op;
	int pos;
	string ch;
	int f;
}p[MAXN];
int main()
{
	cin>>s;
	int q;
	cin>>q;
	int ans=0;
	for(int i=1;i<=q;i++){
		cin>>p[i].op;	
		if(p[i].op==2){
			cin>>p[i].pos>>p[i].ch;
			p[i].f=ans;
		}else ans++;
	}
	if(ans&1)reverse(s.begin(),s.end());
	string cnt="";
	for(int i=1;i<=q;i++){
		if(p[i].op==2){
			if(((ans-p[i].f)%2==1&&p[i].pos==1)||((ans-p[i].f)%2==0&&p[i].pos==2))
				s+=p[i].ch;

			if(((ans-p[i].f)%2==1&&p[i].pos==2)||((ans-p[i].f)%2==0&&p[i].pos==1))
				cnt+=p[i].ch;

			
		}
	}
	reverse(cnt.begin(),cnt.end());
	cout<<cnt+s<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 15456
#include<stdio.h>
int main(){
  int n,i,a,b,d;
  char s[200010];	 
  scanf("%s",s);
  for(i=d=a=0;s[i];i++){
    if(s[i]=='T'){
      a--;
      if(a<0){
	d+=2;
	a=0;
      }
    }
    if(s[i]=='S')a++;//printf("%d\n",d);
  }
  printf("%d\n",d);
  return 0;
}


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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;

	vector< vector<char> > mp(h, vector<char>(w));

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> mp[i][j];
		}
	}

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

	bool h2 = true;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			bool h3 = false;
			if (mp[i][j] == '.') {
				h3 = true;
			}
			for (int k = 0; k < 4; k++) {
				if (0 <= j + dx[k] && j + dx[k] < w && 0 <= i + dy[k] && i + dy[k] < h) {
					if (mp[i][j] == '#' && mp[i+dy[k]][j+dx[k]] == '#') {
						h3 = true;
					}
				}
			}
			if (!h3) {
				h2 = false;
			}
		}
	}

	if (h2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
void ERR(T)(in T x) { stderr.writeln(x); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	long[][3] abc;
	abc[0] = RDR.split.to!(long[]);
	abc[1] = RDR.split.to!(long[]);
	abc[2] = RDR.split.to!(long[]);
	abc[0].sort();
	abc[1].sort();
	abc[2].sort();

	auto dp = new long[][](3, N+1);
	fill(dp[0], 1);
	foreach (i; 0..2)
	{
		long j, k;
		while (k < N)
		{
			if (j >= N)
			{
				dp[i+1][k+1] = dp[i+1][k];
				++k;
				continue;
			}
			else if (abc[i][j] >= abc[i+1][k])
			{
				dp[i+1][k+1] = dp[i+1][k];
				++k;
				continue;
			}

			dp[i+1][k] += dp[i][j];
			++j;
		}
	}

	ERR(dp);
	writeln(dp[$-1][0..N].sum);
	stdout.flush();
}

Measured memory_bytes: 12872
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static String _5keta(int n){
        if(n/10000>0){return ""+n;}
        if(n/1000>0){return " "+n;}
        if(n/100>0){return "  "+n;}
        if(n/10>0){return "   "+n;}
        return "    "+n;
    }
    public static void main(String[] args)  {

    	try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line;
            while((line=br.readLine())!=null){if(line.isEmpty())break;
	        	String[] spl = line.split(" ");
	            int n = Integer.parseInt(spl[0]);
	            if(n==0){break;}
                    int[][] matrix = new int[n][n];
                    for(int i=0; i<n;i++){
                        line=br.readLine();
                        spl=line.split(" ");
                        for(int j=0; j<n;j++){
                            matrix[i][j]=Integer.parseInt(spl[j]);   
                        }
                    }
                    for(int i=0; i<n;i++){
                        int sum=0;
                        for(int j=0;j<n;j++){
                            sum+=matrix[i][j];
                            System.out.print(_5keta(matrix[i][j]));
                        }
                        System.out.println(_5keta(sum));
                    }
                    int totalSum = 0;
                    for(int j=0; j<n;j++){
                        int sum=0;
                        for(int i=0; i<n; i++){
                            sum+=matrix[i][j];
                        }
                        totalSum+=sum;
                        System.out.print(_5keta(sum));
                    }
                    System.out.println(_5keta(totalSum));
            }//End WHILE


        }catch(Exception e){e.printStackTrace();}

    }


}

Measured memory_bytes: 17632
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(x[k - 1])

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main() {
    long long int X, A, B;
    cin >> X >> A >> B;
    
    if(B-A<=0) {
        cout << "delicious" << endl;
    } else if(B-A<=X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << 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;
using ll = long long;
using P = pair<int,int>;

void Main()
{
  int N; cin >> N;
  vector<int> A(N);
  unordered_map<int,int> ut;
  ll cnt = 0;
  rep(i,N) {
    cin >> A[i];
    if (ut.find(-A[i]+i) != ut.end()) cnt += ut[-A[i]+i];
    if (ut.find(A[i]+i) == ut.end()) ut[A[i]+i] = 1;
    else ut[A[i]+i]++;    
  }
  cout << cnt << endl;
}

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


Measured memory_bytes: 12156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int forR,forD,forX2,forCal;
  vector<int> vdata(22);
  vector<int> cdata(22);
  int judge = 0;
  forCal = 0;
  
    cin >> forR>>forD>>forX2;
  
  forCal=forX2;
  
  for (int i = 1; i <= 10; i++) {
     forCal = forR*forCal-forD;
    cout << forCal << endl;
  }

  
}
  
 

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n=inp()
    s1=input()
    s2=input()
    if s1[0]==s2[0]:
        ans=3
        index=1
        key=0
    else:
        ans=6
        index=2
        key=1
    while index<=n-1:
        if s1[index]==s2[index]:
            if key==0:
                ans=(ans*2)%mod
                index+=1
            else:
                key=0
                index+=1
                continue
        else:
            if key==0:
                ans=(ans*2)%mod
                index+=2
                key=1
            else:
                ans=(ans*3)%mod
                index+=2
    print(ans)
if __name__ == "__main__":
    main()

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i50 = 0; i50 <= a; ++i50)
  for(int i10 = 0; i10 <= b; ++i10)
  for(int i5  = 0; i5  <= c; ++i5)
  {
    if (500*i50 + 100*i10 + 50*i5 == x) ans++;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3564
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 998244353;
const int N = 100000 + 7;

int main()
{
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i+=2)
        if(s[i]=='L')
        {
            puts("No");
            return 0;
        }
    for(int i=1; i<s.size(); i+=2)
        if(s[i]=='R')
        {
            puts("No");
            return 0;
        }
    puts("Yes");
    return 0;
}


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

int n,a[200005],Next[200005],t[200005];
ll k,p;
bool v[200005];

int getNext(int now){
	p++;
	if (Next[now]<=now){
		p+=Next[now]+n-now;
	}else p+=Next[now]-now;
	now=Next[now];
	if (now==n) now=1;
	else now=now+1;
	return now;
}

int main(){
	cin>>n>>k;
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	for (int i=n;i>=1;--i){
		if (t[a[i]]) Next[i]=t[a[i]];
		t[a[i]]=i;
	}
	memset(t,0,sizeof t);
	for (int i=1;i<=n;++i){
		if (t[a[i]]==0) t[a[i]]=i;
		if (Next[i]==0){
			Next[i]=t[a[i]];
		}
	}
	int now=1;
	while (1){
		if (v[now]){
			k=((k)%p)*(n%p)%p;
			if (k==0) return 0;
			k--; p=0;
			while (1){
				int tt=getNext(now);
				if (p>=k){
					break;
				}
				now=tt;
			}
			break;
		}
		v[now]=1;
		int tt=getNext(now);
		now=tt;
	}
	memset(t,0,sizeof t);
	deque <int> q;
	for (int i=now;i<=n;++i){
		if (t[a[i]]!=0){
			int z;
			do{
				z=q.back(); q.pop_back();
				t[z]=0;
			}while (z!=a[i]);
		}else q.push_back(a[i]),t[a[i]]=1;
	}
	while (!q.empty()){
		cout<<q.front()<<" "; q.pop_front();
	}
	return 0;
}

Measured memory_bytes: 4864
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);

        var ary = ToIntArray(input.ReadLine(), m);

        var c = ary.Sum();

        if (c > n) return -1;
        return n - c;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 3e5+35;
const int maxn = 4e3+23;
LL a[maxn];
int main(){
    a[0] = 100;
    for(int i = 1;i < maxn; ++i) a[i] = a[i-1]+(LL)(a[i-1]*0.01);
    LL x; cin >> x;
    for(int i = 0;i < maxn; ++i){
        if(a[i] >= x){
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a=0, b = 0,c,d, n, k;
string s, t;


int main()
{
	cin >> a >> b;
	if ((a + b) % 2 == 1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << (a + b) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Swap(string s) {
  if (s == "#") {
    cout << "#";
    s = ".";
  } else {
    cout << ".";
    s = "#";
  }
}
int main() {
  int h, w;
  while (1) {
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    string s = "#";
    rep(i, h) {
      rep(j, w) {
        if (i % 2 == 0) {
          if (j % 2 == 0)
            cout << "#";
          else
            cout << ".";
        } else {
          if (j % 2 != 0)
            cout << "#";
          else
            cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3136
s=input()
t=input()
n=len(s)
m=len(t)
INF=10**18
dp=[[INF]*(m+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(-1,n):
  for j in range(-1,m):
    if i==-1 and j==-1:continue
    if i>=0 and j>=0:
      if s[i]==t[j]:dp[i+1][j+1]=min(dp[i][j],dp[i+1][j+1])
      else:dp[i+1][j+1]=min(dp[i][j]+1,dp[i+1][j+1])
    if i>=0:dp[i+1][j+1]=min(dp[i][j+1]+1,dp[i+1][j+1])
    if j>=0:dp[i+1][j+1]=min(dp[i+1][j]+1,dp[i+1][j+1])
print(dp[n][m])


Measured memory_bytes: 42536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	rep(i, s.size()){
		char c = s[i];
		if(i % 2 == 0){
			if(c == 'p') ans--;
		}else{
			if(c == 'g') ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tu = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll S(ll x){
    string y=to_string(x);
    ll n=y.size();
    ll rec=0;
    for(ll i=0;i<n;i++){
        ll j=y[i]-'0';
        rec+=j;
    ;}
    return rec;
}

int main(){
    set<string> Se;
    for(ll i=0;i<=16;i++){
        for(ll j=0;j<100||(j<1000&&i<=15);j++){
            string ret="";
            if(j>0)ret=to_string(j);   
            for(ll k=0;k<i;k++){
                ret+='9';
            ;}
            if(ret=="")ret="0";
            Se.insert(ret);
        ;}
    ;}
    priority_queue<ll, vector<ll>, greater<ll>>  ans;
    priority_queue<ll> once;
    ll n=Se.size();
    auto x=Se.begin();
    for(ll i=0;i<n;i++){
        string f=*x;
        ll e=stoll(f);++x;
        once.emplace(e);
    ;}
    ll R=INF,L=1;
    
    while(!once.empty()){
        ll e=once.top();
        once.pop();
        ll h=S(e);
        if(R*h>=L*e){
            ans.emplace(e);
            R=e,L=h;
        }
    }
    ll K;
    cin >> K;
    ans.pop();
    for(ll i=1;i<=K;i++){
        print(ans.top());
        ans.pop();
    ;}

    return 0;
}


Measured memory_bytes: 1920
# -*- coding: utf-8 -*-

def main(S):
    A = list("abcdefghijklmnopqrstuvwxyz")
    for i in S:
        if i in A:
            A.pop(A.index(i))

    print(A[0]) if A else print("None")
    
if __name__ == '__main__':
    S = input()
    main(S)

Measured memory_bytes: 3188
#include<stdio.h>
int main() {
	int a, b, c,i,result=0;

	scanf("%d%d",&a,&b);
	c = b - a;

	for (i = 1; i <= c; i++) {
		result += i;
	}
	result = result - b;
	printf("%d",result);
	return 0;
}

Measured memory_bytes: 128
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

bool cmp(pair<int,int> &a,pair<int,int> &b){
	return a.F<b.F;
}

void solve(int test_case) {//233
	int n,d;
	cin>>n>>d;
	d=2*d+1;
	n+=d-1;
	cout<<n/d;
	
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3520
#include<iostream>
#include<vector>
#include<cstdio>
//#include<iomanip>
using namespace std;

int main(){
    int N, K;
    double ans, temp=0;
    cin >> N >> K;
    vector<double> p(N);
    for (int i=0; i<K; i++){
        cin >> p.at(i);
        temp += (p.at(i)+1)/2;
    }
    ans = temp;
    for (int i=K; i<N; i++){
        cin >> p.at(i);
        temp = temp + (p.at(i) - p.at(i-K))/2;
        if (temp > ans){
            ans = temp;
        }
    }
//  cout << fixed << setprecision(10)
//    cout << ans << endl;
    printf("%.10f\n", ans);
}

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

int main()
{
    int n;
    cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9)
    {
        cout<<"hon"<<endl;
    }else if(a==0||a==1||a==6||a==8)
    {
        cout<<"pon"<<endl;
    }else
    {
        cout<<"bon"<<endl;
    }
}

Measured memory_bytes: 3456
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> intpair;
typedef std::pair<long long, long long> llpair;

#define mod 1000000007
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i, n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using namespace std;

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

	intpair tiket[4];
	rep(i, 4) {
		int t;
		int n;
		cin >> t >> n;

		int price;
		switch (t) {
		case 1:
			price = 6000;
			break;
		case 2:
			price = 4000;
			break;
		case 3:
			price = 3000;
			break;
		default:
			price = 2000;
			break;
		}

		cout << price * n << "\n";
	}

	return 0;
 }



Measured memory_bytes: 3224
### a<=b<=cととることとし、a,bを固定すると
### cは　c<a+b
N = int(input())
lst = list(map(int, input().split()))
sor = sorted(lst)

def BinarySearch(lst, key): ## lstの値のうち、key以上になる最初のインデックス
    left = -1  ## index=0が条件を満たす場合も存在
    right = len(lst)  ## index = len(lst)-1が条件を満たさないこともある、key以上になるものが存在しない
    
    while right != left + 1:
        mid = (left + right) // 2
        val = lst[mid]
        if val >= key:
            right = mid
        elif val < key:
            left = mid
    return right  ### key以上になるものが存在しない場合はlen(lst)が帰る

res = 0
for i in range(N):
    for j in range(i+1, N):##ここでa<=bを満たしている
        a = sor[i]
        b = sor[j]
        ab = a+b

        highbound = BinarySearch(sor, ab)
        res += highbound - j - 1
print(res)

Measured memory_bytes: 43996
public class Main {


  private static void solve() {
    int n = ni();
    int t = ni();
    int a = ni() * 1000;
    int[] h = na(n);
    
    int min = Integer.MAX_VALUE;
    int minArg = 1;
    for (int i = 0; i < n; i ++) {
      int x = t * 1000 - 6 * h[i];
      int d = Math.abs(x - a);
      if (d < min) {
        min = d;
        minArg = i;
      }
    }
    System.out.println(minArg + 1);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int H, W;
    cin >> H >> W;
    if (H == 0 && W == 0){
      break;
    }
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        if ((i + j) % 2 == 0){
          cout << '#';
        } else {
          cout << '.';
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            //Define
            short[] s, h, c, d;
            s = new short[13];
            h = new short[13];
            c = new short[13];
            d = new short[13];
            for(int i= 0; i<13;i++)
            {
                s[i] = -1;
                h[i] = -1;
                c[i] = -1;
                d[i] = -1;
            }
            for (int i = 0; i < n; i++)
            {
                
                string[] strArr = (Console.ReadLine().Split(' ').Select(_ => _).ToArray());
                if (strArr[0] == "S")
                {
                    s[short.Parse(strArr[1])-1] = 1;
                }
                else if (strArr[0] == "H")
                {
                    h[short.Parse(strArr[1])-1] = 1;
                }
                else if (strArr[0] == "C")
                {
                    c[short.Parse(strArr[1])-1] = 1;
                }
                else if (strArr[0] == "D")
                {
                    d[short.Parse(strArr[1])-1] = 1;
                }
            }
            string strs="", strh="", strc="", strd="";
            for(int i = 0; i<13;i++)
            {
                if (s[i] == -1)
                    strs+=string.Format("S {0}\r\n", i+1);
                if (h[i] == -1)
                    strh += string.Format("H {0}\r\n", i + 1);
                if (c[i] == -1)
                    strc += string.Format("C {0}\r\n", i + 1);
                if (d[i] == -1)
                    strd += string.Format("D {0}\r\n", i + 1);
            }
            Console.Write(strs + strh + strc + strd);
        }
    }
}


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

int main(){
  int n,k,count=0,tmp;
  cin >> n >> k;
  rep(i,n){
    cin >> tmp;
    if(tmp >= k) count++;
  }
  cout << count << endl;
  return 0;
}

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

using namespace std;

int main()
{
	string S;
	cin >> S;
	if (S[2] == S[3] && S[4] == S[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
string s;
int main(){
	cin>>s;
	int ans=0;
	int n=s.length();
	reverse(s.begin(),s.end());
	s[n]='0';
	for(int i=0;i<=n;i++){
		int t=s[i]-'0';
		if(t>=10) {
			t-=10;
			s[i+1]+=1;
		}
		if(t==5) {
			ans+=5;
			if(s[i+1]>='5') s[i+1]++;
		}
		else if(t>5){
			ans+=(10-t);
			s[i+1]+=1;
		}
		else {
			ans+=t;
		}
		//cout<<t<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100;

ll N,a[2][MAX_N];

int main(){
  cin>>N;
  for(ll i=0;i<N;i++){
    cin>>a[0][i];
  }
  for(ll i=0;i<N;i++){
    cin>>a[1][i];
  }

  ll ans=0;
  for(ll i=0;i<N;i++){
    ll tmp=0;
    for(ll j=0;j<i;j++){
      tmp+=a[0][j];
    }
    tmp+=a[0][i];
    for(ll j=i;j<N;j++){
      tmp+=a[1][j];
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
prev = -2
for x in A:
    ans += B[x-1]
    if x==prev+1:
        ans += C[x-2]
    prev = x
print(ans)

Measured memory_bytes: 61208
W, H, N = map(int, input().split())

l = [list(map(int, input().split())) for i in range(N)]

coordinate = [[0, 0], [W, H]]

for i in l:
    if i[2] == 1:
        if coordinate[0][0] < i[0]:
            coordinate[0][0] = i[0]
    elif i[2] == 2:
        if coordinate[1][0] > i[0]:
            coordinate[1][0] = i[0]
    elif i[2] == 3:
        if coordinate[0][1] < i[1]:
            coordinate[0][1] = i[1]
    elif i[2] == 4:
        if coordinate[1][1] > i[1]:
            coordinate[1][1] = i[1]

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

if x <= 0 or y <= 0:
    print(0)
else:
    print(x * y)


Measured memory_bytes: 3064
K = list(map(int,input().split()))[0]
A,B = list(map(int,input().split()))

def is_ok(k, a, b):
  for i in range(a, b+1):
    if i % k == 0:
      return True
  return False

print('OK' if is_ok(K, A, B) else 'NG')

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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    if (a + b - c >= 0) {
        cout << "No" << endl;
    }
    else {
        ll tmp = c - a - b;
        if (4 * a * b < tmp*tmp) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {

		while(sc.hasNext()) {
			int[] arr = inputRan();
			int limit = (int)Math.sqrt(arr.length);
			prime(arr, limit);
		}


	}
	private static void prime(int[] arr, int limit) {
		int cnt = 0;

		for (int j = 2 ; j <= limit; j++) {
			for(int k = 2; k * j <= arr.length; k++) {
				arr[(k * j) - 1] = 1;
			}
		}

		for (int i = 0; i < arr.length; i++) {
			if (arr[i] > 1) {
				cnt++;
			}
		}

		System.out.println(cnt);

	}
	private static int[] inputRan() {
		int x = sc.nextInt();
		int[] arr = new int[x];

		for (int i = 0; i < x; i++) {
			arr[i] = i + 1;
		}

		return arr;
	}

}


Measured memory_bytes: 58420
#include <bits/stdc++.h>
using namespace std;
int memo[4];
 
int main(){
  int a,b;
  
  for(int i=0;i<3;i++){
    cin >> a >> b;
    memo[a-1]++;
    memo[b-1]++;
  }
  
  if( 1 <= memo[0] && memo[0] <= 2 &&
      1 <= memo[1] && memo[1] <= 2 &&
      1 <= memo[2] && memo[2] <= 2 &&
      1 <= memo[3] && memo[3] <= 2 ){
         cout << "YES" << endl;
  } else cout << "NO"  << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    for(int i=a;i<b+1;i++){
        if(c % i == 0 ) ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());

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


Measured memory_bytes: 640
import itertools

def c165(n, m, q, adli):

    ans = 0
    li = list(itertools.combinations_with_replacement(range(1,m+1), n))
    for i in li:
        count = 0
        for a, b, c, d in adli:
            if i[b-1] - i[a-1] == c:
                count += d
        ans = max(ans, count)

    return ans

def main():
    n, m, q = map(int, input().split())
    adli = [list(map(int, input().split()))for i in range(q)]
    print(c165(n, m, q, adli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 84576
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N + 1) {  //最初は全てが根であるとして初期化
    for (int i = 1; i <= N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  UnionFind tree(n);
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    tree.unite(x, y);
  }
  map<ll, ll> f;
  for (ll i = 1; i <= n; i++) {
    ll num = tree.root(i);
    f[num]++;
  }

  ll ans = -1;
  auto begin = f.begin();
  auto end = f.end();
  for (auto iter = begin; iter != end; iter++) {
    ans = max(ans, iter->second);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    while (cin >> n and n) {
        bool l, r, s=false;
        l = r = false;
        int ans=0;

        rep(i, n) {
            string t; cin >> t;

            if (t == "lu") l=true;
            else if (t == "ld") l=false;
            else if (t == "ru") r=true;
            else if (t == "rd") r=false;

            if (!s and l and r) {
                ans++;
                s=!s;
            }
            else if (s and !l and !r) {
                ans++;
                s=!s;
            }
        }

        cout << ans << endl;
    }
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << '\n';
	else cout << 10 << '\n';
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

n = 0

for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			m = i*500+j*100+k*50
			if m == x:
				n += 1
                
print(n)       

Measured memory_bytes: 3060
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

nums=[-1]*20001
for i in range(N):
  if nums[AB[i][0]]<0:
    nums[AB[i][0]]=AB[i][1]
  else:
    nums[AB[i][0]]=min(AB[i][1], nums[AB[i][0]])
  
for i in range(1, H):
  if nums[i]>0:
    for j in range(N):
      if nums[i+AB[j][0]]>0:
        if nums[i+AB[j][0]]>nums[i]+AB[j][1]:
          nums[i+AB[j][0]]=nums[i]+AB[j][1]
      else:
        nums[i+AB[j][0]]=nums[i]+AB[j][1]
      
anss=[]
for i in range(H, 20000):
  if nums[i]>0:
    anss.append(nums[i])
    
print(min(anss))

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T>inline bool chmax(T& a,T b){
  if(a < b){
    a = b;
    return true;
  }
  return false;
}
template<class T>inline bool chmin(T& a,T b){
  if(a > b){
    a = b;
    return true;
  }
  return false;
}

const ll INF = 1e18;
const int MX = 2005;

int n,m;
vector<vector<int>>G;

int dp[100100];
int rec(int v){
  if(dp[v] != -1) return dp[v];
  
  int res = 0;
  for(auto nv:G[v]){
    chmax(res, rec(nv) + 1);
  }
  return dp[v] = res;
}

int main() {
  cin >> n >> m;
  G.assign(n,vector<int>());
  rep(i,m){
    int x,y; cin >> x >> y;
    --x,--y;
    G[x].push_back(y);
  }
  
  rep(v,n) dp[v] = -1;
  
  int res = 0;
  rep(v,n) chmax(res, rec(v));
  cout << res << endl;
}

Measured memory_bytes: 8192