akhauriyash/Code-Regression huggingface dataset:
//Self-control leads to consistency.
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
ll n,q;
ll arr[500011],bit[600001];
set<ll> val[500011];
map<dos,ll>g;
ve qur[500001];
void upd(ll va,ll ind){
  for (ll i = ind; i <= n; i+=(i&(-i)))
  {
    bit[i]+=va;
  }
}
ll poin(ll ind){
  ll res=0;
  for (ll i = ind; i > 0; i-=(i&(-i)))
  {
    res+=bit[i];
  }
  return res;
}
ll range(ll l,ll r){
  return poin(r)-poin(l-1);
}
int main()
{
  //flash;
  cin>>n>>q;
  for (ll i = 0; i < n; ++i)
  {
    cin>>arr[i];
    val[arr[i]].insert(i);
  }
  vedos ans;
  while(q--){
    ll x,y;
    cin>>x>>y;
    x--,y--;
    qur[y].pb(x);
    ans.pb({x,y});
  }
  for (ll i = 0; i < n; ++i)
  {
    if(val[arr[i]].find(i)==val[arr[i]].begin()){
      upd(1,i+1);
    }
    else{
      auto u=val[arr[i]].find(i);
      u--;
      upd(1,i+1);
      upd(-1,(*u)+1);
    }
    for(auto it:qur[i]){
      ll yo=range(it+1,i+1);
      g[{it,i}]=yo;
    }
  }
  for(auto it:ans){
    cout<<g[{it.first,it.second}]<<'\n';
  }
  return 0;
}

Measured memory_bytes: 119240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String st[] = new String[h];
		boolean tw[] = new boolean[w];
		boolean th[] = new boolean[h];
		for (int i=0;i<h;i++)
			th[i] = false;
		for (int j=0;j<w;j++)
			tw[j] = false;
		
		for (int i=0;i<h;i++) {
			st[i] = sc.next();
			for (int j=0;j<w;j++) {
				tw[j] |= st[i].charAt(j)!='.';
				th[i] |= st[i].charAt(j)!='.';
			}
		}
		
		for (int i=0;i<h;i++) {
			if (th[i]) {
				for (int j=0;j<w;j++) {
					if (tw[j]) System.out.print(st[i].charAt(j));
				}
			System.out.println();
			}
		}

	}

}


Measured memory_bytes: 29416
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = [0] * (N+1)
    for x in range(1, 102):
        for y in range(1, 102):
            for z in range(1, 102):
                t = x*x + y*y + z*z + x*y + y*z + z*x
                if t <= N:
                    A[t] += 1
    for i in range(1, N+1):
        print(A[i])


if __name__ == "__main__":
    main()

Measured memory_bytes: 9764
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
l=list(map(int,input().split()))

l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            # print(l[i],l[j],l[k])
            if l[i]==l[j] or l[j]==l[k] or l[i]==l[k]:
                continue
            if l[i]+l[j]>l[k]:
                ans+=1
print(ans)

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

lli f(lli b, lli n) {
    if (n < b)
        return n;
    else
        return f(b, n / b) + n % b;
}

int main() {
    lli n, s;
    cin >> n >> s;
    const lli inf = 1LL << 60;
    lli ans = inf;
    if (n < s) {
        cout << -1 << endl;
        return 0;
    }
    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }
    if ((n - s) % (n - 1) == 0 && f(n, n) == s) {
        ans = n;
    }
    for (lli b = 2; b * b <= n; b++) {
        if ((n - s) % (b - 1) == 0) {
            lli rest = (n - s) / (b - 1);
            if (f(b, n) == s) {
                ans = min(ans, b);
            }
            if (f(rest + 1, n) == s) {
                ans = min(ans, rest + 1);
            }
        }
    }
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = input()
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
if int(n[-1]) in hon:
    print('hon')
elif int(n[-1]) in pon:
    print('pon')

