akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long int LLI;

void solution(LLI n, LLI y)
{
	int diff = y - n;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= n-i; j++)
			if( y - n == 9*i + 4*j )
			{
				cout << i << " " << j << " " << n-i-j;
				return;
			}
	cout << "-1 -1 -1";
}

int main()
{
	LLI n, y;
	cin >> n >> y;
	y /= 1000;
	solution(n,y);
}

Measured memory_bytes: 3616
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const C = parseInt(arg[0].split(" ")[1]);
    const K = parseInt(arg[0].split(" ")[2]);
    
    const T = arg.slice(1, N + 1).map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    let peopleNowRiding = [];
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        peopleNowRiding.push(T[i]);

        for(let j=parseInt(i)+1; j<=parseInt(i)+C; j++) {
            if(peopleNowRiding.length < C && T[j] - T[i] <= K) {
                peopleNowRiding.push(T[j]);
            } else {                
                i = j - 1;
                answer++;
                
                peopleNowRiding = [];
                break;
            }
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
	int x;
	cin >> x;
	set<int> s;
	for(int i = 2; i< 33; i++){
		for(int j=2; j<11; j++){
			int result = pow(i,j);
			if (result <= 1000) s.insert(result);
			else break;
		}
	}
	s.insert(1);
	for(int i = x; i>=1; i--){
		if (s.count(i)) {cout << i; return 0;}
	}
	
 }


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _160abc
{
    class Program
    {
        static void Main(string[] args)
        {    
            int[] read = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int N = read[0];
            int X = read[1]-1;
            int Y = read[2]-1;
            int[] res = new int[N];
            for(int i = 0; i < N ;i++){
                for(int j = i+1; j < N;j++){
                    var dist = j-i;
                    dist = Math.Min(dist,Math.Abs(i-X)+1+Math.Abs(j-Y));
                    res[dist]++;
                }
            }
            Console.WriteLine(string.Join("\n",res.Skip(1)));
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int MAX = 501;
int SIZE=(1<<30);

int main(){

  int n, i, j, num, sum, A[MAX][MAX], x, y, min, d[MAX], p[MAX], s[MAX];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){

    for ( j = 0; j < n; j++ ){

      scanf("%d", &num);

      A[i][j] = (num==-1)?SIZE:num;

    }
  }

  for ( i = 0; i < n; i++ ) {

    d[i] = SIZE;
    p[i] = -1;
    s[i] = 0;

  }

  d[0] = 0;

  while(1){

    min = MAX;
    x = -1;

    for ( i = 0; i < n; i++ )
      {
	if ( min > d[i] && ! s[i] )
	  {
	    x = i;
	    min = d[i];
	  }
      }
    if ( x == -1 ) break;
    s[x] = 1;

    for ( y = 0; y < n; y++ )
      {
	if ( !s[y] && A[x][y] != MAX )
	  {
	    if ( d[y] > A[x][y] )
	      {
		d[y] =  A[x][y];
		p[y] = x;
	      }
	  }
      }
  }

  sum = 0;

  for ( i = 0; i < n; i++ )
    {
      if ( p[i] != -1 ) sum += A[i][p[i]];
    }

  printf("%d\n", sum);

  return 0;
}

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

int main(){
    int x;
    int h[3];
    for(int a=0;a<10;a++){
        cin >> x;
        if(x>h[0]){
            h[2] = h[1];
            h[1] = h[0];
            h[0] = x;
        }else if(x>h[1]){
            h[2] = h[1];
            h[1] = x;
        }else if(x>h[2]){
            h[2] = x;
        }
    }
    cout << h[0] << "\n" << h[1] << "\n" << h[2] << "\n";
    return 0;
}

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

int main() {
  int K,A,B,flag = 0;
  cin >> K >> A >> B;
  
  for(int i = A;i <= B;i++){
    if(i % K == 0){
      cout << "OK" << endl;
      flag = 1;
      break;
    }
  }
  if(flag != 1){
    cout << "NG" << endl;
  }
  
}


Measured memory_bytes: 3632
import heapq
from sys import stdin

N,K = map(int,input().split())

sushi = {}

for i in range(N):
    t,d = map(int, stdin.readline().split())
    if t in sushi.keys():
        sushi[t].append(d)
    else:
        sushi[t] = [d]

P = []
Q = []

for x in sushi.keys():
    sushi[x].sort(reverse = True)
    P.append(sushi[x][0])
    
    for i in range(1,len(sushi[x])):
        Q.append(sushi[x][i])

heapq.heapify(P)

Q = list(map(lambda x:-x,Q))
heapq.heapify(Q)

while len(P) > K:
    m = heapq.heappop(P)
    heapq.heappush(Q,-m)

cur = 0

if K <= len(sushi.keys()):
    max_variation = K
else:
    max_variation = len(sushi.keys())
    for _ in range(K-max_variation):
        cur -= heapq.heappop(Q)

cur += sum(P)
ans = cur + max_variation**2

for i in range(max_variation-1):
    p = heapq.heappop(P)
    cur -= p
    q = -heapq.heappushpop(Q,-p)
    cur += q
    ans = max(ans,cur+(max_variation-i-1)**2)

print(ans)

Measured memory_bytes: 93392
#include <bits/stdc++.h>
#define INF 114514810
using namespace std;

int main(void){
    string s;
    int a = INF, z = -1;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') a = min(a, i);
        if (s[i] == 'Z') z = max(z, i);
    }
    cout << z - a + 1 << endl;
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

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


int main()
{
	FAST;
	string str;
	cin >> str;
    str.pop_back();
	while(str.substr(0 , str.size()/2) != str.substr(str.size()/2 , str.size()/2))
	{
		str.pop_back();
	}

	cout << str.size()-1;

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) {
    int x;
    cin >> x;
    l.at(i) = x;
  }
  int count = 0;
  rep(i, n) {
    for (int j=i+1; j < n; j++) {
      for (int k=j+1; k < n; k++) {
        if (l.at(i) != l.at(j)) {
          if (l.at(j) != l.at(k)) {
            if (l.at(k) != l.at(i)) {
              if (l.at(i)+l.at(j) > l.at(k)) {
                if (l.at(j)+l.at(k) > l.at(i)) {
                  if (l.at(k)+l.at(i) > l.at(j)) {
                    count++;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << count << endl;
}


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

int N; //頂点の数
vector<vector<int>> G; //グラフ
vector<int> h; //入次数
vector<int> l_depth; //最大経路長
vector<int> ans; //トポロジカルソート結果を格納

void input(){
  int n;
  cin>>n;
  vector<vector<int>> IDs(n, vector<int>(n, -1));
  N = n*(n-1)/2;
  G.resize(N);
  h.resize(N, 0);
  l_depth.resize(N, -1);

  int id = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      IDs[i][j] = id;
      IDs[j][i] = id;
      id++;
    }
  }

  int t, bufid, vsid;
  for(int i=0; i<n; i++){
    bufid = -1;
    for(int j=0; j<n-1; j++){
      cin>>t;t--;
      vsid = IDs[i][t];

      if(bufid != -1){
        G[bufid].push_back(vsid);
        h[vsid]++;
      }

      bufid = vsid;
    }
  }
}

void topoBFS(){   
  queue<int> unchecked;
  for(int i=0; i<N; i++){
    if(h[i]==0){
      unchecked.push(i); //入次数が0の頂点をキューに入れる
      l_depth[i] = 0; //そのような頂点は深さが0
    }
  }
  while(!unchecked.empty()){
    int current = unchecked.front();
    unchecked.pop();
    ans.push_back(current); //キューから取り出したらすぐソート後のリストに加える

    for(int next: G[current]){ //「行ける」頂点について
      h[next]--; //入次数を減らす
      l_depth[next] = max(l_depth[next], l_depth[current]+1); //最長経路
      if(h[next]==0){ //入次数0になったらキューに追加
        unchecked.push(next);
      }
    }
  }
}

int main(){
  input();
  
  topoBFS();

  bool isDAG = ans.size()==N;
  if(isDAG){
    int l_max = *max_element(l_depth.begin(), l_depth.end());
    cout<<l_max+1<<endl;
  }else{
    cout<<-1<<endl;
  }
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll F(ll h){
	if(h==1)return 1;
	return F(h/2)*2+1;
}
int main(){
	ll h;cin>>h;
	cout<<F(h)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
map<string, ll> mp;
ll res;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		string s;
		cin >>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	for (map<string, ll>::iterator it=mp.begin();it!=mp.end();it++)
	{
		ll x=it->second;
		res+=x*(x-1)/2;
	}
	cout <<res;
	return 0;
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;

void print(LL x) { printf("%lld", x); exit(0); }

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    int N, M;
    scanf("%d%d", &N, &M);

    if(N % 3 == 0 || M % 3 == 0)    print(0);

    LL ans = min(N, M);

    for(int i = 0; i <= 2; i++)
    {
        LL lgt = (N + i) / 3;
        LL a1 = 1LL * lgt * M;
        LL a2 = 1LL * (N - lgt) * (M / 2);
        LL a3 = 1LL * (N - lgt) * ((M + 1) / 2);
        ans = min(ans, max( max(a1, a2), a3 ) - min( min(a1, a2), a3 ));

        swap(N, M);
        lgt = (N + i) / 3;
        a1 = 1LL * lgt * M;
        a2 = 1LL * (N - lgt) * (M / 2);
        a3 = 1LL * (N - lgt) * ((M + 1) / 2);
        ans = min(ans, max( max(a1, a2), a3 ) - min( min(a1, a2), a3 ));

        swap(N, M);
    }

    print(ans);

    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    bool check = true;
    rep(i, s.size()){
        if(s[i] != t[i]) check = false;
    }
    cout << (check? "Yes": "No") << endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
typedef long long ll;
ll x,k,d;
ll need = 0;

template<typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
int main(){
    read(x); read(k); read(d);
    if(x < 0) x = -x;
    need = x / d;
    if(need >= k) printf("%lld\n",x - k * d);
    else
        if((k - need) & 1) printf("%lld\n",-(x - (need + 1) * d));
        else printf("%lld\n",(x - need * d));
    return 0;
}
/*

*/

Measured memory_bytes: 1604
#include <bits/stdc++.h>
#define base 950527
#define base2 1777771
#define N 1001
using namespace std;
typedef unsigned long long ull;
ull A[N][N],tmp[N][N],ans;
int w,h,p,a[N][N],b[N][N];

void Reverse(){for(int i=0;i<p;i++)reverse(b[i],b[i]+p);}

void rol_90(){
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++) tmp[p-j-1][i]=b[i][j];
  
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++) b[i][j]=tmp[i][j];
}

ull ctoi(char ch){
  if(isupper(ch)) return ch-'A';
  if(islower(ch)) return 26+ch-'a';
  if(isdigit(ch)) return 52+ch-'0';
  if(ch=='+') return 62;
  return 63;
}

void in(int y,int tmp[N][N]){
  string str[N];
  for(int i=0;i<y;i++) cin>>str[i];
  
  for(int i=0;i<y;i++)
    for(int j=0;j<str[i].size();j++)
      for(int k=0;k<6;k++)tmp[i][6*j+5-k]=(ctoi(str[i][j])>>k)&1;
}

set <ull> S;
void roll_hs(){
  ull target=0;
  for(int i=0;i<p;i++){
    ull k=0;
    for(int j=0;j<p;j++)k=k*base+b[i][j];
    target=target*base2+k; 
  }
  
  if(S.count(target))return;
  S.insert(target);
  
  for(int i=0;i<h;i++){
    ull k=0,l=1;
    for(int j=0;j<w;j++){
      k=k*base+a[i][j];
      if(j-p>=0) k-=l*a[i][j-p];
      else l*=base;
      A[i][j]=k;
    }
  }

  for(int j=p-1;j<w;j++){
    ull k=0,l=1;
    for(int i=0;i<h;i++){
      k=k*base2+A[i][j];
      if(i-p>=0) k-=l*A[i-p][j];
      else l*=base2;
      if(target==k&&i>=p-1)ans++;
    }
  }
}

int main(){
  while(1){
    cin>>w>>h>>p;
    if(!w&&!h&&!p)break;
    in(h,a),in(p,b);
    
    ans=0,S.clear();
    for(int i=0;i<4;i++){
      rol_90(),roll_hs(); 
      Reverse(),roll_hs(),Reverse();
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 19232
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b) memset(a,b,sizeof(a)); //works only for 0 and -1
int main(){
  fast();
int n,k;
cin>>n>>k;
int arr[n];
fr(i,n)cin>>arr[i];
sort(arr,arr+n);
ll sum = 0;
fr(i,k)sum+=arr[i];
cout<<sum;
 return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A + B > C + D){
    cout << "Left" << endl;
  } else if(A + B == C + D) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//using ll=long long;
static const int MAX = 100000;
int N;
vector<int> G[MAX];
bool visited[MAX];
int prenum[MAX], lowest[MAX], parent[MAX], t = 1;
vector<int> ans;

void dfs(int current, int prev) {
	prenum[current] = lowest[current] = t;
	t++;
	visited[current] = true;

	int next;
	for (int i = 0; i < G[current].size(); i++) {
		next = G[current][i];
		if (not visited[next]) {
			parent[next] = current;
			dfs(next, current);
			lowest[current] = min(lowest[current], lowest[next]);
		}
		else if(next!=prev){
			lowest[current] = min(prenum[next], lowest[current]);
		}
	}
}

void art_points() {
	for (int i = 0; i < N; i++) visited[i] = false;
	t = 1;
	dfs(0, -1);
	int np = 0;
	vector<int> out;
	for (int i = 1; i < N; i++) {
		int p = parent[i];
		if (p == 0) np++;
		else if (prenum[p] <= lowest[i]) {
			out.push_back(p);
		}
	}
	if (np > 1) out.push_back(0);
	sort(out.begin(), out.end());
	int prev=-1;
	for (int i = 0; i < out.size(); i++) {
		if(prev!=out[i]) cout << out[i] << endl;
		prev = out[i];
	}
}

int main() {
	int e, s, trmn;
	cin >> N >> e;
	for (int i = 0; i < e; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	art_points();
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

bool exist[2000][2000];
int max_doll[2000][2000];

int main(){
	
	int n, m;
	
	while(true){
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int i = 0; i <= 1000; i++){
			for(int j = 0; j <= 1000; j++){
				exist[i][j] = false;
				max_doll[i][j] = 0;
			}
		}
		
		int h, r;
		
		for(int i = 0; i < n; i++){
			cin >> h >> r;
			exist[h][r] = true;
		}
		
		cin >> m;
		
		for(int i = 0; i < m; i++){
			cin >> h >> r;
			exist[h][r] = true;
		}
		
		for(int i = 1; i <= 1000; i++){
			for(int j = 1; j <= 1000; j++){
				if(exist[i][j]){
					max_doll[i][j] = max(max(max_doll[i - 1][j], max_doll[i][j - 1]), max_doll[i - 1][j - 1] + 1);
				}else{
					max_doll[i][j] = max(max_doll[i - 1][j], max_doll[i][j - 1]);
				}
			}
		}
		
		cout << max_doll[1000][1000] << endl;
		
	}
	return 0;
}

Measured memory_bytes: 12824
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l,r,d,cnt=0;
	scanf("%d%d%d",&l,&r,&d);
	int p=d;
	while(p<=r)
	{
		if(p>=l)cnt++;
		p+=d;
	}
	printf("%d\n",cnt);
	return 0;
}


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

using namespace std;

int main(void) {
    string S;
    cin >> S;

    int ans = 0;
    for(int i=1; i<S.size()/2; i++) {
        if(S.substr(0, i) == S.substr(i, i)) {
            ans = i;
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3592
# main

loop do
  n = gets.strip.to_i
  break if n == 0

  stack = []
  prvc = -1

  for i in (0...n)
    ci = gets.strip.to_i

    if (i & 1) == 0
      if prvc != ci
        stack << [i, ci]
      end
    else
      if prvc == 1 - ci
        stack.pop
        if stack.empty?
          stack << [0, ci]
        end
      end
    end

    prvc = ci
  end

  if stack.last[1] == 0
    stack << [n, 1]
  end

  len = 0

  for i in (0...stack.length)
    if stack[i][1] == 0
      len += stack[i + 1][0] - stack[i][0]
    end
  end

  p len
end

Measured memory_bytes: 6108
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
using namespace std;

int main()
{   
    long long n,k;
    cin >> n>>k;

    long long tmp = n % k;

    if(tmp <= abs(tmp-k))cout << tmp <<endl;
    else cout <<  abs(tmp-k)<< endl;

    return 0;
}

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


int main()
{
    string s,c;
    cin >> s;
    
    
    for(int i=4;i<10;i++){
        c[i]=s[i];
        c = c + c[i];
    }
    cout <<2018<< c << endl;
    return 0;
    
}

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

typedef long long ll;
int n;
vector<int>fig(100);
ll memo[21][101];

ll rec(ll sum,ll ind){  
  if(sum < 0 || sum > 20) return 0;
  if(ind == n-1) return (sum == fig[ind]? 1 : 0);
  if(memo[sum][ind] != 0) return memo[sum][ind];

  return memo[sum][ind] = rec(sum + fig[ind],ind+1) + rec(sum - fig[ind],ind+1);
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++) cin >> fig[i];
  cout << rec(fig[0],1) << endl;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;
ll a[maxn],dig[63];
int vis[63];
void add(ll x){
    for(int i=61;i>=0;i--){
        if(!vis[i]) continue;
        if(x&(1ll<<i)){
            if(dig[i]) x^=dig[i];
            else{
                dig[i]=x;
                break;
            }
        }
    }
}
ll get(){
    ll res=0;
    for(int i=60;i>=0;i--){
        if(vis[i] && ( !(res&(1ll<<i)) ) )
            res^=dig[i];
    }
    return res;
}
int main()
{
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum^=a[i];
    }
    for(int i=0;i<=61;i++){
        if(!(sum&(1ll<<i))) vis[i]=1;
    }
    for(int i=1;i<=n;i++) add(a[i]);
    ll res=get();
    printf("%lld\n",res+(res^sum));
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace soundhound2018_summer_qual_a
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			if (x.Sum() == 15) Console.WriteLine("+");
			else Console.WriteLine(x[0] * x[1] == 15 ? "*" : "x");
		}
	}
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N,K;
int A[100005];
int dp[100005];

int solve(int id){
  if( dp[id] != -1 ) return dp[id];
  return dp[id] = solve( A[id] )+1;
}


bool iszero(){
  int R = dp[A[0]]+1; 
  if( K == 1 ){
    for(int i=0;i<N;i++)
      if( A[i] != 0 ) return false;
  } else if( R == 1 ) {
    for(int i=1;i<N;i++)
      if( A[i] > K ) return false;
  } else if( K <= R ){
    for(int i=1;i<N;i++)
      if( dp[i] != K ) return false;
  } else {
    for(int i=1;i<N;i++){
      if( K >= dp[i] && (K-dp[i])%R==0 ) continue;
      return false;
    }
  }
  return true;
}
int res;
int dfs(int id,int d){
  if( id == 0 ) return dp[id]=0;
  if( dp[id] + d <= K ) return dp[id];
  if( d == K-1 && A[id] != 0) {
    A[id] = 0;
    res++;
    return dp[id] = 1;
  }                  
  return dp[id] = dfs(A[id],d+1)+1;
}

int main(){
  cin >> N >> K;
  for(int i=0;i<N;i++) {
    cin >> A[i]; --A[i];
  }
  memset( dp, -1, sizeof( dp ) );
  dp[0] = 0;
  for(int i=0;i<N;i++) solve(i);
  if(iszero()) cout << 0 << endl;
  else {
    res = 0;
    if( A[0] ) res++;
    A[0] = 0;
    vector<P> v;
    for(int i=1;i<N;i++){
      v.push_back( P( dp[i], i ) );
    }
    sort( v.rbegin(), v.rend() );

    for( P t : v ){
      if( dp[t.second] <= K ) continue;
      dfs( t.second, 0 );
    }
    
    cout << res << endl;
  }
}


Measured memory_bytes: 3704
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
using namespace std;
using ll = long long int;
using P = pair<int, int>;

int main(){
    ll n;
    cin >> n;
    ll Snum = (1LL << n);
    vector<ll> S(Snum);
    for(int i = 0; i < Snum; i++)cin >> S[i];

    sort(S.begin(), S.end());
    vector<int> parent;
    parent.push_back(S[Snum-1]);
    multiset<int> child;
    for(int i = 0; i < Snum-1; i++)child.insert(S[i]);
    bool ans = true;
    for(int i = 1; i <= n; i++){
        int num = parent.size();
        for(int j = 0; j < num; j++){
            multiset<int>::iterator it = child.lower_bound(parent[j]);
            if (it == child.begin()){
                cout << "No" << endl;
                return 0;
            }
            --it;
            parent.push_back(*it);
            child.erase(it);
        }
    }
    cout << "Yes" << endl;
    return 0;
}   

Measured memory_bytes: 17136
def factrial(n):
    INF = 10 ** 9 + 7
    ret = 1
    for i in range(2, n + 1):  ret = (ret * i) % INF
    return ret

N, M = list(map(int,input().split()))
if abs(N - M) >= 2:  ans = 0
elif N == M:  ans = (2 * (factrial(N) ** 2)) % (10 ** 9 + 7)
else:  ans = factrial(N) * factrial(M)
print(ans % (10 ** 9 + 7))

Measured memory_bytes: 62944
#include <cstdio>
#include <map>
using namespace std;
typedef map<int,int>mii;
int d[999],n,m,a,b,i,x;
map<int,mii>z;
int D(int c){
	if(d[c]>=0)return d[c];
	int i=0,x=0;
	mii::iterator it=z[c].begin();
	for(;it!=z[c].end();it++)x=max(x,D(it->first)+it->second);
	return d[c]=x;
}
main(){
	for(scanf("%d%d",&n,&m);i<m;i++)scanf("%d%d%d",&a,&b,&x),z[b][a]=x;
	for(i=1;i<n;i++)d[i]=-1;
	printf("%d\n",D(n-1));
}

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().ToLong();
            var dp = new long[111000][];
            var k = new long[n][];
            for (int i = 0; i < n; i++)
            {
                var r = ReadSplit();
                k[i] = new long[3];
                for (int j = 0; j < 3; j++)
                {
                    k[i][j] = r[j].ToLong();
                }
            }

            for (int i = 0; i < 111000; i++)
            {
                dp[i] = new long[3];
            }

            for (int i = 0; i < n; i++)
            {
                for (int l = 0; l < 3; l++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (i != 0 && l == j) continue;
                        ChangekMax(ref dp[i + 1][j], dp[i][l] + k[i][j]);
                    }
                }
            }
            long ans = 0;
            for (int i = 0; i < 3; i++)
            {
                if (ans < dp[n][i]) ans = dp[n][i];
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToLong(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;
using tTree=__gnu_pbds::tree< ll , __gnu_pbds::null_type, less< ll >, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll a,b,c;
  cin>>a>>b>>c;

  cout << max(0LL,c-(a-b)) << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>

typedef long long int lld;
typedef unsigned long long int ulld;
const int mod = 1000000007;

using namespace std;

int main (void) {
	ios::sync_with_stdio (false);
	int len, c = 0;
	string s;
	cin >> len >> s;
	for (int i = 0; i < len - 2; i ++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			c ++;
		}
	}
	cout << c << endl;
	return 0;
}

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

'''
Author: andyli
Time: 2020-07-11 19:58:49
'''

def main():
    n = int(input())
    x = input()
    popcounts = x.count('1')
    if popcounts == 1:
        for i in range(n):
            if x[i] == '1':
                print(0)
                continue
            if (i == n-1 and x[-1] == '0') or (i != n-1 and x[-1] == '1'):
                print(2)
            else:
                print(1)
        return
    if popcounts == 0:
        for i in range(n):
            print(1)
        
        return
    modmi = [0 for i in range(n+2)]
    modpl = [0 for i in range(n+2)]
    s = 1
    for i in range(0,n+2):
        s %= (popcounts-1)
        modmi[i] = s
        s <<= 1
    s = 1
    for i in range(0,n+2):
        s %= (popcounts+1)
        modpl[i] = s
        s <<= 1
    demodmi = int(x,base=2)%(popcounts-1)
    demodpl = int(x,base=2)%(popcounts+1)
    def count(n):
        ans = 0
        while n > 0:
            n %= bin(n).count('1')
            ans += 1
        return ans
    # print('\t',demodmi,demodpl)
    for i in range(n):
        if x[i] == '0':
            demodmi = (demodmi + modmi[(n-i-1)]) % (popcounts-1)
            demodpl = (demodpl + modpl[(n-i-1)]) % (popcounts+1)
            pass
        else:
            demodmi = (demodmi - modmi[(n-i-1)]) % (popcounts-1)
            demodpl = (demodpl - modpl[(n-i-1)]) % (popcounts+1)
            pass
        mod = demodmi if x[i] == '1' else demodpl
        # print('\t', mod)
        print(1 + count(mod))
        if x[i] == '1':
            demodmi = (demodmi + modmi[(n-i-1)]) % (popcounts-1)
            demodpl = (demodpl + modpl[(n-i-1)]) % (popcounts+1)
            pass
        else:
            demodmi = (demodmi - modmi[(n-i-1)]) % (popcounts-1)
            demodpl = (demodpl - modpl[(n-i-1)]) % (popcounts+1)
            pass

    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 84320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e5;
mint fac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    mint cnt[60];
    fill(cnt, cnt+60, 0);
    rep(i, N){
        rep(j, 60){
            if(A[i] & (1LL<<j)) cnt[j] += 1;
        }
    }
    mint ans = 0, tw = 2;
    rep(i, N){
        rep(j, 60){
            if(A[i] & (1LL<<j)){
                mint n = (mint)N-cnt[j];
                ans += tw.pow(j)*n;
            }
            else{
                ans += tw.pow(j)*cnt[j];
            }
        }
    }
    ans /= 2;
    cout << ans.x << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

ll n, m;
set<ll> s;

void test(ll x){
    if(x==1) return;
    m = n;
    while(m%x==0) m/=x;
    if(m%x==1) s.insert(x);
}

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

    cin>>n;
    for(ll i = 1; i*i<=n; i++){
        if(n%i == 0){
            test(i);
            test(n/i);
        }
    }

    n--;
    for(ll i = 1; i*i<=n; i++){
        if(n%i==0){
            s.insert(i);
            s.insert(n/i);
        }
    }
    
    s.erase(1);
    cout<<s.size()<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int a, b, c;

  unused = scanf("%d %d %d", &a, &b, &c);
  if(a+b==c || a+c==b || b+c==a) printf("Yes");
  else printf("No");

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	char c;
	string a="consonant";
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		a = "vowel";
	cout << a << endl;
}


Measured memory_bytes: 256
using System;
public class CE {
    public static void Main() {
        string read = Console.ReadLine();
        int N = int.Parse(read);
        string[] read2 = new string[N];
        read2 = Console.ReadLine().Split(' ');
        int[] num = new int[N];
        for (int i = 0; i < N; i++) {
            num[i] = int.Parse(read2[i]);
        }
        Array.Sort(num);
        int number = 0;
        int[] num2 = new int[N];
        for (int i = 0; i < N - 1; i++) {
            if (num[i] == num[i + 1]) {
                num2[number]++;
                if (num2[number] == 3) {
                    num2[number] = 1;
                }
                if (i == N - 2) {
                    num2[number]++;
                }
            } else {
                num2[number]++;
                if (num2[number] == 3) {
                    num2[number] = 1;
                }
                number++;
                if (i == N - 2) {
                    num2[number]++;
                }
            }
        }
        number++;
        if (number % 2 == 1) {
            Console.WriteLine(number);
        } else {
            Console.WriteLine(number - 1);
        }
        /*int count = 0;
        int[] check = new int[number];
        for (int i = 0; i < number; i++) {
            if (num2[i] == 2) {
                count++;
                check[count] = i;
            }
        }
        if (count % 2 == 1) {
            number--;
        } else if (count == 2) {
            if (check[0] == check[1]) {
                number--;
            }
        }
        Console.WriteLine(number);*/

    }
}

Measured memory_bytes: 10968
from heapq import heappush, heappop
import sys

que = []
ans = []
for line in sys.stdin.readlines():
    cmd, *v = line.split()
    if cmd == 'insert':
        heappush(que, -int(v[0]))
    elif cmd == 'extract':
        ans.append("%d\n" % -heappop(que))
sys.stdout.writelines(ans)



Measured memory_bytes: 219536
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a); i < (b); ++i) 

const int MAX_N = 52;
char A[MAX_N][MAX_N], B[MAX_N][MAX_N];
int N, M;

bool match(int x, int y) {
    //エラー回避
    /*
    if(x + M-1 > N-1) return false;
    if(y + M-1 > N-1) return false;
    */

    REP(i, 0, M) REP(j, 0, M) {
        int nx = x + i, ny = y + j;
        if(A[nx][ny] != B[i][j]) return false;
    }
    return true;
}

int main()
{
    scanf("%d %d", &N, &M);
    REP(i, 0, N) scanf("%s", A[i]);
    REP(i, 0, M) scanf("%s", B[i]);

    REP(i, 0, N - M + 1) REP(j, 0, N - M + 1) 
        if(match(i, j)) {
            cout << "Yes" << endl; return 0;
        }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

const int N = (int)2e5 + 5, LOG = __lg(N) + 1;
int n, K, p[N], lst[N], ans, rmqMin[N][LOG], rmqMax[N][LOG];
bool eli[N];

int getMin(int l, int r) {
    int log = __lg(r - l + 1);
    return min(rmqMin[l][log], rmqMin[r - (1 << log) + 1][log]);
}

int getMax(int l, int r) {
    int log = __lg(r - l + 1);
    return max(rmqMax[l][log], rmqMax[r - (1 << log) + 1][log]);
}

int main() {
    scanf("%d %d", &n, &K);
    for (int i = 0; i < n; ++i) scanf("%d", p + i), rmqMin[i][0] = rmqMax[i][0] = p[i];

    for (int j = 1; j < LOG; ++j) {
        for (int i = 0; i < n; ++i) if (i + (1 << j) - 1 < n) {
            rmqMin[i][j] = min(rmqMin[i][j - 1], rmqMin[i + (1 << (j - 1) )][j - 1]);
            rmqMax[i][j] = max(rmqMax[i][j - 1], rmqMax[i + (1 << (j - 1) )][j - 1]);
        }
    }

    for (int i = n - 1; i >= 0; --i) {
        if (p[i] < p[i + 1]) lst[i] = lst[i + 1];
        else lst[i] = i;
    }

    for (int i = 0; i < n; ++i) if (lst[i] - i + 1 >= K) { ++ans; break ; }
    for (int i = 0; i < n; ++i) if (lst[i] - i + 1 >= K) eli[i] = 1;
    
    for (int i = 0; i + K < n; ++i) if (lst[i] - i + 1 < K) {
        if (p[i] < getMin(i + 1, i + K - 1) && getMax(i + 1, i + K - 1) < p[i + K]) eli[i] = 1;
    }
    
    for (int i = 0; i + K - 1 < n; ++i) ans += (!eli[i]);
    
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 30080
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int dp[3333][3333];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, T, S; cin >> N >> T >> S;
  int A[N], B[N];
  FOR(i,0,N) cin >> A[i] >> B[i];
  FOR(i,0,N) {
    FOR(j,0,T+1) {
      // ???i???????????????
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

      // ???i??????????????????
      if((j < S && S < j + B[i]) || j + B[i] > T) continue;
      dp[i+1][j+B[i]] = max(dp[i+1][j+B[i]], dp[i][j]+A[i]); 
    }
  }
  int ans = 0;
  FOR(i,0,T+1) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 42252
s=gets.chomp.split("")
leftS = []
rightS = []
sSize = s.size
sSizeHalf = sSize/2
s.delete_at(sSizeHalf) if sSize.odd?
leftS = s[0...sSizeHalf]
rightS = s[sSizeHalf...sSize].reverse
count = 0
sSizeHalf.times do |index|
  count += 1 if leftS[index] != rightS[index]
end
puts count

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;


int main(){
    vector<int> p(100001,0) ;
    int n ;
    cin >> n ;
    int a ;
    int64_t ans = 0 ;
    for (int i = 0; i < n; i++)
    {
        cin >> a ;
        p.at(a) ++ ;
        ans += a ;
    }
    
    int q,b,c ;
    cin >> q ;
    for (int i = 0; i < q; i++)
    {
        cin >> b >> c ;
        ans += p.at(b) * ( c - b ) ;
        p.at(c) += p.at(b) ;
        p.at(b) = 0 ;
        cout << ans << endl ;
    }
    
}

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

char mp[150][150];
int judx[150],judy[150];
int h,w;

int main(void)
{
    cin >>h>>w;
    
    char ch;
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++) {
            cin >>mp[i][j];
        }
    }

    for(int i=1; i<=w; i++) {
        bool flag=true;
        for(int j=1; j<=h; j++) {
            if(mp[j][i] =='#') flag=false;
        }
        if(flag) judx[i]=1;
    }

    for(int i=1; i<=h; i++) {
        bool flag=true;
        for(int j=1; j<=w; j++) {
            if(mp[i][j] =='#') flag=false;
        }
        if(flag) judy[i]=1;
    }

    for(int i=1; i<=h; i++) {
        if(judy[i]) continue;
        for(int j=1; j<=w; j++) {
            if(judx[j]) continue;
            cout <<mp[i][j];
        }
        cout <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

lint powmod(lint x, lint n, lint p){
    lint ret = 1;
    while(n > 0){
        if(n&1) ret *= x, ret %= p, n -= 1;
        else x *= x, x %= p, n >>= 1;
    }
    return ret;
}

int power[30];

int main(){
    int n, p;
    string s;
    cin >> n >> p >> s;
    if(p == 2 || p == 5){
        lint ans = 0;
        rep(i, n)if((s[i]-'0') % p == 0) ans += i+1;
        printf("%lld\n", ans);
    }
    else{
        int log_p = 0;
        for(int t=n; t>1; t>>=1) ++log_p;
        int table[log_p+1][p], rev[log_p+1][p];
        rep(i, p) table[0][i] = i * 10 % p;
        For(i, 1, log_p+1)rep(j, p){
            table[i][j] = table[i-1][table[i-1][j]];
        }
        rep(i, log_p+1)rep(j, p) rev[i][table[i][j]] = j;

        lint ans = 0;
        int cnt[p];
        memset(cnt, 0, sizeof(cnt));
        cnt[0] = 1;
        int sum = 0;
        rep(i, n){
            sum = (sum * 10 + s[i]-'0') % p;
            int t = sum;
            rep(k, log_p+1)if(i+1 >> k & 1) t = rev[k][t];
            ans += cnt[t];
            ++cnt[t];
        }
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 1924
import java.util.Scanner;

public class Main{
	 public static  long stoneGame(int[] piles) {
		 long[][] dp = new long[piles.length + 1][piles.length];
			

			for (int gap = 0; gap < piles.length; gap++) {
				for (int i = 0, j = i + gap; j < piles.length; j++, i++) {
					if (gap == 0) {
						dp[i][j] = piles[i];
					} else {
						dp[i][j] = Math.max(piles[i] - dp[i + 1][j], piles[j] - dp[i][j - 1]);
					}

				}

			}
		
			return dp[0][piles.length - 1];
		}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int piles[]=new int[n];
		for(int i=0;i<n;i++){
			piles[i]=scn.nextInt();
		}
		System.out.println(stoneGame(piles));
		

	}

}


Measured memory_bytes: 129640
using System;
using System.Collections;
public class Takoyaki{
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        string[] d = Console.ReadLine().Split(' ');
        int ans = 0;
        for(int i=0; i<N; i++){
            for(int j=i+1; j<N; j++){
                ans += int.Parse(d[i])*int.Parse(d[j]);
            }
        }
        Console.WriteLine(ans);
    }
}

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

const int N = 1e6+5;
int n;
vector<pair<int, int>> open, close;

bool arrange(int& cnt, vector<pair<int,int>>& v) {
	for(int i = 0; i < v.size(); i++) {
		cnt -= v[i].first;
		if(cnt < 0)
			return 0;
		cnt += v[i].second;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		string s; cin >> s;
		pair<int, int> tmp = {0,0};
		for(int j = 0; j < s.size(); j++) {
			if(s[j] == '(') tmp.second++;
			else if(tmp.second > 0) tmp.second--;
			else tmp.first++;
		}
		if(tmp.second - tmp.first >= 0)
			open.push_back(tmp);
		else
			close.push_back(tmp);
	}

	sort(open.begin(), open.end(),
		[](const pair<int, int>& a, const pair<int, int>& b) -> bool { return a.first < b.first; });
	sort(close.begin(), close.end(),
		[](const pair<int, int>& a, const pair<int, int>& b) -> bool { return a.second > b.second; });

	int cnt = 0;
	if(arrange(cnt, open) && arrange(cnt, close) && cnt == 0)
		cout << "Yes" << '\n';
	else
		cout << "No" << '\n';

	return 0;
}

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

using namespace std;

int main(){
     int n, a, b;
    scanf("%d", &n);
    int ans = 0, Min = 1e9 + 7;
    for(int i = 1; i <= n; i++){
        scanf("%d%d",  &a, &b);
        if(Min > b) Min = b, ans = a + b;
     }
     printf("%d\n", ans);
     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,k,i;
    cin>>k;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int m=0,x=0,y=0,d;
    for(i=0;i<n-1;i++){
        if(m<(a[i+1]-a[i])){
            m=a[i+1]-a[i];
            x=i;
            y=i+1;
        }
    }
    if(m<(k-a[n-1]+a[0]))
        d=a[n-1]-a[0];
    else
        d=a[x]+k-a[y];
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 1024