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

std :: unordered_map < int, int > cnt ;

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

	for ( int i = 1 ; i <= n ; ++ i )  {
		static int x ;
		
		scanf ( "%d", & x ) ;
	
		++ cnt [x] ;
	}

	int ans ( 0 ) ;

	for ( std :: unordered_map < int, int > :: iterator it = cnt.begin ( ) ; it != cnt.end ( ) ; ++ it )  {
		ans += it -> second - it -> first >= 0 ? it -> second - it -> first : it -> second ;
	} 

	return ! printf ( "%d\n", ans ) ;
}


Measured memory_bytes: 4260
fun main(args: Array<String>) {
    abc086c()
}

private data class Txy(val time: Int, val x: Int, val y: Int)

fun abc086c() {
    val n = readLine()!!.toInt()
    val txy = listOf(Txy(0, 0, 0)) + (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
        .map { Txy(it[0], it[1], it[2]) }

    val answer = (0 until n).all { i ->
        val curr = txy[i]
        val next = txy[i + 1]

        val move = Math.abs(next.x - curr.x) + Math.abs(next.y - curr.y)
        val moveCap = Math.abs(next.time - curr.time)
        val remainMove = moveCap - move
        remainMove >= 0 && remainMove % 2 == 0
    }.let { if (it) "Yes" else "No" }

    println(answer)
}


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

int gcd(int a, int b){
    while(a != b){
        if(a > b) a = a - b; else b = b - a;
    }
    return a;
}

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

int main(){
    int h, w;
    while(true){
        char torus[10][20];
        string str[2048];
        bool ok[2048];
        int num = 0;

        for(int i=0; i<2048; ++i){
            str[i] = "";
            ok[i] = true;
        }

        cin >> h >> w;
        if(h==0 && w==0) break;

        int cml = lcm(w, h);

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cin >> torus[i][j];
            }
        }

        //一番長い文字列をつくる

        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<h; ++i){
                    str[num] += torus[(y+i)%h][x];
                    str[num+1] += torus[h-(y+i)%h-1][x];
                }
                num += 2;
            }
        }
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<w; ++i){
                    str[num] += torus[y][(x+i)%w];
                    str[num+1] += torus[y][w-(x+i)%w-1];
                }
                num += 2;
            }
        }
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<cml; ++i){
                    str[num] += torus[(y+i)%h][(x+i)%w];
                    str[num+1] += torus[(y+i)%h][w-(x+i)%w-1];
                    str[num+2] += torus[h-(y+i)%h-1][(x+i)%w];
                    str[num+3] += torus[h-(y+i)%h-1][w-(x+i)%w-1];
                }
                num += 4;
            }
        }


        vector<char> result;

        sort(str, str+num);

        for(int i=num-1; i>0; --i){
            int length = 0;
            vector<char> k;
            for(int j=0; j<min(str[i].length(), str[i-1].length()); ++j){
                if(str[i][j] == str[i-1][j]) k.push_back(str[i][j]); else break;
            }
            if(k.size() >= result.size()){
                result = k;
            }
        }

        if(result.size() == 1){
            cout << "0" << endl;
        }else{
            vector<char>::iterator it = result.begin();
            while( it != result.end()){
                cout << *it;
                ++it;
            }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1524
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename T = char, typename U = string>
vector<pair<T, int> > rle(const U &str) {
  int n = str.size();
  vector<pair<T, int> > res;
  T now = str[0];
  int cnt = 1;
  FOR(i, 1, n) {
    if (str[i] != now) {
      res.emplace_back(now, cnt);
      cnt = 0;
    }
    now = str[i];
    ++cnt;
  }
  res.emplace_back(now, cnt);
  return res;
}

int main() {
  int n; cin >> n;
  string s; cin >> s;
  vector<pair<char, int> > ans = rle<>(s);
  cout << ans.size() << '\n';
  return 0;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		cout<<n*n;
	}
	return 0;
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
cnt = 0

if k % 2 == 1:
    for i in range(1, n+1):
        if i % k == 0:
            cnt += 1
    ans = cnt ** 3
elif k % 2 == 0:
    cnt1 = 0
    cnt2 = 0
    for i in range(1, n+1):
        if i % k == 0:
            cnt1 += 1
        elif i % k == k/2:
            cnt2 += 1
    ans = cnt1 ** 3 + cnt2 ** 3
print(ans)

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

using namespace std;

typedef long long int ll;

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

typedef pair<int,int> pair;


int main(){
    int a,b; cin >> a >> b;

    int sum=a+b;
    int ans;

    if(sum==3){
        ans=3;
    }else if(sum==4){
        ans=2;
    }else if(sum==5){
        ans=1;
    }

    cout << ans << endl;

    
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int outCount = 0; // MAX:3
		int inning = 0; //????????????????????° MAX:50
		int runner = 0; //?????????????????° MAX:3
		int point = 0; // ??????
		String str;
		ArrayList<Integer> inningRun = new ArrayList<Integer>();
		Scanner sc = new Scanner(System.in);
		inning = sc.nextInt(); // ????????????????????°(???????????°)
		for (int i = 0; i < inning; ++i) {
			while (true) { // ???????????¢???????????§?????????
				str = sc.next();
				if (str.equals("OUT")){
					++outCount; //??¢?????????????????????1????¢????
				} else if (str.equals("HIT")) {
					if(runner < 3) ++runner; // 1???????????§????????????1???
					else if(runner == 3) ++point; // ?????????????????????????????§???????????§????????§???????????????????????????
				} else if (str.equals("HOMERUN")) {
					if(runner == 0) ++point; // ????????????????????????1???
					else if(runner == 1){
						point += 2; // ????????????1?????????2???
						runner = 0;
					}

					else if(runner == 2){
						point += 3; // ????????????2?????????3???
						runner = 0;
					}
					else if(runner == 3){
						point += 4; // ????????????3?????????4???
						runner = 0;
					}
				}//System.out.println(outCount+"out,????????????:"+runner);
				if(outCount == 3){ //???????????¢?????????????????????????????????????????¢?????????????????????????????????
					//System.out.println(point+"??????");
					inningRun.add(point);
					runner = 0;
					point = 0;
					outCount = 0;
					break;
				}
			}
		}
		for(int i = 0; i < inningRun.size(); ++i){
			System.out.println(inningRun.get(i));
		}
		sc.close();
	}

}

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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      string str;
      cin>>str;

      ll cnt=0;
      ll mx=0;
      for(int i=0; i<3; i++){
            if(str[i]=='R'){cnt++;continue;}
            else{
                  if(cnt>mx) mx=cnt;
                  cnt=0;
            }
      }
      if(cnt>mx) mx=cnt;
      cout<<mx<<endl;


      bye;
}


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

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

    string S, T;
    cin >> S >> T;

    int res = 0;
    REP(i, S.size()) {
        if (S[i] == T[i]) ++res;
    }

    cout << res << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n,m) for(int i=(n);i<(m);i++)
