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

using namespace std;

typedef unsigned long long ull;

int occ[255];

int main()
{
    int h,w;
    char x;
    cin >> h >> w;
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            cin >> x;
            occ[x]++;
        }
    }
    bool res=true;
    if(h%2==0 && w%2==0)
    {
        for(int i='a';i<='z';++i)
        {
            if(occ[i]%4!=0) res=false;
        }
    }
    else if(h%2==0 && w%2==1)
    {
        int num = (w/2)*(h/2);
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/4,num);
            if(occ[i]/4>=temp) occ[i]-=4*temp;
            else occ[i]=occ[i]%4;
            if(num==0) break;
        }
        if(num!=0) res=false;
        num=h/2;
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/2,num);
            if(occ[i]/2>=temp) occ[i]-=2*temp;
            else occ[i]=occ[i]%2;
            if(num==0) break;
        }
        if(num!=0) res=false;
    }
    else if(h%2==1 && w%2==0)
    {
        int num = (w/2)*(h/2);
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/4,num);
            if(occ[i]/4>=temp) occ[i]-=4*temp;
            else occ[i]=occ[i]%4;
            if(num==0) break;
        }
        if(num!=0) res=false;
        num=w/2;
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/2,num);
            if(occ[i]/2>=temp) occ[i]-=2*temp;
            else occ[i]=occ[i]%2;
            if(num==0) break;
        }
        if(num!=0) res=false;
    }
    else
    {
        int num = (w/2)*(h/2);
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/4,num);
            if(occ[i]/4>=temp) occ[i]-=4*temp;
            else occ[i]=occ[i]%4;
            if(num==0) break;
        }
        if(num!=0) res=false;
        num=w/2;
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/2,num);
            if(occ[i]/2>=temp) occ[i]-=2*temp;
            else occ[i]=occ[i]%2;
            if(num==0) break;
        }
        if(num!=0) res=false;
        num=h/2;
        for(int i='a';i<='z';++i)
        {
            int temp=num;
            num -=  min(occ[i]/2,num);
            if(occ[i]/2>=temp) occ[i]-=2*temp;
            else occ[i]=occ[i]%2;
            if(num==0) break;
        }
        if(num!=0) res=false;
        num=1;
        for(int i='a';i<='z';++i)
        {
            if(occ[i]==1)
            {
                num=0;
                break;
            }
        }
        if(num!=0) res=false;
    }
    if(res) cout << "Yes";
    else cout << "No";

}


Measured memory_bytes: 256
import numpy as np
n, k = [int(i) for i in input().split()]

A = []
check = np.ones(n)
for i in range(k):
  d = int(input())
  A = [int(i) for i in input().split()]
  for j in A:
    check[j-1] = 0
print(int(check.sum()))

Measured memory_bytes: 27136
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#define pii pair<int,int>
#define pb push_back
using namespace std;


int main(){
  int n;
  cin>>n;
  if(n>999) cout<<"ABD"<<endl;
  else cout<<"ABC"<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
    int an,bn,a[100000],b[100000],m,x,y,c,i,f=0,am=10000000,bm=10000000,min;
    cin >> an >> bn >> m;
    for(i=0;i<an;i++){
        cin >> a[i];
        if(am>a[i])am=a[i];
    }
    for(i=0;i<bn;i++){
        cin >> b[i];
        if(bm>b[i])bm=b[i];
    }
    min=am+bm;
    for(i=0;i<m;i++){
        cin >> x >> y >> c;
        if(min>a[x-1]+b[y-1]-c) min=a[x-1]+b[y-1]-c;
    }
    cout << min;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  char a='7';
  if(s.at(0) == a){
  cout<<"Yes"<<endl;
  }
  else if(s.at(1)==a){
  cout<<"Yes"<<endl;
  }
  else if(s.at(2)==a){
  cout<<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
}


Measured memory_bytes: 3648
N = int(input())
s = [input() for i in range(N)]

M = int(input())
t = [input() for j in range(M)]

n_num = 0
m_num = 0
x = []
y = []

for i in range(N):
    n_num = s.count(s[i])
    m_num = t.count(s[i]) * -1
    x.append(n_num + m_num)


for j in range(M):
    n_num = s.count(t[j])
    m_num = t.count(t[j]) * -1
    y.append(n_num + m_num)

ans = x + y
if max(ans) < 0:
    print(0)
else:
    print(max(ans))



Measured memory_bytes: 3064
import java.util.*;
import java.util.stream.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		String a=s.next(),b=s.next();
		System.out.println(IntStream.range(0,a.length()).filter(i->a.charAt(i)==b.charAt(i)).count());
	}
}


