akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main(){
  int N;
  cin>>N;
  long A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A, A + SIZE_OF_ARRAY(A));
  int flag=1;
  for(int i=0;i<N-1;i++){
    if(A[i]==A[i+1]){
      flag=0;
      break;
    }
  }
  if(flag==1){
    cout<<"YES";
  }else{
    cout<<"NO";
  }
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int a,b;
  cin >> a >> b;
  if(a==1 || b==1)
  {
    if(a==1 && b==1)
      cout << "Draw" << endl;
    else if(a==1 && b!=1)
      cout << "Alice" << endl;
    else if(a!=1 && b==1)
      cout << "Bob" << endl;
  }
  else
  {
    if(a>b)
      cout << "Alice" << endl;
    else if (b>a)
      cout << "Bob" << endl;
    else
      cout << "Draw" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// Tazoe

#include <iostream>
#include <string>
using namespace std;

void roll01(int c[6])
{
	int tmp = c[0];
	c[0] = c[1];
	c[1] = c[5];
	c[5] = c[4];
	c[4] = tmp;
}

void roll02(int c[6])
{
	int tmp = c[0];
	c[0] = c[2];
	c[2] = c[5];
	c[5] = c[3];
	c[3] = tmp;
}

void roll12(int c[6])
{
	int tmp = c[1];
	c[1] = c[2];
	c[2] = c[4];
	c[4] = c[3];
	c[3] = tmp;
}

void rotate(int c[6])
{
	if(c[0]==1){
		;
	}
	else if(c[1]==1){
		roll01(c);
	}
	else if(c[2]==1){
		roll02(c);
	}
	else if(c[3]==1){
		roll02(c);
		roll02(c);
		roll02(c);
	}
	else if(c[4]==1){
		roll01(c);
		roll01(c);
		roll01(c);
	}
	else if(c[5]==1){
		roll02(c);
		roll02(c);
	}

	if(c[1]==2){
		;
	}
	else if(c[2]==2){
		roll12(c);
	}
	else if(c[4]==2){
		roll12(c);
		roll12(c);
	}
	else if(c[3]==2){
		roll12(c);
		roll12(c);
		roll12(c);
	}
	else if(c[1]==3){
		;
	}
	else if(c[2]==3){
		roll12(c);
	}
	else if(c[4]==3){
		roll12(c);
		roll12(c);
	}
	else if(c[3]==3){
		roll12(c);
		roll12(c);
		roll12(c);
	}
}

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

		if(n==0)
			break;

		int C[30][6];
		for(int i=0; i<n; i++){
			for(int j=0; j<6; j++){
				string str;
				cin >> str;

				if(str=="Red")
					C[i][j] = 1;
				else if(str=="Yellow")
					C[i][j] = 2;
				else if(str=="Blue")
					C[i][j] = 3;
				else if(str=="Magenta")
					C[i][j] = 4;
				else if(str=="Green")
					C[i][j] = 5;
				else if(str=="Cyan")
					C[i][j] = 6;
			}
		}

		for(int i=0; i<n; i++){
			rotate(C[i]);
		}

		for(int i=0; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				if(C[i][1]>C[j][1]
				 ||(C[i][1]==C[j][1]&&C[i][2]>C[j][2])
				 ||(C[i][1]==C[j][1]&&C[i][2]==C[j][2]&&C[i][3]>C[j][3])
				 ||(C[i][1]==C[j][1]&&C[i][2]==C[j][2]&&C[i][3]==C[j][3]&&C[i][4]>C[j][4])
				 ||(C[i][1]==C[j][1]&&C[i][2]==C[j][2]&&C[i][3]==C[j][3]&&C[i][4]==C[j][4]&&C[i][5]>C[j][5])){
					for(int k=0; k<6; k++){
						int tmp = C[i][k];
						C[i][k] = C[j][k];
						C[j][k] = tmp;
					}
				}
			}
		}

		int m = n;
		for(int i=1; i<n; i++){
			bool flg = true;
			for(int j=0; j<6; j++){
				if(C[i][j]!=C[i-1][j]){
					flg = false;
					break;
				}
			}

			if(flg){
				m--;
			}
		}

		cout << n-m << '\n';
	}

	return 0;
}

