akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int N,M;
const long long mod = 1000000007;
long long prv[303][303],nxt[303][303];

void add(long long &a, long long b)
{
	a = (a + b) % mod;
}

int main()
{
	scanf ("%d %d",&N,&M);
	prv[1][0] = 1;
	for (int m=0;m<M;m++){
		for (int i=1;i<=N;i++) for (int j=0;j<=N;j++) nxt[i][j] = 0;
		for (int i=1;i<=N;i++) for (int j=0;j<=N;j++) if (prv[i][j]){
			add(nxt[i+j][0], prv[i][j] * i);
			add(nxt[i][j], prv[i][j] * j);
			add(nxt[i][j+1], prv[i][j] * (N - i - j));
		}
		for (int i=1;i<=N;i++) for (int j=0;j<=N;j++) prv[i][j] = nxt[i][j];
	}

	printf ("%lld\n",prv[N][0]);

	return 0;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){
		x+=p.x,y+=p.y;
		return *this;
	}
	Point& operator-=(Point p){
		x-=p.x,y-=p.y;
		return *this;
	}
	Point& operator*=(double c){
		x*=c,y*=c;
		return *this;
	}
	Point& operator/=(double c){
		x/=c,y/=c;
		return *this;
	}
};
Point operator+(Point a,Point b){
	return a+=b;
}
Point operator-(Point a,Point b){
	return a-=b;
}
Point operator*(Point a,double c){
	return a*=c;
}
Point operator*(double c,Point a){
	return a*=c;
}
Point operator/(Point a,double c){
	return a/=c;
}
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}

double Abs(Point p){
	return sqrt(p.x*p.x+p.y*p.y);
}
double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Arg(Point p){
	return atan2(p.y,p.x);
}
double Dot(Point a,Point b){
	return a.x*b.x+a.y*b.y;
}
double Cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
	Line(double px,double py,double dx,double dy):pos(px,py),dir(dx,dy){}
};

// aとbは必ず交差していること
// 同一直線上にある場合，a.posを返す
Point InterPointLL(Line a,Line b){
	if(abs(Cross(a.dir,b.dir))<EPS) return a.pos;
	return a.pos+Cross(b.pos-a.pos,b.dir)/Cross(a.dir,b.dir)*a.dir;
}

void solve()
{
	Point a,b,c,d;
	cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
	Point p=InterPointLL(Line(a,b-a),Line(c,d-c));
	printf("%.10f %.10f\n",p.x,p.y);
}

int main()
{
	int q; cin>>q;
	rep(_,q) solve();
}

Measured memory_bytes: 1240
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define ji -
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fe(x) for(int i=be[x];i;i=e[i].ne)
using namespace std;
const int p=1e9+7;
int n,na[210000],rk[210000],m;
long long f[210000];
struct nod{
	int x,v;
	bool operator <(const nod &a)const{
		return x<a.x;
	}
};
nod a[210000];
bool cmp(int c,int d){
	return a[c].v<a[d].v;
}
struct seg{
	int l,r;
	bool operator <(const seg &a)const{
		return r<a.r||(r==a.r&&l<a.l);
	}
};
seg e[210000];
inline long long sum(int x){
	long long ans=0;
	while (x){
		ans+=f[x];
		x-=x&(-x);
	}
	return ans;//!!!!!!!!!!
}
inline void add(int x,int v){
	while (x<=m){
		f[x]+=v;
		x+=x&(-x);
	}
}
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d%d",&a[i].x,&a[i].v);
	sort(a+1,a+n+1);
	fo(i,1,n) na[i]=i;
	sort(na+1,na+n+1,cmp);
	fo(i,1,n) rk[na[i]]=i;
	int t=1;
	fo(i,1,n){
		if (a[i].v>a[t].v) t=i;
		e[i].r=rk[t];
	}
	t=n;
	fd(i,n,1){
		if (a[i].v<a[t].v) t=i;
		e[i].l=rk[t];
	}
	sort(e+1,e+n+1);
	m=n+1;
	add(1,1);
	/*printf("----after0---\n");
	fo(i,1,m) printf("%I64d ",sum(i)-sum(i-1));
	putchar('\n');*/
	fo(i,1,n){
		add(e[i].r+1,(sum(e[i].r+1)-sum(e[i].l-1))%p);
		/*printf("----after%d---\n",i);
		fo(i,1,m) printf("%I64d ",sum(i)-sum(i-1));
		putchar('\n');*/
	}
	printf("%d\n",(sum(n+1)-sum(n)+p)%p);
	return 0;
}