#define REP_EQ(i,n,m) for(int i=(n);i<=(m);i++)
#define CNT(i,n) for(int i=(n);i>0;i--)
#define REP_two(i,n,m) for(int i=(n);i<(m);i+=2)
#define ll long long
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int MAX=1e9;
int MOD=1e9+7;

int main(){
  int a,b,k;
  cin>>a>>b>>k;
  vector<int> c(0);
  for(int i=1;i<=100;i++){
    if(a%i==0&&b%i==0){
      c.push_back(i);
    }else{
      c.push_back(1);
    }
  }
  sort(c.begin(),c.end(),greater<int>());
  cout<<c[k-1]<<endl;
}


Measured memory_bytes: 256
from decimal import *

a, b= input().rstrip().split(' ')

# num_len = max(len(a), len(b)) + 1
# minprec = 27
# if num_len > minprec:
#     getcontext().prec = num_len
# else:
#     getcontext().prec = minprec
getcontext().prec = 1000000    

print(Decimal(a) + Decimal(b))


Measured memory_bytes: 6720
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int main(void){
	int n=nextint();
	int x=nextint();
	int t=nextint();
	int ans=(n-1)/x*t+t;
	printf("%d\n", ans);
}


Measured memory_bytes: 1576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, q;
ll a[105], b[105], c[105], d[105];
ll ans;
vector<ll> A;
void dfs(ll index)
{
    if (index == n + 1)
    {
        ll now = 0;
        for (ll i = 1; i <= q; i++)
            if (A[b[i]] - A[a[i]] == c[i])
                now += d[i];
        ans = max(ans, now);
        return;
    }
    for (ll k = A[index - 1]; k <= m; k++)
    {
        A.push_back(k);
        dfs(index + 1);
        A.pop_back();
    }
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> n >> m >> q;
    for (ll i = 1; i <= q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    A.assign(1LL, 1LL);
    dfs(1LL);
    cout << ans << endl;
}

Measured memory_bytes: 3588
import Control.Monad
import Data.List

strictList []     = []
strictList (x:xs) = x `seq` x : strictList xs

solve = count . scanl' f 0
  where
    f n [a, b] = if a < n then n else b
    count = length . nub . tail

readN = map read . words <$> getLine

main = do
  [n, m] <- readN
  rs <- replicateM m readN
  print $ solve . sortOn last . strictList $ rs


Measured memory_bytes: 94588
//ΔAGC032D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 5005;
const LL inf = 1e17;
int n,p[N];
LL a,b,f[N];
int main()
{
	int i,j,o,x,y;
	scanf("%d%d%d",&n,&x,&y);
	a=x,b=y;
	for(i=1;i<=n;i=i+1)
		scanf("%d",p+i);
	p[0]=0,p[n+1]=n+1;
	f[0]=-inf;
	for(i=1;i<=n+1;i=i+1){
		o=-1;
		x=0,y=0;
		for(j=i-1;j>=0;j=j-1){
			if(p[j]>p[i])
				x++;
			else{
				if(p[j]>o){
					f[i]=min(f[i],f[j]+a*x+b*y);
					o=p[j];
				}
				y++;
			}
		}
		//cout<<i<<f[i]+inf<<endl;
	}
	cout<<f[n+1]+inf;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b , c , x , y;
    cin >> a >> b >> c >> x >> y;
	int n = 1e9;
   	for( int i = 0 ; i <= max( x , y ) ; i++ ) {
    	int d = max( x - i , 0 ) * a + max( y - i , 0 ) * b + i * 2 * c;
     	n = min( n , d );
    }
    cout << n;
}


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

#define ll  long double
#define ld long double
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define nguyendz the_best
#define pii pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;

using namespace std;
const ll maxn=2e3+2;
const ll maxx=1e16;
const ll mod=1e9+7;
const ll mod1=998244353;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     ll a,b, c, d;
     cin>>a>>b>>c>>d;
     bool x=false;
     while (1)
     {
         if (!x)
         {
             c-=b;
             if (c<=0)
             {
                 cout <<"Yes";
                 return 0;
             }


         }
         else
         {
             a-=d;
             if (a<=0)
             {
                 cout <<"No";
                 return 0;
             }
         }
         x=!x;
     }
}