Measured memory_bytes: 0
X, Y = list(map(int, input().split()))

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
if (X + Y) % 3 != 0:
    print(0)
else:
    x = (2*Y-X) // 3
    y = (2 * X - Y) // 3
    total = x + y
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(total, x, p))

Measured memory_bytes: 127560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    vector<char> n(3);
    rep(i,3) cin>>n[i];
    rep(i,3){
        if(n[i] == '1') cout << '9';
        else cout << '1';
    }
    cout << endl;
    
    
    return 0;
}




Measured memory_bytes: 256
N = int(input())
p = list(input().split())
p = [int(p[i]) for i in range(N)]

p_sorted = sorted(p)
count = 0
for i in range(N):
    if p[i] != p_sorted[i]:
        count += 1

if count <= 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

#define MAX 100000

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);

    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);

    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);

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



Measured memory_bytes: 2052
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define inf 1ll<<60
#define ll long long 
#define ull unsigned long long
#define MAXN 1000005 

int n,m;
ll k;
ll a[MAXN],b[MAXN];
ll suma[MAXN],sumb[MAXN];
int l,r=1,ans=0;

int main()
{
	read(n),read(m),readl(k);
	l=n;
	suma[0]=sumb[0]=0;
	for(int i=1;i<=n;i++) readl(a[i]),suma[i]=suma[i-1]+a[i];
	for(int i=1;i<=m;i++) readl(b[i]),sumb[i]=sumb[i-1]+b[i];
	sumb[m+1]=1ll<<60;
	for(int i=n;i>=0;i--)
	{
		if(suma[i]>k) l--;
		else break; 
	}
	for(int i=l;i>=0;i--)
	{
		while(suma[i]+sumb[r]<=k) r++;
		r-=1;
		ans=max(ans,i+r);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 10080
N,K=input().split()
N=int(N)
K=int(K)
List = [[int(j) for j in input().split()] for i in range(2*K)]

A=[0]*N

for i in range(K):

  for j in range(0,List[i*2][0]):
    A[List[1+i*2][j]-1]+=1
print(A.count(0))

  
   
  
  

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int,int> pii;
const long long linf=1LL<<62;
const int iinf=1000000009;
const double dinf=1e17;
const int Mod=1e9+9;
typedef long long ll;
typedef long double ld;
const int maxn=1000005;
char s[maxn];
int n;
int a[100]={111,222,333,444,555,666,777,888,999,1111};
void solve(){
	iossy;
	cin>>n;
	For(i,0,9) 
		if(a[i]>=n) {cout<<a[i]<<endl;return ;}

}
int main(){
	int t=1;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 256
from collections import deque
import heapq

N,M,K,S = map(int,input().split())
# - N nodes, M edges, K zombie nodes
# - S本以下の道路を使って到達できる街 = 危険な街

P,Q = map(int,input().split())
# - P: not dangerous
# - Q: dangerous

C = []
for _ in range(K):
  C.append(int(input()))
# C[i] = zombie cities

# M rows
adj = [ [] for _ in range(N+1) ]
for _ in range(M):
  a,b = map(int,input().split())
  adj[a].append(b)
  adj[b].append(a)

expensive_cities = set()
for c in C:
  q = deque([c])
  step = 0
  visited = [False] * (N+1)

  while q and step <= S:
    l = len(q)
    new_q = deque()

    for _ in range(l):
      node = q.popleft()
      visited[node] = True

      for nei in adj[node]:
        if visited[nei]: continue
        if nei in q or nei in new_q: continue
        if nei in C: continue
        new_q.append(nei)
    
    q = new_q
    step += 1

  for i in range(1, N+1):
    if visited[i] and i not in C:
      expensive_cities.add(i)

# print(expensive_cities)

adj2 = [ [] for _ in range(N+1) ]
for i in range(1, N+1):
  for city in adj[i]:
    if city in C: continue
    if city in expensive_cities:
      adj2[i].append((city,Q))
    else:
      adj2[i].append((city,P))

# print(adj2)

pq = [(0,1)]
dist = [float('inf')] * (N+1)
visited = [False] * (N+1)
dist[1] = 0
while pq:
  d,n = heapq.heappop(pq)
  if n==N: break
  visited[n] = True

  for nei,nd in adj2[n]:
    # import pdb; pdb.set_trace()
    if visited[nei]: continue
    if d+nd < dist[nei]:
      dist[nei] = d+nd
      heapq.heappush(pq, (d+nd,nei))

# print(dist)
d = dist[N]
if N in expensive_cities:
  print(d-Q)
else:
  print(d-P)


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

const int N=4000005;
const long long MOD=1e9+7;
int n,k;
long long f[N],inv[N],p[N],ans=1;
char ch[N];

long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b%2) res=res*a%MOD;
		a=a*a%MOD,b/=2;
	}
	return res;
}

