akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 998244353
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

ll modpow(ll n, ll p){
  ll ret = 1;
  while(p){
    if(p & 1){
      ret *= n;
      ret %= MOD;
    }
    p >>= 1;
    n = n * n;
    n %= MOD;
  }
  return ret;
}

map<ll, ll> modinv_memo;
ll modinv(ll n) {
  if(modinv_memo.count(n)) return modinv_memo[n];
  // ll b = MOD, u = 1, v = 0;
  // while (b) {
  //   ll t = n / b;
  //   n -= t * b; swap(n, b);
  //   u -= t * v; swap(u, v);
  // }
  // u %= MOD;
  // if (u < 0) u += MOD;
  //modinv_memo[n] = u;
  ll ret = modpow(n, MOD-2);
  modinv_memo[n] = ret;
  return ret;
}


int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  if(M == 1){
    if(K == N - 1){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
    return 0;
  }
  ll ret = 0;
  ll it = (M * modpow(M - 1, N - 1)) % MOD;
  REP(k, K + 1){
    ret += it;
    ret %= MOD;
    it *= modinv(k + 1);
    it %= MOD;
    it *= (N - 1 - k);
    it %= MOD;
    it *= modinv(M - 1);
    it %= MOD;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 15560
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[100005];
int n, ans, p, g;
int main() {
	scanf("%s", s);
	n = strlen(s);
	for(int i = 0; i < n; ++i) {
		if (s[i] == 'p') {
			if (p < g) ++p;
			else ++g, --ans;
		} else {
			if (p < g) ++p, ++ans;
			else ++g;
		}
	} printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
using namespace std;
int n;
ll x,a[104];

int w33ha(){
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]<=x){
            x-=a[i];
            a[i]=0;
            ++ans;
        }
    }
    if(x>0){
        bool flag=0;
        for(int i=1;i<=n;i++)if(a[i]!=0)flag=1;
        if(!flag)--ans;
    }
    printf("%d\n",ans);
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d%lld",&n,&x)!=EOF)w33ha();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, l, r;
    cin >> n;

    int ans = 0;
    for (int i=0; i<n; i++) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int L, R;
  cin >> L >> R;

  ll ans = 2020;
  if (2020 < R - L) ans = 0;
  else {
    rep(i,L,R) {
      rep(j,i+1,R) {
        ans = min(ans, i * j % 2019);
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())  
  
while not is_prime(x):
  x+=1
  
print(x)  

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public double toRad(double inA) {
        double buf;
        buf = (inA / 180.0) * Math.PI;
        return buf;
    }

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

        double a, b, c;
        double s, l, h;
        double d;
        a = Double.parseDouble(scan.next());
        b = Double.parseDouble(scan.next());
        c = Double.parseDouble(scan.next());

        s = a * b * 0.5 * Math.sin(app.toRad(c));
        d = Math.sqrt(a * a + b * b - 2.0 * a * b * Math.cos(app.toRad(c)));
        l = a + b + d;
        h = 2.0 * s / a;

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



Measured memory_bytes: 26332
#!/usr/bin/env python
a, b, c, d = map(int, input())

for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            if a + i * b + j * c + k * d == 7:
                def op(x):
                    return '+' if x == 1 else '-'
                print(str(a) + op(i) + str(b) + op(j) + str(c) + op(k) + str(d) + '=7')
                exit()


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   int a,b;cin>>a>>b;
   cout<<a*a-b;
}



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

#define SIZE 100000

int main(void)
{
    int n, q;
    int com, x, y, z;
    int rootX, rootY;
    int diffX, diffY;
    int parent[SIZE + 1];
    int parent_diff[SIZE + 1] = {};
    
    cin >> n >> q;
    
    for(int i = 0; i <= n; ++i)
    {
        parent[i] = i;
    }
    
    for(int i = 0; i < q; ++i)
    {
        cin >> com;
        
        if(com == 0)
        {
            cin >> x >> y >> z;
            
            diffX = 0;
            rootX = x;
            while(parent[rootX] != rootX)
            {
                diffX += parent_diff[rootX];
                rootX = parent[rootX];
            }
            diffY = 0;
            rootY = y;
            while(parent[rootY] != rootY)
            {
                diffY += parent_diff[rootY];
                rootY = parent[rootY];
            }
                
            if(rootX < rootY)
            {
                parent[rootY] = rootX;
                parent_diff[rootY] = diffX - diffY - z;
            }
            else
            {
                parent[rootX] = rootY;
                parent_diff[rootX] = diffY - diffX + z;
            }
        }
        else if(com == 1)
        {
            cin >> x >> y;
            
            diffX = 0;
            rootX = x;
            while(parent[rootX] != rootX)
            {
                diffX += parent_diff[rootX];
                rootX = parent[rootX];
            }
            diffY = 0;
            rootY = y;
            while(parent[rootY] != rootY)
            {
                diffY += parent_diff[rootY];
                rootY = parent[rootY];
            }
            
            if(rootX == rootY)
                cout << diffX - diffY << endl;
            else
                cout << '?' << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3868
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    ll N, D;
    cin >> N >> D;
    vector<ll> X(N), Y(N);
    REP(i, N) cin >> X[i] >> Y[i];
    ll ans = 0;
    REP(i, N)
    {
        ll dd = X[i] * X[i] + Y[i] * Y[i];
        if (dd <= D * D) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6424
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[105];
int u[105];
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &in[i]);

	vector <int> Va;
	while (N) {
		int a = 0;
		for (i = 1; i <= N; i++) if(in[i] == i) a = i;
		if (a == 0) return !printf("-1\n");

		Va.push_back(a);
		for (i = 1; i < a; i++) u[i] = in[i];
		for (i = a + 1; i <= N; i++) u[i - 1] = in[i];
		for (i = 1; i < N; i++) in[i] = u[i];
		N--;
	}
	reverse(all(Va));
	for (auto it : Va) printf("%d\n", it);
	return 0;

}

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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(a);
    scanInt(b);
    if (a <= b){
        cout << a << endl;
    }else{
        cout << (a - 1) << endl;
    }
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = map(int, input().split())
    B = map(int, input().split())

    sum = 0
    ans = 0
    rest = []
    for a, b in zip(A, B):
        if b > a:
            sum += b - a
            ans += 1
        else:
            rest.append(a - b)
    rest.sort(reverse=True)

    if sum <= 0:
        print(0)
        exit()

    for r in rest:
        sum -= r
        ans += 1
        if sum <= 0:
            break
    if sum > 0:
        print(-1)
    else:
        print(ans)
    
if __name__ == '__main__':
    main()


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

int main(){
  int N,M,A,B,x;
  cin>>N>>M>>A>>B;
  vector<int> E;
  for(int i=0;i<N;i++){
    cin>>x;
    if(x>=A)E.push_back(x);
    else break;
  }
  if(N-(int)E.size()<M)
    while(!E.empty()&&E.back()<=B)
      E.pop_back();
  cout<<E.size()<<endl;
  return 0;
}

Measured memory_bytes: 3156
# import math
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque
# from collections import Counter

import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 配列入力の受け取り
arrA = np.array(input().split(),dtype=np.int64)

ans = 0
while len(arrA)>0:
    filter = (arrA%2 == 0)
    ans += len(arrA[filter])
    arrA = arrA[filter]//2

print(ans)

Measured memory_bytes: 13516
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int a, b, c;
  while(cin >> a >> b >> c && (a|b|c)) {
    int N; cin >> N;
    vector<int> v(a+b+c+1, 2);
    vector<int> I(N), J(N), K(N), R(N);
    for(int i=0; i<N; i++) {
      cin >> I[i] >> J[i] >> K[i] >> R[i];
    }
    
    for(int i=0; i<N; i++) {
      if(R[i]) {
        v[I[i]] = v[J[i]] = v[K[i]] = 1;
      }
    }
    for(int i=0; i<N; i++) {
      if(!R[i]) {
        if(v[I[i]]==1 && v[J[i]]==1) v[K[i]] = 0;
        if(v[J[i]]==1 && v[K[i]]==1) v[I[i]] = 0;
        if(v[K[i]]==1 && v[I[i]]==1) v[J[i]] = 0;
      }
    }
    
    for(int i=1; i<=a+b+c; i++) {
      cout << v[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
int cmp(int*a, int*b){ return *a - *b; }

data[10010];
n,i;main(){
    for(;~scanf("%d",data+i++););
    // ¸
    //qsort(data,5,4,"\x8b\6+\1\xc3");
    qsort(data,5,4,cmp);
    for(i=4; i>=0; i--)printf("%d%c",data[i],i?32:10);
    return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        //r(a, 0, "");
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int D = in.nextInt();
        boolean T = false;
        for(;;) {
            C -= B; //T
            if(C <= 0) {
                T = true;
                break;
            }
            A -= D; //A
            if(A <= 0) {
                T = false;
                break;
            }
        }
        if(T) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 27080
#include <iostream>
#include <vector>
using namespace std;
typedef long long llong;
#define int llong

// 隣接リストで使う辺を表す型
struct Edge {
  int to, cost;  // 辺の接続先頂点, 辺の重み
  Edge(int to, int cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<Edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
                // graph[v][i]は頂点vから出るi番目の辺Edge
AdjList graph2;

const int INF = 100000000000;

vector<int> dist; // 最短距離

// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
  dist = vector<int>(n, INF);
  dist[s] = 0; // 開始点の距離は0
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        Edge e = graph[v][k];
        if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
        }
      }
    }
  }
  return false;
}



bool vis[2505];

void dfs(int v){
    vis[v] = true;
    for (int k = 0;k < graph2[v].size(); k ++){
        Edge e = graph2[v][k];
        if(not vis[e.to]){
            dfs(e.to);
        }
    }

}


signed main() {
  int n, m , p;
  cin >> n >> m >> p;

  graph = AdjList(n);
  graph2 = AdjList(n);
  
  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    graph[from-1].push_back(Edge(to-1,  p - cost));
    graph2[to-1].push_back(Edge(from-1,1));
  }

  for (int i = 0; i < n; i++) vis[i] = false;

  dfs(n-1);
  for(int i = 0; i < n; i++){
      if(not vis[i]){
          graph[i].clear();
      }
  }


  if( bellman_ford(n, 0) ){
      cout << -1 << endl;
      return 0;
  }
  

  cout << max(int(0), - dist[n - 1 ]) << endl;
  
  return 0;
}

Measured memory_bytes: 768
n,l= map(int, input().split())
ans=[l]
b=[]

    
if l > 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1
    print(sum(ans)-ans[0])
        
        
        
if l == 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1    
    print(sum(ans))
    
    
if l < 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1
    
    for j in range(n-1):
        b.append(abs(ans[j]))
        
    m = min(b)
    if m == 0:
        print(sum(ans)+m)
    else:
        print(sum(ans)+m-1)


Measured memory_bytes: 3064
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 14052
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int n;
  cin>>n;
  vector<string> st(n);
  rep(i,n){
    cin>>st[i];
  }
  sort(all(st));

  string memo=st[0];
  int cnt=1;
  vector<pair<int,string>> p;
  for(int i=1;i<n;i++){
    if(memo==st[i]){
      cnt++;
    }else{
      p.emplace_back(cnt,memo);
      memo=st[i];
      cnt=1;
    }
  }
  p.emplace_back(cnt,memo);

  sort(all(p));
  reverse(all(p));
  int maxv=p[0].first;
  VS ans;
  for(const auto & x: p){
      if(maxv==x.first){
        ans.emplace_back(x.second);
      }
  }

  sort(all(ans));
  for(const auto & x:ans){
    cout<<x<<endl;
  }
}

Measured memory_bytes: 21488
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //入力を受けとる
    int n,a[100001],b[100001],c[100001];
    std::cin >> n;
    long long sum=0;//答えの出力用
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }for (int i = 0; i < n; i++) {
        std::cin >> c[i];
    }
    //sort
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);

    //bを走査
    for (int i = 0; i < n; i++) {
    //二分探索でa,cを探索
    //aはb以下の個数を、cはb以上の個数を求める
    //それをかけて、sumに足す
        auto it1=lower_bound(a,a+n,b[i]);
        auto it2=upper_bound(c,c+n,b[i]);
        sum+=(it1-a)*(c+n-it2);
    }
    //sumを出力
    std::cout << sum << std::endl;
}


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



