akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

struct Node
{
    int key;
    Node* parent;
    Node* left;
    Node* right;

    Node(int k) : key(k), parent(NULL), left(NULL), right(NULL) {}
};

void insert(Node** T, int k)
{
    Node* n = *T;
    Node* parent = NULL;
    Node* new_node = new Node(k);

    while (n != NULL) {
        parent = n;
        if (new_node->key < n->key)
            n = n->left;
        else
            n = n->right;
    }
    new_node->parent = parent;

    if (parent == NULL)
        *T = new_node;
    else if (new_node->key < parent->key)
        parent->left = new_node;
    else
        parent->right = new_node;
}

bool find(Node* T, int k)
{
    Node* node = T;
    while (node != NULL) {
        if (node->key == k)
            return true;
        else if (node->key < k)
            node = node->right;
        else
            node = node->left;
    }
    return false;
}

void inorder(Node* T)
{
    if (T == NULL)
        return;

    inorder(T->left);
    cout << ' ' << T->key;
    inorder(T->right);
}

void preorder(Node* T)
{
    if (T == NULL)
        return;

    cout << ' ' << T->key;
    preorder(T->left);
    preorder(T->right);
}

void print(Node* T)
{
    inorder(T);
    cout << '\n';
    preorder(T);
    cout << '\n';
}

void delete_tree(Node* T)
{
    if (T == NULL)
        return;

    delete_tree(T->left);
    delete_tree(T->right);
    delete T;
}

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

    Node* T = NULL;
    for (int i = 0; i < m; ++i) {
        string instruction;
        cin >> instruction;
        if (instruction == "insert") {
            int k;
            cin >> k;
            insert(&T, k);
        } else if (instruction == "find") {
            int k;
            cin >> k;
            bool result = find(T, k);
            if (result)
                cout << "yes\n";
            else
                cout << "no\n";
        } else {
            print(T);
        }
    }

    delete_tree(T);
}



Measured memory_bytes: 21768
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin>>a;
int x;
int ans=0;
for(x=0;x<a.size();x++)
{
	if(a[x]=='2')
	{
		ans++;
	}
	}	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