int main()
{
	scanf("%d%s",&n,ch),f[0]=p[0]=1;
	k=strlen(ch),n+=k;
	for(int i=1;i<=n;i++) f[i]=f[i-1]*i%MOD;
	inv[n]=ksm(f[n],MOD-2);
//	cout<<inv[n]*f[n]%MOD<<endl;
	for(int i=n;i>=1;i--) inv[i-1]=inv[i]*i%MOD;
	for(int i=1;i<=n;i++) p[i]=p[i-1]*25%MOD,ans=ans*26%MOD;
	for(int i=0;i<k;i++)
	{
		ans=(ans-f[n]*inv[i]%MOD*inv[n-i]%MOD*p[n-i]%MOD+MOD)%MOD;
//		cout<<i<<' '<<f[n]*inv[i]%MOD*inv[n-i]%MOD<<' '<<inv[i]<<' '<<inv[i]*f[i]%MOD<<endl;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 51664
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main(){
  int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1920
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val A = Array.fill(N)(BigInt(sc.nextLong()))

    def gcd(a: BigInt, b: BigInt): BigInt =
      if (a % b == 0L) b
      else gcd(b, a % b)

    def lcm(a: BigInt, b: BigInt): BigInt =
      a * (b / gcd(a, b))

    val LCM = A.reduce((a, b) => lcm(a, b)) - 1
    val r = A.foldLeft(BigInt(0))((b, n) => b + LCM % n)
    println(r)
  }

}


Measured memory_bytes: 49016
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int nmax = 2e5 + 10;
int n;
int a[nmax], b[nmax];
vector <int> a1, b1;
int main() {
    IO;
   
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    ll res = 0;
    for (int k = 0; k <= 29; k++) {
        int cnt = 0;
        int T = 1 << k;
        a1.clear(), b1.clear();
        for (int i = 0; i < n; i++) {
            a1.push_back(a[i] % (2 * T));
            b1.push_back(b[i] % (2 * T));
        }
        sort(all(b1));
        for (int i = 0; i < n; i++) {
            int l, r;
            l = lower_bound(all(b1), T - a1[i]) - b1.begin();
            r = lower_bound(all(b1), 2 * T - a1[i]) - b1.begin();
            cnt = (cnt + r - l) % 2;
            l = lower_bound(all(b1), 3 * T - a1[i]) - b1.begin();
            //r = lower_bound(all(b1), 4 * T - a1[i]) - b1.begin();
            cnt = (cnt + b1.size() - l) % 2;
        }
        if (cnt & 1) res += T;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3572
import heapq
n, m = map(int, input().split())

jobs = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        jobs[a].append(-b)

h = []
ans = 0
for i in range(1, m+1):
    for j in jobs[i]:
        heapq.heappush(h, j)
    if len(h) > 0:
        ans += -heapq.heappop(h)

print(ans)

Measured memory_bytes: 88632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
			out.println(2 * b == c + a ? "YES": "NO");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;
using  ull = unsigned long long int;

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


int main() {

	ull n;
	cin >> n;
	vector<ull>num(n);
	vector<ull>side;

	rep(i, 0, n)cin >> num[i];
	sort(num.begin(), num.end(), greater<ull>());

	ull tmp = -1;

	rep(i, 0, n) {
		if (tmp == num[i]) {
				side.push_back(num[i]);
				tmp = -1;
		}
		else tmp = num[i];
				
	}	
	
	if (2 <= side.size()) {
		cout << side[0] * side[1] << endl;
	}
	else cout << "0" << endl;
	

	return 0;
}

Measured memory_bytes: 1660
#include<iostream>
using namespace std;
int main()
{
	int sya=100000;
	int i;
	int n,a;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		sya *= 1.05;
		if (sya % 1000 > 0)
		{
			a = sya % 1000;
			sya = sya - a + 1000;
		}
	}
	cout << sya << endl;
	return 0;
}

Measured memory_bytes: 3040
import numpy as np

def judge(A, B):
    sum_A, sum_B = sum(A), sum(B)
    if sum_A < sum_B:
        return -1
    D = np.sort(np.array(A) - np.array(B))
    num = 0
    pid = D.argmax()
    nid = len(D[D < 0]) - 1
    pnew, nnew = True, True
    while nid >= 0:
        if D[pid] + D[nid] > 0:
            num += pnew + nnew
            D[pid] += D[nid]
            D[nid] = 0
            nid -= 1
            pnew, nnew = False, True
        elif D[pid] + D[nid] == 0:
            num += pnew + nnew
            D[pid] = 0
            D[nid] = 0
            pid -= 1
            nid -= 1
            pnew, nnew = True, True
        else:
            num += pnew + nnew
            D[nid] += D[pid]
            D[pid] = 0
            pid -= 1
            pnew, nnew = True, False
    return num

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(judge(A, B))

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

namespace contest_Csharp
{
    class Program
    {


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

            var vals = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();

            var N = vals[0];
            var A = Console.ReadLine().Split(' ')
                .Select(x => long.Parse(x)).ToList();
            var ans = 0L;
            //var flg = true;

            long sum = A.Sum();
            long used=0;

            long Maxwidth = 1;

            for (int i = 0; i < N+1; i++)
            {
                if (Maxwidth-A[i]<0)
                {
                    ans = -1;
                    break;
                }
                ans += Maxwidth;

                used += A[i];
                Maxwidth -= A[i];
                
                Maxwidth = Math.Min(Maxwidth * 2, sum - used);

            }



            Console.WriteLine(ans);
            Console.Out.Flush();

        }



    }

}


Measured memory_bytes: 38408
program irreversible_operation
  implicit none
  character(200000) :: s
  integer :: n, i, m = 0
  integer(8) :: x = 0_8
  read(*,*) s
  n = len_trim(s)
  do i = n, 1, -1
    if (s(i:i) == "W") cycle
    x = x+int(n-i-m,8)
    m = m+1
  end do
  write(*,'(i0)') x
end program irreversible_operation

Measured memory_bytes: 1084
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
  int main(){
  int K;
  int A,B;
  cin >> K;
  cin >> A >> B;
  int count = A;
  rep(i,B-A+1){
    if(count%K == 0){
      cout << "OK" <<endl;
      break;
    }
    count++;
    if(count > B){
      cout << "NG" <<endl;
      break;
    }
  }
  
}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
int E;

int main(){

  while(cin >> E){
    if ( E == 0) break;
    int min = 100000001; 
    for (int z = 0; z*z*z < E + 1; ++z){
      for (int y = 0; y*y < E - z*z*z + 1 ; ++y){
        int x = E - z*z*z - y*y;
        if( x + y + z < min ) min = x + y + z ;
      }
    }
    cout << min << endl;
  }
return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n,m;
    cin>>n>>m;
    int freq[n+1];
    rep(i,0,n)freq[i]=0;
	rep(i,0,m){
		int a,b;
		cin>>a>>b;
		freq[a-1]++;
		freq[b]--;
	}
	int cnt=0;
	rep(i,0,n){
		if(freq[i]==m)cnt++;
		freq[i+1]+=freq[i];
	}
	cout<<cnt<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    long x, a, b;

	cin >> x;
	cin >> a;
	cin >> b;

	x -= a;

	Out(x % b);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define trav(a, x) for(auto& a : x)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin >> n;
    string s[3];
    rep(i,0,3) cin >> s[i];

    int ans=0;
    rep(i,0,n){
        int x=0;
        rep(j,0,3){
            rep(k,0,j){
                if(s[j][i]==s[k][i]) x++;
            }
        }
        if(x==0) ans+=2;
        else if(x==1) ans+=1;
    }

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


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  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;
  }
};
 
struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

LL N,K;
LL A[100000];

mint ans = 0;
 
void solve(){
	if(K==1) return;
	sort(A,A+N);//昇順
	combination c(N);
	for(int i=0;i<N-K+1;i++){
		mint comb = c(N-1-i,K-1);
		mint A_max = A[N-1-i];
		mint A_min = A[i];
		A_max = A_max*comb;
		A_min = A_min*comb;
		ans = (ans+A_max);
		ans = (ans-A_min);
	}
}
 
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++) cin >> A[i];
 
	solve();

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

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

using namespace std;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    ll arr[n] = {0};
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        ll j = 1;
        ll a = i * j;
        while (a <= n)
        {
            arr[a - 1]++;
            j++;
            a = i * j;
        }
    }
    for (ll i = 0; i < n; i++)
    {
        ans += (arr[i] * (i + 1));
    }
    cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n;
    map<string, int> a;
    rep(i, n)
    {
        string s;
        cin >> s;
        a[s]++;
    }
    int count = 0;
    for (auto p : a)
    {
        if (p.second % 2 == 1)
            count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 11408
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;

const int MAX_V = 370;
using Capacity = int;
using Cost = long long;
const auto inf = numeric_limits<Capacity>::max() / 8;

struct Edge {
	int dst;
	Capacity cap, cap_orig;
	Cost cost;
	int revEdge; bool isRev;
	Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
		:dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {
	}
};

struct PrimalDual {
	int n;
	vector<vector<Edge> > g;
	PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(int src, int dst, Capacity cap, Cost cost) { // テヲツ慊嘉・ツ青妥ィツセツコ
		g[src].emplace_back(dst, cap, cost, g[dst].size(), false);
		g[dst].emplace_back(src, 0, -cost, g[src].size() - 1, true);
	}
	Cost solve(int s, int t, int f) {
		Cost res = 0;
		static Cost h[MAX_V], dist[MAX_V];
		static int prevv[MAX_V], preve[MAX_V];
		for(int i = 0; i < n; i++) {
			h[i] = 0;
		}
		while(f > 0) {
			typedef pair<Cost, int> pcv;
			priority_queue<pcv, vector<pcv>, greater<pcv> > q;
			for(int i = 0; i < n; i++) {
				dist[i] = inf;
			}
			dist[s] = 0;
			q.emplace(pcv(0, s));
			while(q.size()) {
				pcv p = q.top(); q.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i = 0; i < g[v].size(); i++) {
					Edge &e = g[v][i];
					if(e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
						dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
						prevv[e.dst] = v;
						preve[e.dst] = i;
						q.emplace(pcv(dist[e.dst], e.dst));
					}
				}
			}
			if(dist[t] == inf) {
				return -1;
			}
			for(int v = 0; v < n; v++) {
				h[v] += dist[v];
			}
			// s-t テゥツ鳴禿ヲツ慊?ァツ淞ュティツキツッテ」ツ?ォテヲツイツソテ」ツ?」テ」ツ?ヲテァツ崢ョテ、ツクツ?ヲツ敖ッテヲツオツ?」ツ??
			int d = f;
			for(int v = t; v != s; v = prevv[v]) {
				d = min(d, g[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.revEdge].cap += d;
			}
		}
		return res;
	}
	// テヲツオツ?」ツつ古」ツ?淌」ツδ陛」ツδュテ」ツδシ=テ・ツ?ε」ツ??」ツ?ョテ・ツョツケテゥツ??テァツ渉セテ・ツ慊ィテ」ツ?ョテ・ツョツケテゥツ?湘」ツつ津ィツ。ツィテァツ、ツコ
	void view() {
		for(int i = 0; i < g.size(); i++) {
			for(int j = 0; j < g[i].size(); j++) {
				if(!g[i][j].isRev) {
					Edge& e = g[i][j];
					printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
				}
			}
		}
	}
};

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

	int n;
	while(cin >> n, n) {
		PrimalDual pd(370);

		for(int i = 0; i <= 365; i++) {
			pd.add_edge(i, i + 1, 2, 0);
		}
		for(int i = 0; i < n; i++) {
			int x, y, w;
			cin >> x >> y >> w;
			pd.add_edge(x, y + 1, 1, -w);
		}

		cout << -pd.solve(1, 366, 2) << endl;
	}
}

