akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

ll Gcd(ll a,ll b){
    if(a < b)swap(a, b);

	if(a%b == 0)return(b);

	else return(Gcd(b, a%b));
}

vector<pll> Factor(ll n){
    vector<pll> prime;
    ll sq = sqrt(n) + 1;

    for(int i = 2; i <= sq; ++i){
        sq = sqrt(n) + 1;
        if(n%i == 0){
            prime.push_back(make_pair(i, 0));
            while(n%i == 0){
                n /= i;
                prime[prime.size()-1].second++;
            }
        }
    }

    if(n != 1){
        prime.push_back(make_pair(n, 1));
    }

    return prime;
}

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

    vector<pll> fac = Factor(Gcd(a, b));

    cout << fac.size() + 1 << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ll N, ans = 0;
    set<string> A;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        string s;
        cin >> s;
        A.insert(s);
    }

    cout << A.size() << endl;
}


Measured memory_bytes: 19108
// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MAXN 10000002 
const ll M = 1e9 + 7, N = 1e6 + 5;

ll spf[MAXN]; 

void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 

    for (ll i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 

                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 

map<ll, ll> getFactorization(ll x) 
{ 
    map<ll, ll> mp; 
    while (x != 1) 
    { 
        mp[spf[x]]++;
        x = x / spf[x]; 
    } 
    return mp; 
} 

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    sieve();
    ll n;
    cin >> n;
    ll ans = 1;
    for (ll i = 2; i <= n; i++)
    {
        map<ll,ll> mp = getFactorization(i);
        ll cnt = 1;
        for (auto i: mp) cnt *= (i.second + 1);
        ans += i * cnt;
    }
    cout << ans;
}

Measured memory_bytes: 81748
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int D; cin >> D;
    int N; cin >> N;

    if(N == 100){
        N++;
    }
    cout << N << string(2 * D, '0') << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int mm = n+1;
    int ans = 0;
    rep(i, n){
        if (mm > p[i]){
            ans++;
            mm = p[i];
        }
    }

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

Measured memory_bytes: 1024
/* cpp file
 * kanzo
 * @2020
 * */
#include<bits/stdc++.h>
using namespace std;

#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define pi pair<int,int>

int main()
{
		boost;
		string S,T;
		
		cin >> S >> T;
		
		int s = S.length(); 
		int t = T.length();   	
		int res = INT_MAX;
		for(int i=0;i< s - t + 1; i++)
		{
				int minChar = 0;
				for(int j=0;j<t;j++)
				{
						if(T[j] != S[i+j])
							minChar++;
				}
				
				res = min(res,minChar);
		}
		
		cout << res << endl;
		return 0;
}




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

int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);std::cout.tie(0);    
    int n,k;
    std::cin>>n>>k;
    if(n==1 && k==0)
        std::cout<<"0 0 1 1\n";
    else if((1<<n)<=k)
        std::cout<<-1<<'\n';
    else {
        std::vector<int> v={k};
        int xs=0;
        for(int i=0;i<(1<<n);++i)
            if(i!=k) {
                v.push_back(i);
                xs^=i;
            }
        if(xs==k) {
            v.push_back(k);
            for(int i=(1<<n)-1;i>=0;--i)
                if(i!=k)
                    v.push_back(i);
            for(int i=0;i<v.size();++i)
                std::cout<<v[i]<<(i+1==v.size()?'\n':' ');
        } else
            std::cout<<-1<<'\n';
    }
    return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
bool T=false;
int main(){
    int N,K;cin>>N>>K;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    int ans=0;
    for (int i = 0; i < K; i++)
    {
        ans+=p[i];
    }
    cout<<ans<<endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

void dfs(string s,int c,int d){
  if(c==0){
    cout<<s<<endl;
    return;
  }
  for(int i=0;i<=d;i++){
    char a='a'+i;
    string S=s+a;
    if(i==d)dfs(S,c-1,d+1);
    else dfs(S,c-1,d);
  }
}

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

  int N;
  cin>>N;
  dfs("a",N-1,1);
  return 0;
}


Measured memory_bytes: 1536
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'

input()
a = input().split()
m = a.count('1')
if len(a) > m + 1:
  u = set()
  i = None
  for x in map(int, a):
    s = set()
    while x > 1:
      p = spf[x]
      if p in u:
        r = 'setwise'
      s.add(p)
      x //= p
    u |= s
    if m == 0:
      if i is None: i = s
      else: i &= s
  if i:
    r = 'not'
print(r, 'coprime')


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