Measured memory_bytes: 3740
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()

ans = 0
for i in range(K, N + 1):
    M = ((N + 1) * i) - (i * (i + 1) // 2)
    m = (i * (i - 1) // 2)
    a = M - m + 1
    ans = (ans + a) % MOD
ans = (ans + 1) % MOD
print(ans)

Measured memory_bytes: 63680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const int INF = 1001001001;

int main(){
    int n;
    cin >> n;
    bool ans = false;
    rep(i, 9) if (n%(i+1)==0 && n/(i+1)<10)  ans = true;
    if (ans==true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	string s;
	cin >> s;
	int x = 0;
	for (auto c : s) {
		if (x == 0 && c == 'C')
			x++;
		else if (x == 1 && c == 'F')
			x++;
	}
	if (x == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int t[n],x[n],y[n],cnt=0;
	for(int i=0;i<n;i++){
		cin >> t[i] >> x[i] >> y[i];
	}
	for(int i=0;i<n;i++){
		if(cnt==0){
			if(abs(x[i])+abs(y[i])>abs(t[i])||abs(t[i])%2!=abs(x[i]+y[i])%2){
				cout << "No" << endl;
				return 0;
			}
		}else{
			if(abs(x[i])+abs(y[i])-abs(x[i-1])-abs(y[i-1])>abs(t[i])-abs(t[i-1])||abs(t[i]-t[i-1])%2!=abs(x[i]+y[i]-x[i-1]-y[i-1])%2){
				cout << "No" << endl;
				return 0;
			}
		}
		cnt++;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 200005;
long long a[N];
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] += a[i - 1];
	}
	long long ans = 1e18;
	for (int i = 1; i < n; i++)
		ans = min(ans, abs(a[i] - (a[n] - a[i])));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  cin >> S;

  vvi sum(H, vi(W + 1, 0));
  rep(i, H) {
    rep(j, W) sum[i][j + 1] = sum[i][j] + (S[i][j] == '1');
  }

  int ans = INF;

  rep(i, 1 << (H - 1)) {
    int line = 0;
    rep(j, H - 1) {
      if (i & (1 << j)) line++;
    }

    int lastX = 0;
    bool b = true;
    int a = 0;
    rep(x, W) {
      int s = 0;
      rep(h, H) {
        s += sum[h][x + 1] - sum[h][lastX];
        if (h == H - 1 || i & (1 << h)) {
          // line
          if (s > K) {
            if (x == lastX) {
              b = false;
              break;
            }
            lastX = x;
            x--;
            a++;
          }
          s = 0;
        }
      }
      if (!b) break;
    }
    if (b) chmin(ans, a + line);
  }

  out(ans);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{ 
	ll k,a,b;
	cin>>k>>a>>b;
	if(a % k == 0){
		cout<<"OK"<<endl;
	}
	else {
		ll val = a % k;
	if(a - (a % k) + k <= b){
		cout<<"OK"<<endl;
	}
	else cout<<"NG"<<endl;
	}
	
	return 0;	
} 


Measured memory_bytes: 3624
# 6!は6*5*4*3*2*1
# それぞれを素因数分解すると、3*2*5*2*2*3*2*1となる
# それぞれの個数は5が1個、2が4個、3が2個である
# 選ばない場合もあるので、+1した値をかける
# 2*5*3=30個になる


def prime_factorization(n):
    table = []
    for x in range(2, int(n ** 0.5) + 1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


N = int(input())
MOD = 10**9+7

mp = [0]*1000
for i in range(2, N+1):
    pf = prime_factorization(i)
    for p in pf:
        mp[p] += 1

ans = 1
for p in mp:
    if p == 0:
        continue

    ans = ans*(p+1)

print(ans % MOD)


Measured memory_bytes: 9320
#include <iostream>
#include <iomanip>
#include <string>

using namespace std; 
int main(){
    int a,b,c;
    string op;
    do{
        cin >>a >> op >> b;
        if(op.compare("+") == 0) c = a + b;
        if(op.compare("-") == 0) c = a - b;
        if(op.compare("/") == 0) c = a / b;
        if(op.compare("*") == 0) c = a * b;
        if(op.compare("?") != 0) cout << c << endl;
    }while(op.compare("?") != 0);
    return 0;
}


Measured memory_bytes: 3164
import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int i;
            int n = Integer.parseInt(br.readLine());
            ArrayDeque<String> list = new ArrayDeque<String>();
            String[] num = new String[2];
            String command;
            char c;
            for(i=0; i<n; i++)
            {
                command = br.readLine();
                c = command.charAt(0);

                if(c == 'd')
                {
                    c = command.charAt(6);
                    if(c == 'F')
                    {
                        list.pollFirst();
                    }
                    else if(c == 'L')
                    {
                        list.pollLast();
                    }
                    else
                    {
                        num = command.split(" ",0);
                        list.remove(num[1]);
                    }
                }
                else
                {
                    num = command.split(" ",0);
                    list.offerFirst(num[1]);
                }
            }

            StringBuilder s = new StringBuilder();
            s.append(list.poll());
            while(list.size()>0)
            {
                s.append(" ").append(list.poll());
            }
            System.out.println(s);
        }
        catch(Exception e)
        {
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  deque<int> d;
  for (int i{}; i < N; ++i) {
    int a;
    cin >> a;
    int p = lower_bound(d.begin(), d.end(), a) - d.begin();
    if (!p) {
      d.push_front(a);
    } else {
      d[p-1] = a;
    }
  }

  cout << d.size() << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define dump(x) cerr<<#x<<": "<<x<<endl
#define debug(x) cerr<<#x<<": "<<x<<" ("<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;

int main() {
    int n, t; cin >> n >> t;
    vint a(n);
    rep(i, n) cin >> a[i];
    vint b(n);
    b[0] = a[0];
    FOR(i, 1, n) b[i] = min(b[i-1], a[i]);
    rep(i, n) b[i] = a[i] - b[i];
    sort(b.begin(), b.end(), greater<int>());
    int cnt = 0;
    rep(i, n) {
        if(b[i] != b[0]) break;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll>a(n),b(n),c(n);
    rep(i, 0, n)cin >> a[i];
    rep(i, 0, n)cin >> b[i];
    rep(i, 0, n)cin >> c[i];
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    rep(i, 0, n){
        auto itr1 = lower_bound(a.begin(),a.end(),b[i]);
        ll p = itr1 - a.begin();
        auto itr2 = upper_bound(c.begin(),c.end(),b[i]);
        ll q = c.end() - itr2; 
        ans += p*q;
        //cout << p << " " << q << endl;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

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

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

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

  int vec_b[m][l];
  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
      cin >> vec_b[i][j];
    }
  }

  // 行列Cを宣言、初期化
  long long vec_c[n][l];
  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      vec_c[i][j] = 0;
    }
  }

  // 行列Cへ代入
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      for(int k=0;k<l;k++){
        vec_c[i][k] += vec_a[i][j] * vec_b[j][k];
      }
    }
  }

  // 行列Cを出力
  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      if(j==l-1){
        cout << vec_c[i][j];
      } else {
        cout << vec_c[i][j] << " ";
      }
    }
    cout << endl;
  }
}



