akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    char str[1000];
    int i = 0;
    
    fgets(str, sizeof(str), stdin);
    
    while(str[i] && i < 996){
        if(str[i]     == 'a')
            if(str[i + 1] == 'p')
                if(str[i + 2] == 'p')
                    if(str[i + 3] == 'l')
                        if(str[i + 4] == 'e'){
                            str[i]     = 'p';
                            str[i + 1] = 'e';
                            str[i + 2] = 'a';
                            str[i + 3] = 'c';
                            str[i + 4] = 'h';
                            
                            i += 5;
                        }else
                            i += 4;
                    else
                        i += 2;
                else
                    i++;
            else
                i++;
        else
            if(str[i]     == 'p')
                if(str[i + 1] == 'e')
                    if(str[i + 2] == 'a')
                        if(str[i + 3] == 'c')
                            if(str[i + 4] == 'h'){
                                str[i]     = 'a';
                                str[i + 1] = 'p';
                                str[i + 2] = 'p';
                                str[i + 3] = 'l';
                                str[i + 4] = 'e';
                                
                                i += 5;
                            }else
                                i += 4;
                        else
                            i += 2;
                    else
                        i += 2;
                else
                    i++;
            else
                i++;
    }
    
    printf("%s", str);
        
    return 0;
}     

Measured memory_bytes: 524
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;

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

int bfs(int sx, int sy, int gx, int gy, vector<string>& vs) {
  vector<vector<int>> d(vs.size(), vector<int>(vs[0].size(), -1));
  queue<P> que;

  que.push(P(sx, sy));
  d[sy][sx] = 0;

  while (que.size()) {
    P p = que.front(); que.pop();
    if (p.first == gx && p.second == gy) break;
    
    rep(i, 4) {
      int nx = p.first + dx[i], ny = p.second + dy[i];

      if (0 <= nx && nx < vs[0].size() &&
          0 <= ny && ny < vs.size() && 
          vs[ny][nx] != '#' && d[ny][nx] == -1) {
        d[ny][nx] = d[p.second][p.first] + 1;
        que.push(P(nx, ny));
      }
    }
  }

  return d[gy][gx];
}


int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> vs(H);
  rep(i, H) cin >> vs[i];

  // 幅優先探索で最短経路を求める
  int shortest = bfs(0, 0, W - 1, H - 1, vs);
  if (shortest == -1) {
    cout << -1 << endl;
    return 0;
  }
  int count = 0;  // 初期状態の白マス全て
  rep(i, H) rep(j, W) if (vs[i][j] == '.') ++count;
  // 全ての白マスから、最短経路を除外する
  count -= shortest + 1;

  cout << count << endl;

  
  return 0;
}

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

long long int gcd( long long int m, long long int n ){
  if(n == 0) return m;
  else return gcd(n,m%n);
}

int main(){
  int N;
  cin>>N;
  long long int X;
  cin>>X;
  long long int ans,x;
  cin>>ans;
  ans = abs(ans-X);
  for(int i=1;i<N;i++){
    cin>>x;
    x = abs(x-X);
    ans = gcd(ans,x);
  }
  cout<<ans <<endl;
}

Measured memory_bytes: 256
WV = $<.read.split.map(&:to_i).each_slice(2).to_a
N,W = WV.shift
WV.sort_by! {|w,v| w>W ? 1<<60 : (v<<30)+w}
I = [0]
tv=tw = 0
i = WV.each_with_index {|(w,v),i|
  break 0...i  if w > W
  I << I[-1]=[v,i]  if I[-1][0] < v
  tv+=v; tw+=w
}.size
I[-1] = [1<<60,i]
A = Array.new(tv+1, [tw,-1])
A[0] = [0,0]
l = tw > W ? 0 : tv
l.upto(tv-1) {|n|
  c,b = A[n]
  l = n if c <= W
  next  if c >= W
  0.upto(I.size-2) {|i|
    j = I[i+1][1] - 1
    next  if b[j] > 0
    v,i = I[i]
    next  if A[v+n][0] <= c + WV[i][0]
    i = (i..j).bsearch {|x| b[x] == 0}
    w = c + WV[i][0]
    x = b | b+(1<<i)
    A[v+n] = [w,x]  if A[v+n][0] > w
  }
}
p l

Measured memory_bytes: 9336
N = int(input())
A = [int(k) for k in input().split()]


M = [1]
for a in A[:-1]:
    M.append((M[-1] - a) * 2)