Measured memory_bytes: 28884
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){

    int n,t;
    cin >> n >> t;
    ll a[100005] = {};
    
    ll mi,sa = 0,cnt = 1;
    
    rep(i,0,n){
        cin >> a[i];  
    }

    mi = a[0];

    rep(i,1,n){
        mi = min(mi,a[i]);

        if(sa == a[i]-mi)cnt++;
        else if(sa < a[i]-mi){
            sa = a[i]-mi;
            cnt = 1;
        }
    }

    P(cnt);
    
    
	return  0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
int N, M, A, B, C, D, x1, x2, y1, y2;
int K[32][32];
const int inf = 1001001001;
int main() {
 scanf("%d%d", &N, &M);
 for (int i=1; i<=N; ++i) {
  for (int j=1; j<=N; ++j) {
   K[i][j] = inf;
  }
 }
 for (int i=0; i<M; ++i) {
  scanf("%d,%d,%d,%d", &A, &B, &C, &D);
  K[A][B] = C;
  K[B][A] = D;
 }
 for (int k=1; k<=N; ++k) {
  for (int i=1; i<=N; ++i) {
   for (int j=1; j<=N; ++j) {
    if (K[i][j] > K[i][k] + K[k][j]) { K[i][j] = K[i][k] + K[k][j]; }
   }
  }
 }
 scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
 int ans = y1 - K[x1][x2] - K[x2][x1] - y2;
 printf("%d\n", ans);
}


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

#define pb push_back

#define jael(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout <<  *it  << " : " << a << endl;
    err(++it, args...);
}


const int N=4010,inf = 1e9 + 7;
int a[N],b[N],c[N],d[N],e[N],f[N];
int uu[N][N],dd[N][N],ll[N][N],rr[N][N];
bool vis[N][N];

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

int main(){

	std::ios::sync_with_stdio(0); std::cin.tie(0);

	int n,m; cin>>n>>m;
	vector<int>  xs,ys;
	xs.pb(inf),xs.pb(inf*-1);
	ys.pb(inf),ys.pb(inf*-1);

	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
		xs.pb(a[i]),xs.pb(b[i]);
		ys.pb(c[i]);
	}
	for(int i=0;i<m;i++){
		cin>>d[i]>>e[i]>>f[i];
		xs.pb(d[i]);
		ys.pb(e[i]),ys.pb(f[i]);
	}

	// la magie opère ici
	sort(xs.begin(),xs.end()),sort(ys.begin(),ys.end());
	xs.resize(unique(xs.begin(),xs.end())-xs.begin());
	ys.resize(unique(ys.begin(),ys.end())-ys.begin());

	for(int i=0;i<n;i++){ // ici on remplit les contraintes de mouvements de haut en bas
		int x1=lower_bound(xs.begin(),xs.end(),a[i])-xs.begin();
		int x2=lower_bound(xs.begin(),xs.end(),b[i])-xs.begin();
		int y=lower_bound(ys.begin(),ys.end(),c[i])-ys.begin();
		for(int j=x1;j<x2;j++){
			uu[j][y-1]=1;
			dd[j][y]=1;
		}
	}

	for(int i=0;i<m;i++){// ici on remplit les contraintes de mouvements gauche et droite
		int x=lower_bound(xs.begin(),xs.end(),d[i])-xs.begin();
		int y1=lower_bound(ys.begin(),ys.end(),e[i])-ys.begin();
		int y2=lower_bound(ys.begin(),ys.end(),f[i])-ys.begin();
		for(int j=y1;j<y2;j++){
			rr[x-1][j]=1;
			ll[x][j]=1;
		}
	}
	////////ici se termine la magie /////////
	////////////////////////////////////////

	int x=lower_bound(xs.begin(),xs.end(),0)-xs.begin();
	int y=lower_bound(ys.begin(),ys.end(),0)-ys.begin();
	x--,y--;

	//trace(x,y);
	///////////////// largeur première recherche //////////////////////

	queue<pair<int,int> > q;
	q.push({x,y});
	vis[x][y]=1;
	//trace(q.size())	;
	while(!q.empty()){
		int xf=q.front().first;
		int yf=q.front().second;
		//trace(xf,yf,vis[xf][yf]);
		q.pop();
		for(int i=0;i<4;i++){
			if(i==0 and uu[xf][yf]) continue;
			if(i==1 and dd[xf][yf]) continue;
			if(i==2 and rr[xf][yf]) continue;
			if(i==3 and ll[xf][yf]) continue;
			int nx=xf+dx[i],ny=yf+dy[i];
			if(nx<0 or nx>=xs.size()-1 or ny<0 or ny>=ys.size()-1) continue;
			if(vis[nx][ny]) continue;
			vis[nx][ny]=true;
			q.push({nx,ny});
		}
	}

	////////////////////////////////////////////////////////////////

	if(vis[0][0] or vis[xs.size()-1][ys.size()-1]){cout<<"INF"<<endl;return 0;}

	long long wyn=0;
	for(int i=0;i<xs.size()-1;i++){
		for(int j=0;j<ys.size()-1;j++){
			if(vis[i][j]) {
			//	trace(i,j);
				wyn+=(long long)(xs[i+1]-xs[i])*(ys[j+1]-ys[j]);
			}
		}
	}
	cout<<wyn<<endl;

	return 0;
}

