akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    vector<int> h(n);
    cin>>h.at(0);
    for(int i=1; i<n; i++){
        cin>>h.at(i);
        if(h.at(i-1)>=h.at(i)) cnt++;
        else cnt=0;
        ans=max(cnt, ans);
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

class SEGTREE{
        ll n, dflt;
  		vector<ll> dat;
    public:
    	SEGTREE(unsigned long _n, unsigned long _max_n, ll _a) : dat(_max_n, _a){
    	    n = 1;
    	    dflt = _a;
    	    while(n < _n) n *= 2;
        }
        void update(ll k, ll a){
            k += n - 1;
            dat[k] = a;
            while(k > 0){
                k = (k - 1) / 2;
                dat[k] = min(dat[k*2 + 1], dat[k * 2 + 2]);
            }
        }
        ll Q(ll a, ll b){
    	    return query(a, b, 0, 0, n);
    	}
        ll query(ll a, ll b, ll k, ll l, ll r){
            if(r <= a || b <= l) return dflt;
            if(a <= l && r <= b) return dat[k];
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
};
/*ll MAX_N = 400010, n;
vec dat(MAX_N,INF);
void init(ll _n){
    n = 1;
    while(n < _n) n *= 2;
    rep(i, n*2 - 1) dat[i] = INF;
}

void update(ll k, ll a){
    k += n - 1;
    dat[k] = a;
    while(k > 0){
        k = (k - 1) / 2;
        dat[k] = min(dat[k*2 + 1], dat[k * 2 + 2]);
    }
}

ll query(ll a, ll b, ll k, ll l, ll r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return dat[k];
    ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
}*/

int main() {
    cin>>N>>M;
    vec l(M), r(M), c(M);
    rep(i,M) cin>>l[i]>>r[i]>>c[i];
    vec ord(M);
    rep(i,M) ord[i] = i;
    sort(ALL(ord) , [&](ll x, ll y){
        return l[x] < l[y];
    });
    SEGTREE tre(N + 10, 400010, INF);
    tre.update(1,0);
    rep(i,M){
        ll id = ord[i];
        ll last_dist = tre.Q(l[id], N + 1);
        //cout<<i<<' '<<last_dist<<endl;
        tre.update(r[id], min(tre.Q(r[id], r[id] + 1), last_dist + c[id]));
    }
    ll ans = tre.Q(N, N + 1);
    cout<<(ans == INF ? -1 : ans)<<endl;
    //reps(i,1,N + 1) cout<<tre.Q(i, i + 1)<<endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  int ans = 1;
  for (int i = 2; i <= n; i++) {
    (ans *= i) %= (int)(1e9 + 7);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main{
  static long n;
  static long a, b, c, d;

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

    n = sc.nextInt();
    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();
    d = sc.nextInt();

    long diff = Math.abs(a - b);
    for(long i = 0; i < n - 1; i++){
      if(c * (n - i - 1) - d * i <= diff &&
        diff <= d * (n - i - 1)  - c * i){
        System.out.println("YES");
        return;
      }
    }

    System.out.println("NO");
  }
}

Measured memory_bytes: 23764
# ALDS1_11_B: Depth First Search

class Timer
  def initialize(start = 0)
    @time = start
  end

  def next
    @time += 1
  end
end

class DepthFirstSearcher
  def initialize(graph)
    @graph = graph
  end

  def search_by(method_name, found, finished)
    last  = @graph.size - 1
    timer = Timer.new
    proc  = self.method "#{method_name.to_s}_search"
    (1..last).each do |id|
      proc.call(id, found, finished, timer)
    end
  end

  private

    def recursive_search(id, found, finished, timer)
      return unless found[id].nil?

      found[id] = timer.next
      @graph[id].each do |d_id|
        recursive_search d_id, found, finished, timer
      end
      finished[id] = timer.next
    end

    def stack_search(id, found, finished, timer = Timer.new)
      return unless found[id].nil?

      stack = [id]
      found[id] = timer.next

      until stack.empty?
        id = stack.last
        next_id = @graph[id].find do |d_id|
          found[d_id].nil?
        end

        if next_id.nil?
          finished[id] = timer.next
          stack.pop
        else
          if found[next_id].nil?
            stack.push next_id
            found[next_id] = timer.next
          end
        end
      end
    end
end

n_vertexes = gets.to_i
max_v      = n_vertexes + 1
graph      = Array.new, max_v

n_vertexes.times do
  id, n_adjs, *adjs = gets.split.map &:to_i
  graph[id] = adjs
end

searcher = DepthFirstSearcher.new graph
found    = Array.new max_v
finished = Array.new max_v
searcher.search_by :stack, found, finished

(1..n_vertexes).each do |id|
  puts "#{id} #{found[id]} #{finished[id]}"
end

Measured memory_bytes: 8700
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)

int n, in[26], out[26], G[26][26];
bool visited[26];

bool check(){
    rep(i, 26) if ( in[i] != out[i] ) return false;
    return true;
}

void dfs(int u){
    visited[u] = true;
    rep(v, 26) if ( !visited[v] && G[u][v] ) dfs(v);
}

int getNComponent(){
    int nc = 0;
    rep(i, 26){
	if ( in[i] == 0 && out[i] == 0 ) continue;
	if ( !visited[i] ){ nc++; dfs(i); }
    }
    return nc;
}

int main(){
    while( cin >> n && n ){
	rep(i, 26){
	    in[i] = out[i] = 0;
	    visited[i] = false;
	    rep(j, 26) G[i][j] = 0;
	}
	
	string str;
	rep(i, n){
	    cin >> str;
	    in[str[0]-'a']++;
	    out[str[str.size()-1]-'a']++;
	    G[str[0]-'a'][str[str.size()-1]-'a'] = 1;
	    G[str[str.size()-1]-'a'][str[0]-'a'] = 1;
	}
	
	cout << (( check() && getNComponent() == 1 )?"OK":"NG") << endl;
    }
    return 0;
}

Measured memory_bytes: 912
import sys
import math
from fractions import gcd

a,b,c,d = (int(i) for i in input().split())

c1 = b // c - (a - 1) // c
d1 = b // d - (a - 1) // d
cd = (c * d) //gcd(c,d)
cd1 = b // cd - (a - 1) // cd



print((b - a + 1) - c1 - d1 + cd1)

Measured memory_bytes: 5076
#include <stdio.h>

int main(void)
{
	int n, s;
	int sum;
	int min, max;
	int i;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		sum = 0;
		min = 1000;
		max = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &s);
			sum += s;
			
			if (min > s){
				min = s;
			}
			if (max < s){
				max = s;
			}
		}
		sum = sum - min - max;
		
		printf("%d\n", sum / (n - 2));
	}
	return (0);
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;