elif int(n[-1]) in bon:
    print('bon')


Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
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;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int pre = 0;
    ll sum = 0;
    for(int i = 0; i < n; i++) {
        if(pre <= a[i]) {
            pre = a[i];
        } else {
            sum += pre - a[i];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3912
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
const int Max = 4e5 + 5;
int vis[Max]; 
vector<int> e[Max];
int n, m;
int s[Max], s1[Max];
bool bfs(int u)
{
	queue<int> q;
	q.push(u);
	vis[u] = 0;
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (int i = 0; i < (int)e[u].size(); i++)
		{
			int v = e[u][i];
			if (vis[v] == -1)
			{
				vis[v] = u;
				q.push(v);
			}
		}
	}
	for (int i = 2; i <= n; i++)
	{
		if (vis[i] == -1)return false;
	}
	return true;
}
int main()
{
	
	while (cin >> n >> m)
	{
		memset(vis, -1, sizeof(vis));
		memset(s, 0, sizeof(s));
		memset(s1, 0, sizeof(s1));
		int k = 0;
		for (int i = 1; i <= m; i++)
		{
		
			cin >> s[k] >> s1[k];
			e[s[k]].push_back(s1[k]);
			e[s1[k]].push_back(s[k]);
			k++;
		}
		if (!bfs(1))
			cout << "No" << endl;
		else
		{
			cout << "Yes" << endl;
			for (int i = 2; i <= n; i++)
				cout << vis[i] << endl;
		}
		for (int i = 0; i < k; i++)
		{
			e[s[i]].clear();
			e[s1[i]].clear();
		}
	}
	return 0;
}

Measured memory_bytes: 21660
n, k, q = map(int, input().split())
#全問不正解者を基準にする
ans = [int(input()) for _ in range(q)]
l = [k-q]*n

for a in ans:
  #正解者に+１する
  l[a-1]+=1
for i in l:
  #全ラウンド終了後の結果を出力
  if i>0: print("Yes")
  else: print("No")
  

Measured memory_bytes: 55896
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
using namespace std;

const int N_MAX = 101;
int N;
typedef pair<string, int> P;
string s;
int p;
struct Data {
	string S;
	int P;
	int idx;
};


bool compare_by_b(Data a, Data b) {
	if (a.S != b.S) {
		return a.S < b.S;
	}
	else {
		return a.P > b.P;
	}
}

int main() {
	cin >> N;
	vector<Data> d(N);
	//Data d[N_MAX];
	for (int i = 0; i < N; i++) {
		cin >> s >> p;
		d[i].S = s;
		d[i].P = p;
		d[i].idx = i;
	}
	sort(d.begin(), d.end(), compare_by_b);
	for (int i = 0; i < N; i++) {
		cout << d[i].idx+1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
ll ans = 0;


int main() {
	ll n, x;
	cin >> n >> x;
	ans = n;
	ll a = x;
	ll b = n - x;
	if (a < b)
		swap(a, b);
	while (b) {
		ll d = a / b;
		ans += d * 2 * b;
		a -= d * b;
		swap(a, b);
	}
	ans -= a;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanInt() int {
	scanner.Scan()
	a, err := strconv.Atoi(scanner.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanByte() byte {
	scanner.Scan()
	return []byte(scanner.Text())[0]
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	// scanner.Split(bufio.ScanWords)

	var s string
	fmt.Scan(&s)

	// s := scanText()

	space := make([]byte, 5*int(math.Pow(10, 5)))
	si := 2 * int(math.Pow(10, 5))
	ei := si + len(s)
	for i := si; i < ei; i++ {
		space[i] = s[i-si]
	}

	b := false

	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var t int
		fmt.Scan(&t)
		// t := scanInt()
		if t == 1 {
			b = !b
		} else { // t == 2
			var f int
			var c string
			fmt.Scan(&f, &c)
			// f := scanInt()
			// c := scanByte()
			if f == 1 && !b || f == 2 && b { // 先頭
				si--
				space[si] = c[0]
			} else {
				space[ei] = c[0]
				ei++
			}
		}
	}

	str := string(space[si:ei])
	if !b {
		fmt.Println(str)
	} else {
		fmt.Println(reverse(str))
	}
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
string a,b,c;
lli ans = 0;

int main(){
  cin >> n;
  cin >> a >> b >> c;
  for(lli i = 0;i < n;i++){
    if(a[i] == b[i] && b[i] == c[i]) continue;
    if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) ans += 2;
    else ans += 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

int N, ans = inf;

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

    for (int i = -200; i <= 200; i++)
    {
        int p = 0;
        for (int j = 0; j < N; j++)
        {
            p += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, p);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define STACK_SIZE 1000
#define MAX_LEN 1000

int stack[STACK_SIZE];
int stack_size = 0;

// ????????????????????????
int pop()
{
	if (stack_size <= 0) return 0;
	return stack[--stack_size];
}

// ?????????????????????
void push(int a)
{
	stack[stack_size++] = a;
}

// ????´??????°?????????????????????
int is_digit(char *s)
{
	// ?¬??????????
	if (*s == '+' || *s =='-') {
		s++;
		if (*s >= '0' && *s <= '9') return 1;
		return 0;
	}
	// ?¬??????????
	if (*s >= '0' && *s <= '9') return 1;
	return 0;
}

// ?????????????????°??????????????????
int get_number(char *s)
{
	int sign = 0, n = 0;
	
	// ?¬??????????
	if (*s == '+') {
		s++;
	} else if (*s == '-') {
		sign = 1;
		s++;
	}
	// char to int
	while (*s >= '0' && *s <= '9') {
		n = n * 10 + (*s - '0');
		s++;
	}
	// ?¬??????????????????????
	if (sign) return -n;
	return n;
}

// ???????????????????¨????????????????????¨????
int calc_rpn(char *s)
{
	int a, b, n;
	
	// ???????????§??°?????????
	while (*s) {
		
		// ??°?????????????????????????????????????????????
		if (is_digit(s)) {
			n = get_number(s);
			push(n);
			while (*s == '-' || *s == '+') {
				s++;
			}
			while (n) {
				n /= 10;
				s++;
			}
			
		// ?????????????????????2???????¨??????????
		} else {
			switch (*s) {
			case '+':
				a = pop();
				b = pop();
				push(b+a);
				break;
			case '-':
				a = pop();
				b = pop();
				push(b-a);
				break;
			case '*':
				a = pop();
				b = pop();
				push(b*a);
				break;
//			case '/':
//				a = pop();
//				b = pop();
//				if (a == 0) break;
//				push(b/a);
//				break;
//			case '%':
//				a = pop();
//				b = pop();
//				if (a == 0) break;
//				push(b%a);
			}
			s++;
		}
	}
	return pop();
}

int main()
{
	char s[MAX_LEN];
	scanf("%[^\n]*s", s);
	printf("%d\n", calc_rpn(s));
    return 0;
}

Measured memory_bytes: 536
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=3005,P=1e9+7,inv2=500000004;
inline void Add(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))if(y&1)res=mul(res,x);
	return res;
}
struct node{int x,y;}p[N];
int f[N][N],g[2][N],ans[2][N][N],a[N];
int n,q,res;
void solve(int pos){
	int tag=1;
	fd(t,q,1){
		tag=mul(tag,2);
		int x=p[t].x,y=p[t].y;
		fp(i,1,n)g[0][i]=g[1][i]=0;
		fp(i,1,n)g[0][i]=add(f[x][i],f[y][i]),g[1][i]=add(f[i][x],f[i][y]);
		int c=f[x][y],d=f[y][x];
		fp(i,1,n)f[x][i]=f[y][i]=mul(g[0][i],inv2),f[i][x]=f[i][y]=mul(g[1][i],inv2);
		f[x][y]=f[y][x]=mul(add(c,d),inv2),f[x][x]=f[y][y]=0;
	}
	fp(i,1,n)fp(j,1,n)ans[pos][i][j]=mul(f[i][j],tag);
}
void init(){
	fp(i,1,n)fp(j,1,n)f[i][j]=0;
	fp(i,1,n)fp(j,i+1,n)f[i][j]=1;
	solve(0);
	fp(i,1,n)fp(j,1,n)f[i][j]=0;
	fp(i,1,n)fp(j,1,i-1)f[i][j]=1;
	solve(1);
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),q=read();
	fp(i,1,n)a[i]=read();
	fp(i,1,q)p[i].x=read(),p[i].y=read();
	init();
	fp(i,1,n)fp(j,i+1,n)Add(res,a[i]==a[j]?0:a[i]>a[j]?ans[0][i][j]:ans[1][i][j]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 106752
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std ;
 
typedef long long ll ;
typedef long double ld ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = ( int ) 1e5 + 10 ;

int n , a [ N ] , b [ N ] ;

int32_t main()                     
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 0 ; i < n ; ++ i )
		cin >> a [ i ] >> b [ i ] ;
	int added = 0 , res = 0 ;
	for ( int i = n - 1 ; i >= 0 ; -- i ) {
		a [ i ] += added ;
		if ( a [ i ] % b [ i ] == 0 ) continue ; 
		int reach = a [ i ] + ( b [ i ] - ( a [ i ] % b [ i ] ) ) ;
		added += reach - a [ i ] ; 
	}
	cout << added << endl ; 
}


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

#define rep(i, n) for(int i = 0; i < n;i++)

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    short h,w,ans = 0;
    cin >> h >> w;
    char ai[w];
    rep(i,h) {
        cin >> ai;
        rep(j,w) if (ai[j] == '#') ans ++;
    }
    if (ans == h+w-1) cout << "Possible\n";
    else cout << "Impossible\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string s; cin >> s;
	int L = s.size();
	int left = 0, right = 0;
	for (int i = 0; i < L; i++) {
		if (i + 1 < L&&s[i] == s[i + 1]) {
			left = i, right = i + 1;
			break;
		}
		else if (i + 2 < L&&s[i] == s[i + 2] ) {
			left = i, right = i + 2;
			break;
		}
	}
	if (left == right) cout << -1 << " " << -1 << endl;
	else cout << left+1 << " " << right+1 << endl;
}


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

int main() {
    int a[4];
    int s[] = {1, 9, 7, 4};
    cin >> a[0] >> a[1] >> a[2] >> a[3];

    vector<int> b;
    for(int i = 0; i < 4; i++) {
        b.push_back(a[i]);
    }
    
    for(int i = 0; i < 4; i++) {
        int x = s[i];
        bool f = false;
        for(vector<int>::iterator it = b.begin(); it != b.end(); it++) {
            if(*it == x) {
                f = true;
            }
        }
        if(!f)
            goto END;
    }
    cout << "YES" << endl;
    return 0;
    END:
        cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll> cnt(m);
    vector<ll> a;
    while(1) {
        if(cnt[x] > 1 || a.size() >= n) break;
        cnt[x]++;
        a.push_back(x);
        x = x*x%m;
    }
    ll ans = 0;
    if(a.size() >= n) {
        for(auto v : a) ans += v;
        cout << ans << endl;
        return 0;
    }
    auto itr = find(a.begin(), a.end(), x);
    ll idx = distance(a.begin(), itr);
    ll loop = 0;
    for(ll i = 0;i < a.size();i++) {
        if(i < idx) ans += a[i];
        else loop += a[i];
    }
    ll cycle = a.size() - idx;
    ans += (n-idx)/cycle * loop;
    for(ll i = 0;i < (n-idx)%cycle;i++) {
        ans += a[idx+i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5048
#include<iostream>
using namespace std;
int main(){
  int n, h[100000], dp[100000], cnt=0;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  dp[n-1] = 0;
  cnt = 0;
  for(int i=n-2; i>=0; i--){
    if(h[i] >= h[i+1]){
      cnt ++;
      dp[i] = max(dp[i+1], cnt);
    }else{
      cnt = 0;
      dp[i] = dp[i+1];
    }
  }
  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 1152
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++)
  for (int j = 0; j <= n - i; j++) {
    int k = n - i - j;
    if (10000 * i + 5000 * j + 1000 * k == y) {
      cout << i << ' ' << j << ' ' << k << '\n';
      return;
    }
  }
  cout << "-1 -1 -1" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main(){
	int n;
	cin >> n;
	
	map<string,int> mp;
	
	rep(i,n){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}

	ll ans = 0;
	for(auto p : mp){
		int cnt = p.second;
		ans += (ll)cnt * (cnt-1) / 2;
	}
	cout << ans << endl;

}

Measured memory_bytes: 11264
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int d[100];
vector<int> adj[100];

void bfs(int n, int start) {
	queue<int> que;

	for (int i = 0; i < n; i++)
		d[i] = i == start ? 0 : -1;

	que.push(start);
	while(!que.empty()) {
		int from = que.front();
		que.pop();

		for (int& to : adj[from])
			if (d[to] == -1) {
				d[to] = d[from] + 1;
				que.push(to);
			}
	}
}

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		while (k--) {
			int v;
			cin >> v;
			adj[u - 1].push_back(v - 1);
		}
	}

	bfs(n, 0);

	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << d[i] << endl;

	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,k,n,h,w;
    string s;
    cin>>h>>w;
    char a[h+2][w+2];
    memset(a,'.',sizeof(a));
    /*
    replace (.) with 0
    count adjacent, increase
    */
    for(i=1; i<=h; i++)
        for(j=1; j<=w; j++)
        {
            cin>>a[i][j];
         //   if(a[i][j]=='.')
           //     a[i][j]='0';
        }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            if(a[i][j]!='#')
            {
                ll cnt=0;
                char c;
                if(a[i-1][j+1]=='#')
                    cnt++;
                if(a[i-1][j]=='#')
                    cnt++;
                if(a[i-1][j-1]=='#')
                    cnt++;
                if(a[i][j+1]=='#')
                    cnt++;
                if(a[i][j-1]=='#')
                    cnt++;
                if(a[i+1][j+1]=='#')
                    cnt++;
                if(a[i+1][j]=='#')
                    cnt++;
                if(a[i+1][j-1]=='#')
                    cnt++;
                c='0'+cnt;
                a[i][j]=c;
        //        cout<<c<<" ";
            }
        }
      //  cout<<endl;
    }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
            cout<<a[i][j];

        cout<<endl;
    }






    return 0;
}





Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
const int mod = 1000000007;
typedef long long ll;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> s(2e5,0), f(2e5,0);
    vector<ll> A;
    ll cntz = 0, cntpl = 0, cntmi = 0;
    rep(i,N){
        ll a;
        cin >> a;
        A.push_back(abs(a));
        if(a == 0)cntz++;
        if(a > 0){
            s.push_back(a);
            cntpl++;
        }
        if(a < 0){
            f.push_back(abs(a));
            cntmi++;
        }
    }
    sort(all(A));
    sort(all(s), greater<>());
    sort(all(f), greater<>());
    mint ans = 1;
    if(N == K){
        rep(i,K)ans *= A[i];
        if(cntmi & 1)ans = -ans;
        cout << ans << endl;
        return 0;
    }
    // K < N;
    ll idx[] = {0,0};
    if(K&1){
        if(cntpl > 0)ans *= s[idx[0]++];
        else{
            rep(i,K)ans *= A[i];
            ans = -ans;
            cout << ans << endl;
            return 0;
        }
    }
    // 残りの偶数個を決めていく
    ll len = K / 2;
    while(len--){
        ll tmp[2];
        tmp[0] = s[idx[0]] * s[idx[0]+1];
        tmp[1] = f[idx[1]] * f[idx[1]+1];
        if(tmp[0] < tmp[1]){
            ans *= tmp[1];
            idx[1] += 2;
        }
        else{
            ans *= tmp[0];
            idx[0] += 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12864
#include <bits/stdc++.h>
#include <atcoder/all>

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T, size_t N, size_t I = N>
auto make_vector(const std::array<int, N> &a, T value = T()){
  static_assert(I >= 1);
  static_assert(N >= 1);
  if constexpr (I == 1){
    return std::vector<T>(a[N - I], value);
  }else{
    return std::vector(a[N - I], make_vector<T, N, I - 1>(a, value));
  }
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}



namespace solver {
  namespace ac = atcoder;

  void init(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(12);
    std::cerr << std::fixed << std::setprecision(12);
    std::cin.exceptions(std::ios_base::failbit);
  }

  int op(int a, int b){return std::max(a, b);}
  int e(){return -1;}

  void solve(){
    int N, Q; std::cin >> N >> Q;
    std::vector<int> a(N); std::cin >> a;
    auto seg = ac::segtree<int, op, e>(a);

    for(int i = 0; i < Q; ++i){
      int type; std::cin >> type;

      if(type == 1){
        int x, v; std::cin >> x >> v;
        seg.set(x - 1, v);
      }else if(type == 2){
        int l, r; std::cin >> l >> r;
        std::cout << seg.prod(l - 1, r) << "\n";
      }else{
        int x, v; std::cin >> x >> v;
        std::cout << seg.max_right(x - 1, [v](int x){return x < v;}) + 1 << "\n";
      }
    }
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 6116
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();

        int[] price = new int[n];
        int[][] skillUpValue = new int[n][m];

        for(int i = 0; i < n; i++){//多次元配列の生成（長さnの配列、配列の各要素はmの配列）
            price[i] = sc.nextInt();//値段の配列の生成
            for(int k = 0; k < m; k++){
                skillUpValue[i][k] = sc.nextInt();
            }
        }

        int min = (int)12e6;
        out:for(int i = 0; i < (1<<n);i++){//2進数に見立ててN冊の本の買い方を全探索（2^n-1までやれば全探索になっている）
            int rikai[] = new int[m];
            int cost = 0;
            for(int j = 0;j < n ;j++) {//各n桁の2進数iについて、1〜n桁目を見ていく
                if ((i >> j & 1) == 1) {//iの、j+1桁目が1かどうか判定 → 1なら該当の本を購入している
                    for (int k = 0; k < m; k++) {
                        rikai[k] += skillUpValue[j][k];//1〜Mまでの各アルゴリズムの理解度に本から得られる理解度を計上
                    }
                    cost += price[j];//購入した本の代金をコストに計上
                }
            }

            for(int l = 0; l < m;l++){
                if(rikai[l] < x){
                    continue out;
                }
            }
            if(min > cost) {
                min = cost;
            }
        }
        System.out.println(min == (int)12e6 ? -1 : min);
    }
}


Measured memory_bytes: 37560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int ans = 0;
		for (int i=0; i<s.length(); i++){
			int len = 0;
			for (int j=i; j<s.length(); j++){
				char c = s.charAt(j);
				if (c == 'A' || c == 'C' || c == 'G' || c == 'T'){
					len++;
				} else {
					break;
				}
			}
			ans = Math.max(ans, len);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <string.h>
char s[200001], t[200001];
int main() {
	scanf("%s%s", s, t);
	int ans = 0;
	int len = strlen(s);
	for (int i = 0; i < len; i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

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

    double a,b,x;
    cin >> a >> b >> x;
    double h = x/(a*a);
    double theta;
    if(h<b/2){
        theta = atan((2*a*h)/(b*b));
    }
    else{
        theta = atan(a/(2*(b-h)));
    }
    cout << fixed << setprecision(10) << 90-theta*180/3.141592654;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int cnt[100001] = {0};

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    char pre = 'C';
    int count = 0;
    rep(i, N) {
            if (pre == 'A' && S[i] == 'C') {
                count += 1;
            }
        cnt[i] = count;
        pre = S[i];
    }

    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        int result = cnt[r-1] - cnt[l-1];
        cout << result << endl;
    }
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll w[102],v[102];

ll dp[102][100005];

int main(){
    ll N,W; cin >> N >> W;
    rep(i,N) cin >> w[i] >> v[i];

    // dp[i][j] := i番目までの荷物で総和がj以下のときの価値の最大値
    for(int i=0;i<N;i++){   // see w[i],v[i]
        for(int j=0;j<=W;j++){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            if(j+w[i]<=W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]],dp[i][j] + v[i]);
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  char C;
  cin >> C;
  string memo = "abcdefghijklmnopqrstuvwxyz";
  for (int i = 0; i < 26; i++){
    if (C == memo.at(i)) {
      cout << memo.at(i + 1) << endl;
      break;
    }
  }
}

Measured memory_bytes: 3568
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
#include<math.h>

int main(void){
    int H, W;
    scanf("%d %d", &H, &W);
 
    char **S = (char**)malloc(H * sizeof(char*));
    int i, j;
    for(i=0; i<H; i++) {
        S[i] = (char*)malloc(W * sizeof(char));
    }
 
    for(i=0; i<H; i++) {
            scanf("%s", S[i]);
    }
    int h, w;
    for(h=0; h<H; h++) {
        for(w=0; w<W; w++) {
        int count = 0;
            if(S[h][w] == '.') {
                if(h != 0 && w != 0) {
                    if(S[h-1][w-1] == '#'){ count++;}
                }

                if(h != 0) {
                        if(S[h-1][w] == '#'){    count++;}
                }

                if(h != 0 && w < W - 1) {
                    if(S[h-1][w+1] == '#'){    count++;}
                }
                if(w != 0) {
                    if(S[h][w-1] == '#') {   count++;}
                }
                if(w < W - 1) {
                    if(S[h][w+1] == '#'){    count++;}
                }
                if( h < H - 1 && w != 0) {
                    if(S[h+1][w-1] == '#'){    count++;}
                }
                if(h < H - 1) {
                    if(S[h+1][w] == '#'){    count++;}
                }
                if(h < H - 1 && w < W - 1) {
                    if(S[h+1][w+1] == '#'){    count++;}
                }
                    S[h][w] = count + '0';

            }
        }
    }
    for(h=0; h<H; h++) {
        for(w=0; w<W; w++) {
            printf("%c", S[h][w]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
n, k = map(int,input().split())
a = [k+1 if x > k else x for x in map(int,input().split())]
a.sort()
lef = [1]*n
rig = [1]*n
mask = (1 << (k+1)) - 1
for i in range(n-1):
  lef[i+1] = lef[i] | (lef[i] << a[i]) & mask
  rig[-i-2] = rig[-i-1] | (rig[-i-1] << a[-i-1]) & mask
ok = -1
ng = n
while ng - ok > 1:
  mid = (ng + ok) // 2
  if a[mid] >= k:
      ng = mid
      continue
  lc = lef[mid]
  rc = rig[mid]
  cov = ((1 << k) - 1) ^ ((1 << (k - a[mid])) - 1)
  for i in range(k):
    if lc & 1 and rc & cov:
      ng = mid
      break
    lc >>= 1
    cov >>= 1
  else:
    ok = mid
print(ok + 1)

Measured memory_bytes: 10356
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define fr(i,x,n) for(int i=x;i<n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define MOD 1000000007
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=3000+50;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
int main(){
    int ans=0;
    LL x,y;scanf("%lld%lld",&x,&y);
    while(x<=y){x*=2;ans++;}
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

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

const int MAXW = 75, MAXH = 75;
int main()
{
	int w, h;
	while(cin >> w >> h && h)
	{
		string tile[MAXH] = {};
		rep(j, h) cin >> tile[j];
		string dp[MAXW][MAXH] = {}, us, ls;

		rep(j,h)rep(i,w)if(('0' <= tile[j][i]) && (tile[j][i] <= '9'))
		{
			us = dp[i + 1][j];
			ls = dp[i][j + 1];
			if(us.size() < ls.size() || (us.size() == ls.size() && us < ls))
				dp[i + 1][j + 1] = ls + tile[j][i];
			else
				dp[i + 1][j + 1] = us + tile[j][i];

			if(dp[i + 1][j + 1] == "0") dp[i + 1][j + 1] = "";
		}
		string ans  = "";
		rep(j,h)rep(i,w)if(dp[i + 1][j + 1].size() != 0 )
		{
			if(ans.size() < dp[i + 1][j + 1].size() ||
					(ans.size()==dp[i+1][j+1].size() && ans < dp[i + 1][j + 1]))
				ans = dp[i + 1][j + 1];
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
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 (b < a) { a = b; return true; } return false; }
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	int N, W; cin >> N >> W;
	vi v(N), w(N); rep(i, 0, N) cin >> v[i] >> w[i];
	vv(int, dp, N + 1, W + 1, 0);
	rrep(i, N - 1, -1)
		rep(j, 0, W + 1)
			dp[i][j] = (j < w[i]) ? (dp[i + 1][j]) : (max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]));
	P(dp[0][W]);
	return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e10, MOD=998244353;
     
ll n, q=1, a[N], b[N], c[N], f[N], m, x, y, z, o=3, h, w, mx, mn, ans=INF, Ans;
string s, S;
vector <ll> v[N];
pair<ll, ll> p[N];


main(){ios_base::sync_with_stdio(false), cin.tie(0);
                    
    cin>>n;
    if(n%10==7 || n%100/10==7 || n%1000/100==7){
    	cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 27032
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include <map>

using namespace std;
 
int main() {
	int N,ans;
	cin >> N;
	vector<int> A(N,0);

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

	sort(A.begin(),A.end());

	ans = A[N-1] - A[0];

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

Measured memory_bytes: 256
n = int(input())
pret = 0
prex = 0
prey = 0
flag = True
for i in range(n):
    t,x,y = map(int,input().split())
    if flag:
        tmp = t - pret - abs(x - prex) - abs(y - prey)
        #print(t, x, y, tmp)
        if tmp >= 0 and tmp % 2 == 0:
            pret = t
            prex = x
            prey = y
        else:
            flag = False
if flag:
    print('Yes')
else:
    print('No')


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

using namespace std;

int N;

int main() {
	cin >> N;
	int* X = new int[N];
	int* Y = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		Y[i] = X[i];
	}
	sort(X, X + N);
	int a = X[N / 2 - 1];
	int b = X[N / 2];
	for (int i = 0; i < N; i++) {
		if (Y[i] <=  a) {
			cout << b << endl;
		}
		else {
			cout << a << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())

m=[a, b, c, d]
n=[e, f]

k=sorted(m, reverse=True)
l=sorted(n, reverse=True)

x=k[:3]
y=l[:1]

print(sum(x)+sum(y))



Measured memory_bytes: 5592
#include <iostream>
using namespace std;
int main(){

  int n,p[5000],now[5000],i,result=10000000,log=0;

  cin>>n;

  for(i=0;i<n;i++) cin>>p[i];

  for(i=0;i<=p[0];i++){
    log=0;
    for(int j=0;j<n;j++) now[j]=p[j];
    now[0]-=i;
    log+=i;
    for(int j=0;j<n-1;j++){
      log+=now[j]*2;
      now[j+1]-=now[j];
      now[j]=0;
      if(now[j+1]<0) now[j+1]=0;
    }
    log+=now[n-1];
    result=min(result,log);
  }

  cout<<result<<endl;

  return 0;

}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

int main() {
	priority_queue<ll> S;
	ll k;
	string str;
	while (1) {
		cin >> str;
		if (str == "end")
			break;
		if (str == "insert") {
			cin >> k;
			S.push(k);
		} else {
			cout << S.top() << endl;
			S.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 9436
n,m = map(int,input().split())
l = [[False,0] for _ in range(n+1)]
p = 0
c = 0
for i in range(m):
  pi,si = input().split()
  pi = int(pi)
  si = str(si)
  if l[pi][0] == False:
    if si == "AC":
      c += 1
      l[pi][0] = True
      p += l[pi][1]
    else:
      l[pi][1] += 1
print(c,p)

Measured memory_bytes: 15092
N,X,Y = map(int,input().split())
X,Y = X-1,Y-1

ans = [0] * N
for i in range(N-1):
    for j in range(i+1,N):
        d = min(j-i, abs(i-X) + abs(j-Y) + 1)
        ans[d] += 1
print(*ans[1:], sep='\n')

Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main(){
	ll i, j;
	ll N_org;
	cin >> N_org;
	string S_org;
	cin >> S_org;

	ll ans = 0;

	for (ll begin_idx = 0; begin_idx < N_org; begin_idx++){
		string S = S_org.substr(begin_idx);
		ll N = N_org - begin_idx;
		vll A(N);
		A[0] = N;
		i = 1;
		j = 0;
		while (i < N) {
			while (i + j < N && S[j] == S[i + j]) ++j;
			A[i] = j;
			if (j == 0) { ++i; continue; }
			ll k = 1;
			while (i + k < N && k + A[k] < j) A[i + k] = A[k], ++k;
			i += k; j -= k;
		}
		ll ans1 = 0;
		for (ll i = 0; i < N; i++){
			ans1 = max(ans1, min(i, A[i]));
		}
		ans = max(ans, ans1);
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1010;

LL a, b, x;

int main()
{
    cin >> a >> b >> x;

    LL res = b / x - (a + x - 1) / x + 1;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256