Measured memory_bytes: 3284
import java.util.Scanner;

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

        int h = x / (60 * 60);
        int m = (x - h*60*60) / 60;
        int s = (x - h*60*60 - m*60);

        System.out.println(h + ":" + m + ":" + s);
    }
}



Measured memory_bytes: 26388
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = int_fast64_t;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,x;
    cin >> n >> x;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    int cnt = 0;
    REP(i,0,n) {
        x -= a[i];
        if (x >= 0) ++cnt;
        else break;
    }
    if (x > 0) --cnt;
    cout << cnt << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
 
int main() {
  
 string s;  
  cin >> s; 
  int f=  0 ; 
  for (int i = 0; i < s.size() ; i ++ )
    if ( s[i] == '7' )
    {
      f = 1 ; 
      break ; 
    }
  if ( f == 1 )
    	cout << "Yes" << endl; 
 	else 
      	cout << "No" << endl ; 
  
}
  

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int x, a, b;
  cin >> x >> a >> b;
  if(abs(a-x)<abs(b-x)){
    prt("A");
  } else {
    prt("B");
  }
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int c=0;
	int ins=a[0];
	int ans=0;
	for(i=0;i<n;i++)
	{
		if(a[i]==ins)
		{
			c++;
		}
		else
		{
			ans+=c/2;
			c=0;
			ins=a[i];
			i--;
		}
	}
	ans+=c/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
