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

int main()
{
    long long n, count=0,tmp=0;
    cin >> n;
    vector<long long> h(n);

    for (long long i = 0; i < n;i++){
        cin >> h.at(i);
    }
    
    for (long long i = 0; i < n-1; i++)
    {
        if(h.at(i)>=h.at(i+1)){
            count++;
        }
        else if(h.at(i)<h.at(i+1)){
            if(tmp<count){
                tmp = count;
            }
            count = 0;
        }
        //cout << count <<" "<<tmp<< endl;
    }
    if (count < tmp)
    {
        count = tmp;
    }

    cout << count << endl;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1000000007
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector<ll> x(n), y(m);
    rep(i, n){
        cin >> x[i];
    }
    rep(i, m){
        cin >> y[i];
    }

    ll X = 0LL, Y = 0LL;
    for(int i = 0; i < n; ++i){
        X += (2*i-n+1)*x[i];
        X %= MOD;
    }

    for(int i = 0; i < m; ++i){
        Y += (2*i-m+1)*y[i];
        Y %= MOD;
    }

    ppp(X*Y % MOD);

    return 0;
}


Measured memory_bytes: 1792
n = int(input())
A = [int(i) for i in input().split()]
ct_1 = 0
ct_2 = 0
aa = 0

j = 1
for i in range(n):
    if (aa + A[i]) * j <= 0:
        ct_1 += abs(aa + A[i]) + 1
        aa = j
    else:
        aa += A[i]
    j *= -1

aa = 0
j = -1
for i in range(n):
    if (aa + A[i]) * j <= 0:
        ct_2 += abs(aa + A[i]) + 1
        aa = j
    else:
        aa += A[i]
    j *= -1

print(min(ct_1, ct_2))