int main(){
	int n;
	cin >> n;
	map<int,int> mp;
	rep(i,n){
		int d;
		cin >> d;
		mp[d]++;
	}
	int ans = 0;
	for(auto p: mp) ans++;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

queue<int> que;
void Search(int n, vector<list<int>> & p, vector<int> &d) {
	for (auto it = p[n].begin(); it != p[n].end(); it++) {
		if (d[*it] < 0) {
			d[*it] = d[n] + 1;
			que.push(*it);
		}
	}
	if (que.empty())
		return;
	n = que.front();
	que.pop();
	Search(n, p, d);
	return;
}

int main(void) {
	int num, i, j, a, b, c, buf;
	cin >> num >> a >> b;
	vector<list<int>> p(num + 1);
	vector<vector<int>> d(2, vector<int>(num + 1, -1));
	vector<int> ans(num, 0);
	rep(i, num + 1) {
		if (i > 1)
			p[i].push_back(i - 1);
		if (i < num)
			p[i].push_back(i + 1);
	}
	p[a].push_back(b);
	p[b].push_back(a);
	d[0][a] = d[1][b] = 0;
	Search(a, p, d[0]);
	Search(b, p, d[1]);
	c = num - b;
	a--;
	b -= a;
	for (i = 1; i <= a; i++) {
		ans[i] += a - i;
		for (j = a + 1; j <= num; j++)
			ans[d[0][i] + d[0][j]]++;
	}
	for (j = 1; j <= (b - 1) / 2; j++)
		ans[j] += b;
	if (b % 2 == 0)
		ans[b / 2] += b / 2;
	for (; i <= a + b; i++) {
		for (j = a + b + 1; j <= num; j++)
			ans[d[1][i] + d[1][j]]++;
	}
	for (i = 1; i < c; i++)
		ans[i] += c - i;
	for (i = 1; i < num; i++)
		cout << ans[i] << "\n";
	return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split(' '))
import math
n, m = int(math.factorial(N)), int(math.factorial(M))
l = int(math.pow(10,9)) + 7

if N == M:
    n *= m * 2
    n %= l
    print(n)

elif N + 1 == M:
    n *= m
    n %= l
    print(n)

elif N == M + 1:
    n *= m
    n %= l
    print(n)

else:
    print(0)



Measured memory_bytes: 54896
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import heapq

n = int(input())
u = list(map(int, input().split()))
heapq.heapify(u)
for _ in range(n-1):
    heapq.heappush(u, (heapq.heappop(u) + heapq.heappop(u)) / 2)

print(heapq.heappop(u))


Measured memory_bytes: 62488
N = int(input())

H= list(map(int, input().split()))


ans = 'Yes'
H[0]-= 1
for i in range(1,N-1):
    if H[i]>H[i+1] or H[i]<H[i-1]:
        H[i]-=1
    elif H[i]>H[i-1]:
        H[i]-=1
    
    if H[i]>H[i+1] or H[i]<H[i-1]:
        ans = 'No'
        break

print(ans)

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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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 EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, K;
vector<ll> H;

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        ll h;
        cin >> h;
        H.push_back(h);
    }
    sort(H.begin(), H.end(), greater<int>());

    ll ans = 0;
    if (N >= K) {
        for (int i = K; i < N; ++i) ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
N = int(input())

sum = 0
for i in range(1,N+1):
    if(i % 3 == 0 and i % 5 == 0):
        continue
    elif(i % 3 == 0):
        continue
    elif(i % 5 == 0):
        continue
    sum += i
print(sum)

Measured memory_bytes: 9172
number=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
masu=[]
for i in range(H):
    tmp=list(str(input()))
    masu.append(tmp)
count=0
ans=0
for cowmask in range(1<<H):
    for rowmask in range(1<<W):
        count=0
        for x in range(H):
            for y in range(W):
                if (cowmask>>x)&1==0 and (rowmask>>y)&1==0 and masu[x][y]=="#":
                    count+=1
        if count==K:
            ans+=1
print(ans)

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

using namespace std;

#define ll long long

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}