Measured memory_bytes: 3240
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, p; cin >> a >> p;
	p += a * 3;
	cout << p / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N, M;
	cin >> N >> M;
	vector<lint>A(M);
	vector<lint>B(M);
	rep(i, M) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	vector<set<lint>>GG(N);
	rep(i, M) {
		GG[A[i]].insert(B[i]);
		GG[B[i]].insert(A[i]);
	}
	vector<vector<lint>>G(N);
	rep(i, N) {
		set<lint>::iterator it;
		for (it = GG[i].begin(); it != GG[i].end(); it++) {
			G[i].push_back(*it);
		}
	}

	lint color = -1;
	int INF = 1000000000;

	vector<int>dist(N, INF);

	for (lint start = 0; start < N; start++) {

		if (dist[start] == INF) {
			//cout << '!' << enld;
			color++;
			queue<int> que;

			dist[start] = color;
			que.push(start);

			//BFS
			while (!que.empty()) {
				int v = que.front();
				que.pop();

				for (int nv : G[v]) {
					if (dist[nv] != INF)continue;
					dist[nv] = color;
					que.push(nv);
				}
			}
		}
	}
	sort(dist);

	lint ans = 0;
	lint cnt = 1;
	for (lint i = 1; i < N; i++) {
		if (dist[i] != dist[i - 1]) {
			ans = max(ans, cnt);
			cnt = 1;
		}
		else {
			cnt++;
		}
	}
	ans = max(ans, cnt);
	
	cout << ans << enld;
}