Measured memory_bytes: 14468
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int ct = int.Parse(Console.ReadLine());
        int[] v = new int[ct];
        for (var i = 0; i < ct; i++)
        {
            v[i] = int.Parse(Console.ReadLine());
        }

        int x = 1;
        for (var i = 0; i < ct; i++)
        {
            x = Math.Max(v[i], x);
        }
        int ct_x = 0;
        for (var i = 0; i < ct; i++)
        {
            if (x == v[i]) ct_x++;
        }

        for (var i = 0; i < ct; i++)
        {
            int ans = 0;
            if (ct_x > 1 || v[i] != x)
            {
                ans = x;
            }
            else
            {
                int x2 = 1;
                for (var j = 0; j < ct; j++)
                {
                    if (i != j) x2 = Math.Max(v[j], x2);
                }
                ans = x2;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17108
#include <stdio.h>
#define MAX 150
#define NIL -1
#define N 10000

int graph[MAX][MAX];
int d[MAX];
int n;
  
int Que[N];
int head=0, tail=0;
 
void enQue(int q){
  Que[head]=q;
  head++;
}
 
int deQue(void){
  tail++;
  return Que[tail-1];
}
 
int size(void){
  return head-tail;
}
 
 
void bfs(int i){

  int j;
  
  for( j = 0; j < n; j++){
  
    if(graph[i][j]==1 && d[j]==NIL){
      d[j]=d[i]+1;
      enQue(j);
    }
  }
}
 
int main(){

  int u,k,i,j,v;
  
  scanf("%d",&n);
  
  for(i = 0; i < MAX; i++) d[i]=NIL;
  for(i = 0; i < n; i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      graph[u-1][v-1]=1;
    } 
  }
  d[0]=0;
  bfs(0);
  
  while(size() != 0){
    bfs(deQue());
  }
  
  for(i = 0; i < n; i++){
    printf("%d %d\n",i+1,d[i]);
  }
return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#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()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	int a, b;
	char c;
	cin >> a >> c >> b;
	cout << (c=='+'? a+b: a-b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		ans+=b-a+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

bool vector_find(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) {
        return true;
    }
    else {
        return false;
    }
}

vector<string> split(const string& src, const char* delim = ":") {
    vector<string> vec;
    string::size_type len = src.length();
    
    for (string::size_type i = 0, n; i < len; i = n + 1) {
        n = src.find_first_of(delim, i);
        if (n == string::npos) {
            n = len;
        }
        vec.push_back(src.substr(i, n - i));
    }
    
    return vec;
}

int main(int argc, char *argv[]){
    ll result = 0;
    ll r, D, x;
    cin >> r >> D >> x;
    result = x;

    rep(i, 10){
        result = r * result - D;
        cout << result << endl;
    }
    
}





Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_158
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] np = ReadInts();
            int n = np[0];
            int p = np[1];
            string s = Read();

            long res = 0;
            if (p == 2)
            {
                for(int i = 0; i < n; i++)
                {
                    if ((s[i] - '0') % 2 == 0)
                    {
                        res += i + 1;
                    }
                }
            }
            else if (p == 5)
            {
                for(int i = 0; i < n; i++)
                {
                    int current = s[i] - '0';
                    if (current == 0 || current == 5)
                    {
                        res += i + 1;
                    }
                }
            }
            else
            {
                int[] margins = new int[p];
                margins[0] = 1;
                int digMargin = 1;
                int tmpMargin = 0;
                for (int i = n - 1; i >= 0; i--)
                {
                    int current = (s[i] - '0') % p;
                    tmpMargin = (current * digMargin + tmpMargin) % p;
                    res += margins[tmpMargin];
                    margins[tmpMargin]++;
                    digMargin = (digMargin * 10) % p;
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13212
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(void) {
	int i, j, k;
	string s;
	cin >> s;
	vector<vector<ll>> dp(s.size() + 1, vector<ll>(13, 0));
	dp[0][0] = 1;
	for (i = 0; i < s.size();) {
		switch (s[i]) {
		case '?':
			for (j = 0; j < 10; j++) {
				for (k = 0; k < 13; k++) {
					dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
				}
			}
			break;
		default:
			j = s[i] - '0';
			for (k = 0; k < 13; k++) {
				dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
			}
			break;
		}
		i++;
		for (j = 0; j < 13; j++) {
			dp[i][j] %= MOD;
		}
	}
	cout << dp[i][5] << "\n";
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const double pi = 3.1415926535;

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double angle = -H*30;
  angle += 5.5*M;
  angle = abs(angle);
  cout << setprecision(15) << sqrt(A*A+B*B-2*A*B*cos(angle*pi/180)) << endl;
  return 0;
}


Measured memory_bytes: 4116
#include<iostream>
#include<cstdio>

const int maxn=1e5+10;

using namespace std;

int N,a[maxn],ans[maxn];

int main() {
	cin>>N;
	for(int i=1;i<=N;++i) {
		cin>>a[i];
		ans[a[i]]=i;
	}
	
	for(int i=1;i<=N;++i)
		cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 1536
// 26
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define lli __int128_t
#define li long long int
#define ld double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> &p) {
  return os << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  rep(i, (int)v.size()) os << setw(7) << left << v[i];
  return os << endl;
}
// 6
template <class A, class B>
ostream &operator<<(ostream &os, map<A, B> &m) {
  for (auto &kv : m) os << "{" << kv.fi << " " << kv.se << "}";
  return os;
}
// 3
void _main(int tc) {
  int n;
  cin >> n;
  vector<ld> p(n);
  rep(i, n) cin >> p[i];
  /************* Recursive *************
  vector<vector<ld>> mem(n, vector<ld>(n + 1, -1));
  function<ld(int, int)> f = [&](int i, int c) -> ld {
    if (n - i + c <= i - c) return 0;
    if (i == n) return 1;
    if (mem[i][c] != -1) return mem[i][c];
    return mem[i][c] = p[i] * f(i + 1, c) + (1 - p[i]) * f(i + 1, c - 1);
  };
  cout << setprecision(10) << f(0, n) << endl;
  *********** End Recursive ***********/
  vector<vector<ld>> mem(n + 1, vector<ld>(n + 1));

  int mid = n & 1 ? (n + 1) / 2 : n / 2 + 1;
  forn(i, mid, n + 1) mem[n][i] = 1;

  rrep(i, n) {
    forn(c, mid, n + 1) {

      mem[i][c] = p[i] * mem[i + 1][c] + (1 - p[i]) * mem[i + 1][c - 1];
    }
  }

  debug(mem);
  
  cout << setprecision(10) << mem[0][n] << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 70784
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[10009], dp[5009][2];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) scanf("%d", &a[i]);
	for (int i = 0; i <= n >> 1; i++) dp[i][0] = dp[i][1] = 999999999;
	dp[0][0] = dp[1][1] = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = n >> 1; j >= 0; j--) {
			dp[j][0] = min(dp[j][0], dp[j][1] + a[i]);
			dp[j][1] = (j ? min(dp[j - 1][1], dp[j - 1][0] + a[i]) : 999999999);
		}
	}
	printf("%d\n", dp[n >> 1][0]);
	return 0;
}

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