void solve()
{
    int x;
    cin>>x;
    if(x>=400 && x<=599)
    {
        cout<<"8"<<endl;
    }
    if(x>=600 && x<=799)
    {
        cout<<"7"<<endl;
    }
    if(x>=800 && x<=999)
    {
        cout<<"6"<<endl;
    }
    if(x>=1000 && x<=1199)
    {
        cout<<"5"<<endl;
    }
    if(x>=1200 && x<=1399)
    {
        cout<<"4"<<endl;
    }
    if(x>=1400 && x<=1599)
    {
        cout<<"3"<<endl;
    }
    if(x>=1600 && x<=1799)
    {
        cout<<"2"<<endl;
    }
    if(x>=1800 && x<=1999)
    {
        cout<<"1"<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3640
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    Integer a[] = new Integer[N];
    Integer count[] = new Integer[N+1];
    Arrays.fill(count, 0);
    int ans = 0;
    for(int i=0; i<N; i++){
      a[i] = sc.nextInt();
      if(a[i] > N) ans++;
      else{
        count[a[i]]++;
      }
    }
    for(int i=1; i<N+1; i++){
      if(count[i] < i) ans += count[i];
      else ans += count[i] - i;
    }
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 61468
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


n = make_divisors(N)
answer = 0
for i in n[::-1]:
    if i == 1:
        continue
    q, r = divmod(N, i - 1)
    if q == r:
        answer += i - 1
    else:
        break

print(answer)

Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n,m;
  cin>>n>>m;
  long long int a[m],s=0;
  for(long long int i=0;i<m;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  if(n-s>=0)
    cout<<n-s;
  else
    cout<<-1;
  return 0;
}

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,temp1,temp2,t,x,y,m,k,a,b,c,M=1e6;
	
	int arr[5];
	
	for(int i =0;i<5;i++)
	{
		cin>>arr[i];
		if(arr[i]==0)
		{
			cout<<i+1;
			return 0;
		}
	}
	
}

Measured memory_bytes: 3580
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None


root = None

def insert(key):
    global root
    x = root #Tの根
    y = None #親を設定
    # while x: x, y = x.left if key < x.key else x.right, x
    while x is not None:
        y = x
        if key < x.key:
            x = x.left #左の子へ移動
        else:
            x = x.right  #右の子へ移動

    if y is None: #Tが空の場合
        root = Node(key)
    elif key < y.key:
        y.left = Node(key) #keyをyの左の子にする
    else:
        y.right = Node(key) #keyをyの右の子にする

def inorder(node):
    return   inorder(node.left) + " "+ str(node.key) + inorder(node.right) if node else ''
def preorder(node):
    return   " " + str(node.key) + preorder(node.left) + preorder(node.right) if node else ''
input()
for e in sys.stdin:
    if e[0] == "i":
        insert(int(e[7:]))
    else:
        print(inorder(root))
        print(preorder(root))



Measured memory_bytes: 63324
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <numeric>
#include <tuple>

intmax_t constexpr mod = 1e9+7;

int main() {
  size_t h, w;
  scanf("%zu %zu", &h, &w);

  std::vector<std::string> s(h);
  for (auto& si: s) {
    char buf[2048];
    scanf("%s", buf);
    si = buf;
  }

  std::vector<std::vector<size_t>> hz(h, std::vector<size_t>(w));
  auto vt = hz;
  for (size_t i = 0; i < h; ++i) {
    for (size_t j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      hz[i][j] = 1;
      if (j > 0) hz[i][j] += hz[i][j-1];
    }
    for (size_t j = w; j--;) {
      if (s[i][j] == '#') continue;
      if (!(j+1 < w)) continue;
      hz[i][j] = std::max(hz[i][j], hz[i][j+1]);
    }
  }

  for (size_t j = 0; j < w; ++j) {
    for (size_t i = 0; i < h; ++i) {
      if (s[i][j] == '#') continue;
      vt[i][j] = 1;
      if (i > 0) vt[i][j] += vt[i-1][j];
    }
    for (size_t i = h; i--;) {
      if (s[i][j] == '#') continue;
      if (!(i+1 < h)) continue;
      vt[i][j] = std::max(vt[i][j], vt[i+1][j]);
    }
  }

  // for (size_t i = 0; i < h; ++i)
  //   for (size_t j = 0; j < w; ++j)
  //     fprintf(stderr, "%zu%c", hz[i][j], j+1<w? ' ':'\n');

  // for (size_t i = 0; i < h; ++i)
  //   for (size_t j = 0; j < w; ++j)
  //     fprintf(stderr, "%zu%c", vt[i][j], j+1<w? ' ':'\n');

  size_t res = 0;
  for (size_t i = 0; i < h; ++i)
    for (size_t j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      res = std::max(res, hz[i][j]+vt[i][j]-1);
    }

  printf("%zu\n", res);
}


Measured memory_bytes: 66944
#include<bits/stdc++.h>
#include<vector>
#include<map>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n,t,a;
	cin>>n>>t>>a;
	double arr[n];
	for(int i=0;i<n;i++)
	{
		double p;
		cin>>p;
		p = t-(p*0.006);
		//cout<<p<<endl;
		arr[i] = p;
	}
	double mi;
	int in = 1;
	mi = abs(arr[0]-a);
	for(int i=1;i<n;i++)
	{
		double s = abs(arr[i]-a);
		if(mi > s)
		{
			mi = s;
			in =i+1;
		}
	}
	cout<<in<<endl;
}

Measured memory_bytes: 256
N = gets.to_i
h = {}
as = (0...N).map{ gets.to_i }
(0...(N+1)/2).each{ |i| a = as[2*i]; h[a] = (h[a] || 0) + 1 }
as.sort!
(0...(N+1)/2).each{ |i| a = as[2*i]; h[a] = (h[a] || 0) - 1 }
p h.values.reduce(0) { |a,b| a + [b,0].max }


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

