akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node
{
	struct node *parent,*left,*right;
	int key;
};
node NIL;
node *nil = &NIL;
node *root = nil;
void setdepth(node*,int);
node* getroot(node*);
void inorder(node*);
void preorder(node*);
void insert(int);
void print();

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		if(s == "insert"){
			int key;
			cin >> key;
			insert(key);
		}
		else if(s == "print") print();
	}

	
	return 0;

}

node* getroot(node* x){
	int i=0;
	while(x->parent != nil){
		x = x->parent;
		i++;
		if(i >= 100000){
			cerr << "ERROR:GETROOT" << endl;
			break;
		}
	}
	//cerr << "root: " << x->key<< endl;
	return x;
}

void printchildren(node* x){

}

void insert(int key){
	node *x;
	x = (node*)malloc(sizeof(node));
	x->key = key;
	x->parent = x->left = x->right  = nil;
	if(root == nil) root = x;
	else{
		node* cur = root;
		node* prev = cur;
		bool isleft = true;
		while(cur != nil){
			prev = cur;
			if(key <= cur->key){
			 	isleft=true;
			 	cur = cur->left;
			}
			else {
				cur = cur -> right;
				isleft = false;
			}
		}
		x->parent = prev;
		if(isleft) prev->left = x;
		else prev -> right = x;
	}
}

void inorder(node *x){
	if(x->left != nil) inorder(x->left);
	cout << " " << x->key;
	if(x->right != nil) inorder(x->right);
}

void preorder(node *x){
	if(x == nil) return;
	else{
		cout << " " << x->key;
		preorder(x->left);
		preorder(x->right);
	}
}

void print(){
	inorder(root);
	cout << endl;
	preorder(root);
	cout << endl;
}

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

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

    int n;
    cin >> n;
    long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i % 3 != 0 && i % 5 != 0)
            ans += i;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;


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

    if(s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
N=int(input())
A=[int(input()) for _ in range(N)]
M1=max(A[0],A[1])
M2=min(A[0],A[1])
for i in range(2,N):
    if A[i]>=M1:
        M2=M1
        M1=A[i]
    else:
        M2=max(M2,A[i])
for i in range(N):
    if A[i]==M1:
        print(M2)
    else:
        print(M1)


Measured memory_bytes: 16892
#include <bits/stdc++.h>
using namespace std;
 
int kaizyo(int n){
    if(n>0)return n*kaizyo(n-1);
    if(n==0)return 1;
}

int main(){
 int N;
 cin >> N;
 int p[N];
 int q[N];
 int i;
 for(i=0;i<N;++i){
   cin >> p[i];}
 for(i=0;i<N;++i){
   cin >> q[i];}
int pcount = 0;
int qcount = 0;
 for(i=0;i<N;++i){
  pcount += (p[i]-1)*kaizyo(N-i-1);
  qcount += (q[i]-1)*kaizyo(N-i-1);
  for(int j=0;j<N;j++){
      if(p[j]>p[i])p[j]--;
      if(q[j]>q[i])q[j]--;
  }
 }
 cout << abs(pcount-qcount) << endl;
}

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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')
    {
        cout<<"Yes";
    }
    else cout<<"No";


















    return 0;

}













Measured memory_bytes: 3616
#include<iostream>
static const int NMAX = 100;

void PrintArray(const int* A, int N);
int SelectionSort(int* A, int N);

int main() {
    int A[NMAX], n, swapNr;

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

    swapNr = SelectionSort(A, n);
    PrintArray(A, n);
    std::cout << swapNr << std::endl;

    return 0;
}

void PrintArray(const int* A, int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            std::cout << " ";
        }
        std::cout << A[i];
    }
    std::cout << std::endl;
    
}

int SelectionSort(int* A, int N) {
    int swapNr = 0, minIndex;

    for (int i = 0; i < N - 1; i++) {
        minIndex = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minIndex]) {
                minIndex = j;
            }
        }

        if (minIndex != i) {
            int tmp;
            tmp = A[i];
            A[i] = A[minIndex];
            A[minIndex] = tmp;

            swapNr++;
        }
    }

    return swapNr;
}


Measured memory_bytes: 3104
b = list(map(int,input().split()))

if b[0]%2==0:
  for i in range(13):
    taxa = int(b[0]*12.5+i)
    for j in range(10):
      taxb = b[1]*10+j
      if taxa == taxb:
        break
    if taxa == taxb:
        break
