akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
int v[MAX_N];

int main2() {
  int N = nextInt();
  int P = nextInt();
  string S; cin >> S;
  REP(i, N) v[i] = S[i] - '0';

  if (P == 2) {
    ll ans = 0;
    for (int i = N-1; i >= 0; i--) {
      if (v[i] % 2 == 0) {
        ans += i+1;
      }
    }
    cout << ans << endl;
  } else if (P == 5) {
    ll ans = 0;
    for (int i = N-1; i >= 0; i--) {
      if (v[i] % 5 == 0) {
        ans += i+1;
      }
    }
    cout << ans << endl;
  } else {
    ll ans = 0;
    map<int, ll> count;
    ll s = 0;
    ll ten = 1;
    for (int i = N-1; i >= 0; i--) {
      s += (v[i] * ten) % P;
      s %= P;

      ans += count[s];
      ++count[s];
      if (s == 0) ans++;

      ten = (ten * 10) % P;
    }
    cout << ans << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
   long long int i,k=0,n,x,j,m=0;

   vector<long long int>v;
   cin>>n;
   for(i=0;i<n;i++)
   {
       cin>>x;
       v.push_back(x);
       k=k+x;
   }
   j=round(k*1.0/n*1.0);
   for(i=0;i<n;i++)
   {
       m=m+(v[i]-j)*(v[i]-j);
   }
   cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
t = input()
n = len(s)
f = [False]
i = 0
for i in range(0,n):
    if (f[0] == True):
        break
    if (s == t):
        f[0]=True
        break
    else:
        p = s[0]
        s=s.lstrip(p)
        s=s+p


if (f[0]==True):
    print("Yes")
if (f[0]==False):
    print("No")


Measured memory_bytes: 3060
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    x = int(input())
    if x == 0:
        print(1)
    else:
        print(0)
if __name__ == "__main__":
    run()


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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  int ans=0;
  for(int i=1; i<50000; i++){
    double cnt = double(i)*1.08;
    if(n==int(floor(cnt))) ans = i;
  }
  if(ans==0) cout << ":(" << endl;
  else cout << ans << endl;
  return 0;
}


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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

int D,G;
vector<int>p,c;
ll ans = INF;

ll func(int usebit){
   ll sum = 0;
   ll cc = 0;

   for(int i=0;i<D;i++){
      if(usebit & (1<<i)){
         sum+=100*(i+1)*p[i]+c[i];
         cc+=p[i];
      }
   }

   if(sum < G){
      int bit=-1;
      for(int i=0;i<D;i++){
         if(!(usebit&(1<<i))){
            bit = i;
         }
      }
      if(bit==-1)return INF;

      for(int i=0;i<p[bit]-1;i++){
         if(sum >= G)break;
         sum+=100*(bit+1);
         cc++;
      }
      if(sum < G)return INF;

   }

   return cc;
}

int main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   
   cin>>D>>G;
   p.resize(D,0);
   c.resize(D,0);
   for(int i=0;i<D;i++)cin>>p[i]>>c[i];

   for(int i=0;i<=pow(2,D);i++){
      ans = min(func(i),ans);
   }

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


Measured memory_bytes: 384
n = int(input())
a = [int(i) for i in input().split(" ")]
cs = []

def argmax(a):
    m = a[0]
    mi = 0
    for i in range(1, len(a)):
        if m < a[i]:
            m = a[i]
            mi = i
    return (m, mi)

def argmin(a):
    m = a[0]
    mi = 0
    for i in range(1, len(a)):
        if m > a[i]:
            m = a[i]
            mi = i
    return (m, mi)


mx, argmx = argmax(a)
mi, argmi = argmin(a)

if mx + mi >= 0:
    for i in range(0, n):
        if a[i] < 0 and a[i] < mx:
            a[i] += mx
            cs.append((argmx, i))
    for i in range(1, n):
        a[i] += a[i - 1]
        cs.append((i - 1, i))
else:
    for i in range(0, n):
        if a[i] > 0 and a[i] > mi:
            a[i] += mi
            cs.append((argmi, i))
    for i in reversed(range(0, n - 1)):
        a[i] += a[i + 1]
        cs.append((i + 1, i))

print(len(cs))
for c in cs:
    print(c[0] + 1, c[1] + 1)

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

using namespace std;

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

	int n, k;
	string s;

	cin >> n >> k >> s;

	int ans = 0, cnt = 1;
	
	for(int i = 1; i < s.length(); i++) {
		if(s[i] == s[i-1]) ans++;
		else cnt++;
	}

	if(cnt & 1) {
		ans += 2 * min(cnt/2, k);
	}
	else {
		ans += 2*min(cnt/2-1, k);
		if(cnt/2-1 < k) ans++;
	}

	cout << ans;

	return 0;
}



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

