akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/
#define int lld
const int N=2e5+5,P=1e9+7;

int fac[N],fnv[N];

int n,a,b,c;

int pw(int a,int m,int p){
    int res=1;
    while(m)m&1?res=1ll*res*a%p:0,a=1ll*a*a%p,m>>=1;
    return res;
}
int binom(int n,int m){
    if(n<m)return 0;
    return 1ll*fac[n]*fnv[m]%P*fnv[n-m]%P;
}
void init(int x){
    fac[0]=1;
    FOR(i,1,x)fac[i]=1ll*fac[i-1]*i%P;
    fnv[x]=pw(fac[x],P-2,P);
    ROF(i,x,1)fnv[i-1]=1ll*fnv[i]*i%P;
}
int ans;
signed main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
    init(n*2);
    int an=pw(a,n,P),bn=pw(b,n,P);
    int i100c=pw(100-c,P-2,P);
    FOR(m,n,n*2-1){
        int t=binom(m-1,n-1);
        int s=1ll*an*pw(b,m-n,P)%P+1ll*pw(a,m-n,P)*bn%P;
        s=1ll*s*pw(pw(a+b,m,P),P-2,P)%P;
        s=1ll*s*m%P;
        s=1ll*s*100%P*i100c%P;
        ans=(ans+1ll*t*s)%P;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    long long int k;
    cin>>k;
    if (s.at(0)=='1') {
        if (s.size()==1) {
            cout<<s.at(0)<<endl;
        } else {
            int tmp=1;
            for (int i=1;i<s.size();i++) {
                if (s.at(i)!='1') {
                    tmp=i;
                    break;
                }
            }
            if (k<=tmp) {
                cout<<1<<endl;
            } else {
                cout<<s.at(tmp)<<endl;
            }
        }
    } else {
        cout<<s.at(0)<<endl;
    }
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>
 
using namespace std;
 
int main() {
	int card,gate, min[100010],max[100010];
	
	cin >> card >> gate;
	for (int i = 0; i < gate; i++) {
		cin >> min[i] >> max[i];
	}
	sort(min, min + gate);
	sort(max, max +gate);
  
 
	if (max[0] - min[gate-1] >= 0) {
		cout << max[0] - min[gate-1]+1;
	}
	else cout << 0;
 
	
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n = n_in()
from collections import Counter
c = Counter()

for i in range(1, n+1):
    c[(int(str(i)[0]), int(str(i)[-1]))] += 1

from itertools import product

print(sum(c[(i,j)]*c[(j,i)] for i,j in product(range(1,10), repeat=2)))


Measured memory_bytes: 42092
n, k = map(int, input().split())

cnt = 0

if k % 2 == 0:
  k_2 = k // 2
else:
  k_2 = k

for a in range(k_2, n+1, k_2):
  cnt += len(range(k-(a%k), n+1, k)) ** 2
        
print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const int mxN=1e5;
const ll mod = 1e9+7;

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

    int v[n][3];
    int dp[n+1][3];

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

    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;

    for(int i=1;i<=n;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + v[i-1][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + v[i-1][1];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + v[i-1][2];
    }

    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

Measured memory_bytes: 5896
#include<stdio.h>
 
void dividing(int pm, int pe, int pj);
 
int main(void)
{
    int n;
    int pm, pe, pj;
    while (1) {
        int i = 0;
        scanf("%d", &n);
        if (n == 0) {
            break;
        } else {
            while (i < n) {
                scanf("%d %d %d", &pm, &pe, &pj);
                dividing(pm, pe, pj);
                 i++;
            }
        }
     }
  return 0;
}
 
void dividing(int pm, int pe, int pj)
{
    if (pm == 100 || pe == 100 || pj == 100) {
        printf("A\n");
    }
    else if (pm + pe >= 90 * 2) {
        printf("A\n");
    }
    else if (pm + pe + pj >= 80 * 3) {
        printf("A\n");
    }
    else if (pm + pe + pj >= 70 * 3) {
        printf("B\n");
    }
    else if ((pm + pe + pj >= 50 * 3) && (pm >= 80 || pe >= 80)) {
        printf("B\n");
    } else {
        printf("C\n");
    }
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a % k == 0 || b % k == 0 || a / k != b / k) {
            System.out.println("OK");
        } else {
            System.out.println("NG");
        }
    }
}

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

using namespace std;

struct Point {
  int x;
  int y;
  int height;
  bool upper_bound;
};

int distance(const Point& lhs, const Point& rhs) {
  return abs(lhs.x - rhs.x) + abs(lhs.y - rhs.y);
}

void print(const Point& pt) {
  cout << pt.x << " " << pt.y << " " << pt.height << endl;
}

int main() {
  int N;
  cin >> N;
  vector<Point> points;
  for (int i = 0; i < N; ++i) {
    int x, y, h;
    cin >> x >> y >> h;
    points.emplace_back(Point{x, y, h, h == 0});
  }
  constexpr int max_grid = 100;
  list<Point> summits;
  for (int x = 0; x <= max_grid; ++x) {
    for (int y = 0; y <= max_grid; ++y) {
      summits.emplace_back(Point{x, y, -1, false});
    }
  }
  for (auto pt = points.cbegin(); pt != points.cend(); ++pt) {
    for (auto summit = summits.begin(); summit != summits.end();) {
      auto height = distance(*summit, *pt) + pt->height;
      bool ok = true;
      if (summit->height == -1) {
        summit->height = height;
        summit->upper_bound = pt->upper_bound;
      } else if (summit->upper_bound) {
        if (!pt->upper_bound) {
          if (summit->height < height) {
            ok = false;
          } else {
            summit->height = height;
            summit->upper_bound = false;
          }
        } else {
          summit->height = min(summit->height, height);
        }
      } else if ((!pt->upper_bound && summit->height != height) ||
                 (pt->upper_bound && summit->height > height)) {
        ok = false;
      }
      if (!ok) {
        summit = summits.erase(summit);
      } else {
        ++summit;
      }
    }
    if (summits.size() == 1) {
      print(summits.front());
      return 0;
    }
  }
  return -1;
}


Measured memory_bytes: 768
n = int(input())
l = list(map(int,input().split()))
ans = 0
rui = []
mi = l[0]
for i in l:
    mi = min(i, mi)
    rui.append(mi)
for i in range(n):
    if l[i] == rui[i]:
        ans+=1
print(ans)


Measured memory_bytes: 24744
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=510;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,m,cnt[maxn];
char s[maxn][maxn];
int main()
{
	read(n);read(m);
	for(rg int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		for(rg int j=1;j<=m;j++)
		  if(s[i][j]=='#')
		    {cnt[i]=1;break;}
	}
	for(rg int i=1;i<=n;i++,putchar('\n'))//&
	  for(rg int j=1;j<=m;j++)
	  {
	  	if(s[i][j]=='#') putchar('#');
	  	else if(i&1){if(!cnt[i]&&j==m) putchar('.');else putchar('#');}
	  	else if(!cnt[i]&&j==1) putchar('#');
	  	else putchar('.');
	  }
	putchar('\n');
	for(rg int i=1;i<=n;i++,putchar('\n'))
	  for(rg int j=1;j<=m;j++)
	  {
	  	if(s[i][j]=='#') putchar('#');
	  	else if(~i&1){if(!cnt[i]&&j==1) putchar('.');else putchar('#');}
	  	else if(!cnt[i]&&j==m) putchar('#');
	  	else putchar('.');
	  }
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  for(int i = 0;i<N;i++){
    B[i] = A[i] -(i+1);
  }
  sort(B.begin(),B.end());
  ll ans = 0;
  
  if(N%2 != 0){
   ll b = B[N/2];
    for(int i = 0;i<N;i++){
      ans += abs(B[i]-b);
    }
    cout << ans << endl;
  }
  else {
    ll b = (B[N/2] + B[N/2 -1])/2;
    for(int i = 0;i<N;i++){
      ans += abs(B[i]-b);
    }
    cout << ans << endl;
  }
    
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  string S; cin >> S;
  int ans = 0;
  int l = 0, r = S.size()-1;
  while(r>l) {
    if(S[l] != S[r]) ans++;
    l++; r--;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        if(Math.abs(a-c)<=d)System.out.println("Yes");
        else if(Math.abs(a-b)<=d&&Math.abs(c-b)<=d)System.out.println("Yes");
        else System.out.println("No");
	}
}

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

typedef vector<vector<int>> Matrix;

int n, m, a, b, c, t;
Matrix S, A;

Matrix mul(const Matrix &A, const Matrix &B)
{
	Matrix res(A.size(), vector<int>(B[0].size(), 0));
	
	for (int i = 0; i < A.size(); i++){
		for (int j = 0; j < B[0].size(); j++){
			for (int k = 0; k < A[0].size(); k++){
				res[i][j] += A[i][k] * B[k][j];
				res[i][j] %= m;
			}
		}
	}
	
	return res;
}

Matrix pow(const Matrix &A, int p)
{
	Matrix res(A.size(), vector<int>(A.size(), 0));
	for (int i = 0; i < A.size(); i++){
		res[i][i] = 1;
	}
	
	Matrix B = A;
	while (p){
		if (p & 1) res = mul(res, B);
		B = mul(B, B);
		p >>= 1;
	}
	
	return res;
}

int main()
{
	while (cin >> n >> m >> a >> b >> c >> t, n){
		A.assign(n, vector<int>(n, 0));
		for (int i = 0; i < n; i++){
			if (i - 1 >= 0) A[i][i - 1] = a;
			A[i][i] = b;
			if (i + 1 < n) A[i][i + 1] = c;
		}
		
		S.assign(n, vector<int>(1));
		for (int i = 0; i < n; i++){
			cin >> S[i][0];
		}
		
		Matrix res = mul(pow(A, t), S);
		for (int i = 0; i < n; i++){
			cout << res[i][0] << "\n "[i < n - 1];
		}
	}
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    string s = "";
    while(n--)
    {
        char x = 'a' + n % 26;
        s += string(1, x);
        n /= 26;
    }
    reverse(begin(s), end(s));
    cout << s;
    return 0;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
 
using namespace std;
 
int min_prime(int n);
int isprime(int n);
 
int main()
{
    int n, p;
    while(1){
        cin >> n >> p;
        if(n == -1 && p == -1) break;
        int prime_array[1000] = {0}, sum_array[50000] = {0};
        prime_array[0] = min_prime(n);
        for(int i = 0; i < (2 * p); i++){
            prime_array[i + 1] = min_prime(prime_array[i]);
        }
        int k = 0;
        for(int i = 0; i < (2 * p) + 1; i++){
            for(int j = i; j < (2 * p) + 1; j++){
                sum_array[k] = prime_array[i] + prime_array[j];
                k++;
            }
        }
        sort(sum_array, sum_array+k);
        cout << sum_array[p - 1] << endl;
    }
    return 0;
}
 
int min_prime(int n)
{
    while(++n){
        if(isprime(n)) break;
    }
    return n;
}
 
int isprime(int n)
{
    int ans = 0;
    if(n == 0 || n == 1) ans = 0;
    else if(n == 2) ans = 1;
    else {
        for(int i = 2; i < n; i++){
            if(i * i > n) { ans = 1; break; }
            else if(n % i == 0){
                ans = 0;
                break;
            }
        }
    }
    return ans;
}

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

main(){
  int x,y,z;
  cin >>x >> y >> z;
vector<int> vec;
  vec = {x,y,z};
  sort(vec.begin(),vec.end());
  vector<int> vec2;
  vec2 = {5,5,7};
  if(vec == vec2)cout << "YES" << endl;
  else{cout << "NO" << endl;}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
        static long mod = 998244353;
        static long pow(long a, long n)
        {
            a %= mod;
            long ret = 1;
            long buf = a;
            while (true)
            {
                if((n & 1) == 1) ret = ret * buf % mod;
                else if (n == 0) break;
                buf = buf * buf % mod;
                n >>= 1;
            }
            return ret;
        }
        static long inv2 = pow(2, mod - 2);
        static void Main(string[] args)
        {   
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n+1];
            for (int i=0; i<n; i++) a[i+1] = int.Parse(Console.ReadLine());
            long[,] dp = new long[n + 1, 300 * n + 1];
            long[,] dp2 = new long[n + 1, 300 * n + 1];
            dp[0, 0] = pow(2, n);
            dp2[0, 0] = 1;
            int sum = 0;
            for (int i=1; i<=n; i++)
            {
                sum += a[i];
                for (int j=0; j<=300*n; j++)
                {
                    if (j < a[i])
                    {
                        dp[i,j] = dp[i-1, j];
                        dp2[i, j] = dp2[i-1, j];
                    }
                    else 
                    {
                        dp[i, j] = (dp[i-1, j] + dp[i-1, j-a[i]] * inv2) % mod;
                        dp2[i, j] = (dp2[i-1, j] + dp2[i-1, j-a[i]]) % mod;
                    }
                }
            }
            long ngCase = 0;
            for (int i=sum/2+1; i<=sum; i++)
            {
                ngCase += dp[n, i];
                ngCase %= mod;
            }
            ngCase = ngCase * 3 % mod;
            if (sum % 2 == 0)
            {
                ngCase = (ngCase + 3 * dp[n, sum/2] % mod - 3 * dp2[n, sum/2]) % mod;
            }
            long ans = pow(3, n) - ngCase;
            ans %= mod;
            if (ans < 0) ans += mod;
            Console.WriteLine(ans);

        }
    }
    //mcs Main.cs
    //mono Main.exe

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

using namespace std;
bool check(long long n){
    if(n==1) return 0;
    if(n==2) return 1;
    for(long long i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}
int main(){
    long long a,b;
    cin>>a>>b;
    long long c=__gcd(a,b);
    vector<long long> prs;
    for(long long i=2;i*i<=c;i++){
        if(c%i==0){
            if(i*i==c) prs.push_back(i);
            else{
                prs.push_back(i);
                prs.push_back(c/i);
            }
        }
    }
    long long ans=1;
    for(long long v:prs){
        if(check(v)) ans++;
    }
    if(check(c)) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================
/*Advanced
vi g[N];
int a[N];
*/
void solve() {
  int i, j, n, m;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int k;
	cin >> k;
	k = k % mod;
	int sequ = 7 % k;
	int i = 1;
	while(i != 1e7) {
		if(sequ == 0) {
			cout << i;
			return 0;
		}
		sequ = (sequ * 10 + 7) % k;
		i++;
	}
	cout << -1;
    return 0;
}
/*
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}
*/


Measured memory_bytes: 3644
#include <stdio.h>

int main()
{
    int n, x, y, z;
    int temp;
    int v[10000];

    scanf("%d", &n);

    for (x = 0; x < n; x++){
        scanf("%d", &v[x]);
    }

    for (y = 0; y < n / 2; y++){
        temp = v[y];
        v[y] = v[n - y - 1];
        v[n - y - 1] = temp;
    }

    for (z = 0; z < n - 1; z++){
        printf("%d ", v[z]);
    }
    printf("%d\n", v[n - 1]);

    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

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

        int h = sc.nextInt();
        int w = sc.nextInt();

		  for (int i = 0; i < w+2; i++) {
            System.out.print('#');
        }
        System.out.println();

        for (int i = 0; i < h; i++) {
            String s = sc.next();
            System.out.print('#');
            for (int j = 0; j < w; j++) {
                System.out.print(s.charAt(j));
            }
            System.out.println('#');
        }
        
        for (int i = 0; i < w+2; i++) {
            System.out.print('#');
        }
    }
}


Measured memory_bytes: 23716
def smaller(x, y):
	if x < y: return x
	return y

A, B, AB, X, Y = map(int, input().split())
sum = 0
if A + B <= 2 * AB:
	sum += A * X + B * Y
else:
	pizzaset = 2 * smaller(X, Y)
	sum += pizzaset * AB
	X -= pizzaset // 2
	Y -= pizzaset // 2
	if X == 0:
		if B <= 2 * AB:
			sum += B * Y
		else:
			sum += 2 * Y * AB
	else:
		if A <= 2 * AB:
			sum += A * X
		else:
			sum += 2 * X * AB
print(sum)

Measured memory_bytes: 38448
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
  ll n,m;
  cin >> n >> m;
  vector<pair<ll, ll>> abc(n+m);
  REP(i,n){
    ll a;
    cin >> a;
    abc[i] = make_pair(a, 1);
  }
  REP(i,m){
    ll b,c;
    cin >> b >> c;
    abc[i+n] = make_pair(c, b);
  }
  sort(ALL(abc), greater<pair<ll, ll>>());
  ll sum = 0;
  ll cnt = n;
  REP(i,n+m){
    sum += abc[i].first * min(abc[i].second, cnt);
    cnt -= abc[i].second;
    if(cnt<=0) break;
  }
  cout << sum << '\n'; 
  return 0;  
}

Measured memory_bytes: 3328
// Author: droftware
#include <bits/stdc++.h>

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

#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
using namespace std;

const int N = 100+5, K = 1e5+5, MOD = 1e9+7;

int nums[N];
int dp[N][K], pre[N][K];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	rep(i,0,n){
		cin>>nums[i];
	}
	// init dp
	dp[0][0] = 1;
	pre[0][0] = 1;
	rep(i,1,n){
		dp[i][0] = 1;
		pre[i][0] = dp[i][0];
	}
	rep(i,1,k+1){
		if(i <= nums[0])
			dp[0][i] = 1;
		pre[0][i] = (1ll*pre[0][i-1] + 1ll*dp[0][i])%MOD;
	}
	rep(i,1,n){
		rep(j,1,k+1){
			int lo = j - min(nums[i], j) -1;
			int x = (1ll*pre[i-1][j] - 1ll*(lo >= 0 ? pre[i-1][lo] : 0));
			if(x < 0)
				x += MOD;
			dp[i][j] = x;
			pre[i][j] = (1ll*pre[i][j-1] + 1ll*dp[i][j])%MOD;
		}
	}
	cout<<dp[n-1][k]<<endl;	
}