Measured memory_bytes: 6656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRainFlowsIntoDams solver = new DRainFlowsIntoDams();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRainFlowsIntoDams {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), a[] = new int[n];
            long ans[] = new long[n], c = 0;
            a[0] = s.nextInt();
            c = a[0];
            for (int i = 1; i < n - 1; i++) {
                a[i] = s.nextInt();
                if ((i & 1) == 1) {
                    c -= a[i];
                } else {
                    c += a[i];
                }
            }
            a[n - 1] = s.nextInt();
            ans[0] = a[n - 1] + c;
            for (int i = 1; i < n; i++) {
                ans[i] = (a[i - 1] - ans[i - 1] / 2) << 1;
            }
            for (long i : ans) w.print(i + " ");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 38128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CKDMC {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,q,k;
        string s;
        in>>n>>s>>q;
        vector<int> sm(n+1),D,M,C;
        fr(i,n){
            sm[i+1]=sm[i];
            if(s[i]=='D') D.emplace_back(i);
            if(s[i]=='M') M.emplace_back(i),++sm[i+1];
            if(s[i]=='C') C.emplace_back(i);
        }
        fr(_,q){
            in>>k;
            int l=0,r=0;
            ll ans=0,ss=0;
            fr(i,C.size()){
                while(l<D.size()&&D[l]<=C[i]-k) ss-=sm[D[l]],++l;
                while(r<D.size()&&D[r]<C[i]) ss+=sm[D[r]],++r;
                ans+=(ll)(r-l)*sm[C[i]]-ss;
            }
            out<<ans<<endl;
        }
    }
};

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


Measured memory_bytes: 11928
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