a, b, n = map(int, input().split())

temp_prev = 0
temp_curr = 0
x = min(n, b-1)

while x <= n:
    temp_prev = temp_curr
    temp_curr = int(a * x / b) - a * int(x / b)
    x += 1.0

    if temp_curr <= temp_prev:
        break

print(max(temp_curr, temp_prev))

Measured memory_bytes: 9052
#include <stdio.h>

int main(void)
{
    int a, b;

    scanf("%d %d", &a, &b);

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
        printf("Possible\n");
    }
    else {
        printf("Impossible\n");
    }
    return (0);
}

Measured memory_bytes: 128
def solve():
  while True:
    m, n  = int(input()), int(input())
    if not m:
      break
    ices = [[0] + list(map(int,input().split())) + [0] for _ in range(n)]
    ices.insert(0, [0] * (m + 2),)
    ices.append([0] * (m + 2))
#    score = [[0] * (m + 2) for _ in range(n + 2)]
#    
#    for x in range(1, n + 1):
#      for y in range(1, m + 1):
#        if ices[x][y]:
#          score[x][y] += (ices[x - 1][y] + ices[x + 1][y] + ices[x][y - 1] + ices[x][y + 1])
    
    def bfs(x, y, imap, acc):
      imap[x][y] = 0
      acc += 1
      a = b = c = d = 0
      if imap[x - 1][y]:
        a = bfs(x - 1, y, imap, acc)
      if imap[x + 1][y]:
        b = bfs(x + 1, y, imap, acc)
      if imap[x][y - 1]:
        c = bfs(x, y - 1, imap, acc)
      if imap[x][y + 1]:
        d = bfs(x, y + 1, imap, acc)
      imap[x][y] = 1
      return max(acc, a, b, c, d)
    
    ans = 0
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        #if score[x][y] in [1, 2] and ices[x][y]:
        if ices[x][y]:
          a = bfs(x, y, ices, 0)
          if ans < a:
            ans = a
    
    print(ans)