Measured memory_bytes: 47928
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
using ll = long long;
using P = pair<int,int>;

ll n,m,sum;
string s,t;

int main() {
  cin >> s ;
  for(auto c : s){
    if(c=='7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl s(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    s[i + 1] = s[i] + a;
  }
  ll ans = 1e18;
  rep(i, n - 1) {
    ll now = abs(s[n] - 2 * s[i + 1]);
    ans = min(ans, now);
  }
  cout << ans << endl;
}

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

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

int main() {
  
  int N, M;
  while(cin >> N >> M && (N|M)) {
    vector<vector<double> > p(N, vector<double>(N, 0));
    rep(i, N) rep(j, N) cin >> p[i][j];
    vector<vector<double> > dp(M, vector<double>(N, 0));
    rep(i, N) dp[0][i] = 1.0;
    REP(k, 1, M) rep(i, N) rep(j, N)
      dp[k][j] = max(dp[k][j], dp[k-1][i]*p[i][j]);

    double res = 0.;
    rep(i, N) res = max(res, dp[M-1][i]);
    
    printf("%.2f\n", res);
  }
  
  return 0;
}

Measured memory_bytes: 1356
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
	int n, d, res = 0;
	long x, y = 0;
	cin >> n >> d;

	for (int i = 0; i < n; i++)
	{
		cin >> x >> y;
		if (x <= d && y <= d) {
			if (sqrt(pow(x + y, 2) - 2 * x * y) <= d) {
				res++;
			}
		}
	}

	cout << res << endl;
	
}