int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  int n=s.length();
  int f=0;
  for(int i=0;i<n;i++){
    if(s[i]!=t[i]){
      f++;
    }
  }
  cout<<f<<endl;




}
 
 
 


Measured memory_bytes: 3740
T, N = list(map(int,input().split()))

ans_c = 1001
for i in range(T):
    c, t = list(map(int,input().split()))
    if (N >= t) and (c <= ans_c):
        ans_c = c

if ans_c == 1001:
    print("TLE")
else:
    print(ans_c)

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

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;

  if(N % 2 != 0){
    cout << "No";
    return 0;
  }

  string SubS1 = S.substr(0, N/2); 
  string SubS2 = S.substr(N/2, N/2); 
  
  if(SubS1.compare(SubS2)==0){
    cout << "Yes";
  }
  else{
    cout << "No";  
  }
   
  return 0;
}









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

using namespace std;
int main()
{
    int n,K,Y,X,a;
    cin>>n>>K>>X>>Y;
    if(n<=K)
    {
        a=n*X;
    }
    else if(n>K)
    {
        a=(n-K)*Y+X*K;
    }
    cout<<a<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int house[4][3][10];

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

	int b, f, r, v;
	for (int i = 0;i < n;i++)
	{
		cin >> b >> f >> r >> v;
		house[b-1][f-1][r-1] += v;
	}

	for (int i = 0;i < 4;i++)
	{
		for (int j = 0;j < 3;j++)
		{
			for (int k = 0; k < 10; k++)
			{
				cout << " " << house[i][j][k];
			}
			cout << endl;
		}
		if (i != 3)
			cout << "####################" << endl;
	}


	return 0;
}



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

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

