akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	D = inputInt()
	C = inputList()
	S = []
	for i in range(D):
		s = inputList()
		S.append(s)

	ans1 = []
	ans2 = []
	ans3 = []
	ans4 = []
	for i in range(D):
		bestSco1 = 0
		bestSco2 = 0
		bestSco3 = 0
		bestSco4 = 0
		bestI1 = 1
		bestI2 = 1
		bestI3 = 1
		bestI4 = 1

		for j,val in enumerate(S[i]):
			if j == 0:
				tmpAns = ans1 + [j+1]
				tmpSco = findScore(tmpAns, S, C)
				if bestSco1 < tmpSco:
					bestSco4 = bestSco3
					bestI4 = bestI3
					bestSco3 = bestSco2
					bestI3 = bestI2
					bestSco2 = bestSco1
					bestI2 = bestI1
					bestSco1 = tmpSco
					bestI1 = j+1
			else:
				tmpAns1 = ans1 + [j+1]
				tmpAns2 = ans2 + [j+1]
				tmpAns3 = ans3 + [j+1]
				tmpAns4 = ans4 + [j+1]
				tmpSco1 = findScore(tmpAns1, S, C)
				tmpSco2 = findScore(tmpAns2, S, C)
				tmpSco3 = findScore(tmpAns3, S, C)
				tmpSco4 = findScore(tmpAns4, S, C)
				if bestSco1 < tmpSco1:
					bestSco1 = tmpSco1
					bestI1 = j+1
				if bestSco2 < tmpSco2:
					bestSco2 = tmpSco2
					bestI2 = j+1
				if bestSco3 < tmpSco3:
					bestSco3 = tmpSco3
					bestI3 = j+1
				if bestSco4 < tmpSco4:
					bestSco4 = tmpSco4
					bestI4 = j+1
		ans1.append(bestI1)
		ans2.append(bestI2)
		ans3.append(bestI3)
		ans4.append(bestI4)

	aa = []
	aa.append(bestSco1)
	aa.append(bestSco2)
	aa.append(bestSco3)
	aa.append(bestSco4)
	aa.sort()

	if aa[0] == bestSco1:
		for i in ans1:
			print(i)
	elif aa[0] == bestSco2:
		for i in ans2:
			print(i)
	elif aa[0] == bestSco3:
		for i in ans3:
			print(i)
	elif aa[0] == bestSco4:
		for i in ans4:
			print(i)