int main() {
	int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    for (int i = 0; i < n; ++i) {
        ll ai;
        cin >> ai;
        fw.add(i, ai);
    }

    while(q--) {
        int t, a, b;
        cin >> t >> a >> b;
        if(t) {
            cout << fw.sum(a, b) << endl;
        } else {
            fw.add(a, b);
        }
    }
}


Measured memory_bytes: 8216
X = int(input())

if 400 <= X and X <= 599:
    print("8")
elif 600 <= X and X <= 799:
    print("7")
elif 800 <= X and X <= 999:
    print("6")
elif 1000 <= X and X <= 1199:
    print("5")
elif 1200 <= X and X <= 1399:
    print("4")
elif 1400 <= X and X <= 1599:
    print("3")
elif 1600 <= X and X <= 1799:
    print("2")
elif 1800 <= X and X <= 1999:
    print("1")


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

using namespace std;

map<int, int> a;

const int MOD = 1e9 + 7;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x; scanf("%d", &x);
		a[x]++;
		a[abs(i - (n - i - 1))]--;
	}
	for (auto x : a) {
		if (x.second != 0) {
			puts("0");
			return 0;
		}
	}
	int ans = 1;
	for (int i = 0; i < n / 2; i++) {
		ans = ans + ans;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4096
/*AOJ 0028*/

#include<iostream>
using namespace std;

#define FOR(i,n) for(int i=0;i<n;i++)

int main(){

	int data[100];
	int num;
	int max=0;

	FOR(i,100){
		data[i] = 0;
	}

	while(cin>>num){
		
		if(num == 0){
			break;
		}
		data[num-1]++;
	}

	FOR(i,100){
		if(max<=data[i]){
			max = data[i];
		}
	}

	FOR(i,100){
		if(data[i] == max){
			cout<<i+1<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**6)

def dfs(v):
    if dp[v] != 0: return dp[v]
    cnt = 0
    for i in g[v]:
        cnt = max(cnt, dfs(i) + 1)
    dp[v] = cnt
    return dp[v]

N, M = map(int, input().split())
dp = [0] * (N + 1)
g = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    g[x - 1].append(y - 1)

for i in range(N):
    dfs(i)

print(max(dp))

Measured memory_bytes: 61400
#include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

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

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vector<int64_t> p(A), q(B), r(C);
    for (int i = 0; i < A; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < B; i++)
    {
        cin >> q[i];
    }
    for (int i = 0; i < C; i++)
    {
        cin >> r[i];
    }
    sort(begin(p), end(p), greater<int64_t>());
    sort(begin(q), end(q), greater<int64_t>());

    int64_t ans = 0;
    priority_queue<int64_t, vector<int64_t>, greater<int64_t>> pque;
    for (int i = 0; i < X; i++)
    {
        ans += p[i];
        pque.push(p[i]);
    }
    for (int i = 0; i < Y; i++)
    {
        ans += q[i];
        pque.push(q[i]);
    }

    for (int i = 0; i < C; i++)
    {
        int64_t top = pque.top();
        pque.pop();
        ans -= top;

        pque.push(max(top, r[i]));
        ans += max(top, r[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4852
w, h, n = map(int, input().split())

X, Y = [0, w], [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        X[0] = max(X[0], x)
    if a == 2:
        X[1] = min(X[1], x)
    if a == 3:
        Y[0] = max(Y[0], y)
    if a == 4:
        Y[1] = min(Y[1], y)

if X[1]-X[0] <= 0 or Y[1]-Y[0] <= 0:
    print(0)
else:
    print((X[1] - X[0]) * (Y[1] - Y[0]))

Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	ll ans = 0 ;
	for(ll i=k;i<=n+1;i++){
		ll cnt = i*(n+n-i+1)/2-i*(i-1)/2+1 ;
//		cout << i*(n+n-i+1)/2 << " " << i*(i-1)/2 << endl ;
		ans = (ans+cnt)%mod ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 3632
import Control.Applicative
import Control.Monad.State
import Control.Monad
import Data.List
import Data.Either
import Data.Int

main = do
  n <- readLn :: IO Int
  ts <- map read . words <$> getLine :: IO [Int64]
  as <- map read . words <$> getLine :: IO [Int64]


  let
    ts' = (`evalState` 0) $ do
      forM ts $ \t -> do
        x <- get
        put t
        return $ if t == x then Left t else Right t

    as' = reverse $ (`evalState` 0) $ do
      forM (reverse as) $ \a -> do
        x <- get
        put a
        return $ if a == x then Left a else Right a  
  
  print $ (foldl (\x y -> (x*y)`mod`(10^9+7)) 1 $ zipWith f as' ts')

  where
    f (Left x) (Left y) = min x y
    f (Left x) (Right y) = if x >= y then 1 else 0
    f (Right x) (Left y) = if x <= y then 1 else 0
    f (Right x) (Right y) = if x == y then 1 else 0


Measured memory_bytes: 119420
#include <iostream>
using namespace std;
int main(void){
    int A, B; //CDの値段、支払額

    while(true){
        cin >> A >> B;
        if(A + B == 0) break;

        int T = B - A;
        int h, g, s; //100円玉の個数、500円玉の個数、1000円札の枚数
        s = T / 1000;
        g = (T - 1000 * s) / 500;
        h = (T - 1000 * s - 500 * g) / 100;

        cout << h << " " << g << " " << s << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
n, d = map(int, input().split())
lists = []
cnt = 0

for i in range(n):
  x, y = map(int, input().split())
  lists.append([x, y])
  

for j in range(n):
  l = (lists[j][0] ** 2 + lists[j][1] ** 2) ** (1 / 2)
  if l <= d:
    cnt += 1
  else:
    continue

print(cnt)

Measured memory_bytes: 39396
def main():
    n = int(input())
    s = input()
    a = [0]*n
    b = [0]*n
    for i in range(n):
        if s[i] == "#":
            a[i] += 1
        if 0 < i:
            a[i] += a[i-1]
    for i in reversed(range(n)):
        if s[i] == ".":
            b[i] += 1
        if i < n-1:
            b[i] += b[i+1]
    ans = float("inf")
    for i in range(1, n):
        ans = min(ans, a[i-1]+b[i])
    ans = min(ans, b[0], a[n-1])
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 19176
s = input()
t = input()

min_score = len(t)
for i in range(len(s) - len(t)+1):
  s_p = s[i:i+len(t)]
  count_wrong = 0
  for j in range(len(t)):
    if t[j] != s_p[j]:
      count_wrong += 1
  min_score = min(count_wrong, min_score)

print(min_score)

Measured memory_bytes: 67664
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(n: int, a: "List[int]"):
    i = 0
    res = []
    tmp = [a[0]]
    flag = 0  # -1:単調減少,  0:初期値,  1:単調増加
    while i < len(a)-1:
        if a[i+1] == a[i]:
            tmp.append(a[i+1])
        elif a[i+1] > a[i]:
            if flag != -1:
                tmp.append(a[i+1])
                flag = 1
            else:
                res.append(tmp)
                tmp = []
                tmp.append(a[i+1])
                flag = 0
        elif a[i+1] < a[i]:
            if flag != 1:
                tmp.append(a[i+1])
                flag = -1
            else:
                res.append(tmp)
                tmp = []
                tmp.append(a[i+1])
                flag = 0
        i += 1
    res.append(tmp)
    # print(res)
    print(len(res))
    return


# Generated by 1.1.4 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
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 22076
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace ConsoleAppAtCoderABC171
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var a = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var aDic = a.GroupBy(x => x).ToDictionary(k => k.Key, e => e.Count());
            var q = int.Parse(ReadLine());
            var s = a.Sum(x => (long)x);

            for(int i = 0; i < q; i++)
            {
                var bc = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var b = bc[0];
                var c = bc[1];

                // bが存在した場合
                if(aDic.TryGetValue(b, out int count))
                {
                    // sを調整
                    s += (c - b) * count;

                    // aDicを調整
                    aDic.Remove(b);
                    if(aDic.ContainsKey(c))
                    {
                        aDic[c] += count;
                    }
                    else
                    {
                        aDic.Add(c, count);
                    }
                }

                WriteLine(s);
            }
        }
    }
}


Measured memory_bytes: 52396
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
int n;
cin >> n;
cout << n*(n+1)/2 << endl;








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

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

int n,a[10];

int main()
{
    scanf("%d",&n);
    int hd=9;
    while(n--)
    {
        int k;
        for(k=9;k>hd;k--)
            if(a[k]!=a[k-1]+1&&a[k]!=9) break;
        if(k==hd&&a[k]==9)
        {
            hd--,k--;
            a[hd]=1;
        }
        else a[k]++;
        for(int i=k+1;i<=9;i++) a[i]=max(0,a[i-1]-1);
    }
    for(int i=hd;i<=9;i++) printf("%d",a[i]);
    return 0;
}

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

int main()
{
    string s, t;
    int count = 0;

    cin >> s >> t;

    rep(i , 3)
    {
        if(s.at(i) == t.at(i))
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize "O3"

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  if (n % 2 == 1) {                        //個数が奇数
    for (int i = n - 1; i >= 0; i -= 2) {  //偶数を逆に出力
      cout << a[i] << " ";
    }
    for (int i = 1; i <= n - 2; i += 2) {  //奇数を出力
      cout << a[i] << " ";
    }
  } else {                                 //個数が偶数
    for (int i = n - 1; i >= 1; i -= 2) {  //奇数を逆に出力
      cout << a[i] << " ";
    }
    for (int i = 0; i <= n - 2; i += 2) {  //偶数を出力
      cout << a[i] << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 2944
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  long long a, b, c, k, i;
  cin >> a >> b >> c >> k;

  // if(atai>pow(10,18)){
  //   cout<<"Unfair"<<endl;
  //   return 0;
  // }

  long long init_sa = a - b;
  if (k % 2 == 0)
    cout << init_sa << endl;
  else
    cout << -init_sa << endl;
}


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    N, M, C = [int(item) for item in input().split()]
    Bs = [int(item) for item in input().split()]

    grid = [[int(item) for item in input().split()] for _ in range(N)]

    cnt = 0

    for i in range(N):
        temp = C
        for j in range(M):
            temp += grid[i][j]*Bs[j]
        if temp > 0:
            cnt += 1

    print(cnt)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9104
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,k = map(int, input().split())
a = list(map(int, input().split()))

# 累積和
def cumsum(a, pos=False):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num if not pos else max(0, num)
    l[-1] = c
    return l

ca = cumsum(a)
pca = cumsum(a, pos=True)
ans = 0
for i in range(0, n-k+1):
    ans = max(ans, pca[i] + max(0,ca[i+k]-ca[i]) + (pca[n]-pca[i+k]))
print(ans)

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

typedef long long int lli;

int main(void){
    // Here your code !
    lli x;
    cin >> x;
    lli a = (x/11);
    lli b = x%11;
    
    lli c = a*2;
    
    if(b == 0)
        c+=0;
    else if(b <= 6)
        c++;
    else
        c+=2;
    
    cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>

int main () {
  std::string S;
  std::cin >> S;
  int n;
  std::cin >> n;
  int size = S.size();
  
  int i = 0;
  while (true) {
    std::cout << S[i] ;
    i = i + n;
    if (i >= size) {
      std::cout << std::endl;
      break;  

    }      
  }  
}

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

int main(){
  int a, b, t;
  cin >> a >> b >> t;
  int ans = 0;
  for (int i = a; i < t+0.5; i+=a){
    ans++;
  }
  cout << ans*b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int a[12][12];
void solve(int m, int n) {
	if (m + 1<12 && a[m + 1][n] == 1) {
		a[m + 1][n] = 0;
		solve(m + 1, n);
	}
	if (m - 1 >= 0 && a[m - 1][n] == 1) {
		a[m - 1][n] = 0;
		solve(m - 1, n);
	}
	if (n + 1<12 && a[m][n + 1] == 1) {
		a[m][n + 1] = 0;
		solve(m, n + 1);
	}
	if (n - 1 >= 0 && a[m][n - 1] == 1) {
		a[m][n - 1] = 0;
		solve(m, n - 1);
	}
}
int main() {
	int z = 0;
	while (true) {
		string b;
		getline(cin, b);
		if (b == ""&&z == 0) {
			z++;
			getline(cin,b);
		}
		if (b == ""&&z != 2) {
			z++;
			getline(cin, b);
		}
		if (b == "")
			break;
		z = 0;
		for (int i = 0; i<12; i++) {
			a[0][i] = (int)b[i] - '0';
		}
		for (int i = 1; i<12; i++) {
			cin >> b;
			for (int j = 0; j<12; j++) {
				a[i][j] = (int)b[j] - '0';
			}
		}
		int o = 0;
		for (int i = 0; i<12; i++) {
			for (int j = 0; j<12; j++) {
				if (a[i][j] == 1) {
					o++;
					a[i][j] = 0;
					solve(i, j);
				}
			}
		}
		cout << o << endl;
	}
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF 2000'000'000

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);
	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

 int main(){
    int N;
    scanf("%d", &N);
 
    int d[N-1];
    for (int i = 0; i < N ;i++){
        scanf("%d", &d[i]);
    }
    int Q = N;
    int q;

    for (int j = 0; j < N;j++){
        q = 0;
        for (int k = j + 1; k < N;k++){
            if (d[j] == d[k]){
                q = 1;
            }
        }
        Q = Q - q;
    }
    printf("%d", Q);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> A;
	A.push_back(0);
	rep(i, N) {
		int num;
		cin >> num;
		A.push_back(num);
	}
	A.push_back(0);

	int sum = 0;
	rep(i, N + 1) {
		sum += abs(A[i + 1] - A[i]);
	}

	REP(i, 1, N) {
		int minus = abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1]);
		int plus = abs(A[i - 1] - A[i + 1]);
		cout << sum - minus + plus << endl;
	}

    return 0;
}


Measured memory_bytes: 2164
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

ll n,c[111][111];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>n;
	rep(i,n)rep(j,n)cin>>c[i][j];
	ll ans=0;
	rep(i,n)rep2(j,i+1,n)ans+=min(c[i][j],c[j][i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)

	fx := 0
	temp := n
	for temp > 0 {
		fx += temp % 10
		temp /= 10
	}

	if n%fx == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> AC(N, false);
    vector<int> pena(N, 0);
    for (int i = 0; i < M; i++) {
        int p; string r;
        cin >> p >> r; p--;
        if (r == "AC") AC[p] = true;
        else if (!AC[p]) pena[p]++;
    }
    
    int ac = 0, pe = 0;
    for (int i = 0; i < N; i++) {
        if (AC[i]) { ac++; pe += pena[i]; }
    }
    cout << ac << " " << pe << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
      int x = Integer.parseInt(br.readLine());
      System.out.printf("%d\n", x*x*x);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}



Measured memory_bytes: 24632
n, m = map(int, input().split())
h = list(map(int, input().split()))
lst = [0]*n

for i in range(m):
    a, b = map(int, input().split())
    ah=h[a-1]
    bh=h[b-1]
    if ah==bh:
        lst[a-1]+=1
        lst[b-1]+=1
    elif ah>bh:
        lst[b-1]+=1
    else:
        lst[a-1]+=1

print(lst.count(0))

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> cand;
    cand.insert(1);
    cand.insert(9);
    cand.insert(7);
    cand.insert(4);
    REP(i, 4) {
        int n;
        cin >> n;
        if(cand.count(n) > 0) cand.erase(n);
    }
    cout << (cand.size() > 0 ? "NO" : "YES") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
	Deque<Integer> b = new ArrayDeque<Integer>();
	Deque<Integer> c = new ArrayDeque<Integer>();
	Scanner in = new Scanner(System.in);
	final int dataSet = in.nextInt();
	for (int i = 0; i < dataSet; i++) {
	 b.clear();
	 b.addLast(Integer.valueOf(0));
	 c.clear();
	 c.addLast(Integer.valueOf(0));
	 boolean isYes = true;
	 for (int ball = 0; ball < 10; ball++) {
		Integer num = in.nextInt();
		if (isYes) {
		 boolean abigb = (num.compareTo(b.peekLast()) >= 0);
		 boolean abigc = (num.compareTo(c.peekLast()) >= 0);
		 if (!abigb && !abigc) {
			isYes = false;
		 } else {
			boolean bbigc = (b.peekLast().compareTo(c.peekLast()) >= 0);
			if (abigb && bbigc) {
			 b.addLast(num);
			} else {
			 c.addLast(num);
			}
		 }
		}
	 }
	 System.out.println(isYes ? "YES" : "NO");
	}
 }
}

Measured memory_bytes: 12000
def answer(a)
  char_count = {}
  a.each_with_index.inject(1) do |ans, (aa, i)|
    char_count[aa] ||= 0
    char_count[aa] += 1
    ans + i - char_count[aa] + 1
  end
end

p answer(gets.chomp.split(//))

Measured memory_bytes: 16764
#include <iostream>
#include <ctime>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include<cstring>
#include <set>
using namespace std;
string s, t;
set<string> S;

void Work()
{
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])//如果字符相等
        {
            string tmp = s;              //构造判断子串之前的字符
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')
                    tmp[j] ='a';
            bool can = false;
            for(int j = 0; j < lent; j++)    //判断是否为子串
            {

                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  //字符匹配
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';//处理匹配后的字符
                S.insert(tmp);  //压入容器
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main()
{
    cin >> s >> t;
    Work();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5+100;
ll n, x, s;
ll B[N], L[N], U[N], su[N], idx[N];
ll ans = LINF;
V<pair<ll, int>> v;
ll check(ll m, int i){
  int j = idx[i];
  ll ss = (j<m ? su[m+1]-v[j].fi : su[m]);
  if(ss>=s) return x*m;
  if(ss+L[i]*B[i]>=s) return x*m + (s-ss+L[i]-1)/L[i];
  if(ss+v[j].fi>=s) return x*m + (s-ss+(U[i]-L[i])*B[i]+U[i]-1)/U[i];
  return LINF;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x;
  FOR(i, 0, n){
    ll b, l, u;
    cin >> b >> l >> u;
    B[i] = b;
    L[i] = l;
    U[i] = u;
    s += b*l;
    v.pb(mp(u*(x-b)+l*b, i));
  }
  sort(all(v));
  reverse(all(v));
  FOR(i, 0, n){
    su[i+1] += su[i]+v[i].fi;
    idx[v[i].se] = i;
  }
  FOR(i, 0, n){
    int j = idx[i], l = -1, r = n-1, m;
    while(r-l>1){
      m = (r+l)/2;
      if(check(m, i)<LINF){
        r = m;
      }else{
        l = m;
      }
    }
    mins(ans, check(r, i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5872
#include <iostream>
#include <cstdio>
#include <cmath>
// #include <stack>
// #include <vector>
#include <cstring>
// #include <algorithm>
using namespace std;

const int SENTINEL = 1000000001;
int N, A[500000];
int count = 0;

void merge(int left, int mid, int right) {
    int leftA[250001];
    for (int i = left; i < mid; i++) {
        leftA[i - left] = A[i];
    }
    leftA[mid - left] = SENTINEL;
    int leftCur = 0;
    
    int rightA[250001];
    for (int j = mid; j < right; j++) {
        rightA[j - mid] = A[j];
    }
    rightA[right - mid] = SENTINEL;
    int rightCur = 0;
    
    for (int i = left; i < right; i++) {
        // printf("%d:%d - %d:%d\n", leftCur, leftA[leftCur], rightCur, rightA[rightCur]);
        // cout << endl;
        if (leftA[leftCur] <= rightA[rightCur]) {
            A[i] = leftA[leftCur];
            leftCur++;
        } else {
            A[i] = rightA[rightCur];
            rightCur++;
        }
        
        count++;        
    }
}

void mergeSort(int left, int right) {
    // printf("%d,%d --- mergeS \n", left, right);
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        // cout << mid;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    mergeSort(0, N);

    for (int i = 0; i < N; i++) {
        if (i != 0) {
            cout << " ";
        }
        printf("%d", A[i]);
    }
    
    cout << endl;
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 7008
using System;


public class B
{	
	public static void Main()
	{	
		int N = Int32.Parse(Console.ReadLine());
		int tmpSum = 0;
		int maxPrice = 0;
		for(int i = 0; i < N; i++)
		{
			int p = Int32.Parse(Console.ReadLine());
			tmpSum += p;
			maxPrice = Math.Max(p, maxPrice);			
		}
		Console.WriteLine(tmpSum - (maxPrice/2));
	}
}

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

using namespace std;

const int N = 22;
const int mod = 1e9 + 7;
int compatable[N][N];
int dp[N][1 << N];

int main() {
    int n;
    int total = 0;
    cin >> n;

    for (int i = 0; i < n; i++) { 
        for (int j = 0; j < n; j++) {
            cin >> compatable[i][j];
        }
    }

    dp[0][0] = 1;

    for (int mask = 0; mask < (1 << n) - 1; mask++) {
        int girl = __builtin_popcount(mask);
        for (int men = 0; men < n; men++) {
            if (compatable[men][girl] && !(mask & (1 << men))) {
                dp[girl + 1][mask | (1 << men)] += dp[girl][mask]; 
                dp[girl + 1][mask | (1 << men)] = dp[girl + 1][mask | (1 << men)] % mod;
            }
        }
    }

    cout << dp[n][(1 << n) - 1];
    return 0;
}



Measured memory_bytes: 93644
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);
fscanf(STDIN, "%d %d", $N, $M);
$array = array();
for ($i = 0; $i < $M; $i++) {
	fscanf(STDIN, "%d %d", $a, $b);
	if (!isset($array[$a])) {
		$array[$a] = $b;
	} else {
		$array[$a] = min($array[$a], $b);
	}
}

ksort($array);
// var_dump($array);

$answer = 0;
$cursor = 1;
foreach ($array as $key => $val) {
	// echo "{$cursor} < {$val} {$answer}\n";
	if ($key < $cursor) {
		$cursor = min($cursor, $val);
		continue;
	}
	if ($cursor < $val) {
		$answer++;
		$cursor = $val;
	}
}

echo $answer . PHP_EOL;


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

int main()
{
int n,d1,d2,c=0,flag=0;
cin>>n;
while(n--)
{
    cin>>d1>>d2;
    if(d1==d2)
    {
        c++;
        if(c>=3)
        {
            flag=1;
        }
    }
    else
    {
        c=0;
    }
}
if(flag==1)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int b;
    cin >>b;
    int n[b], r[b];
    for(int i = 0; i < b; i++)
    {
    	cin >> n[i];
    	r[i] = 0;
	}
	r[1] = abs(n[1]-n[0]);
	for(int i = 2; i < b; i++)
	{
		r[i] = min(r[i-1] + abs(n[i]-n[i-1]), r[i-2] + abs(n[i]-n[i-2]));
	}
	cout << r[b-1] << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += max(0, v[i] - c[i]);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int64_t> pq;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        pq.push(a);
    }
    for(int i = 0; i < m; i++){
        int a = pq.top(); pq.pop();
        a /= 2;
        pq.push(a);
    }
    int64_t ans = 0;
    while(!pq.empty()){
        int a = pq.top(); pq.pop();
        ans += a;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
    int n;
    int m, e, j;
    
    while (1){
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < n; i++){
            scanf("%d %d %d", &m, &e, &j);
            if ((m == 100) || (e == 100) || (j == 100)){
                printf("A\n");
            }
            else if (90 <= ((m + e) / 2.0)){
                printf("A\n");
            }
            else if (80 <= ((m + e + j) / 3.0)){
                printf("A\n");
            }
            else if (70 <= ((m + e + j) / 3.0)){
                printf("B\n");
            }
            else if ((50 <= ((m + e + j) / 3.0)) && ((80 <= m) || (80 <= e))){
                printf("B\n");
            }
            else {
                printf("C\n");
            }
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

#define netoze(a) (a<=0?0:a)


int main(void){
	int n, m;
	cin >> n >> m;
	char a[n][n], b[m][m];
	rep(i, n) rep(j, n) cin >> a[i][j];
	rep(i, m) rep(j, m) cin >> b[i][j];
	
	rep(i, n-m+1) rep(j, n-m+1){
		int f = 0;
		rep(k, m){
			rep(l, m) if(b[k][l] != a[k+i][l+j]){
				f = -1;
				break;
			}
			
			if(f == -1) break;
			if(k == m-1){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[200005],R[200005];
void make(){
	F[0] = 1;
	for(int i=1;i<200005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<200005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}

int b,w;
vector<ll>dw,up;
ll bin[200005];
int main(){
	make();
	cin>>b>>w;
	for(int i=0;i<b;i++) dw.pb(1LL);
	ll cur = 1;
	for(int i=0;i<w+1;i++){
		dw.pb(cur);
		cur = cur*2LL+C(b+i,i+1);
		cur %= mod;
	}
	
	for(int i=0;i<w;i++) up.pb(1LL);
	cur = 1;
	for(int i=0;i<b+1;i++){
		up.pb(cur);
		cur = cur*2LL+C(w+i,i+1);
		cur %= mod;
	}
	bin[0] = 1;
	for(int i=1;i<200005;i++) bin[i] = bin[i-1]*2LL%mod;
	
	for(int i=0;i<b+w;i++){
		ll ans = 1;
		if(i >= w){
			ans += up[i] * modpow(bin[i],mod-2) % mod;
		}
		if(i >= b){
			ans -= dw[i] * modpow(bin[i],mod-2) % mod;
		}
		ans %= mod;
		printf("%lld\n",(ans*((mod+1)/2)%mod+mod)%mod);
	}
}

/*
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
*/

Measured memory_bytes: 10096
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
  // 整数の入力
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll turn = 0;
  while (true)
  {
    if (turn % 2 == 0)
    {
      C -= B;
    }
    else
    {
      A -= D;
    }
    if (A <= 0 || C <= 0)
    {
      break;
    }
    turn++;
  }
  // cout << A << endl;
  // cout << C << endl;
  if (C <= 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

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

struct Card {char suit, value;};

void bubble(struct Card A[], int N) {
  for (int i=0; i<N; i++) {
    for (int j=N-1; j>=i+1; j--) {
      if (A[j].value < A[j-1].value) {
        Card t=A[j]; A[j]=A[j-1]; A[j-1]=t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for (int i=0; i<N; i++) {
    int minj = i;
    for (int j=i; j<N; j++) {
      if (A[j].value < A[minj].value) minj=j;
    }
    Card t=A[i]; A[i]=A[minj]; A[minj]=t;
  }
}

void print(struct Card A[], int N) {
  for (int i=0; i<N; i++) {
    if (i>0) cout<<" ";
    cout<<A[i].suit<<A[i].value;
  }
  cout<<endl;
}


bool isStable(struct Card C1[], struct Card C2[], int N) {
  for (int i=0; i<N; i++) {
    if (C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main() {
  Card C1[100], C2[100];
  int N;
  char ch;

  cin>>N;
  for (int i=0; i<N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for (int i=0; i<N; i++) C2[i]=C1[i];

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout<<"Stable"<<endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout<<"Stable"<<endl;
  } else {
    cout<<"Not stable"<<endl;
  }

  return 0;
}



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

alpha = [chr(i) for i in range(97, 97+26)]

def dfs(s, mx):
    if(len(s)==n):
        print(s)
    else:
        for i in range(mx):
            if i==mx-1:
                dfs(s+alpha[i], mx+1)
            else:
                dfs(s+alpha[i], mx)

dfs("",1)

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

int n, h[100005], d[100005];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &h[i]);
    d[1] = 0, d[2] = abs(h[1] - h[2]);
    for(int i = 3; i <= n; i++)
        d[i] = min(d[i - 1] + abs(h[i - 1] - h[i]), d[i - 2] + abs(h[i - 2] - h[i]));
    printf("%d", d[n]);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int A, B, C;
   cin >> A >> B >> C;
   cout << min(C, B / A) << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;++i)
int n,a,b,y[]={1000,100,10,1};
map<char,int> x;
string s,t="mcxi";
main(){
  x['m']=1000,x['c']=100,x['x']=10,x['i']=1;
  cin>>n;
  R(i,n){
    a=0;
    R(j,2){
      cin>>s;
      R(k,s.size())
        t.find(s[k])!=string::npos?a+=x[s[k]]:a+=(s[k]-'0')*x[s[++k]];
    }
    R(j,4){
      b=1;
      while(a/y[j])a-=y[j],++b;
      --b>1&&cout<<b<<t[j];
      --b||cout<<t[j];
    }cout<<endl;
  }
}

Measured memory_bytes: 3016
from sys import stdin

N = int(stdin.readline().rstrip())

ls = []
sum = 0

for i in range(1, N+1):
    p = int(stdin.readline().rstrip())
    ls.append(p)

ls = sorted(ls, reverse=True)

sum = ls[0] // 2

for i in range(1, len(ls)):
    sum = sum + ls[i]

print(sum)


Measured memory_bytes: 3060
A = list()

#0:pushBack
def pushBack(x):
  A.append(x)

#1:randomAccess
def randomAccess(x):
  print(A[x])
  
#2:popBack
def popBack():
  A.pop()


cmdList = [ pushBack, randomAccess, popBack ]
n = int(input())

for i in range(n):
  cmd = input()
  if cmd.startswith("0"):
    c,param = map(int,cmd.split(" "))
    cmdList[0](param)
  if cmd.startswith("1"):
    c,param = map(int,cmd.split(" "))
    cmdList[1](param)
  if cmd.startswith("2"):
    cmdList[2]()


Measured memory_bytes: 13360
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
  int N, L;
  cin >> N >> L;
	vector <int> apple;
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		int taste = L + i - 1;
		apple.push_back(taste);
		sum += taste;
	}
	int diff = 100000000;
	for (int i = 0; i < apple.size(); i++) {
		if (abs(diff) > abs(apple[i])) {
			diff = apple[i];
		}
	}
	int ans = sum - diff;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
R, G, B, N = list(map(int, input().split()))

x = 0
for i in range(N // R + 1):
  for j in range((N - (i * R)) // G + 1):
    k = i * R + j * G
    if  k > N:
      break
    if (N - k) % B == 0:
      x += 1
print(x)

Measured memory_bytes: 40684