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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N;
    scanf("%d",&N);
    char S[N+1];
    scanf("%s",S);

    int ans=0;
    if(N%2!=0){
        ans=1;
    }
    else{
        int n=N/2;
        for(int i=0;i<n;i++){
            if(S[i]!=S[i+n]){
                ans=1;
                break;
            }
        }
    }

    if(ans==0) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 128
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         long MOD = 1000000007L;
         int[][] grid = new int[N][M];
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            char[] c = st.nextToken().toCharArray();
            for(int a=0; a < M; a++)
               if(c[a] == '#')
                  grid[i][a] = 1;
         }
         long[][] dp = new long[N][M];
         dp[0][0] = 1L;
         for(int x=0; x < N; x++)
            for(int y=0; y < M; y++)
            {
               if(x < N-1 && grid[x+1][y] == 0)
               {
                  dp[x+1][y] += dp[x][y];
                  dp[x+1][y] %= MOD;
               }
               if(y < M-1 && grid[x][y+1] == 0)
               {
                  dp[x][y+1] += dp[x][y];
                  dp[x][y+1] %= MOD;
               }
            }
         System.out.println(dp[N-1][M-1]%MOD);
      }
   }

Measured memory_bytes: 51156
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int A, B, C;

    cin >> A >> B >> C;

    if ( (A-B) > C ) {
        cout << 0 << endl;
    } else {
        cout << ( C - (A-B)) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

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

    vector<vector<int>> A(H, vector<int>(W));
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j], A[i][j]--;

    map<int, pair<int, int>> M;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) M[A[i][j]] = make_pair(i, j);

    vector<vector<pair<int, int>>> B(D, vector<pair<int, int>>());
    for (int i = 0; i < H * W; i++) B[i % D].push_back(M[i]);

    vector<vector<int>> pSum(D);
    for (int i = 0; i < D; i++) pSum[i] = vector<int>(B[i].size(), 0);
    for (int i = 0; i < D; i++) for (int j = 0; j < B[i].size() - 1; j++) pSum[i][j + 1] = pSum[i][j] + abs(B[i][j + 1].first - B[i][j].first) + abs(B[i][j + 1].second - B[i][j].second);

    int Q;
    cin >> Q;

    for (int i = 0; i < Q; i++) {
        int L, R;
        cin >> L >> R;
        L--, R--;

        int which = L % D;
        int s = L / D;
        int t = R / D;

        cout << pSum[which][t] - pSum[which][s] << endl;
    }

    return 0;

}








































Measured memory_bytes: 16256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    std::vector<ll> A,B;
    REP(i,0,N){
        A.emplace_back(ii());
        B.emplace_back(ii());
    } 
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(N%2==0){
        ll n=A[N/2-1]+A[N/2];
        ll m=B[N/2-1]+B[N/2];
        oie(m-n+1);
    }else{
        ll n=A[N/2];
        ll m=B[N/2];
        oie(m-n+1);
    }
    return 0;
}

Measured memory_bytes: 6588
num = int(input())

result = 0

def is_odd(number):
    if not number % 2 == 0:
        return True
    else:
        return False

ketasu = len(str(num))
ruizyo = ketasu - 1

if is_odd(ketasu):
  result += (num+1-10**ruizyo)

for i in range(1,10,2):
  if i > ruizyo:
    break
  result += (10**(i))-(10**(i-1))

print(result)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	string s,t;
	cin>>s>>t;
	cout<<t<<s<<endl;			
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int N;
  cin >> N;
  int B[N-1];
  for (int i = 0; i < N-1; i++) cin >> B[i];
  int ans = B[0];
  for (int i = 0; i < N-2; i++) {
    ans += min(B[i], B[i+1]);
  }
  ans += B[N-2];
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
#n,m = map(int,input().split())

S={}
for i in range(n):
    a,b = map(int,input().split())
    if b in S:
        S[b]+=a
    else:
        S[b]=a
    