def findScore(ans, S, C):
	scezhu = [inf for i in range(26)]
	sco = 0
	for i,val in enumerate(ans):
		tmp = S[i][val-1]
		scezhu[val-1] = i
		mins = 0
		for j,vol in enumerate(C):
			if scezhu[j] == inf:
				mins = mins + (vol * (i+1))
			else:
				mins = mins + (vol * ((i+1)-(scezhu[j]+1)))
		tmp -= mins
		sco += tmp
	return sco

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 87212
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main(){
	int a, b, n, x, y;
	vector< vector< int > > field;
	
	while(cin >> a >> b, a){
		cin >> n;
		
		field.RS(a);
		REP(i, a){
			field[i].RS(b);
			REP(j, b) field[i][j] = 0;
		}
		
		REP(i, n){
			cin >> x >> y;
			field[x-1][y-1] = -1;
		}
		
		field[0][0] = 1;
		REP(i, a){
			REP(j, b){
				if(field[i][j] != -1){
					if(i > 0) field[i][j] += (field[i-1][j] != -1 ? field[i-1][j] : 0);
					if(j > 0) field[i][j] += (field[i][j-1] != -1 ? field[i][j-1] : 0);
				}
			}
		}
		
		cout << field[a-1][b-1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
isInRect x y x1 y1 x2 y2 
    | x1 <= x && x <= x2 && y1 <= y && y <= y2 = True 
    | otherwise = False 
 
main = getLine >>= putStrLn . (\ [w,h,x,y,r] -> if isInRect x y r r (w-r) (h-r) then "Yes" else "No") . map (read :: String -> Int) . words

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    int a, b, k;
    cin >> a >> b >> k;
    int flag = 1;
    for (int i = 0; i < k; i++) {
        if (flag == 1) {
        if (a % 2 == 1) {
            a--;
        }
        b += a / 2;
        a /= 2;
            flag = -1;
        } else {
            if (b % 2 == 1) {
                b--;
            }
            a += b / 2;
            b /= 2;
            flag = 1;
        }

    }
    cout << a << " " << b << endl;
}




Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int q_one = 0;
  int q_two = 0;
  int q_four = 0;
  for(int i=0; i<N; i++){
    int tmp;
    cin >> tmp;
    tmp %= 4;
    if(tmp == 0) q_four++;
    else if(tmp == 2) q_two++;
    else q_one++;
  }
  q_two %= 2;
  bool tf = false;
  if(q_two == 0){
    if(q_four >= q_one-1) tf = true;
  }else{
    if(q_four >= q_one) tf = true;
  }
  if(tf) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {
    string s; cin >> s;
    int ans = 0;
    char c = s[0];
    for (int i = 0; i < s.size(); i++) {
        if (c != s[i]) { ans++; c = s[i]; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int n,s[1111111];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	for(int i=n;i>=1;i-=2) printf("%d ",s[i]);
	if(n%2==0) for(int i=1;i<=n;i+=2) printf("%d ",s[i]);
	if(n%2==1) for(int i=2;i<=n;i+=2) printf("%d ",s[i]);
	printf("\n");
}


Measured memory_bytes: 2944
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	public static final double EPS = 1E-10;
	public static boolean epsEquals(double a, double b) { return Math.abs(a-b) < EPS; };

	static void solve() {
		out.println(isParallel(new Vector(in.nextDouble(),in.nextDouble(),in.nextDouble(),in.nextDouble()),new Vector(in.nextDouble(),in.nextDouble(),in.nextDouble(),in.nextDouble())) ? "YES" : "NO");
	}

	static boolean isParallel(Vector a, Vector b) {
		return epsEquals(Vector.cross(a,b),0.0);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		int n = in.nextInt();
		while(n-- > 0) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}

	static class Vector implements Comparable {

		private double x, y;
		public Vector(double x, double y) {
			this.x = x; this.y = y;
		}
		public Vector(Point target, Point source) {
			this.x = target.getX() - source.getX();
			this.y = target.getY() - source.getY();
		}
		public Vector(double tx, double ty, double sx, double sy) {
			this.x = tx - sx;
			this.y = ty - sy;
		}

		public static double dot(Vector a, Vector b) { return a.getX()*b.getX() + a.getY()*b.getY(); }
		public static double cross(Vector a, Vector b) { return a.getX()*b.getY() - a.getY()*b.getX(); }

		public double getX() {
			return this.x;
		}
		public double getY() {
			return this.y;
		}

		public void set(double x, double y) {
			this.x = x; this.y = y;
		}

		public int compareTo(Object other) {
			Vector p = (Vector)other;
			if (!epsEquals(this.x,p.x)) return this.x < p.x ? -1 : 1;
			if (!epsEquals(this.y,p.y)) return this.y < p.y ? -1 : 1;
			return 0;
		}

		public boolean equals(Vector p) {
			return epsEquals(this.x,p.x) && epsEquals(this.y,p.y);
		}

		public String toString() {
			return "("+x+","+y+")";
		}
	}

	static class Point implements Comparable, Cloneable {

		private double x, y;
		public Point(double x, double y) {
			this.x = x; this.y = y;
		}

		public double getX() {
			return this.x;
		}
		public double getY() {
			return this.y;
		}

		public void set(double x, double y) {
			this.x = x; this.y = y;
		}

		public int compareTo(Object another) {
			Point p = (Point)another;
			if (!epsEquals(this.x,p.x)) return this.x < p.x ? -1 : 1;
			if (!epsEquals(this.y,p.y)) return this.y < p.y ? -1 : 1;
			return 0;
		}

		public boolean equals(Point p) {
			return epsEquals(this.x,p.x) && epsEquals(this.y,p.y);
		}

		public Point clone() {
			return new Point(this.x, this.y);
		}

		public String toString() {
			return "("+x+","+y+")";
		}
	}
}

Measured memory_bytes: 30124
#include <iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include <stdio.h>
#include<cstdlib>
#include<math.h>
#include<complex>

using namespace std;

int main() {
	string a;
	cin >> a;
	if (a[0] !=a[1] && a[1] !=a[2] && a[0] !=a[2])cout << "Yes" << endl;
	else cout << "No" << endl;
		

}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    map<int,int> mp;
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    int cnt=0;
    rep(i,n){
        if(a[i]>=3200) cnt++;
        else mp[a[i]/400]++;
    }
    int ans=mp.size();
    if(ans==0){
        cout<<1<<endl;
        cout<<cnt<<endl;
        return 0;
    }
    cout<<ans<<endl;
    cout<<ans+cnt<<endl;
}

Measured memory_bytes: 4992
package main

import (
	"fmt"
)

func main() {
	var a int
	var b int
	fmt.Scan(&a)
	fmt.Scan(&b)
	var result int
	if a > b {
		result = a + a - 1
	} else if a == b {
		result = a + b
	} else {
		result = b + b - 1
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

int main() {
	std::string S;
	std::cin >> S;

	int price = 700;

	for(char c : S) {
		if(c == 'o') {
			price += 100;
		}
	}

	std::cout << price << std::endl;

	return 0;
}

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

int main(void) {
	char op;
	int a, b, ans;
	while (1) {
		cin >> a >> op >> b;
		if (op == '?')
			break;
		switch (op) {
		case '+':
			ans = a + b;
			break;
		case '-':
			ans = a - b;
			break;
		case '*':
			ans = a * b;
			break;
		case '/':
			ans = a / b;
			break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	diff := 0
	for p, i := 0, 0; i < n; i++ {
		fmt.Scan(&p)
		if p != i+1 {
			diff++
		}
	}
	ans := ""
	if diff <= 2 {
		ans = "YES"
	} else {
		ans = "NO"
	}
	fmt.Println(ans)
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ny = ReadInts();
            var N = ny[0];
            var Y = ny[1];

            //iが1000円
            //jが5000円
            //kが10000円

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N - i; j++)
                {
                    var k = N - i - j;
                    if (1000 * i + 5000 * j + 10000 * k == Y)
                    {
                        WriteLine($"{k} {j} {i}");
                        return;
                    }
                }
            }
            WriteLine("-1 -1 -1");
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        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: 13140
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
  string s,t;
  cin>>s>>t;
  bool f=1;
  rep(i,0,3) if(s[i]!=t[2-i]) f=0;
  if(f) cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
N = input()
inputs = [map(int, raw_input().split(' ')) for i in range(N)]
for xs in inputs:
    a, b = 0, 0
    for x in xs:
        if min(a,b) > x:
            print 'NO'
            break
        else:
            if (a>b and x>a) or (b>x):
                a=x
            else:
                b=x
        if x == xs[-1]:
            print 'YES'

Measured memory_bytes: 6308
#include<stdio.h>
main(){
	int H1 = 0;
    int M1 = 0;
  	int H2 = 0;
  	int M2 = 0;
  	int K = 0;
 	int i = 0;
  	int j = 0;
  	int k = 0;
  	
  	scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);
  	i = H1 * 60 + M1;
  	j = H2 * 60 + M2;
  	k = j - K - i;
  
  	printf("%d", k);
}

Measured memory_bytes: 1728
h,w = map(int,input().split())

tab = []
for i in range(0,h):
    tab.append(input())

alone = False

#for i in range(0,h):
#    print(tab[i][0:])

#print(tab[h-1][w-1])
for hi in range(0,h):
    if alone :
        break
    for wi in range(0,w):

        if tab[hi][wi] != '#':
            continue

        if hi + 1 < h:
            if tab[hi + 1][wi] == '#':
                continue

        if hi - 1 >= 0:
            if tab[hi - 1][wi] == '#':
                continue

        if wi + 1 < w:
            if tab[hi][wi + 1] == '#':
                continue

        if wi - 1 >= 0:
            if tab[hi][wi - 1] == '#':
                continue

        alone = True
        break;

#    if alone:
#        break
print("Yes" if not alone else "No")

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

class UnionFind {
private:
	std::vector<int> pre;
	std::vector<int>siz;
	int root(int x);
public:
	UnionFind(int n);
	void unite(int x, int y);
	int size(int x);
	bool same(int x, int y);
};

UnionFind::UnionFind(int n) : pre(n), siz(n) {
	for (int i = 0; i < pre.size(); ++i) {
		pre.at(i) = i;
		siz.at(i) = 1;
	}
}

int  UnionFind::root(int x) {
	if (pre.at(x) == x) return x;
	else return pre.at(x) = root(pre.at(x));
}

void UnionFind::unite(int x, int y) {
	int root_x = root(x);
	int root_y = root(y);
	if (root_x == root_y) return;
	else {
		siz.at(root_y) += siz.at(root_x);
		pre.at(root_x) = root_y; 
	}
}

int UnionFind::size(int x) {
	return siz.at(root(x));
}

bool UnionFind::same(int x, int y) {
	return root(x) == root(y);
}

int main(void) {
	int n, m, k;
	std::cin >> n >> m >> k;

	UnionFind tree(n);

	std::vector<int>fb(n, 1);
	for (int i = 0; i < m; ++i) {
		int tx, ty;
		std::cin >> tx >> ty;

		int x = tx - 1, y = ty - 1;
		tree.unite(x, y);
		fb.at(x)++;
		fb.at(y)++;
	}
	for (int i = 0; i < k; ++i) {
		int tx, ty;
		std::cin >> tx >> ty;

		int x = tx - 1, y = ty - 1;
		if (tree.same(x, y)) {
			fb.at(x)++;
			fb.at(y)++;
		}
	}

	for (int i = 0; i < n; ++i) {
		std::cout << tree.size(i) - fb.at(i) << " ";
	}
}

Measured memory_bytes: 2560
// By Atul Rathore

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

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007


int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC";
	else cout<<"ABC";





}


Measured memory_bytes: 3652
def main():
    h, w = list(map(int, input().split()))
    if (h==1 or w==1):
        print(1)
    elif (h%2==0 or w%2==0):
        print(int((h*w)/2))
    else:
        print(int((h*w)//2+1))

if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> d(n);
    rep(i, n) {
        cin >> d.at(i).first;
        cin >> d.at(i).second;
    }

    bool res = false;
    rep(i, n - 2) {
        if(d.at(i).first == d.at(i).second) {
            if(d.at(i + 1).first == d.at(i + 1).second) {
                if(d.at(i + 2).first == d.at(i + 2).second) {
                    res = true;
                }
            }
        }
    }

    if(res)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <complex>
#include <iomanip>

using namespace std;

typedef complex<double> Point;

ostream& operator<<(ostream& os, const Point& p){
    return os <<  p.real() << " " << p.imag();
}

inline double dot(const Point& a, const Point& b){
    return real(conj(a) * b);
}

struct Line : vector<Point> {
    Line(const Point& a, const Point& b):vector<Point>{a, b}{}
};

inline Point proj(const Line& l, const Point& p){
    double t = dot(p - l[0], l[1] - l[0]) / norm(l[1] - l[0]);
    return l[0] + (l[1] - l[0]) * t;
}

inline Point refl(const Line& l, const Point& p){
    return p + (proj(l, p) - p) * 2.0;
}

int main(){
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    Line l(Point(x0, y0), Point(x1, y1));
    int q;
    cin >> q;
    while(q--){
        int x2, y2;
        cin >> x2 >> y2;
        cout << fixed << setprecision(10) << refl(l, Point(x2, y2)) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,mp[105][105],swp,vis[105][105];
int main()
{
	ios_base::sync_with_stdio(0);
	cout<<"100 100"<<endl;
	cin>>n>>m;
	swap(n,m);
	for (i=1;i<=100;i++)
	{
		for (j=1;j<=100;j++)
		{
			if (j<=50) mp[i][j]='.'; else mp[i][j]='#';
		}
	}
	n--;
	m--;
	/*for (i=3;i<=98;i++)
	{
		for (j=3;j<=98;j++)
		{
			if ((i&1)^(j&1)) mp[i][j]='*';
		}
	}
	int cnta=0,cntb=0;
	for (i=1;i<=100;i++)
	{
		for (j=1;j<=100;j++)
		{
			if (vis[i][j]) continue;
			if (mp[i][j]=='.')
			{
				cnta++;
			}
			else
			{
				cntb++;
			}
			dfs(i,j);
		}
	}
	cerr<<cnta<<' '<<cntb<<endl;
	n-=cntb;
	m-=cnta;
	for (i=1;i<=n;i++)
	{
	 */
	for (i=2;i<=99;i++)
	{
		for (j=2+(i&1);j<=49;j+=3)
		{
			if (n)
			{
				n--;
				mp[i][j]='#';
			}
		}
	}
	for (i=2;i<=99;i++)
	{
		for (j=52+(i&1);j<=99;j+=3)
		{
			if (m)
			{
				m--;
				mp[i][j]='.';
			}
		}
	}
	for (i=1;i<=100;i++)
	{
		for (j=1;j<=100;j++)
		{
			cout<<(char)mp[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k%2==1) {
    cout << b-a << endl;
  }
  else {
    cout << a-b << endl;
  }
}

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

using namespace std;

const int MOD = 1000000007;

int n, ans = 1;

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

    cin >> n;

    for (int i = 1; i <= n; i++) {
        ans = ((long long)(ans) * (long long)(i)) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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 div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, d;

void solve(){
    stack<int> st[n];
    int sum[n];
    memset(sum, 0, sizeof(sum));
    int num = 0;
    rep(i, n){
        int m;
        scanf("%d", &m);
        num += m;
        rep(_, m){
            int c;
            scanf("%d", &c);
            st[i].push(c);
            sum[i] += c;
        }
    }
    multiset<int> S;
    rep(i, n) S.insert(sum[i]);

    while(num){
        bool flag = false;
        rep(i, n)if(!st[i].empty()){
            S.erase(S.find(sum[i]));
            sum[i] -= st[i].top();
            S.insert(sum[i]);
            if(*S.rbegin() - *S.begin() <= d){
                flag = true;
                st[i].pop();
                --num;
                break;
            }
            S.erase(S.find(sum[i]));
            sum[i] += st[i].top();
            S.insert(sum[i]);
        }
        if(!flag){
            puts("No");
            return;
        }
    }
    puts("Yes");
}

int main(){
    while(scanf("%d%d", &n, &d) && n){
        solve();
    }
}


Measured memory_bytes: 3188
N, M = list(map(int, input().rstrip().split()))

t = [0] * N

for i in range(M):
    tmp = list(map(int, input().rstrip().split()))
    if tmp[0] == 1:
        t[tmp[1] - 1] |= 1
    
    if tmp[1] == N:
        t[tmp[0] - 1] |= 2


result = 'POSSIBLE' if 3 in t else 'IMPOSSIBLE'
print(result)
        


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

int main()
{
  int N;
  cin >> N;
  for(int i; i < 1000000; i++)
  {
    if(1000 * i >= N)
    {
      cout << 1000 * i - N << endl;
      break;
    }
  }
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(void){
	int a[4], b[4];
	int hit;
	int blow;
	int i, j;

	while(scanf("%d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3]) != EOF){
		hit = 0;
		blow = 0;
		for(i=0; i<4; i++){
			if(a[i] == b[i]) hit++;
		}
		for(i=0; i<4; i++){
			for(j=0; j<4; j++){
				if(a[i] == b[j]) blow++;
			}
		}
		blow -= hit;

		printf("%d %d\n", hit, blow);
	}

	return 0;
}

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

using namespace std;

const int M = 1e9+7;

int mpow(long long a, int n)
{
  if (n % 2) return mpow(a, n-1) * a % M;
  if (n == 0) return 1;
  return mpow(a * a % M, n/2);
}

int main()
{
  int n, k; cin >> n >> k;
  int a[100005]; for (int i = 0; i < n; ++i) cin >> a[i];
  
  sort(a, a+n);
  
  long long kaijo[100005]; kaijo[0] = 1;
  for (int i = 1; i <= n; ++i) kaijo[i] = kaijo[i-1] * i % M;
  
  int inv[100005];
  for (int i = 0; i <= n; ++i) inv[i] = mpow(kaijo[i], M-2);
  
  long long com[100005];
  for (int i = k-1; i <= n; ++i) com[i] = kaijo[i] * inv[k-1] % M *inv[i-k+1] % M;
  int mn = 0, mx = 0;
  for (int i = 0; i < n-k+1; ++i) {
    mn = (mn + (a[i] + M) * com[n-i-1] % M) % M;
    mx = (mx + (a[n-i-1] + M) * com[n-i-1] % M) % M;
  }
  
  int ans = (mx - mn + M) % M;
  cout << ans << endl;
  return 0;
}

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

int a[110][110], f[110][110];

int main() {
	ios::sync_with_stdio(false);
	int h,w; cin >> h >> w;
	string s;
	for (int i = 0; i < h; i++) {
		cin >> s;
		for (int j = 0; j < w; j++) a[i+1][j+1] = ((s[j] == '.')?0:1);
	}
	/*
	for (int i = 1; i <= h; i++) {
		int last = w;
		for (int j = w; j; j--) {
			if (a[i][j] != a[i][last]) last = j;
			passr[i][j] = last;
		}
	}
	for (int j = 1; j <= w; j++) {
		int last = h;
		for (int i = h; i; i--) {
			if (a[i][j] == a[last][j]) last = i;
			passc[i][j] = last;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			
		}
	}
	*/
	f[1][1] = a[1][1];
	for (int j = 2; j <= w; j++) {
		f[1][j] = f[1][j-1];
		if (!a[1][j-1] && a[1][j]) f[1][j]++;;
	} 		
	for (int i = 2; i <= h; i++) {
		f[i][1] = f[i-1][1];
		if (!a[i-1][1] && a[i][1]) f[i][1]++;		
		for (int j = 2; j <= w; j++) {
			int tmp1 = f[i-1][j];
			if (!a[i-1][j] && a[i][j]) tmp1++;
			int tmp2 = f[i][j-1];
			if (!a[i][j-1] && a[i][j]) tmp2++;
			f[i][j] = min(tmp1,tmp2);
		}			
	}
	cout << f[h][w] << "\n";
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, m, q, val[11][100005];
int col[100005];

vector<int> v[100005];

int main(){
	scanf("%d %d", &n, &m);
	FI(i, 1, m){
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	scanf("%d", &q);
	FI(i, 1, q){
		int v, d, c;
		scanf("%d %d %d", &v, &d, &c);
		col[i] = c;
		val[d][v] = i;
	}
	FD(i, 9, 0){
		FI(j, 1, n){
			val[i][j] = max(val[i][j], val[i + 1][j]);
			for(auto to: v[j]){
				val[i][j] = max(val[i][j], val[i + 1][to]);
			}
		}
	}
	FI(i, 1, n) printf("%d\n", col[val[0][i]]);
	return 0;
}


Measured memory_bytes: 11128
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897L
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"No\n"; return 0;}
#define yup {cout<<"Yes\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

int main() {
    
    get2(n,m);

    map<int,int> mapa;
    ll low, high;
    if(n==1) low = 0, high = 9;
    if(n==2) low = 10, high = 99;
    if(n==3) low = 100, high = 999;

    bool f = 0;
    rep(i,m) {
        get2(s,c); s = s-1;
        if(mapa.count(s) && mapa[s]!=c) {
            f = 1;
        }
        mapa[s] = c;
    }
    if(!f)
    for(ll i=low;i<=high;i++) {
        bool f = 0;
        vector<ll> a{i%10, i/10%10, i/100%10};
        while(a.size()>n) a.pop_back();
        reverse(ALL(a));
        
        for(auto i:mapa) {
            if(a[i.fi]!=i.se) f=1;
        }
        if(f) continue;

        printf("%lld\n",i);
        return 0;
    }

    printf("-1\n");
    return 0;  
}   


Measured memory_bytes: 256
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A& lang=jp    "Single Source Shortest Path I"?????¨??????
?§£??????Dijkstra???
????????????1h+???????????°1h
memset??§D[100000]????????????1000000000???????????????????????¨???????????§???????????????????????£????????????????????????????????????
*/
#include <iostream>
#include <string.h>
using namespace std;
#include <queue>
int main (){
    long D[100000];//r??????????????????????????¢
    for(int i=0;i<100000;i++){
        D[i]=1000000000;//?????????????????????????????§????????§??????100000*10000
    }
    int V,E,r;
    cin>>V>>E>>r;//???????????°???????????°????§???????????????????
    int head[100000],next[500000]={},to[500000]={},D2[500000]={};
    memset(head,-1,sizeof(head));
    for(int i=0;i<E;i++){//i???????????????????????????????????????
        int s,t,d;
        cin>>s>>t>>d;
		next[i]=head[s];//??????????????????s????????????????????????head[s]??§?????????next[i]?????£??\
        head[s]=i;//head[s]?????´??°
        to[i]=t;//i?????????????????????????????£??\
        D2[i]=d;//i??????????????????????????£??\
    }
    queue<int> Q;
    Q.push(r);//?§???????Q?????\??????
    D[r]=0;//?§?????????§????????¢???0
    while(! Q.empty()){//Q????????????????????§?¶???????
		int x=Q.front();//Q????????????????????????x?????£??\
        Q.pop();
        for(int i=head[x];i!=-1;i=next[i]){//x?????????????????????????????????????????????
            if(D[to[i]]>D[x]+D2[i]){
                D[to[i]]=D[x]+D2[i];//???????????¢??´??°
                Q.push(to[i]);//???????????¢?????´??°??????????????§?????????????????????????????????Q?????\?????´???
            }
        }
    }
    for(int i=0;i<V;i++){
        if(D[i]==1000000000) cout<<"INF"<<endl;//1000000000???????????????????????§?????????????????????????????????
        else cout<<D[i]<<endl;
    }
}

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

int gcd(int p, int q){
  if(p%q == 0) return q;
  return gcd(q, p%q);
}

int main(){
  int k;
  cin >> k;
  int ans = 0;
  for(int a = 1; a <= k; ++a){
  	for(int b = 1; b <= k; ++b){
  		for(int c = 1; c <= k; ++c){
  			ans += gcd(gcd(a, b), c);
  		}
  	}
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, m;
    char[] l, r, res;
    String str;
    int i, j;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      l = new char[n];
      r = new char[n];
      for(i = 0;i < n;i++){
        str = sc.next();
        l[i] = str.charAt(0);
        str = sc.next();
        r[i] = str.charAt(0);
      }

      m = sc.nextInt();
      res = new char[m];
      for(i = 0;i < m;i++){
        str = sc.next();
        res[i] = str.charAt(0);
        for(j = 0;j < n;j++){
          if(res[i] == l[j]){
            res[i] = r[j];
            break;
          }
        }
        System.out.print(res[i]);
      }
      System.out.println();
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 69456
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<int> ivec;
typedef pair<int, int> ipair;

int main() {
    int N, X, D, A[100];
    cin >> N;
    cin >> D >> X;
    for (int i = 0; i < N; i++) cin >> A[i];

    int sum = 0;
    for (int i = 0; i < N; i++) {
        int j;
        for (j = 1; j <= D; j++) {
            if (j * A[i] + 1 > D) break;
        }
        sum += j;
    }
    cout << sum + X << endl;
    return 0;
}


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

using namespace std;

int main(){
	int n,k;
	cin >> k >> n;
	if(k%2 == 0){
		cout << k/2 << " ";
		for(int i = 1; i<n; i++) cout << k << " ";
	}else{	
		int sub = n/2;
		vector<int> v;
		for(int i = 0; i<n; i++) v.push_back(k/2+k%2);
		while(sub--){
			if(v.back() == 1) v.pop_back();
			else{
				v[v.size()-1]--;
				while(v.size() < n) v.push_back(k);
			}
		}
		for(auto i : v) cout << i << " ";
	}
}


Measured memory_bytes: 3568
#include<stdio.h>
	int main(){
		int H=0,W=0,i,k,cnt=0,r,t,e;
		int data[1000],data2[1000];
		while(1){
			scanf("%d %d",&data[H],&data2[W]);
			if(data[H]==0 && data[W]==0)break;
			H++;
			W++;
			cnt++;
		}
			for(r=0;r<cnt;r++){
				e = data[r];
				t = data2[r];
			for(i=0;i<e;i++){
				for(k=0;k<t;k++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
			}
			return 0;
	}

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

int main(){
    int n, cost[100000], h[100000], i;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> h[i];
        if(i == 0){
            cost[i] = 0;
        }else if(i == 1){
            cost[i] = abs(h[i] - h[i -1]); 
        }else{
            cost[i] = min(cost[i-2] + abs(h[i] - h[i-2]),cost[i-1] + abs(h[i] - h[i-1]) );
        }
    }
    cout << cost[n-1] << '\n';
    return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  reverse(all(a));
  ll ans=0;
  rep(i,k){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        if(n%k == 0){
            System.out.println(0);
        }else{
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;

namespace AtCoder0913
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            //long[] N = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray() ;
            long all = 1;
            long tasu = 1;
            long hiku = 1;
            long hiku2 = 1;
            long ans = 0;
            long mod = 1000000000 + 7;

            for (var i = 0; i < N; i++)
            {


                all = all * 10 % mod;
                hiku = hiku * 9% mod;
                hiku2 = hiku2 * 9 % mod ;
                tasu =  tasu *8 % mod;

            }
            ans = (all + tasu - hiku - hiku2) % mod;
            if(ans < 0)
            {
                ans += mod;
            }
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 27480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	string s;
	cin>>n>>s;
	int ans = 0;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
			ans++;
	}
	cout<<ans;
	
	return 0;
}
	
	
	
	
	
	
	
	
	
	
	

























Measured memory_bytes: 256
//When I wrote this only God and I knew what it is
//Now, only The_Blitz knows...
#pragma GCC optimize ("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define FER(i,a,b) for(int i =int(a); i < int(b); ++ i)
#define IFR(i,a,b) for(ll i = ll(a); i >= ll(b); -- i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> ii;

const int N = 2e3 + 2;

vector<int> adj[N];
int dist[N], dp[N];

void dfs(int x){
	queue<int> q;
	q.push(x); dist[x] = 0;
	while(!q.empty()){
		int u = q.front(); q.pop();
		dp[dist[u]] ++;
		for(auto v: adj[u]){
			if(dist[v] == -1){
				dist[v] = dist[u] + 1;
				q.push(v);
			}
		}
	}
}

int main(){
	fastio;
	int n, x, y; cin >> n >> x >> y;
	FER(i, 1, n) adj[i].pb(i + 1), adj[i + 1].pb(i);
	adj[x].pb(y); adj[y].pb(x);
	FER(i, 1, n + 1){
		FER(j, 1, n + 1) dist[j] = -1;
		dfs(i);
	}
	FER(i, 1, n) cout << dp[i] / 2 << endl;
	return 0;
}



Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define Min(a,b) ((a)<(b)?(a):(b))

int cmp(const void *ax, const void *ay){
	unsigned long x = *(unsigned long *)ax;
	unsigned long y = *(unsigned long *)ay;

	if(x > y) return -1;
	if(x < y) return 1;
	if(x = y) return 0;
}

unsigned long sub2(unsigned long **V, unsigned int *n, unsigned long W, unsigned long base, unsigned int ofs){
	unsigned int i,  N;	
	unsigned long sum = 0, tmp, w;
	w = base+ofs;
	N = Min(n[ofs], (unsigned int)(W/w+1));

	if(ofs == 0) return V[0][N-1];

	for(i = 0; i < N; i++){
		tmp = V[ofs][i] + sub2(V, n, W-w*i, base, ofs-1); 
		if(sum < tmp) sum = tmp;
	}

	return sum;
}

unsigned long sub1(unsigned int N, unsigned long W, unsigned long *w, unsigned long *v){
	unsigned int i, n[4], diff;
	unsigned long *V[4], Vmax;

	for(diff = 0; diff < 4; diff++){
		V[diff] = (unsigned long *)malloc(sizeof(unsigned long) * (N+1));
		if(V[diff] == NULL) exit(1);
		V[diff][0] = 0;
		n[diff] = 1;
	}
		
	for(i = 0; i < N; i++){
		diff = (unsigned int)(w[i] - w[0]);
		V[diff][n[diff]] = v[i];
		n[diff]++;
	}
	for(diff = 0; diff < 4; diff++){
		qsort(&V[diff][1], n[diff]-1, sizeof(unsigned long), cmp);
		for(i = 1; i < n[diff]; i++) V[diff][i] += V[diff][i-1];
	}
	
	Vmax = sub2(V, n, W, w[0], 3);
	for(diff = 0; diff < 4; diff++) free(V[diff]);
	return Vmax;
}

int main(){
	unsigned int N, i;
	unsigned long W, *w, *v;
	char line[64];

	fgets(line, 64, stdin);
	sscanf(line, "%u %lu", &N, &W);

	w = (long *)malloc(sizeof(long) * N);
	v = (long *)malloc(sizeof(long) * N);
	if((w == NULL)||(v == NULL)) exit(1);
	for(i = 0; i < N; i++){
		fgets(line, 64, stdin);
		sscanf(line, "%lu %lu", w+i, v+i);
	}

	printf("%lu\n", sub1(N, W, w, v));

	free(w);
	free(v);
	return 0;
}


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

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int ans;
  if (n <= k) {
    ans = x * n;
  } else {
    ans = x * k + y * (n - k);
  }

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


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

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  
  int count = 0;
  for(int i = 1; i <= n; ++i){
    int keta = i % 10;
    keta += (i / 10) % 10;
    keta += (i / 100) % 10;
    keta += (i / 1000) % 10;
    keta += (i / 10000) % 10;
    if(a <= keta && keta <= b){
      count += i;
    }
  }
  cout << count <<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	In := readBigLineInt()
	K := In[1]
	Result := 0
	for _, v := range readBigLineInt() {
		if v >= K {
			Result++
		}
	}
	fmt.Println(Result)
}

/////////////////////////////////////////
func readBigLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readBigLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readBigLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

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

int main(){
  string s[1000];
  int n=0;
  while(cin>>s[n]) n++;
  sort(s,s+n);
  int m,c;
  m=c=0;
  string t,ms,l;
  ms=t=s[0];
  for(int i=0;i<n+1;i++){
    if(t==s[i]) c++;
    else{
      if(c>m){
	m=c;
	ms=t;
      }
      c=1;
      t=s[i];
      if(t.length()>l.length()) l=t;
    }
  }
  cout<<ms<<" "<<l<<endl;
  return 0;
}

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

const int Mod = 998244353;

int main() {
  int n;
  cin >> n;
  ll d[n], cnt[n];
  rep(i, n) cnt[i] = 0;
  int mx = 0;
  rep(i, n) {
    cin >> d[i];
    ++cnt[d[i]];
    if (d[i] > mx) mx = d[i];
  }
  ll ans = 1;
  for (int i = 1; i <= mx; ++i) {
    for (int j = 0; j < cnt[i]; ++j) {
      ans = ans * cnt[i-1] % Mod;
    }
  }
  cout << ((!d[0] && cnt[0] == 1) ? ans : 0) << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 100010;
const ll INF = 1e9 + 10;
ll dp[MAXN];

int main() {
   int N;
   cin >> N;
   ll a[N];
   for (int i = 0; i < N; i++) cin >> a[i];
   reverse(a, a + N);
   fill(dp, dp + N, INF);
   for (int i = 0; i < N; i++) {
      *upper_bound(dp, dp + N, a[i]) = a[i];
   }
   int ans = lower_bound(dp, dp + N, INF) - dp;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1792
n,k = gets.chomp.split(" ").map(&:to_i)
d = gets.chomp.split(" ")
loop do
  f = 0
  d.each do |num|
    if n.to_s.include?(num)
      f = 1
      break
    end
  end
  if f == 0
    puts n
    exit
  end
  n += 1
end

Measured memory_bytes: 1788
#include<iostream>
int main(){
  while(1){
    int n,x,count=0;
    std::cin >> n >> x;
    if(n == 0 && x == 0) break;
    for(int i=1; i<=n-2; i++){
      for(int j=i+1; j<=n-1;j++){
        for(int k=j+1; k<=n; k++){
          if(i+j+k == x){
            count++;
          }
        }
      }
    }
    std::cout << count << "\n";
  }
  return 0;
}

Measured memory_bytes: 3092
N = int(input())
S = input()
m = 0
for i in range(N-1):
  a = S[:i+1]
  b = S[i+1:]
  c = 0
  for j in list(set(a)):
    if j in b:
      c += 1
  if c > m:
    m = c
print(m)


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

using namespace std;
#define DIM  107
#define DIM2 100007
#define INF 10E16
#define MAXN 107
#define LG 18
#define MODULO 1000000007
#define MODULO2 MODULO*2
typedef long long  ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef ll arr[DIM];
typedef vector<ll> vec;
typedef vector<ll> graph[DIM];
typedef pll parr[DIM];
typedef ll table[DIM][DIM2];
typedef ll arr2[DIM2];
struct pp {
	ll a, b;
	bool operator <(const pp& V)const {
		if (a == V.a)return b < V.b;
		return a < V.a;
	}
	bool operator ==(const pp& V)const {
		if (a == V.a && b == V.b)return 1;
		return 0;
	}
};
ll n, k,D[DIM][DIM2],sum[DIM][DIM2];
arr A;
int main()

{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> A[i];
	for (int i = 0; i <= k; i++) {
		if (i<=A[1])
		D[1][i] = 1;
		sum[1][i] = sum[1][i - 1] + D[1][i];
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			D[i][j] = sum[i - 1][j];
			if (j >= A[i] + 1)D[i][j] -= sum[i - 1][j - A[i] - 1];
			if (D[i][j] < 0)D[i][j] += MODULO;
			D[i][j] %= MODULO;
			sum[i][j] = sum[i][j - 1] + D[i][j];
			if (j == 0)sum[i][j] -= sum[i][j - 1];
			sum[i][j] %= MODULO;
			
		}
	}
	cout << D[n][k] << endl;	
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n,0);

    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int A=0,B=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            A += a[i];
        }else{
            B += a[i];
        }
    }
    cout << A-B << endl;
}

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

int a[1000][1000];

int main()
{
	int n, m, t, p;
	while (cin >> n >> m >> t >> p, n | m | t | p) {
		int xl = 0, xr = n, yl = 0, yr = m;
		for (int i = xl; i < xr; i++) {
			for (int j = yl; j < yr; j++) {
				a[i][j] = 1;
			}
		}
		for (int i = 0; i < t; i++) {
			int d, c;
			cin >> d >> c;
			if (d == 1) {
				for (int j = 0; j < c; j++) {
					for (int y = yl; y < yr; y++) {
						a[xl + c * 2 - 1 - j][y] += a[xl + j][y];
						a[xl + j][y] = 0;
					}
				}
				xr = max(xr, xl + c * 2);
				xl += c;
			}
			else {
				for (int x = xl; x < xr; x++) {
					for (int j = 0; j < c; j++) {
						a[x][yl + c * 2 - 1 - j] += a[x][yl + j];
						a[x][yl + j] = 0;
					}
				}
				yr = max(yr, yl + c * 2);
				yl += c;
			}
		}
		while (p--) {
			int x, y;
			cin >> x >> y;
			printf("%d\n", a[xl + x][yl + y]);
		}
		for (int i = xl; i < xr; i++) {
			for (int j = yl; j < yr; j++) {
				a[i][j] = 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 4792
//与えられた3つの数字の最大最小を求める
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>

int main (){
    std::vector<int> vec{};
    int a;
    
    for(int i=0;i<3;i++){
        std::cin>>a;
        vec.push_back(a);
    }

    auto t = std::minmax_element(vec.begin(),vec.end());//iteratorなので*をつけないと要素はわからない
    std::cout<<*t.first<<" "<<*t.second<<std::endl;

    return 0;
}



Measured memory_bytes: 3144