public class Program
{
	public static void Main(string[] args)
	{
		var N = int.Parse(Console.ReadLine());
		double total = 0;

		for (int i = 0; i < N; i++)
		{
			// スペース区切りの整数の入力
			var input = Console.ReadLine().Split(' ');
			if (input[1] == "JPY")
			{
				total += double.Parse(input[0]);
			}
			else
			{
				total += double.Parse(input[0]) * 380000;
			}
		}
		Console.WriteLine(total);

	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int meke_comb(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int fact(int n){
//   int ans;
//   if(n==1 || n == 0) return 1;
//   ans = n*fact(n-1);
//   return ans;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }




int main(){
  int N,X;
  cin >> N >> X;
  int x;
  int ans;
  cin >> x;
  ans = abs(x-X);
  rep(i,N-1){
    int num;
    cin >> num;
    ans = gcd(abs(X-num),ans);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] s = new int[n + 1];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }

        int q     = sc.nextInt();
        int count = 0;
        
        for (int i = 0; i < q; i++) {
            int target = sc.nextInt();
            int left = 0;
            int right = n - 1;
            while (right - left >= 0) {
                int mid = (left + right) / 2;
                if (s[mid] > target) {
                    right = mid - 1;
                } else if (s[mid] < target) {
                    left = mid + 1;
                } else {
                    count++;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 68796
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

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

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

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}

#define MOD 1000000007

LL mypow(LL a, LL n) {
    if(n == 1) return a % MOD;
    if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
    LL t = mypow(a, n/2);
    return (t * t) % MOD; 
}

int main(void) {
    int n;
    cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    VI ans(300000, -1); 

    int idx = 150000;
    int dir = 1;
    REP(i, n) {
        idx += i * dir;
        ans[idx] = a[i];
        dir *= -1;
    }
    if(n % 2 == 0) {
        idx = 0;
        while(ans[idx] < 0) idx++;
        REP(i, n) {
            cout << ans[i + idx] << " ";
        }
    } else {
        idx = 299999;
        while(ans[idx] < 0) idx--;
        REP(i, n) {
            cout << ans[idx - i] << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100005;
int n,a[N],ans,inv[N],sum,tmp,pre[N],jc;
void up(int &x,int y){x=x-mod+y;x=(x<0)?x+mod:x;}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),ans=((ll)ans+a[i])%mod;
	inv[0]=inv[1]=1;jc=1;
	for (int i=2;i<=n;i++) inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jc=(ll)jc*i%mod,pre[i]=((ll)pre[i-1]+inv[i])%mod;
	for (int i=1;i<=n;i++)
	{
		int tmp=0;up(tmp,pre[i]);up(tmp,pre[n-i+1]);
		up(ans,(ll)tmp*a[i]%mod);
	}
	printf("%d\n",(ll)ans*jc%mod);
	return 0;
}

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

int main(){
    string s,ss;
    ll k,c=0,cc=0;
    cin >> s;
    cin >> k;
    int n = s.length();
    int check = 0;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            check = 1;
        }
    }
    if(check == 0){
        cout<<(n*k)/2<<endl;
        return 0;
    }

    int f[n];
    rep(i,n) f[i]=0;
    

    rep(i,n-1){
        if(s[i] == s[i+1] && f[i] == 0){
            f[i+1]=1;
            c++;
        }
    }
    
    ss = s+s;
    int ff[2*n];
    rep(i,2*n)ff[i]=0;

    rep(i,(2*n)-1){
        if(ss[i] == ss[i+1] && ff[i] == 0){
            ff[i+1]=1;
            cc++;
        }
    }
    int diff = cc-c;
    ll ans = c+diff*(k-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950


bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}

//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////
ll r=0;
void printDivisibleNumber(int arr[], int n){
   unordered_set<int> s;
   int maxElement = INT_MIN;
   for (int i = 0; i < n; i++) {
      s.insert(arr[i]);
      maxElement = max(maxElement, arr[i]);
   }
   unordered_set<int> res;
   for (int i = 0; i < n; i++) {
      if (arr[i] != 0) {
         for (int j = arr[i] * 2; j <= maxElement; j += arr[i]) {
            if (s.find(j) != s.end())
               res.insert(j);
            }
         }
      }
   unordered_map<int, int> mp;
   for (int i = 0; i <n; i++)
      mp[arr[i]]++;
   unordered_map<int, int>::iterator it;
   vector<int> ans;
   for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= 2) {
         if (res.find(it->first) == res.end()) {
            int val = it->second;
            while (val--)
               ans.push_back(it->first);
         }
      }
      if (res.find(it->first) != res.end()) {
         int val = it->second;
         while (val--)
            ans.push_back(it->first);
      }
   }
   for (auto x : ans){
     // cout<<x<<"\t";
      r++;
   }

}
void solve(){

    int n;
    cin>>n;

    int a[n];
    loop(i,0,n){
        cin>>a[i];
    }

    //divisibilityCheck(a,n);
    printDivisibleNumber(a,n);
    cout<<n-r;



    return;
} 
 
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 30560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    string s;
    cin >> n >> s;
    int c = 0;
    VI a(n), b(n);
    REP(i,n){
        if (s[i] == '#') c++;
        a[i] = c;
    }
    c = 0;
    FORR(i,n-1,0){
        if (s[i] == '.') c++;
        b[i] = c;
    }
    int ans = min(a[n - 1], b[0]);
    REP(i,n-1) ans = min(ans, a[i] + b[i + 1]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2180
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 100010
using namespace std;
struct node{double x,y;}b[N];
node O;
double R;
double sqr(double x){return x*x;}
double dis(node x,node y)
{
    return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y));
}
bool incircle(node x)
{
    if(dis(O,x)<=R) return true;
    return false;
}
node solve(double a,double b,double c,double d,double e,double f)
{
    double y=(f*a-c*d)/(b*d-e*a);
    double x=(f*b-c*e)/(a*e-b*d);
    return (node){x,y};
}
int main()
{
    int n;
    scanf("%d",&n);
    int i,j,k;
    for(i=1;i<=n;i++)
    scanf("%lf%lf",&b[i].x,&b[i].y);
    random_shuffle(b+1,b+n+1);
    R=0;
    for(i=1;i<=n;i++)
    if(!incircle(b[i]))
    {
        O.x=b[i].x;O.y=b[i].y;R=0;
        for(j=1;j<i;j++)
        if(!incircle(b[j]))
        {
            O.x=(b[i].x+b[j].x)/2;
            O.y=(b[i].y+b[j].y)/2;
            R=dis(O,b[i]);
            for(k=1;k<j;k++)
            if(!incircle(b[k]))
            {
                O=solve(
                b[i].x-b[j].x,b[i].y-b[j].y,(sqr(b[j].x)+sqr(b[j].y)-sqr(b[i].x)-sqr(b[i].y))/2,
                b[i].x-b[k].x,b[i].y-b[k].y,(sqr(b[k].x)+sqr(b[k].y)-sqr(b[i].x)-sqr(b[i].y))/2 
                );
                R=dis(b[i],O);
            }
        }
    }
    printf("%.18lf\n",R);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    while ((readStr = reader.readLine()) != null) {
      int[] list = new int[2];
      list[0] = Integer.parseInt(readStr.split(" ")[0]);
      list[1] = Integer.parseInt(readStr.split(" ")[1]);
      
      if (list[0] == 0 && list[1] == 0) break;
      
      ascendingSort(list);

      System.out.println(Arrays.toString(list)
              .replaceAll("\\[|\\]|,", ""));
    }
  }

  public static void ascendingSort(int[] array) {
    for (int i = 0; i < array.length; i++) {
      for (int j = 0; j < array.length - 1 - i; j++) {
        if (array[j] > array[j + 1]) {
          int tmp = array[j];
          array[j] = array[j + 1];
          array[j + 1] = tmp;
        }
      }
    }
  }

}

Measured memory_bytes: 31688
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

class Graph{
	private:
	int V,root;
	vvi List;
	vi rank,a,L,R;
	void Rank(){
		queue<P> q;
		q.push({root,0});
		rank[root]=0;
		while(!q.empty()){
			P p=q.front();
			q.pop();
			int u=p.first;
			for(int i=0;i<List[u].size();i++){
				int w=List[u][i];
				if(rank[w]==-1){
					rank[w]=p.second+1;
					q.push({w,p.second+1});
				}
			}
		}
	}
	void BFS(){
		vp b(V);
		for(int i=0;i<V;i++) b[i]={rank[i],i};
		sort(b.begin(),b.end(),[](P p,P q){
			return p.first>q.first;
		});
		for(int i=0;i<V;i++){
			int v=b[i].second,l=-inf,r=inf;
			for(int i=0;i<List[v].size();i++){
				int u=List[v][i];
				if(rank[v]<rank[u]){
					l=max(l,L[u]-1);
					r=min(r,R[u]+1);
				}
			}
			if(a[v]!=-1){
				l=max(l,a[v]);
				r=min(r,a[v]);
			}
			int eo=a[root]%2^rank[v]%2;
			if(l%2!=eo) l++;
			if(r%2!=eo) r--;
			L[v]=l;
			R[v]=r;
		}
	}
	bool bfs_f(int v,int x){
		if(R[v]<x||x<L[v]) return 1;
		a[v]=x;
		return 0;
	}
	bool bfs(){
		queue<int> q;
		q.push(root);
		if(bfs_f(root,a[root])) return 1;
		while(!q.empty()){
			int v=q.front();
			q.pop();
			for(int i=0;i<List[v].size();i++){
				int u=List[v][i];
				if(rank[v]<rank[u]){
					q.push(u);
					if(bfs_f(u,a[v]-1)&&bfs_f(u,a[v]+1)) return 1;
				}
			}
		}
		return 0;
	}
	public:
	Graph(int v){
		V=v;
		List=vvi(v);
	}
	void add_edge(int s,int t){
		List[s].push_back(t);
		List[t].push_back(s);
	}
	void solve(){
		L=R=vi(V);
		a=rank=vi(V,-1);
		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			int v,p;
			cin>>v>>p;
			a[v-1]=p;
			if(!i) root=v-1;
		}
		Rank();
		BFS();
		if(bfs()) cout<<"No"<<endl;
		else{
			cout<<"Yes"<<endl;
			for(int i=0;i<V;i++) cout<<a[i]<<endl;
		}
	}
};

int n,k;

int main(){
	cin>>n;
	Graph g(n);
	for(int i=1;i<n;i++){
		int s,t;
		cin>>s>>t;
		g.add_edge(s-1,t-1);
	}
	g.solve();
}

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

using namespace std;

int n, k;
char x[10005], mi;

int main() {
	scanf("%d%d%s", &n, &k, x);
	for (int i = 0; i < n; i++)
		x[n + i] = x[n - 1 - i];
	if (k == 1) {
		string ans = string(x, n);
		for (int i = 1; i <= n; i++)
			ans = min(ans, string(x + i, n));
		printf("%s\n", ans.c_str());
		return 0;
	}
	mi = x[0];
	for (int i = 1; i < n; i++)
		mi = min(mi, x[i]);
	string ans = string(x, n);
	for (int i = n + 1; i <= n + n; i++)
		if (x[i - 1] == mi && x[i] != mi) {
			int cnt = 0;
			for (int j = 1; i - j >= 0 && x[i - j] == mi; j++)
				cnt++;
			cnt = min(cnt, n);
			string cur = string(x + (n + n - (i - cnt)), n - cnt);
			if (cur.size() < ans.size() || (cur.size() == ans.size() && cur < ans))
				ans = cur;
		}
	int cnt = n - ans.size();
	for (int i = 1; i < k && cnt != n; i++)
		cnt = min(n, cnt * 2);
	for (int i = 0; i < cnt; i++)
		printf("%c", mi);
	printf("%s\n", string(ans.c_str(), n - cnt).c_str());
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))

