akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
template <int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod)
            x -= mod;
    }
    ModInt &operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0)
            x += mod;
        return *this;
    }
    ModInt &operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt &operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
    friend ostream &operator<<(ostream &s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream &operator>>(istream &s, ModInt<mod> &a) {
        s >> a.x;
        return s;
    }
};
using mint = ModInt<(int)1e9 + 7>;
int main(int argc, char const *argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long n;
    mint ans=0;
    cin>>n;
    vector<long long>v(n);
    for(long long i=0;i<n;i++) cin>>v[i];
    for(long long i=0;i<60LL;i++) {
        long long cnt1=0,cnt0=0;
        for(auto &mask:v) {
            if(mask>>i&1)
                cnt1++;
            else
                cnt0++;
        }
        mint total=(1LL<<i);
        ans+=(total*cnt1*cnt0);     
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
function main(input)
{
    const args=input.split(' ')
    const a=parseInt(args[0],10)
    const b=parseInt(args[1],10)

    if ((a * b) % 2 === 0)
    {
        console.log('Even')
    }
    else
    {
        console.log('Odd')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N, K = list(map(int, input().split()))
k_max = int(cmb(N - 1, 2))

if N == 2:
    if K == 0:
        print(1)
        print(1, 2)
    else:
        print(-1)
elif k_max < K:
    print(-1)
else:
    E = [[v, N] for v in range(1, N)]

    add_need = k_max - K
    if add_need >= 1:
        count = 0
        for i in range(1, N):
            for k in range(i + 1, N):
                E.append([i, k])
                count += 1
        #         print(count)
                if count == add_need:
                    break
            if count == add_need:
                break

    print(len(E))
    for e in E:
        print(e[0], e[1])



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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  ll A,B,N;
  cin>>A>>B>>N;
  //int x = min(B-1,N);
  ll x;
  if(N%B == 0){
    x = N-1;
  }else if(N <= B-1){
    x = N;
  }else{
    x = (N/B-1)*B+B-1;
  }
  //cout << x << endl;
  //cout << x << endl;
  cout << (A*x)/B - A*(x/B) << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long int ll;
using namespace std;
int main(){
	io;
	ll n,k;
	cin >> n >> k;
	n = n%k;
	ll temp = abs(n-k);
	if(temp < n){
		n = temp;
	}
	cout << n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int w,h,n;
int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};
string mp[20];

struct dat{
  int y1,x1;
  int y2,x2;
  int y3,x3;
};


int D[14][14][15][15][15][15];
queue<dat> Q;
void DD(dat &a,int b){D[a.y1-1][a.x1-1][a.y2-1][a.x2-1][a.y3-1][a.x3-1] = b;}
int DD(const dat &a){return D[a.y1-1][a.x1-1][a.y2-1][a.x2-1][a.y3-1][a.x3-1];}

bool check(const dat &a){
  if(mp[a.y1][a.x1]=='#') return 0;
  if(n>=2&&mp[a.y2][a.x2]=='#') return 0;
  if(n>=3&&mp[a.y3][a.x3]=='#') return 0;
  return DD(a)==-1;
}

void update(const dat &a){
  int cost = DD(a);

  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      for(int k=0;k<5;k++){
	int ny1 = a.y1+dy[i], nx1 = a.x1+dx[i];
	int ny2 = a.y2+dy[j], nx2 = a.x2+dx[j];
	int ny3 = a.y3+dy[k], nx3 = a.x3+dx[k];
	if(n<=1) ny2 = 15,nx2 = 14;
	if(n<=2) ny3 = 14,nx3 = 15;
	
	dat nt = (dat){ny1,nx1,ny2,nx2,ny3,nx3};
	if(!check(nt))continue;
	if((ny1==ny2&&nx1==nx2) ||(ny2==ny3&&nx2==nx3) ||(ny3==ny1&&nx3==nx1))continue;//same pos
	if(((a.y1==ny2&&a.x1==nx2) && (a.y2==ny1&&a.x2==nx1)) || // swap positoin
	   ((a.y2==ny3&&a.x2==nx3) && (a.y3==ny2&&a.x3==nx2)) ||
	   ((a.y3==ny1&&a.x3==nx1) && (a.y1==ny3&&a.x1==nx3)) )continue;

	Q.push(nt);
	DD(nt,cost+1);
      }
}

bool goal(const dat &s,const dat &t){
  char a = mp[s.y1][s.x1];
  char b = mp[s.y2][s.x2];
  char c = mp[s.y3][s.x3];
  char A = mp[t.y1][t.x1];
  char B = mp[t.y2][t.x2];
  char C = mp[t.y3][t.x3];
  return toupper(a)==A&&(n<=1||toupper(b)==B)&&(n<=2||toupper(c)==C);
}

int bfs(dat start){
  memset(D,-1,sizeof(D));
  while(!Q.empty())Q.pop();
  Q.push(start);
  DD(start,0);
  
  while(!Q.empty()){
    dat t = Q.front();Q.pop();
    if(goal(start,t)) return DD(t);
    update(t);
  }
  return 0;
}

int main(){
  while(1){
  cin>>w>>h>>n;
  if(!w&&!h&&!n)break;
  cin.ignore();
  for(int i=0;i<h;i++)getline(cin,mp[i]),mp[i]+='#';
  

  dat start = (dat){15,15,15,14,14,15};
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(!islower(mp[i][j]))continue;
      if(start.y1==15) start.y1=i,start.x1=j;
      else if(start.y2==15) start.y2=i,start.x2=j;
      else start.y3=i,start.x3=j;
    }

  cout<<bfs(start)<<endl;
  }
  return 0;
}

Measured memory_bytes: 47748
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;

  if (s.substr(0,n/2) == s.substr(n/2,n)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){
  int n;
  cin >> n;
  vector<double> vec;
  for(int i=0; i<n; i++){
    double num;
    cin >> num;
    vec.push_back(num);
  }
  sort(vec.begin(), vec.end(), greater<int>());
  double num = 0;
  num += vec[n-1];
  for(int i=vec.size()-2; i>=0; i--){
    num += vec[i];
    num = num / 2.0;
  }
  cout << setprecision(10) << num << endl;
  return 0;
}
    

Measured memory_bytes: 256
S = input()

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == 'R' or S[i] == 'U' or S[i] == 'D':
            continue
        else:
            print('No')
            break
    else:
        if S[i] == 'L' or S[i] == 'U' or S[i] == 'D':
            continue
        else:
            print('No')
            break
else:
    print('Yes')

Measured memory_bytes: 3064
#include<stdio.h>
#define N 100001

typedef struct{
  char mark;
  int num,id;
}Cards;

Cards A[N];


void QuickSort(int p, int r){
  int q;
  if (p<r){
    q = Partition(p,r);
    QuickSort(p,q-1);
    QuickSort(q+1,r);
  }
}

int Partition(int p, int r){
  int x,i,j;
  Cards temp;
  x = A[r].num;
  i = p-1;
  for (j=p;j<=r-1;j++){
    if (A[j].num<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
}

int main(){
  int n,i,key,flag=0;
  char temp;
  scanf("%d%c",&n,&temp);
  for (i=0;i<n;i++){
    scanf("%c%d%c",&A[i].mark,&A[i].num,&temp);
    A[i].id=i;
  }
  QuickSort(0,n-1);
  for (i=1;i<n;i++){
    if ((A[i].num==A[i-1].num) && (A[i].id<=A[i-1].id)){
      printf("Not stable\n");
      flag=1;
      break;
    }
  }
  if (flag==0){
    printf("Stable\n");
  }

  for (i=0;i<n;i++){
    printf("%c %d\n",A[i].mark,A[i].num);
  }
 
  return 0;
}

Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    int h, w, k;
    cin >> h >> w >> k;
    char c[h][w];
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
    }
    int ans = 0;
    for(int r = 0; r < (1<<h); r++){// 行をYes/Noでフラグ立てる
        for(int C = 0; C < (1<<w); C++){// 列をフラグ立てる
            int black = 0;
            rep(i,h){
                rep(j,w){
                    // フラグが立っていないところが'#'なら黒
                    if(((r >> i) & 1)==0 && ((C >> j) & 1)==0 && c[i][j]=='#') black++;
                }
            }
            if(black == k) ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3620
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var A = cin.ReadInt();
            var B = cin.ReadInt();

            WriteLine((A + B) % 24);
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }

    public class Pair<T1, T2>
    {
        public T1 First;
        public T2 Second;
        public Pair() { First = default(T1); Second = default(T2); }
        public Pair(T1 f, T2 s) { First = f; Second = s; }
        public override string ToString() { return "(" + First + ", " + Second + ")"; }
        public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            else if (obj == null) return false;
            var tmp = obj as Pair<T1, T2>;
            return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second);
        }
    }

    #region HashMap
    public class HashMap<K, V> : Dictionary<K, V>
    {
        public HashMap() : base() { }
        public HashMap(int cap) : base(cap) { }
        public HashMap(IDictionary<K, V> dictionary) : base(dictionary) { }
        new public V this[K i]
        {
            get
            {
                V v;
                return TryGetValue(i, out v) ? v : base[i] = default(V);
            }
            set { base[i] = value; }
        }
    }
    #endregion
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mod 1000000007
using namespace std;

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
    fast();
    ll t=1;
//    cin>>t;
    while(t--){
    	ll fans=INT_MAX;
    	string s,t;
    	cin>>s>>t;
    	ll m=s.length();
    	ll n=t.length();
    	ll val=abs(m-n);
    	for(ll i=0;i<=val;i++){
    		ll ans=0;
    		string u=s.substr(i,t.size());
    		for(ll j=0;t[j];j++){
    			if(t[j]!=u[j]){
    				++ans;
				}
			}
			fans=min(fans,ans);
		}
		cout<<fans;
	}
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << " " << x << "\n"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e2 + 3;
const ll M = 1e5 + 3;
const ll INF = 1e18;

ll n, k, w[N], v[N], dp[M], mx, res;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fill(dp, dp + M, INF);
	
	cin >> n >> k;
	for (ll i = 1; i <= n; ++i) {
		cin >> w[i] >> v[i];
		mx += v[i];
	}
	
	dp[0] = 0;
	for (ll i = 1; i <= n; ++i) {
		for (ll j = mx - v[i]; j >= 0; --j) {
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
		}
	}
	
	res = 0;
	for (ll i = 1; i <= mx; ++i) {
		if (dp[i] <= k) res = i;
	}
	cout << res;
	
	return 0;
}


Measured memory_bytes: 1024
fore = {}
aft  = {}
cont = {}
while True:
    s = input().strip()
    if s=='':
        break
    cst,n = map(int,s.split(','))
    if cst in fore:
        fore[cst] += 1
    else:
        fore[cst] = 1
while True:
    try:
        s = input().strip()
        cst,n = map(int, s.split(','))
        if cst in aft:
            aft[cst] += 1
        else:
            aft[cst] = 1
    except EOFError:
        break

for cst in fore:
    if cst in aft:
        cont[cst] = fore[cst] + aft[cst]

for cst in sorted(cont.keys()):
    print(cst,cont[cst])

Measured memory_bytes: 7576
# n = int(sys.stdin.readline())
import sys,bisect,math
sys.setrecursionlimit(15000)

s = sys.stdin.readline().rstrip()
cum = [0]*(len(s)+1)#cumulative sum
import collections
d = collections.defaultdict(int)
d[0] = 1
ret = 0
dig = 1
for i in range(len(s))[::-1]:
    cum[i]=(int(s[i])*dig+cum[i+1])%2019
    dig = (dig*10)%2019
    #cum[i+1]=int(s[i:])%2019
    if cum[i] in d:
        ret += d[cum[i]]
    d[cum[i]] += 1
#print(d,cum,ret)
print(ret)

Measured memory_bytes: 70324
import sys

n, k = map(int, input().split())

a = list(map(int, input().split()))

num_flag = [0 for i in range(n)]

for item in a:
    num_flag[item - 1] += 1

# while 0 in num_flag:
#     num_flag.remove(0)

# num_flag.sort()

# cnt = 0
# while len(num_flag) > k:
#     print(len(num_flag))
#     cnt += num_flag[0]
#     num_flag.pop(0)

num_flag.sort(reverse=True)

cnt = 0
for i in range(k):
    cnt += num_flag[i]

print("{}".format(n - cnt))

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

typedef pair<int,int> PII;


int main() {
    int N;
    cin >> N;
    vector<int> data;
    int pl = 0;
    int mn = 0;
    vector<int> pls, mns;

    for(int i=0; i<N; i++) {
        int a;
        cin >> a;
        if(a>0)
            pls.push_back(a);
        else
            mns.push_back(a);
    }
    sort(mns.begin(), mns.end());
    sort(pls.begin(), pls.end());
    reverse(pls.begin(), pls.end());
    if(pls.size() == 0) {
        int k = mns.back();
        mns.pop_back();
        pls.push_back(k);
    }
    if(mns.size() == 0) {
        int k = pls.back();
        pls.pop_back();
        mns.push_back(k);
    }

    vector<PII> output;

    while(pls.size() >= 2) {
        int k = mns.back();
        mns.pop_back();
        int j = pls.back();
        pls.pop_back();
        output.push_back(PII(k, j));
        k -= j;
        mns.push_back(k);
    }
    while(mns.size() >= 1) {
        int k = pls.back();
        pls.pop_back();
        int j = mns.back();
        mns.pop_back();
        output.push_back(PII(k, j));
        k -= j;
        pls.push_back(k);

    }
    cout << pls[0] << endl;
    for(auto elem: output) {
        int a = elem.first;
        int b = elem.second;
        cout << a << " " << b << endl;
 
    }


    return 0;
} 

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {
	void Solve() {
		string S; cin >> S;
		UL Q; cin >> Q;
		bool flip = false;
		string Front, Back;
		rep(i, Q) {
			UL c; cin >> c;
			if (c == 1) {
				flip = !flip;
			}
			if (c == 2) {
				UL F; cin >> F;
				char t; cin >> t;
				if (!flip) ((F == 1) ? Front : Back).push_back(t);
				else ((F == 2) ? Front : Back).push_back(t);
			}
		}

		S += Back;
		reverse(S.begin(), S.end());
		S += Front;
		if (!flip) reverse(S.begin(), S.end());

		cout << S << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1348
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const ll p=1000000007;
const int N=100010;
int cmp(pii a,pii b)
{
    if(a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
int n,m,t,t2;
int a[N],b[N],d[N];
pii c[N];
ll e[N];
ll add(ll a,ll b)
{
    a+=b;
    return a>=p?a-p:a;
}
void add(int x,ll v)
{
    for(;x<=t2;x+=x&-x)
        e[x]=add(e[x],v);
}
ll sum(int x)
{
    ll s=0;
    for(;x;x-=x&-x)
        s=add(s,e[x]);
    return s;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=m;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
        if(a[i]>b[1]&&a[i]<b[m])
        {
            int x=lower_bound(b+1,b+m+1,a[i])-b;
            if(b[x]==a[i])
                continue;
            c[++t]=pii(a[i]-b[x-1],b[x]-a[i]);
            d[++t2]=b[x]-a[i];
        }
    sort(d+1,d+t2+1);
    t2=unique(d+1,d+t2+1)-d-1;
    for(int i=1;i<=t;i++)
        c[i].second=lower_bound(d+1,d+t2+1,c[i].second)-d;
    sort(c+1,c+t+1,cmp);
    t=unique(c+1,c+t+1)-c-1;
    ll ans=1;
    for(int i=1;i<=t;i++)
    {
        ll s=sum(c[i].second-1)+1;
        ans+=s;
        add(c[i].second,s);
    }
    ans%=p;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2560
def main():
    N = int(input())
    S = [[] * N for i in range(N)]
    ans = 0

    for i in range(N):
        A = int(input())
        for j in range(A):
            x, y = map(int, input().split())
            S[i].append([x-1, y])

    P = [0]*N
    
    for i in range(2**N):
        for j in range(N):
            if P[j] == 0:
                P[j] = 1
                break
            else:
                P[j] = 0
        
        if sum(P) <= ans:
            continue
        flag = 0
        for p in range(len(P)):
            if P[p] == 1:
                for s in S[p]:
                    if s[1]!= P[s[0]]:
                        flag = 1
        if flag == 1:
            continue
        else:
            ans = sum(P)
        
    print(ans)


 
if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
 
        while(n-- > 0){
            char[] s = sc.nextLine().toCharArray();
            for(int i=0;i<s.length;i++) s[i] -= 'a';
 
            String aft = "";
 
            for(int a=1;aft.equals("");a++){
                if(gcd(a,26) != 1) continue;
                for(int b=0;b<26;b++){
                    for(int i=0;i<s.length;i++){
                        if(0<=s[i] && s[i]<26){
                            aft += (char)((a * s[i] + b) % 26 + 'a');
                        }
                        else{
                            aft += (char)(s[i] + 'a');
                        }
                    }
 
                    if(aft.contains("that") || aft.contains("this")) break;
                    aft = "";
                }
            }
 
            System.out.println(aft);
        }
    }
 
    private static int gcd(int a,int b){
        return b==0 ? a : gcd(b,a%b);
    }
}


Measured memory_bytes: 59988
#include<deque>
#include<queue>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const llint mod=1000000007;


int main(void){
	int N,M,i,j,a,b,ans,ok;
	deque<int> path;
	vector<bool> tota;
	vector<vector<int>> edge;
	scanf("%d %d",&N,&M);
	edge.resize(N+1);
	tota.resize(N+1);
	for(i=0;i<M;i++){
		scanf("%d %d",&a,&b);
		edge[a].pub(b);
		edge[b].pub(a);
	}
	path.pub(1);
	tota[1]=true;
	while(-1){//伸ばす
		a=path.front();ok=0;
		for(i=0;i<edge[a].size();i++){
			if(tota[edge[a][i]]==false){
				ok=1;
				tota[edge[a][i]]=true;
				path.push_front(edge[a][i]);
				break;
			}
		}
		if(ok==0){break;}
	}
	while(-1){//伸ばす
		a=path.back();ok=0;
		for(i=0;i<edge[a].size();i++){
			if(tota[edge[a][i]]==false){
				ok=1;
				tota[edge[a][i]]=true;
				path.push_back(edge[a][i]);
				break;
			}
		}
		if(ok==0){break;}
	}
	printf("%d\n",path.size());
	for(i=0;i<path.size();i++){
		if(i<path.size()-1){ printf("%d ",path[i]); } else{ printf("%d\n",path[i]); }
	}
	return 0;
}



Measured memory_bytes: 6656
X,N = map(int, input().split())
if N ==0:
  print(X)
  exit() 
if N !=0:
  p = list(map(int, input().split()))
if p.count(X) == 0:
  print(X)
  exit()
for a in range(1000):
  if p.count(X-a) ==0:
    print(X-a)
    exit()
  elif p.count(X+a) ==0:
    print(X+a)
    exit()


Measured memory_bytes: 9220
#define _CRT_SECURE_NO_WARNINGS
#define TASK "C-large"
#pragma comment(linker, "/STACK:171088640")
#include <stdio.h>
#include <iostream>
#include <iomanip> 
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <assert.h>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000007;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int gcd(int a, int b) {
	if (!b) {
		return a;
	}
	return gcd(b, a % b);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
#endif

	int n, k, mx = -1, g = 0;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; ++i) {
		int a;
		scanf("%d", &a);
		g = gcd(g, a);
		mx = max(mx, a);
	}
	if (k <= mx && k % g == 0) {
		printf("POSSIBLE\n");
	}
	else {
		printf("IMPOSSIBLE\n");
	}

	my_return(0);
}

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

## Library

from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

K=int(input())
S = input()

## Logic

if len(S)<=K:
    print(S)
else:
    print(S[0:K]+"...")

## output



Measured memory_bytes: 72904
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let a=tnn(3)
  let k=tn()
  let m=a.indexOf(Math.max(null,...a))
  for(let i=0;i<k;i++){
    a[m]*=2
  }
  to(a.reduce((a,x) => a+=x,0))
}
main()


Measured memory_bytes: 7372
#include<stdio.h>
#include<stdlib.h>
int cmpint(const void *a,const void *b){
  return *(int* )b - *(int* )a;
}//b-aかaーbで小さい順か大きい順に決められる

int main(){
  int N;
  scanf("%d",&N);
  int i,j;
  int a[3*N];
  for(i=0;i<3*N;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,3*N,sizeof(int),cmpint);
  long long int count=0;
  for(i=0;i<N;i++){
    count+=a[1+2*i];
  }
  printf("%lld",count);
}


Measured memory_bytes: 2556
import copy
n = int(input())
ans = 0
for i in range(2,10):
  list = ["3","5","7"]
  for j in range(i):
    dlist = []
    for k in list:
      for l in ("3","5","7"):
        dlist.append(k+l)
    list = copy.copy(dlist)
  for m in list:
    if "3" in m and "5" in m and "7" in m:
      if int(m) <= n:
        ans +=1
      else:
        print(ans)
        exit()

Measured memory_bytes: 10108
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($($args),*), ($($args),*));
    };
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.cin();
    let b: usize = sc.cin();
    let c: usize = sc.cin();
    put!(
        if a==b&&b==c { "Yes" } else { "No" }
        );
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;
vector<int>pos[27];

int F(int ind, int curr){
  int lo = 0;
  int hi = pos[ind].size() - 1;
  int res = 1e8;
  while (lo <= hi){
    int mid = lo + ((hi - lo) / 2);
    if (pos[ind][mid] > curr){
      res = min(res, mid);
      hi = mid - 1;
    }
    else {
      lo = mid + 1;
    }
  }
  if (res >= 1e7){
    return -1;
  }
  return pos[ind][res];
}

int main(){
  FASTER;
  string s, t;
  cin >> s >> t;
  vector<int>cs(26, 0), ct(26, 0);
  for (int i = 0; i < s.size(); i++){
    cs[s[i] - 'a']++;
    pos[s[i] - 'a'].push_back(i + 1);
  }
  for (int i = 0; i < t.size(); i++){
    ct[t[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++){
    if (ct[i] > 0 && cs[i] <= 0){
      cout << -1 << '\n';
      return 0;
    }
  }
  /*
  for (int i = 0; i < 26; i++){
    for (int j = 0; j < pos[i].size(); j++){
      cout << pos[i][j] << ' ';
    }
    cout << '\n';
  }
  */
  int curr = 0;
  ll ans = 0;
  int sz = s.size();
  for(int i = 0; i < t.size(); i++){
    int ind = t[i] - 'a';
    int x = F(ind, curr);
    /*
    cout << curr << ' ';
    cout << (char)(ind + 'a');
    cout << ' ' << x << '\n';
    */
    if (x == -1){
      ans += (sz - curr);
      ans += (pos[ind][0]);
      curr = pos[ind][0];
    }
    else {
      ans += (x - curr);
      curr = x;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  int N, W;
  cin >> N >> W;
  vector<P> b(N + 1);
  rep(i, N) {
    int w, v;
    cin >> w >> v;
    b[i + 1] = P(w, v);
  }
  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));

  for (int i = 1; i <= N; i++) {
    for (int w = 1; w <= W; w++) {
      dp[i][w] = dp[i - 1][w];
      if (w < b[i].first) continue;
      dp[i][w] = max(dp[i - 1][w - b[i].first] + b[i].second, dp[i - 1][w]);
    }
  }
  cout << dp[N][W] << endl;

  return 0;
}

Measured memory_bytes: 83084
/* dijkstra.cpp
    ダイクストラ法で、ある頂点から各頂点への最短距離を求めるアルゴリズム
    負の辺が含まれる場合はうまく計算出来ないので、ベルマンフォード法を用いる

    verified: AOJ GRL_1_A
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
*/

#include <bits/stdc++.h>
using namespace std;

template <typename T>
struct Edge {
    int to;
    T cost;
};
using Graph = vector<vector<Edge<long long>>>;  // 距離/コストの型 T を指定する
const long long INF = (1LL << 60);              // 型 T のINF (完全な最大値は取らないように)

/* dijkstra(G,s,dis,prev)
    入力：グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
    計算量：O(|E|log|V|)
    副作用：dis, prevが書き換えられる
*/
template <typename T>
void dijkstra(const Graph &G, int s, vector<T> &dis, vector<int> &prev) {
    using P = pair<T, int>;

    int N = G.size();
    dis.resize(N, INF);
    prev.resize(N, -1);
    priority_queue<P, vector<P>, greater<P>> pq;  // the least element is top. first:cost, second: node
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();  // the least element
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                prev[e.to] = v;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

/* get_path(prev, t)
    入力：dijkstra で得た prev, ゴール t
    出力： t への最短路のパス
*/
vector<int> get_path(const vector<int> &prev, int t) {
    vector<int> path;
    for (int cur = t; cur != -1; cur = prev[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end());
    return path;
}

int main() {
    int V;
    cin >> V;
    Graph G(V);
    for (int i = 0; i < V - 1; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    vector<long long> ans(Q);
    vector<long long> dis;
    vector<int> prev;
    dijkstra(G, K, dis, prev);
    for (int i = 0; i < Q; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        ans[i] = dis[x] + dis[y];
    }

    for (auto i : ans) {
        cout << i << "\n";
    }

    return 0;
}


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

void Main() {
	int N;
	string n;
	set<string> sSet;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> n;
		sSet.insert(n);
	}
	cout << sSet.size() << endl;
}

int main() {
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 19100
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2002,M=1e9+7;
int n,i,f[N*2][N*2],fac[N*4],inv[N*4],ans,a[200002],b[200002],j;
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%M)if(y&1)z=1ll*z*x%M;return z;}
int INV(int x){return pw(x,M-2);}
signed main(){
	scanf("%lld",&n);
	for (i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]),f[N-a[i]][N-b[i]]++;
	for (i=1;i<N+N;i++)
		for (j=1;j<N+N;j++) (f[i][j]+=(f[i-1][j]+f[i][j-1])%M)%=M;
	fac[0]=1;
	for (i=1;i<N*4;i++) fac[i]=fac[i-1]*i%M;
	inv[N*4-1]=INV(fac[N*4-1]);
	for (i=N*4-2;~i;i--) inv[i]=inv[i+1]*(i+1)%M;
	for (i=1;i<=n;i++) (ans+=f[a[i]+N][b[i]+N]-1ll*fac[(a[i]+b[i])*2]*inv[a[i]*2]%M*inv[b[i]*2]%M+M)%=M;
	printf("%lld",ans*INV(2)%M);
}

Measured memory_bytes: 128768
from collections import deque

h,w = map(int,input().split())

s = [0]*(h+2)
for i in range(1,h+1):
    s[i] = [0] + list(input()) + [0]
s[0] = [0]*(w+2)
s[-1] = [0]*(w+2)

reach = [[-1 for j in range(w+2)] for i in range(h+2)]
lis = []

for i in range(1,h+1):
    for j in range(1,w+1):
        if reach == 0:
            pass
        else:
            black = 0
            white = 0
            if s[i][j] == "#":
                state = 1
                black += 1
            else:
                state = 0
                white += 1
                
            q = deque()
            q.append([i,j,state])
            reach[i][j] = 0
            
            while q:
                [x,y,state] = q.popleft()
                
                if reach[x-1][y] == -1:
                    if state == 0 and s[x-1][y] == "#":
                        reach[x-1][y] = 0
                        q.append([x-1, y ,1])
                        black += 1
                    elif  state == 1 and s[x-1][y] == ".":
                        reach[x-1][y] = 0
                        q.append([x-1, y ,0])
                        white += 1
                
                if reach[x+1][y] == -1:
                    if state == 0 and s[x+1][y] == "#":
                        reach[x+1][y] = 0
                        q.append([x+1, y ,1])
                        black += 1
                    elif  state == 1 and s[x+1][y] == ".":
                        reach[x+1][y] = 0
                        q.append([x+1, y ,0])
                        white += 1
                        
                if reach[x][y-1] == -1:
                    if state == 0 and s[x][y-1] == "#":
                        reach[x][y-1] = 0
                        q.append([x, y-1 ,1])
                        black += 1
                    elif  state == 1 and s[x][y-1] == ".":
                        reach[x][y-1] = 0
                        q.append([x, y-1 ,0])
                        white += 1
                    
                if reach[x][y+1] == -1:
                    if state == 0 and s[x][y+1] == "#":
                        reach[x][y+1] = 0
                        q.append([x, y+1 ,1])
                        black += 1
                    elif  state == 1 and s[x][y+1] == ".":
                        reach[x][y+1] = 0
                        q.append([x, y+1 ,0])
                        white += 1
                
            lis.append([black,white])
ans = 0
for s,t in lis:
    ans += s*t
print(ans)

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


int main() {
  int k;
  cin >> k;
  int a, b;
  cin >> a >> b;
  bool ans= false;
  for(int i = a;i < b+1;++i){
    if(i%k == 0){
      ans = true;
      break;
    }
  }
  if(ans) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;

public class Main {

	static FastScanner sc = new FastScanner();

	public static void main(String[] args) throws Exception{
		int[] hist = new int[256];
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int[] I = new int[N];
			for (int i = 0; i < N; ++i) {
				I[i] = sc.nextInt();
			}
			double best = Double.MAX_VALUE;
			int bs = 0;
			int ba = 0;
			int bc = 0;
			for (int s = 0; s < 16; ++s) {
				for (int a = 0; a < 16; ++a) {
					for (int c = 0; c < 16; ++c) {
						Arrays.fill(hist, 0);
						int r = s;
						for (int i = 0; i < N; ++i) {
							r = (a * r + c) & 0xFF;
							hist[(I[i] + r) & 0xFF]++;
						}
						double e = 0;
						for (int i = 0; i < 256; ++i) {
							if (hist[i] != 0) {
								double v = 1.0 * hist[i] / N;
								e -= v * Math.log(v);
							}
						}
						if (e < best - 1e-10) {
							best = e;
							bs = s;
							ba = a;
							bc = c;
						}
					}
				}
			}
			System.out.println(bs + " " + ba + " " + bc);
		}
	}

	static class FastScanner {
		Reader input;

		FastScanner() {
			this.input = new BufferedReader(new InputStreamReader(System.in));
		}

		int nextInt() throws IOException {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			int ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		}
	}

}

Measured memory_bytes: 21320
import bisect

WCLS = ["light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"]
WEIGHT = [48,51,54,57,60,64,69,75,81,91]
if __name__ == '__main__':

    while True:
        try:
            w = float(input())
            
            ind = bisect.bisect_left(WEIGHT,w)
            print(WCLS[ind])
        except EOFError:
            break



Measured memory_bytes: 5612
#include <iostream>

using namespace std;

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

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        while (a % 2 == 0)
        {
            sum++;
            a /= 2;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  bool flag = false;
  srep(i,a,b+1) {
    if(i%k==0) flag=true;
  }
  if(flag) cout << "OK" << endl;
  else cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.Stack;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] tokens = scanner.nextLine().split(" ", -1);

        Stack<Integer> stack = new Stack<>();
        int lhs, rhs;
        for (String token : tokens) {
            switch (token) {
                case "+":
                    rhs = stack.pop();
                    lhs = stack.pop();
                    stack.push(lhs + rhs);
                    break;
                case "-":
                    rhs = stack.pop();
                    lhs = stack.pop();
                    stack.push(lhs - rhs);
                    break;
                case "*":
                    rhs = stack.pop();
                    lhs = stack.pop();
                    stack.push(lhs * rhs);
                    break;
                case "/":
                    rhs = stack.pop();
                    lhs = stack.pop();
                    stack.push(lhs / rhs);
                    break;
                default:
                    stack.push(Integer.parseInt(token));
                    break;
            }
        }
        System.out.println(stack.pop());
    }
}



Measured memory_bytes: 26192
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int A,B;
    cin >> A>>B;

    cout << (A-1)*(B-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int chmin(long long *x, long long y) { if (*x > y) { *x = y; return 1; } return 0; }
int chmax(long long *x, long long y) { if (*x < y) { *x = y; return 1; } return 0; }
const long long INF = LONG_MAX >> 5;

int main() {
    
    int N;
    long long W;
    long long weight[110];
    long long value[110];
    long long **dp;
    dp = (long long **)calloc(110, sizeof(long long *));
    for (int i = 0; i < 110; i++) {
        dp[i] = (long long *)calloc(100100, sizeof(long long));
    }

    
    scanf("%d%lld", &N, &W);
    
    for (int i = 0; i < N; i++) {
        scanf("%lld%lld", &weight[i], &value[i]);
    }
    
    for (int i = 0; i < N; i++) {
        for (int sum_w = 0; sum_w <= W; sum_w++) {
            if (sum_w - weight[i] >= 0) {
                chmax(&dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            chmax(&dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }
    
    printf("%lld\n", dp[N][W]);
    
    return 0;
}


Measured memory_bytes: 78592
#include <iostream>

#define _USE_MATH_DEFINES

#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	double r;
	double s, l;
	
	cin >> r;

	s = r * r * M_PI;
	l = 2 * r* M_PI;

	printf("%f %f", s, l);
	return 0;
}

Measured memory_bytes: 1232
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    unsigned int x;
    cin >> x;
    bitset<32> bit(x);
    cout << bit << endl;
    cout << ~bit << endl;
    cout << (bit<<1) << endl;
    cout << (bit>>1) << endl;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
//const int MAXN = 200005;

LL x, y, p;

LL want(LL k) {
	return p % k == 0 ? p / k - 1 : p / k;
}

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

	int tc;
	cin >> tc;
	while (tc--) {
		cin >> x >> y;
		p = x * y;
		if (x > y) swap(x, y);
		if (p == 1) {
			cout << "0\n";
			continue;
		}
		
		LL l = x, r = y + 1, last = x;
		while (l <= r) {
			LL m = (l + r) / 2;
			if (m * (m - 1) <= p && want(m) > 0) {
				last = m;
				l = m + 1;
			}
			else {
				r = m - 1;
			}
		}
		
		LL ans = last - 1, take = 2e18;
		if (last > x) {
			take = want(last);
		}
		else if (x != 1) {
			take = want(x - 1);
		}
		
		LL other = want(last + 1);
		if (other == take) other--;
		ans += max(other, 0LL);
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
import sys
import math

n, k = map(int, input().split())

# n_start = math.floor(n / k)
# # print(n_start)
# n = n - n_start*k
# # print(n)

n = n % k

while True:
    min_n = n
    n = abs(n-k)
    # print("n, k =", n, k)
    if min_n > n:
        min_n = n
    else:
        break
print(min_n)


Measured memory_bytes: 62020