Measured memory_bytes: 82176
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int K, N;
	cin >> K >> N;


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

	int AM = 0;
	for (int i = 0; i < N - 1; i++) chmax(AM, A[i + 1] - A [i]);
	chmax(AM, K - A[N - 1] + A[0]);

	cout << K - AM << "\n";

	return 0;
}

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

int main() {
    int n;
    ll t, ans, tmp;
    scanf("%d %lld", &n, &t);
    ans = t;
    ll ti[n];
    for (int i = 0; i < n; i++) {
        scanf("%lld", &ti[i]);
    }
    for (int i = 1; i < n; i++) {
        tmp = ti[i] - ti[i-1];
        if (t <= tmp) ans += t;
        else ans += tmp;
    }
    printf("%lld\n", ans);
}

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

int n;
int main(){
  cin >> n;
  int flg = 0;

    for (int i = 0; i <= n/7; i++) {
        if((n-i*7)%4 == 0) {
          flg = 1;
          break;
        }
    }
  cout << (flg == 0 ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N=300005,mu=1000000007;
const int tran[2][N]={{1,3,4,1,6,7,4,8,7},{2,0,5,1,2,5,4,5,7}};
int l,dp[N][10];
char s[N];
void reduce(int &x){x+=x>>31&mu;}
int main(){
	scanf("%s",s+1);
	int l=strlen(s+1);
	dp[0][0]=1;
	for (int i=1;i<=l;i++){
		for (int j=0;j<=8;j++){
			if (s[i]!='1') reduce(dp[i][tran[0][j]]+=dp[i-1][j]-mu);
			if (s[i]!='0') reduce(dp[i][tran[1][j]]+=dp[i-1][j]-mu);
		}
	}
	reduce(dp[l][5]+=dp[l][7]-mu);
	reduce(dp[l][5]+=dp[l][8]-mu);
	reduce(dp[l][5]+=dp[l][2]-mu);
	printf("%d",dp[l][5]);
} 

Measured memory_bytes: 12288
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// good-grid.rs --- Good Grid
// author: Seong Yong-ju <sei40kr@gmail.com>

#[allow(unused_macros)]
macro_rules! get {
  ($t:ty) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.trim().parse::<$t>().unwrap()
    }
  };
  ($($t:ty),*) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      let mut iter = line.split_whitespace();
      (
        $(iter.next().unwrap().parse::<$t>().unwrap(),)*
      )
    }
  };
  ($t:ty; $n:expr) => {
    (0..$n).map(|_|
                get!($t)
    ).collect::<Vec<_>>()
  };
  ($($t:ty),*; $n:expr) => {
    (0..$n).map(|_|
                get!($($t),*)
    ).collect::<Vec<_>>()
  };
  ($t:ty ;;) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.split_whitespace()
        .map(|t| t.parse::<$t>().unwrap())
        .collect::<Vec<_>>()
    }
  };
  ($t:ty ;; $n:expr) => {
    (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
  };
}

