akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int a,b;cin >> a >> b;
  rep1(i,10000){
    if(8*i/100==a&&i/10==b){
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>): Unit {

    val s = readLine()!!.trim()
    var b = s[0] == 'A'
    b = b && s.drop(2).dropLast(1).count{it == 'C'} == 1
    b = b && s.count{it.isUpperCase()} == 2
    println(
            if (b) "AC"
    else "WA"
    )
}

Measured memory_bytes: 33648
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  ll n;
  cin >> n;
  unordered_multiset<ll> gr;
  ll ans = 0;
  vl v(n);
  REP(i,n) cin >> v[i];
  sort(ALL(v));
  REP(i,n){
    ll tmp = v[v.size()-i-1];
    ll t = 1;
    bool flag = false;
    REP(j,30){
      t <<= 1;
      auto itr = gr.find(abs(tmp-t));
      if(itr!=gr.end()){
        flag = true;
        gr.erase(itr);
        ++ans;
        break;
      }
    }
    if(!flag){
      gr.insert(tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 10056
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i];
    }

    int ans = accumulate(b.begin(), b.end(), 0);
    for (int i = 0; i < n - 1; i++) {
        if ((a[i] + 1) == a[i + 1]) {
            ans += c[a[i] - 1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
const int maxn = 3005;
const int mo = 1e9 + 7;
using namespace std;
int f[2][maxn], s[maxn], Max[maxn];
int n, m;
int main(){
	scanf("%d%d", &n, &m); getchar();
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + getchar() - '0';
	for (int l, r, i = 1; i <= m; i++){
		scanf("%d%d", &l, &r);
		Max[l] = max(Max[l], r);
	}
	for (int i = 1; i <= n; i++) Max[i] = max(i, max(Max[i], Max[i - 1]));
	f[0][0] = 1; int T = 1;
	for (int i = 1; i <= n; T ^= 1, i++){
		memset(f[T], 0, sizeof f[T]);
		for (int j = 0; j <= n; j++){
			if (j + s[Max[i]] - s[Max[i - 1]] > 0) (f[T][j - 1 + s[Max[i]] - s[Max[i - 1]]] += f[T ^ 1][j]) %= mo;
			if (j + s[Max[i]] - s[Max[i - 1]] < Max[i] - (i - 1)) (f[T][j + s[Max[i]] - s[Max[i - 1]]] += f[T ^ 1][j]) %= mo;
		}
	}
	printf("%d\n", f[T ^ 1][0]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int MAX_N = 1000001;
int main(){
  
  vector<int> prime(MAX_N,1);
  prime[0]=0;prime[1]=0;
  for(int i = 2;i*i<MAX_N;i++){
    if(prime[i])
      for(int j = 2*i;j<MAX_N;j++){
	if(prime[j] && j%i == 0)prime[j] = 0;
      }
  }
  int a,n,d;
  while(cin>>a>>d>>n){
    if(!a&&!d&&!n)break;
    int ct = 0;
    REP(i,MAX_N){
      if(prime[a+(i)*d])
	ct++;
      if(ct==n){
	cout << a+(i)*d << endl;
	break;
      }
    }
  }     
  return 0;
}

Measured memory_bytes: 6616
a  = [list(map(int, input().split())) for _ in range(3)]

n = int(input())
b = [0] * n
for i in range(n):
    b[i] = int(input()) 


ans = [[0 for i in range(3)]  for j in range(3)]

for i in range(3):
    for j in range(3):
        for h in range(n):
            if a[i][j] == b[h]:
                ans[i][j] = 1

hantei = False
for i in range(3):
    if ans[i] == [1,1,1]:
        hantei = True
    if ans[0][i] == 1 and ans[1][i] == 1 and ans[2][i] == 1:
        hantei = True

if ans[0][0] == 1 and ans[1][1] == 1 and ans[2][2] == 1:
    hantei = True

if ans[0][2] == 1 and ans[1][1] == 1 and ans[2][0] == 1:
    hantei = True

if hantei:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var vv = num / 2;
            var xx = int.MaxValue;
            for (int i = 1; i <= vv+1; i++)
            {
                var st1 = i.ToString().Sum(x => int.Parse(x.ToString()));
                var st2 = (num - i).ToString().Sum(x => int.Parse(x.ToString()));
                var ss = st1 + st2;
                if (ss < xx)
                    xx = ss;
            }
            Console.WriteLine(xx);
            Console.ReadLine();
        }


    }
}



Measured memory_bytes: 15428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; 
#define ll long long  
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define mp make_pair
#define endl "\n"
#define forn(i,n) for(int i = 0; i < int(n); ++i)
#define forni(i,a,b) for(int i=int(a) ; i<=int(b) ; ++i)
#define sz(z) (int)z.size()
#define lb lower_bound
#define ub upper_bound 
#define dbg cout << "yo" << endl  
#define N (ll)5e5+10
#define M (ll)2e6+10 

typedef pair<ll,ll> pll ;
typedef vector<pair<ll,ll>> vpll ;
typedef vector<ll> vll ;
typedef vector<char> vch ;
typedef vector<bool> vbl ;


int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    
    
   int n ;
   cin >> n ;
   int a[n] , b[n] ;
   forn(i,n){
    cin >> a[i] >> b[i] ;
   }
   bool ok=0 ;
   forn(i,n){
    int cnt=0 ;
    forn(j,3){
        if(i+j>=n)break ;
        if(a[i+j]==b[i+j])cnt++ ;
    }
    if(cnt==3)ok=1 ;
   }
   if(ok)cout << "Yes" ;
   else cout << "No" ;

    return 0 ;
    
}



Measured memory_bytes: 3648
'use strict';
console.log(function(args){
  const tmp = args.trim().split('\n').map(a=>a.split(' ').map(v=>v|0));
  const N = tmp[0][0], M = tmp[0][1];
  const p = tmp[M+1];
  const k = Array(M),s = Array(M);
  let count = 0;
  for ( let i = 1; i <= M; i++ ) {
    k[i-1] = tmp[i][0];
    s[i-1] = tmp[i].slice(1).map(v=>v-1);
  }
  TEST: for ( let state = 0; state < 1<<N; state++ ) {
    for ( let i = 0; i < M; i++ ) {
      let bulb = !p[i];
      for ( let j = 0; j < k[i]; j++ ) {
        if ( state & (1 << s[i][j] ) ) {
          bulb^=1;
        }
      }
      if ( !bulb ) continue TEST;
    }
    count++;
  }
  return count.toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 7372
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define INF 1000000001;

int main() {
  int n,m;
  cin >> n >> m;
  long long ans = 0;

  ans = 1900*m + 100*(n-m);

  for(int i = 0; i < m; i++){
    ans *= 2; 
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
  
using namespace std;
  
struct Node{
  int key;
  Node* next;
  Node* prev;
};
  
struct List{
  Node* nil;
  
  void init(){
    nil=(Node*)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
    nil->key=0;
  }
  
  Node* find(int key){
    for(Node* i=nil->next;i!=nil;i=i->next){
      if(i->key==key)return i;
    }
    return nil;
  }
  
  void insert(Node *x){
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
  }
   
  void add(int x){
    Node* p = (Node*)malloc(sizeof(Node));
    p->key=x;
    insert(p);
  }
    
  void delete_x(int key){
    Node* x=find(key);
    if(x==nil)return;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  }
    
  void deleteFirst(){
    Node* x = nil->next;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  }
    
  void deleteLast(){
    Node* x = nil->prev;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);   
  }
  
  void output(){
    int flg=0;
    for(Node* i=nil->next;i!=nil;i=i->next){
      if(flg)cout<<' ';
      cout<<i->key;
      flg=1;
    }
    cout<<endl;
  }
};
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  List list;
  list.init();
  int n,x;
  string str;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    if(str=="insert"){
      cin>>x;
      list.add(x);
    }else if(str=="delete"){
      cin>>x;
      list.delete_x(x);
    }else if(str=="deleteFirst"){
      list.deleteFirst();
    }else {
      list.deleteLast();
    }
  }
  //cout<<'-'<<endl;
  list.output();
}


Measured memory_bytes: 34264
#include <bits/stdc++.h>
#define M 1e9+7
using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	long long int a[n];
	for (int i=0;i<n;i++) scanf("%lld",&a[i]);
	long long int sum = 0;
	for (int i=0;i<n-1;i++){
		sum+=a[i]/2;
		a[i]%=2;
		if (a[i] && a[i+1]){
			sum++;
			a[i] = 0;
			a[i+1]--;
		}
	}
	sum+=a[n-1]/2;
	cout << sum;
	return 0;
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    ll ans = 0;

    for (ll i = 1; i < s.size(); i++){
        if (s[i-1] == s[i]){
            continue;
        }
        else{
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3776
#include <iostream>

 using namespace std;
 typedef long long ll;

 int main(void){
 ll H,W;
 cin >> H >> W;

 if(H == 1 || W == 1){
 cout << 1 << endl;
 } else {
 cout << (H * W + 1) / 2 << endl;
 }

 return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define MAX_V 100005

using namespace std;
// first-> dst, second-> cost
typedef pair<int, int> Edge;

vector<Edge> tree[MAX_V];
int ans[MAX_V];

void dfs(int cur_v, int par_v, int color) {
  ans[cur_v] = color;
  for (int i = 0; i < tree[cur_v].size(); i++) {
    Edge e = tree[cur_v][i];
    if ( e.first == par_v ) { continue; }
    if ( e.second & 1 ) {
      dfs(e.first, cur_v, 1-color);
    } else {
      dfs(e.first, cur_v, color);
    }
  }
}

int main() {
  int n; cin >> n;

  for (int i = 0; i < n-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    tree[u].push_back( make_pair(v, w) );
    tree[v].push_back( make_pair(u, w) );
  }
  
  dfs(0, -1, 0);

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 9984
S = input()

head = S[0] + S[1]
tail = S[2] + S[3]

is_head_month = False
is_tail_month = False

if (int(head) <= 12 and int(head) != 0) :
    is_head_month = True

if (int(tail) <= 12 and int(tail) != 0) :
    is_tail_month = True

if (is_head_month == True and is_tail_month == True) :
    print("AMBIGUOUS")
elif (is_head_month == True and is_tail_month == False) :
    print("MMYY")
elif (is_head_month == False and is_tail_month == True) :
    print("YYMM")
else :
    print("NA")

Measured memory_bytes: 3064
/*
a matrix is given  with a[i][j] - compatibility of men i with women j
only compatibles pairs are valid 

find total number of ways to pair up all the men and women
no man and woman are part of more than 1 pair
*/

#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
using namespace std::chrono;
long long int p=1e9 +7;
int n;

bool compatibility[21][21];
ll dp[21][1ll << 21];               //dp[i][j] represents i people left and
                                    //j is the bitmask for women left

ll solve(int N,int left){
    ll curr=0;                       //initialise with 0
    
    if(dp[N-1][left]!=-1){             //check if we have already found the dpwer
        return dp[N-1][left];
    }

    if(N==1) {
        for(int j=0;j<n;j++){
            int x=1<<j;                         // bit fo jth woman
            if(left & x){                       //check if the jth women is left
                if(compatibility[N-1][j]){ 
                    dp[N-1][left]=1;
                    return 1;                   //If they are compatible return 1, as only 1 of the n women will be available
                }
                else{
                    dp[N-1][left]=0;
                    return 0;                   //If the last 2 aren't compatible return 0
                }
            }
        }
    }

    for(int i=0;i<n;i++) {
        
        if(left & (1ll<<i)){                            //If the ith women is left - available for pairing 
            
            if(compatibility[N-1][i])   {               //If the 2 are compatible
                curr += solve(N-1, left - (1ll << i));  // now the ith women is unavailble so unset the bit in left  
            }
        }
    }

    curr%=p;
    dp[N-1][left] = curr;
    
    return dp[N-1][left];
}


ll solve(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1ll<<n);j++){
            dp[i][j]= -1;                      //memoisation initialisation
        }
    }

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

    return solve(n,(1<<n)-1);                   // all men available, 
                                                // all women available because all bits set in mask
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout<<solve()<<"\n";
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

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

const ull mod = (ull)1e9 + 7;

int main(void)
{
	char c;
	cin >> c;
	cout << (char)(c + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
from math import sqrt
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

xs, ys, xt, yt = map(int, input().split())
n = int(input())
xyr = [list(map(int, input().split())) for _ in range(n)]

xyr.append([xs, ys, 0])
xyr.append([xt, yt, 0])

row = []
col = []
cost = []

for i, (xi, yi, ri) in enumerate(xyr):
    for j, (xj, yj, rj) in enumerate(xyr[i+1:], i+1):
        row.append(i)
        col.append(j)
        dist = max(0, sqrt((xi - xj) ** 2 + (yi - yj) ** 2) - ri - rj)
        cost.append(dist)

g = csr_matrix((cost, (row, col)), shape=(n + 2, n + 2))
d = dijkstra(g, directed=False, indices=n)
ans = d[n+1]
print(ans)


Measured memory_bytes: 69076
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
int n, h,w;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>h>>w;
    cout<<(n-h+1)*(n-w+1)<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int X,K,D;
  cin>>X>>K>>D;
  if(abs(X)*1.0/D>=K)cout<<abs(X)-D*K<<endl;
  else if((abs(X)/D-K)%2==0)cout<<abs(X)%D<<endl;
  else cout<<D-abs(X)%D<<endl;
}

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

#define MAX 1010
#define INF (1<<30)

double costSum[MAX][MAX],optCost[MAX][MAX];

//{{{ Functions
void ComputeOptCost(int i, int j){
	optCost[i][j]=INF;
	for(int k=i; k<=j; k++){
		optCost[i][j]=min(optCost[i][k-1]+optCost[k+1][j], optCost[i][j]);
	}
	optCost[i][j]+=costSum[i][j];
}
//}}}

int main(){
	int n;	cin>>n;
	vector<double> P(n+1),Q(n+1);
	for(int i=1;i<=n;i++)cin>>P[i];
	for(int i=0;i<=n;i++)cin>>Q[i];

	/*
		costSum[i][j]:
			(i: 1,2,~,n)

		(j==i-1) Q[i-1]
		(else) costSum[i][j-1]+ P[j]+Q[j]
	*/

	//costSum の初期化
	for(int i=1; i<=n; i++){
		costSum[i][i-1]=Q[i-1];
		for(int j=i; j<=n; j++){
			costSum[i][j]=costSum[i][j-1] + P[j]+Q[j];
		}
	}

	for(int i=1;i<=n+1;i++)optCost[i][i-1]=Q[i-1];
	for(int d=0; d<=n-1; d++){
		for(int i=1;i<=n-d;i++){
			ComputeOptCost(i,i+d);
		}
	}
	//cout<<optCost[1][1]<<endl;
	//cout<<optCost[1][n]<<endl;
	printf("%.8lf\n",optCost[1][n]);

	return 0;
}



Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int l;
    l = s.size();
    int a_place, z_place;
    for (int i = 0; i < l; i++){
        if (s[i] == 'A'){
            a_place = i;
            break;
        }
    }
    for (int k = l-1; k > -1; k--){
        if (s[k] == 'Z'){
            z_place = k;
            break;
        }
    }
    cout << z_place - a_place + 1 << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;
 
const int maxn=2e5+5,pps=1e9+7;
 
bool vis[maxn];
int n,x,y,tot,ans=1,top;
int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];
 
int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}
 
struct Ball {
	int c,w,id;
}b[maxn];
 
int quick(int a,int b) {
	int sum=1;
	while(b) {
		if(b&1)sum=1ll*sum*a%pps;
		a=1ll*a*a%pps,b>>=1;
	}
	return sum;
}
 
bool cmp1(Ball a,Ball b) {
	if(a.c==b.c)return a.w<b.w;
	return a.c<b.c;
}
 
bool cmp2(Ball a,Ball b) {
	if(a.w==b.w)return a.c<b.c;
	return a.w<b.w;
}
 
void add(int a,int b) {
	pre[++tot]=now[a];
	now[a]=tot,son[tot]=b;
}
 
void work1() {
	int lst=0;
	for(int i=1;i<=n;i++) {
		if(b[i].c!=b[lst].c) {
			lst=i;continue;
		}
		if(b[i].w+b[lst].w<=x) {
			add(b[i].id,b[lst].id);
			add(b[lst].id,b[i].id);
		}
	}
}
 
void work2() {
	int fake;b[n+1].w=1e9;
	for(fake=2;fake<=n;fake++)
		if(b[fake].c!=b[1].c)break;
	for(int i=2;i<=n;i++)
		if(b[i].c!=b[1].c) {
			if(b[i].w+b[1].w>y)break;
			add(b[i].id,b[1].id);
			add(b[1].id,b[i].id);
		}
		else if(b[i].w+b[fake].w<=y) {
			add(b[i].id,b[fake].id);
			add(b[fake].id,b[i].id);
		}
}
 
void prepare() {
	fac[0]=inv[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%pps;
	inv[n]=quick(fac[n],pps-2);
	for(int i=n-1;i;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%pps;
}
 
void dfs(int u) {
	vis[u]=1;
	int c=color[u];
	if(!insta[c]) {
		sta[++top]=c;
		insta[c]=top;
		sum[top]=1;
	}
	else sum[insta[c]]++;
	for(int p=now[u],v=son[p];p;p=pre[p],v=son[p])
		if(!vis[v])dfs(v);
}
 
void calc() {
	int cnt=0;
	while(top) {
		ans=1ll*ans*inv[sum[top]]%pps;
		cnt+=sum[top],insta[sta[top]]=0,sta[top]=0,sum[top]=0,top--;
	}
	ans=1ll*ans*fac[cnt]%pps;
}
 
int main() {
	n=read(),x=read(),y=read(),prepare();
	for(int i=1;i<=n;i++)
		color[i]=b[i].c=read(),b[i].w=read(),b[i].id=i;
	sort(b+1,b+n+1,cmp1);work1();
	sort(b+1,b+n+1,cmp2);work2();
	for(int i=1;i<=n;i++)
		if(!vis[i])dfs(i),calc();
	printf("%d\n",ans);
	return 0;
}


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

int N, A[100];

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

	long long result = 0;
	for (int i = 0; i < N; i ++){
		for (int j = i + 1; j < N; j ++){
			for (int k = j + 1; k < N; k ++){
				if (A[i] + A[j] > A[k]){
					if (A[j] + A[k] > A[i]){
						if (A[i] + A[k] > A[j]){
							if (A[i] != A[j] && A[j] != A[k] && A[i] != A[k]){
								result ++;
							}

							// cout << A[i] << " " << A[j] << A[k] << "\n";

						}
					}
				}
			}
		}
	}
	cout << result << "\n";
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  char s[100010];
  int c[26];
  scanf("%s",s);
  int l=strlen(s);
  for(int i=0;i<26;i++){
    c[i]=0;
  }
  for(int i=0;i<l;i++){
    c[s[i]-'a']++;
  }
  for(int i=0;i<26;i++){
    if(c[i]==0){
      printf("%c\n",i+97);
      return 0;
    }
    if(i==25 && s[i]!=0){
      printf("None\n");
      return 0;
    }
  }
}

Measured memory_bytes: 1772
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
  ll N=0; cin>>N;
  vector<ll> A(N,0),B(N,0),C(N,0);
  for(ll i=0;i<N;i++) cin>>A[i];
  for(ll i=0;i<N;i++) cin>>B[i];
  for(ll i=0;i<N;i++) cin>>C[i];

  sort(A.begin(),A.end()); sort(C.begin(),C.end());

  ll ans=0;

  for(ll i=0;i<N;i++){
    ll a=lower_bound(A.begin(),A.end(),B[i])-A.begin();
    ll c=N-(upper_bound(C.begin(),C.end(),B[i])-C.begin());
    ans+=a*c;
  }

  cout<<ans<<endl;

  return 0;
}


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

int main() {

    map<string, int> mp;

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

    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        string t; cin >> t;
        mp[t]--;
    }

    int ans = 0;
    for (auto it : mp) {
        ans = max(ans, it.second);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);

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

	int min = INT_MAX;
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (min > p[i]) {
			min = p[i];
			res++;
		}
	}

    cout << res << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define reg register
#define maxn 200001
using namespace std;
int nt[maxn << 1], fi[maxn], go[maxn], d[maxn], rt;
int dp[maxn], n, sum, sumx, siz[maxn], ans, cnt;
char s[maxn];
vector<int> Q[maxn];
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
void add(int u, int v){
	nt[++cnt] = fi[u]; fi[u] = cnt; go[cnt] = v;
}
void dfs(int u, int fa){
	siz[u] = (s[u] == 'W'); 
	for(int i = fi[u]; i; i = nt[i]){
		int v = go[i]; if(v == fa) continue;
		dfs(v, u); siz[u] += siz[v];
		if(siz[v] != ans && siz[v] != 0){
			Q[u].push_back(v); Q[v].push_back(u);
		}
	}
}
void find(int x, int fa){
	sum += 2;  d[x] = 0;
	if(s[x] == 'W' && Q[x].size() % 2 == 0) sum += 1, d[x] = 2;
	if(s[x] == 'B' && Q[x].size() % 2 == 1) sum += 1, d[x] = 2;
	for(int i = 0; i < Q[x].size(); i++){
		int v = Q[x][i]; if(v == fa) continue;
		find(v, x);
	}
}
void solve(int x, int fa){
	dp[x] = d[x]; int maxx = 0, cmaxx = 0;
	for(int i = 0; i < Q[x].size(); i++){
		int v = Q[x][i]; if(v == fa) continue;
		solve(v, x); 
		if(dp[v] > maxx) cmaxx = maxx, maxx = dp[v];
		else if(dp[v] > cmaxx) cmaxx = dp[v];
		
	}
	sumx = max(sumx, maxx + cmaxx + d[x]);
	dp[x] += maxx;
}
int main()
{
	n = read();
	for(int i = 1; i < n; i++){
		int x = read(), y = read();
		add(x, y); add(y, x);
	}
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) {
		ans += ((s[i] == 'W') ? 1 : 0);
		if(s[i] == 'W') rt = i;
	}
	if(ans == 0) {puts("0\n"); return 0;}
	if(ans == 1) {printf("1\n"); return 0;}
	dfs(1, 0);  find(rt, 0);
	sum = sum - 2; 	solve(rt, 0);
	cout << sum - sumx << endl;
	return 0;
}

Measured memory_bytes: 21376
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n, k;

void Input() {
	cin >> n >> k;
}

void Solve() {
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	vll b(n, inf);
	b[0] = 0;
	for (ll i = 1; i < n; i++) {
		ll K = k, j = i - 1;
		while (K and j >= 0) {
			b[i] = min(abs(a[i] - a[j]) + b[j], b[i]);
			j--, K--;
		}
	}
	cout << b[n - 1];

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

Measured memory_bytes: 4784
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  long long  n;
  long long retval = 0;
  if(scanf("%lld",&n)<1){
    exit(1);
  }
  long long a[n];
  long long b[n+1];
  b[0] = 0;
  for(int i = 0; i<n;i++){
    if(scanf("%lld",&a[i])<1){
      exit(1);
    }
    b[i+1] = b[i] + a[i];
  }
  for(int i = 0; i<n;i++){
    retval += (a[i]%1000000007)*((b[n]-b[i+1])%1000000007);
    retval %= 1000000007;
  }
  printf("%lld",retval);
  return 0;
}

Measured memory_bytes: 4856
#include<iostream>
#define ll long long int
using namespace std;
ll a,b,k;
ll max(ll a, ll b){
	return (a < b ) ? b : a;
}
int main(){
	cin>>a>>b>>k;
	cout<<max(a-k,0)<<" "<<max(b-(max(k-a,0)),0)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, p;
signed main() {
	cin >> n >> p;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		ans += max(0, k - p);
	}
	if (!ans)cout << "kusoge\n";
	else cout << ans << endl;
}


Measured memory_bytes: 3112
# Vector class
class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def is_orthogonal(self, v):
        if self.x * v.x + self.y * v.y == 0:
            return True
        else:
            return False
    def is_parallel(self, v):
        if self.x * v.y - self.y * v.x == 0:
            return True
        else:
            return False

# Acceptance of input and judge

import sys

file_input = sys.stdin

q = map(int, file_input.readline().split())

for line in file_input:
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())
    s1 = Vector(x_p1 - x_p0, y_p1 - y_p0)
    s2 = Vector(x_p3 - x_p2, y_p3 - y_p2)
    if s1.is_parallel(s2):
        print(2)
    elif s1.is_orthogonal(s2):
        print(1)
    else:
        print(0)

Measured memory_bytes: 7744
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin >> s >> t;
	int n = s.size();
	//各アルファベットについて、出現した場所を保存しておく
	vector<vector<int>> spos(26),tpos(26);
	for(int i=0;i<n;i++){
		int snum = s[i] - 'a';
		int tnum = t[i] - 'a';
		spos[snum].push_back(i);
		tpos[tnum].push_back(i);
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<spos[i].size();j++){
			int sfirst = spos[i][0];
			if(t[sfirst]!=t[spos[i][j]]){
				cout << "No" << endl;
				return 0;
			}
		}
		for(int j=0;j<tpos[i].size();j++){
			int tfirst = tpos[i][0];
			if(s[tfirst]!=s[tpos[i][j]]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3092
#include <stdio.h>
int main()
{
    int a,b,c,d,e,n,m=0;
    scanf("%d%d",&a,&b);
    if(b%2==0&&a*4>=b&&a*2<=b){

        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1592
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){  
  int n;
  cin >> n;
  int a[100000] = { };
  REP(i, n){
    int x;
    cin >> x;
    a[x-1]++;
  }
  int d = 0;
  REP(i, 100000){
    if(a[i] > 1) d += a[i]-1;
  }
  cout << n-(((d+1)/2)*2) << endl;
	return 0;
}

Measured memory_bytes: 640
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    ll N;
    ll A[5];
    cin >> N;
    REP(i, 5)
    {
        cin >> A[i];
    }

    int index = 0;
    REP(i, 5)
    {
        if (A[index] > A[i])
            index = i;
    }
    ll ret = N / A[index];
    if (N % A[index] != 0)
        ret++;

    cout << (ret + 4) << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
  io;
  string s,t;
  ll i,found,ans=INT_MAX,j,n;
  cin>>s;
  cin>>t;
  n=s.size();
  // cout<<n<<endl;
  for(i=0;n-i>=t.size();i++)
  {
    // cout<<i<<endl;
    ll k=0;
    ll temp=0;
    ll size=t.size();
    j=i;
    while(size--)
    {
      if(s[j]!=t[k])
      temp++;

      k++;
      j++;
    }
    if(temp<ans)
    ans=temp;

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


Measured memory_bytes: 3572
#include <bits/stdc++.h>
 
typedef long long ll;

using namespace std;
using Graph = vector<vector<int>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000


void Main() {
    int n, k, d, a, ans;

    cin >> n >> k;
    vector<int> count(n, 0);

    REP(i, k) {
        cin >> d;
        REP(j, d) {
            cin >> a;
            count[a - 1] += 1;
        }
    }

    ans = 0;
    REP(i, n) {
        if (count[i] == 0) {
            ans += 1;
        }
    }

    COUT(ans)
}
 
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N;
	cin >> N;
	map<string,int> m;
	rep(i,N){
		string s;
		cin >> s;
		m[s]++;
	}
	cout << m.size() << endl;

	return 0;
}

Measured memory_bytes: 19136
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int dp[3500], n, t;
pii a[N];
void solve () {
	cin >> n >> t;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].F >> a[i].S;
	}
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= t; i ++) {
		dp[i] = -1;
	}        
	dp[0] = 0;
	for (int i = 1; i <= n; i ++) {
		for (int j = t - 1; j >= 0; j --) {
			 if (dp[j] != -1) {
			 	dp[min (j + a[i].F, t)] = max (dp[min (j + a[i].F, t)], dp[j] + a[i].S);
			 }
		}
	}
	int maxi = 0;
	for (int i = 0; i <= t; i ++) {
		maxi = max (maxi, dp[i]);	
	}
	cout << maxi;

}                               	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//	cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 256
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {
  StdIn.readLine()
  val l = StdIn.readLine()
  var size = 0
  for (i <- l.indices){
    if(i == 0 || l(i) != l(i-1)) size += 1
  }
  println(size)
}


Measured memory_bytes: 27256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N, K, R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;

	auto score = [&](char x) {
		if (x == 'r') {
			return P;
		}
		else if (x == 's') {
			return R;
		}
		else {
			return S;
		}
	};

	long long ans = 0;

	for (int i = 0; i < K; ++i) {
		char x = '?';
		for (int j = i; j < N; j += K) {
			if (T[j] != x) {
				ans += score(T[j]);
				x = T[j];
			}
			else {
				x = '?';
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 512
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    if (i+1)%2==1 and a[i]%2==1:
        ans += 1
print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    if (n < 2)
        cout << 0 << endl;
    else
        cout << (n * (n - 1)) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
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;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll rui[ohara], dp[ohara][15];

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

  cin >> s;
  reverse(all(s));
  rui[0] = 1;
  rrep(i, 1, ohara) { rui[i] = (rui[i - 1] * 10) % 13; }
  if (s[0] == '?') {
    rep(i, 10) { dp[0][i] = 1; }
  } else
    dp[0][(s[0] - '0')] = 1;

  rep(i, Size(s) - 1) {
    rep(j, 13) {
      ll nex;
      if (s[i + 1] != '?') {
        tmp = s[i + 1] - '0';
        (nex = tmp * rui[i + 1] + j) %= 13;
        (dp[i + 1][nex] += dp[i][j]) %= MOD;
      } else {
        rep(k, 10) {
          tmp = k;
          (nex = tmp * rui[i + 1] + j) %= 13;
          (dp[i + 1][nex] += dp[i][j]) %= MOD;
        }
      }
    }
  }

  Cout(dp[Size(s) - 1][5]);
  return 0;
}

Measured memory_bytes: 21072
#include <stdio.h>
#include <string.h>
int main(void)
{
   int L,i,f;
   char s[100];
  
   scanf("%s",s);
   L=strlen(s);
   
   f=0;
   for(i=0;i<(L/2);i++)
     if(s[i]!=s[L-i-1]) f++;
  
   printf("%d",f); 
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<stdlib.h>

void listen_price(std::map<std::string,int> &);
void listen_recipe(std::map<std::string,std::vector<std::string> > &);
void listen_choicedItem(std::string &);
void echo_bestPrice(std::string &,std::map<std::string,int> &,std::map<std::string,std::vector<std::string> >&);
int  calc_bestPrice(std::string &,std::map<std::string,int> &,std::map<std::string,std::vector<std::string> >&);

void wroughtGoldMaster();

//-------------------main------------------------------

int main()
{
	for(;1;)
	{
		wroughtGoldMaster();//終了処理は関数内のexitで行われる
	}
	return 0;
}
void wroughtGoldMaster()
{
	std::map<std::string,int> price;
	listen_price(price);
	
	std::map<std::string,std::vector<std::string> > recipe;//本来はmultimapを使うべきかもしれないが練習のため
	listen_recipe(recipe);
	
	std::string choicedItem;
	listen_choicedItem(choicedItem);
	echo_bestPrice(choicedItem,price,recipe);
}

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

void listen_price(std::map<std::string,int> &price)
{
	using namespace std;
	
	int kind_num;
	cin>>kind_num;
	if(!kind_num)
	{
		exit(0);//入力の終わり
	}
	
	string tmp_string;
	int tmp_value;
	for(int roop=0;roop<kind_num;roop++)
	{
		cin>>tmp_string>>tmp_value;
		price[tmp_string]=tmp_value;
	}
}

void listen_recipe(std::map<std::string,std::vector<std::string> >&recipe)
{
	using namespace std;
	int kind_num;
	cin>>kind_num;
	
	string tmp_string;
	string tmp_string_forItem;
	int itemCount_num;
	for(int roop=0;roop<kind_num;roop++)
	{
		cin>>tmp_string>>itemCount_num;
		for(int itemroop=0;itemroop<itemCount_num;itemroop++)
		{
			cin>>tmp_string_forItem;
			recipe[tmp_string].push_back(tmp_string_forItem);
		}
	}
}

void listen_choicedItem(std::string &choicedItem)
{
	using namespace std;
	
	cin>>choicedItem;
}

void echo_bestPrice(std::string &choicedItem,std::map<std::string,int> &price,std::map<std::string,std::vector<std::string> >&recipe)
{
	using namespace std;
	
	cout<<calc_bestPrice(choicedItem,price,recipe)<<endl;//calc_bestPrice:再帰的にレシピを探索して各品目の最安コストを探索するための関数
}

int calc_bestPrice(std::string &item,std::map<std::string,int> &price,std::map<std::string,std::vector<std::string> >&recipe)
{
	using namespace std;
	
	vector<string>::iterator itr;
	int sum_compCost;
	if(recipe.find(item)==recipe.end())
	{
		return price[item];
	}
	else
	{
		sum_compCost=0;
		for(itr=recipe[item].begin();itr<recipe[item].end();++itr)
		{
			sum_compCost+=calc_bestPrice(*itr,price,recipe);
		}
	}
	
	if(sum_compCost<price[item])
	{
		return sum_compCost;
	}
	else
	{
		return price[item];
	}
}

Measured memory_bytes: 1232
import static java.lang.System.out;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int alphaAns = 0;
        int betaAns = 0;
        for (int i = 0; i < num; i++) {
            String alpha = scan.next();
            String beta = scan.next();
            if (alpha.compareTo(beta) == 0) {
                alphaAns++;
                betaAns++;
            } else if (alpha.compareTo(beta) > 0) {                    
                alphaAns += 3;
            } else {
                betaAns += 3;
            }
        }
        out.printf("%d %d\n", alphaAns, betaAns);
    }
}

Measured memory_bytes: 29716
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n; cin >> n;
    int W; cin >> W;
    int v[n], w[n];
    rep(i,n)cin >> v[i] >> w[i];

    int dp[W+1] = {};


    rep(i,n){
        rep(j,W+1){
            if(w[i] <= j){
                dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
            }
        }
    }

    cout << dp[W] << endl;
    
    return 0;
}
 
 



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

w = sum(A)//2
for i in range(1,N-1,2):
  w -= A[i]
W = [0]*N
W[0] = w
for i in range(1,N):
  W[i] = A[i-1]-W[i-1]
W = [2*w for w in W]
print(*W)

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

int pos[100005], neg[100005];
vector< pair<int, int> > X;

int main()
{
    ios::sync_with_stdio(0);
    
    int N;
    cin >> N;

    int k1 = 0, k2 = 0;

    for(int i=1; i<=N; i++)
    {
        int x;
        cin >> x;

        if(x >= 0)
            pos[++k1] = x;
        else
            neg[++k2] = -x;
    }

    long long ans = 0;
    sort(pos+1, pos+1+k1);
    sort(neg+1, neg+1+k2);

    if(k1 == 0)
    {
        ans = -neg[1];

        for(int i=2; i<=k2; i++)
        {
            X.push_back({ans, -neg[i]});
            ans += neg[i];
        }
    }
    else
    {
        int ptr1 = 1, ptr2 = 1;
        ans = (k2 == 0 ? pos[ptr1++] : -neg[ptr2++]);

        while(ptr1 < k1)
        {
            X.push_back({ans, pos[ptr1]});
            ans -= pos[ptr1++];
        }

        if(ptr1 == k1)
        {
            X.push_back({pos[ptr1], ans});
            ans = pos[ptr1] - ans;
        }

        while(ptr2 <= k2)
        {
            X.push_back({ans, -neg[ptr2]});
            ans += neg[ptr2++];
        }
    }

    cout << ans << "\n";
    
    for(auto x : X)
        cout << x.first << " " << x.second << "\n";

    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int siz,he[N],e,edg,col[N];
bool vis[N],flag;
struct sa{
	int ne,va,to;
} a[N];
long long ans=0,cot[3];
void add(int u,int v,int w){
	a[++e].to=v;
	a[e].va=w;
	a[e].ne=he[u];
	he[u]=e;
}
void dfs(int k){
	cot[col[k]]++;
	vis[k]=1;
	
	for(int i=he[k];i;i=a[i].ne){
		edg+=(a[i].va==1);
		int v=a[i].to;
		int rec=(3+col[k]+a[i].va)%3;
		if(!vis[v]){
		    siz++;
		    col[v]=rec;
		    dfs(v);
	    }
	    else if(col[v]!=rec) flag=0;
	}
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		add(u,v,1);
		add(v,u,-1);
	}
	for(int i=1;i<=n;i++) if(!vis[i]){
		edg=cot[1]=cot[0]=cot[2]=0;
		siz=flag=1;
		dfs(i);
		if(!flag) ans+=(long long)siz*siz;
		else if(cot[0]&&cot[1]&&cot[2]) ans+=(long long) cot[0]*cot[1]+(long long) cot[0]*cot[2]+(long long) cot[1]*cot[2]; 
		else ans+=edg;
	}
	cout<<ans<<endl;
}

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

int main(){
  
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int sum = 0;
  for(int i = 0; i < N; i++) {
    if (i % 2 == 0) sum += a[N - 1 - i];
    if (i % 2 == 1) sum -= a[N - 1 - i];
  }
  cout << sum;
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		int length=0;
		int[] store;
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null ) {
            	length=Integer.parseInt(line);
            	String[] str=br.readLine().split(" ");
            	if(length==2){
            		store=new int[2];
            		for(int i=0;i<str.length;i++){
            			store[i]=Integer.parseInt(str[i]);
            		}
            		for(int i=1;i<Integer.min(store[0],store[1])+1;i++){
            			if(store[0]%i==0 && store[1]%i==0){
            				System.out.println(i);
            			}
            		}
            	}else{
            		store=new int[3];
            		for(int i=0;i<str.length;i++){
            			store[i]=Integer.parseInt(str[i]);
            		}
            		int min=Integer.min(Integer.min(store[0],store[1]),Integer.min(store[2],store[1]));
            		for(int i=1;i<min+1;i++){
            			if(store[0]%i==0 && store[1]%i==0 && store[2]%i==0){
            				System.out.println(i);
            			}
            		}
            	}

            	break;
            }
		}
	}

}

Measured memory_bytes: 25644