akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<cmath>
#include<cassert>
#include<string>
#include<map>
#include<queue>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = { 0,-1,0,1 };
static const int dy[4] = { 1,0,-1,0 };
static const char dir[4] = { 'r','u','l','d' };
int MDT[N2][N2];

struct Puzzle { int f[N2], space, MD; };


Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle  pz) {
    int sum = 0;
    for (int i = 0; i < N2; i++) {
        if (pz.f[i] == N2)continue;
        sum += MDT[i][pz.f[i] - 1];
    }

    return sum;
}
bool dfs(int depth, int prev) {
    if (state.MD == 0)return true;
    if (depth + state.MD > limit)return false;

    int sx = state.space / N;
    int sy = state.space % N;
    Puzzle tmp;

    for (int r = 0; r < 4; r++) {
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if (tx < 0 || ty < 0 || tx >= N || ty >= N) {
            continue;
        }

        if (max(prev, r) - min(prev, r) == 2) continue;
        tmp = state;
        state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
        state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
        swap(state.f[tx * N + ty], state.f[sx * N + sy]);
        state.space = tx * N + ty;
        if (dfs(depth + 1, r)) { path[depth] = r; return true; }
        state = tmp;

    }
    return false;
}

bool isSolved() {
    for (int i = 0; i < N2; i++) {
        if (state.f[i] != i + 1)return false;
        return true;
    }
}