l_min = min(lst)
l_max = max(lst)

m = 10**8

for i in range(l_min,l_max+1):
    c = 0
    
    for j in range(n):
        c += (lst[j]-i)**2
    
    if c < m:
        m = c

print(m)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	FASTIO

	int l, r, d;
	cin >> l >> r >> d;

	int ans = r / d - ((l - 1) / d);
	cout << ans << endl;
	
}

Measured memory_bytes: 3580
n=int(input())
AC=0
WA=0
TLE=0
RE=0
for _ in range(n):
    s=input()
    if s=="AC":
        AC=AC+1
    elif s=="WA":
        WA=WA+1
    elif s=="TLE":
        TLE=TLE+1
    elif s=="RE":
        RE=RE+1

print("AC x", AC)
print("WA x", WA)
print("TLE x", TLE)
print("RE x", RE)


Measured memory_bytes: 69852
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int seven = 0;
		int five = 0;
		while (sc.hasNext()) {
			int num = sc.nextInt();
			if (num == 7) {
				seven++;
			} else if (num == 5) {
				five++;
			}
		}
		if (seven == 1 && five == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 21076
#include<cstdio>
#include<stack>
#include<vector>

using namespace std;

vector<int> vec[101];
bool ch[101]={};
bool visited[101]={};
int dp[101]={};
int maxx = -1;
int maxNODE = -1;


void DFS(int i,int val){
    if(val > maxx)maxx = val;
    dp[i] = max(dp[i],val);
    int len = vec[i].size();
    for (int k=0; k<len; k++) {
        if(!ch[vec[i][k]]){
            visited[vec[i][k]] = true;
            ch[vec[i][k]] = true;
            DFS(vec[i][k],val+1);
            ch[vec[i][k]] = false;
        }
    }
}

int main(){
    maxx = -1;
    maxNODE = -1;
    int n,a,b;
    scanf("%d",&n);
    if(n == 0)return 0;
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a,&b);
        vec[a].push_back(b);
        vec[b].push_back(a);
        if(a>b)if(maxNODE < a)maxNODE = a;
        if(a<b)if(maxNODE < b)maxNODE = b;
    }
    for (int i=1; i<=maxNODE; i++) {
        if(!visited[i]){
            visited[i] = true;
            ch[i] = true;
            DFS(i,1);
            ch[i] = false;
        }
    }
    for (int i=1; i<=maxNODE; i++) {
        if(maxx == dp[i]){
            ch[i] = true;
            DFS(i,1);
            ch[i] = false;
            break;
        }
    }
    printf("%d\n",maxx);
    for (int i=1; i<=maxNODE; i++) {
        visited[i] = false;
        dp[i] = 0;
        vec[i].clear();
    }
    main();
    
    
}

