akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  bool f;
  while(true){
    c-=b;
    if(c<=0){
      f=true; break;
    }
    a-=d;
    if(a<=0){
      f=false; break;
    }
  }
  YesNo(f);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    ll ans=1;
    for(int i=1;i<=n;i++){
        if(ans<k)
            ans<<=1;
        else
            ans+=k;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll=long long;

int main()
{
    ll x[100100];
    x[0]=1;
    for(int i=1;i<100100;i++){
        x[i]=x[i-1]*(i+1)%1000000007;
    }
    int n,m;cin >>n >>m;
    ll ans;
    n--;m--;
    if(abs(n-m)>=2){
        cout << 0<< endl;
        return 0;
    }
    else {
        ans=x[n]*x[m]%1000000007;
    }
    if(abs(n-m)==1)cout << ans << endl;
    else if(abs(n-m)==0)cout << ans*2%1000000007<< endl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	if(A==1 || B==1) {
		cout<<1<<endl;
	}
	else if(A*B%2==0) {
		cout<<A*B/2<<endl;
	}
	else {
		ll ret=(A/2)*B+(B+1)/2;
		cout<<ret<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#define INFINI 100000001


int main(){

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


    int maxmin=(a<c)?c:a;
    int minmax=(b<d)?b:d;

    
    if(maxmin>minmax)
        printf("0");
    else
        printf("%d",minmax-maxmin);

}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	int l;
	char a[105][105];
	char b[105];
	memset(b, 0, sizeof(b));
	scanf("%d %d", &n, &l);
	for(int i = 0; i < n; i++)
	{
		scanf("%s", a[i]);
		}
	for(int i = 0; i < n; i++)
	{
		for(int j = i; j < n; j++)
		{
			if(strcmp(a[i], a[j]) > 0)
			{
				strcpy(b, a[j]);
				strcpy(a[j], a[i]);
				strcpy(a[i], b);
				}
			}
		}
	for(int i = 0; i < n; i++)
	{
		printf("%s", a[i]);
		}
	printf("\n");
	}

Measured memory_bytes: 128
#include <iostream>
#include <stack>
using namespace std;
int main()
{
    int n;
    stack<int> st;
    while (cin>>n) {
        if (n > 0){
            st.push(n);
        }else{
            cout << st.top() << endl;
            st.pop();
        }
    }
    return 0;
}

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

int selectionSort(int A[], int n)
{
    int count = 0;
    for (int i = 0; i < n - 1; i++)
    {
        int minj = i;
        int j;
        for (j = i; j < n; j++)
        {
            if (A[j] < A[minj])
            {
                minj = j;
            }
        }

        if (minj != i)
        {
            swap(A[minj], A[i]);
            count++;
        }
    }

    return count;
}

int main()
{
    int A[100], n, count;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    count = selectionSort(A, n);
    for (int i = 0; i < n; i++)
    {
        if (i)
            cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3100
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//繋がっている地点を格納するリストの配列
	static List<int>[] pathArray;
	//合計
	static int N;
	//答え
	static int ans;

	//次の地点に進む関数
	static void GoForward(int x, int cnt, bool[] arrived){
			//現在地点を記録
			cnt ++;
			bool[] arr = new bool[N];
			Array.Copy(arrived, arr, N);
			arr[x-1] = true;

			//N回以上の経路を通った場合
			if(cnt == N){
					ans ++;
					return;
			}
			else{
					//次の地点へ進む
					foreach(int next in pathArray[x-1]){
							//まだ到達していなければ次へ
							if(arr[next-1] == false){
									GoForward(next, cnt, arr);
							}
					}
			}
	}

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] line = Console.ReadLine().Split(' ');
		N = int.Parse(line[0]);
		int M = int.Parse(line[1]);

		//配列を初期化
		pathArray = new List<int>[N];
		for(int i=0; i<N; i++){
				pathArray[i] = new List<int>();
		}

		//辺を読み込み、リストに追加
		for(int i=0; i<M; i++){
				string[] line1 = Console.ReadLine().Split(' ');
				int a = int.Parse(line1[0]);
				int b = int.Parse(line1[1]);

				pathArray[a-1].Add(b);
				pathArray[b-1].Add(a);
		}

		//全探索
		GoForward(1, 0, new bool[N]);

		//答えを出力
		Console.WriteLine(ans);

	}
}



Measured memory_bytes: 13268
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.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

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 class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int m = in.nextInt();
			int[][] d = new int[n][n];
			int[] a = new int[m];
			int[] b = new int[m];
			int[] c = new int[m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (i == j) {
						d[i][j] = 0;
					} else {
						d[i][j] = Integer.MAX_VALUE;
					}
				}
			}
			for (int i = 0; i < m; i++) {
				int ta = in.nextInt() - 1;
				int tb = in.nextInt() - 1;
				int tc = in.nextInt();
				a[i] = ta;
				b[i] = tb;
				c[i] = tc;
				d[ta][tb] = tc;
				d[tb][ta] = tc;
			}
			Set<Integer> set = new HashSet<>();
			for (int i = 0; i < m; i++) {
				set.add((a[i]+1)*1000+b[i]+1);
			}

			warshallFloyd(d);

			for (int s = 0; s < n; s++) {
				for (int i = 0; i < m; i++) {
					if (d[s][a[i]] + c[i] == d[s][b[i]]) {
						set.remove((a[i]+1)*1000+b[i]+1);
					}
				}
			}

			out.println(set.size());

		}

		void warshallFloyd(int[][] d) {
			int INF = Integer.MAX_VALUE;
			int len = d.length;
			for (int i = 0; i < len; i++) {
				for (int j = 0; j < len; j++) {
					if (d[j][i] == INF)
						continue;
					for (int k = 0; k < len; k++) {
						if (d[i][k] == INF)
							continue;
						d[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);
					}
				}
			}
		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	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 int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = 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 InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class MinCostFlow:
    """ 最小費用流(ダイクストラ版)：O(F*E*logV) """

    INF = 10 ** 18

    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap, cost):
        G = self.G
        G[fr].append([to, cap, cost, len(G[to])])
        G[to].append([fr, 0, -cost, len(G[fr])-1])

    def flow(self, s, t, f):
        from heapq import heappush, heappop

        N = self.N; G = self.G
        INF = MinCostFlow.INF

        res = 0
        H = [0] * N
        prv_v = [0] * N
        prv_e = [0] * N

        while f:
            dist = [INF] * N
            dist[s] = 0
            que = [(0, s)]

            while que:
                c, v = heappop(que)
                if dist[v] < c:
                    continue
                for i, (to, cap, cost, _) in enumerate(G[v]):
                    if cap > 0 and dist[to] > dist[v] + cost + H[v] - H[to]:
                        dist[to] = r = dist[v] + cost + H[v] - H[to]
                        prv_v[to] = v; prv_e[to] = i
                        heappush(que, (r, to))
            if dist[t] == INF:
                return INF

            for i in range(N):
                H[i] += dist[i]

            d = f; v = t
            while v != s:
                d = min(d, G[prv_v[v]][prv_e[v]][1])
                v = prv_v[v]
            f -= d
            res += d * H[t]
            v = t
            while v != s:
                e = G[prv_v[v]][prv_e[v]]
                e[1] -= d
                G[v][e[3]][1] += d
                v = prv_v[v]
        return res