dsum = 0
d = 0
ok = True
for i in range(len(A) - 1, -1, -1):
    min_d = ((d + 1) // 2 if d % 2 else d // 2) + A[i]
    max_d = d + A[i]
    if min_d > M[i]:
        ok = False
        break
    d = min(M[i], max_d)
    dsum += d

print(dsum if ok else -1)


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  vector<string>S(N);
  for(int i=0;i<N;i++)cin>>S[i];
  map<string,int>m;
  for(auto it:S)m[it]++;
  cout<<"AC"<<" x "<<m["AC"]<<endl;
  cout<<"WA"<<" x "<<m["WA"]<<endl;
  cout<<"TLE"<<" x "<<m["TLE"]<<endl;
  cout<<"RE"<<" x "<<m["RE"]<<endl;

  return 0;
}


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

namespace ARC61_C
{
    class Program
    {
        static void Main(string[] args)
        {

            var s = Console.ReadLine();
            int n = s.Length - 1;
            var bits = new List<string>();
            for (int i = 0; i < Math.Pow(2, n); i++)
            {
                bits.Add(Convert.ToString(i, 2).PadLeft(n, '0'));
            }
            long sum = 0;
            for (int i = 0; i < bits.Count; i++)
            {
                string p = "";
                for (int j = 0; j < s.Length; j++)
                {
                    p += s[j];
                    if (j != s.Length -1 && bits[i][j] == '1')
                    {
                        p += '+';
                    }
                }
  
                sum += p.Split('+').Select(long.Parse).Sum();
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11348
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
#include<string>
#include<set>
//#include<unordered_map>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll>PLL;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int eps=1e-9;
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
const int maxn=1e5+50;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        printf("ACL");
    }   
    cout<<endl;
   return 0;
}

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

// intersects returns whether [a1, b1) \cap [a2, b2) is nonempty
bool intersects(int a1, int b1, int a2, int b2) {
  return ((a2 >= a1 and a2 < b1) or (a1 >= a2 and a1 < b2));
}

struct Seg {
  int start;
  int end;
  int x;
  Seg *l;
  Seg *r;
  Seg(int start, int end, int x) : start(start), end(end), x(x) {
    if (end > start + 1) {
      l = new Seg(start, (start + end) / 2, x);
      r = new Seg((start + end) / 2, end, x);
    }
  }
  int Get(int s, int t) {
    if (s <= start and t >= end) {
      return x;
    } else if (intersects(s, t, l->start, l->end) and
               intersects(s, t, r->start, r->end)) {
      return min(l->Get(s, t), r->Get(s, t));
    } else if (intersects(s, t, l->start, l->end)) {
      return l->Get(s, t);
    } else { // intersects right interval
      return r->Get(s, t);
    }
  }
  void Set(int i, int new_x) { // 1-indexed
    if (start == end - 1) {
      x = new_x;
      return;
    }
    (i < l->end ? l : r)->Set(i, new_x);
    x = min(l->x, r->x);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  auto seg = new Seg(1, n + 1, numeric_limits<int>::max());
  int c, x, y;
  while (cin >> c >> x >> y) {
    if (c == 0)
      seg->Set(x + 1, y); // internal repr. is 1-indexed
    if (c == 1)
      cout << seg->Get(x + 1, y + 2) << endl; // and uses open intervals
  }
}


Measured memory_bytes: 12468
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
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;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

int myGCD(int A, int B)
{
  int a = A, b = B;
  while (a * b != 0  &&  a != 1  &&  b != 1)
  {
    if (a < b) b %= a;
    else a %= b;
  }
  if (a * b == 0) return max(a, b);
  else return 1;
}

signed main()
{
  int N, X;
  cin >> N >> X;

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int x;
    cin >> x;
    ans = myGCD(ans, abs(X - x));
  }

