akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli inf = 10000 * 10000;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli a, b, c, k;
	cin >> a >> b >> c >> k;

	if (k <= a) {
		cout << k << endl;
	}
	else if (k <= a + b) {
		cout << a << endl;
	}
	else if (k <= a + b + c) {
		cout << a - (k - b - a) << endl;
	}


	return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

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

        int price = 700;
        char[] S = sc.next().toCharArray();

        if (S[0] == 'o') {
            price += 100;
        }
        if (S[1] == 'o') {
            price += 100;
        }
        if (S[2] == 'o') {
            price += 100;
        }
        System.out.println(price);
    }
}

Measured memory_bytes: 35460
#include <bits/stdc++.h>
	using namespace std;
	#define all(x) (x).begin(), (x).end()
	#define allr(x) (x).rbegin(), (x).rend()
	#define pb push_back
	#define ff first
	#define ss second
	#define ll long long
	#define ld long double
	typedef pair<ll,ll> pll;
	typedef pair<pll,pll> ppll;
	typedef vector <string> vi;
	#define out(x) return cout<<x,0;
	#define precision(x,d) cout<<fixed<<setprecision(d)<<x
	#define lc(n) 2*n+1
	#define rc(n) 2*n+2
	#define fill(a,b) memset((a),(b),sizeof((a)))
	#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
	string A = "" , B = "" ;
	ll X, Y , C , n;
	vi v;

	void permute(string a, int l, int r)  
{  
    // Base case  
    if (l == r)  {
    	v.pb(a);
    }  
    else
    {  
        // Permutations made  
        for (int i = l; i <= r; i++)  
        {  
  
            // Swapping done  
            swap(a[l], a[i]);  
  
            // Recursion called  
            permute(a, l+1, r);  
  
            //backtrack  
            swap(a[l], a[i]);  
        }  
    }  
}  
	int main(){
		FAST;
	    ll k, m, z = 0, ans = 0, j, t = 0, x = 0, y = 0, c = 0, i;
	    cin >> n ;
	    string s = ""; 
	    for ( i = 0 ; i < n ; i ++ ){
	    	s += ( i + 1 + '0') ;
	    } 
	    for ( i = 0 ; i < n ; i ++ ){
	    	cin >> x;
	    	A += ( x + '0');
	    }
	    for ( i = 0 ; i < n ; i ++ ){
	    	cin >> x;
	    	B += ( x + '0');
	    } 
    	permute(s, 0, n-1); 
    	if ( A > B ) swap( A , B );
    	sort ( all (v) );
    	for ( i = 0 ; i < v.size() ; i ++ ){
    		if ( ans == 0 ){
    			if ( v[i] == A ) ans = i + 1; 
    		}
    		else{
    			if ( v[i] == B ) out( i + 1 - ans );
    		}
    	}
    	cout << 0;
	}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
#define mod      1000000007
#define pi       acos(-1.0)
typedef long long ll;
using namespace std;
int c[200000];
int main()
{      


     ios::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
     int n;
     cin>>n;
     int x;
     for(int i=1;i<n;i++)
      {
        cin>>x;
        c[x]++;
      }
      for(int i=1;i<=n;i++)
        cout<<c[i]<<endl;

      return 0;
 }       


Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int x,y,n;
     cin>>n;
    x=1000;
    while(1)
    {
        if(x>=n)
        {
            cout<<x-n<<endl;
            break;
        }
        x=x+1000;

    }

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>

int main()
{
  int N, A, B;
  int total_sum = 0;

  scanf("%d %d %d", &N, &A, &B);

  for (int i = 1; i <= N; i++)
  {
    int sum = 0;
    int num = i;
    while (num != 0)
    {
      sum += num % 10;
      num /= 10;
    }
    if (sum >= A && sum <= B)
    {
      total_sum += i;
    }
  }
  printf("%d\n", total_sum);
  return 0;
}

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

//マクロ
#define FOR(i, a, b) for(int i = (a); i < (b), i++)
#define REP(i, n) FOR(i, 0, n);
#define ALL(a) (a).begin(),(a).end()