int main(){
	const int MAX=123456*2+1;
	bool isPrime[MAX+1];
	for(int i=2; i<=MAX; ++i)	isPrime[i]=true;
	isPrime[0]=isPrime[1]=false;
	for(int i=2; i*i<=MAX; ++i)if(isPrime[i])for(int j=i+i; j<=MAX; j+=i)	isPrime[j]=false;
	int sum[MAX+1];
	sum[0]=sum[1]=0;
	for(int i=2; i<=MAX; ++i)	sum[i]=sum[i-1]+(isPrime[i]? 1: 0);
	int n;
	while(cin >> n,n){
		cout << sum[2*n]-sum[n] << endl;
	}
}

Measured memory_bytes: 2364
#include <iostream>
#include <memory.h>
#include <string>

using namespace std;

typedef long long ll;

int N, M;
char S[100005];
char T[100005];
int pos[100005][26];
int main() {
  scanf("%s", S);
  scanf("%s", T);
  N = strlen(S);
  M = strlen(T);
  
  memset(pos, -1, sizeof(pos));
  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      pos[i][j] = pos[i + 1][j];
    }
    pos[i][S[i] - 'a'] = i;
  }
  
  int j = 0;
  ll res = 0;
  for (int i = 0; i < M; i++) {
    int k = T[i] - 'a';
    if (pos[0][k] == -1) {
      printf("%d\n", -1);
      return 0;
    }
    if (pos[j][k] == -1) {
      res++;
      j = pos[0][k] + 1;
    } else {
      j = pos[j][k] + 1;
    }
  }
  printf("%lld\n", N * res + j);
  return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=2e18;
char s[2005];
ll f[2005][2005],g[2005][2005],k;
bool vis[2005][2005];
ll update(ll a,ll b)
{
	if (a==INF || b==INF) return INF;
	if (a+b>INF) return INF;
	return a+b;
}
void solve(int i,int j)
{
	if (i==j)
	{
		f[i][j]=1,g[i][j]=1;
		return;
	}
	if (i>j)
	{
		f[i][j]=0,g[i][j]=1;
		return;
	}
	if (vis[i][j]) return;
	vis[i][j]=true;
	if (s[i]==s[j])
	{
		solve(i+1,j-1);
		f[i][j]=f[i+1][j-1]+2,g[i][j]=g[i+1][j-1];
	}
	else
	{
		solve(i+1,j);
		solve(i,j-1);
		f[i][j]=min(f[i+1][j],f[i][j-1])+2;
		if (f[i+1][j]==f[i][j-1]) g[i][j]=update(g[i+1][j],g[i][j-1]);
		else if (f[i+1][j]<f[i][j-1]) g[i][j]=g[i+1][j];
		else g[i][j]=g[i][j-1];
	}
} 
void get_ans()
{
	int len=strlen(s);
	if (k>g[0][len-1])
	{
		printf("NONE\n");
		return;
	}
	int tot=f[0][len-1];
	int p=0,q=len-1;
	string ans="";
	while (p<=q)
	{
		if (s[p]==s[q]) ans+=s[p],p++,q--;
		else
		{
			if (f[p+1][q]==f[p][q-1])
			{
				if (s[p]>s[q])
				{
					if (k>g[p][q-1])
						k-=g[p][q-1],ans+=s[p],p++;
					else
						ans+=s[q],q--;
				}
				else
				{
					if (k>g[p+1][q])
						k-=g[p+1][q],ans+=s[q],q--;
					else
						ans+=s[p],p++;
				}
			}
			else if (f[p+1][q]<f[p][q-1])
				ans+=s[p],p++;
			else ans+=s[q],q--;
		}
	}
	cout<<ans;
	reverse(ans.begin(),ans.end());
	if (tot%2) ans=ans.substr(1);
	cout<<ans<<endl;
}
int main()
{
	scanf("%s",s);
	scanf("%lld",&k);
	int len=strlen(s);
	solve(0,len-1);
	get_ans();
	return 0;
}


Measured memory_bytes: 50124
def main():

	while True:
		numbers = input().split()
		x, y = map(int, numbers)
		
		if x == 0 and y == 0:
			break

		else:
			if x >  y:
				print('{0} {1}'.format(y, x))
			if x <= y:
				print('{0} {1}'.format(x, y))

	    


if __name__=="__main__":
	main()

Measured memory_bytes: 6720
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ll = long long;

int mod;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }

constexpr int nax = 305;

int C[nax][nax];

int Dp(int n, int k);
int Drzewo(int n, int k);

int Drzewo_(int n, int k) {
  int wynik = 0;
  for (int x = 1; x <= k; x++) {
    DodajDo(wynik, Dp(n, k - x));
  }
  return wynik;
}

int Dp_(int n, int k) {
  if (n == 0) {
    return 1;
  }
  int wynik = 0;
  for (int len = 0; len + 1 <= n; len++) {
    int ile = Mnoz(C[n - 1][len], Dp(n - len - 1, k));
    DodajDo(wynik, Mnoz(ile, Drzewo(len, k)));
  }
  return wynik;
}

