akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll n,k,r,s,p;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    string tt="";
    ll ans=0;
    for (int i=0;i<t.size();i++)
    {
        if (t[i]=='r')
            tt+='p';
        if (t[i]=='p')
            tt+='s';
        if (t[i]=='s')
            tt+='r';
    }
    for (int i=0;i<k;i++)
    {
     string f="";
     int j=i;
     while (j<n)
     {
         f+=tt[j];
         j+=k;
     }
     int ii=0,jj=0;
     vector <pair <char,ll> > c;
     while (ii<f.size())
     {
         int cnt=0;
         while (jj<f.size()&&f[ii]==f[jj])
             cnt++,jj++;
         c.pb({f[ii],cnt});
         ii=jj;
     }
     for (int j=0;j<c.size();j++)
     {
         if (c[j].first=='r')
         {
             ans+=r*((c[j].second+1)/2);
         }
         if (c[j].first=='p')
         {
             ans+=p*((c[j].second+1)/2);
         }
         if (c[j].first=='s')
         {
             ans+=s*((c[j].second+1)/2);
         }
     }

    }
    cout<<ans;



}

Measured memory_bytes: 2824
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // board[i][j]: 迷路
        char[][] board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }
        
        // visited[i][j]: 当該マスを既に通ったか否か
        boolean[][] visited = new boolean[h][w];
        
        // 上下左右
        int[] dx = new int[]{1, 0, -1, 0};
        int[] dy = new int[]{0, 1, 0, -1};
        
        int[][] newboard = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                newboard[i][j] = -1;
            }
        }
        
        int now = 1;
        char nowchr = board[0][0];
        for (int i = 0; i < h; i++) {
            if (board[i][0] != nowchr) {
                now++;
                nowchr = board[i][0];
            }
            newboard[i][0] = now;
        }
        now = 1;
        nowchr = board[0][0];
        for (int i = 0; i < w; i++) {
            if (board[0][i] != nowchr) {
                now++;
                nowchr = board[0][i];
            }
            newboard[0][i] = now;
        }
        
        for (int i = 1; i < h; i++) {
            for (int j = 1; j < w; j++) {
                int a = newboard[i-1][j];
                if (board[i][j] != board[i-1][j]) a++;
                int b = newboard[i][j-1];
                if (board[i][j] != board[i][j-1]) b++;
                newboard[i][j] = Math.min(a, b);
            }
        }
        
        int group = newboard[h-1][w-1];
        if (board[0][0] == '.') {
            System.out.println(group / 2);
        } else {
            System.out.println((group+1) / 2);
        }
    }
}

Measured memory_bytes: 24360
package main
 
import (
  "fmt"
  "strings"
)
 