Measured memory_bytes: 2788
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int r,D,x;
    cin >>r>>D>>x;
    for(int i=1;i<=10;i++){
        x=r*x-D;
        cout <<x<<endl;
    }
}

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

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

    string ans="No";

    for (int i=1; i<3; i++) {
        if (s.at(i-1) != s.at(i)) ans = "Yes";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
      Scanner input = new Scanner(System.in);
      int a = input.nextInt();
      int b = input.nextInt();
       if(a>9 || b>9){
         	System.out.println(-1);
       } 
      	else{
          System.out.println(a*b);
        }  
    }
} 

Measured memory_bytes: 27112
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define BITS 8

void show_bin(int v) {
  for (int i = 0; i < BITS; i++) {
    printf("%d", (v >> (BITS - i - 1)) & 1);
  }
  puts("");
}

int count_bin(int v) {
  int n = 0;
  for (int i = 0; i < BITS; i++) {
    n += (v >> (BITS - i - 1)) & 1;
  }
  return n;
}

bool ok(int v, const vector<int>& pats) {
  if (pats.size() > 30)
    abort();

  for (int i = 0; i < (1<<pats.size()); i++) {
    int n = v;
    for (int j = 0; j < pats.size(); j++) {
      if ((i >> j) & 1) {
        n ^= pats[j];
      }
    }
    if (n == 0)
      return true;
  }
  return false;
}