using namespace std;

int main() {
  
  int sheep=0, wolf=0;
  
  cin >> sheep >> wolf;
  
  if(sheep<=wolf) {
    
    cout << "unsafe" << endl;
    
  } else {
    
    cout << "safe" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
vector<int> g[N];
queue<int> q;
int in[N];
int dp[N];
int main(){
    int n,m,u,v,ans=0;
    scanf("%d %d",&n,&m);
    while(m--){
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        in[v]++;
    }
    for(int i=1;i<=n;i++)
        if(!in[i])
            q.push(i);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        ans = max(ans,dp[now]);
        for(auto x : g[now]){
            dp[x] = max(dp[x],dp[now]+1);
            in[x] -- ;
            if(!in[x])  q.push(x);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n,k;
  cin>>n>>k;
  vector<ll> a(n);
  cin>>a;
  sort(begin(a),end(a));
  cout<<(accumulate(begin(a),begin(a)+k,0ll))<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int L, R, d, ans;
  cin >> L >> R >> d;
  ans=0;
  if (L%d==0 && R%d==0) {
    ans=(R-L)/d+1;
  }
  else {
    if (R%d==0) {
      ans=(R-L+(L%d))/d;
    }
    else {
      if (L%d==0) {
        ans=(R-(R%d)-L)/d+1;
      }
      else {
        ans=(R-(R%d)-L+(L%d))/d;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {
	static int N;
	static int ans;

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

		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();

		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}

		double min = Integer.MAX_VALUE;
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (min > Math.abs(A - (T - H[i] * 0.006))) {
				ans = i + 1;
				min = Math.abs(A - (T - H[i] * 0.006));
			}
		}

		System.out.println(ans);
	}

}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	cout<<min((N+W-1)/W,(N+H-1)/H)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int m = max(max(a, b), c);
	for (int i = 0; i < k; i++)
		m *= 2;
	cout << m + a + b + c - max(max(a, b), c) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;

int main(){
    int N;cin >> N;
    vector<int> a(N),b(N),c(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(N+1,vector<int> (3,0));
    for (int i = 0; i < N; i++) {
        dp[i+1][0]=a[i]+max(dp[i][1],dp[i][2]);
        dp[i+1][1]=b[i]+max(dp[i][0],dp[i][2]);
        dp[i+1][2]=c[i]+max(dp[i][0],dp[i][1]);
    }
    cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;
    return 0;
}



Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<int,int>;
int a,b;

int main(){
   cin >> a >> b;
   auto c = 0;
   for (int i = a; i <= b; i++)
   {
      string s = to_string(i);
      reverse(s.begin(),s.end());
      if(stoi(s)==i){
         c++;
      }
   }
   cout << c << endl;
}
  
  

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

def solve(X: int):
    current = 101
    now = 1
    while True:
        if current >= X:
            print(now)
            break
        current = math.floor(current*1.01)
        now+=1
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63392
#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;

typedef vector<ii> vii;
//#define int long long 


signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
   // freopen("test.txt","r",stdin);

   	int a,b;cin>>a>>b;

   	cout<<max( 0 , a-2*b);

    
}
    




Measured memory_bytes: 256
import java.math.BigDecimal;
        import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int[] x = new int[50];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        
        long[][][] dp = new long[51][51][3010];
        
        dp[0][0][0] = 1;

        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n; k++) {
                for (int j = 0; j <= a*n; j++) {
                    dp[i + 1][k][j] += dp[i][k][j];
                    dp[i + 1][k + 1][j+x[i]] += dp[i][k][j];
                }
            }

        }

        long ans = 0;
        for (int k = 1; k <= n; k++) {
            ans += dp[n][k][k * a];
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 130604
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<vector<int>> graph;
map<P,int> mp;
int main(){
  int n;
  cin>>n;
  graph.resize(n);
  vector<P> p(n-1);
  for(int i=0;i<n-1;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      graph[a].push_back(b);
      graph[b].push_back(a);
      if(a>b)swap(a,b);
      p[i]=(P(a,b));
  }
  queue<P> q;
  q.push(P(1,0));
  vector<bool> used(n,true);
  while(!q.empty()){
       P no=q.front();
       int now=no.fi,bfo=no.se;
       q.pop();
       used[now]=false;
       int cnt=1;
       for(int v:graph[now]){
             if(!used[v])continue;
             if(cnt==bfo)cnt++;
             if(now>v)mp[P(v,now)]=cnt;
             else mp[P(now,v)]=cnt;
             q.push(P(v,cnt));
             cnt++;
       }
  }
  ll ma=0;
   for(int i=0;i<n-1;i++){
      if(ma<mp[p[i]])ma=mp[p[i]];
  }
  cout<<ma<<endl;
  for(int i=0;i<n-1;i++){
      cout<<mp[p[i]]<<endl;
  }
}



Measured memory_bytes: 13952
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    ss=input().split()
    print(ss[0][0].upper()+ss[1][0].upper()+ss[2][0].upper())

main()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<string, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s[110];
int p[110];

void solve() {
    vector<P> vec(n);
    map<int, int> idx;
    for (int i = 0; i < n; i++) {
        vec[i] = make_pair(s[i], -p[i]);
        idx[-p[i]] = i+1;
    }
    sort(ALL(vec));
    for (int i= 0 ; i< n; i++) {
        cout << idx[vec[i].second] << endl;
    }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        n = int(lines[0])
        for _ in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        n = int(lines[0])
    
    s = lines[1:]

    return (n, s)


def solve(n, s):

    result = len(set(s))

    return  result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 109232
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

ll bfs(vector<vector<long>>& c, vector<vector<bool>> ispassed, long num, ll cost, ll min_cost) {
    // 既に探索の場所を1，探索していなかったら0を格納する配列
    min_cost = min(cost + c[num][1], min_cost);
    for(size_t i=0;i<10; i++)
    {
        if(num == 1 || num==i || ispassed[num][i]) continue;
        ll current_cost = cost;
        ispassed[num][i] = true;
        ispassed[i][num] = true;
        current_cost+=c[num][i];
        if(min_cost <= current_cost) continue;
        min_cost = min(bfs(c, ispassed, i, current_cost, min_cost), min_cost);
    }
    return min_cost;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long H, W;
    cin >> H >> W;
    std::vector<std::vector<long>> c(10, vector<long>(10, 0));
    for(size_t i=0;i<10; i++)
    {
        for(size_t j=0;j<10; j++)
        {
            cin >> c[i][j];
        }
    }
    //std::vector<std::vector<long>> A(H, vector<long>(W, 0));
    map<ll, ll> A;
    for(size_t i=0;i<H; i++)
    {
        for(size_t j=0;j<W; j++)
        {
            ll a;
            cin >> a;
            if(a != -1) A[a]++;
        }
    }

    //各数字を1に変えるのにかかるコスト
    
    vector<long> num(10);
    for(size_t i=0;i<10; i++)
    {
        vector<vector<bool>> ispassed(c.size(), vector<bool>(c[0].size(), false));
        //cerr << (bfs(c, ispassed, i, 0)) << endl;
        num[i] = bfs(c, ispassed, i, 0, INF);
        cerr << i << ":" << num[i] << endl;
    }
    /*
   for(size_t k=0;k<10; k++)
   {
       for(size_t i=0;i<10; i++)
       {
           for(size_t j=0;j<10; j++)
           {
               c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
           }
       }
   }
   
    for(size_t i=0;i<10; i++)
    {
        cerr << i << ":" << c[i][1] << endl;
    }
    */
    ll total = 0;
    for(auto a : A) total += num[a.first] * a.second;//total += c[a.first][1] * a.second;
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main()
{
   int A,B,C,D,n,m;
  while(scanf("%d%d%d%d",&A,&B,&C,&D)!=EOF)
   {
    n=A+B;
    m=C+D;
   if(n>m)
   {
       printf("Left");
       continue;
   }
if(n<m)
   {
       printf("Right");
    continue;
   }
   if(n=m)
   {
       printf("Balanced");

   }



   }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> T(N-1,vector<int>(3));
  for (int i=0;i<N-1;i++){
    cin >> T[i][0] >> T[i][1] >> T[i][2];
  }
  for (int i=0;i<N;i++){
    int t=0;
    for (int j=i;j<N-1;j++){
      if (t>T[j][1]){
        t=((t+T[j][2]-1)/T[j][2])*T[j][2]+T[j][0];
      }
      else {
        t=T[j][1]+T[j][0];
      }
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c,k,i,sum = 0,maks=0,temp =0;
	cin >> a >> b >> c >> k;
	maks=max(max(a,b),c);
	temp=maks ;
	for (i=1;i<=k;i++){
		maks =maks *2;
	}
	sum = a+b+c-temp+maks;
	cout << sum << endl;
}


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

using namespace std;

int f[110][10];

int main()
{
	int N;
	scanf("%d",&N);
	memset(f,0,sizeof(f));
	for (int i=0;i<=N;i++)
		for (int j=0;j<10;j++)f[i][j] = -1000000;
	f[0][0] = 0;
	for (int i=0;i<N;i++)
	{
		for (int j=0;j<10;j++)
			f[i+1][j] = f[i][j];
		int s;
		scanf("%d",&s);
		for (int j=0;j<10;j++)
		{
			int nxt = (j+s)%10;
			f[i+1][nxt] = max(f[i+1][nxt],f[i][j] + s);
			//printf("%d ",f[i][j]);
		}
		//puts("");
	}
	int ans = 0;
	for (int i=1;i<10;i++) ans = max(ans,f[N][i]);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort(reverse=True)
ls = [0 for i in range(10**6)]
for a in a_ls:
    ls[a+1] += 1
ls = [i for i in accumulate(ls)]

def check(x):
    res = 0
    for a in a_ls:
        res += n - ls[max(0,x - a)]
    return res

up = 10**6
down = 0
while True:
    mid = (up + down) // 2
    if check(mid) >= m:
        if down == mid:
            break
        down = mid
    else:
        if up == mid:
            if check(up) == m:
                mid = up
            break
        up = mid

acc_ls = [i for i in accumulate([0] + a_ls)]
ans = 0
for a in a_ls:
    x = n - ls[max(0, mid - a)]
    ans += x * a + acc_ls[x]
print(ans - (check(mid) - m) * mid)

Measured memory_bytes: 118792
# 2019-11-14 20:54:46(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    s = sys.stdin.readline().rstrip()
    for i in range(3):
        if s[i] == s[i+1]:
            ans = 'Bad'
            break
    else:
        ans = 'Good'
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
	int n;
	int x;
	int i;
	long long sum;
	int min,max;
	scanf("%d",&n);
	sum=0;
	min=1000000;
	max=-1000000;
	for(i=0;i<n;i++){
		scanf("%d",&x);
		sum+=x;
		if(x<min){
			min=x;
		}
		if(x>max){
			max=x;
		}
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
const int maxm=1e4+5;
int sz; char s[maxn]; LL c[maxm];
inline int lowbit(int x) { return x&-x; }
int main(void)
{
	int n; LL p; scanf("%d%lld",&n,&p);
	scanf("%s",s+1);
	LL res=0; LL t=1; LL num=0;
	if(10%p==0)
	{
		for(int i=1;i<=n;i++)
		{
			if((s[i]-'0')%p==0) res+=i;
		}
	}
	else
	{
		for(int i=n;i>=1;i--)
		{
			c[num]++;
			num=(num+(s[i]-'0')*t)%p;
			t=t*10%p;
			res+=c[num];
		}
	}
	printf("%lld\n",res);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>

int n;

int A[20];

long long DP(int l,int lx,int r,int rx){
	if (r-l==1) return 0;
	long long res=0x3f3f3f3f3f3f3f3f;
	for (int k=l+1;k<=r-1;k++)
		res=std::min(res,DP(l,lx,k,lx+rx)+DP(k,lx+rx,r,rx)+static_cast<long long>(A[k])*(lx+rx));
	return res;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	printf("%lld\n",DP(1,1,n,1)+A[1]+A[n]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N,M,T;
    cin >> N >> M >> T;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int cnt[20005];
    for(int i=0;i<=T;i++){
        cnt[i] =0;
    }

    for(int i=0;i<N;i++){
        cnt[a[i]-M]++;
        cnt[a[i]+M]--;
    }

    for(int i=0;i<=T;i++){
        cnt[i+1] += cnt[i];
    }

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



Measured memory_bytes: 3096
#define yuki(x, y) for(int i = x; i < (y); ++i)
#define yukj(x, y) for(int j = x; j < (y); ++j)
#define yukii(x, y) for(int i = x; i <= (y); ++i)
#define yukji(x, y) for(int j = x; j <= (y); ++j)
#define yuk(x, y, z) for(int x = y; x < (z); ++x)
#define yui(x, y, z) for(int x = y; x >= (z); --x)
#define sclr(x) memset(x, 0, sizeof(x))
#define sclr1(x) memset(x, -1, sizeof(x))
#define scl(x, y) memset(x, y, sizeof(x))
#define ft first
#define sc second
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long lol;
int n, t[1010], a[1010];
lol l, r;
void sread()
{
    scanf("%d", &n);
    yuki(0, n) scanf("%d%d", t+i, a+i);
}
int main(int argc, char **argv)
{
	sread();
	l = r = 1ll;
	yuki(0, n)
	{
	    lol k1 = l%t[i], k2 = r%a[i];
	    if(k1) l += t[i]-k1;
	    if(k2) r += a[i]-k2;
	    k1 = l/t[i], k2 = r/a[i];
	    if(k1 < k2) l += (k2-k1)*t[i];
	    else if(k1 > k2) r += (k1-k2)*a[i];
	}
	printf("%lld\n", l+r);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {      
      List<string> n = Console.ReadLine().ToList().ConvertAll(x=>x.ToString());
      int count =0;
      bool flag = false;
      //var hashSet = new HashSet<string>(n);
      
      for (int i=0;i<3;i++)
      {
        if (n[i]==n[i+1])
        {
          count+=1;
        }
        else
        {
          count=0;
        }
        if (count>=2)
        {
          flag = true;
        }
      }
      if (flag)
      {
        Console.WriteLine("Yes");
        
      }
      else
      {
        Console.WriteLine("No");
      }
    }
}


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

#include <iostream>
using namespace std;
int main() {
  int64_t x, n;
  cin >> x >> n;
  vector<int64_t> p(n);
  for (auto& pi : p) {
    cin >> pi;
  }
  int64_t diff = 1000;
  int64_t ans = -1;
  bool is_end = false;
  for (int64_t i = 0; i <= 101; ++i) {
    bool a = true;
    for (auto pi : p) {
      if (pi == i) {
        a = false;
      }
    }
    if (a) {
      if (diff > abs(x - i)) {
        diff = abs(x - i);
        ans = i;
      } else {
        is_end = true;
      }
    }
    if (is_end) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int A,B;
	cin >> A >> B;
	if (A % 2 == 1 && B % 2 == 1)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B;
  C = 0;
  for (int i = A; i < B+1; i++){
    int D, E, F, G;
    D = i%10;
    E = i/10%10;
    F = i/1000%10;
    G = i/10000%10;
    if ((D == G)&&(E == F)) {
      C++;
    }
  }
  cout << C << endl;
}


Measured memory_bytes: 256
n = input()
l = len(n)
s = [0] * 2020
m = [0] * (l+1)
m[0] = 1
s[0] = 1
for i in range(1, l+1):
    m[i] = (m[i-1]*10) % 2019
tmp = 0
n = list(n)[::-1]
for i in range(len(n)):
    #print(i, n[-1-i], m[i])
    tmp = (tmp + int(n[i])*m[i]) % 2019
    # print(tmp)
    s[tmp] += 1
su = 0
for i in s:
    if i > 1:
        # print("#", i)
        su += i * (i - 1)//2
print(su)


Measured memory_bytes: 19256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){

  int a,b,c,sum=0;

  scanf("%d %d %d",&a,&b,&c);

  sum=a+b+c;

  if(sum>=22){
    printf("bust\n");
  }else{
    printf("win\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
 
 
 
 
int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int len=0;
  int dp[5005][5005];
  for(int i=n-1;i>=0;i--){
    for(int j=n-1;j>=0;j--){
      if(s[i]!=s[j]){
        dp[i][j]=0;
      }else{
        dp[i][j]=dp[i+1][j+1]+1;
      }
    }  
  }
  rep(i,n)rep(j,n){
    if(i>=j)continue;
    int a=min(dp[i][j],j-i);
    len=max(a,len);
  }
  cout<<len;



}




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

int card[50];

void swap(int p,int c){
	int tmp[50];
	for(int i=0;i<c;i++)
		tmp[i]=card[i+p-1];
	for(int i=0;i<p-1;i++)
		tmp[i+c]=card[i];
	for(int i=0;i<p+c-1;i++)
		card[i]=tmp[i];
	return ;
}

int main(void){
	int n,r;
	while(cin >> n >> r,n){
		for(int i=0;i<n;i++)
			card[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			cin >> p >> c;
			swap(p,c);
		}
		cout << card[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#[allow(dead_code)]
fn main() {
    let s: Vec<i64> = i::s().iter().map(|&c| c as i64 - '0' as i64).collect();
    let n = s.len();

    // 左からi桁見たときのMOD2019の値でDP
    let mut ans = 0;
    let mut before = vec![0; 2020];
    for i in 0..n {
        let mut d = vec![0; 2020];
        let c = s[i];
        for j in 0..2019 {
            let k = (j * 10 + c) % 2019;
            d[k as usize] += before[j as usize];
        }
        d[c as usize] += 1;
        ans += d[0];
        before = d;
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4320
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        ab[i].append(ab[i][0] + ab[i][1])
    arr = sorted(ab, reverse=True, key=lambda x: x[2])
    ans = 0
    for i in range(n):
        if i % 2 == 0:
            ans += arr[i][0]
        else:
            ans -= arr[i][1]
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 91632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
ll ans=1,h;
queue<ll> q;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>h;
	q.push(h);
	while(!q.empty()){
		ll a=q.front();
		q.pop();
		ans=2*ans;
		ll c=a/2;
		if(c!=0) q.push(c);
	}
	cout<<ans-1;
	return 0;
 } 

Measured memory_bytes: 256
def rot_n(c,n):
    if 'a' <= c and c <= 'z':
        return chr((ord(c) - ord('a') + int(n)) % 26 + ord('a'))
    if 'A' <= c and c <= 'Z':
        return chr((ord(c) - ord('A') + int(n)) % 26 + ord('A'))
    return c

def rot(s,n):
    c=(rot_n(c,n) for c in s)
    ans="".join(c)
    return ans

if __name__=="__main__":
    n = int(input())
    s=list(input())
    answer=rot(s,n)
    print(answer)

Measured memory_bytes: 39280
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

vector<ll>a, p;
int n; ll x;

ll dfs(ll i, ll len) {
	if (i == 0) {
		if (len <= 0) {
			return 0;
		}
		return 1;
	}
	else if (len <= 1 + a[i - 1]) {
		return dfs(i - 1, len - 1);
	}
	else {
		return p[i - 1] + 1 + dfs(i - 1, len - 2 - a[i - 1]);
	}
}

int main() {
	cin >> n >> x;
	a.push_back(1);
	p.push_back(1);
	for (int i = 0; i < n; i++) {
		a.push_back(a[i] * 2 + 3);
		p.push_back(p[i] * 2 + 1);
	}
	cout << dfs(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
 int A,B;
  
 scanf("%d%d",&A,&B);
 if(A>=13)printf("%d\n",B);
  else if(A<13 && A>=6)printf("%d\n",B/2);
  else printf("0\n");

 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n;
long long k;
long long a[200100];
long long INF=1000000000010000000LL;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	long long cl,cr,cx,l,r,x,tot;
	cl=-INF;
	cr=INF;
	while(cl+1<cr){//binary answer
		cx=(cl+cr)/2LL;
		tot=0LL;
		for(int i=0;i<n;i++){//check(binary search)
			if(a[i]<0){
				l=-1;
				r=n;
				while(l+1<r){
					x=(l+r)/2LL;
					if(a[i]*a[x]<cx)
						r=x;
					else
						l=x;
				}
				tot+=(long long)(n)-r;
			}
			else{
				l=-1;
				r=n;
				while(l+1<r){
					x=(l+r)/2LL;
					if(a[i]*a[x]<cx)
						l=x;
					else
						r=x;
				}
				tot+=r;
			}
			if(a[i]*a[i]<cx)
				tot-=1LL;
		} 
		tot/=2LL;
		if(tot<k)
			cl=cx;
		else
			cr=cx;
	}
	cout<<cl<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define N 10000

int serch(int,int,int);

int main(){
  int num,num2,i,S[N],SA[N],j;
  int cnt = 0;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&num2);
  for(i=0;i<num2;i++){
    scanf("%d",&SA[i]);
  }
    for(i=0;i<num2;i++){
      for(j=0;j<num;j++){
	if(S[j] == SA[i]) {
	  cnt++;
	  break;
	}
    }
    }

  printf("%d\n",cnt);
  
  return 0;
}




Measured memory_bytes: 2100