def compress(S):
    """ 座標圧縮 """

    zipped, unzipped = {}, {}
    for i, a in enumerate(sorted(S)):
        zipped[a] = i
        unzipped[i] = a
    return zipped, unzipped

N = INT()
S = set()
AB = []
for i in range(N):
    a, b = MAP()
    AB.append((a, b))
    S.add(a)
    S.add(b)

zipped, unzipped = compress(S)
M = len(zipped)
mcf = MinCostFlow(N+M+2)
s = N + M
t = N + M + 1
# 負コストを避けるための調整用
MAX = 10 ** 6
# 積み木iをどう使うか
for i, (a, b) in enumerate(AB):
    # 始点 -> 各積み木
    mcf.add_edge(s, i, 1, 0)
    # 積み木iを幅a,高さbに使う
    mcf.add_edge(i, N+zipped[a], 1, MAX-b)
    # 積み木iを幅b,高さaに使う
    mcf.add_edge(i, N+zipped[b], 1, MAX-a)

# 積み木を使わない場合の辺
mcf.add_edge(s, t, N, MAX)

for i in range(M):
    # ある幅 -> 終点
    mcf.add_edge(N+i, t, 1, 0)

res = MAX * N - mcf.flow(s, t, N)
print(res)



Measured memory_bytes: 8200
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  string s;
  char ans[6][10]={"the","the.","this","this.","that","that."};
  while(getline(cin,s)){
    int n=0;
    rep(i,s.size())if(s[i]==' ')n++;
    n++;
    vector<string> word(n);
    i=0;
    rep(j,n){
      while(s[i]!=' '&&s[i]!='\0')
	word[j].push_back(s[i]),i++;
      i++;
    }
    rep(k,26){
      bool c=false;
      rep(i,n)rep(j,word[i].size())
	if(word[i][j]=='z')word[i][j]='a';
	else if(word[i][j]<='z' && word[i][j]>='a')
	  word[i][j]=word[i][j]+1;
      rep(i,n)rep(j,6)
	if(word[i]==ans[j]){
	  c=true;
	}
      if(c){
	rep(i,n){
	  if(i)cout<<" ";
	  cout<<word[i];
	}
	cout<<endl;
	break;
      }
    }
  }
}

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