func main() {
  var s string
  fmt.Scanf("%s", &s)
  
  ans := "No"
  if strings.Replace(s, "hi", "", -1) == "" {
    ans = "Yes"
  }
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1836
#include <iostream>
#include <vector>

int main() {

    // The frog jumps from stone `i` to either stone `i+1` or `i+2`. The cost of doing so is
    // equal to the difference in heights of the two stones, |h[j] - h[i]| when jumping to
    // stone `j` from stone `i`.
    //
    // Consider any generic stone `i` that the frog is on. Let DP[i] equal the minimum possible
    // cost of jumping to stone `i`. So the cost of jumping from stone `i-2` must be equal to
    // `DP[i-2] + abs(h[i]-h[i-2])`, and likewise with i-1: `DP[i-1] + abs(h[i]-h[i-2])`. So the
    // cost to get to stone `i` must be the minimum of those two!

    int n, k;
    std::cin >> n;
    std::cin >> k;
    std::vector<int> heights(n);
    for (int i = 0; i < n; i++) {
        std::cin >> heights[i];
    }

    std::vector<int> dp(n);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        int minval = 2e9;
        for (int j = 1; j <= k; j++) {
            if (i-j < 0) {
                continue;
            }
            minval = std::min(minval, dp[i-j] + std::abs(heights[i]-heights[i-j]));
        }

        dp[i] = minval;
    }

    std::cout << dp[n-1];


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD =1000000007;

     signed main(){
int n;
cin>>n;
vector<int> hen[n];
int gr[n]={};
int p[n];
for(int i=0;i<n;i++){
    cin>>p[i];p[i]--;
    hen[p[i]].push_back(i);
}
queue<int> que;
int w[n];
for(int i=0;i<n;i++){
    w[i]=hen[i].size();
    if(w[i]==0)que.push(i);
}
while(!que.empty()){
    int t=que.front();
    que.pop();
    priority_queue<int,vector<int>,greater<int>> pr;
    for(auto&& i:hen[t])pr.push(gr[i]);
    while(!pr.empty()){
        if(pr.top()==gr[t])gr[t]++;
        pr.pop();
    }
    w[p[t]]--;
    if(w[p[t]]==0)que.push(p[t]);
}
int t=0;
while(w[t]==0)t++;
int s=t,l;
int count=0;
while(true){
    if(s==t)count++;
     l=0;
    priority_queue<int,vector<int>,greater<int>> pr;
    for(auto&& i:hen[s])pr.push(gr[i]);
    while(!pr.empty()){
        if(pr.top()==l)l++;
        pr.pop();
    }
    if(count==3)break;
    gr[s]=l;
    s=p[s];
}
if(gr[t]==l)cout<<"POSSIBLE"<<endl;
else cout<<"IMPOSSIBLE"<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 18208
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

dp = [[0] * w for _ in range(h)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(h):
    for j in range(w):
        if i + 1 < h and a[i + 1][j] == '.':
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod
        if j + 1 < w and a[i][j + 1] == '.':
            dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod

print(dp[h - 1][w - 1])

Measured memory_bytes: 51460
def somesums(x):
    x = int(x)
    return x%10 + x%100//10 + x%1000//100 + x%10000//1000 + x%100000//10000
N,A,B = map(int,input().split())
i = 1
ans = 0
for i in range(N+1):
    if(A<=somesums(i)<=B):ans+=i
print(ans)


Measured memory_bytes: 2940
import sys
from collections import *
import heapq
import math

import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())

ans=0
# cnt=0
if n==1:
    print(0)
    quit()
for i in range(int(n**0.5)):
    x=(n-(i+1))//(i+1)
    if n//x==n%x:
        ans+=x
    # print(n//cnt,cnt)
print(ans)

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

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

int main()
{

    //ifstream cin("input.txt");
    //ofstream cout("triangles.out");

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int k, s;
    cin >> k >> s;

    int ans = 0;
    for (int x = 0; x <= k; ++x) {
        for (int y = 0; y <= k; ++y) {
            int z = s - x - y;
            if (z >= 0 && z <= k) {
                ++ans;
            }
        }
    }

    cout << ans << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
} 
vl trans(string s){
    vl ss(s.size()+1);
    ss[0]=0;
    string now;
    rep(i,s.size()){
        now+=s[i];
        if(now.size()==1){
            if(now[0]=='A')ss[i+1]=1;
            else ss[i+1]=-1;
        }
        else{
            if(now=="AA")ss[i+1]=-1,now="B";
            else if(now=="BB")ss[i+1]=1,now="A";
            else ss[i+1]=0,now="";
        }
    }
    return ss;
}
int main(){
    string s,t;cin >> s >> t;
    vector<ll> ss=trans(s),tt=trans(t);
    //for(auto p:ss)cout << p <<" ";cout << endl;
    //for(auto p:tt)cout << p <<" ";cout << endl;
    ll q;cin >> q;
    while(q--){
        ll a,b,c,d;cin >> a >> b >> c >> d;
        a--;b--;c--;d--;
        ll p=ss[b+1]-ss[a],q=tt[d+1]-tt[c];
        if(p==2)p=-1;
        if(p==-2)p=1;
        if(q==2)q=-1;
        if(q==-2)q=1;
        if(p==q)cout << "YES" <<endl;
        else cout <<"NO" <<endl;
    }
}

Measured memory_bytes: 5004
n, m = gets.chomp.split.map(&:to_i)
arr = Array.new(m)
m.times do |i|
	arr[i] = gets.chomp.split.map(&:to_i)
end

ken = Array.new(n+1).map{Array.new()}
arr.each do |pp, yy|
	ken[pp] << yy
end

hash = {}
(n+1).times do |i|
	ken[i] = ken[i].sort
	ken[i].length.times do |j|
		hash[ken[i][j]] = i.to_s.rjust(6, "0") + (j+1).to_s.rjust(6, "0")
	end
end

arr.each do |pp, yy|
	puts hash[yy]
end


Measured memory_bytes: 41064
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val A = na(N)

    val dp = Array.ofDim[Long](2, K + 2)
    dp(0)(0) = 1
    REP(N) { i =>
      val x = i % 2
      import java.util
      util.Arrays.fill(dp(x^1), 0)

      REP(K + 1) { k =>
        // kから配る
        val dist = min(k + A(i) + 1, K + 1)
        dp(x ^ 1)(k) = (dp(x ^ 1)(k) + dp(x)(k)) % MOD
        dp(x ^ 1)(dist) = (MOD + dp(x^1)(dist) - dp(x)(k)) % MOD
      }

      REP(K + 1) { j =>
        dp(x ^ 1)(j + 1) = (dp(x ^ 1)(j + 1) + dp(x ^ 1)(j)) % MOD
      }
    }

    val ans = dp(N % 2)(K)
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


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

class TSort{
public:
  int V;
  vector<unordered_set<int> > in,out;
  vector<int> tp;
  TSort():V(0){}
  TSort(int V):V(V),in(V),out(V){}
  
  void add_edge(int from,int to){
    assert(from >= 0 && to >= 0);
    assert(from < V && to < V);
    out[from].insert(to);
    in[to].insert(from);
  }

  vector<int> dfs(){
    vector<int> visited(V,0);
    
    function<void(int)> dfs = [&](int pos){
      if(visited[pos]++) return;
      for(int nx:out[pos]) dfs(nx);
      tp.push_back(pos);
    };
    
    tp.clear();
    for(int i=0;i<V;i++) dfs(i);
    reverse(tp.begin(),tp.end());
    return tp;
  }

  vector<int> bfs(){
    auto tmp = in;
    tp.clear();
    queue<int> Q;
    for(int i=0;i<V;i++)if(in[i].empty()) Q.push(i);
    
    while(!Q.empty()){
      int v = Q.front();Q.pop();
      tp.push_back(v);
      for(int nx:out[v]){
        if(in[nx].size() == 1) Q.push(nx);
        assert(in[nx].count(v));
        in[nx].erase(v);
      }     
    }
    for(int i=0;i<V;i++) if(!in.empty()) tp.clear(); // exist loop
    tmp = in;
    return tp;
  }
};

class UF{
public:
  int V;
  vector<int> par,rnk,sz;
  UF(){}
  UF(int V):V(V),par(V),rnk(V,0),sz(V,1){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y])par[x]=y, sz[y] += sz[x];
    else{
      par[y]=x;
      sz[x] += sz[y];
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}

  int size(int x){return sz[find(x)];}
};

typedef pair<int,int> P;

int N, M, ans[100005];
vector<int> G[100005];

signed main(){
  
  cin>>N>>M;
  
  TSort ts(N);
  
  for(int i=0;i<N+M-1;i++){
    int a, b;
    cin>>a>>b;
    ts.add_edge(a-1,b-1);
    G[a-1].push_back(b-1);
  }
  
  vector<int> ord = ts.dfs();
  
  map<int,int> memo;
  
  for(int i=0;i<N;i++) memo[ord[i]] = i;
  
  memset(ans,-1,sizeof(ans));
  
  UF uf(N);
  
  for(int i=ord.size()-1;i>=0;i--){
    
    int idx = ord[i];
    
    vector<P> G2;
    
    for(auto p : G[idx] ) G2.push_back(P(memo[p],p));
    
    sort(G2.begin(), G2.end());
    
    for(auto tmp : G2 ){

      int p = tmp.second;
      
      if( uf.same( idx, p ) ) continue;
      
      uf.unite( idx, p );
      
      ans[p] = idx;
      
    }
    
  }
  
  for(int i=0;i<N;i++){
    cout<<ans[i]+1<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 43876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//素因数分解
map<int,int> prime_factor(int n){
    map<int,int> res; //res[2] = 4は、素因数2が4個あることを表す
    for(int i = 2;i*i <= n;i++){//小さい素因数から順に割っていく
        while(n % i == 0){//i = 2が素因数だとすると、割り切れる限り2で割る
            res[i]++;//割り切れる回数をres[i]に格納
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;//ループ処理の結果、nが素数の場合、res[n] = 1とする。
    return res;
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
 
  int count = 0;
 // cout << (int)S[2] - 48 << endl;
  for(int j = 0; j < 1000;j++){
      int a = j/100;
      int b = (j/10)%10;
      int c = j%10;
      /*bool flag0 = false;//Sにaがあるか
      bool flag1 = false;
      bool flag2 = false;*/
      vector<int> v = {a,b,c};
    int f = 0;
    for(int i = 0;i<N;i++){
      if((int)S[i] - 48 == v[f]) f++;//S[i]とvの先頭が一致するたびに、見るべきvの位置を後ろにずらす
      
      if(f == 3){
        count++;
        break;
      }
    }
  }
  cout << count << endl;
 }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
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*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,a[MN+5],mn=1e9,mx=0;
int main()
{
	n=read();
	for(int i=1;i<=n;++i) a[i]=read(),mx=max(mx,a[i]),mn=min(mn,a[i]);
	if(mx-mn>1) return 0*puts("No");
	if(mx==mn) return 0*puts((mx==n-1||mx<=n/2)?"Yes":"No");
	int num1=0,num2=0;
	for(int i=1;i<=n;++i) if(a[i]==mn) ++num1; else ++num2;
	if(mx<num1||mn>num2/2+num1-1||num2<2||mn<num1) return 0*puts("No");
	puts("Yes"); 
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
 
int n, m;
int a[100010], b[100010];
int q;
int v[100010], d[100010], c[100010];
int color[100010][12];
vector<int> G[100010];
 
void dfs(int u, int p, int cnt, int dist, int iro){
	if(cnt >= dist) return;
	for(auto v : G[u]) {
		if(v == p) continue;
		if(color[v][dist - cnt - 1] != 0) continue;
		for (int i = dist - cnt - 1; i >= 0; --i) {
			if(color[v][i] == 0)color[v][i] = iro;
			//else break;
		}
		
		dfs(v, u, cnt + 1, dist, iro);
	}
}
 
int main(void) {
	cin >> n >> m;
	rep(i, m) cin >> a[i] >> b[i];
	cin >> q;
	rep(i, q) cin >> v[i] >> d[i] >> c[i];
	rep(i, m) G[a[i]].pb(b[i]), G[b[i]].pb(a[i]);
 
	for (int i = q - 1; i >= 0; --i) {
		if(color[v[i]][d[i]] != 0) continue;
		for (int j = d[i]; j >= 0; --j) {
			if(color[v[i]][j] == 0) color[v[i]][j] = c[i];
			//else break;
		}
		
		dfs(v[i], -1, 0, d[i], c[i]);
	}
	// reps(i, 1, n + 1){rep(j, 12)printf("%d ", color[i][j]); printf("\n");}
	reps(i, 1, n + 1)printf("%d\n", color[i][0]);
	return 0;
}
 

Measured memory_bytes: 13176
from collections import Counter
def main():
    S = list(map(int, input()))
    S = S[::-1]
    T = [0] * len(S)
    P = 2019
    T[0] = S[0] % P
    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P
    counter = Counter(T)
    ans = sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]
    print(ans)

if __name__ == '__main__':
    main()

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

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

    long long x;
    cin >> x;

    long long count = 0;
    count = x % 11;
    if (count == 0)
    {
        cout << x / 11 * 2 << endl;
    }
    else
    {
        if (count <= 6)
        {
            cout << x / 11 * 2 + 1 << endl;
        }
        else
        {
            cout << x / 11 * 2 + 2 << endl;
        }
    }

    return 0;
}

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

using namespace std;

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

	auto L = vector<int>(N);
	auto sum = 0;
	while (N--) {
		cin >> L[N];
		sum += L[N];
	}
	sort(L.begin(), L.end());

	cout << (L.back() < sum - L.back() ? "Yes" : "No");
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll K, N; cin >> K >> N;
  vector<ll> A(2 * N);
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    A[i] = a;
    A[N + i] = K + a;
  }
  ll ans = 2 * K;
  for (ll i = 0; i < N; i++) {
    ans = min(ans, A[N - 1 + i] - A[i]);
  }
  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 6348
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    day = 0
    for i in range(0, M):
        day += A[i]
    
    res = N - day
    if res < 0:
        print(-1)
        return
    print(res)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 68564
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int num[100005];
int s[100005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
	cin>>num[i];
    }
    sort(num,num+n);
    int mid=n/2;
    long long sum=0;
    if(n%2==0)
    {
	for(int i=0;i<mid;i++)
	    sum-=2*num[i];
	for(int i=mid;i<n;i++)
	    sum+=2*num[i];
	sum=sum-num[mid]+num[mid-1];
    }
    else 
    {
	long long sum1=0;
	for(int i=0;i<mid;i++)
            sum1-=2*num[i];
        for(int i=mid;i<n;i++)
            sum1+=2*num[i];
        sum1=sum1-num[mid]-num[mid+1];
        for(int i=0;i<=mid;i++)
            sum-=2*num[i];
        for(int i=mid+1;i<n;i++)
            sum+=2*num[i];
        sum=sum+num[mid]+num[mid-1];
 	if(sum1>sum) sum=sum1;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 768
#include<stdio.h>
#define Max 100000 
int main()
{
  int S[Max],T[Max],i,j,n,q;
  int left,mid,right;

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

  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&T[i]);

  j=0;
  for(i=0;i<q;i++)
    {
      left=0;
      right=n;
      while(left<right)
	{
	  mid = (left + right)/2;
	  if(S[mid] == T[i])
	    {
	      j++;
	      break;
	    }
	  else if (T[i] < S[mid])
	    right = mid;

	  else left = mid + 1;
	}
    }
  printf("%d\n",j);
  return 0;
}

Measured memory_bytes: 1192
from heapq import heappop, heappush, heapify
n,m = map(int, input().split())
al = list(map(int, input().split()))
alm = []
for a in al:
    alm.append(a*(-1))

heapify(alm)
for _ in range(m):
    poped = heappop(alm)
    val = (poped*(-1))//2
    heappush(alm, val*(-1))

ans = sum(alm)
print(-ans)


Measured memory_bytes: 92240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int t, a, b;
  cin >> t >> a >> b;
  a = t * a;

  if (a <= b) {
    cout << a << endl;
  }
  else if (a >= b) {
    cout << b << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

import collections
c=collections.Counter(a)
C=c.most_common()

even=0
for i in range(len(C)):
    p,q=C[i]
    if q%2==0:
        even += 1
if even%2==0:
    print(len(C))
else:
    print(len(C)-1)

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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define PI 3.1415926535897932384626
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

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

    int t;
    cin>> t;
    set<string> s;
    while(t--){
        string k;
        cin>>k;
        s.insert(k);
    }

    cout << s.size() ;
    return 0;
}

Measured memory_bytes: 19188
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int x;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x;
    vector<bool> can(x+1,false);
    can[100]=true;
    can[101]=true;
    can[102]=true;
    can[103]=true;
    can[104]=true;
    can[105]=true;
    for(int i=106;i<=x;i++){
        for(int j=100;j<=105;j++){
            if(can[i-j]) can[i]=true;
        }
    }
    if(can[x])
    cout << 1<< "\n";
    else
    cout << 0<< "\n";
}



Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var io = new StandardIO();
        new Process(io).Run();
    }

}