int dp[nax][nax];
bool juz[nax][nax];

int Dp(int n, int k) {
  if (juz[n][k]) return dp[n][k];
  juz[n][k] = true;
  return dp[n][k] = Dp_(n, k);
}

int drz[nax][nax];
bool zuj[nax][nax];

int Drzewo(int n, int k) {
  if (zuj[n][k]) return drz[n][k];
  zuj[n][k] = true;
  return drz[n][k] = Drzewo_(n, k);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k >> mod;

  for (int i = 0; i < nax; i++) {
    C[i][i] = C[i][0] = 1;
    for (int j = 1; j < i; j++) {
      C[i][j] = Dodaj(C[i - 1][j - 1], C[i - 1][j]);
    }
  }

  cout << Dp(n, k) << endl;
  return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] b = new int[n];

		for (int i = 0; i < n - 1; i++) {
			b[i] = Integer.parseInt(sc.next());
		}

		int cnt = b[0];
		for (int i = 0; i < n - 1; i++) {
			cnt += Math.min(b[i], b[i + 1]);
		}
		cnt += b[n - 2];

		System.out.println(cnt);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int a[200005];
long long cnt[200005];
bool vis[200005];
void solve()
{
	int n;
	cin>>n;
	int i;
	long long sum=0;
	for(i=1;i<=n;i++) 
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	for(i=1;i<=n;i++)
	{
		if(vis[a[i]]) continue;
		sum=sum+cnt[a[i]]*(cnt[a[i]]-1)/2;
		vis[a[i]]=1;
	}
	for(i=1;i<=n;i++)
	{
		printf("%lld\n",sum-cnt[a[i]]*(cnt[a[i]]-1)/2+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2);
	}
}
int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 4096
import datetime
import sys

weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

for line in sys.stdin:
    data = line.strip().split()
    m = data[0]
    d = data[1]
    if m == '0':
        break

    date = datetime.datetime.strptime('2004-' + m + '-' + d + ' 13:13:13', '%Y-%m-%d %H:%M:%S')
    print weekdays[date.weekday()]

Measured memory_bytes: 5096
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
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; }

string s;