void outPut_YN(bool isYes) {
	if(isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

int main()
{
	long long h, n, sum = 0;

	cin >> h >> n;

	vector<long long> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		sum += a[i];
	}

	outPut_YN(sum >= h);

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int n,i,r=1;
	char s[100];
	scanf("%d%s",&n,s);
	if(n%2){
		r=0;
	}
	else{
		for(i=0;i<n/2;i++){
			r*=s[i]==s[n/2+i];
		}
	}
	printf(r?"Yes":"No");
	return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,ans=0;
  cin>>N;
  REP(i,N+1){
    if(i<10 || (i>=100&&i<1000) || (i>=10000&&i<100000))ans++;
  }
  cout<<ans-1<<endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
field = [input() for _ in range(h)]
direction = [(1,0), (0,1), (-1,0), (0,-1)]
def wfs(c, search, done):
    if search == set():
        return -1
    if (h-1, w-1) in search:
        return c
    newsearch = set()
    for x, y in search:
        for dx, dy in direction:
            xa = x + dx
            ya = y + dy
            if xa in range(h) and ya in range(w) and (xa, ya) not in done and field[xa][ya] == '.':
                newsearch.add((xa, ya))
        done.add((x, y))
    return wfs(c+1, newsearch, done)
ret = wfs(0, {(0,0)}, set())
if ret == -1:
    print(-1)
else:
    white = 0
    for i in range(h):
        for j in range(w):
            if field[i][j] == '.':
                white += 1
    print(white - ret - 1)


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

int main()
{
    size_t H, W;
    cin >> H >> W;

    vector<size_t> A(H);
    vector<size_t> B(H);
    for (size_t i = 0; i < H; i++)
    {
        cin >> A[i] >> B[i];
    }

    set<pair<size_t, size_t>> goal_start;
    set<pair<int, size_t>> ans;
    for (size_t i = 1; i <= W; i++)
    {
        goal_start.insert(make_pair(i, i));
        ans.insert(make_pair(0, i));
    }

    for (size_t i = 0; i < H; i++)
    {
        size_t start = 0;
        size_t right = 0;
        for (
            set<pair<size_t, size_t>>::iterator itr = goal_start.lower_bound(make_pair(A[i], 0));
            itr != goal_start.end() && itr->first <= B[i];
            itr = goal_start.erase(itr))
        {
            size_t goal = itr->first;
            start = itr->second;

            ans.erase(ans.find(make_pair(goal - start, goal)));
            right = max(right, start);
        }
        if (start > 0 && B[i] < W)
        {
            goal_start.insert(make_pair(B[i] + 1, right));
            ans.insert(make_pair(B[i] + 1 - right, B[i] + 1));
        }

        if (ans.empty())
        {
            cout << -1 << endl;
        }
        else
        {
            cout << i + 1 + ans.begin()->first << endl;
        }
    }
}


Measured memory_bytes: 31496
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 100;
const int T = 17;

void check(int cnt[N], P c[T], queue<int> &q, int &l, int &t){
  REP(i, T){
    if(c[i].first == -1) continue;
    int n = c[i].first;
    if(c[i].second + (17 * (n % 2) + 3 * (n % 3) + 19) == t){
      l = max(l, c[i].first);
      c[i] = P(-1, -1);
    }
  }
  while(!q.empty()){
    int n = q.front();
    int m = (n % 5 == 1 ? 5 : 2);
    bool ff = false;
    REP(i, T - m + 1){
      bool f = true;
      REP(j, m) if(c[i + j].first != -1) f = false;
      if(f){
        cnt[n] = t - n * 5;
        REP(j, m) c[i + j] = P(n, t);
        ff = true;
        q.pop();
        break;
      }
    }
    if(!ff) break;
  }
}

int main() {
  int cnt[N], l = -1, t = 0;
  P c[T];
  memset(cnt, 0, sizeof(cnt));
  REP(i, T) c[i] = P(-1, -1);
  queue<int> q;
  while(l < N){
    if(t % 5 == 0) q.push(t / 5);
    check(cnt, c, q, l, t);
    ++t;
  }
  int n;
  while(cin >>n) cout <<cnt[n] <<endl;
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n, k; cin >> n >> k;
    --k;
    string s; cin >> s;
    if(s[k] == 'A') s[k] = 'a';
    if(s[k] == 'B') s[k] = 'b';
    if(s[k] == 'C') s[k] = 'c';
    cout << s << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, M, AC = 0, WA = 0;
    cin >> N >> M;
    vector<pair<int64_t, string>> pS(M);
    vector<pair<bool, int64_t>> A(N);
    for (int i = 0; i < M; i++) {
        cin >> pS.at(i).first >> pS.at(i).second;
    }
    for (int i = 0; i < N; i++) {
        A.at(i).first = false;
        A.at(i).second = 0;
    }
    for (int i = 0; i < M; i++) {
        if (pS.at(i).second == "AC") {
            A.at(pS.at(i).first - 1).first = true;
        }
        else if (!(A.at(pS.at(i).first - 1).first)){
            A.at(pS.at(i).first - 1).second++;
        }
    }
    for (int i = 0; i < N; i++) {
        if (A.at(i).first == true) {
            AC++;
            WA += A.at(i).second;
        }
    }
    cout << AC << " " << WA << endl;

}



Measured memory_bytes: 8064
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int a=n/2;
        if(n%2==1)
            a+=1;
        if(k>a)
            System.out.println("NO");
        else
            System.out.println("YES");
    }
}

Measured memory_bytes: 25300
from collections import deque
n, k = map(int, input().split())
v = list(map(int, input().split()))
d = deque(v)

t = min(n, k)
score = 0
for a in range(t+1):
    for b in range(t-a+1):
        tmp_d = d.copy()
        jems = []
        for i in range(a):
            jems.append(tmp_d.pop())
        for i in range(b):
            jems.append(tmp_d.popleft())
        jems.sort()
        for i in range(min(len(jems), k-b-a)):
            if jems[i] < 0:
                jems[i] = 0
            else:
                break
        tmp_score = sum(jems)
        if tmp_score > score:
            score = tmp_score
print(score)


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

dic = {}
for i in A:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
two = []
four = []
for j, k in dic.items():
	if k>=4:
		four.append(j)
	if k>=2:
		two.append(j)
two.sort(reverse=True)
four.sort(reverse=True)
if len(four) == 0:
	if len(two) <= 1:
		print(0)
	else:
		print(two[0]*two[1])	
else:
	if len(two) <= 1:
		print(four[0]**2)
	else:	
		print(max(two[0]*two[1], four[0]**2))

Measured memory_bytes: 18060
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var w, h, x, y int
	fmt.Scan(&w, &h, &x, &y)

	a := float64(w*h) / 2.0
	b := 0
	if x+x == w && y+y == h {
		b = 1
	}
	fmt.Printf("%f %d\n", a, b)
}


Measured memory_bytes: 512
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl read
  solve n <$> getl (map read . words) >>= print