Measured memory_bytes: 3628
import math
def calcAngle(h,m):     
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
        angle = abs(hour_angle - minute_angle) 
        angle = min(360 - angle, angle) 
        return angle 

a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])
print(math.sqrt(a[0]*a[0]+a[1]*a[1]-2*a[0]*a[1]*math.cos(math.radians(calcAngle(a[2],a[3])))))




Measured memory_bytes: 62568
#include<bits/stdc++.h>
using namespace std;
long long n,x,y,z,d,ma;
int main()
{
    
    scanf("%d%d%d%d%d",&x,&y,&z,&d,&n);ma=min(min(4*x,2*y),z);
    
    
    cout<<min(ma*n,(n/2*d+n%2*ma))<<endl;

    return 0;
}

Measured memory_bytes: 256
N, D = gets.chomp.split(' ').map(&:to_i)
X = []
Y = []
Xtmp = 0
Ytmp = 0
N.times do
  xtmp, ytmp = gets.chomp.split(' ').map(&:to_i)
  X.push(xtmp)
  Y.push(ytmp)
end
dist = []
N.times do |index|
  dist[index] = Math.sqrt(X[index]**2 + Y[index]**2)
end
count = 0
N.times do |index|
  if dist[index] <= D
    count += 1
  end
end
print count

Measured memory_bytes: 19408
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int odd=0,even=0,feven=0;
    for(int i=0;i<n;i++){
      cin >> a[i];
      if(a[i]%4==0) feven++;
      else if(a[i]%4==2) even++;
      else odd++;
    }
    //case "04...040...40"
    if(even==0 && feven+1==odd) cout << "Yes" << endl;
    else if(feven>=odd) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
n = int(input())
s = input()
ans = 0
for i in range(10):
    if str(i) in s:
        t = s[s.index(str(i))+1:]
        for j in range(10):
            if str(j) in t:
                u = t[t.index(str(j))+1:]
                for k in range(10):
                    if str(k) in u:
                        ans +=1
print(ans)

Measured memory_bytes: 3188
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
n,m,*L=map(int,open(0).read().split())
s=floyd_warshall(csr_matrix((L[2::3],(L[::3],L[1::3])),(n+1,n+1)),0)
ans=0
for f,t,c in zip(*[iter(L)]*3):ans+=s[f,t]<c
print(ans)

Measured memory_bytes: 16544
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	int GetHead(int n) {
		while (n / 10 != 0) {
			//std::cout << n << std::endl;
			n /= 10;
		}

		return n;
	}
	int GetMaxNum(int head, int tail, int digit) {
		int res = 1;
		for (int i = 0; i < digit - 1; ++i) res *= 10;
		res *= (head + 1);
		res -= 10;
		res += tail;
		return res;
	}

	int GetMinNum(int head, int tail, int digit) {
		int res = 1;
		for (int i = 0; i < digit - 1; ++i) res *= 10;
		res *= head;
		res += tail;
		return res;
	}
}


int main() {

	int n;
	std::cin >> n;

	ll ans = 0;

	// c[i][j] := 先頭が i，末尾がjの個数
	std::vector<std::vector<int>> c(10, std::vector<int>(10, 0));
	
	for (int a = 1; a <= n; ++a) {
		int head = GetHead(a);
		int tail = a % 10;
		++c[head][tail];
	}

	rep(i, 10) {
		rep(j, 10) {
			ans += c[i][j] * c[j][i];
		}
	}

	std::cout << ans << std::endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i<b; i++)