class Process
{
    public Process(IIO io)
    {
        this.io = io;
    }

    IIO io;

    public void Run()
    {
        var count = io.GetInteger();
        int[] ds = new int[count];
        for (int i = 0; i < count; i++)
            ds[i] = io.GetInteger();
        var result = ds.Distinct().Count();
        io.Write(result.ToString());
    }
}

public interface IIO
{
    string Get();
    void Write(string s);
    void Flush();
}

public class StandardIO : IIO
{
    string IIO.Get()
    {
        return Console.ReadLine();
    }

    void IIO.Write(string s)
    {
        Console.WriteLine(s);
    }

    void IIO.Flush()
    {
        Console.Out.Flush();
    }
}

public static class InputExtension
{
    public static int GetInteger(this IIO input)
    {
        return int.Parse(input.Get());
    }

    public static string[] GetStrings(this IIO input, char separator = ' ')
    {
        return input.Get().Split(separator);
    }

    public static int[] GetIntegerArray(this IIO input, char separator = ' ')
    {
        return input.GetStrings().Select(s => int.Parse(s)).ToArray();
    }
}



Measured memory_bytes: 13276
//ABC 050-B
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
	int N, T[100], M, P, X, TotalTime = 0, ans[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
		TotalTime += T[i];
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
	cin >> P >> X;
	ans[i] =TotalTime - T[P-1] + X;
	cout << TotalTime - T[P-1] + X << endl;
	}