solve :: Integer -> [Integer] -> Integer
solve n as
  | odd n && head sas == 0 && f 2 (tail sas) = g (n `div` 2) 1
  | even n && f 1 sas = g (n `div` 2) 1
  | otherwise = 0
  where
    mn = 1000000007
    sas = sort as
    f _ [] = True
    f s (x:y:ys) = if x == y && x == s then f (s+2) ys else False
    g m r = if m > 30 then g (m - 30) (r * ((2 ^ 30) `mod` mn) `mod` mn) else r * (2 ^ m) `mod` mn

getl :: (String -> a) -> IO a
getl f = f <$> getLine


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

int main(void){
	ll r,D,x;
	cin>>r>>D>>x;
	rep(i,10){
		x = r*x-D;
		cout<<x<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 20
using namespace std;
ll k,dp[N][N],sum[N];
string s="";
int main(){
	ll i,j,x;
	cin>>k;
	k++;
	memset(sum,0,sizeof(sum));
	memset(dp,0,sizeof(dp));
	dp[0][19]=1;
	sum[0]=1;
	for(i=0;i<20;i++)
	{
		if(i!=0)
		{
			dp[i][19]=sum[i-1];
			sum[i]=dp[i][19];
		}
		for(j=0;j<10;j++)
		{
			if(i==0)
			{
				dp[i][j]=1;
			}
			else
			{
				dp[i][j]=dp[i-1][j];
				if(j>0)
				{
					dp[i][j]+=dp[i-1][j-1];
				}
				if(j<9)
				{
					dp[i][j]+=dp[i-1][j+1];
				}
			}
			if(j!=0)
			{
				sum[i]+=dp[i][j];
			}
		}
		if(k<=sum[i])
		{
			break;
		}
	}
	while(i>=0)
	{
		if(s=="")
		{
			if(k>dp[i][19])
			{
				k-=dp[i][19];
			}
			else
			{
				s+='0';
				i--;
				continue;
			}
			for(j=1;j<=10;j++)
			{
				if(k>dp[i][j])
				{
					k-=dp[i][j];
				}
				else
				{
					s+=(char)('0'+j);
					break;
				}
			}
		}
		else
		{
			x=s[s.size()-1]-'0';
			for(j=max((ll)0,x-1);j<=1+min((ll)9,x+1);j++)
			{
				if(k>dp[i][j])
				{
					k-=dp[i][j];
				}
				else
				{
					s+=(char)('0'+j);
					break;
				}
			}
		}
		i--;
	}
	while(s[0]=='0')
	{
		s.erase(s.begin());
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

long long check(long long n) {
	long long ret = 0;
	long long x = 1;
	const int mod = 1e9;

	for (int i = n; i >= 2; i -= 2) {
		x = x * i;
		while (x % 10 == 0) {
			ret++;
			x /= 10;
		}
		x %= mod;
	}

	return ret;
}

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

	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}

	// cout << check(n) << endl;
	long long ans = 0;
	long long tmp = n;

	long long x = 2;
	do {
		x *= 5;
		ans += n / x;
	} while (x <= n / 5);

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)
#define COUT(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================
// Template End =========================

constexpr int MOD=1e9+7;
locale LOCATE=locale::classic();

int main(void){
  int N,T; cin>>N>>T;
  vector<pl> AB(N); cin>>AB;
  SORT(AB);
  mat<ll> dp(N+1,vec<ll>(T+3010,-1));
  dp[0][0]=0;
  for(int i=0; i<N; ++i){
    for(int j=0; j<T+3010; ++j){
      if(dp[i][j]==-1) continue;
      if(j<T){
        dp[i+1][j+AB[i].first]=max(dp[i+1][j+AB[i].first],dp[i][j]+AB[i].second);
      }
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
  }
  ll ans=0;
  rep(i,T+3010){
    ans=max(ans,dp[N][i]);
  }
  cout<<ans<<endl;
}










Measured memory_bytes: 141312
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define maxn 1000000000

int main()
{
    long long n;
    while(~scanf("%lld",&n))
    {
      long long i;
       for(i=n;i>=0;i--)
       {
           int a=sqrt(i);
          // printf("%d\n",a);
           if(a*a==i)
           {
               printf("%lld\n",i);
               break;
           }
       }
    }
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
ans_list = [0] * (a_list[n - 1] + 1)
ans = 0

for a in a_list:
    if ans_list[a] >= 1:
        ans_list[a] += 1
        continue
    for j in range(2 * a, a_list[n - 1] + 1, a):
        ans_list[j] += 1
    ans_list[a] = 1

for a in a_list:
    if ans_list[a] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32300
#include <iostream>
#include <iomanip>
#include <cmath>
#define PI 3.14159265359
using namespace std;

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  double theta, y;
  if(2*x <= a*a*b){
    y = 0.5*a*b*b/x;
  } else {
    y = 2*(a*a*b-x)/a/a/a;
  }
  theta = atan(y)*180/PI;
  cout << setprecision(10) << theta << endl;
  return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
#define int long long
using namespace std;

signed main(){
    
    int t=1;
    //cin>>t;
    int coco=1;
    while(t--){
        int n,k;
        cin>>n>>k;
        int x;
        vi a;
        for(int i=0;i<n;i++){
        	cin>>x;
        	a.pb(x);
        }
        vvi dp(n+1,vi(k+1,0));
        dp[0][0]=1;
        vi sum(k+1,1);
        for(int i=1;i<=n;i++){
        	for(int j=1;j<=k;j++){
        		sum[j]=(sum[j-1]+dp[i-1][j])%mod;
        	}
        	for(int j=0;j<=k;j++){
        		dp[i][j]=sum[j];
        		if(j-a[i-1]-1>=0){
        			dp[i][j]=(dp[i][j]-sum[j-a[i-1]-1]+mod)%mod;
        		}
        	}
        }
       	cout<<dp[n][k]<<endl;
        //cout<<dp[0][n-1][0]-(bb[n]-dp[0][n-1][0])<<endl;
    }   
    return 0;
}

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

int tb[1112],ans[1112],N;

int nr(int a)
{
	int ret=1;
	for(int i=2; i<1112; i++)
	{
		if(tb[i]>a) break;
		ret=i;
	}
	return tb[ret];
}

int calc(int z)
{
	int z3=z*z*z, ret=z3;
	for(int i=1; i<z; i++)
	{
		int i3=i*i*i, j3=nr(z3-i3);
		if(i3+j3>=z3) break;
		
		ret=min(ret, z3-i3-j3);
	}
	return ret;
}

int main()
{	
	for(int i=1; i<1112; i++)
		tb[i]=i*i*i;
		
	for(int i=1; i<1112; i++)
		ans[i]=calc(i);
		
	while(cin >> N, N)
		cout << ans[N] << endl;
}

Measured memory_bytes: 812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
//二項係数mod
    const int MAX = 510000;
    const int MOD = 1000000007;
    long long fac[MAX], finv[MAX], inv[MAX];

    // テーブルを作る前処理
    void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    // 二項係数計算
    long long COM(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }


int main()
{
ll h,w,a,b;
cin >> h>>w>>a>>b;
COMinit();
rep(i,h-a){
    ans+=COM(b-1+i,i)*COM(h+w-b-2-i,w-b-1)%mo;
    //cout << COM(b-1+i,i) <<" "<< COM(h+w-b-2-i,h-i)<< endl;
    ans%=mo;
}

cout << ans << endl;
return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
const int N=1e6+10;
const int M=2e5+10;
int a[M];
int pass[M];
int main()
{
   IOS;
   int k,n;
   cin >> k >> n;
   for(int i=1;i<=n;i++){
       cin >> a[i];
   }
   pass[n] = min((k-a[n]+a[1]),a[n]-a[1]);
   for(int i=1;i<n;i++){
       pass[i]=a[i+1]-a[i];
       //cout<<pass[i]<<endl;
   }

   sort(pass+1,pass+n+1);
   //cout<<pass[1]<<" "<<pass[2]<<" "<<pass[3]<<endl;
   int p=n-1;
   ll ans=0;
   for(int i=1;i<=p;i++){
       ans+=pass[i];
   }
   cout<<ans;
}


Measured memory_bytes: 1792
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

N, P = map(int, input().split())

vals = factorization(P)
ans = 1
for x in vals:
    flag = 1
    while flag:
        if x[1] >= N:
            ans *= x[0]
            x[1] -= N
        else:
            break
print(ans)



Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <cmath>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> dp(N);
    dp.at(0)=0;
    vector<int> h(N);
    rep(i,N){
        cin>>h.at(i);
    }
    rep(i,N){
        if(i>=2){
            dp.at(i)=min(dp.at(i-1)+abs(h.at(i)-h.at(i-1)),dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
        }else if(i==1){
            dp.at(1)=dp.at(0)+abs(h.at(1)-h.at(0));
        }
    }
    cout <<dp.at(N-1)<<endl;



    return 0;
}


Measured memory_bytes: 4024
#include<stdio.h>
int main(void)
{
	int n,m;
	int a[10001],b[10001];
	int flg[10001];
	int i;
	int c;
	
	scanf("%d",&n);
	scanf("%d",&m);
	while(n!=0 && m!=0){
		c=0;
		for(i=2;i<=n;i++){
			flg[i]=0;
		}
		flg[1]=2;
		for(i=1;i<=m;i++){
			scanf("%d %d",&a[i],&b[i]);
			if(a[i]==1){
				c++;
				flg[b[i]]=1;
			}
		}
		for(i=1;i<=m;i++){
			if(flg[a[i]]==1 && flg[b[i]]==0){
					c++;
					flg[b[i]]=2;
			}
		}
		for(i=1;i<=m;i++){
			if(flg[a[i]]==0 && flg[b[i]]==1){
					c++;
					flg[a[i]]=2;
			}
		}
		printf("%d\n",c);
		scanf("%d",&n);
		scanf("%d",&m);
	}
	return 0;
}
			

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 3004;
vector <int> g[N];
int dp[N], a[N];
int n;
void dfs(int u, int s)
{
	int nchild = 0;
	for(auto v : g[u])
	{
		if(v == s)
			continue;
		nchild++;
		// cout << v << ' ' << u << '\n';
		dfs(v, u);
		if(a[v] < a[u] && dp[v] == 0)
		{
			dp[u] = 1;
		}
		
	}
	if(nchild == 0)
		dp[u] = 0;
}

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

	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	for(int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(3, -1);
	// cout << dp[3] << ' 
	for(int i = 1; i <= n; i++)
	{
		memset(dp, 0, sizeof(dp));
		dfs(i, -1);
		// cout << dp[3] << '\n';
		if(dp[i] == 1)
			cout << i << ' ';
	}
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N;
    cin >> N;
    vec A(N);
    mat X(N), Y(N);
    REP(i,0,N) {
        cin >> A[i];
        REP(j,0,A[i]) {
            ll x, y;
            cin >> x >> y;
            --x;
            X[i].pb(x); Y[i].pb(y);
        }
    }

    ll mx = 0;
    vec F(N);
    REP(i,0,1<<N) {
        REP(j,0,N) F[j] = (i >> j) & 1;
        bool f = true;
        REP(j,0,N) {
            REP(k,0,A[j]) {
                if(F[j] && F[X[j][k]] != Y[j][k]) {
                    f = false;
                    break;
                }
            }
            if(!f) break;
        }
        ll cnt = 0;
        if(f) {
            REP(j,0,N) cnt += F[j];
            mx = MAX(mx,cnt);
        }
    }
    _PR(mx);

    return 0;
}

/*



*/

Measured memory_bytes: 256
local s=io.read()
local map={[0]=1}
local digit=1
local ms=0
for i=#s,1,-1 do
    local n=tonumber(s:sub(i,i))
    ms=(ms+n*digit)%2019
    map[ms]=(map[ms] or 0)+1
    digit=(digit*10)%2019
end

local counter=0
for k,v in pairs(map) do
    counter=counter+v*(v-1)//2
end
print(counter)

Measured memory_bytes: 2788
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N;
ll A,B;

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

  cin>>N>>A>>B;

  ll res=0;

  ll prv=0;
  for(int i=0;i<N;i++) {
    ll x;cin>>x;
    if (prv) {
      res += min(A*(x-prv), B);
    }
    prv = x;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int cnt = 0, n;

struct st {
	int ab[10][10];
};
struct st stt;

struct sttyo {
	bool tyo[10];
};
sttyo sss;

int func(int in, st tt, sttyo ty) {
//int func(int in, int  *ab, bool  *tyo) {
	/*
	for (int i = 0; i < 10; i++) cout << i << " ";
	cout << endl;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cout << ab[i][j] << " ";
		}
		cout << endl;
	}
	*/

	//cout << "in->" << in << endl;
	ty.tyo[in] = true;
	bool flag = false;
	for (int i = 1; i <= n; i++) {
		if (ty.tyo[i] == false) flag = true;
	}
	if (flag == false) {
		cnt++;
		//cout << "cnt->" << cnt << endl;
		//cout  << cnt << endl;
		return 0;
	}

	for (int i = 1; i < 10; i++) {
		if (i == in) continue;
		if (tt.ab[in][i] == 0 && ty.tyo[i]==false) {
		//if (ab[in][i] == 0) {
			tt.ab[in][i] = 1;
			func(i, tt, ty);
		}
		//tyo[in] = true;
	}
	//tyo[in] = true;

	//return 0;
}

int main() {
	int i, j, k;
	int m; //ab[10][10];
	bool tyo[10];

	//fill((int*)ab, (int*)(ab+10), -1);
	fill(tyo, tyo + 10, false);

	cin >> n >> m;

	
	

	fill((int*)stt.ab, (int*)(stt.ab + 10), -1);

	int a, b;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		stt.ab[a][b] = 0;
		stt.ab[b][a] = 0;
	}


	func(1, stt, sss);


	cout << cnt << endl;




	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e15;

int main(){

    string s;
    cin >> s;
    ll k;
    cin >> k;

    char a, b;
    int pos;
    a = s.at(0);
    if (s.size()>1){
        for (int i=1; i<s.size(); i++){
            b = s.at(i);
            pos = i;
            if (b != '1') break;
        }
    }

    if ((a == '1') && (pos+1<=k)) cout << b << endl;
    else cout << a << endl;

    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   int n; cin>>n;
   vector<int> a(n),b(n);
   rep(i,0,n)cin>>a[i]>>b[i];
   sort(ALL(a)); sort(ALL(b));
   int res=0;
   if(n&1){
      res=b[n/2]-a[n/2]+1;
   }
   else{
      res=b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
   }
   cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 4844
#include <sstream>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void insertion_sort(vector<int> &list) {
  for (int i = 1; i < list.size(); ++i) {
    for (auto iter = list.begin(); iter != list.end()-1; ++iter) {
      cout << *iter << " ";
    }
    cout << list.back() << endl;
    int key = list[i];
    int j = i - 1;
    while (j >= 0 && list[j] > key) {
      list[j+1] = list[j];
      j--;
    }
    list[j+1] = key;
  }
}

int main() {
  string str;
  int N;
  cin >> N; cin.ignore();
  getline(cin, str);
  istringstream istr(str);
  string tmp;
  vector<int> v;
  while (getline(istr, tmp, ' ')) {
    v.push_back(stoi(tmp));
  }
  insertion_sort(v);
  for (auto iter = v.begin(); iter != v.end()-1; ++iter) {
    cout << *iter << " ";
  }
  cout << v.back() << endl;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
char a[100][101],b[102][102];
int main(){
    int H,W;
    cin>>H>>W;
    for(int i=0;i<H;i++)
    scanf("%s",a[i]);

    for(int i=0;i<H+2;i++)
    for(int j=0;j<W+2;j++)
    b[i][j]='#';

    for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
    b[i+1][j+1]=a[i][j];

    for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++)
    cout<<b[i][j];
    cout<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include <cstdlib>
#include <stdlib.h>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define MOD 1000000007
using namespace std;
using ll=long long;
int cnt,element;
int main()
{
    int a,b,n,rafi,flag=0;
    cin>>n;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%n==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int n, ans = 0, count = 1, max_count = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (true) {
      if (j % 2) {
        if (count >= max_count) {
          ans = i;
          max_count = count;
        }
        count = 0;
        break;
      }
      j /= 2;
      count++;
    }
  }
  cout << ans << '\n';
  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 PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct state {
    int D;
    vector<int> c;
    vector<vector<int>> s;
    vector<int> before;

    state(int D,vector<int> &c,vector<vector<int>> &s): D(D),c(c),s(s),before(26,-1) {}

    vector<ll> solve() {
        ll ans = -INF,best_i = -1;
        vector<ll> indexs;
        rep(i,26) {
            vector<ll> op = optimization(i);
            if (op[0] > ans) {
                ans = op[0];
                indexs = op;
            }
        }
        return indexs;
    }
    
    //あるパラメータの時の解
    vector<ll> optimization(int x) {
        vector<ll> indexs(D + 1);
        ll sco = 0;
        rep(i,D) {
            int ret,idx = next_day(i,x);
            before[idx] = i;
            indexs[i + 1] = idx + 1;
            sco += ret;
        }
        indexs[0] = sco;
        return indexs;
    }

    //d日目にi番目のコンテストを開いた時のx日後までのスコア
    int evaluate(int d,int i,int x) {
        int score = 0;
        score += s[d][i];
        int bf = before[i];
        before[i] = d;
        rep(k,x)rep(j,26) {
            score -= (k + d - before[j]) * c[j];
        }
        before[i] = bf;
        return score;
    }

    //d日目のスコア
    int next_day(int d,int x) {
        int idx = -1,ans = -INF;
        rep(i,26) {
            //choose i th contest
            int ret = evaluate(d,i,x);
            if (ans < ret) {
                ans = ret;
                idx = i;
            }
            before[i] = x;
        }
        return ans,idx;
    }
};

int main() {
    int D; cin >> D;;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(i,D)rep(j,26) cin >> s[i][j];
    
    /*
    //答え確認用
    printf("%d\n",D);
    rep(i,26) printf("%d ",c[i]); 
    cout << '\n';
    rep(i,D){
        rep(j,26) printf("%d ",s[i][j]);
        cout << '\n';
    }
    */
    
    state st(D,c,s);
    vector<ll> ans = st.solve();
    rep(i,D) printf("%ld\n",ans[i + 1]);
    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	int N,M;
	cin >> N;
	int T[N];
	for (size_t i = 0; i < N; i++) {
		cin >> T[i];
	}
	cin >> M;
	int P[M],X[M];
	for (size_t i = 0; i < M; i++) {
		cin >> P[i] >> X[i];
		P[i] = P[i] - 1;
	}

	int sum = 0;
	for (size_t i = 0; i < N; i++) {
		sum += T[i];
	}
	int ans;
	for (size_t i = 0; i < M; i++) {
		ans = sum - T[P[i]] + X[i];
		cout << ans << '\n';
	}
	return 0;
}


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

int n, m, x;
int p, q;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m >> x;
	for(int i=0; i<m; ++i){
		int a;
		cin >> a;
		if(a < x) ++p;
		else ++q;
	}
	cout << min(p, q) << "\n";
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$n);
$arr=explode(' ',trim(fgets(STDIN)));
$cnt=0;
$max_arr=array();
for($i=0;$i<$n-1;$i++){
	if($arr[$i]>=$arr[$i+1]){
		$cnt++;
		$max_arr[$i]=$cnt;
	}else{
		$cnt=0;
	}
}
 
//print_r($max_arr);
if(count($max_arr)<>0){
	echo max($max_arr);
}else{
	echo 0;
}
?>

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

typedef long long ll;
ll mod = 1e9 + 7;

const int N = 2e3 + 10;
ll dp[N];

int main()
{
	int s;
	cin >> s;
	dp[3] = 1;
	for (int s2 = 4; s2 <= s; s2++)
	{
		ll sum = 0;
		for (int x = 3; x <= s2; x++) 
		{
			sum += dp[s2 - x];
			if (x == s2) sum++;
			sum %= mod;
		}
		dp[s2] = sum;
	}
	cout << dp[s];
}


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

int memo[5000][5000];
string ds[5000];

int main()
{
	int h,w;
	cin>>h>>w;
	for(int y=0; y<h; y++)
	{
		cin>>ds[y];
		int c=0;
		for(int x=0; x<w; x++)
		{
			char c1=ds[y][x];
			c=(c1=='#'?0:c+1);
			memo[y][x]=c;
		}
		c=0;
		for(int x=w-1; x>=0; x--)
		{
			c=(memo[y][x]==0?0:max(c,memo[y][x]));
			memo[y][x]=c;
		}
	}
	int ans=0;
	for(int x=0; x<w; x++)
	{
		int c=0,ts2[5000];
		for(int y=0; y<h; y++)
		{
			char c1=ds[y][x];
			c=(c1=='#'?0:c+1);
			ts2[y]=c;
		}
		c=0;
		for(int y=h-1; y>=0; y--)
		{
			c=(ts2[y]==0?0:max(c,ts2[y]));
			if(ans<c+memo[y][x])
				ans=c+memo[y][x];
		}
	}
	cout<<ans-1;
	return 0;
}


Measured memory_bytes: 44544
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_134
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int[] cnts = new int[n];
            for(int i = n - 1; i >= 0; i--)
            {
                int now = i + 1;
                int sum = 0;
                for(int j = 2; now * j <= n; j++)
                {
                    sum += cnts[now * j - 1];
                }
                if (sum % 2 != array[i]) cnts[i] = 1;
            }

            List<int> res = new List<int>();
            for(int i =0; i < n; i++)
            {
                if (cnts[i] == 1) res.Add(i);
            }

            if (res.Count == 0)
            {
                WriteLine(0);
                return;
            }
            WriteLine(res.Count);
            for(int i = 0; i < res.Count; i++)
            {
                Write(res[i] + 1);
                if (i < res.Count - 1) Write(' ');
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 30296