int main(){
    
    //入力
    int n, d, x; cin >> n >> d >> x;
    vector<vector<int> > p(d, vector<int> (n));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < n; j++){
            cin >> p[i][j];
        }
    }

    int w = x;

    for(int k = 0; k < d - 1; k++){

        vector<int> weight(n);
        vector<int> value(n);
        vector<vector<int> > dp(n, vector<int> (w + 1, 0));
        for(int i = 0; i < n; i++){
            weight[i] = p[k][i];
            value[i] = p[k + 1][i] - p[k][i];
        }

        //dp
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= w; j++){
                if(i == 0){
                    if(j >= weight[i]) dp[i][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
                }else{
                    if(j >= weight[i]) dp[i][j] = max({dp[i][j - weight[i]] + value[i], dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]});
                    else dp[i][j] = dp[i - 1][j];
                }
            }
        }

        //cout << dp[n - 1][w] << endl;
        w += dp[n - 1][w];
    }

    cout << w << endl;

    return 0;
}


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

int main(){
	int A, B, C;
	cin>>A>>B>>C;
	int sum;
	if(A>=B && A>=C){
		sum = A*10+B+C;
	}	else if(B>=A && B>=C){
		sum = B*10+A+C;
	}	else{
		sum = C*10+A+B;
	}
	cout<<sum;
	return 0;
}


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