Node treeMinimum(Node x){
while(x->left!=NIL){
x=x->left;
}
return x;
}

Node treeSearch(Node u, int k){  
if(u==NIL || k==u->key){
return u;
}
if(k<u->key){
return treeSearch(u->left,k);
}
 else{
return treeSearch(u->right,k);
}

}

Node treeSuccessor(Node x){
Node y;  
if(x->right!=NIL){
return treeMinimum(x->right);
}
y=x->parent;
while(y!=NIL && x==y->right){
x=y;
y=y->parent;
}
return y;
}

void treeDelete(Node z){
Node y; // node to be deleted
Node x; // child of y
if(z->left==NIL || z->right==NIL){
y=z;
}
 else{
y=treeSuccessor(z);
}
if(y->left!=NIL){
x=y->left;
}
 else{
x=y->right;
}
if(x!=NIL){
x->parent=y->parent;
}
if(y->parent==NIL){
root=x;
}
 else if(y==y->parent->left){
y->parent->left=x;
}
 else{
y->parent->right=x;
}
if(y!=z){
z->key=y->key;
}


}

void insert(int k){
Node y = NIL;
Node x = root;
Node z;

z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL;
z->right = NIL;
while(x!=NIL){
y=x;
if(z->key < x->key){
x=x->left;
}
 else{
x=x->right;
}
z->parent=y;
}
if(y==NIL){
root=z;
}
 else if(z->key < y->key){
y->left=z;
}
 else{
y->right=z;
}
}

void inorder(Node u){
if(u!=NIL){
inorder(u->left);
printf(" %d",u->key);
inorder(u->right);
}
}
void preorder(Node u){
if(u!=NIL){
printf(" %d",u->key);
preorder(u->left);
preorder(u->right);
}
}


int main(){
int n, i, x;
char com[20];
scanf("%d", &n);

for ( i = 0; i < n; i++ ){
scanf("%s", com);
if ( com[0] == 'f' ){
scanf("%d", &x);
Node t = treeSearch(root, x);
if ( t != NIL ) printf("yes\n");
 else printf("no\n");
} else if ( com[0] == 'i' ){
scanf("%d", &x);
insert(x);
} else if ( com[0] == 'p' ){
inorder(root);
printf("\n");
preorder(root);
printf("\n");
} else if ( com[0] == 'd' ){
scanf("%d", &x);

}
}

return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long l,r,i,val,j;
    cin>>l>>r;
    long long minn=((l%2019)*((l+1)%2019))%2019;
    for(i=l;i<r;i++){
        if(minn==0){
                break;
            }
        for(j=i+1;j<=r;j++){
            val=((i%2019)*(j%2019))%2019;
            if(val<minn){
                minn=val;
            }
            if(minn==0){
                break;
            }
            
        }
    }
    cout<<minn;
    return 0;
}

//  long long result = ((l%2019)*((l+1)%2019))%2019;