typedef long long ll;
int main() {
    ll n;
    cin >> n;
    ll cnt = 2*(n/11);
    ll v = n%11;
    if (v>6)cnt+=2;
    else if(v!=0)cnt++;
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>


using ll=long long;


int main(void)
{
	int r, d, x;

	while(scanf("%d%d%d", &r, &d, &x)==3)
	{
		ll ans=x;
		for(int i=1;i<=10;i++)
		{
			ans=std::max(r*ans-d, 0LL);
			printf("%lld\n", ans);
		}
	}

	return 0;
}


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

hum_can = [[] for _ in range(n)]

for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        hum_can[a[j] - 1] += [i]

print(hum_can.count([]))


Measured memory_bytes: 9200
// input macro
// ref: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_mut)]
fn solve(s: String) -> String {
    let mut left = 0;

    let mut stack: Vec<char> = vec![];

    for c in s.chars() {
        if c == '(' {
            stack.push('(');
        }
        else if c == ')' {
            if stack.is_empty() {
                left += 1;
            }
            else {
                stack.pop();
            }
        }
    }

    let right = stack.len();

    let mut ans = String::new();
    for _ in 0..left {
        ans.push('(')
    }

    for c in s.chars() {
        ans.push(c);
    }

    for _ in 0..right {
        ans.push(')');
    }

    return ans
}

#[allow(unused_mut)]
fn main() {
    input!(
        _n: usize,
        s: String,
    );

    let ans = solve(s);
    println!("{}", ans);
}


Measured memory_bytes: 4352
s = list(str(input()))

n = len(s)
dp = [0] * 13
dp[0] = 1

for i in range(n):
    prev = dp[:]
    dp = [0]*13

    if s[i] == '?':
        for z in range(10):
            for j in range(13):
                dp[(j*10+z)%13] += prev[j]
                dp[(j*10+z)%13] %= 10**9+7

    else:
       _s = int(s[i])
       for j in range(13):
            dp[(j*10+_s)%13] += prev[j]
            dp[(j*10+_s)%13] %= 10**9+7

print(dp[5])



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

int main() {

	ll n; cin >> n;
	map<string, ll> mp;
	for (ll i = 0; i < n; i++) {
		string s; cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	ll ans = 0;
	for (auto u : mp) {
		ans += u.second * (u.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11396
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <utility>
#include <tuple>
using namespace std;
using AnsType = long long int;

const int SIZE = 1 << 19;
struct SegmentTree {
  AnsType node[2 * SIZE];
  SegmentTree() {
    fill(node, node + 2*SIZE, 0);
  }
  void add(int k, AnsType val) {
    k += SIZE - 1;
    node[k] += val;
    while(k > 0) {
      k = (k - 1) / 2;
      node[k] = node[2*k+1] + node[2*k+2];
    }
  }
  AnsType query(int a, int b, int l=0, int r=SIZE, int k=0) {
    if(b <= l or r <= a) return 0;
    if(a <= l and r <= b) return node[k];
    int mid = (l + r) / 2;
    AnsType vl = query(a, b, l, mid, 2*k+1);
    AnsType vr = query(a, b, mid, r, 2*k+2);
    return vl + vr;
  }
};

SegmentTree seg;
int main() {
  int N, C; scanf("%d%d", &N, &C);
  map< pair<AnsType, int>, int > comp;
  vector<AnsType> point(N);
  for(int i=0; i<N; i++) {
    comp[ make_pair(0LL, i) ]++;
  }
  
  vector<int> q(C), v1(C), v2(C);
  for(int i=0; i<C; i++) {
    scanf("%d", &q[i]);
    if(q[i] == 0) {
      scanf("%d%d", &v1[i], &v2[i]);
      v1[i]--;
      point[ v1[i] ] -= v2[i];
      comp[ make_pair(point[ v1[i] ], v1[i]) ]++;
    }
    if(q[i] == 1) {
      scanf("%d", &v1[i]);
    }
  }

  fill(point.begin(), point.end(), 0LL);
  int id = 0;
  vector< pair<AnsType, int> > info;
  for(auto &e : comp) {
    info.emplace_back(e.first);
    e.second = id++;
  }

  for(int i=0; i<N; i++) {
    int k = comp[ make_pair(0, i) ];
    seg.add(k, 1);
  }
  
  for(int i=0; i<C; i++) {
    if(q[i] == 0) {
      int t = v1[i], p = v2[i];
      int u = comp[ make_pair(point[t], t) ];
      seg.add(u, -1);
      point[t] -= p;
      int v = comp[ make_pair(point[t], t) ];
      seg.add(v, 1);
    }
    if(q[i] == 1) {
      int ub = N + C + 10, lb = -1, m = v1[i];
      while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        AnsType s = seg.query(0, mid);
        if(s < m) {
          lb = mid;
        }
        else {
          ub = mid;
        }
      }
      int k = lb;
      int ans1 = 1 + info[k].second;
      AnsType ans2 = -info[k].first;
      printf("%d %lld\n", ans1, ans2);
    }
  }

  return 0;
}



Measured memory_bytes: 29624
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define cst first
#define dur second
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;

char s[N];
int a[N];
int out[N];

int main(){
    scanf("%s", &s);
    int n = strlen(s);
    for(int i = 0 ; i < n ; ++i){
        if(s[i] == 'R' && s[i + 1] == 'L'){
            int r = 0;
            for(int j = i; j >= 0 && s[j] == 'R' ; --j)++r;
            int l = 0;
            for(int j = i + 1 ; j < n && s[j] == 'L' ; ++j)++l;
            int nos = (l + r) / 2;
            if((l + r) & 1)out[i] = nos + (r % 2), out[i + 1] = nos + (l % 2);
            else out[i] = nos, out[i + 1] = nos;
        }
    }
    for(int i = 0 ; i < n ; ++i)
        printf("%d%c", out[i], " \n"[i == n - 1]);
}

Measured memory_bytes: 896
#define _CRT_DISABLE_PERFCRIT_LOCKS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include<math.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<iii,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define vv vector
#define endl "\n"

using namespace std;

int main()
{
  // int t;scanf("%d",&t);
      int n;
       scanf("%d",&n);
       if(n%1000==0)
        printf("0\n");
       else
       {    int k=1000-(n%1000);
           printf("%d\n",k);

       }

}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1000005;
int a[maxn],b[maxn],c[maxn],n,m,q,f[maxn],mi,ma,tot[maxn];
int find(int x)
{
 return x==f[x]?x:f[x]=find(f[x]);
}
int max(int x,int y)
{
	return x>y?x:y;
}
signed main()
{
	scanf("%lld%lld%lld",&n,&m,&q);
	for(int i=1;i<=n;++i)f[i]=i;int flag=0;
	for(int i=1;i<=q;++i)
	{
		 scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);a[i]++;b[i]++;
		 if(!c[i])
		 {
		 	int x=find(a[i]);int y=find(b[i]);
		 	if(x!=y)
			{
		 		f[y]=x;
			}
		 }
	}
	for(int i=1;i<=q;++i)
	{
		if(c[i])
		{
			flag=1;
			if(find(a[i])==find(b[i]))
			{
				puts("No");return 0;
			}
		}
	}
	int c=0;
	for(int i=1;i<=n;++i)
	{
		if(find(i)==i)
		{
	     c++;
		}
	}
	if(!flag)mi=c-1;
	else mi=max(3,c);
	ma=c*(c-1)/2;
	m-=(n-c);
	if(m>=mi&&m<=ma)puts("Yes");
	else puts("No");
}


Measured memory_bytes: 12544
#include<iostream>
#include<string>
#include<vector>
using namespace std;

vector<string> usr_name;

int main(){
  vector<string>::iterator it;
  int n,m,i = 0,j = 0;
  bool k = 0;
  string tmp;
  cin >>n;
  cin.ignore();
  for(i = 0;i < n;i++){
    cin >>tmp;
    usr_name.push_back(tmp);
    cin.ignore();
  }
  cin >> m;
  cin.ignore();
  for(i = 0; i<m;i++){
    j = 0;
    cin >> tmp;
    it = usr_name.begin();
    while(it != usr_name.end()){
      it++;
      if(tmp == usr_name[j]){
	if(k == 0){
	  cout << "Opened by "<<tmp<<endl;
	  k = !k;
	}else{
	  cout << "Closed by "<<tmp<<endl;
	  k = !k;
	}
	j = -1;
	break;
      }
      j++;
    }
    if(j != -1)
      cout <<"Unknown "<<tmp<<endl;
  }
    return 0;
  }

Measured memory_bytes: 1224