int solve(int v) {
  vector<int> pats;
  for (int i = BITS; i > 1; i--) {
    for (int j = 0; j <= BITS - i; j++) {
      pats.push_back(((1 << i) - 1) << j);
    }
    if (ok(v, pats))
      return i;
  }
  return 1;
}

int solve2(int v) {
  int ans = (BITS + 1) / 2;
  for (int i = 0; i < 2; i++) {
    int d = 0;
    for (int j = 0; j < BITS / 2; j++) {
      if ((v >> j) & 1) {
        d = j + 1;
      }
      if ((v >> (BITS - j - 1)) & 1) {
        d = j + 1;
      }
    }

    int a = BITS - d;
    if ((BITS & 1) && (v >> (BITS / 2)) & 1)
      a = (BITS + 1) / 2;
    if (ans < a)
      ans = a;

    v ^= ((1 << BITS) - 1);
  }
  return ans;
}

int main() {
#if TEST
  for (int i = 0; i < (1 << BITS); i++) {
    show_bin(i);

    int a = solve(i);
    int a2 = solve2(i);

    int n = count_bin(i);
    if (n < BITS / 2)
      n = BITS - n;
    printf("%d %d\n", a2, a);
    if (a2 != a)
      abort();
  }
  return 0;
#endif

  string s;
  cin >> s;
  int ans = (s.size() + 1) / 2;
  for (int i = 0; i < 2; i++) {
    int d = 0;
    for (int j = 0; j < s.size() / 2; j++) {
      if (s[j] == '1' || s[s.size()-j-1] == '1') {
        d = j + 1;
      }
    }

    int a = s.size() - d;
    if ((s.size() & 1) && s[s.size() / 2] == '1')
      a = (s.size() + 1) / 2;
    if (ans < a)
      ans = a;

    for (int j = 0; j < s.size(); j++) {
      s[j] ^= 1;
    }
  }
  printf("%d\n", ans);
}



Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
using namespace std;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt = 0;

void Merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;

	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];

	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;

	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void Sort(int A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		Sort(A, n, left, mid);
		Sort(A, n, mid, right);
		Merge(A, n, left, mid, right);
	}
}
int main() {
	int *A, n, i;
	cnt = 0;

	scanf("%d", &n);
	A = new int[n];
	for(i = 0; i < n; i++) scanf("%d", &A[i]);

	Sort(A, n, 0, n);

	for (i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", A[i]);
	}

	printf("\n");

	cout << cnt << endl;


	return 0;
}



Measured memory_bytes: 7128
#include<bits/stdc++.h>
#define ll long long
#define thekingisborn ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ld  long double
#define f first
#define se second
#define pb push_back
#define maxn 200005
#define mod 1000000007
#define pi 3.14159265359

using namespace std;

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

/*ll power(ll a,ll n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    a = a%mod;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
ll gcd(ll a,ll b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
/*int root(int x)
{
    while(par[x] != x)
    x = par[x];
    return x;
}
void dsu(int x,int y)
{
  if(root(x) == root(y))return;
  par[root(y)] = root(x);
  return;
}
void dfs(int x)
{
    done[x] = true;
    for(int i=0;i<int(adj[x].size());++i)
    {
        int y = adj[x][i];
        if(!done1[y])
        dfs(y);
    }
}*/
vector<int>v(maxn);
int ans;

int main()
{
    thekingisborn;
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;++i)
    {
        cin >> v[i];
    }
    for(int i=0;i<n;i+=k-1)
    {
        if(i<n-1)++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
     int x;
    scanf("%d",&x);
        x=x%10;
        if(x==3)
        {
            printf("bon");

        }
        else if(x==2 || x==4 || x==5 || x==7 || x==9)
        {
            printf("hon");

        }
        else
        {
            printf("pon");

        }
    return 0;
}


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

int H,W;

bool grid[110][110];

int dp[110][110][2];
const int INF = 100000;