else:
  for i in range(12):
    taxa = int(b[0]*12.5)+i+1
    for j in range(10):
      taxb = b[1]*10+j
      if taxa == taxb:
        break
    if taxa == taxb:
        break
if taxa == taxb:        
  print(taxa)
else :
  print("-1")

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

public class Main {

	static int MOD=(int)1e9+7;
	static int K;
	static ArrayList<Integer>[]adj;
	static long ans=1;
	static void solve(int u,int level,int sib,int p) {
		int options=K-Math.min(level,2)-sib;
		if(options<=0)
			ans=0;
		ans*=options;
		ans%=MOD;
		int newSib=0;
		for(int v:adj[u]) {
			if(v!=p) {
				solve(v,level+1,newSib++,u);
			}
		}
		
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n=sc.nextInt();
		K=sc.nextInt();
		adj=new ArrayList[n];
		for(int i=0;i<n;i++)
			adj[i]=new ArrayList();
		for(int i=1;i<n;i++) {
			int u=sc.nextInt()-1,v=sc.nextInt()-1;
			adj[u].add(v);
			adj[v].add(u);
		}
		
		solve(0,0,0,-1);
		out.println(ans);
		out.close();

	}
	 
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

bool mt[101][101];
int cnt[101][101];

int main(){
    int h, w;
    cin >> h >> w;
    rep1(i, h) {
        rep1(j, w) {
            char m;
            cin >> m;
            if (m=='.') mt[i][j] = true;
        }
    }
    for (int i=2; i<=w+h; i++) {
        for (int ch=1; ch<i; ch++) {
            int cw = i - ch;
            if (cw > w || ch > h) continue;
            if (ch==1&&cw==1) 
                cnt[ch][cw] = mt[ch][cw]?0:1;
            else if (ch==1) 
                cnt[ch][cw] = (mt[ch][cw]==mt[ch][cw-1])?cnt[ch][cw-1]:(cnt[ch][cw-1]+1);
            else if (cw==1) 
                cnt[ch][cw] = (mt[ch][cw]==mt[ch-1][cw])?cnt[ch-1][cw]:(cnt[ch-1][cw]+1);
            else {
                int right = (mt[ch][cw]==mt[ch][cw-1])?cnt[ch][cw-1]:(cnt[ch][cw-1]+1);
                int height = (mt[ch][cw]==mt[ch-1][cw])?cnt[ch-1][cw]:(cnt[ch-1][cw]+1);
                cnt[ch][cw] = min(right, height);
            }
        }
    }
    int ans = (cnt[h][w] + 1) / 2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, j, k, N, f, array[200][3], score[200] = {0};
	
	scanf("%d", &N);
	
	for (i = 0; i < N; i++){
		for (j = 0; j < 3; j++){
			scanf("%d", &array[i][j]);
		}
	}
	
	for (k = 0; k < 3; k++){
		for (i = 0; i < N; i++){
			f = 0;
			
			for (j = i + 1; j < i + N; j++){
				if (array[i][k] == array[j % N][k]){
					f = 1;
					break;
				}
			}
			
			if (f != 1){
				score[i] += array[i][k];
			}
		}
	}
	
	for (i = 0; i < N; i++){
		printf("%d\n", score[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1LL << 50


long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

using edge = struct{int to; long long cost;};
std::vector<edge> tree[100001];
int N,Q,K;
long long d[100001];
bool visited[100001];

void dfs(int v){
    visited[v] = true;

    for(int i =0; i<tree[v].size(); i++){
        edge e = tree[v][i];
        if(visited[e.to]==false){
            d[e.to] = d[v] + e.cost;
            dfs(e.to);
        }
    }
}

int main(){

    cin >> N;
    for (int i = 0; i < N-1; i++) {
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }
    cin >> Q >> K;
    d[K-1] = 0;

    for(int i=0; i<100001; i++){
        visited[i] = false;
    }

    dfs(K-1);

    for(int i=0; i<Q; i++){
        int x,y; cin >> x >> y;
        cout << d[x-1]+d[y-1] << endl;
    }



    return 0;

}


Measured memory_bytes: 14336
A,B=gets.split.map(&:to_i)
ans=Array.new(100){Array.new(100,"#")}
50.upto(99) do |i|
    100.times do |j|
        ans[i][j]="."
    end
end
(A-1).times do |i|
    ii=2*i+1
    ans[1+(ii/100)*2][ii%100]="."
end
(B-1).times do |i|
    ii=2*i+1
    ans[(ii/100)*2+51][ii%100]="#"
end
puts [100,100].join(" ")
100.times do |i|
    puts ans[i].join("")
end

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

#define rep(X,Y) for(int (X) = 0; (X) < (Y); ++(X))
typedef long long ll;
typedef pair<int, int> pii;

#define all(X) (X).begin(),(X).end()
#define pb push_back
#define eb emplace_back
#define rrep(X,Y) for(int (X)=(Y)-1; (X) >= 0; --(X))
#define X first
#define Y second
#define reps(X,Y,Z) for(int (X)=(Y); (X) <= (Z); ++(X))
#define sz size()
#define in(i,j,k) ((i) >= (j) && (j) <= (k))

#define UNIQUE(X) (X).erase(unique(all(X)), (X).end())

int main(){
  vector<int> a(6);
  while(1){
    rep(i,6)cin>>a[i];
    if(!accumulate(all(a),0))break;
    rep(i,3)a[i]+=a[i+3];
    int d,re=0,res;
    d=min({a[0],a[1],a[2]});
    rep(i,min(d+1,3)){
      res=d-i;
      rep(j,3)
	res+=max(0,a[j]-d+i)/3;
      re=max(re,res);
    }
    cout<<re<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
#include <bitset>
#include <assert.h>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <set>
#include <queue>
#include <unordered_map>
#include <random>
#include <chrono>
#include <stack>
#include <deque>
// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
using namespace std;
const int N = 1e6, inf = 1e9;
typedef long long ll;
#define deb(x) cout << #x << " = " << x << endl;
#define debg cout << "yes" << endl;
 
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
#define Test  \
    int t;    \
    cin >> t; \
    while (t--)
#define F first
#define S second
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, b, n) for (int i = b; i < n; i++)
#define fon(i, n) for (int i = n - 1; i >= 0; i--)
#define Ln length()
#define pb push_back
ll finditm(vector<ll> v, ll itm, ll n)
{
    ll sum = 0;
    fo(i, n)
    {
        sum += itm / v[i];
    }
    return sum;
}
int main()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
ll d,t,m;
cin>>d>>t>>m;
ll l=t*m;
if(l>=d)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

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

using namespace std;

const int kMod = 1e9 + 7;

vector<pair<int, int>> Reduce(vector<pair<int, int>> V) {
    vector<pair<int, int>> ret;

    for (auto p : V) {
        while (ret.size()) {
            if (ret.back().second >= p.second)
                ret.pop_back();
            else break;
        }
        ret.push_back(p);
    }

    return ret;
}

int T[500005];
void Add(int pos, int val) {
    for (++pos; pos > 0; pos -= (pos & -pos))
        T[pos] += val, T[pos] %= kMod;
}
int Get(int pos) {
    int ans = 0;
    for (++pos; pos <= 500000; pos += (pos & -pos))
        ans += T[pos], ans %= kMod;
    return ans;
}

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

    vector<pair<int, int>> V(n);
    for (int i = 0; i < n; ++i) {
        cin >> V[i].first >> V[i].second;
    }
    sort(V.begin(), V.end());

    vector<int> W(n);
    for (int i = 0; i < n; ++i)
        W[i] = V[i].second;

    vector<int> PrefMax(n), SuffMin(n);

    int maxx = -1;
    for (int i = 0; i < n; ++i) {
        maxx = max(maxx, W[i]);
        PrefMax[i] = maxx;
    }

    int minn = 2e9;
    for (int i = n - 1; i >= 0; --i) {
        minn = min(minn, W[i]);
        SuffMin[i] = minn;
    }

    // cerr << "OK\n";

    vector<pair<int, int>> Ranges;
    for (int i = 0; i < n; ++i) {
        int l = -1, r = n;
        for (int step = (1 << 20); step; step /= 2) {
            if (l + step < n && PrefMax[l + step] < W[i])
                l += step;
            if (r - step >= 0 && SuffMin[r - step] > W[i])
                r -= step;
        }
        assert(l < i && r > i);
        Ranges.emplace_back(l + 1, r - 1);
    }

    sort(Ranges.begin(), Ranges.end(), [](pair<int, int> a, pair<int, int> b) {
        if (a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    });
    Ranges = Reduce(Ranges);

    for (int i = 1; i < Ranges.size(); ++i) {
        assert(Ranges[i].first > Ranges[i - 1].first);
        assert(Ranges[i].second > Ranges[i - 1].second);
    }

    int b = 0, e = 0;
    Add(0, 1);
    for (int i = 0; i < n; ++i) {
        while (e < Ranges.size() && Ranges[e].first == i)
            ++e;

        Add(e, Get(b));

        while (b < Ranges.size() && Ranges[b].second == i)
            ++b;
    }

    cout << Get(Ranges.size()) << endl;

    return 0;
}

Measured memory_bytes: 10864
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    bool operator==(const Point& p) const{
        return abs(y - p.y) < EPS && abs(x - p.x) < EPS;
    }
};

class Line
{
public:
    double a, b, c; // a*x + b*y + c = 0
    Line(){
        a = c = 0.0;
        b = 1.0;
    }
    Line(const Point& p1, const Point& p2){ // 2点を結ぶ直線
        double dy = p2.y - p1.y;
        double dx = p2.x - p1.x;
        if(abs(dy / dx) < EPS){
            a = 0.0;
            b = 1.0;
            c = -p1.y;
        }else if(abs(dx / dy) < EPS){
            a = 1.0;
            b = 0.0;
            c = -p1.x;
        }else{
            a = - dy / dx;
            b = 1.0;
            c = dy / dx * p1.x - p1.y;
        }
    }
};

bool linesIntersection(const Line& l1, const Line& l2, Point& intersection)
{
    double s = l1.a*l2.b - l2.a*l1.b;
    if(abs(s) < EPS)
        return false;

    intersection = Point(l2.a*l1.c - l1.a*l2.c, l1.b*l2.c - l2.b*l1.c) / s;
    return true;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Line> line(n);
        for(int i=0; i<n; ++i){
            Point p1, p2;
            cin >> p1.x >> p1.y >> p2.x >> p2.y;
            line[i] = Line(p1, p2);
        }

        int ret = n + 1;
        for(int i=0; i<n; ++i){
            vector<Point> p;
            for(int j=0; j<i; ++j){
                Point q;
                if(linesIntersection(line[i], line[j], q) && -100 + EPS <= min(q.x, q.y) && max(q.x, q.y) <= 100 - EPS){
                    bool ng = false;
                    for(unsigned k=0; k<p.size(); ++k){
                        if(q == p[k])
                            ng = true;
                    }
                    if(!ng)
                        p.push_back(q);
                }
            }
            ret += p.size();
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 1240
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
acc = [0]*(n+1)
for i in range(n-1,-1,-1):
    acc[i] = acc[i+1]+a[i]
#ddprint(acc)
x = 0
for i in range(n-1):
    #ddprint(f"{x=} {i=} {acc[i+1]}")
    x = (x+a[i]*acc[i+1])%R
print(x)


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

int n, siz[25], matx[25][25], maty[25][25], res;
bool honest[25];

void solve(int id, int num) {
    if (id == n) {
        bool ok = 1;
        
        for (int i = 0; i < n; i++) {
            if (!honest[i]) continue;
            for (int j = 0; j < siz[i]; j++) {
                if (maty[i][j] != honest[matx[i][j]]) {
                    ok = 0;
                }
            }
        }
        if (ok) res = max(res, num);
    }
    else {
        solve(id + 1, num);
        honest[id] = 1;
        solve(id + 1, num + 1);
        honest[id] = 0;
    }
}

int main() {
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) {
        scanf("%d", &siz[i]);
        for (int j = 0; j < siz[i]; j++) {
            scanf("%d%d", &matx[i][j], &maty[i][j]);
            matx[i][j]--;
        }
    }
    
    solve(0, 0);
    
    printf("%d\n", res);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}


ll ans(vector<vector<int>> field,int to,int end,int now){
    int mn = INF;
    int id;
    if(to==1)return now;
    rep(i,10){
        if(to==i)continue;
        if(mn>field[to][i]){
            mn = field[to][i];
            id = i;
        }
    }
    if(end==-1)end = field[to][1];
    else end = min(end,now+field[to][1]);
    now += mn;
    if(end<=now)return end;
    else return ans(field,id,end,now);
}

int dist[10][10];
int h,w,a,res;
int main(){
    scanf("%d%d",&h,&w);
    rep(i,10)rep(j,10)scanf("%d",&dist[i][j]);
    rep(k,10)rep(i,10)rep(j,10){
        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
    }
    rep(i,h)rep(j,w){
    scanf("%d",&a);
    if(a>=0)res += dist[a][1];
    }
    printf("%d\n",res);
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
        }

        void Solve()
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(n/3);
        }

    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < (int)s.length(); i++) {
        if (s[i] != t[i]) ans += 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.1415926535897932384626433832
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;}

void lok(){

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    string d;
    cin>>d;
    int a=t-1;
    int b=0;
    int sum=0;
    while(a>b){
        while(d[a]=='W'){
            a--;
        }
        while(d[b]=='R'){
            b++;
        }
        if(a>b){
            sum++;
        }
        a--;
        b++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(ll x, ll y)
{
	return (x|y)&(~x|~y);	
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
	ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
	string str,str1;
	cin>>x>>y>>a>>b>>c;
	ll red[a], green[b], cless[c];
	rep(i,0,a)
	{
		cin>>red[i];
	}
	rep(i,0,b)
	{
		cin>>green[i];
	}
	rep(i,0,c)
	{
		cin>>cless[i];
	}
	ll res=0;
	sort(red, red+a, greater<ll>());
	sort(green, green+b, greater<ll>());
	sort(cless, cless+c, greater<ll>());
	vector<ll>vv;
	rep(i,0,x)
		vv.pb(red[i]);
	rep(i,0,y)
		vv.pb(green[i]);
	rep(i,0,min(x+y,c))
		vv.pb(cless[i]);
	sort(all(vv));
	reverse(all(vv));
	rep(i,0,x+y)
		res+=vv[i];
	cout<<res;
}

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

int main(){
  int N; cin >> N;
  int A[100000];
  for(int i=0; i<N; i++) cin >> A[i];
  
  long long sum=0;
  for(int i=0; i<N; i++) sum+=A[i];
  
  //x1を求める
  long long sum2=0;
  for(int i=0; i<N/2; i++) sum2+=A[2*i+1];
  
  int tmp=sum-2*sum2;  
  for(int i=0; i<N-1; i++){
    cout << tmp << " ";
    tmp=2*A[i]-tmp;
  }
  cout << tmp << endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n,i;
  cin>>n;
  ll a[n],dp[n];
  for(i=0;i<n;i++)
  	cin>>a[i];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  dp[2]=abs(a[2]-a[0]);
  for(i=3;i<n;i++)
  {
  	dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] ac = new int[n], wa = new int[n];
        int acc = 0, wac = 0;
        for (int i = 0; i < m; i++){
            int p = sc.nextInt() - 1;
            String s = sc.next();
            if (ac[p] == 1) continue;
            if (s.equals("AC")) {
                ac[p] = 1;
            } else {
                wa[p]++;
            }
        }
        for (int i = 0; i < n; i++) {
            acc += ac[i];
            if (ac[i] == 1) wac += wa[i];
        }
        System.out.println("" + acc + " " + wac);
    }
}

Measured memory_bytes: 63956
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
c=Counter(s)
l=c.most_common()
l.sort(key=lambda x:x[1],reverse=True)
a=l[0][1]
i=0
ans=[]
while i<len(l) and l[i][1]==a:
  ans.append(l[i][0])
  i+=1
ans.sort()
for j in ans:
  print(j)

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

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

  int cnt = 0;
  int input;
  for (int i = 0; i < N; i++) {
    cin >> input;
    cnt += input;

    if (cnt >= H) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> p_i;

int main()
{
    int d, n;
    cin >> d >> n;
    int res = 1;
    for (int i = 0; i < d; i++)
    {
        res *= 100;
    }
    n = (n == 100) ? 101 : n;
    cout << res * n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vll vector<ll>
#define pb push_back

using namespace std;
using ll = long long;

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];
void nCr_mod_init(){fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;for(ll 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;}}

static inline void ignore_ret(int x) {x++;}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> T inv_mod(T a){T b=MOD,r=1,v=0;while(b){T t=a/b;a-=t*b;swap(a,b);r-=t*v;swap(r,v);}r%=MOD;if(r<0)r+=MOD;return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T factorial_mod(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){if(n<k)return 0;if(n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> T nCr_mod(T n,T k){if(n<k)return 0;if(n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
template<class T> T pow_mod(T a,T n){T r=1;while(n>0){if(n&1)r=r*a%MOD;a=a*a%MOD;n>>=1;}return r;}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(ll X, ll Y){
    if ((X + Y) % 3) cout << 0 << endl;
    else {
        ll ans = nCr_mod<ll>((X + Y) / 3, Y * 2 / 3.0 - X / 3.0);
        cout << ans << endl;
    }
}

int main() {
    nCr_mod_init();

    ll X;
    ignore_ret(scanf("%lld",&X));
    ll Y;
    ignore_ret(scanf("%lld",&Y));
    solve(X, Y);
    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    int N,M,D;cin >> N >> M >> D;
    double ans = 0.0;
    if(D==0) ans = 1. * N / N / N * (M-1); // 0 and 1, 1 and 2, ... M-2 and M-1 : M-1 set
    else ans = 2. * (N-D) / N / N * (M-1); // sum of each e-value
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

int main(){
  char name[100000][10];
  int time[100000];
  int data,max_time,head=0,tail,total=0,rm=0,i;
  scanf("%d %d",&data,&max_time);
  for(tail=0;tail<data;tail++)scanf("%s %d",name[tail],&time[tail]);
  tail=0;
  head=0;
  while(1){
    if(time[head] > max_time){
      total +=max_time;
      time[tail] = time[head] -max_time;
      if(head != tail)strcpy(name[tail],name[head]);
      head++;
      tail++;
      if(head == data){
        head = tail = 0;
        data -= rm;
        rm = 0;
      }
    }
    else{
      total += time[head];
      printf("%s %d\n",name[head],total);
      head++;
      rm++;
      if(head == data){
        head = tail = 0;
        data -= rm;
        rm = 0;
      }
    }
    if(data == 0)break;
  }
  return 0;
}



Measured memory_bytes: 2408
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}



int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int four = 0, two = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] % 4 == 0) four++;
        else if (a[i] % 2 == 0) two++;
    }
    int ans = four * 2;
    if (two <= 1) ans += 1;
    if (two >= 2) ans += two;
    if (ans < N) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, k, s, ah, am, bh, bm, xh[100], xm[100], yh[100], ym[100]; bool ok[2][100][1440];
int main() {
	scanf("%d", &s);
	for (int i = 0; i < s; i++) {
		scanf("%02d:%02d-%02d:%02d", &xh[i], &xm[i], &yh[i], &ym[i]);
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &k);
		for (int j = 0; j < k; j++) {
			scanf("%02d:%02d-%02d:%02d", &ah, &am, &bh, &bm);
			for (int l = ah * 60 + am; l < bh * 60 + bm; l++) {
				ok[0][i][l] = true;
			}
		}
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &k);
		for (int j = 0; j < k; j++) {
			scanf("%02d:%02d-%02d:%02d", &ah, &am, &bh, &bm);
			for (int l = ah * 60 + am; l < bh * 60 + bm; l++) {
				ok[1][i][l] = true;
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < s; i++) {
		int rn = 0, rm = 0;
		for (int j = 0; j < n; j++) {
			bool flag = true;
			for (int k = xh[i] * 60 + xm[i]; k < yh[i] * 60 + ym[i]; k++) {
				if (!ok[0][j][k]) {
					flag = false; break;
				}
			}
			if (flag) rn++;
		}
		for (int j = 0; j < m; j++) {
			bool flag = true;
			for (int k = xh[i] * 60 + xm[i]; k < yh[i] * 60 + ym[i]; k++) {
				if (!ok[1][j][k]) {
					flag = false; break;
				}
			}
			if (flag) rm++;
		}
		ret += min(rn, rm);
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 3032
from collections import deque
around = [(0,1),(1,0),(0,-1),(-1,0)]

H,W = map(int,input().split())
grid = [list(input()) for _ in range(H)]

checked = [[0]*W for i in range(H)]

def dfs(si,sj):
    if grid[si][sj] == ".":
        b = 0; w = 1
    if grid[si][sj] == "#":
        b = 1; w = 0
    dq = deque()
    dq.append((si,sj))
    checked[si][sj] = 1
    while dq:
        i,j = dq.pop()
        for di,dj in around:
            ni = i + di; nj = j + dj
            if not(0 <= ni <= H-1 and 0 <= nj <= W-1):
                continue
            if checked[ni][nj]:
                continue
            p = grid[i][j]
            np = grid[ni][nj]
            if (p,np) == (".","#"):
                b += 1
                dq.append((ni,nj))
                checked[ni][nj] = 1
            if (p,np) == ("#","."):
                w += 1
                dq.append((ni,nj))
                checked[ni][nj] = 1
    return b*w

ans = 0
for i in range(H):
    for j in range(W):
        if not checked[i][j] and grid[i][j] == ".":
            ans += dfs(i,j)
print(ans)

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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < s.size(); i ++)
	{
		int x = s[i] - '0';
		ans *= 10;
		ans += x;
		ans %= 9;
	}
	cout << (ans == 0 ? "Yes\n" : "No");




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3756
public class Main {

  private static int q(int seat) {
    System.out.println(seat);
    String s = next();
    if (s.equals("Male")) {
      return 0;
    } else if (s.equals("Female")) {
      return 1;
    } else {
      System.exit(0);
      return -1;
    }
  }

  private static void solve() {
    int n = ni();
    
    int left = 0;
    int right = n;

    int a = q(left);
    while (right - left > 2) {
      int med = (right - left - 1) / 2 + left;
      int b = q(med);
      int c = (med - left) % 2;
      if (a == b && c == 1 || a != b && c == 0) {
        right = med;
      } else {
        left = med + 1;
        a = b == 1 ? 0 : 1;
      }
    }
    q(left);
    q(right - 1);
  }

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

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

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

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 24996
package main

import (
	"bufio"
	"fmt"
	"os"
)

type Pair struct{ s, t int }

func main() {
	N := ReadInt()
	m := make(map[[2]int]Pair)
	zeros := 0
	for i := 0; i < N; i++ {
		x, y := ReadInt(), ReadInt()
		if x == 0 && y == 0 {
			zeros++
			continue
		}
		gcd := GCD(x, y)
		x /= gcd
		y /= gcd
		if y < 0 {
			x, y = -x, -y
		}
		if y == 0 && x < 0 {
			x, y = -x, -y
		}
		rot90 := x <= 0
		if rot90 {
			x, y = y, -x
		}
		pair := m[[2]int{x, y}]
		if rot90 {
			pair.s++
		} else {
			pair.t++
		}
		m[[2]int{x, y}] = pair
	}
	ans := 1
	for _, pair := range m {
		now := 1
		now += ModPow(2, pair.s) + Mod - 1
		now += ModPow(2, pair.t) + Mod - 1
		now %= Mod
		ans *= now
		ans %= Mod
	}
	ans = ans + zeros + Mod - 1
	ans %= Mod
	fmt.Println(ans)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

const Mod = int(1e9) + 7

func ModPow(a, b int) (x int) {
	for x = 1; b > 0; b >>= 1 {
		if b&1 == 1 {
			x = x * a % Mod
		}
		a = a * a % Mod
	}
	return
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 26192
n,k=map(int,input().split())
P=10**9+7
class FactInv:
    def __init__(self,N,P):
        fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
        for i in range(1,N):
            fact[i+1]=(fact[i]*(i+1))%P
        ifact[-1]=pow(fact[-1],P-2,P)
        for i in range(N,0,-1):
            ifact[i-1]=(ifact[i]*i)%P
        self.fact=fact;self.ifact=ifact;self.P=P
    def comb(self,n,k):
        return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
C=FactInv(2*n+10,P)
ans=0
for i in range(0,min(k+1,n)):
    ans+=(C.comb(n,i)*C.comb(n-1,n-i-1))%P
    ans%=P
print(ans)

Measured memory_bytes: 34676
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
long long a[1000000],b[1000000],c[1000000];
int main ()
{
	int n,i,j,k,x,y;
	long long sum;
	scanf("%d", &n);
	sum = 0;
	for (i = 1; i <= n; i++)
	{
		scanf("%lld",&a[i]);
		sum = sum + a[i];
		b[i] = sum;
	}
	for (i = 1; i <= n-1; i++)
	{
		c[i] = abs(b[i] - (sum - b[i]));
	}
	sort(c+1,c+n);
	printf("%lld",c[1]);
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
const  int maxx=1e5+100;
const int INF=99999999;
const int MOD=1e9+7;
typedef long long ll;
//int n;
//struct node
//{
//    int l,r,nextt;
//    ll dis;
//}s[maxx*2];
//ll d[maxx];
//int h[maxx];
//int cnt;
//void add(int a,int b,ll c)
//{
//    s[cnt].l=a;
//    s[cnt].r=b;
//    s[cnt].dis=c;
//    s[cnt].nextt=h[a];
//    h[a]=cnt++;
//}
//void dfs(int k,int dd)
//{
//    for(int i=h[k]; i!=-1; i=s[i].nextt){
//        int v=s[i].r;
//        if(v==dd)  continue;
//        d[v]=d[k]+s[i].dis;
//        dfs(v,k);
//    }
//}
//int main()
//{
//    scanf("%d",&n);
//    int a,b;
//    ll c;
//    cnt=0;
//    memset(h,-1,sizeof(h));
//    memset(d,0,sizeof(d));
//    for(int i=0; i<n; i++){
//        scanf("%d%d%lld",&a,&b,&c);
//        add(a,b,c);
//        add(b,a,c);
//    }
//    int m,k;
//    scanf("%d%d",&m,&k);
//    dfs(k,-1);
//    while(m--){
//        scanf("%d%d",&a,&b);
//        printf("%lld\n",d[a]+d[b]);
//    }
//    return 0;
//}
int cnt,head[maxx];
ll d[maxx];
struct Edge
{
    int l,r,nxt;
    ll dis;
}e[maxx*2];

void addedge(int u,int v,ll w)
{
    e[cnt].l=u;
    e[cnt].r=v;
    e[cnt].dis=w;
    e[cnt].nxt=head[u];
    head[u]=cnt++;
}

void dfs(int u,int fa)
{
    for(int i=head[u];i!=-1;i=e[i].nxt)
    {
        int to=e[i].r;
        if(to==fa) continue;
        d[to]=d[u]+e[i].dis;
        dfs(to,u);
    }
}

int main()
{
    int n;
    scanf("%d",&n);
        cnt=0;
        memset(head,-1,sizeof(head));
        memset(d,0,sizeof(d));
        int a,b;
        ll c;
        for(int i=1;i<=n-1;i++)
        {
            scanf("%d%d%lld",&a,&b,&c);
            addedge(a,b,c);
            addedge(b,a,c);
        }
        int m,k;
        scanf("%d%d",&m,&k);
        dfs(k,-1);
        int x,y;
        while(m--)
        {
            scanf("%d%d",&x,&y);
            printf("%lld\n",d[x]+d[y]);
        }
    return 0;
}

Measured memory_bytes: 12288
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    a, i = [1], 0
    for _ in [0] * N:
        a.append(A[i])
        i = A[i] - 1

    if K <= N:
        print(a[K])
        return

    n = defaultdict(list)
    for i, v in enumerate(a):
        if n[v]:
            n[v].append(i)
            break
        n[v].append(i)
    l, r = n[v][0], n[v][1]
    loop = a[l:r]
    K -= l
    n = K % (r - l)
    print(loop[n])


main()


Measured memory_bytes: 46336
public class Main {
  private static void solve() {
    char[] s = ns();
    int ret = s.length;
    for (int i = 1; i < s.length; i ++) {
      if (s[i] != s[i - 1]) {
        int now = Math.max(i, s.length - i);
        ret = Math.min(ret, now);
      }
    }
    System.out.println(ret);
  }

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

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

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

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

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

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

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

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

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

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

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

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




Measured memory_bytes: 25684
#include <iostream>
using namespace std;
int s(int n )
{
	int a,b,c;
	a=n%10;
	b=n/10%10;
	c=n/100;
	return a*100+b*10+c;
}
 
int main()
{
	int n,a;
	while (cin >> n)
	{
		a=s(n);
		if(a==n) cout << "Yes"<<endl;
		else  cout << "No"<< endl;
	}

	
	return 0;
 } 

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

int main()
{
    long long int n;
    cin>>n;
    vector<long long int>v(n);
    for(int i=0;i<n;i++)
     cin>>v[i];
    long long int res=1000;
    for(int i=1;i<n;i++)
    {
        long long c=0;
        long long int q=res/v[i-1];
        long long int profit=q*(v[i]-v[i-1]);
        long long int add=max(c,profit);
        res+=add;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 3588
// Last Change: 08/01/2019 13:25:07.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  map<string, int> mp;
  int val;
  string ipt;
  cin >> val;
  for (int i = 0; i < val; ++i) {
    cin >> ipt;
    ++mp[ipt];
  }
  cin >> val;
  for (int i = 0; i < val; ++i) {
    cin >> ipt;
    --mp[ipt];
  }

  int ans = 0;
  for (auto &&e : mp) {
    ans = max(ans, e.second);
  }

  cout << ans << endl;
}


Measured memory_bytes: 500