int main()
{
  int K, X;
  cin >> K >> X;
  if (K * 500 >= X)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<char,vector<ll>> p;
int main(){
    string s,t;cin>>s>>t;
    ll n=s.length();
    for(ll i=0;i<n;i++){
        p[s[i]].push_back(i);
    }
    for(ll i=0;i<26;i++){
        if(p['a'+i].size()>0){
            p['a'+i].push_back(1e9);
        }
    }
    ll ans=n,now=0;
    for(ll i=0;i<t.length();i++){
        if(p[t[i]].size()==0){
            cout<<-1<<endl;
            return 0;
        }
        else{
            ll x=*lower_bound(p[t[i]].begin(),p[t[i]].end(),now);
            if(x<n) now=x+1;
            else{
                ll x=*lower_bound(p[t[i]].begin(),p[t[i]].end(),0);
                ans+=n;now=x+1;
            }
        }
        //cout<<now<<" "<<t[i]<<endl;
    }
    cout<<ans-n+now<<endl;
}


Measured memory_bytes: 1728
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    int cou[26] = {0};
    cin >> s;
    for(unsigned int i = 0; i < s.size(); i++){
        int k = int(s[i]) - int('a');
        cou[k]++;
        if(cou[k] == 2){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

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

int main(){
  int x1,y1,x2,y2,x3,y3,x4,y4;cin>>x1>>y1>>x2>>y2;
  int x = x1-x2;
  int y = y1-y2;
  x3 = x2+y;
  x4 = x1+y;
  y3 = y2-x;
  y4 = y1-x;
  printf("%d %d %d %d",x3,y3,x4,y4);
}

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;

const int INF=1001001001;
int dp[100010];

int main(){
    int n;
    cin>>n;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    rep(i,100010)dp[i]=INF;
    dp[0]=0; dp[1]=abs(h[0]-h[1]);
    for(int i=2; i<n; ++i){
        dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000007
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define fo(i,n) for(long long int i=0;i<n;i++)
#define Fo(i,k,n) for(long long int i=k;i<n;i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x,y) fo(i,sizeof(x)/sizeof(x[0]))x[i]=y
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define uset unordered_set
#define umap unordered_map
#define endl "\n"
#define scanf(arr,n) fo(i,n)cin>>arr[i]
#define printf(x) cout<<x<<"\n"
typedef vector<int> vi;
typedef pair<int,int> pi;
void print (ll *arr, ll n) {fo(i,n){cout<<arr[i]<<" ";}cout<<"\n";}
bool isvaild (int i, int j, int n, int m) { return !( i < 0 or j < 0 or i > n-1 or j > m-1 );}

struct hash_pair {
    template<class T1, class T2>
    size_t operator()(const pair<T1,T2> &p) const 
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);

        return hash1^hash2;
    }
};
/*****************************MANASH**********************************/

umap<pi,int,hash_pair> m;


int main ()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //int t; cin>>t;
    //while (t--)
    {
        string s;
        cin>>s;
        size_t found = s.find('7');
        if(found == string :: npos) cout<<"No";
        else cout<<"Yes";
        //cout<<endl;
    }
    
	return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>

#define MAX 10000

int check_spec(double value);
 
int main (void) {
    double distance;
    double speed;
    double time;
    scanf ("%lf %lf %lf", &distance, &time, &speed);

    if (check_spec(distance) == 0 || check_spec(time) == 0 || check_spec(speed) == 0) {
        return 0;
    }
 
    if (distance/speed * 1.0 > time) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}

int check_spec(double value) {
    if (value < 0 || value > MAX) {
        return 0;
    }

    return 1;
}


Measured memory_bytes: 1712
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 3e2 + 10;

int mod;
ll dp[max_N][max_N], sum[max_N][max_N], choose[max_N][max_N];

int main() {
	int N, K;
	cin >> N >> K >> mod;	
	for (int n = 0; n <= N; ++n) {
		choose[n][0] = choose[n][n] = 1;
		for (int k = 1; k < n; ++k) {
			choose[n][k] = choose[n - 1][k] + choose[n - 1][k - 1];
			choose[n][k] %= mod;
		}
	}
	for (int x = K; x >= 0; --x) {
		dp[1][x] = 1;
		sum[1][x] = sum[1][x + 1] + dp[1][x + 1];
	}
	for (int n = 2; n <= N + 1; ++n) {
		for (int x = K; x >= 0; --x) {
			for (int k = 1; k < n; ++k) {
				ll temp = (dp[n - k][x] * sum[k][x]) % mod;
				dp[n][x] += temp * choose[n - 2][k - 1];
				dp[n][x] %= mod;
			}
			sum[n][x] = (sum[n][x + 1] + dp[n][x + 1]) % mod;
		}
	}
	cout << dp[N + 1][0];
}


Measured memory_bytes: 2432
import numpy as np

N=int(input())
X=list(map(int, input().split()))
Xs=np.array([[X[i], i] for i in range(N)])
Xs=Xs[np.argsort(Xs[:, 0]), :]
p=Xs[N//2, 0]
pi=Xs[N//2, 1]
q=Xs[N//2-1, 0]
for i in range(N):
  if X[i]<p:
    print(p)
  elif X[i]>p:
    print(q)
  else:
    if i<pi:
      print(p)
    else:
      print(q)

Measured memory_bytes: 50416
def lu(n):
  L.append(n)
  a=n%10
  if len(str(n))>11:
    return 1
  if a==0:
    lu(n*10+1)
    lu(n*10)
  elif a==9:
    lu(n*10+9)
    lu(n*10+8)
  else:
    lu(n*10+1+a)
    lu(n*10+a-1)
    lu(n*10+a)
L=list()
lu(1)
lu(2)
lu(3)
lu(4)
lu(5)
lu(6)
lu(7)
lu(8)
lu(9)
L=sorted(set(L))
k=int(input())
print(L[k-1])

Measured memory_bytes: 239696
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M), c(M);
    rep(i, M) cin >> s[i] >> c[i];
    rep(i, 1000) {
        if (N == 1 && i > 9) break;
        if (N == 2 && i < 10) continue;
        if (N == 2 && i > 99) break;
        if (N == 3 && i < 100) continue;
        string t = to_string(i);
        bool f = false;
        rep(j, M) {
            if ((int) (t[s[j] - 1] - '0') != c[j]) f = true;
        }
        if (f) continue;
        cout << i << endl;
        return 0;
    }
    cout << "-1\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <queue> 
using namespace std;
int main(void){
    int n,i,sum1=0,sum2=0,ans=10000000;
    cin>>n;
    int w[n];
    for(i=0;i<n;i++){
        cin>>w[i];
        sum1+=w[i];
    }
    for(i=0;i<n;i++){
        sum2+=w[i];
        sum1-=w[i];
        ans=min(ans,abs(sum1-sum2));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) (c).begin(), (c).end()
#define mt make_tuple
#define pb push_back

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> A(n);
  vector<pair<int, int>> B(m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < m; ++i) {
    int b, c;
    scanf("%d %d", &b, &c);
    B[i].first = c;
    B[i].second = b;
  }
  sort(B.begin(), B.end());
  vector<int> C(n, 0);
  int c = 0;
  for (int i = m - 1; i >= 0; --i) {
    int v = B[i].first;
    int num = B[i].second;
    num = min(n - c, num);
    for (int j = c; j < c + num; ++j) C[j] = v;
    c += num;
  }
  vector<int> D(n + c);
  rep(i, n) D[i] = A[i];
  rep(i, c) D[n + i] = C[i];
  sort(D.begin(), D.end(), greater<int>());
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += D[i];
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 2560
/* ITP1_5_B */
import java.io.*;

class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while(true){
      //input
      String str[] = br.readLine().split(" ");
      int height = Integer.parseInt(str[0]);
      int width = Integer.parseInt(str[1]);
      //finish
      if(height == 0 && width == 0) break;
      if(height < 3 && width > 100) break;
      //draw
      for(int i = 0; i < height; i++){ //height

        for(int j = 0; j < width; j++){ //width

          if(i == 0 || i == height-1){
            System.out.print("#");

          }else {
            if(j == 0 || j== width-1)
              System.out.print("#");
            else
              System.out.print(".");
          }
        }
        System.out.println("");
      }
      System.out.println("");
    }
  }
}

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

# define x first    
# define y second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector         
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;
       
int a[Sz * 10], b[Sz * 10];
                   
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n;      
  for (int i = 1; i <= n; i++) {
    int x; cin >> x;
    a[x] = b[x] = i;
  }
  int ptr = 1;                     
  for (int i = 1; i <= n*n; i++) {
    if (b[i]) {  
      for (int j = 1; j < b[i]; j++) {
        while (a[ptr] && ptr < i)
          ptr++;
        if (ptr >= i) {
          cout << "No"; return 0;
        }    
        assert (a[ptr] == 0);
        a[ptr] = b[i];
      }
    }
  }   
  ptr = n * n;
  for (int i = n*n; i >= 1; i--) {
    if (b[i]) {
      for (int j = 1; j <= n - b[i]; j++) {
        while (a[ptr])
          ptr--;
        if (ptr <= i) {
          cout << "No"; return 0;
        }
        assert (a[ptr] == 0);
        a[ptr] = b[i];
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i <= n*n; i++)
    cout << a[i] << ' ';        


  return 0;
}






// Coded by Z..



Measured memory_bytes: 3968
import java.util.*;

public class Main{

    public static void main(String[] args)  {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int res = a/b;
            if(res*b<a){
                ++res;
            }
            System.out.println(res);
    }
}



Measured memory_bytes: 21972
#include <iostream>
using namespace std;
#define N_MAX 100
int F[N_MAX][10]={0};
int P[N_MAX][11]={0};

int main(){
  int N,bits,i,k,j;
  cin >> N;
  for(i=0;i<N;i++){
    for(k=0;k<10;k++){
      cin >> F[i][k];
    }
  }
  for(i=0;i<N;i++){
    for(k=0;k<11;k++){
      cin >> P[i][k];
    }
  }
  long int sum=0,Pmax=-(1<<30);
  for(i=1;i<(1<<10);i++){
    sum=0;
    for(k=0;k<N;k++){
	  int cnt=0;
      for(j=0;j<10;j++){
        if(i & 1<<j)cnt+=F[k][j]; 
      }
      sum+=P[k][cnt];
    }
    Pmax=max(Pmax,sum);
  }
  cout << Pmax << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int n , a[N] , b[N];
int main()
{
	abdelrahman010
	cin >> n;
	for(int i = 0;i <= n;i++)
		cin >> a[i];
	for(int i = 0;i < n;i++)
		cin >> b[i];
	ll ans = 0;
	for(int i = 0;i < n;i++)
	{
		ans += 1ll * min(a[i] , b[i]);
		b[i] -= min(a[i] , b[i]);
		ans += 1ll * min(a[i + 1] , b[i]);
		a[i + 1] -= min(a[i + 1] , b[i]);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FO(i, a, b) for(int i = a; i <= b; i++)
#define FE(i, a, b) for(int i = a; i < b; i++)
#define FR(i, a, b) for(int i = a; i >= b; i--)
#define R(i) i = read()

using namespace std;

int read() {
	int x = 0; char c = getchar();
	while(c != '-' && (c < 48 || c > 57)) c = getchar();
	if(c == '-') {c = getchar(); while(c >= 48 && c <= 57) x = x * 10 - c + 48, c = getchar();}
	else while(c >= 48 && c <= 57) x = x * 10 + c - 48, c = getchar();
	return x;
}

const int N = 500005;

char c[N];
int l[N], r[N], pd[N], f[N];
int n, cnt;

int main() {
//	freopen("data.in", "r", stdin);
	cin >> n;
	scanf("%s", c + 1);
	FO(i, 1, n) 
		pd[i] = (c[i] == '0' && c[i - 1] == '1' && c[i + 1] == '1');
	FO(i, 1, n)
		if(c[i] == '1') l[i] = cnt, cnt++;
		else{
			if(pd[i]) l[i] = cnt;
			cnt = 0;
		}
	cnt = 0;
	FR(i, n, 1)
		if(c[i] == '1') r[i] = cnt, cnt++;
		else{
			if(pd[i]) r[i] = cnt;
			cnt = 0;
		}
	FO(i, 1, n) {
		f[i] = max(f[i], f[i - 1]);
		if(c[i] == '0') {
			if(pd[i])	{
				f[i + 1] = max(f[i + 1], f[i - l[i] - 1] + l[i]);
				f[i + 1] = max(f[i + 1], f[i - l[i]] + l[i] - 1);
			}
		}
		else 
			f[i] = max(f[i], pd[i - l[i] - 1] ? (f[i - l[i] - 3] + l[i] + 1) : 0);
	}
	int ans = 0;
	FO(i, 1, n) 
		ans = max(ans, f[i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 8576
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
       // int d = new int[K];
       List<Integer> a = new ArrayList<>();
        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
			for (int j = 0 ; j < d ;j++){
				int c = sc.nextInt();
			if (!a.contains(c))	a.add(c);
            }
        }
		System.out.println(N - a.size());
	}
}

Measured memory_bytes: 46628
#include <cstdio>
#include <algorithm>

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

const int maxn=100;

int n,a[maxn+10],x;

int main()
{
  n=read();
  x=read();
  for(int i=1; i<=n; ++i)
    {
      a[i]=read();
    }
  std::sort(a+1,a+n+1);
  for(int i=1; i<=n; ++i)
    {
      if(x<a[i])
        {
          printf("%d\n",i-1);
          return 0;
        }
      x-=a[i];
    }
  if(x>0)
    {
      printf("%d\n",n-1);
    }
  else
    {
      printf("%d\n",n);
    }
  return 0;
}


Measured memory_bytes: 128
import sys
def main():
    r = 0
    d = 0
    for line in sys.stdin:
        A = list(map(int, line.split(",")))
        if A[0] == A[1]:
            d += 1
        else:
            if A[0] ** 2 + A[1] ** 2 == A[2] ** 2:
                r += 1

    print(r)
    print(d)



if __name__ == "__main__":
    main()


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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; j < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  int n, h[100];
  cin >> n;
  repi(n) cin >> h[i];
  int re = 0;
  while (true) {
    bool allzero = true;
    int l = -1, r = -1;
    repi(n) {
      if (h[i]) {
        allzero = false;
        if (l == -1) l = i;
      } else if (l >= 0) {
        r = i;
        break;
      }
    }
    if (allzero) break;
    if (r == -1) r = n;
    re++;
    repr(i, l, r) h[i]--;
  }
  cout << re << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <limits>
#include <type_traits>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

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

	int g = gcd(a, b);

	int t = 1;
	while (1)
	{
		if (g % t == 0)
		{
			k--;
			if (k == 0)
			{
				break;
			}
		}
		t++;
	}
	cout << (g / t) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<ll, ll>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;
const ll MAXN = 100005;

struct Edge {
    ll to;
    ll a;
    ll b;
    Edge(ll to, ll a, ll b): to(to), a(a), b(b) {}
};
vector<Edge> g[MAXN];
ll da[MAXN];
ll db[MAXN];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g[u].eb(v, a, b);
        g[v].eb(u, a, b);
    }
    rep(i, n) {
        da[i] = INFll;
        db[i] = INFll;
    }
    queue<P> q1;
    q1.emplace(s, 0);
    da[s] = 0;
    while (!q1.empty()) {
        P now = q1.front();
        q1.pop();
        ll v = now.fi;
        ll d = now.se;
        if (d!=da[v]) continue;
        for (auto e: g[v]) {
            ll iv = e.to;
            ll id = d + e.a;
            if (chmin(da[iv], id)) {
                q1.emplace(iv, id);
            }
        }
    }
    queue<P> q2;
    q2.emplace(t, 0);
    db[t] = 0;
    while (!q2.empty()) {
        P now = q2.front();
        q2.pop();
        ll v = now.fi;
        ll d = now.se;
        if (d!=db[v]) continue;
        for (auto e: g[v]) {
            ll iv = e.to;
            ll id = d + e.b;
            if (chmin(db[iv], id)) {
                q2.emplace(iv, id);
            }
        }
    }
    vector<ll> cost(n);
    rep(i, n) {
        cost[i] = da[i] + db[i];
    }
    vector<ll> ans(n);
    rrep(i, n) {
        if (i==n-1) ans[i] = cost[i];
        else {
            ans[i] = min(ans[i+1], cost[i]);
        }
    }
    
    ll z = (ll)1E+15;
    rep(i, n) pr(z-ans[i]);
    return 0;
}


Measured memory_bytes: 15592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int INF = 1<<29;

int main(){
    int N,M; cin >> N >> M;

    vector<int> a(M), b(M), c(M);
    vector<vector<int>> graph(N+1, vector<int>(N+1, INF));
    
    
    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i] >> c[i];
        graph[a[i]][b[i]] = c[i];
        graph[b[i]][a[i]] = c[i];
    }
    for(int i=1; i<=N; i++) graph[i][i] = 0;

    for(int k=1; k<=N; k++){
        for(int i=1; i<=N; i++){
            if(graph[i][k] == INF) continue;

            for(int j=1; j<=N; j++){
                if(graph[k][j] == INF) continue;

                graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i=0; i<M; i++){
        bool flg = false;
        for(int s=1; s<=N; s++){
            for(int g=1; g<=N; g++){
                if(graph[s][g] == graph[s][a[i]]+c[i]+graph[b[i]][g]) flg = true;
            }
        }
        if(flg == false) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n, m;
  cin >> n >> m;
  int flg = n % 2 == 0;
  int l = 1, r = n - 1;
  for(int i = 0; i < m; ++i){
  	if(flg && (r - l == n / 2 || r - l == n / 2 - 1))--r;
  	cout << l << " " << r << endl;
  	++l;
  	--r;
  }
  return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int X=sc.nextInt();
		int Y=sc.nextInt();
		
		if(N>K) System.out.println(X*K+Y*(N-K));
		else    System.out.println(X*N);
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
  double a,b,c,d,e,f,x,y;
  while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
    y = (a*f - c*d)/(a*e - d*b);
    x = (c - b*y)/a;
    printf("%.3f %.3f\n",x,y);
  }
}

Measured memory_bytes: 1080
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;
vector<double> p;

double dp[3100][3100];

void solve() {
	dp[0][0] = 1.0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i + 1][j + 1] += dp[i][j] * p[i];
			dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
		}
	}

	double ans = 0.0;
	for (int i = (n + 1)/2; i <= n; i++) ans += dp[n][i];

	printf("%.12f\n", ans);
}

int main(void){
	cin>>n;
	p.resize(n);
	for (int i = 0; i < n; i++) cin>>p[i];
	
	solve();

	return 0;
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

int main()
{
    int x,n;
    cin >> x >> n;
    map<int,int>mp;
    REP(i,n) {
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    int a = x, b = x;
    while(true){
        if(mp[a]==0) {
            cout << a;
            break;
        }
        else if(mp[b]==0){
            cout << b;
            break;
        }
        a--;
        b++;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,A;cin >> N >> A;
  cout << N*N - A << endl;
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<char> = s.trim().chars().collect();

    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let u: Vec<char> = s.trim().chars().collect();

    let mut w: Vec<char> = v.clone();
    let mut b: bool = true;
    let mut d: bool = false;
    let mut i: isize = v.len() as isize - u.len() as isize;
    loop {
        if i < 0 {break;}
        for j in 0..u.len() {
            if v[(i as usize)+j] != '?' && v[(i as usize)+j] != u[j] {b = false; break;}
        }
        if b {
            for j in 0..u.len() {w[(i as usize)+j] = u[j];}
            d = true;
            break;
        }
        b = true;
        i -= 1;
    }
    if !d {println!("UNRESTORABLE"); return;}
    for e in &w {
        print!("{}", if *e == '?' {'a'} else {*e});
    }
    println!("");
}



Measured memory_bytes: 4352
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
string s;

int main(){
    cin >> n;
    cin >> s;
    int ans = 1;
    char pre = (char)s[0];
    for(int i = 1;i < n;i++){
        if(s[i] == pre)continue;
        pre = (char)s[i];
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(d.begin(), d.end());

  int ind = n / 2;

  int res = d[ind] - d[ind - 1];
  cout << res;

  return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b;
	scanf("%d %d", &a, &b);
	if (a<b) {
		if (a==1) {
			printf("Alice\n");
		} else {
			printf("Bob\n");
		}
	} else if (b<a) {
		if (b==1) {
			printf("Bob\n");
		} else {
			printf("Alice\n");
		}
	} else {
		printf("Draw\n");
	}
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;

vector <int> vect;

int main()
{
    SRK;
    string S;
    cin >> S;
    if (S[0] != 'R' && S[1] != 'R' && S[2] != 'R')
    {
        cout << "0\n";
    }
    else if (S[1] == 'R')
    {
        if (S[0] == 'R')
        {
            if (S[2] == 'R')
            {
                cout << "3\n";
            }
            else
            {
                cout << "2\n";
            }
        }
        else if (S[2] == 'R')
        {
            cout << "2\n";
        }
        else
        {
            cout << "1\n";
        }
    }
    else
    {
        cout << "1\n";
    }
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

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

	vector<long long> a(n);
	long long s = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		s += a[i];
	}

	vector<long long> f(n);
	int fmin = 1e6 + 1;
	for (int i = 0; i < n; ++i) {
		cin >> f[i];
		if (f[i] < fmin) {
			fmin = f[i];
		}
	}

	sort(a.begin(), a.end());
	sort(f.begin(), f.end());

	long long maxProduct = 0;
	for (int i = 0; i < n; i++) {
		int p = a[i] * f[n - i - 1];
		if (p > maxProduct) {
			maxProduct = p;
		}
	}

	long long start = 0;
	long long end = 1e12;
	while (start < end) {
		long long lim = (start + end) / 2;
		long long count = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] * f[n - i - 1] > lim) {
				count += a[i] - lim / f[n - i - 1];
			}
		}

		if (count <= k) {
			end = lim;
		}
		else {
			start = lim + 1;
		}
	}

	cout << end;

	return 0;
}


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

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    long long int ans = 0;
    if(A+B <= C*2){
        ans = A*X+B*Y;
    }
    else{
        int m = min(X, Y);
        ans += C*2*m;
        X -= m;
        Y -= m;

        ans += min(A,C*2)*X;
        ans += min(B,C*2)*Y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll INF = (ll)1e16;
const int N = 200200;
int n, m;
vector<pii> g[N];
bool used[N];
ll a[N];
ll L, R;

bool dfs(int v) {
	if (v < n)
		L = max(L, -a[v]);
	else
		R = min(R, a[v]);
	used[v] = 1;
	for (pii e : g[v]) {
		int u = e.first;
		int w = e.second;
		if (used[u]) {
			if (a[v] + a[u] != w) return false;
		} else {
			a[u] = w - a[v];
			if (!dfs(u)) return false;
		}
	}
	return true;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int k;
	scanf("%d%d%d", &n, &m, &k);
	while(k--) {
		int x, y, w;
		scanf("%d%d%d", &x, &y, &w);
		x--;y--;
		g[x].push_back(mp(n + y, w));
		g[n + y].push_back(mp(x, w));
	}
	for (int v = 0; v < n; v++) {
		if (used[v]) continue;
		L = -INF; R = INF;
		if (!dfs(v) || L > R) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 17244
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N;
  cin >> N;
  int M = -1, m = pow(10, 9) + 7;
  for (int i = 0; i < N; i++)
  {
    int A, B;
    cin >> A >> B;
    chmax(M, A);
    chmin(m, B);
  }
  
  int ans = M + m;
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    // 標準入力
    ll l, r;
    cin >> l >> r;

    ll start = max(l, r - 2019);

    // ループスタート（結果にはあまりの最大値である2018をいれておく）
    int res = 2018;
    for (ll i = start; i < r; i++) {
        for (ll j = i + 1; j <= r; j++) {
            res = (res > i * j % 2019) ? i * j % 2019 : res;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll s,w;
    // ll ans=0;
    scanf("%lld%lld",&s,&w);
    // ll [n];
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    if(w>=s){
        printf("unsafe\n");
    }else{
        printf("safe\n");
    }


    
    // printf("%lld\n");
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
using namespace std;
int main(){
	string c;
	getline(cin,c);
	int l=0,k=c.length();
	for(int i=0;i<k/2;i++){
	if(c[i]!=c[k-i-1]){
	     l++;
	}
}
     cout<<l;

}
	


Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Tue Mar 31 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        long N = in.nextLong();
        long A = in.nextLong();
        long B = in.nextLong();

        long ans = A * (N/(A+B)) + Math.min(A, N % (A+B));
        println(ans);
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 23508
#include<stdio.h>
int main()
{
    int len,i;
    char a[100000];

    while (gets(a))
    {len=strlen(a);
        for (i=0; i<len; i++)
        {
            if(i==0)
                printf("%c",a[i]);
            else if (i%2==0)
            {
                printf("%c",a[i]);
            }
        }
    }
}



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

int main() {
  for(int tci = 0;; tci++) {
    int N,M; scanf("%d%d", &N, &M); if(!N) break;
    pair<int,int> *pd = new pair<int,int>[N];
    int ept = 0;
    for(int i = 0; i < N; i++) {
      scanf("%d%d", &pd[i].second, &pd[i].first);
      ept += pd[i].second * pd[i].first;
    }
    sort(pd, pd+N);
    reverse(pd, pd+N);
    int x = M;
    for(int i = 0; i < N && x > 0; i++) {
      ept -= min(pd[i].second, x) * pd[i].first;
      x -= pd[i].second;
    }
    printf("%d\n", ept);
  }
  return 0;
}

Measured memory_bytes: 1756