solve()


Measured memory_bytes: 5676
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let r: i64 = buf.trim_right().parse().unwrap();
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let g: i64 = buf.trim_right().parse().unwrap();
    writeln!(output, "{}", g * 2 - r).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "2002
2017
\n",
            "2032\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "4500
0
\n",
            "-4500\n",
        );
    }
}


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

int main()
{
 int n, s; cin >> n >> s;
 vector<int> v(n+1, 0); int penalties = 0; int  corrects = 0;
 vector<int> wrongs(n+1, 0);
  while(s--)
  {
    int id; string res; cin >> id >> res;
    if(res == "WA")
    {
      if(v[id] == 0) wrongs[id]++;
    }
    else
    {
      
      if(v[id] == 0)
          ++corrects;
        v[id] = 1;
    }
  }
  for(int i = 1; i <= n; ++i)
    if(v[i]) penalties += wrongs[i];
  cout << corrects << " " << penalties;
  
  return 0;
}


Measured memory_bytes: 4040
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    size_t n=G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s]=0;
    Q.emplace(0,s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> v(h+2, vector<int>(w+2, -1));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> v[i+1][j+1];
        }
    }
    int n = h*w;
    vector<vector<edge<ll>>> G(n*n+n);
    auto f = [&n, &w](int i, int j, int k){ return i*(n+1)*w+j*(n+1)+k; };
    array<int, 4> dy{0, 0, -1, 1}, dx{1, -1, 0, 0};
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            for (int k = 0; k < 4; ++k) {
                if(v[i+dy[k]+1][j+dx[k]+1] != -1){
                    for (int l = 0; l < n; ++l) {
                        G[f(i, j, l)].emplace_back(
                                f(i+dy[k], j+dx[k], l+1),
                                (2*l+1)*v[i+dy[k]+1][j+dx[k]+1]);
                    }
                }
            }
        }
    }
    ll ans = INF<ll>;
    auto d = dijkstra(0, G);
    for (int i = 0; i <= n; ++i) {
        ans = min(ans, d[f(h-1, w-1, i)]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 95456
N = int(input())
ans = N
for i in range(N+1):
    cnt = 0
    t = i
    while t>0:
        cnt+=t%6
        t//=6
    j=N-i
    while j>0:
        cnt+=j%9
        j//=9
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
vector<ll> pickdiv(ll n){
    vector<ll> res;
    for(ll i=1; i*i <=n;i++){
        if(n%i)continue;
        res.emplace_back(i);
        ll q = n/i;
        if(q != i){
            res.emplace_back(q);
        }
    }
    return res;
}
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    ll m,M;
    if(N%2){
        m = A[N/2];
        M = B[N/2];
        cout << M - m + 1 << endl;
    }else{
        m = A[N/2] + A[N/2 - 1];
        M = B[N/2] + B[N/2 - 1];        
        cout << M - m + 1 << endl;
    }
}

Measured memory_bytes: 6428
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)

int main() {
  int n;
  cin >> n;
  
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int ans = 0;
  int val = 0;
  rep(i, h.size() - 1) {
    if (h[i] < h[i + 1]) {
      val = 0;
    } else {
      val += 1;
    }
    ans = max(ans, val);
  }

  cout << ans << endl;  
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	string s;
	cin>>s;
	int d,mins=1000;
	for(int i=0;i<(s.size()-2);i++){
		d=((s[i]-'0')*100)+((s[i+1]-'0')*10)+(s[i+2]-'0');
		mins=min(mins,(abs(d-753)));
	}
	cout<<mins;
}



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

int main()
{
    char c;
    std::cin >> c;
    if(std::isupper(c))
    {
        std::cout << "A" << std::endl;
    }
    else
    {
        std::cout << "a" << std::endl;
    }

    return 0;
}


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

using namespace std;
typedef long long int lli;
lli height[100005];
lli dp[100005];
lli n,k;
lli solve(lli i);

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	for (int i=0;i<100005;i++) height[i]=999999999;
	cin>>n>>k;
	for (int i=1;i<=n;i++) cin>>height[i];
	for (int i=1;i<=n;i++) dp[i]=-1;
	solve(1);
	cout<<dp[1]<<endl;
	
	return 0;
}