// for(i=l;i<=r-1;i++){
//   if(result == 0){
//     break;
//   }
//   for(j=i+1;j<=r;j++){
//     if(result == 0){
//       break;
//     }
//     if(result > ((i%2019)*(j%2019))%2019){
//       result = ((i%2019)*(j%2019))%2019;
//       cout<<"i "<<i<<"j: "<<j<<endl;
//     }
//   }
// }
// cout<<result;
// return 0;
// }
 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int a[3];
    REP(i, 3)
    cin >> a[i];

    sort(a, a + 3);

    int ans = a[0] + a[1] + a[2] * 10;

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


Measured memory_bytes: 256
import sys
import numpy as np


def main():
    n, k = [int(x) for x in input().split()]
    if k == 0:
        print(n * n)
        sys.exit()
    ans = 0
    for b in range(k + 1, n + 1):
        ans += ((b - k) * (n // b)) + max(0, (n % b) - k + 1)
    print(ans)


main()


Measured memory_bytes: 12448
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define map map <int,int> 
#define hashmap unordered_map <int,int>
#define Set set <int>
#define hashset unordered_set <int> 
#define array vector <int> 
#define Pair pair<int,int>
using namespace std;

// void minput(int mat[][],int n,int m)
// {
//     for(int i=0;i<n;i++)
//     {
//         for(int j=0;j<m;j++)
//         cin>>mat[i][j];
//     }
// }

// void minput(int mat[][],int n,int m)
// {
//     for(int i=0;i<n;i++)
//     {
//         for(int j=0;j<m;j++)
//         cout<<mat[i][j]<<" ";
//         cout<<endl;
//     }
// }

void input(int arr[],int n)
{
    for(int i=0;i<n;i++)
    cin>>arr[i];
}

void output(int arr[],int n)
{
    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    
    cout<<endl;
}


int main() 
{
    int nusoc,req;
    int soc = 0,actual = 1;
    cin>>nusoc>>req;
    while(actual < req)
    {
        soc += 1;
        actual = actual + nusoc - 1;
    }
    cout<<soc<<endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int main()
{
    int n,m;
    si(n),si(m);
    int a[n];
    priority_queue<int> pq;
    for(int i=0;i<n;i++)
    {
        si(a[i]);
        pq.push(a[i]);
    }
    while(m--)
    {
        int x = pq.top();
        pq.pop();
        x = x/2;
        pq.push(x);
    }
    ll ans = 0;
    while(!pq.empty())
    {
        ll x = pq.top();
        pq.pop();
        ans += x;
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 1148
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;


int main() {
	int n;
	cin >> n;
	vector<pii> w(n);
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		w[i] = make_pair(b, a);
	}
	SORT(w);

	ll now = 0;
	bool fin = true;
	REP(i, n) {
		now += w[i].second;
		if (now > w[i].first) {
			fin = false;
			break;
		}
	}

	if (fin == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b,ans=0x7ffffff;
int main(){
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		int c,d;
		cin>>c>>d;
		if(d<=b) ans=min(ans,c);
	}
	if(ans==0x7ffffff) cout<<"TLE";
	else cout<<ans;
}


Measured memory_bytes: 256
/*ABC*/
#include<stdio.h>
int main(){
  int n,m,i;
  scanf("%d %d",&n,&m);
  int a[m],b[m];
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  int ans;
  for(int j=1;j<n+1;j++){
    ans=0;
    for(i=0;i<m;i++){
      if(a[i]==j)ans++;
      if(b[i]==j)ans++;
    }
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 128
#include <float.h>
#include <math.h>
#include <stdio.h>

int rel_l_l( double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double *x, double *y ) {
	double a, b, c, d;
	int rel;

	if ( x0 != x1 ) {
		a = ( y0 - y1 ) / ( x0 - x1 );
		b = ( x0 * y1 - x1 * y0 ) / ( x0 - x1 );
	}
	if ( x2 != x3 ) {
		c = ( y2 - y3 ) / ( x2 - x3 );
		d = ( x2 * y3 - x3 * y2 ) / ( x2 - x3 );
	}

	rel = 0;
	if ( x0 == x1 ) {
		*x = x0;
		if ( x2 == x3 )
			if ( x0 == x2 )
				rel = 2;
			else
				rel = 1;
		else {
			*y = c * *x + d;
			if ( c == 0.0 )
				rel = 3;
		}
	} else {
		if ( x2 == x3 ) {
			*x = x2;
			if ( a == 0.0 )
				rel = 3;
		} else
			if ( a == c )
				if ( b == d )
					rel = 2;
				else
					rel = 1;
			else {
				*x = ( -b + d ) / ( a - c );
				if ( fabs( a * c + 1.0 ) < DBL_EPSILON )
					rel = 3;
			}
		*y = a * *x + b;
	}

	return rel;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		int rel;
		double x0, y0, x1, y1, x2, y2, x3, y3, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel = rel_l_l( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );

		printf( "%d\n", rel == 0 ? 0 : rel == 1 || rel == 2 ? 2 : 1 );
	}

	return 0;
}

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

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

  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < N - M + 1; j++) {
      bool flag = true;
      for (int r = 0; r < M; r++) {
        for (int c = 0; c < M; c++) {
          if (A[i+r][j+c] != B[r][c]) flag = false;
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  B - Bingo
//
//  Created by Hashizo on 2020/03/01.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {

	vector<vector<ll>> bingo(3, vector<ll>(3));

	REP(i, 3) {
		REP(j, 3) {
			cin >> bingo[i][j];
		}
	}
	

	ll n;
	cin >> n;

	bool flg = false;
	ll point;
	REP(k, n) {
		cin >> point;

		REP(i, 3) {
			REP(j, 3) {
				if (bingo[i][j] == point) {
					bingo[i][j] = 0;
					flg = true;
					break;
				}
			}
			if (flg == true) {
				flg = false;
				break;
			}
		}
	}

	
	if ((bingo[0][0] == 0 && bingo[0][1] == 0 && bingo[0][2] == 0) ||
		(bingo[1][0] == 0 && bingo[1][1] == 0 && bingo[1][2] == 0) ||
		(bingo[2][0] == 0 && bingo[2][1] == 0 && bingo[2][2] == 0) ||
		(bingo[0][0] == 0 && bingo[1][0] == 0 && bingo[2][0] == 0) ||
		(bingo[0][1] == 0 && bingo[1][1] == 0 && bingo[2][1] == 0) ||
		(bingo[0][2] == 0 && bingo[1][2] == 0 && bingo[2][2] == 0) ||
		(bingo[0][0] == 0 && bingo[1][1] == 0 && bingo[2][2] == 0) ||
		(bingo[2][0] == 0 && bingo[1][1] == 0 && bingo[0][2] == 0)) {
		
		cout << "Yes" << endl;
		return 0;

	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

from decimal import Decimal
a, b = map(Decimal, input().split())
print(int(a*b))

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    REP(i, 3) {
        if (S[i] != T[2 - i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int H,W;
string f[2010];
int u[2010][2010];
int d[2010][2010];
int l[2010][2010];
int r[2010][2010];
int calc(int x,int y){
	return l[x][y]+r[x][y]+u[x][y]+d[x][y]+1;
}
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++)cin >> f[i];
	for(int i=0;i<W;i++){
		if(f[0][i]=='#')u[0][i]=-1;
		else u[0][i]=0;
	}
	for(int i=1;i<H;i++){
		for(int j=0;j<W;j++){
			if(f[i][j]=='#')u[i][j]=-1;
			else u[i][j] = u[i-1][j]+1; 
		}
	}
	for(int i=0;i<W;i++){
		if(f[H-1][i]=='#')d[0][i]=-1;
		else d[0][i]=0;
	}
	for(int i=H-2;i>=0;i--){
		for(int j=0;j<W;j++){
			if(f[i][j]=='#')d[i][j]=-1;
			else d[i][j] = d[i+1][j]+1; 
		}
	}
	for(int i=0;i<H;i++){
		if(f[i][0]=='#')l[i][0]=-1;
		else l[i][0]=0;
	}
	for(int i=0;i<H;i++){
		for(int j=1;j<W;j++){
			if(f[i][j]=='#')l[i][j]=-1;
			else l[i][j]=l[i][j-1]+1;
		}
	}
	for(int i=0;i<H;i++){
		if(f[i][W-1]=='#')r[i][W-1]=-1;
		else r[i][W-1]=0;
	}
	for(int i=0;i<H;i++){
		for(int j=W-2;j>=0;j--){
			if(f[i][j]=='#')r[i][j]=-1;
			else r[i][j]=r[i][j+1]+1;
		}
	}

	int ans = 0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(f[i][j]=='#')continue;
			ans = max(ans,calc(i,j));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 67456
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;

ll dp[405][405], prefix[405], sum, n, arr[405];

void solve(ll i , ll l){
	ll r = l + i;
	dp[l][r] = inf;
	for (ll j = 0; j < i; j++){
		dp[l][r] = min(dp[l][r], dp[l][l+j] + dp[l+j+1][r] + prefix[r] - prefix[l-1]);
	}
}
 
int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> arr[i];
		sum += arr[i];
		prefix[i] = sum;
	}
	for (ll k = 1; k < n; k++){
		for (ll t = 1; t <= n - k; t++){
			solve(k, t);
		}
	}
	cout << dp[1][n] << '\n';
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

//inline int read(){int t = 0;int neg=1;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1;continue;}t=t*10+c-48;}return neg*t;}
//inline int readl(){long long t = 0;long long neg=1ll;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1ll;continue;}t=t*10+c-48;}return neg*t;}

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<pi> vpi;
typedef vector<plli> vplli;
const lli M=1000000007ll;

int main(){
	fast_io 
	int a,b;
	cin>>a>>b;
	if(a==1 and b==1) cout<<"Draw";
	else if(a==1) cout<<"Alice";
	else if(b==1) cout<<"Bob";
	else if(a>b) cout<<"Alice";
	else if(b>a) cout<<"Bob";
	else cout<<"Draw";
	
	return 0;
}

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

int main() {
    int K, T;
    cin >> K >> T;
    priority_queue<int> que;
    for (int i = 0; i < T; i++) {
        int a;
        cin >> a;
        que.push(a);
    }

    if (T == 1) {
        cout << que.top() - 1 << endl;
        return 0;
    }

    int cnt = -1;
    int p0 = que.top();
    que.pop();
    while (p0 != 0) {
        int p1 = que.top();
        if (p1 != 0) {
            p0--;
            que.pop();
            que.push(p0);
            p0 = p1;
        } else {
            p0--;
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

int MOD = 1e9 + 7;

long long power(long long b, int p) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        long long xx = power(b, p / 2);
        return (xx * xx) % MOD;
    }
    else {
        long long xx = power(b, p / 2);
        return (((xx * xx) % MOD) * b) % MOD;
    }
}

int main() {
    long long x, y; cin >> x >> y;
    if ((x + y) % 3 != 0 || 2 * x < y || 2 * y < x) {
        cout << 0;
        return 0;
    }
    long long a = (2 * x - y) / 3;
    long long b = (2 * y - x) / 3;

    long long prev = 1, aa = 1, bb = 1;
    for (long long i = 1; i <= a + b; i++) {
        prev = (prev * i) % MOD;
        if (i == a) aa = prev;
        if (i == b) bb = prev;
    }
    long long res = prev;

    res = (res * power(aa, MOD - 2)) % MOD;
    res = (res * power(bb, MOD - 2)) % MOD;
    cout << res;
}

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

int main(){
    ll n,m; cin >> n >> m;
    // 表になるもの　＝　偶数回ひっくり返る -> 四角形の周
    ll ans = 0;
    if(n == 1 && m == 1) ans = 1; // 0次元
    else if(n == 1 || m == 1) ans = n * m - 2; // 1次元
    else ans = n * m  - (n + m) * 2  + 4; // 2次元
    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 x = sc.nextInt();
		int y = sc.nextInt();
        if (y < x) {
            int temp = x;
            x = y;
            y = temp;
        }
        int z = y % x;
        while (z != 0) {
            y = x;
            x = z;
            z = y % x;
        }
        System.out.println(x);
		sc.close();
	}    
}


Measured memory_bytes: 26272
#!/usr/bin/env python3
import numpy as np
from itertools import product
import sys
sys.setrecursionlimit(10**6)

n = int(input())

data = np.zeros((10, n), dtype=int)
for i in range(n):
    f = np.array(list(map(int, input().split())))
    data[:, i] = f

# print(data)

p = [list(map(int, input().split())) for i in range(n)]
# print(p)

ans = -10**10

for j, i in enumerate(product([0, 1], repeat=10)):
    if j == 0:
        continue

    indices = [x for x, y in enumerate(i) if y == 1]
    # print(indices)

    data_tmp = data[indices]
    data_tmp = np.sum(data_tmp, axis=0)
    ans_tmp = sum([p[a][b] for a, b in enumerate(data_tmp)])
    ans = max(ans, ans_tmp)
print(ans)


Measured memory_bytes: 27344
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll a, b;
    cin >> a >> b;
    cout << (a ^ b);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cout<<#x<<" = "<<(x)<<endl;
#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"

#define LIMIT 1000000007 //10^9+7

namespace /* combination.cpp */{
  namespace /* modinv.cpp */{
    namespace /* extGCD.cpp */{
      //ax + by = gcd(a, b)を満たすx, yを参照渡しから入れる
      long long extGCD(long long a, long long b, long long &x, long long &y) {
          if (b == 0) {
              x = 1;
              y = 0;
              return a;
          }
          long long d = extGCD(b, a%b, y, x);
          y -= a/b * x;
          return d;
      }
    }

    /*
    mod pでの a の逆元 x
    ax = 1 mod p
    ax-1がpで割り切れるので
    ax + py = 1 の解 x をとる
    aとpは互いに素であること
    */
    long long modinv(long long a, long long p){
      long long x, y;
      extGCD(a, p, x, y);
      return (x>0? x: x+p);
    }
  }

  long long l_fac(long long n){
    if(n<0) return -1;
    long long ans = 1;
    for(long long i=1; i<=n; i++){
      ans *= i;
      ans %= LIMIT;
    }
    return ans;
  }

  long long l_nPr(long long n, long long r){
    long long ans = 1;
    for(long long i=0; i<r; i++){
      ans *= (n-i);
      ans %= LIMIT;
    }
    return ans;
  }

  long long l_nCr(long long n, long long r){
    if(r > n/2) r = n-r;
    return l_nPr(n, r) * modinv(l_fac(r), LIMIT) % LIMIT;
  }
}

namespace /* COMfast.cpp */{
  #define COMMAX 200000
  long long fac[COMMAX], finv[COMMAX], inv[COMMAX];
  // テーブルを作る前処理
  void COMinit() {
      fac[0] = fac[1] = 1;
      finv[0] = finv[1] = 1;
      inv[1] = 1;
      for (int i = 2; i < COMMAX; i++){
          fac[i] = fac[i - 1] * i % LIMIT;
          inv[i] = LIMIT - inv[LIMIT%i] * (LIMIT / i) % LIMIT;
          finv[i] = finv[i - 1] * inv[i] % LIMIT;
      }
  }

  // 二項係数計算
  long long COM(int n, int k){
      if (n < k) return 0;
      if (n < 0 || k < 0) return 0;
      return fac[n] * (finv[k] * finv[n - k] % LIMIT) % LIMIT;
  }
}


//(sx,sy)から(gx,gy)へいく組み合わせ
ll ways(ll sx, ll sy, ll gx, ll gy){
  ll X = abs(gx - sx);
  ll Y = abs(gy - sy);
  return COM(X+Y, X);
}

//中継点(cx,cy)を通る組み合わせ
ll ways_by_checkpoint(ll sx, ll sy, ll cx, ll cy, ll gx, ll gy){
  ll w1 = ways(sx,sy,cx,cy);
  ll w2 = ways(cx,cy,gx,gy);
  //debug2(w1,w2);
  return w1 * w2;
}

int main(){
  COMinit();
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  ll ans = 0;
  int CH = H - A;
  int CW = B + 1;
  //debug2(CH,CW);
  while(CH>=1 && CW<=W){
    ll plus = ways_by_checkpoint(1,1,CH,CW,H,W);
    ans += plus;
    ans %= LIMIT;
    CH--;CW++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4992
//  Created by conan1024hao on 2019/11/26.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //------------------------------
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    map<int,int>c1,c2;
    for(int i=0;i<n;i+=2){
        c1[v[i]]++;
    }
    for(int i=1;i<n;i+=2){
        c2[v[i]]++;
    }
    int max1=0,max2=0;
    int mmx1,mmx2;
    for(int i=1;i<=100000;i++){
        if(max1<c1[i]){
            max1=c1[i];
            mmx1=i;
        }
        if(max2<c2[i]){
            max2=c2[i];
            mmx2=i;
        }
    }
    int sc1=0,sc2=0;
    if(mmx2==mmx1){
        for(int i=1;i<=100000;i++){
            if(i==mmx1)
                continue;
            if(sc1<c1[i]){
                sc1=c1[i];
            }
            if(sc2<c2[i]){
                sc2=c2[i];
            }
        }
        cout<<n-max1-max(sc1,sc2)<<endl;
    }
    else
    cout<<n-max1-max2<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,h,T;



int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> n >> m;

    cout << (1 << m)*(1900*m + 100 * (n-m)) << "\n";

    return 0;
}


Measured memory_bytes: 256
n,q = map(int,input().split(" "))
tree = [0] * (n + 1)
querys = [tuple(map(int,input().split(" "))) for _ in range(q) ]

def b_sum(i):

    ans = 0
    while i > 0:
        ans += tree[i]
        i -=(i) & (-i)


    return ans



for query in querys:
    com,x,y = query
    if com == 0:
        i = x
        x = y

        while i <= n:

            tree[i] += x
            i += (i) & (-i)

    if com == 1:

        s = x - 1
        t = y




        print(b_sum(t) - b_sum(s))



Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}


int main(){
    double n,m,p,h,k,max=-10000000,min=1000000000,ans=0,sum=0;
    string s,t;
    cin >> n;
    VI x(n);
    VI y(n);

    rep(i,n){
        cin >> x[i] >> y[i];
	}
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            sum += sqrt(pow(x[i]-x[j],2) + pow(y[i]-y[j],2));
        }
    }

    
    cout << setprecision(12) << (double) sum/n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  set<int> se;
  int M=0;
  for(int i = 0; i < n; ++i){
    int a;cin >> a;
    if(a>=3200)++M;
    else{
      se.insert(a/400);
    }
  }
  int m = se.size();
  cout << max(1,m) << " " << m + M << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=305,mod=998244353;
char s[N]; int n,f[N][N][N],ans; bool vis[N][N][N]; // f[i][j][k]: length i; j 0s to add; k 1s to add
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
int main()
{
	RI i,j,k; scanf("%s",s+1); n=strlen(s+1); s[0]='2';
	for (f[0][0][0]=1,i=0;i<n;++i) for (j=0;j<=i;++j)
	for (k=0;j+k<=i;++k) if (f[i][j][k])
	{
		int c=s[n-(i-j-k)]-'0'; inc(f[i+1][j][k],f[i][j][k]);
		if (c) inc(f[i+1][j+1][k],f[i][j][k]); else inc(f[i+1][j][k+1],f[i][j][k]);
	}
	for (vis[0][0][0]=vis[n][0][0]=1,i=n-1;i;--i)
	for (j=0;j<=i;++j) for (k=0;j+k<=i;++k)
	{
		int c1=s[n-(i-j-k)]-'0',c2=s[n-(i-j-k)-1]-'0',t[3]; t[2]=0;
		if (t[0]=j,t[1]=k,++t[0],t[c1])
		{
			if (--t[c1],t[c2]&&(c1==0||c2==0)) --t[c2];
		}
		vis[i][j][k]|=vis[i+1][t[0]][t[1]];
		if (t[0]=j,t[1]=k,++t[1],t[c1])
		{
			if (--t[c1],t[c2]&&(c1==1||c2==1)) --t[c2];
		}
		vis[i][j][k]|=vis[i+1][t[0]][t[1]];
	}
	for (i=1;i<=n;++i) for (j=0;j<=i;++j) for (k=0;j+k<=i;++k)
	if (vis[i][j][k]) inc(ans,f[i][j][k]); return printf("%d",ans),0;
}

Measured memory_bytes: 71304
# coding: utf-8
import os
import time
import re
import math


N = int(input())
SP=[]
for a in range(N):
    temp=input().split()
    SP.append([temp[0],int(temp[1]),(a+1)])
#SP=list(map(lambda x: x[0], SP))
SP.sort(key=lambda x: (x[0],-x[1]))
for a in range(N):
    print(SP[a][2])

Measured memory_bytes: 3184
using System;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            string ans = "No";
            if (b % 2 == 0 && a * 2 <= b && a * 4 >= b)
            { ans = "Yes"; }
             WriteLine(ans);
        }
    }

    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return Factorical(n) / Factorical(n - m); }
        public static long Combination(long n, long m)
        { return Permutation(n, m) / Factorical(m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Pow(long n, long m)
        { return (m == 1 || m == 0) ? 1L : n * Pow(n, m - 1); }
    }

}

Measured memory_bytes: 17724
from math import sqrt
from itertools import combinations

(n,), *xx = [list(map(int, s.split())) for s in open(0)]

tmp = 0

for i,j in combinations(range(n),2):
    xi, yi = xx[i]
    xj, yj = xx[j]
    tmp += sqrt((xi-xj)**2 + (yi-yj)**2)

print(tmp / n * 2)

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

using namespace std;

#define sp << " " <<

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n],b[n],c[n],d[n],p[n],dp[n];
    for(int i=0;i<n;i++)
        cin >> a[i] >> b[i] >> c[i];
    d[0]=a[0];
    p[0]=b[0];
    dp[0]=c[0];
    for(int i=1;i<n;i++)
    {
        d[i]=a[i]+max(p[i-1],dp[i-1]);
        p[i]=b[i]+max(d[i-1],dp[i-1]);
        dp[i]=c[i]+max(d[i-1],p[i-1]);
    }
    cout << max(d[n-1],max(p[n-1],dp[n-1]));
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>

int main(int argc, const char * argv[]) {
    int h, w;
    for ( ; std::cin >> h >> w && !(h == 0 && w ==0); ) {
        for (int j = 0; j < h; j++) {
            for (int i = 0; i < w; i++) {
                if (i == 0 || j == 0 || i == w - 1 || j == h - 1) {
                    std::cout << "#";
                } else {
                    std::cout << ".";
                }
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3060
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
a = LI()

now = 0
ans = 0
for i in range(N):
    if a[i] == now + 1:
        now += 1
    else:
        ans += 1
if ans == N:
    ans = -1
print(ans)

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

int main() {
    int N, P; cin >> N >> P;
    string S; cin >> S;
    int64_t ans = 0;
    if(P == 2 || P == 5) {
        for(int i = 0; i < N; ++i) {
            int mod = (S[i] - '0') % P;
            if(mod == 0) ans += i + 1;
        }
        cout << ans << '\n';
        return 0;
    }
    reverse(S.begin(), S.end());
    map<int, int> mp; mp[0]++;
    int pmod = 0, x = 1;
    for(int i = 0; i < N; ++i) {
        int mod = ((S[i] - '0') * x + pmod) % P;
        ans += mp[mod];
        mp[mod]++;
        pmod = mod;
        x *= 10; x %= P;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string SS, T;
//---------------------------------------------------------------------------------------------------
string solve() {
    int N = SS.length();
    int M = T.length();

    rrep(R, N, M) {
        int L = R - M;
        
        int ok = 1;
        rep(i, 0, M) if (SS[L + i] != '?' and SS[L + i] != T[i]) ok = 0;
        if (ok) {
            rep(i, 0, M) SS[L + i] = T[i];
            rep(i, 0, N) if (SS[i] == '?') SS[i] = 'a';
            return SS;
        }
    }

    return "UNRESTORABLE";
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> SS >> T;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main() {

	int n, m; cin >> n >> m; 
	int a[100010] = {}, pe[100010] = {};

	// AC済み　1　ACなし　0

	for (int i = 0; i < m; i++) {
		int p; string s;
		cin >> p >> s;
		if (a[p] == 0 && s == "AC") { a[p] = 1; continue;}
		if (a[p] == 0 && s == "WA") { pe[p]++; continue; }
		if (a[p] == 1 && s == "AC") { continue; }
		if (a[p] == 1 && s == "WA") { continue; }
	}

	int ansc = 0, anspe = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == 1) { ansc++; anspe += pe[i];}
	}

	cout << ansc << " " << anspe << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static class UnionFind {

        int[] id;
        int count;
        int[] weight;  // size indexed by root id

        public UnionFind(int n) {
            id = new int[n];
            weight = new int[n];
            count = n;
            for (int idx = 0; idx < id.length; idx++) {
                id[idx] = idx;
                weight[idx] = 1;
            }
        }

        public void union(int p, int q) {
            int pRoot = find(p);
            int qRoot = find(q);
            if (pRoot == qRoot) {
                return;
            }
            // make smaller root point to larger one
            if (weight[pRoot] < weight[qRoot]) {
                id[pRoot] = qRoot;
                weight[qRoot] += weight[pRoot];
            } else {
                id[qRoot] = pRoot;
                weight[pRoot] += weight[qRoot];
            }
            count--;
        }

        public int find(int p) {
            if (id[p] != p) {
                id[p] = find(id[p]);
            }
            return id[p];
//            while (id[p] != p) {
//                p = id[p];
//            }
//            return p;
        }

        public boolean connected(int p, int q) {
            return find(p) == find(q);
        }

        public int count() {
            return count;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        UnionFind uf = new UnionFind(n);
        int q = scanner.nextInt();
        while (q-- > 0) {
            int com = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            if (com == 0) {
                uf.union(x, y);
            } else {
                System.out.println(uf.connected(x, y) ? "1" : "0");
            }
        }
    }
}

Measured memory_bytes: 100220
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    string S;
    cin >> S;

    int N;
    N = S.length();

    string S_rev="";

    rep(si,N){
        S_rev = S_rev + S.substr((N-1)-si,1);
    }
    //cout << S_rev << endl;
    if(S == S_rev){
        string S2 = S.substr(0,(N-1)/2);
        int N2 = S2.length();
        S_rev="";
        rep(si,N2){
            S_rev = S_rev + S2.substr((N2-1)-si,1);
        }
        if(S2 == S_rev){
            S_rev="";
            string S2 = S.substr((N+3)/2-1,N);
            int N2 = S2.length();
            rep(si,N2){
                S_rev = S_rev + S2.substr((N2-1)-si,1);
            }
            if(S2 == S_rev){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }


}

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

typedef long long ll;

int main() {
  int n; cin >> n;
  int num[101];
  for ( int i = 1; i <= n; i++ ) cin >> num[i];

  ll dp[101][21];

  memset(dp,0,sizeof(dp));

  dp[1][num[1]] = 1;

  for ( int i = 2; i < n; i++ ) {
    for ( int j = 0; j <= 20; j++ ) {
      if (  j + num[i] <= 20 ) dp[i][j+num[i]] += dp[i-1][j];
      if (  j - num[i] >= 0 ) dp[i][j-num[i]] += dp[i-1][j];
    }
  }

  cout << dp[n-1][num[n]] << endl;
  
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

class Elem {
    public:
        int a, b;
};

int main(){
    ll n, k;
    cin >> n >> k;
    vector<Elem> e(n);
    repi(i, e){
        cin >> (*i).a >> (*i).b;
    }
    sort(e.begin(), e.end(), [](Elem e1, Elem e2){ return e1.a < e2.a; });

    ll sum = 0;
    repi(i, e){
        sum += (*i).b;
        if(k <= sum){
            cout << (*i).a << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;

int main() {
    int64_t N;
    cin >> N;

    struct Edge {
        int64_t to;
        int64_t index;
    };

    vector<vector<Edge>> connect(N);
    for (int64_t i = 0; i < N - 1; i++) {
        int64_t a, b;
        cin >> a >> b;
        a--; b--;
        connect[a].push_back({ b, i });
        connect[b].push_back({ a, i });
    }

    vector<int64_t> ans(N - 1);

    int64_t K = 1;
    stack<pair<int64_t, int64_t>> st;
    vector<bool> visited(N, false);
    st.push({ 0, -1 });
    while (!st.empty()) {
        pair<int64_t, int64_t> top = st.top();
        st.pop();
        visited[top.first] = true;
        int64_t count = 1;
        for (Edge edge : connect[top.first]) {
            if (visited[edge.to]) {
                continue;
            }

            if (top.second != count) {
                ans[edge.index] = count++;
            } else {
                ans[edge.index] = ++count;
                count++;
            }
            st.push({ edge.to, ans[edge.index] });
        }
    }

    cout << *max_element(ans.begin(), ans.end()) << endl;
    for (int64_t v : ans) {
        cout << v << endl;
    }
}

Measured memory_bytes: 8704