  cout << ans << endl;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<long> h(N);
  rep(i, N)
  {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  long ans = pow(10, 9);
  rep(i, N - K + 1)
  {
    long length = h[i + K - 1] - h[i];
    ans = min(length, ans);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

using namespace std;
int n,m,i,x,y,a[200004],b[200004];
bool ok;
int main()
{
    scanf ("%d %d", &n, &m);
    for (i=1;i<=n;i++)
    {
        a[i]=0;
        b[i]=0;
    }
    ok=false;
    for (i=1;i<=m;i++)
    {
        scanf ("%d %d", &x, &y);
        if (x==1)
        {
            a[y]=1;
            if (b[y]==1)
                ok=true;
        }
        if (y==n)
        {
            b[x]=1;
            if (a[x]==1)
                ok=true;
        }
    }
    if (ok==true)
        printf ("POSSIBLE\n");
    else
        printf ("IMPOSSIBLE\n");
    return 0;
}


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

int main() {
int N,ans=1,anse=0;
cin>>N;
int H[N+1];
for(int i=1;i<=N;i++){
cin>>H[i];
}
for(int k=2;k<=N;k++){
  anse=0;
  if(H[k]>=H[1]){
    for(int d=1;d<k;d++){
      if(H[d]<=H[k]) {
        anse++;
    }
    if(anse==k-1)ans++;
    }
  }
}
cout<<ans<<endl;

}


Measured memory_bytes: 256
int main()
{
    int n, k,d,a,cnt=0;
    int i, j;

    scanf("%d%d", &n,&k);

    int nn[100] = { 0 };
    for (i = 0; i < k; i++)
    {
        scanf("%d", &d);
        for (j = 0; j < d; j++)
        {
            scanf("%d", &a);
            nn[a-1]++;
        }
    }
    for (i = 0; i < n; i++)
    {
        if (nn[i] == 0)
        {
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int len=0;
  len = s.size();
 
  for(int i;i<len;i++){
    if(s[i]=='?'){
      s.replace(i, 1, "D");
      
    }
  }
  cout<<s<<endl;

}

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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  if (any_of(a.begin(), a.end(), [&](auto x) { return x == 0; })) {
    cout << 0 << endl;
    return 0;
  }

  ll inf = 1e18;

  ll ans = 1;
  for (auto aa : a) {
    if (log10(ans) + log10(aa) > 18) {
      cout << -1 << endl;
      return 0;
    }
    ans *= aa;
    if (ans < 0 || ans > inf) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4024
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

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

	for (i = 0; i < N; ++i) {//街名i,道路j
		for (j = 0; j < M; ++j) {
			if (a[j] == i+1) {
				++ans[i];
			}
			if (b[j] == i+1) {
				++ans[i];
			}
		}
	}

	for (i = 0; i < N; ++i) {
		cout << ans[i] << endl;
	}

}

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

using namespace std;

#define F first
#define S second
#define MAX_N 1e5+10
#define mod 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vbl;

int main() {
  int n, k;
  cin >> n >> k;
  ll a[n+1];
  ll dp[n+1][k+1], sum[n+1][k+1];
  for (int i = 1 ; i <= n ; i++) {
    cin >> a[i];
    dp[i][0] = 1;
    sum[i][0] = 1;
  }

  for (int c = 0 ; c <= k ; c++) {
    if (c <= a[1]) {
      dp[1][c] = 1;
    }
    else dp[1][c] = 0;
    if (c > 0) {
      sum[1][c] = sum[1][c-1]+dp[1][c];
    }
  }

  for (int i = 2 ; i <= n ; i++) {
    for (int c = 1 ; c <= k ; c++) {
      if (c-a[i]-1 >= 0) {
        dp[i][c] = sum[i-1][c]-sum[i-1][c-a[i]-1];
      }
      else dp[i][c] = sum[i-1][c];
      dp[i][c] = (dp[i][c]+mod) % mod;
      sum[i][c] = sum[i][c-1]+dp[i][c];
      sum[i][c] %= mod;
    }
  }

  cout << dp[n][k] << endl;

  return 0;
}

Measured memory_bytes: 157312
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = min(a, b);
  int y = min(c, d);

  cout << x+y << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int x,y;
int z;
char op;
cin>>x>>op>>y;
if(op=='+'){
	z=x+y;
	cout<< z;
}
else if(op=='-'){
	z=x-y;
	cout<<z;
}
else
cout<<"error";






}

Measured memory_bytes: 256
///****In the name of ALLAH, most Gracious, most Compassionate****//

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

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

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}

const int N=3e5+5;
const int oo=1e9+7;
int dx[]= { 1, 0, -1 ,0};
int dy[]= { 0, 1, 0 ,-1};

int dist[500][500];

bool ache[500][500];

void bfs(int n)
{
    queue<int > q;
    for(int i=0;i<n;i++)
    {
        if(dist[i][0] > 0)
        {
            dist[i][0] =0;
            q.push(i*n+0);
        }
        if(dist[i][n-1] > 0)
        {
            dist[i][n-1] =0;
            q.push(i*n+n-1);
        }
        if(dist[n-1][i] > 0)
        {
            dist[n-1][i] =0;
            q.push((n-1)*n+i);
        }
        if(dist[0][i] > 0)
        {
            dist[0][i] =0;
            q.push(0*n+i);
        }
    }
    while(!q.empty())
    {
        int u =q.front();
        q.pop();

        int x =u/n;
        int y =u % n;
        for(int i=0;i<4;i++)
        {
            int xx =x + dx[i];
            int yy =y + dy[i];
            if(xx<0 or xx>=n) continue ;
            if(yy<0 or yy>=n) continue ;
            if(dist[xx][yy] > dist[x][y] + 1)
            {
                dist[xx][yy] = dist[x][y] + 1;
                q.push(xx*n+yy);
            }
        }
    }
}

void upd(int x,int y,int n)
{
    for(int i=0;i<4;i++)
    {
        int xx =x+ dx[i];
        int yy =y+ dy[i];
        if(xx<0 or xx>=n) continue ;
        if(yy<0 or yy>=n) continue ;
        if(dist[xx][yy] > dist[x][y] + ache[x][y])
        {
            dist[xx][yy] = dist[x][y] + ache[x][y];
            upd(xx,yy,n);
        }
    }
}

void print(int n)
{
    DBG(dist);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cout<<dist[i][j]<<" ";
        NL;
    }
}

int32_t main()
{
    FastIO;
    int n;
    cin>>n;
    int n2 = n *n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            ache[i][j] = 1 , dist[i][j] = oo;
    }
    bfs(n);
    int ans= 0;
    for(int i=0;i<n2;i++)
    {
//        print(n);
//        NL;
        int p;
        cin>>p;
        p--;
        int x = p/n;
        int y = p%n;
//        DBG(x);
//        DBG(y);
//        DBG(dist[x][y]);
//        NL;

        ans+=dist[x][y];
        ache[x][y] =0;
        upd(x,y,n);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 24172
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      if(i == n - 1) {
        System.out.println(a[i]);
      } else {
        System.out.print(a[i] + " ");
      }
    }
    int key;
    int j;
    for(int i = 1; i < n; i++) {
      key = a[i];
      j = i - 1;
      while(j >= 0 && a[j] > key) {
        a[j + 1] = a[j];
        j--;
        a[j + 1] = key;
      }
      for(int k = 0; k < n; k++) {
        if(k == n - 1) {
          System.out.println(a[k]);
        } else {
          System.out.print(a[k] + " ");
        }
      }
    }
  }
}



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


t  = list(map(int,input().split()))



for j in range(n,100000):
    h = str(j)
    u=0
    for s in h:
        if int(s) in t:
            u+=1
            break
    if u==0:
        print(h)
        break


Measured memory_bytes: 9068
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;