//	for (int i = 0; i < M; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){

  int i,c=0,N,f=0,a;
  //load number
  scanf("%d",&N);
  //N>0 ->roop
  while(N-->0){
    //road number
    scanf("%d",&a);
    if(a==1)continue;
    //judge number
    for(i=2;i<=sqrt((double)a);i++){
      //if a%j=0 flag=1
      if(a%i==0) f=1;
    }
    if(f==1)f=0;
    //else count prime number
    else c++;
  }
  //print counter
  printf("%d\n",c);



  return 0;

}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:
const ll limit = 500000000LL;

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

	rep(loop, q) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		assert(a <= limit);
		assert(b <= limit);

		assert(c <= 2LL*limit);
		assert(d <= 2LL*limit);

		c--, d--;	



		const ll total = a + b;
		const ll num = max(a, b);
		const ll den = min(a, b) + 1;
		const ll k = (num + den - 1) / den;

		ll low = 0, high = a + 1;
		while (high - low > 1) {
			const ll mid = (low + high) / 2;
			const ll na = a - mid;
			const ll nb = b - (mid - 1) / k;

			if (na >= 0 and nb >= 0 and nb <= (na + 1) * k)
				low = mid;
			else
				high = mid;
		}

		const ll border = low + (low - 1) / k;
		//cerr << low << endl;

		string ans = "";
		for (ll i = c; i <= d; ++i) {
			if (i < border) {
				if (i % (k + 1) != k)
					ans += 'A';
				else
					ans += 'B';
			} else {
				if ((total - 1 - i) % (k + 1) != k)
					ans += 'B';
				else
					ans += 'A';
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) {
		
		long num[] = new long[4];
		long ans = 0;
		
		for(int i=0;i<4;i++) {
			num[i] = scan.nextLong();
		}
		
		for(int i=0;i<2;i++) {
			for(int j=2;j<4;j++) {
				long kari = num[i]*num[j];
				if(i==0 && j==2) {
					ans = kari;
				}else {
					ans = Math.max(kari, ans);
				}
			}
		}
		
		System.out.println(ans);
	
		
	}
	
	
	public static int gcd(int x,int y) {
		if(x%y == 0) {
			return y;
		}else {
			return gcd(y,x%y);
		}
	}
	
}
 





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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int T[10][10];