int main()
{
    scanf("%d%d",&H,&W);

    for(int i=0;i<H;i++)
    {
        char str[110];
        scanf("%s",str);
        for(int j=0;j<W;j++)
        {
            grid[i][j] = (str[j] == '.');
        }
    }

    dp[0][0][0] = (grid[0][0] ? 0 : INF);
    dp[0][0][1] = (grid[0][0] ? INF : 1);

    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(i==0 && j==0) continue;

            dp[i][j][0] = INF;
            dp[i][j][1] = INF;

            if(grid[i][j])
            {
                if(i>0)
                {
                    dp[i][j][0] = min(dp[i][j][0], dp[i-1][j][0]);
                    dp[i][j][0] = min(dp[i][j][0], dp[i-1][j][1]);
                }
                if(j>0)
                {
                    dp[i][j][0] = min(dp[i][j][0], dp[i][j-1][0]);
                    dp[i][j][0] = min(dp[i][j][0], dp[i][j-1][1]);
                }
            }
            else
            {
                if(i>0)
                {
                    dp[i][j][1] = min(dp[i][j][1], dp[i-1][j][0] + 1);
                    dp[i][j][1] = min(dp[i][j][1], dp[i-1][j][1]);
                }
                if(j>0)
                {
                    dp[i][j][1] = min(dp[i][j][1], dp[i][j-1][0] + 1);
                    dp[i][j][1] = min(dp[i][j][1], dp[i][j-1][1]);
                }
            }
        }
    }

    if(grid[H-1][W-1])
    {
        printf("%d", dp[H-1][W-1][0]);
    }
    else
    {
        printf("%d", dp[H-1][W-1][1]);
    }

    return 0;
}


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

using lli = long long int;

using namespace std;