int main(){
    int n;
    cin >> n;
    vector<int> v(n+1);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    long long r = 0;
    for(int i = 0;i < n; i++){
        if(v[i] % 2 == 1){
            v[i]--;
            if(v[i+1]){
                v[i+1]++;
            }
        }
        r += v[i];
    }
    cout << r/2;

}


Measured memory_bytes: 3748
def main():
    n = int(input())
    A = [0]*(n + 1)
    for x in range(1,101):
        for y in range(1,101):
            for z in range(1,101):
                tmp = x**2 + y**2 + z**2 + x*y + y*z + x*z
                if tmp <= n:
                    A[tmp] += 1
    for i in range(1,n + 1):
        print(A[i])

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

Measured memory_bytes: 68220
n,m=[int(val) for val in input().split()]
matrix=[[int(val) for val in input().split()]for val in range(m)]
#print(n,m,matrix)
ee=[[val[0]-1, val[1]-1] for val in matrix]

cnt=0
k=0
for L in range(m):
    xx=[i for i in range(n)]
    for j in range(m):
        if j!=k:
            val1=xx[ee[j][1]]
            val2=xx[ee[j][0]]
            for i in range(len(xx)):
                if xx[i]==val1:
                    xx[i]=val2
#    print(xx)
    if len(set(xx))>1:
        cnt+=1
    k+=1
    
print(cnt)

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

int px[90010],py[90010];
int rui[90010];

int main(){
  int h,w,d;
  cin >> h >> w >> d;
  //vector<ll> px(h*w,0),py(h*w,0);
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      int a;
      cin >> a;
      px[a]=i;
      py[a]=j;
    }
  }
  //vector<ll> rui(h*w,0);
  for(int i=d+1;i<=h*w;++i){
    rui[i]=rui[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
  }
  int q;
  cin >> q;
  vector<ll> ans;
  for(int i=0;i<q;++i){
    int l,r;
    cin >> l >> r;
    //cout << rui[r]-rui[l] << endl;
    ans.push_back(rui[r]-rui[l]);
  }
  for(int i=0;i<q;++i){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5340
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int n;
    cin >> n;
    vi k(n,0);
    rep(i,n)cin >> k[i];
    SORT(k);
    cout << k[n/2]-k[n/2-1] << endl;
}


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

public class Main
{
    long q, h, s, d;
    long n;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        q = sc.nextLong();
        h = sc.nextLong();
        s = sc.nextLong();
        d = sc.nextLong();
        n = sc.nextLong();
    }

    private void solve() {
        n *= 4;
        Pair[] ps = new Pair[4];
        ps[0] = new Pair(q, 1);
        ps[1] = new Pair(h, 2);
        ps[2] = new Pair(s, 4);
        ps[3] = new Pair(d, 8);
        Arrays.sort(ps);
        long ans = 0L;
        for (int i = 0; i < 4 && n > 0; i++) {
            long tmp = n / ps[i].snd;
            n %= ps[i].snd;
            ans += (tmp * ps[i].fst);
        }
        System.out.println(ans);
    }

    private class Pair implements Comparable<Pair>{
        long fst, snd;
        Pair(long f, long s) {
            fst = f;
            snd = s;
        }

        @Override
        public int compareTo(Pair pair) {
            return Double.compare((double)fst / snd, (double)pair.fst/pair.snd);
        }
    }
}


Measured memory_bytes: 23892
#include<iostream>
#include<utility>
#include<algorithm>
#include<vector>

#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pairs;