lli solve(lli i){
	if (i==n) return 0;
	if (dp[i]!=-1) return dp[i];
	dp[i]=999999999999;
	for (int j=1;j<=k;j++){
		dp[i]=min(dp[i],solve(i+j)+abs(height[i+j]-height[i]));
	}
	return dp[i];
}

Measured memory_bytes: 4992
#include <atcoder/math>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (N == 2) {
        cout << 3 << endl;
        return 0;
    }

    ll r = sqrt(N*2);

    ll t = N*2;
    vector<pair<ll, ll>> factor;
    for (ll i = 2; i <= r; i++) {
        if (t%i != 0) continue;
        ll p = i;
        ll pcnt = 0;
        while (t%p == 0) {
            t /= p;
            pcnt++;
        }
        factor.push_back({p, pcnt});
        if (i > t) break;
    }
    if (t != 1) factor.push_back({t, 1});

    int K = factor.size();
    vector<ll> factorpow(K, 1);
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < factor[i].second; j++) {
            factorpow[i] *= factor[i].first;
        }
    }

    ll ans = 1e18;
    for (int i = 1; i < (1<<K); i++) {
        vector<ll> r(K);
        for (int j = 0; j < K; j++) {
            if (i&(1<<j)) r[j] = factorpow[j]-1;
            else r[j] = 0;
        }
        pair<ll, ll> cand = atcoder::crt(r, factorpow);
        ans = min(ans, cand.first);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & -x)

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    int n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll> (n, 0));
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            cin >> a[i][j];
    vector<ll> cost(1 << n, 0);
    for(int mask = 1; mask < (1 << n); mask ++)
        for(int i = 0; i < n; i ++)
            if(mask & (1 << i))
                for(int j = i + 1; j < n; j ++)
                    if(mask & (1 << j))
                        cost[mask] += a[i][j];

    vector<ll> dp(1 << n, 0);
    for(int mask = 1; mask < (1 << n); mask ++)
        for(int submask = mask; submask; submask = ((submask - 1) & mask))
            dp[mask] = max(dp[mask], dp[mask - submask] + cost[submask]);
    cout << dp[(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 1280
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

N, L = list(map(int, input().split()))
apple = []

for i in range(1,N+1):
    apple.append(L + i - 1)
del apple[getNearestValue(apple, 0)]
print(sum(apple))

Measured memory_bytes: 12616
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        a: u64,
        b: u64,
    }
    match a * b % 2 {
        0 => println!("Even"),
        1 => println!("Odd"),
        _ => assert!(true),
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void)
{
	int a[3];
	int i;
	int min = 100;
	int max = 0;
	
	for (i=0;i < 3; i++){
		scanf("%d", &a[i]);
	}
	
	for (i=0;i<3;i++){
		if (min > a[i]){
			min = a[i];
		}
		if (max < a[i]){
			max = a[i];
		}
		
	}
	
	printf("%d", max - min);
	
	return 0;
}


Measured memory_bytes: 128
from math import gcd

MOD = 10**9+7
N = int(input())
d = {}
zero = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue

    flip = 0
    while not (a >= 0 and b > 0):
        a, b = -b, a
        flip ^= 1

    g = gcd(a, b)
    a //= g
    b //= g
    if not (a, b) in d:
        d[(a, b)] = [0, 0]
    d[(a, b)][flip] += 1

ans = 1
for (v1, v2) in d.values():
    ans *= pow(2, v1, MOD) + pow(2, v2, MOD)-1
    ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)


Measured memory_bytes: 137984
from copy import deepcopy
S = list(input())
N = len(S)
def judge(S):
    L = len(S)
    c = deepcopy(S)
    c.reverse()
    for i in range(L):
        if S[i] != c[i]:
            return False
    return True


a = S[:(N-1)//2]
b = S[(N+3)//2-1:]

j = judge(S) and judge(a) and judge(b)
if j:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 38256