x_sort = sorted(x)
ans_1 = x_sort[int(n / 2)-1]
ans_2 = x_sort[int(n / 2)]

for xi in x:
    if xi <= ans_1:
        print(ans_2)
    else:
        print(ans_1)

Measured memory_bytes: 25472
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,D = map(int,input().split())
ans = 0
for i in range(N):
    x,y = map(int,input().split())
    if x*x+y*y<=D*D:
        ans += 1
print(ans)

Measured memory_bytes: 10532
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LEN 1000000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
P u[LEN+1];
int head, tail, n;

int isEmpty(){
  if( head ==tail) return 1;
  else return 0;
}

void enqueue(P x){
  Q[tail] = x;
      tail++;
}

void initialize(){
  head = 0;
  tail = n+1;
}
  
int main(){
  int count = 1, c,tmp=0;
  int i, q;
  scanf("%d %d", &n, &q);
  int a[n+1];

for(i =1 ;i<=n ;i++){
    u[i].t = 0;
    }
  
  for (i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  initialize();
  
  i=1;
  while(count != n+1){
    if(Q[i].t >q){
      Q[i].t=(Q[i].t - q);
      tmp += q;
      enqueue(Q[i]);
      i++;
    }
    else if(Q[i].t <=q) {
      tmp +=Q[i].t;
      u[count].t=tmp;
      strcpy(u[count].name ,Q[i].name);
      i++;
      count++;
	}
  }
  for(i =1 ;i<=n ;i++){
  printf("%s %d\n",u[i].name,u[i].t);
  }
  return 0;
}



Measured memory_bytes: 26132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
// head
const int maxn = 1e5 + 5;
int n, a[maxn], pos;

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	cin>>n;
	rep(i, 1, n)
	    cin>>a[i];
	sort(a + 1, a + n + 1, cmp);
	rep(i, 0, n) 
	    if(i >= a[i + 1]) {
	    	int j = i - 1;
	    	while(i - 1 < a[j + 2]) j++;
	    	if((j - i + 2)%2 == 0 || (a[i] - (i - 1))%2 == 0) cout<<"First"<<endl;
	    	else cout<<"Second"<<endl;
	    	break;
	    }
} 

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