#[allow(unused_macros)]
macro_rules! debug {
  ($($a:expr),*) => {
    println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("Failed to parse token")
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn main() {
    let (n, m) = get!(usize, usize);
    let d_map = (0..m)
        .map(|_i| (0..m).map(|_j| read::<u32>()).collect::<Vec<_>>())
        .collect::<Vec<_>>();
    let c_map = (0..n)
        .map(|_i| (0..n).map(|_j| read::<u32>() - 1).collect::<Vec<_>>())
        .collect::<Vec<_>>();

    let mut d_sum = vec![vec![0u32; m]; 3];
    for i in 0..n {
        for j in 0..n {
            let x = c_map[i][j];
            for y in 0..m {
                d_sum[(i + j) % 3][y as usize] += d_map[x as usize][y as usize];
            }
        }
    }

    let mut ans = <u32>::max_value();
    for c0 in 0..m {
        for c1 in 0..m {
            for c2 in 0..m {
                if c0 == c1 || c1 == c2 || c2 == c0 {
                    continue;
                }

                ans = min(ans, d_sum[0][c0] + d_sum[1][c1] + d_sum[2][c2]);
            }
        }
    }

    with_bufwriter(|mut out| writeln!(out, "{}", ans).unwrap());
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

typedef pair<long long,int> P;

int main(){
  int n;
  long long h;
  cin>>n>>h;
  long long a[n],b[n];
  long long ma=0;
  REP(i,n){
    cin>>a[i]>>b[i];
    if(ma<a[i]){
      ma = a[i];
    }
  }
  
  vector<long long> nb;
  REP(i,n){
    if(b[i]>=ma){
      nb.push_back(b[i]);
    }
  }
  sort(nb.begin(),nb.end(),greater<long long>());
  int cntb=nb.size();
  
  long long sumb[cntb];
  REP(i,cntb){
    if(i==0){
      sumb[i]=nb[i];
    }else{
      sumb[i]=sumb[i-1]+nb[i];
    }
  }
  int l=1;int r=1000000010;
  int m;
  while(r-l>1){
    m=(l+r)/2;
    if(m<=cntb){
      if(sumb[m-1]>=h){
        r = m+1;
        if(r-l==2){
          if(sumb[l-1]>=h){
            break;
          }else{
            l = m;
          }
        }
      }else{
        l = m+1;
      }
    }else{
      if(((h-sumb[cntb-1])+ma-1)/ma<=(m-cntb)){
        r = m+1;
        if(r-l==2){
          if(((h-sumb[cntb-1])+ma-1)/ma<=(l-cntb)){
            break;
          }else{
            l = m;
          }
        }
      }else{
        l = m+1;
      }
    }
  }
  
  cout<<l<<endl;
  return 0;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int a[1000005], cnt[1000005], cnt2[1000005];
int main(){
    int n, g = 0;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]), cnt[a[i]]++, g = __gcd(a[i], g);
    bool ok = 1;
    for(int i=2;i<=1000000;i++){
        for(int j=i;j<=1000000;j+=i){
            cnt2[i] += cnt[j];
            if(cnt2[i] > 1) ok = 0;
        }
    }
    if(ok) printf("pairwise coprime\n");
    else if(g == 1) printf("setwise coprime\n");
    else printf("not coprime\n");
}

Measured memory_bytes: 15372
#include<stdio.h>
#include<string.h>
#define ll long long
#define MOD 1000000007
#define add0(p,q)(p=(p+(q))%MOD)
#define add1(p,q)(p=(p+(q)-1)%MOD+1)

ll dp[200010][2];//dp[i][j]=下からi桁見て小さいことが確定してい(j?る:ない)ものの和
ll cnt[200010][2];//dp[i][j]=下からi桁見て小さいことが確定してい(j?る:ない)ものの個数
char s[200010],t[200010];
int main(){
	scanf("%s%s",s,t);
	int n=strlen(s);
	ll p10=1;
	cnt[n][1]=1;
	for(int i=n-1;i>=0;i--){
		if(t[i]=='?'){
			for(int k=0;k<10;k++){
				add0(dp [i][k< s[i]-'0'],dp[i+1][0]+k*p10*cnt[i+1][0]);
				add1(cnt[i][k< s[i]-'0'],cnt[i+1][0]);
				add0(dp [i][k<=s[i]-'0'],dp[i+1][1]+k*p10*cnt[i+1][1]);
				add1(cnt[i][k<=s[i]-'0'],cnt[i+1][1]);
			}
		}else{
			int k=t[i]-'0';
			add0(dp [i][k< s[i]-'0'],dp[i+1][0]+k*p10*cnt[i+1][0]);
			add1(cnt[i][k< s[i]-'0'],cnt[i+1][0]);
			add0(dp [i][k<=s[i]-'0'],dp[i+1][1]+k*p10*cnt[i+1][1]);
			add1(cnt[i][k<=s[i]-'0'],cnt[i+1][1]);
		}
		p10=p10*10%MOD;
	}
	printf("%d\n",dp[0][1]);
}


Measured memory_bytes: 8372
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    if(a%2==0) {
      if(a%3!=0&&a%5!=0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
N = int(input())
SP = [list(map(str, input().split()))+[i+1]  for i in range(N)]

for i in range(N):
    SP[i][1] = int(SP[i][1])

SP = sorted(SP, key=lambda x:(x[1]), reverse=True)
SP = sorted(SP, key=lambda x:(x[0]))

for i in range(N):
    print(SP[i][2])


Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++){
    cin >> X[i];
  }
  int M = 1000000;
  for (int P = 1; P <= 100; P++){
    int S = 0;
    for (int i = 0; i < N; i++){
      S += (X[i] - P) * (X[i] - P);
    }
    M = min(M,S);
  }
  cout << M;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		System.out.println((s / 3600) + ":" + ((s % 3600) / 60) + ":" + (s % 60) );
		sc.close();
	}

}

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

int main()
{
    int a, b;
    for (int i = 0; ; i++) {
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        if (a > b) cout << b << " " << a << endl;
        else cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    vll D(N, vl(2));
    rep(i, N){
        cin >> D[i][0] >> D[i][1];
    }
    ll c = 0;
    rep(i, N){
        if(D[i][0] == D[i][1]){
            c++;
        }
        if(D[i][0] != D[i][1]){
            c = 0;
        }
        if(c == 3){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3644
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int m,n;
int che=1;
int k;
struct node{
  int x,y;
};
char mape[1111][1111];
int d[1111][1111];
int r[10];
queue<node> q;
int da[]={0,1,0,-1};
int db[]={1,0,-1,0};
void bfs(){
  while(!q.empty()&&che<=k){
    node nn;
    int x=q.front().x;
    int y=q.front().y;
    q.pop();
    if(mape[x][y]==che+'0'){
      mape[x][y]='.';
      r[che++]=d[x][y];
      memset(d,-1,sizeof(d));
      d[x][y]=r[che-1];
      while(!q.empty())q.pop();
      nn.x=x;
      nn.y=y;
      q.push(nn);
      return;
    }
    for(int i=0;i<4;i++)
      if(x+da[i]>=0&&x+da[i]<m&&y+db[i]>=0&&y+db[i]<n&&mape[x+da[i]][y+db[i]]!='X'&&d[x+da[i]][y+db[i]]==-1){
	int w=x+da[i];
	int e=y+db[i];
	d[w][e]=d[x][y]+1;
	nn.x=w;
	nn.y=e;
	q.push(nn);
      }
  }
}
int main(){
  cin>>m>>n>>k;
  while(!q.empty())q.pop();
  node nn;
  memset(d,-1,sizeof(d));
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++){
      cin>>mape[i][j];
      if(mape[i][j]=='S'){
	nn.x=i;
	nn.y=j;
	d[i][j]=0;
	q.push(nn);
	mape[i][j]='.';
      }
    }
  while(che<=k)bfs();
  cout<<r[k]<<"\n";
}

Measured memory_bytes: 7136
#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() {
    string s;
    int s1, s2;
    cin >> s;
    s1 = stoi(s.substr(0, 2));
    s2 = stoi(s.substr(2, 2));

    if(s1 < 13 and s1 != 0) {
        // s1:month
        if(s2 > 12 or s2 == 0) {
            cout << "MMYY" << endl;
        } else {
            cout << "AMBIGUOUS" << endl;
        }
    } else if(s2 < 13 and s2 != 0) {
        // s2:month
        if(s1 > 12 or s1 == 0) {
            cout << "YYMM" << endl;
        } else {
            cout << "AMBIGUOUS" << endl;
        }
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

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

int main(){
    int N;
    cin>>N;
    vector<long long> L(N+1,0);
    L.at(0)=2;
    L.at(1)=1;
    for (int i = 2; i < N+1; ++i) {
        L.at(i)=L.at(i-1)+L.at(i-2);
    }
    cout<<L.at(N)<<endl;

    return 0;
};

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

int main(){
    int n,m;
    cin >> n>>m;
    int ans = (n*(n-1)+m*(m-1))/2;
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
def check(a,C):
    vertical=False
    horizonal=False
    #vertical
    d1=C[a[0]][0]-C[a[1]][0]
    d2=C[a[0]][1]-C[a[1]][1]
    d3=C[a[0]][2]-C[a[1]][2]
    if d1==d2==d3:
        vertical=True
    #horizonal
    d4=C[0][a[0]]-C[0][a[1]]
    d5=C[1][a[0]]-C[1][a[1]]
    d6=C[2][a[0]]-C[2][a[1]]
    if d4==d5==d6:
        horizonal=True
    return vertical and horizonal    

def main():
    ans=True
    C=[list(map(int,input().strip().split())) for _ in range(3)]
    x=(0,1),(0,2),(1,2)
    for e in x:
        if check(e,C)==False:
            ans=False
            break            
    return "Yes" if ans else "No"

if __name__=="__main__":
    print(main())

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
	cin>>a>>b>>k;
	long long kk=max(0LL,k-a);
	a=max(0LL,a-k);
	k=kk;
	b=max(0LL,b-k);
	cout<<a<<" "<<b<<endl;
	return 0;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  string s;
  cin >> s;

  bool f = false;
  rep(i, s.size() - 1) {
    if (s[i] == s[i + 1]) f = true;
  }
  if (!f)
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  ll MOD=1000000007;
  int n;
  cin>>n;
  ll a[n],b[n];
  map<llP,int> memo;
  map<llP,int> memo2;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    ll c=abs(a[i]),d=abs(b[i]);
    if(c==0 and d==0) memo[make_pair((long long)0,(long long)0)]++;
    else if(c==0) memo[make_pair((long long)0,(long long)-1)]++;
    else if(d==0) memo[make_pair((long long)1,(long long)0)]++;
    else{
      while(c%d!=0){
        ll temp=d;
        d=c%d;
        c=temp;
      }
      a[i]/=d;b[i]/=d;
      if(a[i]<0) {
        a[i]=-a[i];
        b[i]=-b[i];
      }
      memo[make_pair(a[i],b[i])]++;
    }
  }
  if(n==2 and a[0]*a[1]+b[0]*b[1]==0){
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  vector<ll> anss;
  for(auto itr=memo.begin();itr!=memo.end();itr++){
    if(itr->first==make_pair((long long)0,(long long)0)) continue;
    ll f=itr->first.first,s=itr->first.second;
    if(s<0){
      if(memo2[make_pair(f,s)]>0)continue;
      if(memo.count(make_pair(-s,f))){
        anss.push_back(memo[make_pair(f,s)]);
        anss.push_back(memo[make_pair(-s,f)]);
        memo2[make_pair(f,s)]++;memo2[make_pair(-s,f)]++;
      }
      else ans+=itr->second;
    }
    else{
      if(memo2[make_pair(f,s)]>0)continue;
      if(memo.count(make_pair(s,-f))){
        anss.push_back(memo[make_pair(f,s)]);
        anss.push_back(memo[make_pair(s,-f)]);
        memo2[make_pair(f,s)]++;memo2[make_pair(s,-f)]++;
      }
      else ans+=itr->second;
    }
  }
  ll sum=1;
  if(ans!=0) sum=mod(modpow(2,ans,MOD),MOD);
  for(int i=0;i<(int)anss.size()-1;i+=2){
    sum=mod(sum*mod(((modpow(2,anss[i],MOD))+modpow(2,anss[i+1],MOD)-1),MOD),MOD);
  }
  cout<<mod(sum-1+memo[make_pair((ll)0,(ll)0)],MOD)<<endl;
  return 0;
}


Measured memory_bytes: 31564
#include <stdio.h>
#define MOD 1000000007

int dp[1010][1010];
//dp[n][k]=nをk個以下の整数の和で表す場合の数
//        =nをk以下の整数の和で表す場合の数
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int j=0;j<=m;j++)dp[0][j]=1;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dp[i][j]=(dp[i][j-1]+(i-j>=0?dp[i-j][j]:0))%MOD;
	printf("%d\n",dp[n][m]);
}


Measured memory_bytes: 5752
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, d0; readV(n, d0);
  int[] d; readA(n, d);
  int nq; readV(nq);
  int[] q; readA(nq, q);

  auto a = new int[](n+1);
  a[0] = d0;
  foreach (i; 0..n)
    a[i+1] = d[i] < a[i]*2 ? (a[i]-d[i]).abs : a[i];

  auto b = new int[](n+1);
  b[n] = 1;
  foreach_reverse (i; 0..n)
    b[i] = b[i+1] <= d[i]/2 ? b[i+1] : b[i+1]+d[i];

  foreach (qi; q)
    writeln(a[qi-1] >= b[qi] ? "YES" : "NO");
}


Measured memory_bytes: 23492
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int main()
{
	int n, m;
	ll x[100010], y[100010];
	ll ansx=0, ansy=0;
	ll ans;
	cin >> n >> m;
	rep(i, n)
	{
		cin >> x[i];
		ansx+=(2*i+1-n)*x[i];
		ansx%=MOD;
	}
	rep(i, m)
	{
		cin >> y[i];
		ansy+=(2*i+1-m)*y[i];
		ansy%=MOD;
	}
	cout << (ansx*ansy)%MOD << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const long long MAX=1e9+7;
int n,a[2010];long long ans,k;
int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) {
			if(a[i]>a[j]) ans+=k*(k+1)/2;
			else if(a[i]<a[j]) ans+=(k-1)*k/2;
			ans%=MAX;
		}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include <cmath>
using namespace std;
const long long N = 105;
long long M = 1000000007;

int main() {
	string s[105];
	int n, l;
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++) {
		cout << s[i];
	}
}

Measured memory_bytes: 256
#pragma once

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
long long int  result[2],N, A, B,myMin;




int main() {
	cin >> N;

	myMin = 100;

	for (int i = 1; i <=100000; i++) {
		if (0 == N%i && 0 < N / i) {
			A = N / i;

			if (1 <= A &&  9>=A ) {
				result[0] = 1;
			}
			if (1 <= A / 10 && 9 >= A / 10 ) {
				result[0] = 2;
			}
			if (1 <= A / 100 && 9 >= A / 100 ) {
				result[0] = 3;
			}
			if (1 <= A / 1000 && 9 >= A / 1000 ) {
				result[0] = 4;
			}
			if (1 <= A / 10000 && 9 >= A / 10000) {
				result[0] = 5;
			}

			if (1 <= A / 100000 && 9 >= A / 100000 ) {
				result[0] = 6;
			}
			if (1 <= A / 1000000 && 9 >= A / 1000000) {
				result[0] = 7;
			}
			if (1 <= A / 10000000 && 9 >= A / 10000000 ) {
				result[0] = 8;
			}
			if (1 <= A / 100000000 && 9 >= A / 100000000 ) {
				result[0] = 9;
			}
			if (1 <= A / 1000000000 && 9 >= A / 1000000000) {
				result[0] = 10;
			}
			if (1 <= A / 10000000000 && 9 >= A / 10000000000) {
				result[0] = 11;
			}


			if (1 <= i && 9 >= i ) {
				result[1] = 1;
			}
			if (1 <= i / 10 && 9 >= i / 10) {
				result[1] = 2;
			}
			if (1 <= i / 100 && 9 >= i / 100 ) {
				result[1] = 3;
			}
			if (1 <= i / 1000 && 9 >= i / 1000) {
				result[1] = 4;
			}
			if (1 <= i / 10000 && 9 >= i / 10000) {
				result[1] = 5;
			}

			if (1 <= i / 100000 && 9 >= i / 100000) {
				result[1] = 6;
			}
			

			if (myMin > max(result[0], result[1])) {
				myMin = max(result[0], result[1]);
			}

		}
		

	}

	

	cout <<myMin << endl;

	return 0;
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
ab = []
for i in range(n):
    l = list(map(int,input().split()))
    ab.append(l)
ab = sorted(ab, key=lambda x: x[1])

now = 0

f = 0
for i in range(n):
    now += ab[i][0]
    if now > ab[i][1]:
        f = 1
        break

if f == 0:
    print('Yes')
else:
    print('No')

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

int main(){
  
  int N, a, b;
  cin >> N >> a;
  
  b = N%500;
  if(b == 0){
    cout << "Yes" << endl;
  }else if((b-a) <= 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[3];
int main() {
	ll n,a,b,p;
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
		cin>>p;
		if(p<=a)cnt[0]++;
		else if(p<=b)cnt[1]++;
		else cnt[2]++;
	}
	cout<<min({cnt[0],cnt[1],cnt[2]})<<endl;
	return 0;
}

Measured memory_bytes: 256