akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>
#include <utility>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int64;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, x;
  cin >> k >> x;
  --k;
  for (int i = x - k; i <= x + k; ++i) {
    cout << i << " ";
  }
  cout << '\n';
  return 0;
}



Measured memory_bytes: 256
package main

import(
"fmt"
)

func main() {
  var a int
  var b int
  var c int
  var k int
  
fmt.Scan(&a,&b,&c,&k)
  if k - a <= 0{  
    fmt.Println(k)
  }else if k - a - b <=0{
    fmt.Println(a)
  }else{ 
    fmt.Println((k-a-b)*-1 + (a))
  }
}


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

typedef long long ll;

int n, p;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> p >> s;

    ll res;
    if (p == 2 || p == 5) {
        for (int i = 0; i < n; ++i) {
            if ((s[i] - '0') % p == 0)
                res += i + 1;
        }
    } else {
        ll base = 1;
        ll sum = 0;
        unordered_map<int, int> cnt;
        cnt[0] = 1;
        for (int i = n - 1; i >= 0; --i) {
            sum = ((s[i] - '0') * base + sum) % p;
            if (cnt.count(sum)) {
                res += cnt[sum];
            }
            cnt[sum]++;
            base = base * 10 % p;
        }
    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main(){
    ll n; cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vector<ll> count(5);

    rep(i,n){
        if(s[i][0] == 'M')count[0]++;
        if(s[i][0] == 'A')count[1]++;
        if(s[i][0] == 'R')count[2]++; 
        if(s[i][0] == 'C')count[3]++;
        if(s[i][0] == 'H')count[4]++;
    } 
    ll ans = 0;
    rep(i,5){
        _rep(j,i + 1,5){
            _rep(k,j + 1,5){
                ans += count[i] * count[j] * count[k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6144
#!/usr/bin/env python3


def get_points_and_convert(pts):
    x, y = pts
    return x + y, x - y


def main():
    n = int(input())
    points = [
        get_points_and_convert(map(int, input().split()))
        for _ in range(n)
    ]
    plus_coords, minus_coords = list(zip(*points))
    plus_dist = max(plus_coords) - min(plus_coords)
    minus_dist = max(minus_coords) - min(minus_coords)
    print(max(plus_dist, minus_dist))


if __name__ == '__main__':
    main()


Measured memory_bytes: 51612
/*input
4 4
1 1
4 4
..#.
..#.
.#..
.#..
*/

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

struct pos {int i, j, d;};
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si; --sj; --ti; --tj;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    const int INF = 1e9;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    deque<pos> q;
    dist[si][sj] = 0;
    q.emplace_back(pos{si, sj, 0});
    while (!q.empty()) {
        int i = q.front().i;
        int j = q.front().j;
        int d = q.front().d;
        q.pop_front();
        if (dist[i][j] < d) continue;
        rep(v, 4) {
            int ni = i+di[v], nj = j+dj[v];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (s[ni][nj] == '#') continue;
            if (dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(pos{ni, nj, d});
        }
        for (int ei = -2; ei <= 2; ++ei) {
            for (int ej = -2; ej <= 2; ++ej) {
                int ni = i+ei, nj = j+ej;
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (s[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(pos{ni, nj, d+1});
            }
        }
    }
    int ans = dist[ti][tj];
    if (ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 9448
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>n>>l;
    vector<pair<int,int> >a;
    for(int i=0;i<n;i++){
        int temp;
        temp=i+l;
        if(temp<0){
            a.push_back({-temp,temp});
        }
        else{
            a.push_back({temp,temp});
        }
    }
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=1;i<n;i++){
        ans+=a[i].second;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node
{
    int key;
    Node *next, *prev;
};

//哨兵
Node *nil;

Node *ListSearch(int key)
{
    Node *cur=nil->next;
    while(cur!=nil && cur->key!=key)
    {
        cur=cur->next;
    }
    return cur;
}

void Init()
{
    nil=(Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}

void PrintList()
{
    Node *cur=nil->next;
    int isf=0;
    while(true)
    {
        if(cur==nil)
            break;
        if(isf++>0)
            printf(" ");
        printf("%d", cur->key);
        cur=cur->next;
    }
    printf("\n");
}

void DeleteNode(Node *t)
{
    if(t==nil)
        return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}

void DeleteFirst()
{
    DeleteNode(nil->next);
}

void DeleteLast()
{
    DeleteNode(nil->prev);
}

void DeleteKey(int key)
{
    DeleteNode(ListSearch(key));
}

void Insert(int key)
{
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}

int main()
{
    int key, n, i;
    int size=0;
    char com[20];
    int np=0, nd=0;
    scanf("%d", &n);
    Init();
    for(int i=0; i<n; i++)
    {
        scanf("%s%d", com, &key);
        if(com[0]=='i')
        {
            Insert(key);
            np++;
            size++;
        }
        else if(com[0]=='d')
        {
            if(strlen(com)>6)
            {
                if(com[6]=='F')
                    DeleteFirst();
                else if(com[6]=='L')
                    DeleteLast();
            }
            else
            {
                DeleteKey(key);
                nd++;
            }
            size--;
        }
    }
    PrintList();
    return 0;
}



Measured memory_bytes: 33976
N = int(input())
xy = []
for _ in range(N):
  x, y = map(int, input().split())
  xy.append([x, y])
import itertools
from math import sqrt
distance = 0
perm = list(itertools.permutations(xy))
for P in perm:
  for i in range(N):
    if i == N - 1:
      break
    diff = sqrt((P[i][0] - P[i + 1][0]) ** 2 + (P[i][1] - P[i + 1][1]) ** 2)
    distance += diff
print(distance / len(perm))

Measured memory_bytes: 8228
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int n,m,count=0;
    scanf("%lld%lld",&n,&m);
    if(m>=2*n)
    {
        count+=n;
        m-=2*n;
        n=0;
        count+=m/4;
    }
    else
    {
        count=m/2;
    }
    printf("%lld\n",count);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

unordered_map<ll,int> prime_factor(ll n){
    unordered_map<ll,int> ret;
    for(ll i=2; i*i<=n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n]=1;
    return ret;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    ll a=(ll)gcd(N,M);
    unordered_map<ll,int> m = prime_factor(a);
    cout << m.size()+1 << endl;
    
}

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

int main(void){
  char s[3];
  int x=0;
  cin >> s[0] >> s[1] >> s[2];
  for(int i=0;i<3;i++){
    if(s[i]=='1')x++;
  }
  cout << x << endl;
    return 0;
}


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

using namespace std;

int main(){

	int a, b, c, k;

	scanf("%d %d %d %d", &a, &b, &c, &k);

	int maxi = max(a,max(b,c));

	printf("%d\n", a+b+c-maxi+(maxi<<k));
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
signed main(){
	int n;cin>>n;
	
	int a[200000];
	int b[200000];
	for(int i=0;i<n;i++){
		scanf("%d", &a[i]);
		b[i]=i-a[i];
		a[i]=i+a[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	int ans=0;
	int j=0;
	for(int i=0;i<n and j<n;i++){
		int acount=0;
		int bcount=0;
		while(a[i]>b[j] and j<n){j++;if(j==n){break;}}
		if(j==n){break;}
		if(b[j]>a[i]){continue;}
		else{
		
			int s=a[i];
			while(a[i]==s){
				acount++;
				i++;
				if(i==n){break;}
			}
			i--;
			while(b[j]==s){
				bcount++;
				j++;
				if(j==n){break;}
			}
			ans+=acount*bcount;
			//cout<<s<<" "<<acount*bcount<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6828
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		if (a == 0) {
			System.out.println(1);
		}else if (a == 1) {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 35624
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    long long N;
    cin >> N;
    
    vector<long long> A(N),B(N);
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    
    long long minus_count=1;
    B[0]= (-1)*A[0];
    for (long long i=1; i<N-1; i++) {
        if (A[i]<0) {
            B[i]=(-1)*A[i];
            minus_count++;
        }
        else{
            B[i]=A[i];
        }
    }
    B[N-1] = A[N-1];
    //long long plus_count = N - minus_count;
    
    long long ans = accumulate(B.begin(), B.end(), 0LL);
    
    vector<pair<long long, long long>> output(N-1);
    
    output[0]= make_pair(A[N-1], A[1]);
    
    long long pre_m = A[N-1];
    for (long long i=1; i<minus_count; i++) {
        output[i-1]=make_pair(pre_m, A[i]);
        pre_m = pre_m - A[i];
    }
    
    long long pre_p = A[0];
    //cout << minus_count << endl;
    for (long long i=minus_count-1; i<N-2; i++) {
        output[i]=make_pair(pre_p, A[i+1]);
        pre_p = pre_p - A[i+1];
    }
    
    output[N-2] = make_pair(pre_m, pre_p);
    
    
    cout << ans << endl;
    for (int i=0; i<N-1; i++) {
        cout << output[i].first << ' ' << output[i].second << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, k;
int l[50];

int main(int argc, char **argv) {
	cin >> n >> k;
	REP(i, n) cin >> l[i];
	sort(l, l + n);
	reverse(l, l + n);
	int res = 0;
	REP(i, k) res += l[i];
	cout << res << endl;
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll H, W;
	cin >> H >> W;
	vector<string> a(H);
	REP(i, H) cin >> a[i];

	ll dp[H][W];
	REP(i, H)REP(j, W){
		if(i==0&&j==0){
			dp[i][j] = 1;
			continue;
		}
		dp[i][j] = 0;
		if(a[i][j]=='.'){
			if(i>0) dp[i][j] += dp[i-1][j];
			dp[i][j] %= mod;
			if(j>0) dp[i][j] += dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main()
{
        long long int x1,a,b,r=1,s=0,ans=0,i,j=0,n,x=0;
        cin>>a>>b;
           r=2*a;
           n=4*a;
           if(b%2==0)
           {
               if(r<=b && n>=b)
                   cout<<"Yes"<<endl;
               else
                   cout<<"No"<<endl;
           }
        else
            cout<<"No"<<endl;


   return 0;
}









Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template <class T>
class WeightedUnionFind {
  int n;
  vector<int> par,sz;
  vector<T> w;
  // weight[i] : iがpar[i]よりどれだけ重いか
public:
  WeightedUnionFind(){}
  WeightedUnionFind(int _n) : n(_n) {
    par.resize(n, -1);
    sz.resize(n, 1);
    w.resize(n, 0);
  }
  int find(int i){
    if(par[i] < 0){
      return i;
    } else {
      int p = find(par[i]);
      w[i] += w[par[i]];
      par[i] = p;
      return p;
    }
  }
  T weight(int x){
    find(x);
    return w[x];
  }
  bool same(int x, int y){
    return find(x) == find(y);
  }
  // weight[i] +w の位置に j を配置
  void unite(int i, int j, T nw){
    nw += weight(i) - weight(j);
    int x = find(i), y = find(j);
    if(x == y) return;
    if(sz[x] < sz[y]){
      swap(x, y);
      nw = -nw;
    }
    sz[x] += sz[y];
    par[y] = x;
    w[y] = nw;
  }
  // x からみた y の相対位置
  T diff(int x, int y){
    return weight(y) - weight(x);
  }
};

bool solve(){
  int n,m;
  cin>>n>>m;

  WeightedUnionFind<int> uf(n);
  rep(i,m){
    int l,r,d;
    cin>>l>>r>>d;
    l--;r--;
    if(uf.same(l,r)){
      if(uf.diff(l,r) != d) return false;
    } else {
      uf.unite(l,r,d);
    }
  }
  return true;
}

int main(){
  cout << (solve() ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  int b=1;
  cin >> a;
  int c=a;
  if(a>1000){
    while(a>1000){
          a-=1000;
          b++;
    }
  }
  else{
      b=1;
  }
  int d=b*1000-c;
  cout << d <<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
    int n; cin >> n;
    string s[220000];
    rep(i, n) cin >> s[i];
    sort(s, s+n);
    // rep(i, n) cout << s[i] << endl;
    map<string, int> mp;
    rep(i, n) {
        if(!mp[s[i]]) {
            mp[s[i]] = 1;
            continue;
        }
        mp[s[i]] += 1;
    }
    int max = 0;
    vector<string> ans;
    for(auto k : mp) {
        if (k.second > max) {
            max = k.second;
        }
    }
    for(auto k : mp) {
        if (k.second == max) {
            ans.push_back(k.first);
        }
    }
    for(auto a : ans) {
        cout << a << endl;
    }



    return 0;
}


Measured memory_bytes: 28660
#include<stdio.h>

int main(void){
    char S[10] = {};
    scanf("%s",S);
    if(S[0] == 'S'){
        printf("Cloudy");
        return 0;
    }
    if(S[0] == 'C'){
        printf("Rainy");
        return 0;
    }
    if(S[0] == 'R'){
        printf("Sunny");
        return 0;
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define INF 30000000000001
#define ll_max 9000000000000000001
#define mod 1000000007
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 100001;
const ll M = 1;

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m, x = 0, y, ans = 0, W;
        cin >> n >> W;
        ll w[n], v[n];
        for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
        ll dp[N];
        for(int j = N - 1; j > -1; j--) dp[j] = INF;
        dp[0] = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = N - 1; j > -1; j--)
            {
                if(j - v[i] >= 0)
                dp[j] = min(dp[j - v[i]] + w[i], dp[j]);
            }
        }
        for(ll j = 0; j < N; j++)
        {
            if(dp[j] <= W)
            ans = max(j, ans);
        }
        cout << ans << "\n";
    }
    return 0;
}


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

print(' '.join(map(str, A)))
for i in range(1, N):
  value = A[i]
  j = i - 1
  while j >= 0 and A[j] > value:
    A[j+1] = A[j]
    j -= 1
  A[j+1] = value
  print(' '.join(map(str, A)))


Measured memory_bytes: 5596
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a <= 8 && b <= 8) {
        printf("Yay!\n");
    } else {
        printf(":(\n");
    }
}


Measured memory_bytes: 128
n,a,b=map(int,input().split())
def fact(n,p):
    a=1
    for i in range(1,n+1):
        a=(a*i)%p
    return a
def bfact(n,x,p):
    a=1
    for i in range(n-x+1,n+1):
        a=(a*i)%p
    return a
p=10**9+7
na=bfact(n,a,p)%p
nb=bfact(n,b,p)%p
aa=fact(a,p)%p
bb=fact(b,p)%p
aaa=pow(aa,-1,p)
bbb=pow(bb,-1,p)
ans=pow(2,n,p)-1
ans-=(na*aaa+nb*bbb)
print(ans%p)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int a,p;
    cin >> a >> p;
    a *= 3;
    cout << (a+p)/2 << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int fib[50] = {1, 1};
int makeFib(int cur) {
    if(fib[cur]) {
        return fib[cur];
    }
    return fib[cur] = makeFib(cur - 1) + makeFib(cur - 2);
}
int main()
{
    for(int i = 2; i < 45; i++) {
        fib[i] = makeFib(i);
    }
    int n;
    cin >> n;
    cout << fib[n] << "\n";
}


Measured memory_bytes: 3104
INF = float("inf")
n, k, c = map(int, input().split())
s = input()
l, r = [(0, -INF)] + [None] * n, [(0, INF)] + [None] * n
for i, x in enumerate(s):
    wn, wd = l[i]
    l[i+1] = (wn+1, i) if x == "o" and i-wd > c else l[i]

for i, x in enumerate(s[::-1]):
    wn, wd = r[i]
    j = n-i-1
    r[i+1] = (wn+1, j) if x == "o" and wd-j > c else r[i]

for i in range(n):
    ln, ld = l[i]
    rn, rd = r[n-i-1]
    w = ln + rn
    if rd - ld <= c: w -= 1
    if w < k: print(i+1)


Measured memory_bytes: 60008
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <unordered_map>
#include <queue>

using namespace std;

const int maxN = 2e5 + 10;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define PINT pair < int, int >
#define NUM_SET_BIT __builtin_popcountll
#define BIT(x, i) ((x >> i) & 1)

deque < int > b;
int n, a[maxN];

int main() {
    cin >> n;
    FORU(i, 1, n) cin >> a[i];
    bool head = false;
    FORU(i, 1, n) {
        if (head) b.push_front(a[i]);
        else b.push_back(a[i]);
        head = !head;
    }
    if (head) reverse(b.begin(), b.end());
    for (auto x : b) cout << x << " ";
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int l;
    cin >> l;
    cout << fixed << setprecision(6) << pow((double)l/3, 3) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	map<char, ll>mp;
	string S;
	cin >> S;
	string ans = "Yes";
	for (ll i = 0; i < S.size(); i++) {
		for (char c = 'a'; c <= 'z'; c++) {
			if (S[i] == c) mp[S[i]]++;
		}
	}
		for (char c = 'a'; c <= 'z'; c++) {
			if (mp[c] % 2 == 1)
				ans = "No";
		}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, k; cin >> n >> k;
  vector<ll> a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i] >> b[i];
  }
  vector<ll> pos = {k};
  for(int i=1;i<30;++i) {
    if(k & (1<<i)) {
      pos.push_back((k ^ (1<<i)) | ((1<<i) - 1));
    }
  }
  int sz = (int)(pos.size());
  ll ma = 0;
  for(int i=0;i<sz;++i) {
    ll now = 0;
    for(int j=0;j<n;++j) {
      if((pos[i] | a[j]) == pos[i]) now += b[j];
    }
    ma = max(ma, now);
  }
  cout << ma << endl;
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll N,K;

// v[y][x]: 座標y,xに黒い点がいくつあるか
vector<vector<ll>> v(4100, vector<ll>(4100,0));

ll sum(ll x, ll y, ll w, ll h){
    return v[y+h][x+w]
          -v[y+h][x]
          -v[y][x+w]
          +v[y][x];
}

signed main() {
    cin>>N>>K;
    rep(i,0,N){
        ll x,y;
        char c;
        cin>>x>>y>>c;
        if (c=='W'){
            c='B';
            x += K;
        }
        x %= 2*K;
        y %= 2*K;
        v[y][x]++;
    }

    rep(y,0,2*K){
        rep(x,0,2*K){
            v[y+2*K][x+2*K] = v[y][x];
            v[y+2*K][x    ] = v[y][x];
            v[y    ][x+2*K] = v[y][x];
            v[y    ][x    ] = v[y][x];
        }
    }

    // v[y][x]を2次元累積和に変形
    rep(y,1,4*K)
        rep(x,0,4*K)
            v[y][x] += v[y-1][x];
    rep(x,1,4*K)
        rep(y,0,4*K)
            v[y][x] += v[y][x-1];

    ll ans = 0;
    rep(y,0,2*K)
        rep(x,0,2*K) {
            ll t = 0;
            t += sum(x,y,K,K);
            t += sum(x+K,y+K,K,K);
            ans = max(ans,t);
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 131712
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
   N, M = MAP()
   print(len(list(combinations(range(N), 2))) + len(list(combinations(range(M), 2))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4328
#include <bits/stdc++.h>
using namespace std;
const int MD=998244353;
const int N=2e5+5;
struct Point {
	int x,y,id;
	bool operator <(const Point &t)const {
		if(x!=t.x) return x<t.x;
		return y<t.y;
	}
}p[N];
int a[N],n;
int A[N],B[N],s[N];
int quick_pow(int x,int y) {
	int ans=1;
	while(y) {
		if(y&1) ans=1LL*ans*x%MD;
		y>>=1;
		x=1LL*x*x%MD;
	}
	return ans;
}
void update(int pos) {
	for(int i=pos;i<=n;i+=(i&-i)) 
		s[i]++;
}
int query(int pos) {
	int ans=0;
	for(int i=pos;i;i-=(i&-i))
		ans+=s[i];
	return ans;
}
int cal(int a,int b,int c,int d) {
	//printf("%d %d %d %d\n",a,b,c,d);
	a=quick_pow(2,a),b=quick_pow(2,b),c=quick_pow(2,c),d=quick_pow(2,d);
	return (1LL*(a-1)*b%MD*c%MD*(d-1)%MD+1LL*a*(b-1)%MD*(c-1)%MD*d%MD-1LL*(a-1)*(b-1)%MD*(c-1)%MD*(d-1)%MD)%MD;
}
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y),a[i]=p[i].y;
	sort(p,p+n),sort(a,a+n);
	for(int i=0;i<n;i++) p[i].id=lower_bound(a,a+n,p[i].y)-a,p[i].id=n-p[i].id;
	//for(int i=0;i<n;i++) printf("%d %d %d\n",p[i].x,p[i].y,p[i].id);
	for(int i=0;i<n;i++) {
		A[i]=query(p[i].id);
		update(p[i].id);
	}
	for(int i=1;i<=n;i++) s[i]=0;
	for(int i=n-1;i>=0;i--) {
		B[i]=query(p[i].id);
		update(p[i].id);
	}
	int ans=0;
	for(int i=0;i<n;i++) {
		ans=(ans+quick_pow(2,n-1))%MD;
		ans=(ans+cal(A[i],B[i],i-A[i],n-i-1-B[i]))%MD;
	}
	printf("%d\n",(ans+MD)%MD);
	return 0;
}

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

#define Ff(i,j,n)  for (i = j ; i < n; i++)
#define Fb(i,j,n)    for (i = (n - 1); i >= j; i--)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<long, long>
#define pi 3.14159265358979323846
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(), x.end()
#define trav(i,x) for(auto& i:x)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef vector < long long > vll;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;

// const ll mod = 998244353;
const ll N = 1e18;
// ll binpow(ll b, ll p) { ll ans = 1; while (p > 0) {if (p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;} return ans;}
// ll inv(ll x) {return binpow(x, mod - 2);}
// ll divide(ll x, ll y) {return ((x % mod) * (inv(y))) % mod;}


int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS
	int t = 1;
	// cin >> t;
	while (t--) {
		string s;
		int i;
		cin >> s;
		int p = 0;
		int l = s.length();
		Ff(i, 0, l)
		p = (p + s[i] - '0') % N;
		if (p % 9)cout << "No";
		else cout << "Yes";
		cout << endl;

	}


	return 0;
}

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

int main(){
  int n;
  ll x;
  cin >> n >> x;
  int tel[n];
  for(int i=0; i<n; ++i){
    cin >> tel[i];
    tel[i]--;
  }
  vector<int> cnt(n,0);
  int pos=0;
  bool flag = true;
  for(ll i=0; i<x; ++i){
    pos = tel[pos];
    if(flag && cnt[tel[pos]] ==0){
      cnt[tel[pos]] = i+1;
    }
    else if(!flag) continue;
    else{
      int roop = i+1 - cnt[tel[pos]];
      x = (x-i-1) % roop + i+1;
      flag = false;
      if(i == x-1) break;
    }
  }
  cout << pos+1 << endl;
}

Measured memory_bytes: 4772
import bisect
primes = [0, 0] + [1]*999999
for i in range(2, 1001):
    if primes[i]:
        for j in range(i*i, 1000001, i):
            primes[j] = 0

primes = list(filter(lambda x: x != 0, [(v != 0) * i for i, v in enumerate(primes)]))
while True:
    try:
        n = int(input())
    except:
        break
    print(bisect.bisect(primes, n))

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

import math

def sieve(n):
    ass = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(math.sqrt(n))+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            ass.append(i)
    return(ass)

S = sieve(55555)
T = []
for i in range(len(S)):
    if S[i]%5 == 1:
        T.append(S[i])
print(*T[0:n])


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    vector<P> ba(n), cd(n);
    rep(i, n) {
        int a, b; cin >> a >> b;
        ba[i] = {b, a};
    }
    rep(i, n) {
        int c, d; cin >> c >> d;
        cd[i] = {c, d};
    }
    sort(ba.begin(), ba.end());
    reverse(ba.begin(), ba.end());
    sort(cd.begin(), cd.end());

    int ans = 0;
    vector<bool> used(n, false);
    rep(i, n) {
        P B = cd[i];
        int idx = -1;
        rep(j, n) {
            if(!used[j] && ba[j].second < B.first && ba[j].first < B.second) {
                idx = j;
                ans++;
                break;
            }
        }
        if(idx != -1) {
            used[idx] = true;
        }
    }

    cout << ans << '\n';
    return 0;
}

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

int main() {
    int ans = 0;
    vector<int> A(5), B(5);
    for (int i = 0; i < 5; i++){
        cin >> A.at(i);
    }
    B = A;
    for (int i = 0; i < 5; i++) {
        B.at(i) = A.at(i) % 10;
    }
    sort(B.begin(), B.end());
    for (int i = 0; i < 5; i++) {
        if (B.at(i) != 0) {
            ans += B.at(i);
            break;
        }
        if (i == 4){
            ans += 10;
        }
    }
    for (int i = 0; i < 5; i++) {
        ans += ((A.at(i) - 1) / 10 + 1) * 10;
    }
    cout << ans - 10 << endl;
}

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

int main() {

string s;
cin>>s;
string ans="ABC";
if(s=="ABC")
{ans="ARC";}
cout<<ans<<endl;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

typedef long long int int64;

void run(void){
  int n;
  scanf("%d",&n);
  graph *g=newGraph(n,2*n);
  int i;
  for(i=0;i<n-1;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    x--;
    y--;
    addEdge(g,x,y);
    addEdge(g,y,x);
  }
  int *q=(int *)calloc(n,sizeof(int));
  int *parent=(int *)calloc(n,sizeof(int));
  q[0]=0;
  int front=0;
  int last=1;
  while(last<n){
    int v=q[front++];
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      parent[u]=v;
      q[last++]=u;
    }
  }
  const int mod=1000000007;
  int *dp=(int *)calloc(2*n,sizeof(int));
  for(i=n-1;i>=0;i--){
    int v=q[i];
    dp[2*v]=dp[2*v+1]=1;
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(u==parent[v]) continue;
      dp[2*v]=(int64)dp[2*v]*(dp[2*u]+dp[2*u+1])%mod;
      dp[2*v+1]=(int64)dp[2*v+1]*dp[2*u]%mod;
    }
  }
  printf("%d\n",(dp[0]+dp[1])%mod);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <cfloat>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a;
set<int> st;
int dp[100010];
signed main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a;
		st.insert(a);
	}
	dp[0] = 1;
	rep(i, n) {
		dp[i] %= mod;
		if (st.find(i + 1) == st.end())dp[i + 1] += dp[i];
		if (st.find(i + 2) == st.end())dp[i + 2] += dp[i];
	}
	cout << dp[n] % mod << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int f[10001][101][2];
char a[10001];
int main()
{
	int n,d,i,j,l;
	scanf("%s",a);
	scanf("%d",&d);
	n=strlen(a);
	f[0][0][1]=1;
	for(i=0;i<n;i++)
	{
		for(j=0;j<d;j++)
		{
			for(l=0;l<=9;l++)
				f[i+1][(j+l)%d][0]=(f[i+1][(j+l)%d][0]+f[i][j][0])%1000000007;
			for(l=0;l<=a[i]-'0';l++)
			{
				if(l==a[i]-'0')
					f[i+1][(j+l)%d][1]=(f[i+1][(j+l)%d][1]+f[i][j][1])%1000000007;
				else
					f[i+1][(j+l)%d][0]=(f[i+1][(j+l)%d][0]+f[i][j][1])%1000000007;
			}
		}
	}
	printf("%d",(f[n][0][0]+f[n][0][1]+1000000006)%1000000007);
	return 0;
}

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

map<ll,int> pf(ll n){
    map<ll,int> ret;
    for(ll i=2;i*i<=n;++i){
        while(n%i==0){
            ++ret[i];
            n/=i;
        }
    }
    if(n!=1)ret[n]=1;
    return ret;
}

int main(){
    ll N;
    cin>>N;
    
    const auto &prime=pf(N);
    
    ll ans=0;
    for(const auto &p:prime){
        ll n=sqrt(p.second*2);
        if(p.second<n*(n+1)/2)--n;
        ans+=n;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define mp(a, b) make_pair(a, b)

const int adj[] = {1, 3, -1, -3};
int ch, cv;

inline void bitswap(ll &b, int i, int j, int n){
    ll x = ((b >> i) ^ (b >> j)) & ((1UL << n) - 1);
    b ^= ((x << i) | (x << j));
}

inline int zero(ll b){
    for(int k=8; ; --k, b>>=4)if(!(b & 0x0F))return k;
}

int solve(ll s, ll g){
    map<ll, int> mem;
    typedef pair<int, ll> state;
    priority_queue<state, vector<state>, greater<state> > q;
    mem[s] = 0;
    for(q.push(mp(0, s)); !q.empty();){
        state pzl = q.top(); q.pop();
        if(pzl.second == g)break;
        int cur = zero(pzl.second);
        rep(k, 4){
            int nxt = (cur + adj[k] + 9) % 9;
            int cost = pzl.first + (k & 1? cv: ch);
            bitswap(pzl.second, (8 - cur) * 4, (8 - nxt) * 4, 4);
            if(!mem.count(pzl.second) || cost < mem[pzl.second]){
                q.push(mp(cost, pzl.second));
                mem[pzl.second] = cost;
            }
            bitswap(pzl.second, (8 - cur) * 4, (8 - nxt) * 4, 4);
        }
    }
    return mem[g];
}

ll in(){
    ll k, res = 0;
    for(int i=32; i>=0; res|=k<<i, i-=4)cin >> k;
    return res;
}

int main(){
    while(cin >> ch >> cv, ch|cv)cout << solve(in(), in()) << '\n';
    return 0;
}

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

int main(){
    int H, W;
    cin >> H >> W;
    string a[500];
    for(int i = 0; i < H; i++){
        cin >> a[i];
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if((j != W-1) && (j == 0 || i % 2 == 0 || a[i][j] == '#')){
                cout << "#";
            }else{
                cout << '.';
            }
        }
        cout << endl;
    }

    cout << endl;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if((j != 0) && (j == W-1 || i % 2 == 1 || a[i][j] == '#')){
                cout << "#";
            }else{
                cout << '.';
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 1024
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> num(100001,0);
	for(int i=0;i<N;++i){
		cin >> A[i];
		num[ A[i] ]++;
	}
	int count2 = 0;//2枚残る個数
	int ans = 0;
	for(int i=1;i<=100000;++i){
		if( num[i] == 0 ) continue;
		++ans;
		if( num[i] & 1 ){
		}else{
			++count2;
		}
	}
	if( count2 & 1 ){//奇数個
		--ans;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1024
n, x, m = map(int, input().split())

num, lst = set(), []
for i in range(n):
    num.add(x), lst.append(x)
    x = x ** 2 % m
    if x in lst:
        cnt, idx = i + 1, lst.index(x)
        break

ans = sum(num)
if x in lst:
    div, mod = divmod(n - cnt, len(lst) - idx)
    ans += sum(lst[idx:]) * div
    ans += sum(lst[idx:idx + mod])
print(ans)


Measured memory_bytes: 77552
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;


struct f{
    int a;
    int b;
}a[107];

bool cmp(struct f a,struct f b)
{
    return a.a<b.a;
}
int main()
{
    int n,flag=0,t,pos;
    cin>>n>>t;
    for(int i=0;i<n;++i)
    {
        scanf("%d%d",&a[i].a,&a[i].b);
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;++i)
    {
        if(a[i].b<=t) {flag=1;pos=i;break;}
    }
    if(flag) cout<<a[pos].a<<endl;
        else cout<<"TLE"<<endl;

    return 0;
}



Measured memory_bytes: 256
def clear_maze(sx, sy, maze):

    INF = float("inf")

    field_x_length = len(maze)
    field_y_length = len(maze[0])
    distance = [[INF for i in range(field_y_length)] for j in range(field_x_length)]
    #    distance = [[None]*field_x_length]*field_y_length

    def bfs():
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()


            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if 0 <= nx and nx < field_x_length and 0 <= ny and ny < field_y_length:
                    try:
                        if maze[nx][ny] != '#' and distance[nx][ny] == INF:
                            queue.insert(0, (nx, ny))
                            distance[nx][ny] = distance[x][y] + 1
                    except Exception as e:
                        print(nx, ny)
                        print(maze)
                        print(maze[nx][ny])
                        print(distance)
                        exit()
        res = 0
        for x in range(field_x_length):
            for y in range(field_y_length):
                if distance[x][y] < float("inf"):
                    res = max(res, distance[x][y])
        return res

    return bfs()


H, W = map(int, input().split())
maze = []
for w in range(H):
    maze.append([x for x in input()])
ans = 0
for h in range(H):
    for w in range(W):
        if maze[h][w] == ".":
            sx, sy = h, w
            ans = max(clear_maze(sx,sy, maze),ans)
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

int ctoi(char c) {
  if( c >= '0' && c <= '9' ) return c-'0';
  else return -1;
}


signed main() {
  
  int N, P;
  cin >> N >> P;
  
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  
  if( P == 2 || P == 5 ){
    int ans = 0;
    for( int i = 0; i < N; i++ ){
      if( ctoi(S.at(i)) % P == 0 ) ans += N-i;
    }
    cout << ans << endl;
    return 0;
  }
  
  map<int, int> amari;
  amari[0] = 1;
  
  int now = 0;
  int keta = 1;
  for( int i = 0; i < N; i++ ){
    now += ctoi(S.at(i))*keta;
    now %= P;
    if( amari.count(now) ) amari[now]++;
    else amari[now] = 1;
    keta *= 10;
    keta %= P;
  }
  
  int ans = 0;
  for( auto p : amari ){
    ans += p.second * (p.second-1) / 2;
  }
  cout << ans << endl;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;
vector <vector <int> > adj(5);
vector <bool> vis(5,false);
void dfs(int v)
{
    vis[v]=true;

    for(int u:adj[v])
    {
        if(not vis[u])
        {
            dfs(u);
        }
    }
    for(int i=1;i<=4;i++)
    {
        if(not vis[i])
        {
            cout<< "NO";
            exit(0);
        }
    }
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int a,b,p,q,x,y;
    cin>>a>>b>>p>>q>>x>>y;


    adj[a].push_back(b);
    adj[b].push_back(a);
    adj[p].push_back(q);
    adj[q].push_back(p);
    adj[x].push_back(y);
    adj[y].push_back(x);



    int t=1;

    dfs(t);

    cout<< "YES";

    return 0;
}


Measured memory_bytes: 3616