bool check(vint v){
    int r=0;
    for(int i=0;i<5;i++)r=T[r][v[i]];
    return r==0;
}

signed main(){
    rep(i,10)rep(j,10)cin>>T[i][j];
    int cnt=0;
    rep(a,10)rep(b,10)rep(c,10)rep(d,10){
        int e=T[T[T[T[0][a]][b]][c]][d];
        vint v={a,b,c,d,e};

        bool ok=true;
        rep(i,5){
            reps(j,1,10){
                int tmp=v[i];
                v[i]=(v[i]+j)%10;
                if(check(v))ok=false;
                v[i]=tmp;
            }
        }
        rep(i,4){
            swap(v[i],v[i+1]);
            if(check(v)&&v[i]!=v[i+1])ok=false;
            swap(v[i],v[i+1]);
        }
        if(!ok)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int k,n;
    int ans=0;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> kukan(n);
    
    rep(i,n-1){
        kukan[i] = a.at(i+1) - a.at(i);
    }
    kukan[n-1] = a.at(0) + k - a.at(n-1);
    
    sort(kukan.begin(),kukan.end());
    
    rep(i,n-1){
        ans += kukan.at(i);
    }
    cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i, n-1){
    if(s[i] != s[i+1]) ++ans;
  }
  ans++;
  cout << ans << endl;
}
  
  

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