  vll V;
  ll sum = 0;
  ll cnt = 1;
  while (sum < N) {
    V.emplace_back(cnt);
    sum += cnt;
    cnt++;
  }

  if (sum == N) {
    REP(i, 0, V.size()) {
      cout << V[i] << endl;
    }
  } else {
    REP(i, 0, V.size()) {
      if (V[i] != sum - N) {
        cout << V[i] << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.algorithm;
import std.conv;
import std.array;
import std.string;

void main() {
  int n, m;
  auto t = readln.chomp.split(' ').map!(to!int).array;
  n = t[0];
  m = t[1];

  auto s = readln.chomp.split(' ').map!(to!int).array.sum;

  if (n - s < 0) {
    writeln("-1");
  } else {
    writeln(n - s);
  }
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0
#include<string.h>
int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


signed main(){ 
    vector<int>a(5,0);
    int ans;
    rep(i,5)
    {
        cin >> a[i];
        if(a[i]==0)ans = i;
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int main(){
	char a;
	int ans=0;
	for(int i=1;i<=4;i++){
		cin>>a;
		if(a=='2') ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import math

def a():
    x = int(input())
    
    if x < 600:
        print(8)
    elif x<800:
        print(7)
    elif x<1000:
        print(6)
    elif x<1200:
        print(5)
    elif x<1400:
        print(4)
    elif x<1600:
        print(3)
    elif x<1800:
        print(2)
    else:
        print(1)

def b():
    a,b,c = map(int,input().split())
    k = int(input())
    count = 0
    
    while b<= a:
        b *= 2
        count += 1
    
    while c<=b:
        c *= 2
        count += 1
    if count <= k:
        print('Yes')
    else:
        print('No')



def c():
    pass



def d():
    pass


# a()
b()
# c()
# d()

Measured memory_bytes: 9212
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,m,w[110],v[110],f[100010];
signed main(){
	scanf("%lld %lld",&m,&t);
	for(int i=1;i<=m;i++){
		scanf("%lld %lld",&w[i],&v[i]);
	}
	for(int i=1;i<=m;i++){
		for(int j=t;j>=1;j--){
			if(w[i]<=j) f[j]=max(f[j],f[j-w[i]]+v[i]);
		}
	}
	printf("%lld",f[t]);
}

Measured memory_bytes: 1024
use im_rc::HashMap;
use input::*;
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;
    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn string() -> String {
        read()
    }
    pub fn int() -> i64 {
        read()
    }
    pub fn char() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn vecchar() -> Vec<char> {
        string().chars().collect()
    }
    pub fn vecint(n: i64) -> Vec<i64> {
        let mut vec = Vec::new();
        for i in 0..n {
            vec.push(int())
        }
        vec
    }
}
fn main() {
    let n = int();
    let a = vecint(n - 1);
    let mut v = HashMap::new();
    for i in 0..a.len() {
        if !v.contains_key(&a[i]) {
            v.insert(a[i], 0);
        }
        v[&a[i]] += 1;
    }
    for i in 1..=n {
        println!("{}", v.get(&i).unwrap_or(&0))
    }
}


Measured memory_bytes: 42968
#include<stdio.h>
int main()
{
	int i,j,n;
	const int N=10001;
	bool p[N];
	for(i=2;i<N;++i)p[i]=true;
	for(i=2;i<=N/2;++i)if(p[i])for(j=2*i;j<N;j+=i)p[j]=false;
	while(scanf("%d",&n),n){for(i=n;;--i)if(p[i]&&p[i-2])break;printf("%d %d\n",i-2,i);}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#define N 100000
  typedef struct{
    int num;
    char mark;
    int rank;
  }card;
int Partition(card[],int,int);
void Quicksort(card[],int,int);
 
 
int main(){
 
  int n,i,flag=0;
  char a;
  card card1[N];
 
  scanf("%d%c",&n,&a);
  for(i = 0; i < n; i++){
    scanf("%c%d%c",&card1[i].mark,&card1[i].num,&a);
    card1[i].rank = i + 1;
  }
  Quicksort(card1,0,n - 1);
  for(i = 0; i < n -1; i++){
    if(card1[i].num == card1[i + 1].num && card1[i].rank > card1[i + 1].rank && flag == 0){
      printf("Not stable\n");
      flag = 1;
    }
  }
    if(flag == 0) printf("Stable\n");
  for(i = 0; i < n; i++){
    printf("%c %d\n",card1[i].mark,card1[i].num);
  }
  return 0;
}
 
int Partition(card A[],int p,int r){
 
  int x,i,j;
  card tmp;
 
  x = A[r].num;
  i = p - 1;
 
  for(j = p; j < r; j++){
    if(A[j].num <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;
  
  return i + 1;
}
 
void Quicksort(card A[],int p,int r){
 
  int q;
 
  if(p < r){
    q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}

Measured memory_bytes: 1780
x, a, b = input().split()
x = int(x)
a = int(a)
b = int(b)
if x < a:
  distance_xa = a - x
else:
  distance_xa = x - a
#print("distance_xa =", distance_xa)
if x < b:
  distance_xb = b - x
else:
  distance_xb = x - b
#print("distance_xb =", distance_xb)
if distance_xa > distance_xb:
  print("B")
else:
  print("A")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

bool comp(pair<pair<string,ll>,ll> p1, pair<pair<string,ll>,ll> p2){
    if(p1.fi.fi < p2.fi.fi) return true;
    else if(p1.fi.fi > p2.fi.fi) return false;
    return p1.fi.se > p2.fi.se;
}


int main(){
  	ll n;cin>>n;
    vector<pair<pair<string,ll>,ll>> pa;
    rep(i,0,n){
        string s; ll p;
        cin>>s>>p;
        pa.pb(mp(mp(s,p),i));
    }
    sort(all(pa),comp);
    rep(i,0,n){
        cout << pa[i].se + 1 << ednl;
    }


}


Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  string n;
  cin >> n;
  bool a = false;
  if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
    a = true;
  }

  if (a == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


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

char capitalize(char a){
  int x = a;
  x = a-32;
  char A = x;
  return A;
}
 
int main() {
  string a,b,c;
  cin >>a>>b>>c;
  string ans = "";
  ans += capitalize(a.at(0));
  ans += capitalize(b.at(0));
  ans += capitalize(c.at(0));
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ll a[100005], b[100005], c[100005], n, x[100005], y[100005], z[100005];
	cin >> n;
	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] >> b[i] >> c[i];
	z[0] = c[0];
	y[0] = b[0];
	x[0] = a[0];
	for( int i = 1 ; i < n ; i++ ){
		x[i] = a[i] + max( y[i-1], z[i-1]);
		y[i] = b[i] + max( x[i-1], z[i-1]);
		z[i] = c[i] + max( y[i-1], x[i-1]);
	}
	cout << max( x[n-1], max( y[n-1], z[n-1])) << endl;
	return(0);
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   String s=kbd.next();
   String t=kbd.next();
   int x=0;
    for(int i=0;i<s.length();i++){
   if(s.charAt(i)!=t.charAt(i)){
     x++;
   }
 }
 System.out.println(x);
 }
}


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

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

    int n, ans = 0; cin >> n;
    if(n >= 500){
        ans += (n/500) * 1000;
        n %= 500;
    }
    if(n>=5) ans += (n/5) * 5;
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main(void){
    cin>>s;
    if(s.size()%2!=0){
        cout<<"No\n";
        return 0;
    }
    for(int i=0;i<s.size();i+=2){
        if(!(s[i]=='h'&&s[i+1]=='i')){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    string s;
    cin >> n >> s;
    int max = 0;
    int x = 0;
    rep(i, n) {
        if (s[i] == 'I')
            x++;
        else
            x--;
        chmax(max, x);
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  cin >> s;
  int x = s.size() - 2;
  cout << s[0] <<  x <<  s[s.size()-1] << endl;

  return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> v(n);
    int i = 1;
    int cnt = 0;
    while(cnt<n){
        i+=10;
        if(IsPrime(i)){
            cnt++;
            print(i);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    map<pii,vector<int>> mp;
    int vnum = log2(n)+1;
    int count = 0;
    REP(i,vnum-1) {
        mp[{i+1,i+2}].push_back(pow(2,i));
        mp[{i+1,i+2}].push_back(0);
        count += 2;
    }
    int i = vnum-1;
    while(i > 0) {
        int x = pow(2,i-1);
        if (n - x >= pow(2,vnum-1)) {
            mp[{i,vnum}].push_back(n - x);
            count++;
            n -= x;
        }
        i--;
    }

    cout << vnum << " " << count << endl;
    for(auto p:mp) {
        for (auto v:p.second) {
            cout << p.first.first << " " << p.first.second << " " << v << '\n';
        }
    }

    return 0;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int N;
vector<string> graph;
bool cycle(){
  vector<int> check(N,-1);
  queue<int> q;
  check.at(0)=0;
  q.push(0);
  while(!q.empty()){
    int v=q.front();
    q.pop();
    rep(i,N){
      if(graph.at(v).at(i)=='0')  continue;
      if(check.at(i)==-1){
        check.at(i)=check.at(v)^1;
        q.push(i);
        continue;
      }
      else if(check.at(i)==check.at(v)) return false;
    }
  }
  return true;
}

int solve(){
  int ans=0;
  rep(i,N){
    vector<int> check(N,-1);
    queue<int> q;
    check.at(i)=1;
    q.push(i);
    while(!q.empty()){
      int v=q.front();
      q.pop();
      rep(j,N){
        if(graph.at(v).at(j)=='0')  continue;
        if(check.at(j)!=-1) continue;
        check.at(j)=check.at(v)+1;
        q.push(j);
      }
    }
    rep(j,N)  chmax(ans,check.at(j));
  }
  return ans;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  cin >> N;
  graph.resize(N);
  rep(i,N)  cin >> graph.at(i);

  if(!cycle()) cout << -1 << endl;
  else  cout << solve() << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()

const int MOD = 1000000007;
const int N = 100005;
const double PI =4*atan(1);

bool cmp(pair<ll,ll> a,pair<ll,ll> b){
	return a.f-a.s<b.f-b.s;
}
ll n;
pair<ll,ll> a[N];
ll x,y,ans;
set<ll> ss;




int main(){
    ios::sync_with_stdio(0);
    //freopen("baklava.in","r",stdin);
    cin.tie(0);
    cout.tie(0);
    //start
    cin >> n;
    for(int i=0;i<n;i++){
    	cin >> a[i].f;
    	a[i].s=-1;
    	y+=a[i].f;
    }
    for(int i=0;i<n;i++){
    	cin >> a[i].s;
    	x+=a[i].s;
    }
    if(y<x){
    	cout << -1;
    	return 0;
    }
    sort(a,a+n,cmp);
    ll j=n-1;
    ans=0;
    for(int i=0;i<n;i++){
    	if(a[i].f>=a[i].s)break;
    	ans++;
    	ll k=a[i].s-a[i].f;
    	while(k){
    		if(a[j].f>a[j].s)
    		ss.insert(j);
    		x=min(k,a[j].f-a[j].s);
    		k-=x;
    		a[j].f-=x;
    		if(a[j].f==a[j].s)j--;
    	}
    	
    }
    cout << ans+ss.size();

    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,A,B,C,D,i;string S;
  cin>>N>>A>>B>>C>>D>>S;
  bool x=true,y=false;
  FOR(i,min(A,B),max(C,D)-1)if(S[i]=='#'&&S[i+1]=='#')x=false;
  FOR(i,max(A,B)-1,min(C,D))if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.')y=true;
  if(x&&(C<D||y))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

#define mod 998244353
using ll=long long;

ll fact[200002];
ll inv[200002];
ll invfact[200002];

ll modpow(ll n, ll m=mod-2) {
	ll r=1;
	while(m) r=r*((m%2)?n:1)%mod,n=n*n%mod,m>>=1;
	return r;
}

void calc_fact_invfact(){
  if(fact[0]==0){
    fact[0]=inv[1]=invfact[0]=1;
    for(int i=2;i<200002;i++) inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    for(int i=1;i<200002;i++) fact[i] = fact[i-1]*i%mod,invfact[i]=invfact[i-1]*inv[i]%mod;
  }
}
int nCk(int n,int k){
  if(n<k || k<0) return 0;
  else return fact[n]*invfact[k]%mod*invfact[n-k]%mod;
}

int main(){

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

  ll ans = 0;

  calc_fact_invfact();
  for(int i=0;i<=k;i++) ans += nCk(n-1,i)*(m%mod)%mod*modpow(m-1,n-1-i)%mod;

  cout << ans%mod << endl;

}

Measured memory_bytes: 8284
import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.*;

class Main {

    public static void main(String args[]) {
        Scanner cin = new Scanner(new BufferedInputStream(System.in));
        int T;
        while (cin.hasNext()) {
            BigInteger ans = BigInteger.valueOf(1);
            T = cin.nextInt();
            BigInteger tmp;
            for (int i = 0; i < T; i++) {
                tmp = cin.nextBigInteger();
                //System.out.println(ans.multiply(tmp));
                ans = ans.multiply(tmp).divide(ans.gcd(tmp));
            }
            System.out.println(ans);
        }

    }
}

Measured memory_bytes: 22228
/*           pmaik
    ░▒▓█►─═ Maneesh ═─◄█▓▒░


          ( •̪●)
        ███████]▄▄▄▄▄▄▄▄▃  ▃  ▃ 
    ▂▄▅█████████▅▄▃▂
   [███████████████████]
  ...◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤......  */

#include<bits/stdc++.h>
using namespace std;
#define inf() ifstream cin("in00.txt")
#define onf() ofstream cout("out00.txt")
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<ll,ll>
#define fi first
#define se second
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

ll isprime[1000001];
void sieve()
{
    ll i,j,k;
    isprime[0]=isprime[1]=1;
    for(i=2;i<=sqrt(1000000);i++)
    {
        if(!isprime[i])
        {
            for(j=2*i;j<=1000000;j+=i)
            {
                isprime[j]=1;
            }
        }
    }
}

ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    {  
        ll q = a / m; 
        ll t = m;  
        m = a % m; a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }  
    if(x<0) 
       x+=m0; 
    return x; 
}

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

int main()
{
    fastio;
    string s;
    cin>>s;

    int res=0,cnt=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='R')
        {
            cnt++;
        }
        else
        {
            res=max(res, cnt);
            cnt=0;
        }
    }
    res=max(res, cnt);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3608
from bisect import bisect_right

def sft(n, s):
    d = len(s[0])
    if s and d == n:
        return sorted([int(i) for i in s])
    a = []
    for i, si in enumerate(s):
        for k in range(3):
            ai = si + "357"[k]
            da = len(set(list(ai)))
            if d == n - 2 and da < 2:
                continue
            if d == n - 1 and da < 3:
                continue
            a.append(ai)
    return sft(n, a)

def main():
    n = input()
    d = len(n)
    s = []
    l = list("357")
    for i in range(3, d + 1):
        s += sft(i, l)
    print(bisect_right(s, int(n)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 6236
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a,b;

        a = scanner.nextInt();
        b = scanner.nextInt();
        
        System.out.println(a/b + " " + a%b + " " + String.format("%.8f",(double)a/b));
    }
}



Measured memory_bytes: 26500
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
typedef signed long long ll;
#define FOR(i,to) for(i=0;i<(to);i++)

#define INF 1000000000

int main() {
	int i,j,k,l,r,x,y; string s;
    
    int H;
    int W;
    int K;
    int x1;
    int y1;
    int x2;
    int y2;

    cin >>H>>W>>K>>y1>>x1>>y2>>x2;
    x1--;x2--;y1--;y2--;

    string grid[1000000+10];
    int cost[4][H][W];
    FOR(i,H) cin >> grid[i];
    FOR(k,4) FOR(i,H) FOR(j,W) cost[k][i][j]=INF;

	priority_queue<pair<int,int>> Q;
    
    FOR(i,4){
         cost[i][y1][x1]=0;
         Q.push({0,i*1000000+y1*W+x1});
    }
    while(Q.size()){
		int co=-Q.top().first;
		int dir=Q.top().second/1000000;
		int cy=Q.top().second%1000000/W;
		int cx=Q.top().second%1000000%W;
		Q.pop();

        if(cost[dir][cy][cx]!=co) continue;
        if(cx==x2&&cy==y2){
            cout<<(co+K-1)/K<<endl; 
            return 0;
        }

        FOR(i,4){
            int addX[]= {1,0,-1,0};
            int addY[]= {0,1,0,-1};
            int px=0;
            int py=0;

            px=cx+addX[i];
            py=cy+addY[i];
            if(dir==i){
                if(co+1<cost[i][py][px]){
                  	if(px<0 || px>=W|| py<0 || py>=H||grid[py][px]=='@') continue;
                    cost[i][py][px]=co+1; 
                    Q.push({-cost[i][py][px],i*1000000+py*W+px});
                } 
            }else{
                if((co+K-1)/K*K<cost[i][cy][cx]){
                    cost[i][cy][cx]=(co+K-1)/K*K;
                    Q.push({-cost[i][cy][cx],i*1000000+cy*W+cx});
                } 
            }
        }
    }
    cout<<-1<<endl; 
    return 0;
}





Measured memory_bytes: 55524
#include<bits/stdc++.h>
using ll = long long;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second

const ll mod = 1000000007;

int main()
{
    int n;
    std::cin >> n;
    std::vector<std::string> map(2);
    for(int i = 0; i < 2; i++)std::cin >> map[i];
    int i;
    ll ans;
    if(map[0][0] == map[1][0]){
        i = 1;
        ans = 3;
    }else{
        i = 2;
        ans = 6;
    }
    for(; i < n; i++){
        if(map[0][i] == map[1][i]){
            if(map[0][i - 1] == map[1][i - 1]){
                ans *= 2;
                ans %= mod;
            }else{
                ans *= 1;
            }
        }else{
            if(map[0][i - 1] == map[1][i - 1]){
                ans *= 2;
                ans %= mod;
            }else{
                ans *= 3;
                ans %= mod;
            }
            i++;
        }
    }
    std::cout << ans << std::endl;

}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()

	fmt.Println((n-1)*n/2)
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <cstring>

long long dp[110][2][4];
int main()
{
	char s[110];
	int k;
	scanf("%s%d", &s, &k);
	int n = strlen(s);
	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int less = 0; less < 2; ++less)
		{
			const int D = s[i] - '0';
			for (int j = 0; j < k; ++j)
			{
				for (int d = 0; d <= (less ? 9 : D); ++d)
				{
					dp[i + 1][(less || d < D)][j + (d == 0 ? 0 : 1)] += dp[i][less][j];
				}
			}
			dp[i + 1][less || 0 < D][k] += dp[i][less][k];
		}
	}
	printf("%lld\n", dp[n][0][k] + dp[n][1][k]);
}


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

using namespace std;



int main(int argc, char const *argv[]){
    long int n, _a;
    cin >> n;
    vector<long int> a,b;
    for(int i=0;i<n;i++){
        cin >> _a;
        a.push_back(_a);
        b.push_back(0);
    }
    for(int i=0;i<n;i++){
        b[0] += a[i]; 
    }
    for(int i=0;i<(n/2);i++){
        b[0] -= a[i*2+1]*2;
    }
    cout << b[0];
    for (int i=1;i<n;i++){
        b[i] = a[i-1]*2-b[i-1];
        cout << " " << b[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3052