int main() {
    std::string S, T;
    cin >> S >> T;

    int ans = 0;
    for (lli i = 0; i < 3; i++) {
        if (S[i] == T[i]) { ++ans; }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin >> t;
    while (t--) {
        int a,b,c;
        cin>>a>>b>>c;
        int count=0;
        for(int i=a;i<=b;i++){
            if(i%c==0){
                count++;
            }
        }
        cout<<count<<endl;
    }
    return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  for(int i=0;i<N;i++)
    cin >> vec.at(i);
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int count=0;
  for(int j=0;j<N;j++)
    count+=vec.at(j);
  if(vec.at(M-1)*4*M>=count)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int


int main(){
    vector<int> num;
    int n;
    cin >> n;
    vector<string> s(n);
    ll sum = 0;
    in_arr(string, s, n);
    num.resize(5);
    fill(num.begin(), num.end(), 0);
    repi(i, s){
        if((*i)[0] == 'M')
            num[0]++;
        else if((*i)[0] == 'A')
            num[1]++;
        else if((*i)[0] == 'R')
            num[2]++;
        else if((*i)[0] == 'C')
            num[3]++;
        else if((*i)[0] == 'H')
            num[4]++;
    }
    for(int i = 0; i < 33; i++){
        int bits = 0;
        int tmp = i;
        while(tmp > 0){
            bits += tmp & 1;
            tmp = tmp >> 1;
        }
        if(bits != 3)
            continue;
        ll prod = 1;
        for(int j = 0; j < 5; j++){
            if((i & (1 << j)) != 0){
                prod *= num[j];
            }
        }
        sum += prod;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6144
n=int(input())
a=list(map(int, input().split()))
sum_now=a[0]
sum_before=-a[0]
count_1=0
count_2=0
for i in range(n):
    if sum_now*sum_before>=0:
        if sum_before==0:
            sum_now=-a[1]/abs(a[1])
            count_1+=1
        else:
            count_1+=abs(int(sum_now))+1
            sum_now=-sum_before/abs(sum_before)
    if i!=n-1:
        sum_before=sum_now
        sum_now=sum_now+a[i+1]

sum_now=a[0]
sum_before=-a[0]
if sum_before==0:
    sum_now=a[1]/abs(a[1])
    sum_before=-sum_now
    count_2+=1
else:
    count_2+=abs(int(sum_now))+1
    sum_now=-sum_now/abs(sum_now)
    sum_before=-sum_now
for i in range(n):
    if sum_now*sum_before>=0:
        if sum_before==0:
            sum_now=a[1]/abs(a[1])
            count_2+=1
        else:
            count_2+=abs(int(sum_now))+1
            sum_now=-sum_before/abs(sum_before)
    if i!=n-1:
        sum_before=sum_now
        sum_now=sum_now+a[i+1]
print(min(count_1, count_2))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ALL(c) begin(c),end(c)
#define SZ(c) ((int)c.size())
const int INF=1001001001001001001ll;
using pii = pair<int,int>;

signed main() {
    int X,A,B;
    cin>>X>>A>>B;
    if(B<=A) {
        cout<<"delicious"<<endl;
    }
    else if(B<=A+X) {
        cout<<"safe"<<endl;
    }
    else {
        cout<<"dangerous"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[][] nums = new int[n][3];
        for(int i = 0; i < n; i++) {
            for(int k = 0; k < 3; k++) {
                nums[i][k] = input.nextInt();
            }
        }
        int[][] dp = new int[n + 1][3];
        Arrays.fill(dp[0], 0);
        for(int i = 1; i <= n; i++) {
            for(int k = 0; k < 3; k++) {
                for(int h = 0; h < 3; h++) {
                    if(h == k) {
                        continue;
                    }
                    dp[i][k] = Math.max(dp[i - 1][h] + nums[i - 1][k], dp[i][k]);
                }
            }
        }
        System.out.println(Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2])));
    }
}


Measured memory_bytes: 96696
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 問題文============================================================
 
 =================================================================
 
 解説=============================================================
 
 ================================================================
 */
ll ans = 0;
void dfs(ll n,ll Y,ll cnt){
    if(2*n <= Y){
        dfs(2*n,Y,cnt+1);
    }else{
        ans = max(ans,cnt);
    }
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll X,Y; cin >> X >> Y;
    dfs(X,Y,1);
    cout << ans << endl;
    return 0;
}


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

int main(void) {
    int n;
    cin >> n;

    int A[n];
    for (int i = 0; i < n; ++i)
        cin >> A[i];
    int n_2 = 0;
    int n_1 = abs(A[0] - A[1]);
    int sum = 0;
  	if (n == 2)
      sum = n_1;
    for (int i = 2; i < n; ++i) {
        sum = min(n_1 + abs(A[i] - A[i - 1]),
                  n_2 + abs(A[i] - A[i - 2]));
        n_2 = n_1;
        n_1 = sum;
    }

    cout << sum << endl;
}


Measured memory_bytes: 3980
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<cctype>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;

int gcd(int x, int y) {
	int r;
	while (y > 0) {
		if (y > x)swap(x, y);
		r = x%y;
		x = y;
		y = r;
	}
	return x;
}

int main(void) {
	int a, b; cin >> a >> b;
	cout << gcd(a, b) << endl;

}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{	rtn
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}


void print(int val) {
	cout << val << endl;
	exit(0);
}
void solve()
{
	cin >> n;
	int  x = 0;
	lop(i, 0, n) cin >> arr[i], x ^= arr[i];

	if (!x) print(0);
	else
	{
		int y = (x ^ arr[0] ^ arr[1]);
		int sum = arr[0] + arr[1];
		int rxor = y;
		if ( (sum - rxor) % 2 ) print(-1);
		else
		{
			int andd = (sum - rxor) / 2;
			int a = 0, b = 0;
			vector<int> vec;
			lop(i, 0, 50)
			{
				int p = (1LL << i);
				if ( (andd & p) ) a += (p), b += (p);
				else
				{
					if ( (rxor & p) )
					{
						vec.pb(p);
					}
					else;
				}
			}

			reverse(all(vec));
			for (auto &i : vec)
			{
				if ( a + i > arr[0] ) b += i;
				else a += i;
			}

			// bug(a, b);

			if ( a <= 0 or a > arr[0] or b < arr[1] or a + b != arr[0] + arr[1]) print(-1);
			print(arr[0] - a);
		}
	}

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





Measured memory_bytes: 3624
import java.util.Scanner;

class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int a = scan.nextInt();
      int b = scan.nextInt();
      scan.close();
      
      if(a%2==1&&b%2==1){
        System.out.println("Yes");
      }else{
      	System.out.println("No");
      }
    }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[105][100005];


int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  rep(i,105)rep(j,100005)dp[i][j]=0;
  dp[0][0]=1;
  rep(i,n){
    vector<mint> v(k+5,0);
    v[0]=0;
    rep(j,k+1){
      v[j+1]=v[j]+dp[i][j];
    }
    rep(j,k+1){
      if ((j-a[i])<0) dp[i+1][j]=v[j+1];
      else dp[i+1][j]=v[j+1]-v[j-a[i]];
    //  cout<<dp[i+1][j]<<"i"<<i+1<<"j"<<j<<endl;
    }

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






}


Measured memory_bytes: 86340
N = int(input())
P = list(map(int,input().split()))
ans = 'NO'
Pre = sorted(P)
pi = -1
pj = -1
for i in range(N):
  if P[i] != Pre[i]:
    pi = i
    break
for j in range(pi+1,N):
  if P[j] != Pre[j]:
    pj = j
    break
if pi != -1 and pj != -1:
  P[pi], P[pj] = P[pj],P[i]
  
if P == Pre:
  ans = 'YES'
print(ans)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

template<typename T>
vector<vector<T>> rotate(const vector<vector<T>> &ban, int k){
  // k回反時計回りに90度回転させる 負の数でもok
  int n = ban.size();
  int m = ban[0].size();

  k = ((k%4)+4)%4;

  vector<vector<T>> res;
  if(k%2){
    res.assign(m, vector<T>(n));
  }else{
    res.assign(n, vector<T>(m));
  }

  if(k==0){
    REP(i, n){
      REP(j, m){
        res[i][j] = ban[i][j];
      }
    }
  }else if(k==1){
    REP(i, m){
      REP(j, n){
        res[i][j] = ban[j][m-1-i];
      }
    }
  }else if(k==2){
    REP(i, n){
      REP(j, m){
        res[i][j] = ban[n-1-i][m-1-j];
      }
    }
  }else{
    REP(i, m){
      REP(j, n){
        res[i][j] = ban[n-1-j][i];
      }
    }
  }
  return res;
}

vector<vector<int>> left_ones(const vector<vector<int>> &ban){
  // 左側に連続する1の数を数える
  int n = ban.size();
  int m = ban[0].size();
  vector<vector<int>> res(n, vector<int>(m, 0));

  REP(i, n){
    int cnt = 0;
    REP(j, m){
      res[i][j] = cnt;
      if(ban[i][j]){
        cnt++;
      }else{
        cnt = 0;
      }
    }
  }

  return res;
}

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

    int H, W;
    cin >> H >> W;

    using board = vector<vector<int>>;
    board x(H, vector<int>(W));
    REP(i, H){
    	string S;
    	cin >> S;
    	REP(j, W){
    		x[i][j] = (S[j]=='.' ? 1 : 0);
    	}
    }

    vector<board> z(4);
    REP(i, 4){
    	z[i] = rotate(left_ones(rotate(x, i)), -i);
    }

    ll res = 0;
    REP(i, H){
    	REP(j, W){
    		if(x[i][j] == 0) continue;
    		ll tmp = 0;
    		REP(k, 4){
    			tmp += z[k][i][j];
    		}
    		res = max(res, tmp);
    	}
    }
    cout << res+1 << endl;
    return 0;
}

