akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

static const ll INF = std::numeric_limits<ll>::max() / 3;
static const ll MAX_V = 100;  // TODO

ll cost[MAX_V][MAX_V];  // TODO
ll mincost[MAX_V];
bool used[MAX_V];
ll V;  // TODO

typedef pair<ll, ll> Node;

int prim() {
  priority_queue<Node, vector<Node>, greater<Node>> q;
  q.push(Node{0, 0});
  ll res = 0;
  while (!q.empty()) {
    Node node = q.top();
    q.pop();
    if (used[node.second]) {
      continue;
    }
    used[node.second] = true;
    res += node.first;
    for (ll u = 0; u < V; u++) {
      if (cost[node.second][u] != INF) {
        q.push(Node{cost[node.second][u], u});
      }
    }
  }
  return res;
}

void solve(long long n, vector<vector<long long>> a) {
  V = n;
  REP(i, n) {
    REP(j, n) {
      if (a[i][j] == -1) {
        cost[i][j] = INF;
      } else {
        cost[i][j] = a[i][j];
      }
    }
  }
  std::cout << prim() << std::endl;
}

int main() {
  long long n;
  scanf("%lld", &n);
  vector<vector<long long>> a(n, vector<ll>(n));
  REP(i, n) {
    REP(j, n) {
      scanf("%lld", &a[i][j]);
    }
  }
  solve(n, std::move(a));
  return 0;
}



Measured memory_bytes: 3444
n,m=map(int,input().split())
edge=[]
from collections import deque
from collections import defaultdict
d=defaultdict(list)
for i in range(m):
    a,b=map(int,input().split())
    a-=1 
    b-=1 
    edge.append([a,b])
    d[a].append(b)
    d[b].append(a)
def check(d):
    q=deque()
    vis=[0]*n  
    q.append(0)
    vis[0]=1 
    while q:
        t=q.popleft()
        for i in d[t]:
            if not vis[i]:
                vis[i]=1 
                q.append(i)
    return sum(vis)==n 
cnt=0 
for a,b in edge:
    d[a].remove(b)
    d[b].remove(a)
    if not check(d): 
        cnt+=1 
    d[a].append(b)
    d[b].append(a)
print(cnt)

Measured memory_bytes: 39664
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
  
def gcd_list(y):
    if len(y)==1:
        return y[0]
    if len(y)==2:
        return gcd(y[0],y[1])
    else:
        return gcd(gcd_list(y[:len(y)/2]),gcd_list(y[len(y)/2:]))

N,X= map(int,raw_input().split())

x = map(int,raw_input().split())

for i in range(N):
    x[i]= abs(x[i]-X)

print gcd_list(x)

Measured memory_bytes: 11320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> data(N+1);  
  
  data.at(0) = 2;
  data.at(1) = 1;
  
  for(int i = 2; i<=N; i++) {
    data.at(i) = data.at(i-1) + data.at(i-2);
  }
  
  cout << data.at(N) << endl;
}

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

#define OUT(x) cout << (x) << endl;
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; ++i)

int main() {
    int N, M;
    cin >> N >> M;
    int a[100], b[100];
    int ans[100] = {0};
    REP(i, M){
        cin >> a[i];
        cin >> b[i];
    }
    REP(i, M){
        ans[a[i]]++;
        ans[b[i]]++;
    }
    for(int i=1; i<=N; i++) {
        OUT(ans[i]);
    }
}

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

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main(){
    // ========================================================
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9) cout << -1 << endl;
    else cout << a*b << endl;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

#define N 5
#define REP(i, n) for ( int i = 0; i < (int)n; i++ )
#define LIMIT 20

static const int T[12][2] = {{-1, -1}, {1, 1}, {1, 2}, {1, 3}, {2, 0}, {2, 1},
			     {2, 2}, {2, 3}, {2, 4}, {3, 1}, {3, 2}, {3, 3}};
static const int g[N][N] = {{-1, -1, 0, -1, -1}, {-1, 1, 2, 3, -1},
			    {4, 5, 6, 7, 8}, {-1, 9, 10, 11, -1}, {-1, -1, 0, -1, -1}};

class Puzzle{
    public:
    int C[N][N], mdist; //manhatta distance
    Puzzle(){}

    bool swapAdj( int si, int sj, int ti, int tj ){
	if ( ti < 0 || tj < 0 || ti >= N || tj >= N ) return false;
	if ( C[ti][tj] <= 0 ) return false;
	swap(C[ti][tj], C[si][sj]);
	int tti = T[C[si][sj]][0];
	int ttj = T[C[si][sj]][1];
	mdist -= max(tti, ti)-min(tti, ti) + max(ttj, tj)-min(ttj, tj);
	mdist += max(tti, si)-min(tti, si) + max(ttj, sj)-min(ttj, sj);
	return true;
    }