Measured memory_bytes: 118204
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int K;
VI s, t;

PII readtimes()
{
	string s;
	cin >> s;
	s[2] = s[5] = s[8] = ' ';

	SS oss( s );
	int a, b, c, d;
	oss >> a >> b >> c >> d;

	return MP( a * 60 + b, c * 60 + d );
}

VI solve()
{
	int N;
	cin >> N;

	VI res( K );
	REP( iteration, N )
	{
		int M;
		cin >> M;

		VI as( M ), bs( M );
		REP( i, M )
		{
			const PII p = readtimes();
			as[i] = p.fst;
			bs[i] = p.snd;
		}

		REP( i, K )
		{
			REP( j, M )
			{
				res[i] += as[j] <= s[i] && t[i] <= bs[j];
			}
		}
	}
	return res;
}

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

	cin >> K;
	s.resize( K );
	t.resize( K );

	REP( i, K )
	{
		PII p = readtimes();
		s[i] = p.fst; 
		t[i] = p.snd;
	}

	VI counts1 = solve(), counts2 = solve();

	int res = 0;
	REP( i, K )
	{
		res += min( counts1[i], counts2[i] );
	}
	cout << res << endl;

	return 0;
}

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


using namespace std;


typedef long long int lli;
typedef long double ld;


int main() {

  
  int n;
  string s;
  cin >> n >> s;

  bool ok = false;
  if  (n % 2 == 0) {
    string s1 = s.substr(0, n/2);
    string s2 = s.substr(n/2);
    if (s1 == s2) {
      ok = true;
    }
  }

  if (ok) {
    cout << "Yes";
  } else {
    cout << "No";
  }


  return 0;
}


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

int a[101] = {0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i) cin >> a[i];
    sort(a, a+n);
    cout << a[n-1] - a[0] << endl;

    return 0;
}


Measured memory_bytes: 256
K = int(input())

import math

answer = 0

for i in range(1, K+1, 1):
  for j in range(1, K+1, 1):
  	g = math.gcd(i, j)
  	for k in range(1, K+1, 1):
  	  if k % g == 0:
  	  	answer += g
  	  elif k == 1 or g == 1:
  	  	answer += 1
  	  else:
  	  	answer += math.gcd(g, k)
else:
  print(answer)

Measured memory_bytes: 9200
#include<iostream>
#include<cctype>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
        int a[26];
        for(int j=0;j<26;j++){
                a[j]=0;
        }
        char c;
        while(scanf("%c",&c)!=EOF){
                if(c!='\n' || c!='.' || c!=' '){
                        if(isupper(c)){
                                c=tolower(c);
                        }
                    int n=c-'a';
                    a[n]++;
                }
        }
        for(int i=0;i<26;i++){
                printf("%c : %d\n",i+'a',a[i]);
        }
        return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