Measured memory_bytes: 110208
from collections import defaultdict

def main():
    D, G = map(int, input().split())
    problem = []
    for _ in range(D):
        p, c = map(int, input().split())
        problem.append([p,c])
    ans = float('inf')
    for i in range(2**D):
        all_solve = []
        others = []
        score = 0
        cnt = 0
        for j in range(D):
            if (i >> j) & 1:
                all_solve.append(j)
                cnt += problem[j][0]
                score += 100 * (j+1) * problem[j][0] + problem[j][1]
            else:
                others.append(j)
        if score >= G:
            ans = min(cnt,ans)
            continue

        others.sort(reverse=True)
        for k in others:
            for m in range(problem[k][0]):
                score += 100*(k+1)
                cnt += 1
                if score >= G:
                    ans = min(ans, cnt)
                    break
            else:
                score += problem[k][1]
                if score >= G:
                    ans = min(ans, cnt)
            if score >= G:
                break
        
        if score >= G:
            ans = min(ans, cnt)

        
    print(ans)    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9412
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();
		
		if (n%x == 0) {
			System.out.println((n / x)  * t);
		} else {
			System.out.println(((n / x) + 1) * t);
		}
		
	}
}


Measured memory_bytes: 35616
#include <stdio.h>

int main (){
	int N,K,x=1;
	
	scanf ("%d",&N);
	scanf ("%d",&K);

	for (int i=0; i<N; i++){

		if (x*2 > x+K){
		x =	x + K;
		
		}
		else {
		x =	x * 2; 
		
		}	
	}
	printf ("%d",x);
	
	return 0;
}

Measured memory_bytes: 3228
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "functional"
#include "cmath"

using namespace std;

struct norm_str_prd {
    string norm_str = "a";
    int count = 0;
};

vector<norm_str_prd> get_norm_str_prd_vect(
        int N, vector<norm_str_prd> v=vector<norm_str_prd>(), int i=0) {
    if (i == 0) {
        return get_norm_str_prd_vect(N, vector<norm_str_prd>{norm_str_prd()}, 1);
    }

    if (i == N) {
        return v;
    }

    vector<norm_str_prd> next_norm_str_prd_vect;
    for (auto p : v) {
        for (int j = 0; j <= p.count + 1; ++j) {
            string next_norm_str = p.norm_str;
            next_norm_str.push_back('a' + j);
            next_norm_str_prd_vect.push_back(
                    norm_str_prd{next_norm_str , max(j, p.count)});
        }
    }
    return get_norm_str_prd_vect(N, next_norm_str_prd_vect, ++i);
}

int main() {
    // get values from input
    int N;
    cin >> N;

    // main procedure
    vector<norm_str_prd> norm_str_prd_vect = get_norm_str_prd_vect(N);

    // output
    for (auto p : norm_str_prd_vect) {
        cout << p.norm_str << endl;
    }
    return 0;
}


Measured memory_bytes: 11760