    bool isGoal(){
	REP(i, N) REP(j, N) if ( g[i][j] != C[i][j] ) return false;
	return true;
    }

    int getMD(){ // get initial manhattan distance
	int sum = 0;
	int ti, tj;
	REP(i, 5) REP(j, 5){
	    if ( C[i][j] <= 0 ) continue;
	    ti = T[C[i][j]][0];
	    tj = T[C[i][j]][1];
	    sum += (max(ti, i)-min(ti, i) + max(tj, j) - min(tj, j));
	}
	return sum;
    }
};

int limit;

bool dfs( int depth, Puzzle P ){
    if ( P.isGoal() ) return true;
    if ( depth + P.getMD() > limit ) return false;

    static const int di[4] = {0, -1, 0, 1};
    static const int dj[4] = {1, 0, -1, 0};

    REP(i, N) REP(j, N){
	if ( P.C[i][j] != 0 ) continue;
	REP(r, 4){
	    Puzzle v = P;
	    if ( !v.swapAdj(i, j, i+di[r], j+dj[r]) ) continue;
	    if ( dfs( depth + 1, v ) ) return true;
	}
    }

    return false;
}

int idp(Puzzle source){
    for ( limit = 0; limit <= LIMIT; limit++ ){
	source.mdist = source.getMD();
	if ( dfs(0, source) ) return limit;
    }
    return INT_MAX;
}

int main(){
    Puzzle P;
    int top;

    while(1){
	cin >> top;
	if ( top == -1 ) break;
	REP(j, N) P.C[0][j] = -1;
	P.C[0][2] = top;
	for(int i = 1; i < N; i++) REP(j, N){
	    if ( (i == 1 || i == 3) && (j == 0 || j == 4 ) ) P.C[i][j] = -1;
	    else if ( i == 4 && j != 2 ) P.C[i][j] = -1;
	    else cin >> P.C[i][j];
	}

	int cost = idp(P);
	if ( cost == INT_MAX ) cout << "NA" << endl;
	else cout << cost << endl;	
    }

    return 0;
}

Measured memory_bytes: 876
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

//Pachimon Creature
public class Main{

	static class N{
		int i, j, id, k;
		public N(int i, int j, int id, int k) {
			this.i = i;
			this.j = j;
			this.id = id;
			this.k = k;
		}
	}

	static int[][] dist;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h)==0)break;
			List<N>[] node = new ArrayList[5];
			for(int i=0;i<5;i++)node[i]=new ArrayList<N>();
			N[] ns = new N[6000];
			N start = null;
			N goal = null;
			int id = 0;
			for(int i=0;i<h;i++){
				char[] s = sc.next().toCharArray();
				for(int j=0;j<w;j++){
					if(s[j]=='S'){
						start = new N(i, j, id, 5);
						ns[id++] = start;
					}
					if(s[j]=='G'){
						goal = new N(i, j, id, 6);
						ns[id++] = goal;
					}
					if(Character.isDigit(s[j])){
						int k = s[j]-'0'-1;
						N nn = new N(i, j, id, k);
						node[k].add(nn);
						ns[id++] = nn;
					}
				}
			}
			int min = 1<<30;
			int ans = -1;
			for(int z=0;z<5;z++){
				ns[start.id].k = z;
				dist = new int[6][id];
				for(int[]d:dist)Arrays.fill(d, 1<<30);
				dist[1][start.id] = 0;
				PriorityQueue<int[]> q = new PriorityQueue<int[]>(id, new Comparator<int[]>() {
					public int compare(int[] o1, int[] o2) {
						return dist[o1[0]][o1[1]]-dist[o2[0]][o2[1]];
					}
				});
				q.add(new int[]{1, start.id});
				while(!q.isEmpty()){
					int[] a = q.poll();
					int num = a[0];
					int v = a[1];
					if(v==goal.id){
						continue;
					}
					if(num==5){
						int cos = dist[num][v] + Math.abs(goal.i-ns[v].i) + Math.abs(goal.j-ns[v].j);
						if(cos < dist[5][goal.id]){
							dist[5][goal.id] = cos;
							q.add(new int[]{5, goal.id});
						}
						continue;
					}
					int next = (ns[v].k+1)%5;
					for(N n:node[next]){
						int cos = dist[num][v] + Math.abs(n.i-ns[v].i) + Math.abs(n.j-ns[v].j);
						if(cos < dist[num+1][n.id]){
							dist[num+1][n.id] = cos;
							q.add(new int[]{num+1, n.id});
						}
					}
				}
				if(dist[5][goal.id] < min){
					ans = z+1;
					min = dist[5][goal.id];
				}
			}
			System.out.println(ans==-1?"NA":(ans+" "+min));
		}
	}
}