int main(){
    int N;
    cin >> N;
    vector<pairs> A(N);
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        A[i] = make_pair(tmp,i+1);
    }
    sort(A.begin(),A.end());
    for(int i=0; i<N; i++){
        cout << A[i].second << " ";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1664
n = int(input())
if n<2:
    print(0)
    exit()
k=2
mod=10**9+7
framod=[1]
def framod_calc(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
        framod.append(a)

def permmod(n, k, mod):
    if n<k: return 0
    a=framod[n]
    c=framod[n-k]
    return (a * pow(c, mod-2, mod)) % mod

def combmod(n, k, mod):
    if n<k: return 0
    a=framod[n]
    b=framod[k]
    c=framod[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod

framod_calc(n+1, mod)
ans=0

for i in range(2, n+1):
    ans+=(combmod(n,i,mod)*(pow(2, i, mod)-2))*pow(8, n-i, mod)
    ans%=mod

print(ans)

Measured memory_bytes: 164988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
typedef long long ll;
typedef pair<int,ll> P;
ll mod=1e9+9;
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}
int inf=1e9;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int N,M,x[50],y[50];
set<P> st;
P ds[100][100],dt[100][100];
P operator+ (const P& a,const P& b){
	if(a.fs<b.fs) return a;
	if(a.fs==b.fs) return P(a.fs,(a.sc+b.sc)%mod);
	return b;
}
bool is(int x,int y){
	return 0<=x&&x<N&&0<=y&&y<N&&st.find(P(x,y))==st.end();
}
void solve1(){
	rep(i,M) st.insert(P(x[i],y[i]));
	P d[300][300];
	rep(i,N) rep(j,N) d[i][j]=P(inf,0);
	queue<int> qx,qy;
	d[0][0]=P(0,1);
	qx.push(0),qy.push(0);
	while(!qx.empty()){
		int x=qx.front(),y=qy.front();qx.pop(),qy.pop();
		rep(di,4){
			int nx=x+dx[di],ny=y+dy[di];
			if(is(nx,ny)){
				if(d[nx][ny].fs==inf){qx.push(nx),qy.push(ny);}
				P q=P(d[x][y].fs+1,d[x][y].sc);
				d[nx][ny]=d[nx][ny]+q;
			}
		}
	}
	cout<<d[N-1][N-1].sc<<endl;
}
const int X=2000000;
ll f[X+1],inv[X+1],g[X+1];
ll Co(int x,int y){
	if(x<0||y<0) return 0;
	return f[x+y]*g[x]%mod*g[y]%mod;
}
void solve2(){
	rep(i,M) st.insert(P(x[i],y[i]));
	{
		rep(i,100) rep(j,100) ds[i][j]=P(inf,0);
		queue<int> qx,qy;
		ds[0][0]=P(0,1);
		qx.push(0),qy.push(0);
		while(!qx.empty()){
			int x=qx.front(),y=qy.front();qx.pop(),qy.pop();
			rep(di,4){
				int nx=x+dx[di],ny=y+dy[di];
				if(is(nx,ny)&&nx+ny<100){
					if(ds[nx][ny].fs==inf){qx.push(nx),qy.push(ny);}
					P q=P(ds[x][y].fs+1,ds[x][y].sc);
					ds[nx][ny]=ds[nx][ny]+q;
				}
			}
		}
	}
	{
		rep(i,100) rep(j,100) dt[i][j]=P(inf,0);
		queue<int> qx,qy;
		dt[0][0]=P(0,1);
		qx.push(0),qy.push(0);
		while(!qx.empty()){
			int x=qx.front(),y=qy.front();qx.pop(),qy.pop();
			rep(di,4){
				int nx=x+dx[di],ny=y+dy[di];
				if(is(N-1-nx,N-1-ny)&&nx+ny<100){
					if(dt[nx][ny].fs==inf){qx.push(nx),qy.push(ny);}
					P q=P(dt[x][y].fs+1,dt[x][y].sc);
					dt[nx][ny]=dt[nx][ny]+q;
				}
			}
		}
	}
	ll d[250]={};
	vector<P> ps;
	int mn=inf,mn2=inf;
	rep(i,100) chmin(mn,ds[i][99-i].fs);
	rep(i,100) chmin(mn2,dt[i][99-i].fs);
	if(mn==inf||mn2==inf){
		puts("0");
		return;
	}
	rep(i,100) if(dt[i][99-i].fs==mn2) ps.pb(P(N-1-i,N-1-(99-i)));
	rep(i,M){
		int t=x[i]+y[i];
		if(100<=t&&100<=(N-1)*2-t) ps.pb(P(x[i],y[i]));
	}
	sort(all(ps));
	ps.erase(unique(all(ps)),ps.end());
	int K=ps.size();
	ll ans=0;
	rep(i,K){
		int x=ps[i].fs,y=ps[i].sc;
		rep(j,100) if(ds[j][99-j].fs==mn){
			add(d[i],ds[j][99-j].sc*Co(x-j,y-(99-j)));
		}
		rep(j,i){
			add(d[i],-d[j]*Co(x-ps[j].fs,y-ps[j].sc));
		}
		if((N-1)*2-x-y<100){
			add(ans,d[i]*dt[N-1-x][N-1-y].sc);
		}
	}
	cout<<(ans+mod)%mod<<endl;
}
int main(){
	f[0]=1;
	rep1(i,X) f[i]=f[i-1]*i%mod;
	inv[1]=1;
	for(ll i=2;i<=X;i++) inv[i]=mod-mod/i*inv[mod%i]%mod;
	g[0]=1;
	rep1(i,X) g[i]=g[i-1]*inv[i]%mod;
	cin>>N>>M;
	rep(i,M){
		cin>>x[i]>>y[i];
		x[i]--,y[i]--;
	}
	if(N<=300) solve1();
	else solve2();
}

Measured memory_bytes: 51464
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <functional>
using namespace std;

int main() {
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S.at(K-1)=='A') S.at(K-1) = 'a';
  else if (S.at(K-1)=='B') S.at(K-1)='b';
  else S.at(K-1)='c';
  cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main(){
  double a, b;
  cin >> a >> b;
  
  cout << a/b << endl;

}

Measured memory_bytes: 256
S = list(input())

even = ['R','U','D']
odd = ['L','U','D']
ans = 'Yes'
for i in range(len(S)):
    if (i%2 == 0 and S[i] not in even) or (i%2 == 1 and S[i] not in odd):
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  if(s.length() > 10 || t.length() - s.length() != 1){
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0;i < s.length();i++)
  {
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, mod = 1e9 + 7;
    cin >> n >> k;
    vector<long long>pref(n + 5), suff(n + 5);
    pref[0] = 0, suff[0] = 0;
    for(long long i = 0; i <= n; i++){
        pref[i + 1] = (pref[i] + i) % mod;
    }
    for(long long j = n; j >= 0; j--){
        suff[n - j + 1] = (suff[n - j] + j) % mod;
    }
    long long ans = 0;
    for(long long i = k; i <= n + 1; i++){
        ans = (ans + (suff[i] - pref[i] + 1 + mod) % mod) % mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6428
def FindParent(X):
    if Parent[X]==X:
        return X
    else:
        Parent[X] = FindParent(Parent[X])
        return Parent[X]

def IsSameParent(X,Y):
    return FindParent(X)==FindParent(Y)

def UniteParent(X,Y):
    X = FindParent(X)
    Y = FindParent(Y)
    if X==Y:
        return 0
    if Rank[X]<Rank[Y]:
        Parent[X] = Y
    else:
        Parent[Y] = X
        if Rank[X]==Rank[Y]:
            Rank[X] += 1
            
N,M = (int(T) for T in input().split())
Parent = [I for I in range(N+1)]
Rank = [0]*(N+1)
for TM in range(0,M):
    A,B = (int(T) for T in input().split())
    UniteParent(A,B)
for TN in range(1,N+1):
    FindParent(TN)
print(len(set(Parent[1:]))-1)

Measured memory_bytes: 19728
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct node{
	int v,p;
	bool operator < (const node &a) const{
		return v<a.v;
	}
};
int a[200005],b[200005];
priority_queue<node> q;

int main(void){
	int n,i,x,p,l,tmp;
	long long ans=0;
	node k;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&b[i]);
		q.push((node){b[i],i});
	}
	while(!q.empty()){
		k=q.top();
		q.pop();
		
		if(k.p==0){p=n-1;l=1;}
		else if(k.p==n-1){p=n-2;l=0;}
		else{p=k.p-1;l=k.p+1;} 
		
		if(k.v!=a[k.p]){
			if(k.v<b[p]+b[l]){
				printf("-1");
				return 0;
			}
			else{
				ans+=k.v/(b[p]+b[l]);
				k.v=k.v%(b[p]+b[l]);
				if(k.v<a[k.p]){
					tmp=(a[k.p]-k.v)/(b[p]+b[l]);
					if((a[k.p]-k.v)%(b[p]+b[l])!=0){
						printf("-1");
						return 0;						
					}
					ans-=tmp;
					k.v+=tmp*(b[p]+b[l]);
				}
				b[k.p]=k.v;
				q.push(k);
			}			
		}

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

Measured memory_bytes: 3700
def lcm(x, y):
   if x > y:
       greater = x
   else:
       greater = y
 
   while(True):
       if((greater % x == 0) and (greater % y == 0)):
           lcm = greater
           break
       greater += 1
 
   return lcm
 
 
 
num1 = int(input())
a=lcm(num1,360)
b=a/num1
print(int(b))

Measured memory_bytes: 9176
#include <iostream>
using namespace std;
int m,n,a,arr[10000],brr[10000][10000],tmp[10000],num;
void input(){
    cin>>m>>n;
    cin>>a;
    for (int i=0;i<a;i++)
        cin>>arr[i];
    for (int i=0;i<a;i++){
        for (int j=0;j<arr[i];j++){
            tmp[num++]=i+1;
        }
    }
}
void solve(){
    num=0;
    for (int i=0;i<m;i++){
        for (int j=0,k=n-1;j<n,k>=0;j++,k--){
            if (i%2==0)
                brr[i][j]=tmp[num++];
            else
                brr[i][k]=tmp[num++];
        }
    }
    for (int i=0;i<m;i++){
        for (int j=0;j<n;j++){
            cout<<brr[i][j]<<" ";
        }
        cout<<endl;
    }
}
int main(){
    input(),solve();
}


Measured memory_bytes: 2688
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	t := intSliceScanner(n)
	a := intSliceScanner(n)
	h := make([]int, n)
	b := make([]bool, n)
	h[0] = t[0]
	f := true
	b[0] = true
	for i := 1; i < n; i++ {
		if t[i] == h[i-1] {
			h[i] = t[i-1]
		} else {
			h[i] = t[i]
			b[i] = true
		}
	}
	if b[n-1] {
		if a[n-1] != h[n-1] {
			f = false
		}
	} else {
		if h[n-1] < a[n-1] {
			f = false
		} else {
			h[n-1] = a[n-1]
			b[n-1] = true
		}
	}
	for i := n - 2; i >= 0; i-- {
		if !f {
			break
		}
		if b[i] {
			if h[i] > a[i] {
				f = false
			} else if a[i] > a[i+1] && a[i] != h[i] {
				f = false
			}
		} else {
			if a[i] == a[i+1] {
				h[i] = smaller(a[i], h[i])
			} else {
				if a[i] <= h[i] {
					h[i] = a[i]
					b[i] = true
				} else {
					f = false
				}
			}
		}
	}
	if f {
		ans := 1
		for i := 0; i < n; i++ {
			if !b[i] {
				ans *= h[i]
				ans %= mod
			}
		}
		fmt.Println(ans)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 5888
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
  uint16_t A, B;
  cin >> A >> B;
 
  if (A > 12) {
    cout << B << endl;
 
  } else if (A < 13 && A > 5) {
    cout << B / 2 << endl;
 
  } else {
    cout << 0 << endl;
  }
 
  return 0;
}

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

int main() {
    long long x; cin >> x;
    if (x % 11 == 0) {
        cout << (x / 11) * 2 << endl;
    } else if (x % 11 <= 6) {
        cout << ((x - 1) / 11) * 2 + 1 << endl;
    } else {
        cout << ((x / 11) + 1) * 2 << endl;
    }
}


Measured memory_bytes: 256
n = int(input())

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i ==0:
      divisors.append(i)
  return divisors

def digit(n):
  for i in range(15):
    if n>=10**i and n<10**(i+1):
      return i+1
      break

list = make_divisors(n)

ans = 2345

for i in list:
  if max(digit(i), digit(n/i)) < ans:
    ans = max(digit(i), digit(n/i))

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int x, y;
  cin >> x >> y;
  cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;

  int s1 = s % 10;
  int s2 = s / 10 % 10;
  int s3 = s / 100 %10;
  
  int sum = s1 + s2 + s3;
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define req(x,y) for(ll j=x,k=y;j<k;j++,k--)
#define ss(x) s[x].size()
#define ch(w,x,y) if(s[b][w]!=s[x][y])
#define cm(w,x,y,z) w=min(w,c[i]+f(x,y,z))

ll n,c[51],d[51][21][2],v[51][21][2],a=1e18;
string s[51];

ll f(ll b,ll p,ll g){
	if(p==ss(b))return 0;
	ll &e=v[b][p][g];
	ll &m=d[b][p][g];
	if(e)return m;
	e=1,m=1e18;
	ll l=1;
	if(!g){req(p,ss(b)-1)ch(j,b,k)l=0;}
	else{req(0,p)ch(j,b,k)l=0;}
	if(l)return m=0;
	rep(i,n){
		ll y=1;
		ll j,k;
		if(!g){
			for(j=p,k=ss(i)-1;j<ss(b) && k>=0 && y;j++,k--) {
				ch(j,i,k)y=0;
			}
			if(y){
				if(k<0)cm(m,b,j,0);
				else cm(m,i,k,1);
			}
		}
		else{
			for(j=p,k=0;k<ss(i) && j>=0 && y;j--,k++){
				ch(j,i,k)y=0;
			}
			if(y){
				if(j<0)cm(m,i,k,0);
				else cm(m,b,j,1);
			}
		}
	}
	return m;
}

int main() {
	cin>>n;
	rep(i,n)cin>>s[i]>>c[i];
	rep(i,n)cm(a,i,0,0);
	cout<<(a==1e18 ? -1 : a)<<endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;




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

int n,k;
cin >> n >> k;
vi h(n);
ll sum=0;
rep(i,n){
    cin >> h[i];
    sum += h[i];
}
if(n<=k){
    fin(0);
    return 0;
}
Rort(h);
rep(i,k){
    sum -= h[i];
}
fin(sum);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 1024
package main

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

type pair struct {
	l, r int
}

func m() {
	n, q := getInt(), getInt()
	s := []rune(getString())
	ps := make([]pair, q)
	for i := range ps {
		ps[i].l = getInt() - 1
		ps[i].r = getInt() - 1
	}

	cSum := make([]int, n+1)
	for i := 0; i < n; i++ {
		if (i < n-1) && (s[i] == 'A') && (s[i+1] == 'C') {
			cSum[i+1] = cSum[i] + 1
		} else {
			cSum[i+1] = cSum[i]
		}
	}

	for _, p := range ps {
		res := cSum[p.r] - cSum[p.l]
		puts(res)
	}
}

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	buf := 200001
	scanner.Buffer(make([]byte, buf), buf)
	scanner.Split(bufio.ScanWords)
	m()
	writer.Flush()
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}

func puts(a ...interface{}) {
	if _, err := fmt.Fprintln(writer, a...); err != nil {
		panic(err)
	}
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
  string str;
  cin >> str;
  int counter_1 = 0;
  int counter_2 = 0;

  //まずは初めが1のパターン
  for(int i = 0;i < str.size();i++){
    if(i % 2 == 0 && str.substr(i,1) == "0")counter_1++;
    if(i % 2 == 1 && str.substr(i,1) == "1")counter_1++;
  }

  //逆
  for(int i = 0;i < str.size();i++){
    if(i % 2 == 0 && str.substr(i,1) == "1")counter_2++;
    if(i % 2 == 1 && str.substr(i,1) == "0")counter_2++;
  }

  cout << min(counter_1,counter_2) << endl;
}

Measured memory_bytes: 512
ROADS = 3

range_city = list(range(1, 4+1))
appearance = []
for i in range(ROADS):
    a, b = map(int, input().split())
    appearance.append(a)
    appearance.append(b)

count = [appearance.count(city) for city in range_city]
if max(count) <= 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#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>;
using V = vector<int>;

int main(int argc, char const *argv[])
{
    int h, w; cin >> h >> w;
    int si, sj, ti, tj; cin >> si >> sj >> ti >> tj;
    si--; sj--; ti--; tj--;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    const int INF = 1e9;
    vector<vector<int> > dist(h,vector<int>(w,INF));
    dist[si][sj] = 0;
    deque<P> q;
    q.emplace_back(si,sj);
    while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        const int di[] = {-1,0,1,0};
        const int dj[] = {0,-1,0,1};
        rep(v,4) {
            int ni = i + di[v], nj = j + dj[v];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (dist[ni][nj] <= d) continue;
            if (s[ni][nj] == '#') continue;
            dist[ni][nj] = d;
            q.emplace_front(ni,nj);
        }
        const int warpi[] = {-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2};
        const int warpj[] = {-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2};
        rep(v,20) {
            int ni = i + warpi[v], nj = j + warpj[v];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (dist[ni][nj] <= d+1) continue;
            if (s[ni][nj] == '#') continue;
            dist[ni][nj] = d+1;
            q.emplace_back(ni,nj);
        }        
    }
    int ans = dist[ti][tj];
    if (ans == INF) ans = -1;
    cout << ans << endl;    

    return 0;
}

Measured memory_bytes: 9460
import math

n = int(input())

def f(x,y):
    return len(str(max(x,y)))

sum = len(str(n))
#print(sum)
for i in range(2,int(math.sqrt(n))+1):
    if (n % i == 0) and (sum > f(i,n // i)):
        sum = f(i,n//i)
        #print(sum, i, n//i)
print(sum)
        
        

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);


    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }

    vector<int> a0(60),a1(60);
    int ans = 0, keisu = 1;

    for(int i = 0;i < n;i ++){
        for(int j = 0;j < 60;j ++){
            if(a.at(i) & ((int)1 << j)) a1.at(j) ++;
            else a0.at(j) ++;
        }
    }

    for(int i = 0;i < 60;i ++){
        int barabara = 1;
        barabara *= (a0.at(i) * a1.at(i)) % 1000000007;
        barabara *= keisu % 1000000007;
        ans += barabara;
        ans %= 1000000007;
        keisu *= 2;
    }

    cout << ans << endl;

    
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

/*
class Compare
{
  public:
    bool operator()(pi a,pi b)
    {
      if(a.first<b.first || (a.first==b.first && a.second>b.second))
        return true;
      return false;
    }
};
*/

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string t;
	cin >> t;
	f(i, 0, t.length() - 1) {
		if (t[i] == '?')
			t[i] = 'D';
	}
	cout << t << endl;
	return 0;
}































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

int main()
{
    int n;
    cin >> n;
    if(n<600){
        cout << "8" << endl;
    }
    else if(n<800)
        cout << "7" << endl;
    else if(n<1000)
        cout << "6" << endl;
        else if(n<1200)
        cout << "5" << endl;
        else if(n<1400)
        cout << "4" << endl;
        else if(n<1600)
        cout << "3" << endl;
        else if(n<1800)
        cout << "2" << endl;
        else
        cout << "1" << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


//https://atcoder.jp/contests/abc089/tasks/abc089_d

signed main(){

	int H, W, D;
	cin >> H >> W >> D;
	P place[300 * 300+1];
	for (int i = 1; i <= H; i++)
		for (int j = 1; j <= W; j++){
			int A;
			cin >> A;
			place[A-1] = P(i, j);
		}

	vector< vector<int> > sum(D+1);
	for (int i = 0; i < D; i++){
		sum[i].resize(H*W / D + 2);
		sum[i][0] = 0;
		for (int j = 1; i+j*D<=H*W; j++){
			// i+j*Dからi+(j+1)*D
			int f = i + (j - 1)*D, s = i + j*D;
			int dist = abs(place[f].first - place[s].first)
				+ abs(place[f].second - place[s].second);
			sum[i][j+1] = sum[i][j] + dist;
		}
	}

	int Q;
	cin >> Q;
	while (Q--){
		int L, R;
		cin >> L >> R;
		L--; R--;
		cout << sum[L%D][R / D+1] - sum[L%D][L / D+1] << endl;
	}

	return 0;
}

Measured memory_bytes: 6784
#include <iostream>
using namespace std;
int main(){
	int n,l=0;
	string a;
	cin>>n>>a;
	for(int i=0;i<n;i++){
		if(a[i]=='A' and a[i+1]=='B' and a[i+2]=='C'){
			l++;
		}
	}
	cout<<l;
}



Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
b_lst = [int(x) for x in stdin.readline().rstrip().split()]
a_sum = b_lst[0] + b_lst[-1]

for i in range(len(b_lst)-1):
  a_sum += min(b_lst[i], b_lst[i+1])
  
print(a_sum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll K;
  cin>>K;
  
  string S;
  cin>>S;
  
  if(S.size()<=K){
    cout<<S<<endl;
  }
else{
  rep(i,K){
    cout<<S[i];
  }
    cout<<"... "<<endl;
    
  
}
}

  
  

Measured memory_bytes: 3632
import collections
n=int(input())
s=[str(input()) for i in range(n)]
m=int(input())
t=[str(input()) for i in range(m)]
s_s=set(s)
t_s=set(t)
#import pdb;pdb.set_trace()
s_c=collections.Counter(s)
t_c=collections.Counter(t)
a_l=[]
for i in s_c.keys():
    a_l.append(s_c[i]-t_c[i])
if max(a_l)>0:
    ans=max(a_l)
else:
    ans=0
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vec<int> v(n);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    double nv = v[0];
    rep(i, n-1) {
        nv = (nv + v[i+1])/2.0;
    }
    cout << setprecision(10) << nv << endl;
}

Measured memory_bytes: 256