//モジュラー逆数
long long modinv(long long n, long long p) {
  long long a = p, u = 1, v = 0;
  while (a) {
    long long t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

//フィボナッチ数のmod
vector<long long> fibmemo(100000, 0);
long long fib(long long n, long long p) {
  if (n == 0) return 0;
  if (n == 1) return 1;
  if (0 <= n && n <= 99999 && fibmemo.at(n) != 0)
    return fibmemo.at(n) % p;
  if (0 <= n && n <= 99999)
    fibmemo.at(n) = fib(n - 1, p) + fib(n - 2, p) % p;
  return fib(n - 1, p) % p + fib(n - 2, p) % p;
}

//リュカ数
vector<unsigned long long> lucmemo(92, 0);
unsigned long long luc(int n) {
  if (n == 0) return 2;
  if (n == 1) return 1;
  if (0 <= n && n <= 91 && lucmemo.at(n) != 0)
    return lucmemo.at(n);
  if (0 <= n && n <= 91)
    lucmemo.at(n) = luc(n - 1) + luc(n - 2);
  return luc(n - 1) + luc(n - 2);
}

int main() {
  long long n, m, p = 1000000007;
  cin >> n >> m;
  vector<long long> a(m + 1);
  a.at(0) = - 1;
  for (long long i = 0; i < m; i++) {
    cin >> a.at(i + 1);
    if (i > 0 && a.at(i) + 1 == a.at(i + 1)) {
      cout << 0 << endl;
      return 0;
    }
  }
  a.push_back(n + 1);
  vector<long long> b(m + 1);
  for (long long i = 0; i < m + 1; i++) 
    b.at(i) = a.at(i + 1) - a.at(i) - 1;
  long long cnt = 1;
  for (long long i = 0; i < m + 1; i++) {
    cnt *= fib(b.at(i), p);
    cnt %= p;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int d[100000], r[100000];

int main() {
    int n, m;
    cin >> n >> m;
    r[0] = 1;
    REP(i,n){
        d[i] = 1;
    }
    REP(i,m){
        int x, y;
        scanf("%d %d", &x, &y);
        x--;
        y--;
        r[y] |= r[x];
        d[x]--;
        d[y]++;
        if (d[x]==0) r[x] = 0;
    }

    int ans = 0;
    REP(i,n){
        if (d[i]>0 && r[i]) ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a, b, c;

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

	if((a < b) && (b < c))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#define REP0(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REP1(i,n) for((i)=1;(i)<=(long long)(n);(i)++)
#define ll long long
using namespace std;

ll i,j,k;
const ll MOD = 1000000000 + 7;

int main(){
    ll n,m;
    string ans="No";
    cin>>n>>m;
    int ansArray[n]={0};
    vector<vector<int>> A(2000001,vector<int>());
    REP0(i,m){
        int a,b;
        cin>>a>>b;
        A[a].push_back(b);
        A[b].push_back(a);
    }

    queue<int> q;
    q.push(1);
    while(q.size()>0){
        int v=q.front();
        q.pop();
        REP0(i,A[v].size()){
            if(ansArray[A[v][i]-1]==0){
                ansArray[A[v][i]-1]=v;
                q.push(A[v][i]);
                ans="Yes";      
            }
        }
    }
    
    if(ans=="Yes"){
        cout<<ans<<'\n';
        REP1(i,n-1)cout<<ansArray[i]<<'\n';
    }
    else{
        cout<<ans<<'\n';
    }
    
    return 0;
}

Measured memory_bytes: 54760
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();

        StringBuilder builder = new StringBuilder();

        // 最短経路
        int xd = Math.abs(sx - tx);
        int yd = Math.abs(sy - ty);
        // 1回目行き
        for (int i = 0; i < yd; i++) {
            builder.append(sy > ty ? "D" : "U");
        }
        for (int i = 0; i < xd; i++) {
            builder.append(sx > tx ? "L" : "R");
        }
        // 1回目帰り
        for (int i = 0; i < yd; i++) {
            builder.append(sy < ty ? "D" : "U");
        }
        ++xd;
        for (int i = 0; i < xd; i++) {
            builder.append(sx < tx ? "L" : "R");
        }
        // 2回目行き
        ++yd;
        for (int i = 0; i < yd; i++) {
            builder.append(sy > ty ? "D" : "U");
        }
        for (int i = 0; i < xd; i++) {
            builder.append(sx > tx ? "L" : "R");
        }
        builder.append(sy < ty ? "D" : "U");
        // 2回目帰り
        builder.append(sx > tx ? "L" : "R");
        for (int i = 0; i < yd; i++) {
            builder.append(sy < ty ? "D" : "U");
        }
        for (int i = 0; i < xd; i++) {
            builder.append(sx < tx ? "L" : "R");
        }
        builder.append(sy > ty ? "D" : "U");
        System.out.println(builder);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
string s;
int k;
int main(){
    cin>>s>>k;
    for(int i=1;i<=k;i++){
        for(int j=0;j<s.size()-i+1;j++){
            v.push_back(s.substr(j,i));
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    cout<<v[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        String s;
        int sum;
        while(true){
            s = scanner.nextLine();
            if(s.equals("0"))break;
            sum = 0;
            for(int i=0; i< s.length(); i++){
                sum += s.charAt(i) - '0';
            }

            System.out.println(sum);
        }

    }
}



Measured memory_bytes: 26776
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

class EnumerableBits {
  int N;
	vector<bool> bits;
	long long b, max_b;
public:
	EnumerableBits(int N) {
	  this->N = N;
		this->max_b = (1 << N) - 1;
		reset();
	}

  // ビット列を0に戻す
	void reset() {
		bits = vector<bool>(N, 0);
		b = 0;
	}

  // ビット列の桁数を返す
	int size() {
		return N;
	}

  // ビットが1である個数を返す
	int count() {
		return accumulate(bits.begin(), bits.end(), 0);
	}

  // ビット列を1進める
	bool next() {
		if (b == max_b) {
			return false;
		}

		b++;
		for (int i = 0; i < N; i++) {
			bits[i] = b >> i & 1;
		}

		return true;
	}

  // ビット列のvectorを返す
	vector<bool> get_bits() {
		return bits;
	}

  // ビット列のvectorへの参照を返す（変更しない場合はこちらが高速）
	vector<bool>& get_bits_ref() {
		return bits;
	}

	// ビットが1であるインデックスのvectorを返す
	vector<int> get_indices() {
		vector<int> indices;
		for (int i=0; i<bits.size(); i++) {
			if (bits[i]) {
				indices.push_back(i);
			}
		}

		return indices;
	}
};

int H, W, K;
int grid[10][1000];

// ビット列に基づいてスライスに分割
vector<vector<int>> create_slices(vector<bool>& bits) {
	vector<vector<int>> slices;
	vector<int> slice(W, 0); // 横分割後の各スライスのj+1列目のホワイトチョコレートの数
	bool new_slice = true;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			slice[j] += grid[i][j];
		}
		if (i == H-1 || bits[i] == 1) {
			slices.push_back(slice);
			slice = vector<int>(W, 0); // スライスをリセット
		}
	}

	return slices;
}

// 横分割されたスライスについて、最小手数を求める
int count_min_operation(vector<vector<int>>& slices) {
	vector<int> w_choco(slices.size()); // スライスごとのホワイトチョコレートのカウント用
	int result = slices.size() - 1; // 横の分割数
	for (int j=0; j<W-1; j++) {
		bool can_go_next = true;
		for (int i=0; i<slices.size(); i++) {
			if (slices[i][j] > K) {
				return INF; // 最小に分割してもK以下にできない
			}
			w_choco[i] += slices[i][j];

			// 次の分割位置に進めるかどうかを判定
			if (w_choco[i] + slices[i][j+1] > K) {
				can_go_next = false;
				// note: breakするとINFとなるケースを見逃す場合があるのでbreakしない
			}
		}

		if (!can_go_next) {
			result++;
			w_choco = vector<int>(slices.size(), 0); // ホワイトチョコレートのカウントをリセット
		}
	}

	return result;
}

int main(){

	cin >> H >> W >> K;

	string S;
	for (int i=0; i<H; i++) {
		cin >> S;
		for (int j=0; j<W; j++) {
			grid[i][j] = (S[j] == '1' ? 1 : 0);
		}
	}

	EnumerableBits enum_bits(H-1);

	int ans = INF;

	do {
		vector<bool>& bits = enum_bits.get_bits_ref(); // 横分割パターン
		vector<vector<int>> slices = create_slices(bits);

		ans = min(ans, count_min_operation(slices));
	} while (enum_bits.next());

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int N, K;
    scanf("%d%d\n", &N, &K);
    int res = 0;
    for(int ni=0; ni<N; ni++){
        int h;
        scanf("%d", &h);
        if(h >= K){
            res ++;
        }
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int n,k;
int a[110];
// dp[i][j]:=i残してjに回したときの勝敗
int dp[100010][2];
int dfs(int num,int who){
    // cout<<num<<endl;
    if(dp[num][who]!=-1) return dp[num][who];
    int ret=(who+1)%2;
    bool flg=1;
    rep(i,n){
        if(num-a[i]>=0){
            int tmp=dfs(num-a[i],(who+1)%2);
            if(tmp==who) ret=tmp;
            flg=0;
        }
    }
    dp[num][who]=ret;
    return dp[num][who];
}
int main(){
    cin>>n>>k;
    rep(i,n) cin>>a[i];
    if(n==1){
        cout<<(k/a[0]%2?"First":"Second")<<endl;
        return 0;
    }
    rep(i,100010)rep(j,2) dp[i][j]=-1;
    cout<<(dfs(k,0)?"Second":"First")<<endl;
    return 0;
}


Measured memory_bytes: 7296
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15
from heapq import  heapify,heappop,heappush


def main():
    N = int(input())
    C = list(map(int,input().split()))
    C.sort()
    
    power = [1]
    for i in range(N):
        power.append(power[-1]*2%MOD)

    ans = 0
    for i,c in enumerate(C):
        ans += c*(power[N - 2]*power[N]*(N - i - 1))%MOD
        ans += c*(power[N - 1]*power[N])%MOD
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 26512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y; cin >> x >> y;
    if(y%2 == 0 && x*2 <= y && y<= x*4) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3588
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*2+3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)


Measured memory_bytes: 84824
def countingsort(a,k):
    c=[0]*(k+1)
    n=len(a)
    for i in a:
        c[i]+=1
    for i in range(1,k+1):
        c[i]=c[i]+c[i-1]
    b=[0]*n
    for i in range(n-1,-1,-1):
        b[c[a[i]]-1]=a[i]
        c[a[i]]-=1
    return b
o=int(input())
a=list(map(int,input().split()))
q=max(a)
ret=countingsort(a,q)
for i in range(o):
    if i!=o-1:
        print(ret[i],end=" ")
    else:
        print(ret[i])


Measured memory_bytes: 224380