int partition( vector<int> &A, int p, int r )
{
	int x = A[r];
	int i = p - 1;
	for( int j = p; j < r; j++ ) {
		if( A[j] <= x ) {
			i++;
			swap( A[i], A[j] );
		}
	}
	swap( A[i + 1], A[r] );
	return i + 1;
}

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

	int q = partition( A, 0, n - 1 );
	for( int i = 0; i < n; i++ ) {
		if( i ) cout << " ";
		if( i == q ) cout << "[";
		cout << A[i];
		if( i == q ) cout << "]";
	}
	cout << endl;
}



Measured memory_bytes: 3120
s = gets.chomp
t = gets.chomp

len = s.length

ss = s + s
tt = t + t
candidates = 0.upto(ss.length - s.length).map do |i|
  ss[i...(i + len)]
end

if candidates.select {|c| tt.include?(c)}.empty?
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 1788
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, factorial
from copy import deepcopy
 
def main():
    n = int(input()) 
    ans = (10**n) - 2*(9**n) + (8**n) 
    print(ans%(10**9+7))
    

if __name__ == "__main__":
    main()

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

#define FOR(s, i, n) for(int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	vector<int> diff(n);
	vector<int> sum(n);
	int a;
	FOR(0, i, <n){
		cin>>a;
		diff[i] = i-a;
		sum[i] = i+a;
	}
	sort(sum.begin(), sum.end());
	ll ans = 0;
	FOR(0, i, <n){
		ans += upper_bound(sum.begin(), sum.end(), diff[i]) - lower_bound(sum.begin(), sum.end(), diff[i]);
		// if (diff[i] == sum[i]){
		// 	ans--;
		// }
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 4784
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<string>
#include<iomanip>
#include <sstream>
#include<map>
#include<complex>
#include<set>
using namespace std;
#define rep(i,t,n)  for(ll i =(t);i<=(n);++i)
#define per(i,n,t)  for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define Decimal fixed<<setprecision(20)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 5;
typedef double db;
const db pi = acos(-1.);
ll n, k;

int d[maxn];
int main() {
	FAST_IO;

	string s;
	cin >> n;
	cin >> s;
	int p = 0;
	int cnt = 0;
	while (p < n) {
		p++;
		while (p < n && s[p] == s[p-1]) {
			p++;
		}
		cnt++;
	}
	
	cout << cnt << endl;
	cin >> n;
}         
/*
2
A 0 0 2
B 1 0 2


*/


Measured memory_bytes: 512
s = input()
ans = 0
pre = 0
while s.rfind('A') >= 0:
    rec = 0
    index = s.rfind('A')
    t = s[index+1:]
    while t[:2]=='BC':
        rec += 1
        t=t[2:]
    if len(t)==0:
        rec += pre
    pre = rec
    ans += rec
    s = s[:index]
print(ans)

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
	ll x,y;
	cin>>x>>y;

	bool yes=false;
	for(ll i=0;i<=x;i++){
		if(i*4+(x-i)*2==y) yes=true;
	}

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

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define answer(formula) formula ? cout << "Yes" << endl : cout << "No" << endl
#define ANSWER(formula) formula ? cout << "YES" << endl : cout << "NO" << endl

#define PI 3.14159265358979323846
#define INF 1050000000
#define MOD 1000000007
#define EPS (1e-10)

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;

typedef pair<int, int> pii;

constexpr int dir[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

/*<ここから>***********************************************************/

int H, W;
char s[50][50];
int cost[50][50] = { 0 };
bool visited[50][50] = { false };

void bfs()
{
	queue<pair<int, int>> que;
	int d = 0;

	que.push(make_pair(0, 0));

	while (!que.empty()) {

		int x = que.front().first;
		int y = que.front().second;
		que.pop();

		rep(i, 4) {
			int nx, ny;
			nx = x + dir[i][0], ny = y + dir[i][1];
			if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
			if (s[ny][nx] == '.' && !visited[ny][nx]) {
				cost[ny][nx] = cost[y][x] + 1;
				visited[ny][nx] = true;
				que.push(make_pair(nx, ny));
			}
		}
	}
}


int main()
{
	cin >> H >> W;
	int n = 0;
	rep(i, H) {
		rep(j, W) {
			cin >> s[i][j];
			if (s[i][j] == '.') n++;
		}
	}

	bfs();

	if (visited[H - 1][W - 1]) cout << n - cost[H - 1][W - 1] - 1 << endl;
	else cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> e(n);
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    queue<int> que;
    que.push(0);
    bool visited[n] = {};
    visited[0] = true;
    ll ans = k;
    while (!que.empty()) {
        int now = que.front();
        que.pop();
        int color_num;
        if (now == 0) color_num = k - 1;
        else color_num = max(0, k - 2);
        for (auto i : e[now]) {
            if (visited[i]) continue;
            que.push(i);
            visited[i] = true;
            ans *= color_num;
            ans %= MOD;
            color_num--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
/*!* [bitutil] *!*/
/*+* ビット操作関連 *+*/

int PopCount(i64 x) {
    x = (x & 0x5555555555555555) + (x >>  1 & 0x5555555555555555);
    x = (x & 0x3333333333333333) + (x >>  2 & 0x3333333333333333);
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >>  4 & 0x0f0f0f0f0f0f0f0f);
    x = (x & 0x00ff00ff00ff00ff) + (x >>  8 & 0x00ff00ff00ff00ff);
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
    x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff);
    return (int)(x);
}

// 一番後ろに立っているビットの位置を取得
int GetLastBit(i64 x) {
    if(x == 0) return 0;
    for(int i = 0; i < 64; i++) {
        if(x >> i == 1) return i + 1;
    }
    return -1;
}
using P = pair<int, int>;
int main() {
    int N, M;
    cin >> N;
    M = 1 << N;
    vector<vector<P>> data(N);
    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        data[i] = vector<P>(A);
        for(auto &x : data[i]) {
            cin >> x.first >> x.second;
            x.first--;
        }
    }
    int ans = 0;
    for (int i = 0; i < M; i++) {
        bool flag = true;
        for(int j = 0; j < N; j++) {
            if( !(i & (1 << j))) continue;
            for(auto x : data[j]) {
                if( ((i >> x.first) & 1) != x.second) {
                    flag = false;
                }
            }
        }
        if (flag) ans = max(ans, PopCount(i));
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  auto is_RUD = [](char c) { return c == 'R' || c == 'U' || c == 'D'; };
  auto is_LUD = [](char c) { return c == 'L' || c == 'U' || c == 'D'; };
  auto is_easy_steps = [&is_RUD, &is_LUD](const std::string& s) {
    for (size_t i = 0; i < s.size(); i += 2)
      if (!is_RUD(s[i])) return "No";
    for (size_t i = 1; i < s.size(); i += 2)
      if (!is_LUD(s[i])) return "No";
    return "Yes";
  };
  std::string s;
  std::cin >> s;
  std::cout << is_easy_steps(s) << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
vector<pair<int,int> > ans_lis;
int main(){
    int n,i,j,k;
    cin>>n;
    if(n%2==1){
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                if(j!=n-i){
                    ans_lis.push_back({i,j});
                }
            }
        }
        cout<<ans_lis.size()<<endl;
        for(i=0;i<ans_lis.size();i++){
            cout<<ans_lis[i].first<<" "<<ans_lis[i].second<<endl;
        }
    }
    else{
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                if(j!=n-i+1){
                    ans_lis.push_back({i,j});
                }
            }
        }
        cout<<ans_lis.size()<<endl;
        for(i=0;i<ans_lis.size();i++){
            cout<<ans_lis[i].first<<" "<<ans_lis[i].second<<endl;
        }
    }
}

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