int main() {
    cin >> s;
    vector<int> ansalp(26, 0);
    for(int i = 0; i < 26; ++i) {
        char check = i + 'a';
        bool flg = false;
        int cnt = 0;
        for(int j = 0; j < (int)s.length(); ++j) {
            if(s.at(j) != check) {
                flg = true;
                break;
            }
        }
        if(flg) cnt++;
        string sch = s;
        while(flg) {
            string nsch;
            for(int j = 0; j < (int)(sch.length()-1); ++j) {
                if(sch.at(j) == check || sch.at(j+1) == check) {
                    nsch.push_back(check);
                }else {
                    nsch.push_back(sch.at(j));
                }
            }
            bool fflg = true;
            for(int j = 0; j < (int)nsch.length(); ++j) {
                if(nsch.at(j) != check) {
                    fflg = false;
                    break;
                }
            }
            if(fflg) {
                flg = false;
                break;
            }else {
                sch = nsch;
                cnt++;
            }
        }
        ansalp.at(i) = cnt;
    }

    sort(ansalp.begin(), ansalp.end());
    cout << ansalp.at(0) << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


class DICE {
	enum {
		Top,
		Front,
		Right,
		Left,
		Rear,
		Bottom
	};

public:
	int Num[6];

	void Roll(const char*Directions) {
		for (int i = 0; Directions[i] != '\0'; i++) {
			Roll(Directions[i]);
		}
	}

	void Roll(const char Direction) {
		int tmpTop = Num[Top];

		switch (Direction) {
		case'E':
			Num[Top] = Num[Left];
			Num[Left] = Num[Bottom];
			Num[Bottom] = Num[Right];
			Num[Right] = Num[tmpTop];
			break;
		case'N':
			Num[Top] = Num[Front];
			Num[Front] = Num[Bottom];
			Num[Bottom] = Num[Rear];
			Num[Rear] = tmpTop;
			break;
		case'S':
			Num[Top] = Num[Rear];
			Num[Rear] = Num[Bottom];
			Num[Bottom] = Num[Front];
			Num[Front] = tmpTop;
			break;
		case'W':
			Num[Top] = Num[Right];
			Num[Right] = Num[Bottom];
			Num[Bottom] = Num[Left];
			Num[Left] = tmpTop;
			break;
		}
	}

	int TopFrontToRight(const int TopNum, const int FrontNum) {
		const char Directions[][3] = { "N","N","N","NW","WW","\0" };
		DICE Dice;

		for (int i = 0; i < 6; i++)Dice.Num[i] = Num[i];

		for (int i = 0; i < 6; i++) {
			if (TopNum == Dice.Num[Top]) {
				for (int j = 0; j < 4; j++) {
					if (FrontNum == Dice.Num[Front])
						return Dice.Num[Right];

					int tmpFront = Dice.Num[Front];
					Dice.Num[Front] = Dice.Num[Right];
					Dice.Num[Right] = Dice.Num[Rear];
					Dice.Num[Rear] = Dice.Num[Left];
					Dice.Num[Left] = tmpFront;
				}
			}

			Dice.Roll(Directions[i]);
		}

		return 0;
	}
};

int main() {
	DICE Dice;
	int q;

	for (int i = 0; i < 6; i++) {
		cin >> Dice.Num[i];
	}
	cin >> q;

	for (int i = 0; i < q; i++) {
		int Top, Front;
		
		cin >> Top >> Front;

		cout << Dice.TopFrontToRight(Top, Front) << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = longList()
    var four = 0
    var notFour = 0
    var has2 = false
    a.forEach {
        if (it % 4 == 0L) {
            four++
        } else if (it % 2L == 0L) {
            has2 = true
        } else {
            notFour++
        }
    }
    if (has2) {
        notFour++
    }
    if (four >= notFour - 1) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 53888
N,M,X,Y=map(int,input().split())
xs = list(map(int,input().split()))
ys = list(map(int,input().split()))
mx = max(xs)
mx = max(mx,X)
my = min(ys)
my = min(my,Y)
if mx >= my: 
    print("War")
else:
    print("No War")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int main(){
  int x[26]={0};
  string s;
  bool ok=true;
  cin>>s;
  rep(i,s.size()){
    x[s[i]-'a']++;
  }
  rep(i,26){
    if(x[i]>1)ok=false;
  }
  if(ok)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

const int MXN = 1e5 + 5;
const ll MOD = 998244353;
const ll INF = 1000000007;


int N, M, p[MXN], chck[MXN], wa[MXN];
string s[MXN];
map<int,int> ac;



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

	cin >> N >> M;
	F0R(i,M){
		cin >> p[i+1] >> s[i+1];
		if (s[i+1] == "AC") ac[p[i+1]]++;
	}
	int wa_cnt = 0;
	F0R(i,M){
		if (s[i+1] == "AC" && !chck[p[i+1]]){
			chck[p[i+1]] = 1;
			wa_cnt += wa[p[i+1]];
		}
		else if (s[i+1] == "WA" && !chck[p[i+1]]){
			wa[p[i+1]]++;
		}
	}
	int cnt_ac = sz(ac);
	cout << cnt_ac << " " << wa_cnt << newl;






















	return 0;
}


Measured memory_bytes: 11264
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
  
int main()
{
	int d, g;
  cin>>d>>g;
  int p[11], c[11];
  for(int i=1; i<=d; i++){
    cin>>p[i]>>c[i];
  }
  int ans=10000;
  for(int i=0; i<(1<<d); i++){
    int ps=0, m=0;
    for(int j=0; j<d; j++){
      if(i&(1<<j)){
        m+=p[j+1];
        ps+=((j+1)*100*p[j+1]);
        ps+=c[j+1];
      }
    }
    if(g<=ps){
      ans=min(ans, m);
      continue;
    }
    for(int j=d-1; j>=0; j--){
      if(((i>>j)&1)==0){
        if(ps+100*(j+1)*(p[j+1]-1)<g){
          ps+=(100*(j+1)*(p[j+1]-1));
          m+=(p[j+1]-1);
        }else{
          m+=((g-ps+100*(j+1)-1)/(100*(j+1)));
          ps+=((g-ps+100*(j+1)-1)/(100*(j+1))*100*(j+1));
          break;
        }
      }
    }
    if(ps>=g){
      ans=min(ans, m);
    }
  }
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int count=0;
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  FOR(i,1,n-1){
    if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])) ++count;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    int n;
    cin>>n;
    ll a;
    map<ll,int> bou;
    vector<ll> hen;
    for(int i=0;i<n;i++){
        cin>>a;
        bou[a]++;
        if(bou[a] % 2 == 0 && bou[a] > 0) hen.push_back(a);
    }
    sort(hen.begin(),hen.end());
    ll ans = 0;
    if(hen.size() < 2) cout<<ans<<endl;
    else{
        ans = hen[hen.size()-1] * hen[hen.size()-2];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 6528
#include <stdio.h>
int main(){
  int n, q, i, l, r, m, cnt = 0;
  scanf("%d", &n);
  int s[n];
  for(i = 0; i < n; i++)
    scanf("%d", &s[i]);
  scanf("%d", &q);
  int t[q];
  for(i = 0; i < q; i++){
    scanf("%d", &t[i]);
    l = 0, r = n, m = (l + r) / 2;
    while(l != r){
      if(t[i] == s[m]){
	cnt++;
	break;
      }
      if(t[i] < s[m])
	r = m, m = (l + r) / 2;
      else
	l = m + 1, m = (l + r) / 2;
    }
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 1184
using System;

namespace ABC131A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            char[] s = Console.ReadLine().ToCharArray();
            string res = "Good";
            for (int i = 0; i < s.Length-1; i++)
            {
                if (s[i] == s[i+1])
                {
                    res = "Bad";
                    break;
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] V = new int[N];
        for (int i = 0; i < N; i++) {
            V[i] = sc.nextInt();
        }

        int[] C = new int[N];
        for (int i = 0; i < N; i++) {
            C[i] = sc.nextInt();
        }

        int[] sub = new int[N];
        int ans = 0;


        for (int i = 0; i < N; i++) {
            sub[i] = V[i] - C[i];
        }

        for (int i = 0; i < N; i++) {
            if (sub[i] > 0) {
                ans += sub[i];
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	a := reads()

	if a == "ABC" {
		fmt.Println("ARC")
	} else {
		fmt.Println("ABC")
	}
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}


Measured memory_bytes: 1856
#include <bits/stdc++.h>
#define N 100
using namespace std;
bool valid_neighbours(string *grid, int x, int y, char c) {
  if (x && grid[x-1][y] == c) {
    return false;
  }
  if (x && y && grid[x-1][y-1] == c) {
    return false;
  }
  if (x && y+1 < N && grid[x-1][y+1] == c) {
    return false;
  }
  if (y && grid[x][y-1] == c) {
    return false;
  }
  if (y+1 < N && grid[x][y+1] == c) {
    return false;
  }
  if (x+1 < N && y && grid[x+1][y-1] == c) {
    return false;
  }
  if (x+1 < N && grid[x+1][y] == c) {
    return false;
  }
  if (x+1 < N && y+1 < N && grid[x+1][y+1] == c) {
    return false;
  }
  return true;
}
void place_white(string *grid, int C) {
  for (int i = 0; i < N/2-1; i++) {
    for (int j = 0; j < N; j++) {
      if (C == 1) {
        return;
      }
      if (valid_neighbours(grid,i,j,'.')) {
        grid[i][j] = '.';
        C--;
      }
    }
  }
}
void place_black(string *grid, int C) {
  for (int i = N-1; i > N/2; i--) {
    for (int j = 0; j < N; j++) {
      if (C == 1) {
        return;
      }
      if (valid_neighbours(grid,i,j,'#')) {
        grid[i][j] = '#';
        C--;
      }
    }
  }
}
int main() {
  string grid[N];
  int A,B;
  cin >> A >> B;
  for (int i = 0; i < N/2; i++) {
    grid[i] = string(N,'#');
  }
  for (int i = N/2; i < N; i++) {
    grid[i] = string(N,'.');
  }
  cout << N << ' ' << N << endl;
  place_white(grid,A);
  place_black(grid,B);
  for (int i = 0; i < N; i++) {
    cout << grid[i] << endl;
  }
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << " = " << x << "\n"

using LL = long long;
using LD = long double;
using pii = pair <int, int>;
using vii = vector <pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int n, m, cnt;
int a[N];

class dsu {
 public:
  vector<int> p;
  int n, sz;

  dsu(int _n) : n(_n), sz(_n) {
    p.resize(n + 1);
    iota(p.begin(), p.end(), 0);
  }

  int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  void unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      cnt -= a[x] * a[y];
      a[y] += a[x];
      sz--;
    };
  }
};

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

    cin >> n >> m;

    vii edge(m);
    for (int i = 0; i < m; i++) {
        cin >> edge[i].fi >> edge[i].se;
    }

    cnt = n * (n - 1) / 2;
    dsu d(n);
    vector<int> ans;

    for (int i = 0; i < N; i++) {
        a[i] = 1;
    }

    for (int i = m - 1; i >= 0; i--) {
        ans.pb(max(0LL, cnt));
        if (d.get(edge[i].fi) != d.get(edge[i].se)) {
            d.unite(edge[i].fi, edge[i].se);
        }
    }

    for (int i = m - 1; i >= 0; i--) {
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 5364
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.endl(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 998244353  // prime;
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
}
// int size = 200001;  // e6 + 1
vector<ll> fac;   // n!(mod M)
vector<ll> ifac;  // k!^{M-2} (mod M)
vector<ll> inv;   // k!^{M-2} (mod M)
////////////////////////////////////////////////
void fac_mod(int size) {
  // fac[i] = i! (mod M)
  fac[0] = 1;
  fac[1] = 1;
  REP(i, fac.size() - 1) { fac[i + 1] = fac[i] * (i + 1) % MOD; }
}
////////////////////////////////////////////////
void ifac_mod(int size) {
  // ifac[i] = 1/i! (mod M)
  ifac[0] = 1;
  ifac[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < ifac.size() - 1; i++) {
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
}
////////////////////////////////////////////////
ll nCk_mod(ll n, ll k) {
  // nCk (mod M)
  if (n == 0 && k == 0) return 1;
  if (n < k || k < 0) return 0;
  return fac[n] * (ifac[n - k] * ifac[k] % MOD) % MOD;
}
////////////////////////////////////////////////
ll pow_mod(ll x, int n) {
  // x^n (mod M)
  ll pow = 1;
  while (n != 0) {
    if (n & 1) pow = pow * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return pow;
}
////////////////////////////////////////////////
int main() {
  init();
  ll n, m, k;
  cin >> n >> m >> k;
  fac = vector<ll>((int)(n + 1), 0);
  ifac = vector<ll>((int)(n + 1), 0);
  inv = vector<ll>((int)(n + 1), 0);
  fac_mod((int)(n + 1));
  ifac_mod((int)(n + 1));
  vector<ll> mpow(n, 0);
  vector<ll> ncj(n, 0);
  REP(i, n) {
    mpow[i] = pow_mod((ll)(m - 1), i);
    ncj[i] = nCk_mod((n - 1), i);
  }
  ll ans = 0;
  REP(i, k + 1) {
    // cout << mpow[n - 1 - i] << " " << ncj[i] << " "
    //  << ((m * mpow[n - 1 - i]) % MOD * ncj[i]) % MOD << endl;
    ans += ((m * mpow[n - 1 - i]) % MOD * ncj[i]) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11120
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int p[1000000];
int main(void){
	int n,i,j,ans;

	rep(i,2,1000000){
		p[i]=1;
		for(j=2;j*j<=i;j++){
			if(i%j==0){
				p[i]=0;
				break;
			}
		}
		/*if(i<=10){
			printf("%d %d\n",i,p[i] );
		}*/

	}

	while(scanf("%d",&n)!=EOF){
		ans=0;
		rep(i,0,n+1){
			ans+=p[i];
		}
		printf("%d\n",ans );
	}
	
	return 0;
}

Measured memory_bytes: 4500
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#define inf 10000000
using namespace std;
typedef long long int ll;

int main(){

    int i;
    string n;
    cin >> n;

    for(i=0 ; i<3 ; i++){
        if(n[i] == '1'){
            n[i] = '9';
        }else if(n[i] == '9'){
            n[i] = '1';
        }
    }

    cout << n << endl;
    
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
        int m = sc.nextInt(); 
        int c = sc.nextInt();
		int [] in = new int [m];
        int ans = 0;
        for(int i=0;i<m;i++){
                             in[i] = sc.nextInt();
                            }	
        for(int i=0;i<n;i++){int count = 0;
          for(int j=0;j<m;j++){int a = sc.nextInt();
                              count+=a*in[j];
                              if(j==m-1 && count+c>0){ans++;}}
                            }
	System.out.println(ans);
  }
}

Measured memory_bytes: 21712
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < (int)n ; i++)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
using namespace std;
int dp[1001][1001];
int main(){
    string s1, s2;
    cin >> s1;
    cin >> s2;
    rep(i, s1.length()+1) dp[i][0] = i;
    rep(j, s2.length()+1) dp[0][j] = j;
    REP(i, 1,  s1.length()+1){
        REP(j, 1, s2.length()+1){
            int cost = s1[i-1] == s2[j-1]?0:1;
            dp[i][j] = min(min(dp[i-1][j]+1, dp[i][j-1]+1), dp[i-1][j-1]+cost);
        }
    }
    cout << dp[s1.length()][s2.length()] << endl;
}


Measured memory_bytes: 7072
def inpl(): return [int(i) for i in input().split()]

H, W, K = inpl()

if W == 1:
    print(1)
else:
    mod = 10**9 + 7
    S = [[0 for _ in range(W)] for _ in range(H+1)]
    S[0][0] = 1
    
    dpy = [0 for _ in range(W-1)]
    dpn = [0 for _ in range(W-1)]
    dpy[0] = 0
    dpn[0] = 1
    dpy = [0]
    dpn = [1]
    for i in range(1,W-1):
        dpy.append(dpn[i-1])
        dpn.append(dpn[i-1] + dpy[i-1])
    dpy = [0]+dpy
    dpn = [0]+dpn
    dp = [dpy[i] + dpn[i] for i in range(W)]
    for i in range(H):
       for j in range(W):
           if j == 0 or j == W-1:
               c = dp[W-1]
           else:
               c = dp[j]*dp[W-j-1]
           S[i+1][j] += c*S[i][j] % mod
           if  j != 0 :
              S[i+1][j-1] += max(1,dp[j-1])*max(1,dp[W-j-1])*S[i][j] %mod
           if j != W-1 :
               S[i+1][j+1] += max(1,dp[j])*max(1,dp[W-j-2])*S[i][j]  %mod
    print(S[H][K-1]%mod)
               

Measured memory_bytes: 3064