Measured memory_bytes: 16000
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  s=input()
  if s=="AC":
    ac+=1
  elif s=="WA":
    wa+=1
  elif s=="TLE":
    tle+=1
  elif s=="RE":
    re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){

    ll n,k;
    cin>>n>>k;

    ll mnp = INT_MAX;
    vector<ll> v(n);

    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
        if(v[i]>=0)
        mnp = min(mnp,i);
    }

    ll ans = INT_MAX;

    for(ll i=0;i<=n-k;i++)
    {
        if(v[i]<0 && v[i+k-1]>0){
             ans = min((abs(v[i])*2)+abs(v[i+k-1]),ans);
             ans = min((abs(v[i+k-1])*2)+abs(v[i]),ans);
            }
            else
            {
                if(v[i]<0)
                ans = min(abs(v[i]),ans);
                else
                ans = min(v[i+k-1],ans);
            }
        // cout<<ans<<" ";
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
char a[301][301];
bool f[301];
int kq[301][301];
int dem=0;
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='#')
                f[i]=true;
        }
    }
    int status=0;
    for(int i=1;i<=n;i++)
    {
        if(f[i])
            dem++;
        status=0;
        if(f[i]==true)
        {
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]=='#')
                {
                    status++;
                }
                if(status>=2)
                {
                    dem++;
                    status=1;
                }
                kq[i][j]=dem;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(kq[i][j]==0)
                kq[i][j]=kq[i-1][j];
        }
    }
    for(int i=n-1;i>=1;i--)
    {
        for(int j=1;j<=m;j++)
        {
            if(kq[i][j]==0)
                kq[i][j]=kq[i+1][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            cout<<kq[i][j]<<" ";
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
int A,B,x,y,z;
cin >> A >> B;
x=A+B;
y=A-B;
z=A*B;
if(x>=y&&x>=z){cout << x <<endl;}else if(y>=z&&y>x){cout <<y<<endl;}else if(z>x&&z>y){cout << z<<endl;}
return 0;
}

Measured memory_bytes: 256
input = split(readline())
a = input[1]
b = input[2]

if a == "H" && b == "H"
    println("H")
elseif a == "H" && b == "D"
    println("D")
elseif a == "D" && b == "H"
    println("D")
elseif a == "D" && b == "D"
    println("H")    
end

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


int main(){
    int bulbs, switches;
    scanf("%d %d", &switches, &bulbs);
    int **bulbSet=new int*[bulbs];
    int *sizes=new int[bulbs];
    for(int count=0;count<bulbs;count++){
        int max;
        scanf("%d", &max);
        bulbSet[count]=new int[max];
        sizes[count]=max;
        for(int count2=0;count2<max;count2++){
            int next;
            scanf("%d", &next);
            bulbSet[count][count2]=next;
            bulbSet[count][count2]--;
        }
    }
    
    int *keys=new int[bulbs];
    for(int count=0;count<bulbs;count++){
        scanf("%d", &keys[count]);
    }
    int tally=0;
    for(int count=0;count<(1<<(switches));count++){
      
        bool good=true;
        for(int count2=0;count2<bulbs;count2++){
            int number=0;
            // printf("%d\n", sizes[count2]);
            for(int count3=0;count3<sizes[count2];count3++){
                // printf("tally\n");
                int comp=count&(1<<(bulbSet[count2][count3]));
                // printf("%d %d\n", count3, comp);
                if(comp!=0){
                    // printf("%d",comp);
                    number++;
                }
            }
            // printf("keys %d", number);
            if(number%2!=keys[count2]){
                good=false;
                break;
            }
            // printf("Pass %d\n", count2);
        }
        if(good){
//   printf("%d\n", count);
            tally++;
        }
    }
    printf("%d", tally);
    for(int count=0;count<bulbs;count++){
        delete[] bulbSet[count];
    }
    delete[] keys;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;
    for (int j = 0; j < t; ++j) {
      int u;
      cin >> u;
      u--;
      s[i].push_back(u);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; ++i) cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool flg = true;
    for (int j = 0; j < m; ++j) {
      int con = 0;
      for (auto x : s[j])
        if (i & (1 << x)) con++;
      if (con % 2 != p[j]) flg = false;
    }
    if (flg) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vi L(2 * N);
    for (int i = 0; i < 2 * N; i++) {
        cin >> L[i];
    }

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

    int ans = 0;
    for (int i = 0; i < 2 * N; i += 2) {
        ans += L[i];
    }

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


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from decimal import Decimal 
from math import floor
def main():
    a, b = map(Decimal, input().split())
    ans = a*b
    print(floor(ans))
if __name__ == '__main__':
    main()


Measured memory_bytes: 71468
function Main(input) {
  input=input.split("\n");
  var target=input[0]-0;
  target*=9;
  if(target%7===0){
    target/=7;
  }
  var array=new Array(target);
  array.fill(false);
  var num=1;
  var counter=0;
  while(true){
    counter++;
    num=(num*10)%target;
    if(array[num]){
      console.log(-1);
      return;
    }
    if(num===1){
      console.log(counter);
      return;
    }
    array[num]=true;
  }
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


Measured memory_bytes: 102512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
    int n;
    int count = 0;
    vector<int> p;
    const long long int size = 100001;
    //vector<bool> swap(size,0);
 
    cin >> n;
 
    for (int i = 0; i < n; ++i)
    {
        int num;
        cin >> num;
        p.push_back(num);
    }
 
    for (int i = 0; i < n-1; ++i)
    {
        if (p[i]==i+1){
            swap(p[i],p[i+1]);
            ++count;
        }
    }
  
    if (p[n - 1] == n) {
      swap(p[n - 2], p[n - 1]);
      ++count;
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for (int i = 0; i < 1000; i++)
	{
		a -= d;
		c -= b;
		if (c<=0)
		{
			cout << "Yes" << endl;
			break;
		}
		else if (a<=0)
		{
			cout << "No" << endl;
			break;
		}

	}
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int c0=0,c1=0,c2=0,c3=0;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")
            c0++;
        if(s=="WA")
            c1++;
        if(s=="TLE")
            c2++;
        if(s=="RE")
            c3++;
    }
    cout<<"AC"<<" x "<< c0<<endl;
    cout<<"WA"<<" x "<< c1<<endl;
    cout<<"TLE"<<" x "<< c2<<endl;
    cout<<"RE"<<" x "<< c3<<endl; 
    return 0;
}




Measured memory_bytes: 3660
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
ans = sum(a1)+a2[-1]
memo = ans
a1.reverse()
a2.reverse()
for i in range(n-1):
    memo -=a1[i]-a2[i+1]
    if memo > ans:
        ans = memo
print(ans)


Measured memory_bytes: 9124
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll a, b;
    cin >> a >> b;
    if(b%a == 0)cout << a + b << endl;
    else cout << b - a << endl;

}

Measured memory_bytes: 256
/*Mon May 11 01:20:14 2020
   This is written by @pk_2809*/


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define all(z) z.begin(),z.end()
#define mcc ((int)1e9+7)
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> fst;

ll binpow(ll a,ll b)
{
    ll res=1; a%=mcf;
	if (a==1 || b==0) return 1;
	else if (a==0) return 0;
    while(b)
    {
        if (b&1) res=(res*a)%mcf;
        b>>=1;
        a=(a*a)%mcf;
    }
    return res%mcf;
}

const int N=2e5+8;
ll fac[N];

void pre()
{
    fac[0]=fac[1]=1;
    for (int i=2;i<N;i++)
    {
        fac[i]=((fac[i-1]%mcf)*i)%mcf;
    }
}
ll inv(ll n)
{
    return binpow(n,mcf-2);
}

ll ncr(ll n, ll r)
{
    return (((fac[n]*inv(fac[r]))%mcf)*(inv(fac[n-r])%mcf))%mcf;
}

void solve()
{
	pre();
	ll n,m,k,ans=0;
	cin>>n>>m>>k;
	for (int i=0;i<=k;i++)
	{
		ans=(ans+((m*binpow(m-1,n-i-1))%mcf)*ncr(n-1,i))%mcf;
	}
	cout<<ans<<endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 5216
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,K,H,W,ans;
  cin>>N>>K;
  cout<<(N+K-1)/K<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
#define INF 2000000000
int a[200005] = { 0 };
int main() {
	int n, i, t;
	cin >> n;
	for (i = 0; i < n - 1; i++) {
		cin >> t;
		a[t]++;
	}
	for (i = 1; i <= n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4376
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
typedef pair<double, double> P;
int main() {
	int N, L;
	cin >> N >> L;
	double sumT = 0;
	deque<P> Q;
	double t, v;
	cin >> t >> v;
	Q.emplace_back(t, v);
	sumT += t * v;
	printf("%.15lf\n", t);
	for (int i = 1; i < N; i++) {
		cin >> t >> v;
		double del = v;
		while (del > 0) {
			if (Q.front().second <= del) {
				del -= Q.front().second;
				sumT -= Q.front().first*Q.front().second;
				Q.pop_front();
			}
			else {
				Q.front().second -= del;
				sumT -= Q.front().first*del;
				del = 0;
			}
		}
		sumT += t * v;
		printf("%.15lf\n", sumT / L);
		P now = P(t, v);
		while (!Q.empty() && Q.back().first > now.first) {
			double sum_t = Q.back().first*Q.back().second + now.first*now.second;
			double sum_v = Q.back().second + now.second;
			now = P(sum_t / sum_v, sum_v);
			Q.pop_back();
		}
		Q.push_back(now);
	}
}


Measured memory_bytes: 21136
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;
    cin>>n>>q;
    vector<vector<ll> > v(n);
    ll a,b;
    ll num[n];
    memset(num,0,sizeof(num));
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        v[a-1].pb(b-1);
    }
    for(int i=0;i<q;i++){
        cin>>a>>b;
        num[a-1]+=b;
    }
    queue<ll> que;
    que.push(0);
    ll umi;
    ll maki;
    while(!que.empty()){
        umi=que.front();
        que.pop();
        maki=v[umi].size();
        for(int i=0;i<maki;i++){
            num[v[umi][i]]+=num[umi];
            que.push(v[umi][i]);
        }
    }
    for(int i=0;i<n;i++){
        cout << num[i]<<" ";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    string s[2];
    cin >> s[0] >> s[1];

    ll dp[52];
    memset(dp, 0, sizeof(dp));

    if(s[0][0] == s[1][0]){
        dp[0] = 3;
    }else{
        dp[0] = 6;
    }

    //  ab  ab  aa  ca
    //  ab  cb  bb  cb

    rep(i,N-1){
        int a;
        if (s[0][i + 1] == s[1][i + 1]){
            if(s[0][i] == s[1][i]){
                a = 2;
            }else{
                a = 1;
            }
        }else{
            if(s[0][i] == s[1][i]){
                a = 2;
            }else{
                if(s[0][i] == s[0][i+1]){
                    a = 1;
                }else{
                    a = 3;
                }
            }
        }
        dp[i + 1] = dp[i] * a;
        dp[i + 1] %= MOD;
    }

    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 256
n = int(input())
s_l = list(map(int,list(input())))

candidates_l = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            candidates_l.append([i,j,k])

ans = 0
for c in candidates_l:
    if c[0] in s_l:
        tmp1 = s_l.index(c[0])
        if c[1] in s_l[tmp1+1:]:
            tmp2 = s_l[tmp1+1:].index(c[1])
            if c[2] in s_l[tmp1+tmp2+2:]:
                ans += 1

print(ans)    

Measured memory_bytes: 3644
n=int(input())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
if n%2==0:
    B=[]
    for i in range(n//2):
        B+=[(i*2)+1]*2
    if A==B:print((2**(n//2))%MOD)
    else:print(0)
else:
    B=[0]
    for i in range((n-1)//2):
        B+=[(i+1)*2]*2
    if A==B:print((2**((n-1)//2))%MOD)
    else:print(0)

Measured memory_bytes: 14008
import sys
S = input()
if S == 'level':
    print('No')
    sys.exit()


for i in range((len(S)//2)-1):
    if S[i] != S[len(S)-1-i]:
        print('No')
        sys.exit()
       
for j in range((len(S)//4)-1):
    if S[j] != S[(len(S)//2)-j-1]:
        print('No')
        sys.exit()

for k in range((len(S)//4)-1):
    if S[(len(S)//2)+1+k] != S[len(S)-k-1]:
        print('No')
        sys.exit()

print('Yes')

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


int main()
{
	int X;
	cin>>X;
	vector<bool> dp(X+1,false);
	dp[0]=true;
	rep(i,6)
	{
		rep(j,X-(100+i)+1)
		{
			if(dp[j]) dp[j+100+i]=dp[j];
		}
	}
	if(dp[X]) cout<<"1"<<endl;
	else cout<<"0"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		String ans = null;

		while(true) {
			C-=B;
			if(C<1) {
				ans = "Yes";
				break;
			}

			A-=D;
			if(A<1) {
				ans="No";
				break;
			}
		}

		System.out.println(ans);






	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}

}


Measured memory_bytes: 35836
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    if(abs(a-c)<=d)cout<<"Yes";
    else if(((a<=b and b<=c) or (c<=b and b<=a)) and (abs(a-b)<=d and abs(c-b)<=d))cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005 
using namespace std;
map<int,int>Map;
struct node{
    int l, r;
    long long sum;
}tree[4*N];
long long n,m,k,sum;
long long ans;
long long a[N],b[N];
void pushup(int x){
    tree[x].sum=tree[x*2].sum+tree[x*2+1].sum;
}
void build(int x,int l,int r){
    tree[x].l=l;tree[x].r=r;
    if(l==r){tree[x].sum=0;return;}
    int mid=(l+r)/2;
    build(x*2,l,mid);
    build(x*2+1,mid+1,r);
    pushup(x);
}
void change(int n, int x, int y){
    if(tree[n].l>x||tree[n].r<x)return;
    if(tree[n].l==x&&tree[n].r==x){tree[n].sum+=y;return;}
    change(n*2,x,y);
    change(n*2+1,x,y);
    pushup(n);
}
void query(int x,int l,int r){
    if(tree[x].l>r||tree[x].r<l)return;
    if(tree[x].l>=l&&tree[x].r<=r){ans+=tree[x].sum;return;}
    query(x*2,l,r);
    query(x*2+1,l,r);
}
int main(){
    scanf("%d%d",&n,&k);
    sum=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        a[i]=a[i]-k;a[i]=a[i]+a[i - 1];
        b[i]=a[i];
    }
    sort(b,b+n+1);
    m=unique(b,b+n+1)-b;
    for(int i=0;i<=n;i++)a[i]=lower_bound(b,b+m+1,a[i])-b+1;
    build(1,0,n);
    for(int i=0;i<=n;i++){
        ans=0;
        query(1,0,a[i]);
        sum+=ans;
        change(1,a[i],1);
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 15112
//define DEBUG for debug
//#define DEBUG

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair 
#define pb push_back
#define MAX 100000+100
#define MOD 1000000007
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int asallar[100000],asalsay = 0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef DEBUG
	freopen("i.txt","r",stdin);
	freopen("o.txt","w",stdout);
#endif
	ll x;cin >> x;
	for(ll i = 2;i < 100004;i++){
		bool asal = true;
		for(ll a = 0;a < asalsay;a++){
			if(i % asallar[a] == 0){
				asal = false;
				break;
			}
		}
		if(asal){
			if(i >= x){
				cout << i;
				return 0;
			}
			asallar[asalsay] = i;
			asalsay++;
		}
	}
	return 0;
}

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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;


int main(){
    int n; cin>>n;
    set<int> st;
    rep(i,0,n){
        int a,b,c;
        cin>>a>>b>>c;
        st.insert(a*a*a+b*b*b+c*c*c);
    }
    cout<<n-st.size()<<endl;
    
    return 0;
}



Measured memory_bytes: 3132
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	int n = sc.nextInt();
      	int k = sc.nextInt();
      	int hs[] = new int[n];
      	long sum = 0;
      
      	for(int i = 0;i < n;i++) hs[i] = sc.nextInt();        
        Arrays.sort(hs);
      	
      	for(int i = 0;i < n-k;i++) sum += hs[i];     	
      	
      	System.out.println(sum);
        
	}
}


Measured memory_bytes: 60348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s = "";
  int count = 0;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1') {
      count += 1;
    }
  }
  cout << count;
}

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

#define MOD 1000000007LL

long long fac[1000001],finv[1000001],inv[1000001];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<1000001;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 
long long MODpow(long long a,int b){
	if(b==0)return 1;
	if(b%2==0){
		long long t=MODpow(a,b/2);
		return (t*t)%MOD;
	}
	return (a*MODpow(a,b-1))%MOD;
}

long long int gcm(long long a,long long b){
	long long r,tmp;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}

int main(){
	COMinit();
	
	int N;
	cin >> N;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	
	vector<int> count(1111111,0);
	for(auto a:A){
		long long x=a;
		for(int i=2;i*i<=x;i++){
			int c=0;
			while(x%i==0){
				x/=i;
				c++;
			}
			count[i]=max(count[i],c);
		}
		if(x>1)count[x]=max(count[x],1);
	}
	
	vector<pair<long long,int>> P;
	for(int i=0;i<1111111;i++)if(count[i]>0)P.push_back(make_pair(i,count[i]));
	//for(auto p:P)cout << p.first << " " << p.second << endl;
	
	long long ans=0;
	for(auto a:A){
		long long x=a;
		long long add=1;
		for(auto p:P){
			int c=0;
			while(x%p.first==0){
				x/=p.first;
				c++;
			}
			add*=MODpow(p.first,p.second-c);
			add%=MOD;
		}
		ans+=add;
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 28544
#include <stdio.h>
#include <string.h>

int q;
int c[1001][1001];
char X[1001], Y[1001];

void LCSLength(int m, int n) {
  int i, j;

  for (i = 1; i <= m; i++) {
    c[i][0] = 0;
  }
  for (j = 0; j <= n; j++) {
    c[0][j] = 0;
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      if(X[i-1] == Y[j-1])  c[i][j] = c[i-1][j-1] + 1;
      else if (c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }
}

int main() {
  int i, x, y;

  scanf("%d\n", &q);
  for (i = 0; i < q; i++) {
    scanf("%s\n", X);
    scanf("%s\n", Y);
    x = (int)strlen(X);
    y = (int)strlen(Y);
    LCSLength(x, y);
    printf("%d\n", c[x][y]);
  }

  return 0;
}

Measured memory_bytes: 4520
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#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 LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int num[10][10] = {};
    rep(i,n-1)num[s[i]-'0'][s[i+1]-'0']++;
    vi v(9);
    rep(i,9)v[i] = i+1;
    vector<vi> ans(3,vi(3));
    int sum = LINF;
    do{
        int t = 0;
        rep(i,9)rep(j,9){
            int xa = i/3, ya = i%3;
            int xb = j/3, yb = j%3;
            t += num[v[i]][v[j]] * (abs(xa-xb) + abs(ya-yb));
        }
        if(t < sum){
            sum = t;
            rep(i,3)rep(j,3)ans[i][j] = v[i*3+j];
        }
    }while(next_permutation(all(v)));
    rep(i,3){
        rep(j,3)cout << ans[i][j];
        cout << endl;
    }
}



Measured memory_bytes: 3304
/*Bismillahir Rahmanir Raheem*/

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

//constant
#define PI acos(-1.0)

//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned un;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef map<char, char> mcc;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<ll, ll> mll;

// defined for taking input
#define gl(x) getline(cin, x)
#define sf scanf
#define sfi(x) scanf("%d", &x)
#define sfc(x) scanf("%c", &x)
#define sfl(x) scanf("%lld", &x)
#define sflu(x) scanf("%llu", &x)
#define sfii(x, y) scanf("%d %d", &x, &y)
#define sfll(x, y) scanf("%lld %lld", &x, &y)
#define sfiii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sflll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)

//defined for printing
#define pf printf
#define pfn pf("\n")
#define pfcas pf("Case %d: ", cas)
#define pfyes pf("YES");
#define pfno pf("NO");
#define pfi(x) pf("%d", x)
#define pfl(x) pf("%lld", x)

//defined for loop

//increament
#define loopi(i, j, k) for (int i = j; i < k; i++)
#define loopl(i, j, k) for (ll i = j; i < k; i++)
#define loopc(i, j, k) for (char i = j; i < k; i++)
#define looplu(i, j, k) for (ull i = j; i < k; i++)
//decreament
#define loopri(i, j, k) for (int i = j; i > k; i--)
#define looprl(i, j, k) for (ll i = j; i > k; i--)
#define looprlu(i, j, k) for (ull i = j; i > k; i--)
#define looprc(i, j, k) for (char i = j; i > k; i--)
#define wa(t) while (t--)

//testcases
#define testc(t) for (char cas = 1; cas <= t; cas++)
#define testi(t) for (int cas = 1; cas <= t; cas++)
#define testl(t) for (ll cas = 1; cas <= t; cas++)

//some cmd
#define pb push_back
#define ppb pop_back
#define mp make_pair

//code start

int main()
{
    // freopen("/home/grimfirefly/Programming/input.txt","r",stdin);
    // freopen("/home/grimfirefly/Programming/output.txt","w",stdout);
    int a, h;
    sfii(a, h);
    pfi(a % h ? (a / h) + 1 : a / h);
    pfn;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
using namespace std;
struct node
{
	int to;
	node *nxt;
}edges[MAXN*2+5];
node *ncnt=&edges[0],*Adj[MAXN+5];
int d[MAXN+5],cnt[MAXN+5],n;
void AddEdge(int u,int v)
{
	node *p=++ncnt;
	p->to=v;
	p->nxt=Adj[u];
	Adj[u]=p;
	
	node *q=++ncnt;
	q->to=u;
	q->nxt=Adj[v];
	Adj[v]=q;
}
bool DFS(int u,int fa)
{
	cnt[u]=0;
	for(node *p=Adj[u];p!=NULL;p=p->nxt)
	{
		int v=p->to;
		if(v==fa)
			continue;
		if(DFS(v,u)==true)
			return true;
		if(cnt[v]==0)
			cnt[u]++;
	}
	if(cnt[u]>=2)
		return true;
	return false;
}
int main()
{
//	freopen("blackwhite.in","r",stdin);
//	freopen("blackwhite.out","w",stdout);
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&u,&v);
		AddEdge(u,v);
		d[u]++,d[v]++;
	}
	if(n==1)
	{
		printf("First\n");
		return 0;
	}
	if(n==2)
	{
		printf("Second\n");
		return 0;
	}
	int rt;
	for(int i=1;i<=n;i++)
		if(d[i]>=2)
		{
			rt=i;
			break;
		}
	if(DFS(rt,-1)==true||cnt[rt]==0)
		printf("First\n");
	else
		printf("Second\n");
	return 0;
}

Measured memory_bytes: 4864
from collections import Counter

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

dict1 = Counter(i+n for i, n in enumerate(A))
dict2 = Counter(i-n for i, n in enumerate(A))

ans = 0
for key, value in dict1.items():
    ans += value * dict2[key]
print(ans)

Measured memory_bytes: 59684
#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;
typedef pair<int, int> pp;
ifstream fin("ac.in");
ofstream fout("ac.out");

const int M = 2e5+30;
struct edge{
    int y, nxt, id;
}e[M<<1];

vector <pp> v[NMAX];
set <int> c[NMAX];
int d[NMAX];
int len;
int lin[NMAX];
int n, m;

void add(int x,int y, int v)
{
    e[++len] = (edge){y, lin[x], v};
    lin[x] = len;
}

void dijkstra(int nod)
{
    memset(d, -1, sizeof(d));
    d[nod] = 0;
    priority_queue <pair<int,int> > h;
    h.push(make_pair(0, nod));
    bool vizitat[n+3];
    memset(vizitat, false, sizeof(vizitat));
    int from , to, tip;

    while(!h.empty())
    {
       from = h.top().second;
       //cout<<from<<'\n';
       h.pop();
    if(vizitat[from])
            continue;
        vizitat[from] = true;

        for(int i = lin[from]; i>0; i=e[i].nxt)
       {
           to = e[i].y;
           //tie(to, tip) = i;

           tip = e[i].id;
           int a = (c[from].count(tip))?0:1;
           //cout<<from<<' '<<a<<'\n';

           if(d[to]==-1 || d[to]>d[from]+a)
           {
                d[to] = d[from] +  a;
                c[to].clear();
                c[to].insert(tip);
               h.push(make_pair(-d[to], to));
           }
           else if(d[to]==d[from]+a)
                c[to].insert(tip);
       }
    }



}

int main()
{
    cin>>n>>m;
    int x, y, t;
    while(m--)
    {
        scanf("%d%d%d", &x, &y, &t);
        add(x, y, t);
        add(y, x, t);
        //v[x].push_back(make_pair(y, t));
        //v[y].push_back(make_pair(x, t));
    }
    dijkstra(1);
    cout<<d[n];
    //fin>>y>>x>>t;
    return 0;
}


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

typedef long long int ll;

int main()
{
    ll k, a, b;
    cin >> k >> a >> b;

    for(ll i = a;i <= b;i++){
        if(i % k == 0){
            cout << "OK";
            return 0;
        }
    }

    cout << "NG";
    
    return 0;
}


Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        s: [usize; n],
        t: [usize; m]
    }
    let d = 1000000007;
    let mut tab: Vec<Vec<usize>> = vec![vec![0; m + 1]; n + 1];
    for i in 0..n + 1 {
        tab[i][0] = 1;
    }
    for j in 0..m + 1 {
        tab[0][j] = 1;
    }
    for i in 0..n {
        for j in 0..m {
            if s[i] == t[j] {
                tab[i + 1][j + 1] = (tab[i][j + 1] + tab[i + 1][j]) % d;
            } else {
                tab[i + 1][j + 1] = (tab[i][j + 1] + tab[i + 1][j] + d - tab[i][j]) % d;
            }
        }
    }
    println!("{}", tab[n][m]);
}


Measured memory_bytes: 45308
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

########関数部分##############
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
############################
 
 
#####関数をつかってみる．#####
######今回は二進数に変換######
x10 = N
x2 = Base_10_to_n(x10, K)
print(len(list(x2)))

Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * 桁DP問題
 * ABC154E http://drken1215.hatenablog.com/entry/2020/02/09/225300
 * 桁DPの思想 http://drken1215.hatenablog.com/entry/2019/02/04/013700
 * 参考提出@yuya178 https://atcoder.jp/contests/abc154/submissions/9990765
 */
public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        String N = sc.next();
        int K = sc.nextInt();

        System.out.println(solve(N, K));
    }

    private static long solve(String N, int K) {
        //[上限ギリギリか][桁数][条件]
        long[][][] dp = new long[2][N.length()+1][K+2];
        dp[1][0][0] = 1;
        int len = N.length();

        for (int i=0; i<len; i++) {
            int val = N.charAt(i) - '0';
            System.err.println(val);

            for (int k=0; k<=K; k++) {
                // dp[1][*][*]の更新
                if (val > 0) {
                    // ギリギリを維持するパターン
                    // 非0のvalを末尾に利用する
                    dp[1][i+1][k+1] += dp[1][i][k];

                    // ギリギリでなくなるパターン
                    // 1以上val未満の値を利用する
                    dp[0][i+1][k+1] += dp[1][i][k] * (val-1);
                    // 0を利用する場合はKの条件は更新されない
                    dp[0][i+1][k]   += dp[1][i][k];
                } else {
                    // 0の場合はギリギリが自動的に維持される
                    dp[1][i+1][k] += dp[1][i][k];
                }


                // dp[0][*][*]の更新
                // 0でない任意の値を利用する場合
                dp[0][i+1][k+1] += dp[0][i][k] * 9;
                // 0を利用する場合
                dp[0][i+1][k]   += dp[0][i][k];
            }
        }

        return dp[0][len][K] + dp[1][len][K];
    }
}

Measured memory_bytes: 23252