void solve() {
	int n;
	cin >> n;
	map<int,set<int> > L, R, U, D;
	map<int, set<int> > L2, R2, U2, D2;
	map<int, set<int> > L3, R3, U3, D3;
	rep(i, 0, n) {
		int x, y;
		char dir;
		cin >> x >> y >> dir;
		if (dir == 'U') {
			U[x].insert(y);
			U2[x + y].insert(y);
			U3[x - y].insert(y);
		}
		if (dir == 'D') {
			D[x].insert(y);
			D2[x + y].insert(y);
			D3[x - y].insert(y);
		}
		if (dir == 'L') {
			L[y].insert(x);
			L2[x + y].insert(y);
			L3[x - y].insert(y);
		}
		if (dir == 'R') {
			R[y].insert(x);
			R2[x + y].insert(y);
			R3[x - y].insert(y);
		}
	}
	int dis = INT_MAX, dis2 = INT_MAX;
	for (auto m : U) {
		set<int> up = m.second;
		set<int> down = D[m.first];
		for (auto y : up) {
			auto it = down.lower_bound(y);
			if (it == down.end()) {
				break;
			}
			else {
				dis = min(dis, (*it) - y);
			}
		}
	}
	for (auto m : R) {
		set<int> right = m.second;
		set<int> left = L[m.first];
		for (auto x : right) {
			auto it = left.lower_bound(x);
			if (it == left.end()) {
				break;
			}
			else {
				dis = min(dis, (*it) - x);
			}
		}
	}
	for (auto m : L2) {
		int sum = m.first;
		set<int> left = m.second;
		for (auto y : left) {
			set<int> down = D2[sum];
			auto it = down.lower_bound(y);
			if (it == down.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	for (auto m : R3) {
		int diff = m.first;
		set<int> right = m.second;
		for (auto y : right) {
			set<int> down = D3[diff];
			auto it = down.lower_bound(y);
			if (it == down.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	for (auto m : U2) {
		int sum = m.first;
		set<int> up = m.second;
		for (auto y : up) {
			set<int> right = R2[sum];
			auto it = right.upper_bound(y);
			if (it == right.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	for (auto m : U3) {
		int diff = m.first;
		set<int> up = m.second;
		for (auto y : up) {
			set<int> left = L3[diff];
			auto it = left.upper_bound(y);
			if (it == left.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	if (dis == INT_MAX && dis2 == INT_MAX) {
		cout << "SAFE" << endl;
	}
	else {
		int ans = INT_MAX;
		if (dis != INT_MAX) {
			ans = min(ans, dis * 5);
		}
		if (dis2 != INT_MAX) {
			ans = min(ans, dis2 * 10);
		}
		cout << ans << endl;
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



Measured memory_bytes: 106824
a, b = gets.split(' ').map(&:to_i)
c = (a - b).abs
if c % 2 != 0
  puts 'IMPOSSIBLE'
else
  c2 = c / 2
  d, e = a - c2, b - c2
  if (a - d).abs == (b - d).abs
    puts d
  else
    puts e
  end
end

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,m;
vector<string> t;
bool flag=true;

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n){
		string s;
		cin>>s; t.pb(s);
	}
	cin>>m;
	rep(i,m){
		string s;
		cin>>s;
		if(exist(t,s)){
			if(flag){
				cout<<"Opened by "<<s<<endl;
				flag=false;
			}else{
				cout<<"Closed by "<<s<<endl;
				flag=true;
			}
		}else{
			cout<<"Unknown "<<s<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int ans = (n*(n-1))/2 + (m*(m-1))/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
N, M = map(int, input().split())
dp = [0]*(N + 1)
dp[0] = 1
A = [int(sys.stdin.readline()) for _ in range(M)]
D = set(A)
mod = 10**9 + 7
for i in range(1, N+1):
    res = 0
    if i - 1 >= 0 and i - 1 not in D:
        res += dp[i-1]
    if i - 2 >= 0 and i - 2 not in D:
        res += dp[i-2]
    dp[i] = res % mod
print(dp[-1])           


Measured memory_bytes: 14020
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}



int main() {
   fast();
   priority_queue<int> pq;
   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++){
    int l;
    cin>>l;
    pq.push(l);
   }
   while(m--){
    int q=pq.top();
    pq.pop();
    pq.push(q/2);
   }
   long long sum=0;
   while(n--){
      int q=pq.top();
      sum+=q;
      pq.pop();
   }
   cout<<sum<<"\n";


}


Measured memory_bytes: 3888
import sys
buf = sys.stdin.buffer


class UnionFind:
    def __init__(self, num_of_node):
        self.roots = [-1] * num_of_node
        self.groups = num_of_node

    def get_root(self, node):
        root = self.roots[node]
        if root == -1:
            return node

        else:
            root = self.get_root(root)
            self.roots[node] = root
            return root

    def is_same_group(self, node1, node2):
        return self.get_root(node1) == self.get_root(node2)

    def unite(self, node1, node2):
        self.groups -= 1
        root1, root2 = self.get_root(node1), self.get_root(node2)
        self.roots[root2] = root1


def main():
    n = int(buf.readline())
    XY = map(int, buf.read().split())
    Xs = []
    Ys = []
    for i, (x, y) in enumerate(zip(XY, XY)):
        Xs.append((x-1, i))
        Ys.append((y-1, i))

    Xs.sort()
    Ys.sort()

    edges = []
    for i in range(n-1):
        x1, node1 = Xs[i]
        x2, node2 = Xs[i+1]
        y1, node3 = Ys[i]
        y2, node4 = Ys[i+1]
        edges.append((x2-x1, node1, node2))
        edges.append((y2-y1, node3, node4))

    edges.sort(reverse=True)

    ans = 0
    uf = UnionFind(n)
    while uf.groups != 1:
        d, node1, node2 = edges.pop()
        if uf.is_same_group(node1, node2):
            continue
        uf.unite(node1, node2)
        ans += d

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 54604
#include<stdio.h>

int main(void){
  int S[5];
  int SS=2000;
  int DD=2000;
  int i;

  for( i=0 ; i<5 ;i++){
    scanf ("%d",&S[i]);
	 }
      for ( i=0 ; i<3;i++){
	if(SS>=S[i]){
	  SS=S[i];
	}
      }
    for ( i=3 ; i<5;i++){
      if (DD>=S[i]){
	DD=S[i];
      }
    }
    printf("%d\n",DD+SS-50);
    return 0;

}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int m;
int mult(int x, int y) {
	return 1ll * x * y % m;
}
int add(int x, int y) {
	x += y;
	if (x >= m) {
		return x - m;
	}
	return x;
}
int bin_pow(int x, int y) {
	if (y == 0) {
		return 1;
	}
	if (y % 2 == 0) {
		return bin_pow(mult(x, x), y / 2);
	}
	return mult(x, bin_pow(x, y - 1));
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	ll answer = 0;
	if (p == 2) {
		for (int i = 0; i < n; ++i) {
			int num = s[i] - '0';
			if (num % 2 == 0) {
				answer += i + 1;
			} 
		}
	} else if (p == 5) {
		for (int i = 0; i < n; ++i) {
			int num = s[i] - '0';
			if (num == 0 || num == 5) {
				answer += i + 1;
			} 
		}
	} else {
		m = p;
		vector<int> cnt(p);
		++cnt[0];
		int rem = 0;
		for (int i = n - 1; i >= 0; --i) {
			int num = s[i] - '0';
			rem = add(rem, mult(bin_pow(10, n - 1 - i), num));
			assert(rem < p);
			answer += cnt[rem];
			++cnt[rem];
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 720
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a=INT()
    b=INT()
    c=INT()
    d=INT()
    print(min(a,b)+min(c,d))
if __name__ == '__main__':
    do()

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

int solve(string& s){
    int N = s.size();
    int ch = 0;
    for (int i=1; i<N; ++i) {
        if (s[i] != s[i-1]) ++ch;
    }
    return ch;
}

int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<limits.h>
#define WHITE 0
#define GRAY -1
#define BLACK 1

void enqueue(int);
int dequeue();
void BFS(int);
int Q[101], G[101][101], d[101], color[101], head, tail ,n;

main()
{
  int i, j, k, u, value;

  for(i=1 ; i<=101 ; i++)
    {
      for(j=1 ; j<=101 ; j++)
        {
          G[i][j] = 0;
        }
    }

  scanf("%d",&n);
  for(i=1 ; i<=n ; i++)
    {
      scanf("%d%d",&u ,&k);
      for(j=1 ; j<=k ; j++)
        {
          scanf("%d",&value);
          G[u][value] = 1;
        }
    }
  
  for(i=1 ; i<101 ; i++)
    {
    d[i] = -1;
    }
  
  BFS(1);

  for(i=1 ; i<=n ; i++)
    {
      if(d[i] == INT_MAX) d[i] = -1;
      printf("%d %d\n",i ,d[i]);
    }
   
  return 0;
}

void enqueue(int x)
{
  Q[tail] = x;
  if(tail == 101) tail = 1;
  else tail++;
}


int dequeue()
{
  int data;
  data = Q[head];

  if(head == 101) head = 1;
  else head++;

  return data;
}

void BFS(int s)
{
  int i, u, v;

  for(u=1 ; u<=n-1 ; u++)
    {
      color[u] = WHITE;
      d[u] = INT_MAX;
    }

  color[s] = GRAY;
  d[s] = 0;
  head = tail = 0;
  enqueue(s);

  while(head != tail)
    {
      u = dequeue();
      for(v=1 ; v<=n ; v++)
        {
          if(G[u][v] == 1 && color[v] == WHITE)
            {
              color[v] = GRAY;
              d[v] = d[u] + 1;
              enqueue(v);
            }
        }
      color[u] = BLACK;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
#define endl "\n"
#define FILEIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define LL long long 
#define mod 1000000007LL
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
//#define p push
#define I insert
#define bg begin()
#define ed end()
#define sz size()
#define all(v) v.begin(),v.end()
typedef vector<LL> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef map<LL ,LL > mii;
//typedef priority_queue<int> pq;
typedef queue<int>que;
typedef stack<int>stk;
#define Inf 100000005LL
#define f first
#define s second





vi vect_2pow;
void pow_of_2(){
    vect_2pow.assign(32,0);
      for(int i=0;i<=32;i++){
           LL y = 1<<i;
           vect_2pow[i]=y;
      }
}
bool Ispalindrome(string str){
        LL len = str.size();
		bool flag;
		for(int i=0;i<len/2;i++){
				if(str[i]==str[len-i-1])
				     {
						 flag=0;
						 continue;
					 }
					 else 
					    {
							flag=1;
							break;
						}
			}
		if (flag==1)
		  return false;
		else return true;  
		
}
vector<LL> prime_check;
mii get_high_prime;
int high_prime_factor(){
	//cout<<"ecd";
	LL max_prime=0;
	for(int i=2;i<100000;i++)
	{
		LL n=i;
		
		while(n%2==0)
		{
			max_prime=2;
			n>>=1;
		}
		for(int j=3;j<=sqrt(n);j++)
		{
			while(n%j==0){
				max_prime=j;
				n/=j;
			}
		}
		if(n>2)
		  max_prime=n;
		  
		//prime_check.pb(max_prime);
		get_high_prime[i]=max_prime;
	}
	
			
}
int main()
{
	int n,k;
	cin>>n>>k;
	vector<bool> dp(k+1);
	// dp[i]- True if the first player win if there are i stone remaing
     vi vect(n);
	 for(int i=0;i<n;i++)
	    cin>>vect[i];

	for(int stone = 0 ; stone<=k;stone++)
	{
    for(auto x: vect)
	{
		if(stone>=x && !dp[stone-x])
		    dp[stone]=true;
	}
	}	
	if(dp[k])
	   cout<<"First";
	else
	{
		cout<<"Second";
	}
	   



}

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

ll arr[1005][2];
ll h,n;

ll dp[10005];

int main()
{
    std::ios_base::sync_with_stdio(0);	
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
	cin>>h>>n;
	dp[0] = 0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i][0]>>arr[i][1];
	}
	
	for(ll i=1;i<=h;i++)
	{
		dp[i] = 1e18;
		for(ll j=0;j<n;j++)
		{
			dp[i] = min(dp[i],arr[j][1]+dp[max(0LL,i-arr[j][0])]);
		}
	}
	
	cout<<dp[h];
	
}


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

int main()
{
    int x,y;
    int tmp;
    while(cin >> x >> y) {
        if (x == 0 && y == 0) {break;}
        if (x > y) {
            tmp = x;
            x = y;
            y = tmp;
        }
        cout << x << " " << y << endl;
    }
}


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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    string s;
    cin >>n>>s;

    for (int i = 0; i < s.size(); i++){
        int p = s[i] - 'A';

        char nc = 'A' + (p+n)%26;
        
        s[i] = nc;
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << s << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    vi v1, v2;
    v1.push_back(1);
    for(int i=1; i<=n; i++){
        for(int j=0; j<v1.size(); j++){
            v2.push_back(v1[j]*2);
        }
        for(int j=0; j<v1.size(); j++){
            v2.push_back(v1[j]+k);
        }
        v1 = v2;
        v2.clear();
    }
    sort(v1.begin(), v1.end());
    cout<<v1[0]<<endl;
    return 0;
}


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

int main()
{
	string ab, abc;
	int cnt = 0;
	cin >> ab >> abc;
	for (int i = 0; i < 3; i++)
	{
		if (ab[i]==abc[i]) cnt++;
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 100000;
long long n,m,k;
long long maxm, minm;
pair<long long, long long> red[MAX_N], blue[MAX_N];
long long a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N], t[MAX_N];
long long solve(){
    long long count = 0, now ;
    for(int i=0 ; i<n-1 ; i++){
        now = a[i+1] + a[i];
        if(now > k){
            a[i+1] -= now - k;
            count += now - k;
        }
        if(a[i+1]<0){
            a[i] += a[i+1];
            a[i+1] = 0;
        }
    }
    return count;
}
int main(){
    cin >> n >> k;
    for(int i=0 ; i<n ; i++){
        cin >> a[i];
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 2304
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector (Int, Int) -> Bool
solve !n !abn = snd $ foldr
  ( \(!a, !b) (!acc, !r) ->
    if r then let acc' = acc + a in (acc', acc' <= b) else (acc, r)
  )
  (0, True)
  abn'
  where abn' = sortBy (\(x, y) (x1, y1) -> compare y1 y) $ VU.toList abn

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n   <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  abn <-
    VU.replicateM n
    $   (\vec -> (vec VU.! 0, vec VU.! 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
  putStrLn $ if solve n abn then "Yes" else "No"


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int x1,y1,x2,y2; cin >>x1>>y1>>x2>>y2;
    int x3,y3,x4,y4;

    int dx = x2 - x1;
    int dy = y2 - y1;

    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x3 - dx;
    y4 = y3 - dy;

    cout << x3 SP y3 SP x4 SP y4 << endl;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	Vec t(n);
	rep(i, n) t[i] = s[i] - '0';
	Vec pos(n);
	pos[n - 1] = 1;
	repr(i, n - 1){
		pos[i] = pos[i + 1] * 10 % p;
	}

	if(p == 2){
		ll ans = 0;
		repr(i, n){
			if(t[i] % 2 == 0) ans += i + 1;
		}
		co(ans);
		return 0;
	}

	if(p == 5){
		ll ans = 0;
		repr(i, n){
			if(t[i] % 5 == 0) ans += i + 1;
		}
		co(ans);
		return 0;
	}

	unordered_map<ll, ll> ump;
	ll ans = 0;
	ll prev = 0, now = 0;
	repr(i, n){
		now = (prev + t[i] * pos[i]) % p;
		ump[prev]++;
		ans += ump[now];
		prev = now;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,r;
    in>>n>>r;
    cout<<r+100*max(0,10-n)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << (C/B + (C%B?1:0) <= A/D + (A%D?1:0) ? "Yes" : "No") << endl; 
    return 0;
}


Measured memory_bytes: 3636
N, M, X, Y = map(int, input().split())
Xs = list(map(int, input().split()))
Ys = list(map(int, input().split()))
Xs.append(X)
Ys.append(Y)
if max(Xs) < min(Ys):
    print('No War')
else:
    print('War')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using pll = pair<ll, ll >;
const int mod = 1e9+7;
// const int INF = 2e9;
const ll INF = 1e15;
const int MAX = 1e6;
const int YEN = 0, SNUUK = 1;

struct edge {int to, yen, snuuk;}; // 辺
vector<edge> graph[MAX]; // 隣接リスト
// bool visited[MAX]; // 訪問状況
// ll dist_yen[MAX], dist_snuuk[MAX];
ll dist[2][MAX];

void dijkstra(int s, int x) {
    fill(dist[x], dist[x]+MAX, INF);
    dist[x][s] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({dist[x][s], s});
    while (not pq.empty()) {
        int cur = pq.top().second;
        pq.pop();
        for (edge e : graph[cur]) {
            if (x == YEN) {
                if (dist[x][e.to] > dist[x][cur] + e.yen) {
                    dist[x][e.to] = dist[x][cur] + e.yen;
                    pq.push({dist[x][e.to], e.to});
                }
            } else if (x == SNUUK) {
                if (dist[x][e.to] > dist[x][cur] + e.snuuk) {
                    dist[x][e.to] = dist[x][cur] + e.snuuk;
                    pq.push({dist[x][e.to], e.to});
                }
            }
        }
    }
}

// void r_dijkstra(int s) {
//     fill(dist_snuuk, dist_snuuk+MAX, INF);
//     dist_snuuk[s] = 0;
//     priority_queue<pll, vector<pll>, greater<pll>> pq;
//     pq.push({dist_snuuk[s], s});
//     while (not pq.empty()) {
//         int cur = pq.top().second;
//         pq.pop();
//         for (edge e : graph[cur]) {
//             if (dist_snuuk[e.to] > dist_snuuk[cur] + e.snuuk) {
//                 dist_snuuk[e.to] = dist_snuuk[cur] + e.snuuk;
//                 pq.push({dist_snuuk[e.to], e.to});
//             }
//         }
//     }
// }


int main() {
    // input
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        graph[u].push_back({v, a, b});
        graph[v].push_back({u, a, b});
    }
    // solve
    dijkstra(s, YEN); // sからyenを使った各都市までの最短経路
    dijkstra(t, SNUUK); // tからsnuukを使った各都市までの最短経路
    ll min_cost = INF;
    vector<ll> ans(n);
    repr(i, n) {
        ll cost = dist[YEN][i] + dist[SNUUK][i];
        min_cost = min(min_cost, cost);
        ans[i] = INF - min_cost;
    }
    // output
    rep(i, n) {
        cout << ans[i] << "\n";
    }
}

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

int main()
{
  int r,c;
  cin >> r >> c;
  r++;c++;
  int** array = new int*[r];
  for (int i=0; i<r; i++)
  {
    array[i] = new int[c];
  }

  for (int j=0; j<c; j++)   //?????????
  {
    array[r-1][j] = 0;
  }

  for (int i=0; i<r-1; i++)
  {
    array[i][c-1] = 0;      //?????????
    for (int j=0; j<c-1; j++)
    {
      cin >> array[i][j];
      array[i][c-1] += array[i][j];
      array[r-1][j] += array[i][j];
      array[r-1][c-1] += array[i][j];
    }
  }

  for (int i=0; i<r; i++)
  {
    for (int j=0; j<c; j++)
    {
      if ( j < c-1 )
      {
        cout << array[i][j] << ' ' << flush;
      }else
      {
        cout << array[i][j] << endl;
      }
    }
  }

  for (int i=0; i<r; i++)
  {
    delete[] array[i];
  }
  delete[] array;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
 
int main() {

 int N, i;
 cin >> N;
 
 for(i=0;i<N;i++){
   string s;
   cin >> s;
   if(s == "Y"){
     cout << "Four" << endl;
     break;} 
 }
 
 if(i == N){cout << "Three" << endl;}
}   

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int maxn, n, m, y, money, money2, a, c; double b;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> money; money2 = money;
		cin >> y >> m; maxn = 0;
		for (int j = 0; j < m; j++) {
			cin >> a >> b >> c; money = money2;
			if (a == 1) {
				for (int k = 0; k < y; k++) {
					money = (double)money*(1 + b);
					money -= c;
				}
			}
			else {
				for (int k = 0; k < y; k++) {
					money += (double)(money2 - k*c)*b;
				}
				money -= y*c;
			}
			maxn = max(maxn, money);
		}
		cout << maxn << endl;
	}
}

Measured memory_bytes: 1232
def gcd(p,q):
    while q != 0:
        r = p % q
        p = q
        q = r
    return p
k = int(input())
a = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            a += gcd(gcd(i,j),k)
print(a)

Measured memory_bytes: 68708
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = sorted(li())
K = ii()

print(sum(S[0:2]) + S[2]*(2**K))

Measured memory_bytes: 3064
while True:
    n = int(input())

    if n == 0:
        break

    matrix = [[] for _ in range(n)]
    col_sum = [0 for _ in range(n + 1)]
    for i in range(n):
        matrix[i] = list(map(int, input().split()))
        matrix[i].append(sum(matrix[i]))
        for j in range(n + 1):
            col_sum[j] += matrix[i][j]

    matrix.append(col_sum)

    for i in range(n + 1):
        for j in range(n + 1):
            print('%5d' % matrix[i][j], end='')
        print()



Measured memory_bytes: 5620
#include <stdio.h>

int main(){
  int x, y, i, j, p;

  scanf("%d %d", &x, &y);

  if(x < y){
    while(x != 0){
      p = x;
      x = y % x;
      y = p;
    }
    printf("%d\n", y);
  }

  else{
    while(y != 0){
      p = y;
      y = x % y;
      x = p;
    }
    printf("%d\n", x);
  }

  return 0;
}

Measured memory_bytes: 592
#include <iostream>

using namespace std;

int main()
{
    int h, w;
    while (true)
    {
        cin >> h >> w;
        if (h == 0 && w == 0)
        {
            break;
        }

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if(a <= x && a + b >= x) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256