string iterative_deepening(Puzzle in) {
    in.MD = getAllMD(in);

    for (limit = in.MD; limit <= LIMIT; limit++) {
        state = in;
        if (dfs(0, -100)) {
            string ans = "";
            for (int i = 0; i < limit; i++)ans += dir[path[i]];
            return ans;
        }
    }

}
int main()
{
    for (int i = 0; i < N2; i++) {
        for (int j = 0; j < N2; j++) {
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }

    Puzzle in;

    for (int i = 0; i < N2; i++) {
        cin >> in.f[i];
        if (in.f[i] == 0) {
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = iterative_deepening(in);
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 3184
from collections import deque

H, W = map(int, input().split())
C_h, C_w = map(int, input().split())
D_h, D_w = map(int, input().split())
X = [input() for _ in range(H)]

inf = 10 ** 9
dist = [[inf] * W for _ in range(H)]
dist[C_h - 1][C_w - 1] = 0
q1 = deque()
q1.append((C_h - 1, C_w - 1))
q2 = deque()


def bfs_1():
    while q1:
        u, v = q1.popleft()
        q2.append((u, v))
        for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            if (0 <= u + i < H and 0 <= v + j < W
                    and X[u + i][v + j] == "."
                    and dist[u + i][v + j] > dist[u][v]):
                dist[u + i][v + j] = dist[u][v]
                q1.append((u + i, v + j))
                q2.append((u + i, v + j))


def bfs_2():
    while q2:
        u, v = q2.popleft()
        for i in range(-2, 3):
            for j in range(-2, 3):
                if (0 <= u + i < H and 0 <= v + j < W
                        and X[u + i][v + j] == "."
                        and dist[u + i][v + j] > dist[u][v] + 1):
                    dist[u + i][v + j] = dist[u][v] + 1
                    q1.append((u + i, v + j))


while q1 or q2:
    bfs_1()
    bfs_2()

if dist[D_h - 1][D_w - 1] < inf:
    print(dist[D_h - 1][D_w - 1])
else:
    print(-1)


Measured memory_bytes: 100520
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	string s1,s2;
	int count=0;
	cin>>s1>>s2;
	if(s1.length()>s2.length())
	cout<<"GREATER";
	else if(s1.length()<s2.length())
	cout<<"LESS";
	else if(s1.length()==s2.length())
	{
		for(int i=0;i<=s1.length();i++)
		{
			/*int a=s1[i]-'0';
			int b=s2[i]-'0';*/
			if(s1[i]!=s2[i])
			count++;
		}
		int a=s1[0];
		int b=s2[0];
		if(count==0){
		cout<<"EQUAL";
		}else if(a>b)
		cout<<"GREATER";
		else if(a<b)
		cout<<"LESS";
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char a[100][100],b[100][100];
int n,m;
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i]);
    }
    for(int i=0;i<m;i++)
    {
        scanf("%s",b[i]);
    }
    int flag=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {

            if(a[i][j]==b[0][0])
            {
                flag=0;
                for(int x=0;x<m;x++)
                {
                    for(int y=0;y<m;y++)
                    {
                        if(a[i+x][j+y]!=b[x][y])
                        {
                            flag=1;
                            break;
                        }
                    }
                }
            }
            if(flag==0)
            {
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}


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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int tmp1, tmp2;
    tmp1 = a;
    a = b;
    b = tmp1;
    tmp2 = a;
    a = c;
    c = tmp2;
    cout << a  << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<double> p(n+1);
    rep(i,n){
	cin>>p[i];
    }
    vector<vector<double> > dp(n+1,vector<double>(n+1));
    dp[0][0]=1;
    double ans=0;
    rep(i,n){
	rep(j,n){
	    dp[i+1][j+1]+=dp[i][j]*p[i];
	    dp[i+1][j]+=dp[i][j]*(1-p[i]);
	}
    }
    for(int i=n;i>n/2;i--){
	ans+=dp[n][i];
    }
    cout<<setprecision(10)<<ans<<'\n';
    return(0);
}


Measured memory_bytes: 70784
#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> Pair;

int w;
int n;
int vs[1001];
int ws[1001];
int dp[1001][1001];

int main() {
  for (int Case=1; ; Case++) {
    scanf("%d", &w);
    if (w == 0) return 0;

    scanf("%d", &n);
    for (int i=0; i<n; i++) {
      scanf("%d,%d", &vs[i], &ws[i]);
    }

    for (int j=0; j<=w; j++) dp[0][j] = 0;
  
    for (int i=0; i<n; i++) {
      for (int j=0; j<=w; j++) {
        dp[i+1][j] = dp[i][j];
      }
  
      for (int j=0; j<=w-ws[i]; j++) {
        dp[i+1][j+ws[i]] = max(dp[i+1][j+ws[i]], dp[i][j] + vs[i]);
      }
    }
  
    Pair ans(0, 0);
    for (int j=0; j<=w; j++) {
      ans = max(ans, Pair(dp[n][j], -j));
    }
  
    printf("Case %d:\n%d\n%d\n", Case, ans.first, -ans.second);
  }
}

Measured memory_bytes: 6556
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int X; cin >> X;
    int i = 0;
    while (i * (i + 1) / 2 < X) i++;
    cout << i << endl;
}

Measured memory_bytes: 256
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
li = [int(x) for x in s]
l = len(s)
ans = 0
if l == 1:
    print(li[0])
else:
    for i in range(1 << (l - 1)):
        k = li[0]
        ct = 0
        for j in range(l - 1):
            if i >> j & 1:
                ct += k
                k = li[j + 1]
            else:
                k = k * 10 + li[j + 1]
            if j == l - 2:
                ct += k
                ans += ct
    print(ans)

Measured memory_bytes: 5400
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var hs = new HashSet<int>();
		foreach(var n in P) hs.Add(n);
		
		int l = X, r = X;
		while(true){
			if(!hs.Contains(l)){
				Console.WriteLine(l);
				return;
			}
			if(!hs.Contains(r)){
				Console.WriteLine(r);
				return;
			}
			l--;
			r++;
		}
		
		
		
		
	}
	int X,N;
	int[] P;
	public Sol(){
		var d = ria();
		X = d[0]; N = d[1];
		if(N == 0){
			P = new int[0];
			return;
		}
		P = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int selectionSort(int A[],int N){
  int sw = 0;

  for(int i=0;i<N-1;i++){
    int minj = i;
    for(int j=i;j<N;j++){
      if(A[j]<A[minj]) minj = j;
    }
    swap(A[i],A[minj]);
    if(i!=minj) sw++;
  }
  return sw;
}

int main(){
  int A[100],N,sw;

  cin >> N;

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

  sw = selectionSort(A,N);

  for(int i=0;i<N;i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}



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

using ld = long double;
const ld eps = 1e-10, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using point = complex<ld>;

ld dot(point a, point b) {
	return real(conj(a) * b);
}

ld cross(point a, point b) {
	return imag(conj(a) * b);
}

int ccw(point a, point b, point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;	// a,b,c counter-clockwise
	if (cross(b, c) < -eps) return -1;	// a,b,c clockwise
	if (dot(b, c) < 0) return 2;		// c,a,b on a line
	if (norm(b) < norm(c)) return -2;	// a,b,c on a line
	return 0;							// a,c,b on a line
}

struct line {
	point a, b;
	line() : a(), b() {}
	line(const point& a_, const point &b_)
		: a(a_), b(b_) {}
};

bool isis_ll(line l, line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(line l, line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

bool isis_lp(line l, point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(line s, point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

point proj(line l, point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

point is_ll(line s, line t) {
	point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool isis_ss(line s, line t) {
	if (isis_ll(s, t)) return isis_ls(s, t) && isis_ls(t, s);
	return isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a);
}

ld dist_lp(line l, point p) {
	return abs(p - proj(l, p));
}

ld dist_ll(line l, line m) {
	return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}

ld dist_ls(line l, line s) {
	return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}

ld dist_sp(line s, point p) {
	point r = proj(s, p);
	return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}

ld dist_ss(line s, line t) {
	if (isis_ss(s, t)) return 0;
	return min({ dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b) });
}

vector<point> convex_hull(vector<point> ps) {
	sort(ps.begin(), ps.end(), [](const point& a, const point& b) {
		return a.imag() == b.imag() ? a.real() < b.real() : a.imag() < b.imag();
	});
	int k = 0;
	const int n = ps.size();
	vector<point> qs(n + 1);
	for (int i = 0; i < n; ++i) {
		while (k > 1 && ccw(qs[k - 2], qs[k - 1], ps[i]) == -1) {
			k--;
		}
		qs[k++] = ps[i];
	}
	for (int i = n - 2, t = k; i >= 0; --i) {
		while (k > t && ccw(qs[k - 2], qs[k - 1], ps[i]) == -1) {
			k--;
		}
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

int main()
{
	int n;
	cin >> n;
	vector<point> ps;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		ps.emplace_back(x, y);
	}
	auto ch = convex_hull(ps);
	cout << ch.size() << endl;
	for (auto p : ch) {
		cout << p.real() << ' ' << p.imag() << endl;
	}
	return 0;
}



Measured memory_bytes: 12128
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int q,lim;
int bit[400001],num[400000],sz,tl;
void add(int i,int x){
	for(;i<=q;i+=i&-i)bit[i]+=x;
}
int sum(int i){
	int ret=0;
	for(;i;i-=i&-i)ret+=bit[i];
	return ret;
}
int get(int x){
	int lo=0, hi=tl, mid;
	while(lo+1<hi){
		mid=(lo+hi)/2;
		if(sum(mid)<x)lo=mid; else hi=mid;
	}
	return lo;
}
int main()
{
	while(scanf("%d%d",&q,&lim),q){
		memset(bit,0,sizeof(bit));
		map<int,int> pos;
		sz=tl=0;
		rep(it,q){
			int query,x; scanf("%d%d",&query,&x);
			/*cerr<<"q, x: "<<query<<" "<<x<<endl;
			rep(i,10)cerr<<num[i]<<" "; cerr<<endl;
			rep(i,10)cerr<<sum(i)<<" "; cerr<<endl;*/
			
			if(query==0){
				pos[x]=tl;
				num[tl++]=x;
				add(tl,1);
				if(sz>=lim){
					add(get(1)+1,-1);
				}
				else sz++;
			}
			if(query==1){
				//x=get(x);
				add(get(x)+1,-1);
				sz--;
			}
			if(query==2){
				printf("%d\n",num[get(x)]);
			}
			if(query==3){
				add(pos[x]+1,-1);
				sz--;
			}
		}
		puts("end");
	}
	return 0;
}

Measured memory_bytes: 16000
def main():
    n = int(input())
    s = [0] * n
    d = [0] * n
    for i in range(n):
        x, y = map(int, input().split())
        s[i] = x + y
        d[i] = x - y
    print(max(max(s) - min(s), max(d) - min(d)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 24564
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
char str[310000];
set<int>S;
int segtree[1048576];
int getmin(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c||c>d)return 1000000007;
	if(c<=a&&b<=d)return f+segtree[e];
	return min(getmin(a,(a+b)/2,c,d,e*2,f+segtree[e]),getmin((a+b)/2+1,b,c,d,e*2+1,f+segtree[e]));
}
void add(int a,int b,int c,int d,int e,int f){
	if(c>d)return;
	if(d<a||b<c)return ;
	if(c<=a&&b<=d){
		segtree[e]+=f;
		return;
	}
	add(a,(a+b)/2,c,d,e*2,f);
	add((a+b)/2+1,b,c,d,e*2+1,f);
	if(segtree[e*2]>0&&segtree[e*2+1]>0){
		int val=min(segtree[e*2],segtree[e*2+1]);
		segtree[e]+=val;
		segtree[e*2]-=val;
		segtree[e*2+1]-=val;
	}
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	scanf("%s",str);
	for(int i=0;i<a;i++)if(str[i]==')')S.insert(i);
	int now=0;
	for(int i=0;i<a;i++){
		if(str[i]=='(')now++;
		else now--;
		add(0,524287,i+1,i+1,1,now);
	}
	for(int i=0;i<b;i++){
		int c;scanf("%d",&c);c--;
		if(str[c]=='('){
			S.insert(c);
			str[c]=')';
			int at=*(S.begin());
			printf("%d\n",at+1);
			str[at]='(';
			S.erase(at);
			add(0,524287,at+1,c,1,2);
		}else{
			S.erase(c);
			str[c]='(';
			add(0,524287,c+1,a,1,2);
			int L=-1;
			int R=c;
			while(L+1<R){
				int M=(L+R)/2;
				int val=getmin(0,524287,M+1,c+1,1,0);
				if(val>=2)R=M;
				else L=M;
			}
			printf("%d\n",R+1);
			str[R]=')';
			S.insert(R);
			add(0,524287,R+1,a,1,-2);
		}
	}
	
}

Measured memory_bytes: 11604
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n;
    int x[100010];
    int ans = 10001000;

    cin >> n;

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

    sort(x, x+n);

    for (int i = x[0]; i <= x[n-1]; i++) {
        int tmp = 0;
        for (int j = 0; j < n; j++) {
            tmp += pow(x[j] - i, 2);
        }
        if (ans > tmp) {
            ans = tmp;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int X, ans = 1;
	ll n = 1;

	cin >> X;

	while (n < X) {
		ans++;
		n += ans;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define TRUE 1
#define FALSE 0
#define MAX 1000 

int top,S[MAX];
char s[MAX];

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int main(){
  int a,b;
  
  while( scanf("%s",s) != EOF ){
    if ( s[0] == '+' ){
      b=pop();
      a=pop();
      push(a+b);      
    } else if ( s[0] == '-' ){
      b=pop();
      a=pop();
      push(a-b);      
    } else if ( s[0] == '*' ){ 
      b=pop();
      a=pop();
      push(a*b);	
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  
  return 0;
}
void initialize(void){
  top=0;
}
 
int isEmpty(void){
  if(top==0)
    return TRUE;
  else
    return FALSE;
}
int isFull(void){
  if(top>=MAX-1)
    return TRUE;
  else
    return FALSE;
}
void push(int x){
  if(isFull()){
    fprintf(stderr,"Overflow!!\n");
    exit(8);
  }
  else{
    top++;
    S[top]=x;
  }
}
int pop(void){
  if(isEmpty()){
    fprintf(stderr,"Underflow!!\n");
    exit(8);
  }
  else{
    top--;  
    return S[top+1];
  }
}

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

int main(void) {

	int N = 0;
	std::cin >> N;

	int M = 0;
	std::cin >> M;

	std::vector<int> S(M);
	std::vector<int> c(M);

	for (int i = 0; i < M; i++) {
		std::cin >> S[i] >> c[i];

	}

	int answer = -1;
	bool ok = true;

	if (N == 1) {
		for (int i = 9; i >= 0; i--) {
			for (int m = 0; m < M; m++) {
				
				int check = i;
				if (check != c[m]) {
					ok = false;
				}
			}
			if (ok == true) {
				answer = i;
			}
			ok = true;
		}
	}

	else if (N == 2) {
		for (int i = 99; i >= 10; i--) {
			for (int m = 0; m < M; m++) {

				if (S[m] == 1) {
					int check = i / 10;
					if (check != c[m]) {
						ok = false;
					}
				}		
				
				else if (S[m] == 2) {
					int check = i % 10;
					if (check != c[m]) {
						ok = false;
					}
				}
			}

			if (ok == true) {
				answer = i;
			}
			ok = true;
		}
	}

	else if (N == 3) {
		for (int i = 999; i >= 100; i--) {

			for (int m = 0; m < M; m++) {

				if (S[m] == 1) {
					int check = i / 10 / 10;
					if (check != c[m]) {
						ok = false;
					}
				}
				
				else if (S[m] == 2) {
					int check = i / 10 % 10;
					if (check != c[m]) {
						ok = false;
					}
				}
				
				else if (S[m] == 3) {
					int check = i % 10;
					if (check != c[m]) {
						ok = false;
					}
				}
			}

			if (ok == true) {
				//std::cout << answer << std::endl;
				answer = i;
			}
			ok = true;
		}
	}

	std::cout << answer;

	return 0;
}

Measured memory_bytes: 256
s = input().strip()
n = len(s)
D = {chr(i):[] for i in range(97,123)}
for i in range(97,123):
    for j in range(n):
        if s[j]==chr(i):
            D[chr(i)].append(j)
cntmin = 1000
for i in range(97,123):
    if len(D[chr(i)])==1:
        d = D[chr(i)][0]
        cntmin = min(cntmin,max(d,n-1-d))
    elif len(D[chr(i)])>1:
        A = []
        for j in range(len(D[chr(i)])):
            if j==0:
                A.append(D[chr(i)][0])
            if j<len(D[chr(i)])-1:
                A.append(D[chr(i)][j+1]-D[chr(i)][j]-1)
        A.append(n-1-D[chr(i)][-1])
        cntmin = min(cntmin,max(A))
print(cntmin)

Measured memory_bytes: 38512
/*
平面上に N 個の点があり、それぞれ 0 から N−1 までの番号が付けられており、
それぞれの点について x 座標と y 座標が与えられています。
その N 点のうち 2 点を選び結んで得られる線分のうち、最も長くなる線分の長さを求めてください。
*/
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;
	
    bool flag = true;
    for (int i = 0; i < s.length(); ++i) {
        for (int k = 0; k < s.length(); ++k) {
        	if (s[i] == s[k] & i!=k){
        	    flag = false;
        	    break;
        	};
        }
    }
    if (flag) cout <<"yes" << endl;
    else cout <<"no" << endl;
}

Measured memory_bytes: 256
R,G,B,N = map(int,input().split())
count = 0

r = N //R


for i in range(r+1):
    M = N - R * i
    g = M // G
    for j in range(g+1):
        O = M - G * j
        if O % B == 0:
            count += 1

print(count)

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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll INF = 1LL << 60;

int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  printf("%d %d %d %d", c-d+b,d+c-a,a-d+b,c+b-a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  ll A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if (V <= W){
    cout << "NO" << endl;
    return 0;
  }
  ll len = abs(A-B);
  ll v = V-W;
  if (len <= v*T) cout << "YES" << endl;
  else cout << "NO" << endl;
}



Measured memory_bytes: 3524
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());

    int64 ans = 1;
    int cnt = 0;
    for (int i=0; i<n-1; i++) {
        if (a[i] == a[i+1]) {
            ans *= a[i];
            i++;
            cnt++;
        }
        if (cnt == 2) break;
    }
    if (cnt < 2) ans = 0;

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    if(s=="ABC"){
        cout<<"Yes"<<endl;
        return 0;
    }
    while(s.size()>3){
        char c;
        if(s.substr(0,3)=="ABC") c='A';
        else if(s.substr(s.size()-3,3)=="ABC") c='C';
        else c='B';
        string t;
        bool update=false,flag=true;
        rep(i,s.size()){
            if(s.substr(i,3)=="ABC") t+=c,update=true,i+=2;
            else{
                t+=s[i];if(s[i]==c) flag=false;
            }
        }
        if(t=="ABC"){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(!flag||!update&&t!="ABC"){
            cout<<"No"<<endl;
            return 0;
        }
        s=t;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3204
n = int(input())
n
ans = ''
st = 'abcdefghijklmnopqrstuvwxyz'
while n:
    idx = n%26
    if idx == 0:
        idx = 26
    ans += st[idx-1]
    if idx == 26:
        n-=26
    n//=26

print(ans[::-1])


Measured memory_bytes: 61820
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define fl(i,n) for(int i = 0;i<n;i++)
#define rfl(n) for(int i = n-1;i>=0;i--)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a)-1]
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
 
// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
 
//primes for hashing 937,991,1013,1409,1741
 
//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
/* Long Long Int */
#define int long long int
vector<vector<int> > v,z;
int m(int a,int b,int c)
{std::vector<int> x;
    x.pb(a);x.pb(b);x.pb(c);
    return *max_element(all(x));
    
}
int dp(int n,int a)
{
if(z[n][a]==-1)
    if(a==0)
    z[n][a]=m(dp(n-1,1),dp(n-1,2),-1)+v[n][a];
    else if(a==1)
    z[n][a]=m(dp(n-1,0),dp(n-1,2),-1)+v[n][a];
    else if(a==2)
    z[n][a]=m(dp(n-1,1),dp(n-1,0),-1)+v[n][a];
return z[n][a];
}

void solve()
{ 
int n;
cin>>n;

fl(i,n)
{std::vector<int> s;
    fl(j,3)
    {
        int k;cin>>k;
        s.pb(k);
    }
    v.pb(s);
}
z.resize(n);
fl(i,n)
{
    z[i].resize(3);
    fill(all(z[i]),-1);
}
fl(i,3)
z[0][i]=v[0][i];
int ans=m(dp(n-1,0),dp(n-1,1),dp(n-1,2));
cout<<ans;

return;
}

 
signed main()
{
    FAST
    
    
    int t = 1;
//cin>>t;
    while(t--) 
    solve();
    
 
return 0;
}   







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

int main() {
  string n, a, b;
  cin >> a >> b;
  n = a + b;
  int nm = stoi(n);
  bool ans = false;
  for (int i=1; i<1001; i++) {
    if (nm == i*i) ans = true;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
l=[int(input()) for i in range(n)]
#print(l)
a=0
for i in range(n):
    if l[i]%2==1:
        print('first')
        exit()
    a+=l[i]
    a%=2
if a==1:
    print('first')
else:
    print('second')

Measured memory_bytes: 7072
import java.util.Scanner;
public class Main{
	public static void swap(int n[], int a, int b)
	{
		int tmp = n[a-1];
		n[a-1] = n[b-1];
		n[b-1] = tmp;
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int num[] = new int[w];
		for(int i = 1 ; i <= w ; i++)
			num[i-1] = i;
		int n = sc.nextInt();
		for(int i = 0 ; i < n ; i++)
		{
			String str = sc.next();
			String[] str2 = str.split(",");
			int a = Integer.parseInt(str2[0]);
			int b = Integer.parseInt(str2[1]);
			swap(num,a,b);
		}
		for(int i = 0 ; i < w ; i++)
			System.out.println(num[i]);
	}
}


Measured memory_bytes: 26212
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

vector<ll> G[10000];
vector<bool> seen;
map<pair<ll, ll>, bool> seenmp;
vector<ll> ansidx;

ll res = 0;

void dfs(priority_queue<ll> &ans, ll idx, ll value) {
    ansidx[idx] = value;
    seen[idx] = true;
    for (int i = 0; i < G[idx].size(); ++i) {
        pair<ll, ll> p = make_pair(min<ll>(idx, G[idx][i]), max<ll>(idx, G[idx][i]));

        if (!seenmp[p]) {
            seenmp[p] = true;
            ll tmp = ans.top();
            ans.pop();
            res += min(ansidx[idx], tmp);
            if (!seen[G[idx][i]]) dfs(ans, G[idx][i], tmp);
        }
    }
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl();
        rep(i, n - 1) {
            ll a, b;
            cin >> a >> b;
            a--, b--;
            G[a].eb(b);
            G[b].eb(a);
        }
        priority_queue<ll> c;
        rep(i, n) c.push(inl());


        seen.resize(n, false);
        ansidx.resize(n);
        ll tmp = c.top();
        c.pop();
        dfs(c, 0, tmp);

        cout << res << endl;
        rep(i, n) {
            cout << ansidx[i] << " ";
        }

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

using namespace std;


int main() {
	string s;

	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if(s=="Rainy"){
		cout << "Sunny" << endl;
	}
	else {
		cout << "Rainy" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	ll A,B,C,K;

	scanf("%lld %lld %lld %lld",&A,&B,&C,&K);

	if(A >= K){

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

	ll ans = A;
	K -= A;

	if(B >= K){

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

	K -= B;

	ans -= K;

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3812
n,m = map(int,input().split())
h = list(map(int, input().split()))
h.insert(0, 0) #0-indexedを1-indexedにする 
ma = [0] * (n+1) # 0-indexedを1-indexedにする

for i in range(m):
    a,b = map(int, input().split())
    ma[a] = max(ma[a], h[b])
    ma[b] = max(ma[b], h[a])
# print(ma)
ans = 0
for i in range(1, n+1): # 1-indexed
    if h[i] > ma[i]:
        ans += 1
print(ans)

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

using namespace std;

#define ll long long
const int nmax=100000;
int n,v[nmax+5];
int nr;
string a;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        v[i]=-1;
    cout<<"0\n";
    cin>>a;
    if(a=="Vacant")
        return 0;
    if(a=="Female")
        nr=1;
    else
        nr=0;
    int r=0,pas=(1<<20);
    while(pas)
    {
        if(r+pas<n)
        {
            cout<<r+pas<<"\n";
            cin>>a;
            if(a=="Vacant")
                return 0;
            int aux=0;
            if(a=="Female")
                aux=1;
            else
                aux=0;
            if((aux+r+pas)%2==nr)
                r+=pas;
        }
        pas/=2;
    }
    return 0;
}
/**

**/


Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P std::pair<int,int>
#define double long double
#define prique priority_queue<int,vector<int>,greater<int>>
#define INF LLONG_MAX/3
#define inf INT_MAX/3
#define moder 100000
typedef long long ll;
using namespace std;
vector<int> vec[100010];
int n,m,p[100010],y[100010];
signed main() {
	cin>>n>>m;
	rep(i,m){
		cin>>p[i]>>y[i];
		vec[p[i]].push_back(y[i]);
	}
	for(int i=1;i<=n;i++){
		sort(vec[i].begin(),vec[i].end());
	}
	rep(i,m){
		auto a=lower_bound(vec[p[i]].begin(),vec[p[i]].end(),y[i]);
		string s=to_string(p[i]);
		string t=to_string(a-vec[p[i]].begin()+1);
		rep(i,6-s.size())cout<<"0";
		cout<<s;
		rep(i,6-t.size())cout<<"0";
		cout<<t<<endl;
	}
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << p.st << ' ' << p.nd; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 200100;
int n, m, use[N], inv[N], p[N];
pair<int, int> e[N];
vector <pair<int, int> > v[N];

void dfs(int node, int top_edge) {
	use[node] = 1;
	for(auto i : v[node]) {
		if(!use[i.st])
			dfs(i.st, i.nd);
		if(inv[i.nd])
		p[node]++;
	}

	if(p[node] % 2) 
		inv[top_edge] = 1;
	// assert(top_edge == 0 && p[node] % 2);
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	
	if(m % 2) return cout << "-1\n", 0;
	
	for(int i = 1; i <= m; i++) {
		cin >> e[i].st >> e[i].nd;
		
		p[e[i].st]++;
		v[e[i].st].push_back({e[i].nd, i});
		v[e[i].nd].push_back({e[i].st, i});
	}


	dfs(1, -1);

	for(int i = 1; i <= m; i++) {
		if(inv[i]) swap(e[i].st, e[i].nd);
		cout << e[i] << '\n';
	}
}	

	

Measured memory_bytes: 17408
X = int(input())

if X<600:
	print('8')
elif X<800:
	print('7')
elif X<1000:
	print('6')
elif X<1200:
	print('5')
elif X<1400:
	print('4')
elif X<1600:
	print('3')
elif X<1800:
	print('2')
elif X<2000:
	print('1')

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n;
     cin>>n;
     map<string,int>mp;
    for(int i=0;i<n;i++)
      {
         string str;
         cin>>str;
         mp[str]++;
      }
      cout<< "AC"<<" x "<<mp["AC"]<<endl;
      cout<< "WA"<<" x "<<mp["WA"]<<endl;
      cout<< "TLE"<<" x "<<mp["TLE"]<<endl;
      cout<< "RE"<<" x "<<mp["RE"]<<endl;

   return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
	int i,j,k,tmp;
	int ym[10001]={0};
	for(i=0;i<10;i++)scanf("%d",&ym[i]);
	for(i=0;i<10;i++){
		for(j=i+1;j<10;j++){
			if(ym[i]<ym[j]){
				tmp=ym[i];
				ym[i]=ym[j];
				ym[j]=tmp;
			}
		}
	}
	for(k=0;k<3;k++)printf("%d\n",ym[k]);
	return 0;
}


Measured memory_bytes: 1992
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define input freopen("input.txt", "r", stdin);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin>>s>>t;
    int mx=0;
    for(int i=0; i<=s.size()-t.size(); i++){
        int k=i, cnt=0;
        for(int j=0; j<t.size(); j++){
            if(s[k]==t[j]) cnt++;
            k++;
        }
        mx = max(mx, cnt);
    }
    int ans = t.size() - mx;
    cout<<ans;
}







Measured memory_bytes: 3636
n, m = map(int, input().split())

acline = [0]*n
wanum = [0]*n

for i in range(m):
    num, acwa = map(str, input().split())
    
    num = int(num) -1
    
    if acwa == "AC":
        acline[num] = 1
    else:
        if acline[num] == 1:
            continue
        else:
            wanum[num] += 1
            
for j in range(n):
    if acline[j] == 0:
        wanum[j] = 0
            
print(sum(acline), sum(wanum))

Measured memory_bytes: 4596
n,T = [int(x) for x in input().split()]
ct = []
for _ in range(n):
    c,t = [int(x) for x in input().split()]
    ct.append([c,t])

ans = 10000
for i in range(n):
    if ct[i][1] > T:
        pass
    else:
        ans = min(ct[i][0],ans)

if ans == 10000:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
    cin >> vec[i];
    }
    int a = 0;
    int j = 0;
    bool s = true;
    while(s){
        if(vec[j] % 2 == 0){
            vec[j] /= 2;
        }else{
            s = false;
        }
        if(j == N-1 && s == true){
            j = 0;
            a += 1;
        }else if (s == true){
            j++;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;


signed main() {
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;


    return 0;
}

Measured memory_bytes: 3624
N = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

S = [0]*N
S[0] = 1
for s in range(1,N-1):
    S[s] = S[s-1]*(s+1)

def where(r):
    R = len(r)
    L = [0]*N
    now = 0
    for i in range(R):
        now += (r[i]-1-sum(L[0:r[i]]))*S[N-i-2]
        L[r[i]-1] = 1
    return now

a = where(p)
b = where(q)

print(abs(a-b))

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007

void solve()
{
	string s1,s2,ans;
	cin>>s1>>s2;
	ll l1=s1.length();
	ll l2=s2.length();
	ll dp[l1+1][l2+1];
	memset(dp,0,sizeof(dp));
	for(ll i=1;i<=l1;i++)
	{
		for(ll j=1;j<=l2;j++)
		{
			if(s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
			else                 dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	//cout<<dp[l1][l2];
	ll i=l1,j=l2;
	while(i>0 && j>0)
	{
		if(s1[i-1]==s2[j-1])
		{
			ans+=s1[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]) i--;		
		else                           j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}
/*
abcdaf
acbcf
*/

Measured memory_bytes: 70784
#include<stdio.h>
int main(void)
{
        int n,i;
        char a[101];
        scanf("%d",&n);
        for(i=0;i<n;i++) scanf("%c",&a[i]);
        i=0;
        while(i!=n){
                if(a[i]=='Y'){
                        printf("Four\n");
                        return 0;
                }
                i++;
        }
        printf("Three\n");
        return 0;
}


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

using namespace std;

int main()
{
    long long n,m,ans;
    cin >> n >> m;
    for(long long i = m ; i > 0 ; i --){
        if(n * i <= m && m % i == 0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n;
int cnt[100001];
const int MOD=1e9+7;

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

	cin>>n;
	REP(i,n) {
		int a; cin>>a; cnt[a]++;
	}
	bool flg=true;
	if(n&1) {
		if(cnt[0]!=1) {
			flg=false;
		}
		else {
			for(int i=2;i<=n;i+=2) {
				if(cnt[i]!=2) {
					flg=false;break;
				}
			}
		}
	}
	else {
		for(int i=1;i<=n;i+=2) {
			if(cnt[i]!=2) {
				flg=false;break;
			}
		}
	}

	if(flg) cout<<mypow(2,(n/2),MOD)<<endl;
	else cout<<0<<endl;

	return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String[] n = sc.next().split("");
		int sum = Arrays.stream(n)
				.mapToInt(Integer::parseInt)
				.sum();
		System.out.println(sum == 1 ? 10 : sum);
	}
}

Measured memory_bytes: 26704
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

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

int N, L;
int icicle[100002];
int dp[100002];

int solve_rec(int p)
{
	if(dp[p] != 0)
		return dp[p];
	
	int res = L - icicle[p];
	int left = 0, right = 0;
	
	if(p < N+1 && icicle[p] < icicle[p+1])
	{
		right = solve_rec(p+1);
	}
	
	if(p > 0 && icicle[p] < icicle[p-1])
	{
		left = solve_rec(p-1);
	}
	
	res += max(left, right);

	dp[p] = res;
	return res;
}
int solve()
{
	int res = 0;
	
	FOR(i, 0, N)
	{
		res = max(solve_rec(i), res);
	}
	
	return res;
}

int main()
{
	cin >> N >> L;
	CLR(icicle);
	CLR(dp);
	FOR(i, 0, N)
	{
		cin >> icicle[i];
	}
	cout << solve() << endl;
		
	return 0;
}

Measured memory_bytes: 4288
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str;
	int sum=0;
	float n=0,ave=0,j=1f;

	while((str=input.readLine())!=null)
	    {
		String str_ary[]=str.split(",");
		int a[]=new int[2];
		
		for(int i=0;i<2;i++)
		    {
			a[i]=Integer.parseInt(str_ary[i]);
		    }
		sum+=a[0]*a[1];
		n+=a[1];
		ave=n/j;
		if(ave%1>0.4)ave++;
		
		j++;
	    }
	System.out.println(sum+"\n"+(int)(ave));
    }
}

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

int main()
{
    long n, res, tmp, k;
    std::vector<int> h;

    std::cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        std::cin >> tmp;
        h.push_back(tmp);
    }
    std::sort(h.begin(), h.end());
    for (int i = 0; i < n - k; i++)
    {
        res += h[i];
    }

    std::cout << res << std::endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int X,A;
cin>>X>>A;
if(X<A){
  cout<<0<<"\n";
}
else{
  cout<<10<<"\n";
}
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll dp[maxn][5];

int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    repd(i,2,n)
    {
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}


Measured memory_bytes: 14592
ABCD = input()
a, b, c, d = map(int, list(ABCD))
if a + b + c + d == 7:
  print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7")
elif a + b + c - d == 7:
  print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")
elif a + b - c + d == 7:
  print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")
elif a - b + c + d == 7:
  print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")  
elif a + b - c - d == 7:
  print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")  
elif a - b + c - d == 7:
  print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")  
elif a - b - c + d == 7:
  print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7")  
elif a - b - c - d == 7:
  print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")


Measured memory_bytes: 9140