S2=sorted(S.items())
wa=0
for i in range(len(S2)):
    s,w = S2[i]
    wa+=w
    if s<wa :
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 45432
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	double x1, y1, x2, y2, x3, y3;
	int n;
	cin >> n;
	double distanceA, distanceB, distanceC, sinA, r, p, q;
	for (int i = 0; i < n; ++i) 
	{
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		distanceA = sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3)), distanceB = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3)), distanceC = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
	    sinA = sqrt(1.0 - pow((pow(distanceB, 2) + pow(distanceC, 2) - pow(distanceA, 2)) / (distanceB*distanceC * 2), 2));
		r = distanceA / (2 * sinA);
		p = ((y1 - y3)*(y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) - (y1 - y2)*(y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) / (2 * (y1 - y3)*(x1 - x2) - 2 * (y1 - y2)*(x1 - x3));
		q = ((x1 - x3)*(x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) - (x1 - x2)*(x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) / (2 * (x1 - x3)*(y1 - y2) - 2 * (x1 - x2)*(y1 - y3));

		cout << fixed << setprecision(3) << p << " " << q << " " << r << endl;
	}

	return 0;
}

Measured memory_bytes: 3196
n=int(input())
ct = 0

if n <= 9:
	ct = n
elif n <= 99:
	ct = 9
elif n <= 999:
	ct = n - 90
elif n <= 9999:
	ct = 909
elif n <= 99999:
	ct = n - 9000  - 90
elif n == 100000:
	ct = 90909
	
print(ct)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
string a[100000];
int main(){
    long long n;
    cin>>n;
    long long ans=0;
    for(long long i=0;i<n;i++){
        cin>>a[i];
        std::sort(a[i].begin(),a[i].end());
    }
    sort(a,a+n);
    long long z[100000]={0},cnt=0;
    for(long long  i=0;i<n;i++){
        if(i==0){
            z[cnt]=1;
            continue;
        }
        if(a[i]==a[i-1]){
            z[cnt]++;
        }
        else{
            cnt++;
            z[cnt]++;
        }
    }

    for(long long  i=0;i<=cnt;i++){
        ans+=((z[i]*(z[i]-1))/2);
    }
    cout<<ans;
}

Measured memory_bytes: 8064
<?php
$n = trim(fgets(STDIN));
$T = substr_count($n,"T");

$s = 0;
$ans = 0;
$i = 0;
while($i < $T * 2){
    if($n[$i] == "S"){
        ++$s;
    }else{
        if($s == 0){
        ++$ans;
        }else{
        --$s;
        }
    }
    ++$i;
}

echo $ans * 2 . PHP_EOL;
?>