int main()
{
  int w,h,n;
  cin >> w >> h >> n;
  vector<int> array1;
  vector<int> array2;
  vector<int> array3;
  vector<int> array4;
  int x,y,a;
  int i;
  for(i = 0;i < n;++i){
    cin >> x >> y >> a;
    if(a == 1){
      array1.push_back(x);
    }else if(a == 2){
      array2.push_back(x);
    }else if(a == 3){
      array3.push_back(y);
    }else if(a == 4){
      array4.push_back(y);
    }
  }
  int maxx,minx,maxy,miny;
  if(array1.size() != 0){
    maxx = array1.at(0);
    for(i = 0;i < array1.size();++i){
      if(maxx < array1.at(i)){
      maxx = array1.at(i);
      }
    }
  }else{
    maxx = 0;
  }
  if(array2.size() != 0){
    minx = array2.at(0);
    for(i = 0;i < array2.size();++i){
      if(minx > array2.at(i)){
      minx = array2.at(i);
      }
    }
  }else{
    minx = w;
  }
  if(array3.size() != 0){
    maxy = array3.at(0);
    for(i = 0;i < array3.size();++i){
      if(maxy < array3.at(i)){
      maxy = array3.at(i);
      }
    }
  }else{
    maxy = 0;
  }
  if(array4.size() != 0){
    miny = array4.at(0);
    for(i = 0;i < array4.size();++i){
      if(miny > array4.at(i)){
      miny = array4.at(i);
      }
    }
  }else{
    miny = h;
  }
  if(maxx > minx || maxy > miny){
    cout << 0 << endl;
  }else{
    cout <<(minx-maxx)*(miny-maxy) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// ABC139_D
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

ll sum_num(ll N) {
    ll res = 0;
    for (ll i = 1; i <= N-1; ++i) {
        res += i;
    }
    
    return res;
}

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    
    // calculation
    if (N == 1) {
        cout << 0 << "\n";
    } else if (N == 2) {
        cout << 1 << "\n";
    } else {
        cout << sum_num(N) << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
q = int(input())


bc = []
for i in range(q):
    bc.append(list(map(int, input().split())))


co = dict(Counter(a))

s = sum(a)

for b, c in bc:
    if co.get(b) == None:
        print(s)
    else:
        s = s + co[b] * (c - b)
        print(s)
        if co.get(c) == None:
            co[c] = co[b]
        else:
            co[c] += co[b]
        co[b] = 0

Measured memory_bytes: 37500
#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());

  cout << A.back() - A[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int main (){
    int n, k, x, y;

    cin >> n >> k >> x >> y;

    if (n > k){
        cout << x*k + (n-k)*y << endl;
    }
    else {
        cout << x*n << endl;
    }


    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(n):
  A = list(map(int, input().split()))
  if sum([a*b for a,b in zip(A,B)]) + c > 0:
    ans += 1
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int p[400000];
int dp[400000];
signed main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&p[i]);
	rep(i,n){
		dp[p[i]]=dp[p[i]-1]+1;
	}
	int Max=*max_element(dp,dp+n+1);
	
	cout<<n-Max<<endl;
}

Measured memory_bytes: 1792
// Last Update:2018-04-01 20:24:39
// author:sjy
#include<bits/stdc++.h>
using namespace std;
int ask[20005];
int flag[4]={0,2,3,4};
int main(void)
{
    int n;
    cin>>n;
    if(n == 3)
        printf("2 5 63\n");
    else if(n == 4)
        printf("2 5 20 63\n");
    else if(n == 5)
        printf("2 5 20 30 63\n");
    else
    {
      int cn = 0;
      ask[cn++] = 2;
      ask[cn++] = 3;
      int k = 0;
      int v = 3;
      int sum = 5;
      //vec[2].push_back(2);
      //vec[3].push_back(3);
      for(int i = cn;i < n;i++)
      {
          sum += 6*k + flag[v];
          //printf("%d\n",6*k + flag[v]);
          ask[cn++] = 6*k + flag[v];
          v++;
          if(v == 4)
          {
              v = 0;
              k++;
          }
      }
      int t = ask[cn-1] + 1;
      if(sum%6 == 2)
      {
          for(int s = cn - 1;s >= 0;s--)
          {
              if(ask[s]%6 == 2)
              {   while(t%6)t++;
                  ask[s] = t;break;}
          }
      }
      else if(sum%6 == 5)
      {
          for(int s = cn - 1;s >= 0;s--)
          {
              if(ask[s]%6 == 3)
              {   while(t%6!=4)t++;
                  ask[s] = t;break;}
          }
      }
      else if(sum%6 == 3)
      {
          for(int s = cn - 1;s >= 0;s--)
          {
              if(ask[s] %6 == 3)
              {while(t%6)t++;ask[s] = t;break;}
          }
      }
      sort(ask,ask+cn);
      printf("%d",ask[0]);
      for(int s = 1;s < cn;s++)
          printf(" %d",ask[s]);
      printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
n, t = map(int, input().split())
ab = sorted([ list(map(int, input().split())) for _ in range(n)])
A, B = zip(*ab)
dp = [[0]*(t+1) for _ in range(n+1)]
for i in range(n):
  for j in range(t+1):
    if A[i] >= j:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j-A[i]] + B[i], dp[i][j])
maxB = [B[-1]]*n
for i in range(n-2, 0, -1):
  maxB[i] = max(B[i], maxB[i+1])
ans = 0
for i in range(n-1):
  ans = max(ans, dp[i+1][t] + maxB[i+1])
print(ans)

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

int main(){
	int a[200]={0};
	int  N, ans=1000000000, test;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	for(int i=-100;i<=100;i++){
		test=0;
		for(int k=0;k<N;k++){
			test += a[k]*a[k] + i*i - 2*a[k]*i;
		}
		if(test<ans){
			ans = test;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a,b,c; cin>>a>>b>>c;
  if(a==b&&b==c){cout<<1<<endl;}
  else if(a==b||b==c){cout<<2<<endl;}
  else if(a==c){cout<<2<<endl;}
  else{cout<<3<<endl;}
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import qualified Data.List as L
import qualified Data.Char as C
import Debug.Trace

main ::IO()
main = do
  n <- read <$> getLine -- :: IO Int
  putStrLn $ show $ solve n 

solve :: Int -> Int 
solve n =
  ans
  where
    m = ceiling $ fromIntegral n / 10
    n' = n-m
    cand1 =digs m+ digs n'
    cand2 = digs n
    ans = minimum $ L.delete 1 [cand1,cand2]

-- -- functions --

digs :: Integral x => x -> x
digs 0 = 0
digs x = x `mod` 10 + digs (x `div` 10)


Measured memory_bytes: 508
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
gcd = lambda x, y: gcd(y, x % y) if x % y else y
L = list(itertools.accumulate(A, func=gcd))
R = list(itertools.accumulate(A[::-1], func=gcd))[::-1]
ans = max(R[1], L[-2])
for i in range(1, N - 1):
    ans = max(ans, gcd(L[i - 1], R[i + 1]))
print(ans)
# https://img.atcoder.jp/abc125/editorial.pdf


Measured memory_bytes: 14528
def Dict_Choice(D):
    S=0
    for k in D:
        x=D[k]
        S+=(x*(x-1))//2
    return S

N=int(input())
A=list(map(int,input().split()))

D={}
for i in range(N):
    if A[i] in D:
        D[A[i]]+=1
    else:
        D[A[i]]=1

E={}
for k in D:
    x=D[k]
    E[k]=(x*(x-1))//2

S=0
for k in E:
    S+=E[k]

for i in range(N):
    print(S-(D[A[i]]-1))


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

int gcd(int a, int b){
        if(a>b) swap(a,b);
        while(b%a!=0){
                int tmp = b%a;
                b = a;
                a = tmp;
        }
        return a;
}

int main(){
        int n,i,j,jud,t;
        cin >> n;
        vector<int> a(n);
        for(i=0;i<n;++i) cin >> a.at(i);
        vector<int> e(1e6+1);
        vector<int> d(1e6+1);
        for(i=2;i*i<=1e6;++i){
                if(e.at(i)==1) continue;
                for(j=i;j<=1e6;j+=i){
                        e.at(j) = 1;
                        d.at(j) = i;
                }
        }
        jud = a.at(0);
        for(i=1;i<n;++i) jud = gcd(jud,a.at(i));
        if(jud>1) cout << "not coprime" << endl;
        else{
                map<int,pair<int,int>> mp;
                for(i=0;i<n;++i){
                        t = a.at(i);
                        while(t!=1){
                                if(e.at(t)==0) d.at(t) = t;
                                if(mp[d.at(t)].first!=i&&mp[d.at(t)].second==1){
                                        cout << "setwise coprime" << endl;
                                        return 0;
                                }
                                mp[d.at(t)] = {i,1};
                                t /= d.at(t);
                        }
                }
                cout << "pairwise coprime" << endl;
        }
        return 0;
}

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

vector<int> C(26, 0); // C[i]
vector<vector<int> > S(365, vector<int>(26, 0)); // S[d][i]
int D;
int N;

int score(vector<int> V) {
	vector<int> c = C;
	int s = 0;
	for (int d = 0; d < D; d++) {
		c[V[d]] = 0;
		s += S[d][V[d]];
		s -= accumulate(c.begin(), c.end(), 0);
		for (int i = 0; i < N; i++) {
			c[i] += C[i];
		}
	}
	return s;
}

int ls1(int d, int i, int ci, int Ci) {
	return S[d][i] + 5 * ci;
}

double ls(double a, double b, double x, int d, int i, int ci, int Ci) {
	return S[d][i] - x * (S[min(D - 1, d + 1)][i] + S[min(D - 1, d + 2)][i]) / 100 + a * ci - b * Ci;
}

vector<int> findmin(double a, double b, double x) {
	vector<int> V(D, 0);
	vector<int> c = C;
	int s = 0;
	for (int d = 0; d < D; d++) {
		int mi = 0;
		for (int i = 0; i < N; i++) {
			if (ls(a, b, x, d,mi,c[mi],C[mi]) < ls(a, b, x, d, i, c[i], C[i])) mi = i;
		}
		V[d] = mi;
		c[V[d]] = 0;
		s += S[d][V[d]];
		s -= accumulate(c.begin(), c.end(), 0);
		for (int i = 0; i < N; i++) {
			c[i] += C[i];
		}
	}
	return V;
}

int main() {
	cin >> D;
	N = 26;
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int d = 0; d < D; d++) {
		for (int i = 0; i < N; i++) {
			cin >> S[d][i];
		}
	}
	vector<int> V(D, 0);
	for (int d = 0; d < D; d++) {
//		cin >> V[d];
//		V[d]--;
		int i = 0;
		for (int j = 1; j < N; j++) {
			if (S[d][i] < S[d][j]) i = j;
		}
		V[d] = i;
	}


	random_device seed_gen;
	mt19937 engine(seed_gen());
	normal_distribution<> dist(0.0, 4.0);

	double a = 5; // 7;
	double b = 30; //  42;
	double x = 0; // 4;
	vector<int> sV = findmin(a, b, x);
	if (score(V) < score(sV)) V = sV;
	cerr << "a = " << a << ", b = " << b << ", x = " << x << ", s = " << score(V) << endl;
	for (int j = 0; j < 10000; j++) {
		double ba = dist(engine);
		double bb = dist(engine);
		double bx = dist(engine);
		sV = findmin(a + ba, b + bb, x + bx);
		if (score(V) < score(sV)) {
			V = sV;
			a += ba;
			b += bb;
			x += bx;
//			cerr << "a = " << a << ", b = " << b << ", x = " << x << ", s = " << score(V) << endl;
		}
	}

	/*
	random_device seed_gen;
	mt19937 engine(seed_gen());
	uniform_real_distribution<> dist1(0.0, 1.0);
	vector<int> newV = V;
	int ms = score(V);
	for (int j = 0; j < 100000; j++) {
		newV = V;
		for (int k = 0; k < 1; k++) {
			int d1 = int(dist1(engine) * D);
			int d2 = min(D-1, d1 + int(dist1(engine) * 3));
			newV[d1] = V[d2];
			newV[d2] = V[d1];
		}
		int ns = score(newV);
		if (ms < ns) V = newV;
	}
	*/

	for (int d = 0; d < D; d++) {
		cout << V[d] + 1 << endl;
	}
	cerr << score(V) << endl;
  	return(0);
}


Measured memory_bytes: 4228
program A326A
    implicit none
    integer(8)::N,ans,i,calc
    character(100)::S
    read*,N,S
    ans=0
    calc=0
    do i=1,N
        if(S(i:i)=="I")calc=calc+1
        if(S(i:i)=="D")calc=calc-1
        ans=max(ans,calc)
    end do

    print'(i0)',ans
end program A326A

Measured memory_bytes: 256
N = int(input())
v_list = list(map(lambda x:int(x),input().split(" ")))

while len(v_list) > 1:
  min_1 = min(v_list)
  v_list.remove(min_1)
  min_2 = min(v_list)
  v_list.remove(min_2)
  new_value = (min_1 + min_2)/2
  v_list.append(new_value)

print(v_list[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	int cnt2 = 0, cnt4 = 0, cnt1 = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] % 4 != 0 && a[i] % 2 == 0)
			cnt2++;
		if(a[i] % 4 == 0) cnt4++;
		if(a[i] % 2) cnt1++;
	}
	if(cnt4 == 0){
		if(cnt1 == 0)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	else{
		if(cnt2 > 0){
			if(cnt1 <= cnt4)
				cout << "Yes\n";
			else
				cout << "No\n";
		}
		else{
			if(cnt1 <= cnt4 + 1)
				cout << "Yes\n";
			else
				cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

import math

op = "init"
ans = []

while (op != "?"):
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if (op == '+'):
        ans.append(a + b)
    elif (op == '-'):
        ans.append(a - b)
    elif (op == '*'):
        ans.append(a * b)
    elif (op == "/"):
        ans.append(int(a / b))

for answer in ans:
    print(answer)

Measured memory_bytes: 7740