Measured memory_bytes: 4016
#include <stdio.h>
int main(void){
    int i,j;
    char str[11];
    int ary[10];
    
    while(1){
        if(scanf("%s",str) != EOF){             //受け取りが成功した場合
            for(i=0;i<10;i++){                  //int型の配列に一桁ずつ受け取った数を格納していく
                ary[i] = str[i] - '0';
            }
            
            for(i=0;i<9;i++){                   //問題の処理を行う
                for(j=0;j<9-i;j++){
                    ary[j] = (ary[j]+ary[j+1])%10;
                }
            }
            printf("%d\n",ary[0]);              //出力
        }else{                                  //受け取りが失敗した場合
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n,x;cin>>n>>x;
    int *arr=new int[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];

    int cnt=1;
    int last=0;
    for(int i=1;i<=n;i++)
    {
        if((last+arr[i])<=x)
            cnt++;
        last+=arr[i];
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(){

	int N, i;

	cin >> N >> i;

	cout << N - i + 1 << endl;

	return 0;
}


Measured memory_bytes: 768
#coding utf-8
S=input()
N=int(len(S))

child =[0 for i in range(N)]

Rcount=0
Lcount=0

for i in range(N-1):
  if S[i:i+1]=="R":
    if S[i+1:i+2]=="R":
      Rcount +=1
    else:
      Richi=i
  else:
    if S[i+1:i+2]=="L":
      Lcount +=1
    else:
      child[Richi]=1+Rcount//2+(Lcount+1)//2
      child[Richi+1]=1+(Rcount+1)//2+Lcount//2
      Rcount=0
      Lcount=0

      
child[Richi]=1+Rcount//2+(Lcount+1)//2
child[Richi+1]=1+(Rcount+1)//2+Lcount//2      
ans = map(str,child)
ans =" ".join(ans)
print(ans)      

Measured memory_bytes: 10492
houses=[[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n=int(input())

for i in range(n):
    b,f,r,v=map(int,input().split())

    houses[b-1][f-1][r-1] += v

for b in range(4):
    for f in houses[b]:
        print('',*f)
    if b != 3:
        print('#'*20)


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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.at(i);
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += d.at(i) * d.at(j);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
n = int(input())
dum = list(map(int, input().split()))
ame = [0]*n
S = sum(dum)
dumeven, dumodd = 0, 0

for i in range(0, n, 2):
    dumeven += dum[i]
for i in range(1, n-1, 2):
    dumodd +=  dum[i]
    
ame[0] = dumeven - dumodd
for i in range(1, n):
    ame[i] = 2*dum[i-1] - ame[i-1]
for i in range(n):
    print(str(ame[i]) + ' ', end="")

Measured memory_bytes: 14032
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
#include <atcoder/all>

using namespace std;
using namespace atcoder;
typedef long long ll;

/*
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
void Add(ll &pos,ll val){pos=mod(pos+val);}
void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
*/

#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

typedef long double dd;
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
dd EPS=1E-12;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second

#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;


//using mint = modint998244353;
using mint = modint1000000007;
//using mint=modint;
//using mint=static_modint<100>;
//////////////////////////


int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[n][n];rep(i,0,n-1)rep(j,0,n-1)cin>>a[i][j];
    mcf_graph<ll,ll>g(n*2+2);
    ll S=2*n,T=2*n+1;
    rep(i,0,n-1){
        g.add_edge(S,i,k,0);
        g.add_edge(i+n,T,k,0);
    }
    ll B=powl(10,9);
    g.add_edge(S,T,inf,B);
    rep(i,0,n-1){
        rep(j,0,n-1){
            g.add_edge(i,j+n,1,B-a[i][j]);
        }
    }
    l_l ret=g.flow(S,T,n*n);
    cout<<n*n*B-ret.se<<endl;
    bool b[n][n];memset(b,0,sizeof(b));
    auto edges=g.edges();
    for(auto x:edges){
        if(x.from>=2*n)continue;
        if(x.to>=2*n)continue;
        if(x.flow!=1)continue;
        b[x.from][x.to-n]=true;
    }
    rep(i,0,n-1){
        rep(j,0,n-1){
            if(b[i][j])cout<<"X";
            else cout<<".";
        }cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3932
#include <stdio.h>

int gcd_get(int x, int y)
{
	int r;
	while (y != 0)   
	{
		r = x % y; 
		x = y; 
		y = r; 
	}
	return x; 
}

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

	long long int result = 0;
	for(int a = 1; a <= K; a++)
		for (int b = 1; b <= K; b++)
			for (int c = 1; c <= K; c++)
			{
				int r1 = gcd_get(a, b);
				int r = gcd_get(r1, c);

				result += r;
			}

	printf("%lld", result);

	return 0;
}





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

using namespace std;
using ll = long long;

int main() {
    int n;
    ll w;
    cin>>n>>w;
    vector<pair<ll,ll>> d;
    for(int i = 0; i < n; ++i){
        ll w,v;
        cin>>w>>v;
        d.emplace_back(w,v);
    }
    map<ll,ll> mp;
    mp[0]=0;
    map<ll,ll> t;
    for(int i = 0; i < n; ++i){
        t.clear();
        for(auto m:mp) {
            if(m.first+d[i].first<=w)t[m.first+d[i].first]=max(t[m.first+d[i].first],m.second+d[i].second);
        }
        for(auto m:t){
            mp[m.first]=max(mp[m.first],m.second);
        }
    }
    ll ans=0;
    for(auto i:mp)ans=max(ans,i.second);
    cout<<ans<<endl;
    return 0;
}

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

const int MOD = 1000000007;
int main() {
  long long N, K;
  cin >> N >> K;
  long long res = 0;
  for (long long k = K; k <= N + 1; ++k) {
    long long first = k * (k - 1) / 2;
    long long final = (N * 2 - k + 1) * k / 2;
    long long add = final - first + 1;
    res = (res + add) % MOD;
  }
  cout << res << endl;
}


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

typedef long long ll;
const int maxn=4e6+10;
int n,a[maxn],sum;
bitset<maxn> b;

int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i],sum+=a[i];
	b[0]=1;
	for(int i=1;i<=n;++i)
		b|=b<<a[i];
	for(int i=ceil((double)sum/2);i;++i)
		if(b[i]){
			printf("%d\n",i);
			return 0;
		}
	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

ll mo=1000000007;
ll dp[101010];

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

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

	int N, K;
	cin >> N >> K;

	ll sum = 0;
	for(int i=K; i>=1; i--) {
		dp[i] = modpow(K/i,N);
		for (int j=i*2;j<=K;j+=i) dp[i] -= dp[j];
		sum += i*dp[i]%mo;
	}
	cout << sum%mo << endl;

    return 0;
}


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

int bubbleSort(int A[], int n) {
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j > i; j--) {
            if (A[j] < A[j-1]) {
                // swap
                int tmp = A[j-1];
                A[j-1] = A[j];
                A[j] = tmp;
                count++;
            }
        }
    }
    return count;
}

int main () {
    int n;
    cin >> n;
    int A[n];

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

    int count;
    count = bubbleSort(A, n);

    for (int i = 0; i < n; i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
using namespace std;
#define FORN(i,m,n) for(ll i=(m); i<ll(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a,b)
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n, ans = 0;
  string s;
  cin>>n>>s;
  for(int i = 0; i + 2 < n; i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("%s\n","a > b");
    }else if(a<b){
        printf("%s\n","a < b");
    }else printf("%s\n","a == b");
    return 0;
}



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

int main() {
	int r;

	cin >> r;

	if(r < 1200) {
		cout << "ABC" << "\n";
	}
	else if(r < 2800) {
		cout << "ARC" << "\n";
	}
	else {
		cout << "AGC" << "\n";
	}

	return 0;
}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 101;

void solve() {
	int n, s;
	cin >> n >> s;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<vector<int>> dp(n + 1, vector<int>(s + 1));
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= s; j++) {
			dp[i][j] = dp[i - 1][j] * 2 % MOD;
			if (j - a[i] >= 0) dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % MOD;
		}
	}
	cout << dp[n][s];
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 73668
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>n>>a;
  ll ans = 0;
  while(n > 0){
    ans++;
    n/=a;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import collections


def calculateC(n):
    n_C_i = n * (n-1)
    return n_C_i // 2

n = int(input())
ans = []
for _ in range(n):
    s = list(input())
    s.sort()
    a = ''
    for i in range(len(s)):
        a += s[i]
    ans.append(a)
cnt = collections.Counter(ans).most_common()
aa = 0
for i in range(len(cnt)):
    if cnt[i][1] == 1:
        break
    aa += calculateC(cnt[i][1])
print(aa)


Measured memory_bytes: 24460
#include <bits/stdc++.h>
using namespace std;
long long int k, a, b;
long long int ans = 0;

int main()
{
    cin >> k >> a >> b;
    if (b - a <= 2 || k < a + 1)
    {
        cout << k + 1 << endl;
        return 0;
    }
    else
    {
        ans = (k - a + 1) / 2;
        ans *= (b - a);
        ans += a;
    }

    if ((k - a + 1) % 2 == 1)
    {
        ans++;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [0]*(n+1)
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            ans = x**2+y**2+z**2+x*y+x*z+y*z
            if(ans>n):
                continue
            l[ans] += 1

print(*l[1:])



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

using namespace std;

#define F first
#define S second
#define MP make_pair
#define PB emplace_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

const int N = 2e3 + 100;

long long int n, k, dp[N][N], mod = 924844033, fac[N], rev[N], mas[N];

long long int wop(long long int x, long long int y) {
    long long int ret = 1;
    for(; y ; y /= 2) {
        if(y & 1)ret *= x;
        x *= x;
        x %= mod;
        ret %= mod;
    }
    return ret;
}

long long int chos(long long int r, long long int n) {
    if(r < 0 || n < 0 || r > n) return 0;
    return fac[n] * (rev[r] * rev[n - r] % mod) % mod;
}

void add(int x) {
    for(int j = n ; j >= 0 ; j--) {
        for(int i = x ; i >= 1 ; i--) {
            if(j - i < 0) continue;
            mas[j] += (mas[j - i] * dp[x][i]) % mod;
            mas[j] %= mod;
        }
    }
}

int main () {
    fac[0] = rev[0] = 1;
    for(int i = 1 ; i <= 2020 ; i++ ) {
        fac[i] = fac[i-1] * i;
        fac[i] %= mod;
        rev[i] = wop(fac[i], mod - 2);
    }
    cin >> n >> k;
    for(int i = 0 ; i <= n ; i ++ ) {
        for(int j = 0 ; j <= n ; j++ ) {
            dp[i][j] = chos(j, i - j);
        }
    }
    mas[0] = 1;
    int t = n % k;
    int t2 = k - t;
    t*=2;
    t2*=2;
    while(t--) {
        add((n / k) + 1);
    }
    while(t2--) {
        add(n / k);
    }
    long long int ans = 0;
    for(int i = 0 ; i <= n ; i++ ) {
        long long int za = ((i & 1) ? -1 : +1);
        if(za == +1) {
            ans += (mas[i] * fac[n-i]) % mod;
        }
        else {
            ans -= ((mas[i] * fac[n-i]) % mod);
            ans += mod;
        }
        ans %= mod;
    }
    cout << ans;
}


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

using namespace std;

struct Key {
    int price;
    int mask;
    Key() {}
    void read() {
        int b;
        cin >> price >> b;
        mask = 0;
        for (int i = 0; i < b; ++i) {
            int c;
            cin >> c;
            mask |= (1 << (c-1));
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<Key> keys(m);
    for (Key& key : keys) {
        key.read();
    }
    int inf = 1000000000;
    vector<int> best_price(1 << n, inf);
    best_price[0] = 0;
    for (Key& key : keys) {
        for (int mask = 0; mask < (1 << n); ++mask) {
            best_price[mask | key.mask] = min(best_price[mask | key.mask], best_price[mask] + key.price);
        }
    }
    if (best_price[(1 << n)-1] == inf) {
        cout << -1 << endl;
    } else {
        cout << best_price[(1 << n)-1] << endl;
    }
    return 0;
}


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



int main() {

    int n;
    cin>>n;


    vector<int> v(n);
    vector<int> c(n);

    for(int i=0;i<n;i++){
        cin>>v.at(i);
    }

    for(int i=0;i<n;i++){
        cin>>c.at(i);
    }

    int x=0,y=0;
    for(int i=0;i<n;i++){
        if(v.at(i)>c.at(i)){
            x+=v.at(i);
            y+=c.at(i);
        }
    }

    cout<<x-y<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

string s, ans;
int main() {
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '0') ans += '0';
		if (s[i] == '1') ans += '1';
		if (s[i] == 'B' && ans.length() > 0) ans.erase(ans.length() - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s=="A"){
        cout<<"T";
    }else if(s=="T"){
        cout<<"A";
    }else if(s=="C"){
        cout<<"G";
    }else {
        cout<<"C";
    }

    return  0;
}

Measured memory_bytes: 256
#include<stdio.h>

int linearSearch(int S[], int n, int key){
    int i=0;

    S[n] = key;

    while(S[i] != key){
        i++;

        if(i==n){
            return 0;
        }
    }

    return 1;
}

int main(){
    int S[500000], key, i, n, q;
    int sum = 0;

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

    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &key);
        if(linearSearch(S,n,key) == 1)
            sum++;
    }

    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 1852
# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 17:22:42 2018
ABC080
@author: maezawa
"""
import itertools as itr

n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
    
#print(f)
#print(p)
profit = -10**10
for oph in itr.product([0,1], repeat=10):
    if oph == (0,0,0,0,0,0,0,0,0,0):
        continue
    c = [0]*n
    for i in range(n):
        c[i] = sum([f[i][j]*oph[j] for j in range(10)])
    pcurrent = sum([p[i][c[i]] for i in range(n)])
    if pcurrent > profit:
        profit = pcurrent
        #print(oph)

print(profit)


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

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

    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        for (int j = 0; j < S.length() - i + 1; j++) {
            string res = S.substr(i, j);
            if (regex_match(res, regex("(A|T|G|C)*")))
                ans = max((int)res.length(), ans);
        }
    }

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

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    char s[11];
    int a;
    scanf("%s",s);
    a=s[5]-'0';
    a*=10;
    a+=s[6]-'0';
    if(a<5){
        printf("Heisei\n");
    }
    else{
        printf("TBD\n");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N =3003;
double p[N],dp[N][N];
ll n;

int main()
{
    ios_base::sync_with_stdio(false);
	cout<<setprecision(12)<<fixed;


    cin>>n;ll x=n;
    forn(i,n)cin>>p[i+1];
    dp[0][0]=1;forn(i,n)dp[i+1][0]=dp[i][0]*(1-p[i+1]);

    for(int i=1;i<=n;i++)for(int j=1;j<=x;j++)
	{
		dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
	}
	//forn(j,x+1){forn(i,n+1)cout<<dp[i][j]<<" ";cout<<endl;}

    double ans=0;
    for(int i=(n+1)/2;i<=n;i++)ans+=dp[n][i];
    cout<<ans<<endl;
}


Measured memory_bytes: 70656
#include <iostream>
#include <stdio.h>
#include <string>


using namespace std;

int main(){
    int n = 1000;
    int a, b;
    int x;
    //char c[1];
    string c;
    int A[100];
    int count = 0;

    for(int i = 0; i < n; i++){
        cin >> a >> c >> b;
        //printf("a %d\n", a);
        //printf("aaa\n");
        //cout << c << endl;
        if("+" == c){
            //printf("bbb\n");
            x = a + b;
            A[i] = x;
            //printf("ccc\n");
        }
        else if("-" == c){
            x = a - b;
            A[i] = x;
        }
        else if("*" == c){
            x = a * b;
            A[i] = x;
        }
        else if ("/" == c){
            x = a / b;
            A[i] = x;
        }
        else if("?" == c){
            break;
        }
        
        count++;
        //printf("ddd\n");
   
    }
    
    for(int i = 0; i < count; i++){
        printf("%d\n", A[i]);
    }
    

    return 0;
    
}


Measured memory_bytes: 3224
#include<stdio.h>

//----- ユークリッドの互除法を行う関数 -----//

int f_kouyakusuu(int , int , int *);

//----- 最小公倍数を求める関数 -----//

int f_koubaisuu(int , int , int *);


//*****----- main -----*****//

int main(void)
{
	//入力変数2つ
	int x = 0 , y = 0;
	//公約数と公倍数は保存しておかなければならない
	int kouyakusuu = 0 , koubaisuu = 0;

	while (scanf("%d %d" , &x , &y) != EOF)
	{
		koubaisuu = f_koubaisuu(x , y , &kouyakusuu);
		printf("%d %d\n" , kouyakusuu , koubaisuu);
	}

	return 0;
}




//*****----- ユークリッドの互除法を利用する関数 -----*****//

int f_kouyakusuu(int x , int y , int *kouyakusuu)	//最初ｘ＜ｙでもforによって入れ替えられる
{
	//保存変数
	int hozon = 0;

	//割って0になるまで
	while ((hozon = x % y) != 0)
	{
		x = y;
		y = hozon;
	}

	//公約数を保存する
	*kouyakusuu = y;
	//最後に割ったｘを返す
	return y;
}



//*****----- 最小公倍数を求めるプログラム *****-----//

int f_koubaisuu(int x , int y , int *kouyakusuu)
{
	//最初に計算して値を小さくする
	int modoriti = f_kouyakusuu(x , y , kouyakusuu);
	//値がでかいので工夫
	unsigned long long int hozon = x * y;
	hozon = x / modoriti;
	//計算して値を返す
	return hozon * y;
}

Measured memory_bytes: 1024
h,w=map(int,input().split())
n=int(input())
a=map(int,input().split())
l=[["" for _ in range(w)] for _ in range(h)]

m=[]
for i,j in enumerate(a,start=1):
  m.extend([str(i)]*j)

p=0
for i in range(h):
  for j in range(w):
    if i%2:
      l[i][w-j-1]=m[p]
    else:
      l[i][j]=m[p]
    p+=1

for i in l:
  print(" ".join(i))

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    multiset<int> prices;
    while (n --> 0) {
        int price;
        cin >> price;
        prices.insert(price);
    }
    while (m --> 0) {
        int price = *prices.rbegin();
        prices.erase(prices.find(price));
        prices.insert(price/2);
    }
    long long sum = 0;
    for (int price : prices) {
        sum += price;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4992
N, K = map(int, input().split())
A = list(map(int, input().split()))

d = {}

for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

val_sorted = sorted(d.values())

ans = 0

for i in range(len(val_sorted) - K):
    ans += val_sorted[i]

print(ans)


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


int main()
{
	string N;
	cin>>N;
	rep(i,4-3+1)
	{
		if(N[i]==N[i+1]&&N[i+1]==N[i+2])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector <int> A(N), B(N), C(N-1);
    REP(i,N) cin >> A[i];
    REP(i,N) cin >> B[i];
    REP(i,N) cin >> C[i];
    int ans = 0;
    REP(i,N){
        ans += B[A[i]-1];
        if (i!=0 && A[i]==A[i-1]+1) ans += C[A[i-1]-1];
    }
    cout << ans << endl;
    return 0;
}



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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  ll pmax = numeric_limits<ll>::max(), answer = 0;
  REP(i, N) {
    ll P;
    cin >> P;
    if (pmax > P) {
      answer++;
      pmax = P;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3648
n = int(input())
a = list(map(int,input().split()))
y = [0 for _ in range(n)]
suma = sum(a)
ans = []
memo1 = 2*sum([a[j%n] for j in range(0, 0+n, 2)])-suma
memo2 = 2*sum([a[j%n] for j in range(1, 1+n, 2)])-suma
ans.append(str(memo1))
ans.append(str(memo2))
# (i+n-2)%n - (i-2)%n
for i in range(2,n):
	if i%2 == 0:
		memo1 = memo1 + 2*(a[(i+n-1)%n] - a[(i-2)%n])
		ans.append(str(memo1))
	else:
		memo2 = memo2 + 2*(a[(i+n-1)%n] - a[(i-2)%n])
		ans.append(str(memo2))
print(" ".join(ans))

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

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

int dp[n] = {0};

dp[1] = abs(h[0]-h[1]);
for(int i = 2;i<n;i++)
{
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]),dp[i-2]+ abs(h[i]-h[i-2]));
}
cout<<dp[n-1];

}


Measured memory_bytes: 1024
import scala.io.StdIn._

object Main extends App {

  val Array(h,w) = readLine().split(" ").map(_.toInt)
  val Array(h1,w1) = readLine().split(" ").map(_.toInt)

  def solve() = {
    (h-h1) * (w-w1)
  }
  println(solve())

}



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

int main() {
    long n, m;
    cin >> n >> m;
    vector<pair<long,long>> s(n);
    rep(i, n) {
        cin >> s[i].first >> s[i].second; // 値段→本数
    }
    sort(s.begin(), s.end()); // 値段の安い順にソート
    // rep(i, n) {
    //     cout << s[i].first << " " << s[i].second << endl;
    // }
    long k = 0, sum = 0, i = 0;
    while (k < m) {
        long yen = s[i].first, hon = s[i].second;
        if (k + hon < m) {
            k += hon;
            sum += yen * hon;
        } else {
            sum += yen * (m - k);
            k = m;
        }
        i++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define var auto
using ll = long long;
const char newl = '\n';
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if(a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if(a < b) a = b;}

using namespace std;

void solver(string s) {
    vector< int > cnt(12, 0);

    ll ans = 0;
    int n = 0;
    int k = 1;
    cnt[0]++;
    for (int i = s.size() - 1; i >= 0; i -= 1) {
        n += k * (s[i] - '0');
        k *= 10;
        n %= 11;
        k %= 11;
        if (s[i] != '0') ans += cnt[n];
        cnt[n]++;
    }

    cout << ans << endl;
    return;
}

signed main(){
  string s;
  
  while (cin >> s, s != "0") {
      solver(s);
  }
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238 


long long binpow(long long a, long long b) {
    a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
void solve(){
    ll n,k;
    cin>>n>>k;
    vll cnt(n+1,0);
    ll ans =0;
    for(int i =1;i<=k;i++){
        ll d;
        cin>>d;
        for(int j =1;j<=d;j++){
            ll x;
            cin>>x;
            cnt[x]++;
        }
    }
    for(int i =1;i<=n;i++){
        if(cnt[i] ==0)
            ans++;
    }
    cout<<ans<<endl;
}   
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }    
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    ll v = atoll(s.c_str());
    ll ten = 1;
    rep(i,s.size()) ten*=10;

    vector<int> p(10);
    iota(all(p),0);

    string ans;
    ll ansd = -1;
    do {
        string t = "";
        rep(i,s.size()) t += '0'+p[i];
        ll u  = atoll(t.c_str());
        ll d = min(abs(v-u),ten-abs(v-u));
        if(ansd<d || (ansd==d && atoll(ans.c_str())>atoll(t.c_str())))
        {
            ansd = d;
            ans = t;
        }

    } while(next_permutation(all(p)));

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

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main() {
int a,b;
cin>>a>>b;
int c=b-a;
int d=0;
for(int i=1; i<c; i++) d+=i;
cout<<d-a<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 6
#define NA 100
using namespace std;

void change(char);
int dice[N];

int main(){
  
  char arrow[NA];
  string str;
  int i,j;
  for(i=0;i<N;i++){ 
    cin>>dice[i];
  }
  i=0;
  getline(cin,str);
  getline(cin,str);
  
  for(i=0;i<str.length();i++){
    arrow[i]=str[i];
  }

  for(i=0;i<str.length();i++){
    change(arrow[i]);
  }
  cout<<dice[0]<<endl;

}

void change(char c){
  if(c=='N'){
    swap(dice[0],dice[4]);
    swap(dice[0],dice[1]);
    swap(dice[1],dice[5]);
  }else if(c=='S'){
    swap(dice[0],dice[1]);
    swap(dice[0],dice[4]);
    swap(dice[5],dice[4]);
  }else if(c=='W'){
    swap(dice[2],dice[0]);
    swap(dice[2],dice[5]);
    swap(dice[5],dice[3]);
  }else if(c=='E'){
    swap(dice[0],dice[3]);
    swap(dice[3],dice[5]);
    swap(dice[5],dice[2]);
  }
}



Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  long n;
  cin >> n;
  n--;
  long s=0, p=26;
  int i=0;
  for(i=0; i<12; i++){
    if(s<=n && n<s+p){
      n-=s;
      break;
    }
    s+=p;
    p*=26;
  }
  //cerr << n << endl;
  //cerr << i << endl;
  string ret="";
  for(int j=0; j<=i; j++){
    ret.push_back(n%26+'a');
    n/=26;
  }
  reverse(ret.begin(), ret.end());
  cout << ret;
  return 0;
}
    

Measured memory_bytes: 3124
def find(edges):
    import bisect
    edges=sorted(edges)
    ans=0
    for i in range(len(edges)):
        for j in range(i+1,len(edges)):
            temp=edges[i]+edges[j]
            pos=bisect.bisect_left(edges,temp)
            ans+=max(0,pos-1-j)
            #print(edges[i],edges[j],max(0,pos-1-j))
    return ans

input()
print(find(list(map(int,input().strip().split(" ")))))

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

int main() {
  int n;
  cin >> n;
  
  vector<int> dp(100010,0);
  dp[0] = 0;
  for (int n = 1; n <= 100000; n++) {
    dp[n] = 1000000;
    int p = 1;
    while (p <= n){
      dp[n] = min(dp[n], dp[n-p] + 1);
      p *= 6;
    }
    p = 1;
    while (p <= n){
      dp[n] = min(dp[n], dp[n-p] + 1);
      p *= 9;
    }
  }

  cout << dp[n] << endl;

}

Measured memory_bytes: 3760
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b and b == c and a % 2 == 0) {
		printf("%d\n", -1);
		return 0;
	}
	int ans = 0;
	while (true) {
		if (a % 2 or b % 2 or c % 2) break;
		int na = (b + c) / 2, nb = (a + c) / 2, nc = (a + b) / 2;
		a = na, b = nb, c = nc;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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; }

int main() {
  int n, x;
  cin >> n >> x;
  vi a(n);
  REP(i, n) cin >> a[i];
  ll ans = 0;
  FOR(i, 1, n) {
    int tmp = a[i] + a[i-1];
    if(x<tmp) {
      int y = min(tmp-x, a[i]);
      ans += y;
      a[i] -= y;
    }
  }
  reverse(all(a));
  FOR(i, 1, n) {
    int tmp = a[i] + a[i-1];
    if(x<tmp) {
      int y = min(tmp-x, a[i]);
      ans += y;
      a[i] -= y;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
h, w, k = map(int, input().split())
c = []
for i in range(h):
  c.append(list(input()))

ans = 0

for row in range((1 << h) - 1): #2^h - 1
  for col in range((1 << w) - 1): #2^w -1
    black = 0
    for i in range(h):
      for j in range(w):
        if (row >> i) & 1 == 0 and (col >> j) & 1 == 0 and c[i][j] =='#':
           black += 1
    if black == k:
      ans += 1

print(ans)


Measured memory_bytes: 74048
# # 整数の入力
# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())
# # 文字列の入力
# s = input()
n = int(input())

ans = "No"

for i in range(1, 10):
    if n < 100 and n / i == n // i and n / i < 10:
        ans = "Yes"

print(ans)


Measured memory_bytes: 2940