akhauriyash/Code-Regression huggingface dataset:
#define $ for(i=j=0;j<n?:(j=0,++i<n);j++)
#define _(a,b)$ for(b=l=0;l<n;)b+=a[i][l]*p[l++][j]%m;$ a[i][j]=b%m;
long m=1e9+7,p[50][50],a[50][50],b[50][50],k;i,j,l;main(n){scanf("%d%ld",&n,&k);$ a[i][i]=scanf("%d",p[i]+j);for(;k;k/=2){if(k&1){_(a,b[i][j])}_(p,b[i][j])}$ k+=a[i][j];printf("%d",k%m);}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int a, b, c;
    int area;
    
    cin >> a >> b >> c;
    
    if (a>b && a>c) area = (b*c)/2;
    else if (b>a && b>c) area = (a*c)/2;
    else area = (a*b)/2;
    
    cout << area << endl; 

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>

using namespace std;

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

    string ans;

    if(n==m)
        ans = "Yes";
    else
        ans = "No";    

    std::cout << ans << std::endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int x,y;
int main(void)
{
    cin>>x>>y;
    if(4*x<y||y<2*x)cout<<"No"<<endl;
    else
    {
        if((4*x-y)%2)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3112
n = int(input())
def f(a,b,c):
    return a * a + b * b + c * c + a * b + b * c + a * c
c = [0] * n
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            x = f(i, j, k) - 1
            if x < n:
                c[x] += 1
for i in c:
    print(i)

Measured memory_bytes: 68972
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int a[N],b[N];
int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  int n,m;
  string s,r; cin>>s>>r;
  n=s.size();
  REP(i,n){
    a[i+1]=a[i];
    a[i+1]++;
    if(s[i]=='B') a[i+1]++;   
  }
  m=r.size();
  REP(i,m){
    b[i+1]=b[i];
    b[i+1]++;
    if(r[i]=='B') b[i+1]++;   
  }
  int q; cin>>q;
  while(q--){
    int aa,bb,c,d; cin>>aa>>bb>>c>>d;
    aa--;c--;
    if((a[bb]-a[aa])%3!=(b[d]-b[c])%3) printf("NO\n"); else printf("YES\n");
  }
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int f(int n) {
  return (n & 1) ? 3 * n + 1 : n / 2;
}

int main() {
  int s; cin >> s;
  int fn = s, ans = 1;
  while (true) {
    // cout << fn << " ";
    if (fn==1 || fn==2 || fn==4) { break; }
    ans++;
    fn = f(fn);
  }
  cout << ans + 3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    if(zt(x,a)<zt(x,b)){printf("A\n");}else{printf("B\n");}
    return 0;
}

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

#define rep(i,n) for (int i = 0; i < n; ++i)
#define repr(i,n) for (int i = n; i > 0; --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 100;
const int INF = (1<<12);

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

  int ans = A[A.size()/2] - A[A.size()/2 -1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

const int MAXN =1e5+10;

char s[MAXN][10+10];
long long int march[5+5];
int main(){
	int N =0;
	scanf("%d",&N);
	long long int ans =0;
	for(int i=0;i<N;i++){
		scanf("%s",&s[i]);
	}
	for(int i=0;i<N;i++){
		if(s[i][0]=='M')	march[0]++;
		if(s[i][0]=='A')	march[1]++;
		if(s[i][0]=='R')	march[2]++;
		if(s[i][0]=='C')	march[3]++;
		if(s[i][0]=='H')	march[4]++;
	}
	
	ans=march[0]*march[1]*march[2]+march[0]*march[1]*march[3]+march[0]*march[1]*march[4]+march[0]*march[2]*march[3]+march[0]*march[2]*march[4]+march[0]*march[3]*march[4]+march[1]*march[2]*march[3]+march[1]*march[2]*march[4]+march[1]*march[3]*march[4]+march[2]*march[3]*march[4];
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
const int iNF = 1e9 + 100;
const ll INF = 1e18 + 100;
typedef pair<int, int> pii;

int n, m;
ll x;
vector<vector<ll>> books;

ll go(int pos, vector<ll> a) {
   bool ok = 1;
   for(int i = 0; i < m; i++){
      if(a[i] < x){
         ok = 0;
      }
   }
   if(ok){
      return 0;
   }
   if(pos >= n){
      return INF;
   }
   // don't buy it
   ll res1 = go(pos + 1, a);
   // buy it
   for(int i = 0; i < m; i++){
      a[i] += books[pos][ i + 1 ]; 
   }
   ll res2 = books[pos][0] + go(pos + 1, a);
   
   return min(res1, res2);
}

int main(){
   cin >> n >> m >> x;
   int u;
   books = vector<vector<ll>>(n, vector<ll>());
   for(int i = 0; i < n; i++){
      cin >> u;
      books[i].push_back(u);
      for(int j = 0; j < m; j++){
         cin >> u;
         books[i].push_back(u);
      }
   }
   ll res = go(0, vector<ll>(m, 0));
   if(res >= INF){
      cout << -1 << endl;
   }else{
      cout << res << endl;
   }
   return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[5050];

ll ln[5050];
ll i, j, k, ans;

vector<vector<ll>> hashh;
void createHash(){
    const ll b1 = 1009, b2 = 1007, m1 = 1000000007, m2 = 1000000009;
    hashh.resize(N + 5, vector<ll>(N + 5));
    ll i = 0, j = 0, a = 0, b = 0;
    fornum(i,0,N){
        a = 0, b = 0;
        fornum(j,i,N){
            a = (S[j] + a) * b1 % m1;
            b = (S[j] + b) * b2 % m2;
            hashh[i][j + 1] = a * (ll)1e10 + b;
            //printf("%lld ", hashh[i][j + 1]);
        }
        //printf("\n");
    }
}

bool bs(ll a){
    if(a==0)
        return true;
    ll i = 0;
    set<ll> st;
    fornum(i,a,N){
        if(i+a>N)
            break;
        st.insert(hashh[i - a][i]);
        ll h = hashh[i][i + a];
        if(st.count(h))
            return true;
        
    }
    return false;
}
int main(){
    scanf("%lld%s", &N, S);

    createHash();

    ll l = 0, r = N;
    while(l<r){
        ll c = (l + r + 1) / 2;
        if(bs(c)){
            l = c;
        }else{
            r = c - 1;
        }
    }
    printf("%lld", l);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

int m = 1000000007;

long long f(long long n){
    if(n==1) return 1;
    return n * f(n-1) % m;
}

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

    if(abs(N-M) > 1){
        cout << 0 << endl;
        return 0;
    }

    if(abs(N-M) == 0){
        cout << ((((f(N) % m) * (f(M) % m)) % m)*2)%m << endl;
    }else{
        cout << (((f(N) % m) * (f(M) % m)) % m) << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: (x * y) // math.gcd(x, y)
lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = [ii() for _ in range(N)]

    ret = lcm(T[0], T[1]) if len(T) > 1 else T[0]
    for t in T:
        ret = lcm(ret, t)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5156
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define rep2(x,from,to) for(long long x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
long long n;
long long ans;
int main()
{
    cin>>n;
    rep2(i,1,n+1)
    {
        if(i%15==0)
        {
            ;
        }
        else if(i%3==0)
        {
            ;
        }
        else if(i%5==0)
        {
            ;

        }
        else
        {
            ans+=i;
        }
        
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int selectionSort(int A[],int N){
    int count=0,minj;
    for(int i=0;i<N-1;i++){
        minj=i;
        for(int j=i;j<N;j++){
            if(A[j] < A[minj])minj = j;
        }
        swap(A[i],A[minj]);
        if(i!=minj)count++;
    }
    return count;
}
int main(int argc, const char * argv[]) {
    int A[100],N;
    cin>>N;
    for(int i=0;i<N;i++)cin>>A[i];
    
    int sw = selectionSort(A,N);
    
    for(int i=0;i<N;i++){
        if(i>0) cout<<' ';
        cout<<A[i];
    }
    cout<<endl;
    cout<<sw<<endl;
    return 0;
}




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

int main()
{
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) {
        cout << "Yay!";
        return 0;
    }
    cout << ":(";

    return 0;
}


Measured memory_bytes: 256
import itertools, bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1, N):
        cindex = bisect.bisect_left(L, int(L[i]) + int(L[j]))
        ans += cindex-1 - j

print(ans)


Measured memory_bytes: 42972
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
H=input_array()

ans=0
tmp_ans=0
for i in range(1,n):
	if H[i-1]>=H[i]:
		tmp_ans+=1
	else:
		if tmp_ans>ans:
			ans=tmp_ans
		tmp_ans=0
if tmp_ans>ans:
	ans=tmp_ans
print(ans)

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

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

  string ans = "No";

  for (int i = 0; i <= x; i++) {
    int k = x-i;
    if (2*i + 4*k == y) ans = "Yes";
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 3624
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();

    long ans = b/x + 1;
    if(a != 0){
      ans -= (a-1)/x + 1;
    }

    System.out.println(ans);

  }
}


Measured memory_bytes: 23764
_= gets.chomp.split.map(&:to_i)
nums = gets.chomp.split.map(&:to_i)

approved_flag = true

g_nums = []

nums.each do |i|
  g_nums << i if i % 2 == 0
end

if g_nums.empty?
  puts "APPROVED"
  else
  g_nums.each do |i|
    if i % 3 == 0 || i % 5 == 0
      next
    else
      approved_flag = false
    end
  end

  if approved_flag == true
    puts  "APPROVED"
  else
    puts  "DENIED"
  end
end


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

long int ans = (int)1e10;

bool primeNumber(long int n){
    bool check = true;
    if(n < 2) return true;
    else{
        for(int i = 2; i <= sqrt(n); i++){
            if(n % i == 0) {
                ans = i;
                check = false;
            }
        }
        return check;
    }
}

int main() {
    long int N;
    cin >> N;
    if (primeNumber(N)) {
        cout << floor(log10(N) + 1) << endl;
    } else {
        cout << floor(log10(N / ans) + 1) << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=500005;
int head[N];
int to[N];
int edge[N];
int Next[N];
int cnt;

void add(int x,int y){
    to[++cnt]=y;
    Next[cnt]=head[x];
    head[x]=cnt;
}

ll ans;
int d[N];
bool vis[N];
void dfs(int x){
    vis[x]=1;
    for(int i=head[x];i;i=Next[i]){
        int y=to[i];
        if(vis[y])continue;
        d[y]=d[x]+1;
        if(d[y]>d[ans])ans=y;
        dfs(y);
    }
}
int x,y;
int main(){
    int n;
    ans=0;
    d[0]=0;
    cin >> n;
    for(int i=1;i<n;++i){
        cin>>x>>y;
        add(x,y);
        add(y,x);
    }
    dfs(1);
    memset(d,0,sizeof(d));
    memset(vis,0,sizeof(vis));
    dfs(ans);
    if(d[ans]%3==1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}


Measured memory_bytes: 14720
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	if (X < Y) {
		swap(A, B);
		swap(X, Y);
	}
	cout << min({ A*X + B*Y, 2*C*X ,2*C*Y + A*(X - Y) }) << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var s = "0 0"
    val b = new ArrayBuffer[String]
    while({s=readLine.trim;s} != "0 0") {
      val a = ("A",s.split(" ").map(_.toInt).sum) +: Array("B","C","D","E").map{i=>(i,readLine.split(" ").map(_.toInt).sum)}
      val max = a.maxBy(_._2)
      b += max._1 + " " + max._2
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 44688
#include <bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define ld long double
using namespace std;

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, c;
  cin>>a;
  
  for(ll i=1; i*i<=a; i++){
      if(a%i==0){
          b = i;
          c = a/i;
      }
  }
  cout<<b+c-2<<endl;
}

Measured memory_bytes: 256
n=int(input())
cost=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
for i in range(n):
    for j in [i+1,i+2]:
        if j<n:
            dp[j] = min(dp[j], dp[i] + abs(cost[i] - cost[j]))
print(dp[n-1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;

bool check_prime(ll n)
{
	ll flag=0,i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			flag=1;
			break;
		}
	}
	if(n==1)
	{
		return false;
	}
	else if(flag==0 || n==2 || n==3)
	{
		return true;
	}
	else
	{
		return false;
	}
}

ll fastexpo(ll a,ll b,ll MOD) 
{
	ll result=1;
	while(b>0)
	{
		if(b%2==1)
		{
			result=(result*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return result;
}

ll dp[1005][1005];

ll rec(ll i,ll j)
{
	if(dp[i][j]!=-1)
	{
		return dp[i][j];
	}
	if(i>0 && j>0)
	{
		dp[i][j]=(rec(i-1,j)+rec(i,j-1))%mod;
	}
	else if(i>0)
	{
		dp[i][j]=rec(i-1,j)%mod;
	}
	else 
	{
		dp[i][j]=rec(i,j-1)%mod;
	}
	return dp[i][j];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i,j;
    cin>>n>>m;
    char c;
    for(i=0;i<n;i++)
    {
    	for(j=0;j<m;j++)
    	{
    		cin>>c;
    		if(c!='\n')
    		{
    			if(c=='.')
    			{
    				dp[i][j]=-1;
    			}
    			else
    			{
    				dp[i][j]=0;
    			}
    		}
    	}
    }
    dp[0][0]=1;
    cout<<rec(n-1,m-1)<<"\n";	//Atlast rec(n-1,m-1) fxn will give us value of dp[n-1][m-1] so write it directly.Note that dp array is used just to avoid repeating recursion steps.
	return 0;
}

Measured memory_bytes: 11440
#!/usr/bin/env python3
import sys
from collections import deque
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7

def array(*args, initial=0):
    pre = "[" * len(args)
    post = ""
    for a in args[::-1]:
        post += " for _ in range(" + str(a) + ")]"
    S = pre + "{}".format(initial) + post
    return eval(S)


def main():
    H, W, K = MAP()
    x1, y1, x2, y2 = MAP()
    # 空間はINF,壁は-1, →↑←↓
    pond = array(H + 2, W + 2, 4, initial=-1)
    for h in range(1, H + 1):
        for w, c in enumerate(input(), start=1):
            if c == ".":
                for i in range(4):
                    pond[h][w][i] = INF
    # 距離(), x, y, 方向
    q = deque()
    q.append(((0, 0), x1, y1, 0))
    q.append(((0, 0), x1, y1, 1))
    q.append(((0, 0), x1, y1, 2))
    q.append(((0, 0), x1, y1, 3))
    DX = (1, 0, -1, 0)
    DY = (0, 1, 0, -1)
    while q:
        new_q = deque()
        while q:
            (a0, a1), x, y, d = q.popleft()
            # 順方向へ進む
            nx = x + DX[d]
            ny = y + DY[d]
            # print((a0, a1), x, y, d, nx, ny)
            if pond[nx][ny][0] == -1:     # 行き止まりなら何もせず
                continue
            if pond[nx][ny][(d + 1) % 4] > a0 + 1:
                pond[nx][ny][(d + 1) % 4] = a0 + 1
                new_q.append(((a0 + 1, 0), nx, ny, (d + 1) % 4))
            if pond[nx][ny][(d - 1) % 4] > a0 + 1:
                pond[nx][ny][(d - 1) % 4] = a0 + 1
                new_q.append(((a0 + 1, 0), nx, ny, (d - 1) % 4))
            if pond[nx][ny][d] >= a0 + 1:
                pond[nx][ny][d] = a0 + 1
                if a1 + 1 < K:
                    q.append(((a0, a1 + 1), nx, ny, d))
                else:
                    new_q.append(((a0 + 1, 0), nx, ny, d))
            if (nx, ny) == (x2, y2):
                print(a0 + 1)
                return
        q = new_q
    print(-1)
    return


if __name__ == '__main__':
    main()


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  for (ll i = 0; i <= x; ++i) {
    ll k = i;
    ll t = x-k;
    if (k*4+t*2 == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3672
x = int(input())

if 1800 <= x:
    a = 1
elif 1600 <= x:
    a = 2
elif 1400 <= x:
    a = 3
elif 1200 <= x:
    a = 4
elif 1000 <= x:
    a = 5
elif 800 <= x:
    a = 6
elif 600 <= x:
    a = 7
elif 400 <= x:
    a = 8

print(a)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
int main(){
	int n;cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	a[0]=1;
	int co=1;
	vector<ll> v;
	for(int i=1;i<n;i++){
		if(a[i]>=a[i-1]+2){
			co++;
			a[i]=a[i-1]+2;
		}else{
			v.push_back(co);
			co=1;
		}
	}
	vector<ll> f(n+1);
	f[0]=1;
	for(ll i=1;i<=n;i++){
		f[i]=f[i-1]*i%MOD;
	}
	v.push_back(co);
	ll res=1;
	ll t=0,sum=0;
	for(int i=0;i<v.size();i+=2){
		sum+=v[i];
		if(i>0){
			sum+=v[i-1];
		}
		if(i+1<v.size()){
			res*=sum-t+1LL;
		}else{
			res*=sum-t;
		}
		res%=MOD;
		t++;
	}
	res*=f[n-t];
	res%=MOD;
	cout<<res<<endl;
}


Measured memory_bytes: 2676
#include <iostream>
#include <cstdio>
#include <deque>
#include <vector>
using namespace std;
const int maxn = 1e5 + 100;
vector<int> G[maxn];
int deep[maxn], sz[maxn], f[maxn];
deque<int> Q;
void dfs(int x, int fa, int d){
    deep[x] = d;
    sz[x] = 1;
    f[x] = fa;
    for(auto to : G[x]){
        if(to == fa) continue;
        dfs(to, x, d+1);
        sz[x] += sz[to];
    }
}

int main()
{
    int n, x, y;
    cin>>n;
    for(int i = 1; i < n; i++){
        scanf("%d %d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1, 1, 1);
    x = n;
    while(x != 1){
        Q.push_back(x);
        x = f[x];
    }
    Q.push_back(1);
    int ansB = 0, ansW = 0, B = 0, W, temp;
    while(1){
        if(Q.empty()){
            ansB += sz[B]-1-sz[W];
            ansW = sz[W] - ansW;
            if(ansB <= ansW) cout<<"Snuke"<<endl;
            else cout<<"Fennec"<<endl;
            return 0;
        }
        temp = B;
        B = Q.back(); Q.pop_back();
        if(temp != 0) ansB += sz[temp]-sz[B]-1;
        if(Q.empty()) {
            ansB += sz[B]-1-sz[W];
            ansW = sz[W] - ansW;
            if(ansW <= ansB) cout<<"Fennec"<<endl;
            else cout<<"Snuke"<<endl;
            return 0;
        }
        W = Q.front(); Q.pop_front();
        ansW++;
    }
}

Measured memory_bytes: 15104
#include<stdio.h>

int max(int a,int b){if(a>b){return a;}return b;}

int main(){
  int l,i,j,b[256]={0},nr,r=0;
  char s[256];
  scanf("%d%s",&l,s);
  for(i=1;i<l-1;i++){
    for(j='a';j<='z';j++){b[j]=0;}
    for(j=0;j<i;j++){b[s[j]]=1;}
    nr=0;
    for(j=i;j<l;j++){if(b[s[j]]){b[s[j]]=0;nr++;}}
    r=max(r,nr);
  }
  printf("%d\n",r);
  return 0;
}

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

int ucli(int x, int y){
	int X = max(x,y);
	int Y = min(x,y);

	if(Y == 0)return X;

	int N = X%Y;

	ucli(Y,N);
}






int	main(){


int W, H, C;
cin >> W >> H >> C;

int a = ucli(W,H);

cout << (W/a)*(H/a)*C << endl;

	return 0;
}


Measured memory_bytes: 3092
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    if(n&1):
        print("No")
        return
    S=input()
    a=S[:n//2]
    b=S[n//2:]
    print("Yes" if(a==b) else "No")
resolve()

Measured memory_bytes: 38384
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

vector<vector<int>> a;

int depth(int x = 1){
	int r = 0;
	vector<int> d(a[x].size());
	for(int i = 0; i < a[x].size(); i++){
		d[i] = depth(a[x][i]);
	}
	sort(d.begin(), d.end(), greater<int>());
	for(int i = 0; i < d.size(); i++){
		r = max(r, d[i] + i + 1);
	}
	return r;
}

int main(){
	int n;
	scanf("%d", &n);
	a = vector<vector<int>>(n + 1, vector<int>());
	vector<int> cnt(n + 1);
	for(int i = 2; i <= n; i++){
		int in;
		scanf("%d", &in);
		a[in].push_back(i);
	}
	printf("%d\n", depth());
	return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<ll> a(n),sm(n+1);
    REP(i,n){
        cin >> a[i];
        sm[i+1]+=sm[i]+a[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    REP(i,n-1){
        dp[i][i+2]=sm[i+2]-sm[i];
    }
    FOR(i,2,n+1){
        for(int j=0;j+i<=n;j++){
            ll tmp=INF;
            for(int k=j+1;k<j+i;k++){
                chmin(tmp,dp[j][k]+dp[k][j+i]+sm[j+i]-sm[j]);
            }
            dp[j][j+i]=tmp;
        }
    }
    cout << dp[0][n] << endl;
}

Measured memory_bytes: 4456
n = int(input())
x = [ int(i) for i in input().split() ]
s = sum(x)
avg = s//n
avg2 = avg+1

ans1 = 0
ans2 = 0
for i in x:
	ans1 += (avg-i)**2
	ans2 += (avg2-i)**2

print(min(ans1,ans2))


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

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

  for (int i = 1; i <= A*B; i++) {
    if (i * A % B == C) {
      cout << "YES" << endl;
      return 0;
    }
    // if (i == B + 1) {
    //   cout << "NO" << endl;
    //   return 0;
    // }
  }
  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Measured memory_bytes: 3064
using System;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    int a = 64;
    while (a > 0) {
      if (a <= n) {
        Console.WriteLine(a);
        break;
      } else {
        a /= 2;
      }
    }
  }
}

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

int main() {
    int n, m, c; cin >> n >> m >> c;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    rep(i,n){
        rep(j,m){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> ab(n,vector<int>(m));
    rep(i,n){
        rep(j,m){
            int &aij = a[i][j];
            int &bj = b[j];
            ab[i][j] = aij*bj;
        }
    }
    vector<int> s(n,c);
    rep(i,n){
        rep(j,m){
            int &abij = ab[i][j];
            s[i] += abij;
        }
    }

    int ans = 0;
    rep(i,n){
        if(s[i] > 0) ans++;
    }
    cout << ans << endl;
    /*
    rep(i,n){
        rep(j,m){
            cout << ab[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    rep(i,n) cout << s[i] << " ";
    cout << endl;
    */
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  long t,a[5];
  cin >> n;
  string s;
  REP(i,5){
    a[i]=0;
  }
  REP(i,n){
    cin >> s;
    REP(j,5){
      if(s[0]=="MARCH"[j])a[j]++;
    }
  }
  t=0;
  FOR(i,0,3){
    FOR(j,1,4){
      FOR(k,2,5){
        if(i<j&&j<k){
          t+=a[i]*a[j]*a[k];
        }
      }
    }
  }
  cout << t;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define MOD 1000000007
#define MAXN 200001
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
using namespace std;

int main() {
    ll n;
    cin >> n;
    ll sum=0;
    f(i,1,n+1){
        if(i%5!=0 && i%3!=0){
            sum+=i;
        }
    }
    cout << sum;
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int N, M;
int dist[110][110];
vector<pair<pi, int>> edges;

signed main(void) {
    cin>>N>>M;
    REP(i, 1, N) {
        REP(j, 1, N) {
            dist[i][j]=INF;
            if (i==j) dist[i][j]=0;
        }
    }
    rep(i, M) {
        int a,b,c; cin>>a>>b>>c;
        edges.pb(mp(mp(a,b), c));
        dist[a][b]=c;
        dist[b][a]=c;
    }
    REP(k, 1, N) {
        REP(i, 1, N) {
            REP(j, 1, N) {
                if (dist[i][j] > dist[i][k]+dist[k][j]) {
                    dist[i][j] = dist[i][k]+dist[k][j];
                }
            }
        }
    }
    int cnt=0;
    rep(i, edges.size()) {
        bool ok=false;
        int start=edges[i].fi.fi;
        int end=edges[i].fi.se;
        int cost=edges[i].se;
        REP(j, 1, N) {
            REP(k, 1, N) {
                if (dist[j][k]==dist[j][start]+cost+dist[end][k]) ok=true;
                if (dist[j][k]==dist[j][end]+cost+dist[start][k]) ok=true;
            }
        }
        if (!ok) cnt++;
    }

    REP(i, 1, N) {
        REP(j, 1, N) {
            cerr << dist[i][j] << "\t";
        }
        cerr << endl;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let main () =
        let n = int_of_string (read_line ()) in
        let a = split (read_line ()) in
        let b = split (read_line ()) in
        let rec loop prev acc a b =
            match a, b with
            | (a1 :: al, b1 :: bl) ->
                    let arest = max 0 (a1 - prev) in
                    let brest = max 0 (b1 - arest) in
                    let acc = acc + a1 - arest + b1 - brest in
                    loop brest acc al bl
            | a1 :: al, [] ->
                    let arest = max 0 (a1 - prev) in
                    acc + a1 - arest
            | _ -> failwith "??"
        in
        Printf.printf "%d\n" (loop 0 0 a b)
    in
    main ()

Measured memory_bytes: 20096
extern crate proconio;
use proconio::{fastout, input, marker::Usize1};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
    }
    let odd = (m + 1) / 2;
    let even = m / 2;
    for i in 0..odd {
        println!("{} {}", i + 1, odd * 2 - i);
    }
    for i in 0..even {
        println!("{} {}", n - i, n - (even * 2 - i));
    }
}


Measured memory_bytes: 2200
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;

    vector<ll> a(n+1,0);
    for(ll i=0;i<n-1;i++){
        a[i+1]+=a[i];
        if(s[i]=='A' && s[i+1]=='C'){
            a[i+1]++;
        }
    }

    vector<ll> b;
    for(ll i=0;i<q;i++){
        ll l,r;
        cin>>l>>r;

        b.push_back(a[r-1]-a[l-1]);
    }

    for(ll i=0;i<q;i++){
        cout<<b[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 2676
import itertools

#import length
S = input()
#import list
l = input().split()

i = 0
if len(l) < 3:
    print('0')
else:

    for v in itertools.combinations(l, 3):
        #print(v)
        if v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
        #if v[1] + v[2] = 3:
            if int(v[0]) + int(v[1]) > int(v[2]) and int(v[1]) + int(v[2]) > int(v[0]) and int(v[0]) + int(v[2]) > int(v[1]) :
                i = i +1

    print(i)

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);//this works only
    cin.tie(NULL);// when first all inputs are from user
    cout.tie(NULL);//you will see all outputs afterwards
    int n,k,r,p,s;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    int len=t.length();
    ll score=0;
    for (int i = 0; i < len; ++i)
    {
    	if(i<k)
    	{
    		if(t[i]=='r')
    		{
    			score+=p;
    			t[i]='p';	
    		} 
    		else if(t[i]=='s') 
			{
				score+=r;
				t[i]='r';	
			}
    		else 
    		{
    			t[i]='s';
    			score+=s;	
    		}
    	}
    	else
    	{
    		if(t[i]=='r')
    		{
    			if(t[i-k]=='p')
    			{
    				if((i+k)<len)
    				{
    					if(t[i+k]=='p')t[i]='r';
    					else if(t[i+k]=='s') t[i]='s';
    				}
    				continue;
    			}
    			else
    			{
    				score+=p;
    				t[i]='p';
    			}
    		}
    		else if(t[i]=='p')
    		{
    			if(t[i-k]=='s')
    			{
    				if((i+k)<len)
    				{
    					if(t[i+k]=='r')t[i]='r';
    					else if(t[i+k]=='s') t[i]='p';
    				}
    				continue;
    			}
    			else
    			{
    				score+=s;
    				t[i]='s';
    			}	
    		}
    		else
    		{
    			if(t[i-k]=='r')
    			{
    				if((i+k)<len)
    				{
    					if(t[i+k]=='r')t[i]='s';
    					else if(t[i+k]=='p') t[i]='p';
    				}
    				continue;
    			}
    			else
    			{
    				score+=r;
    				t[i]='r';
    			}
    		}
    	}
    }
   // cout<<t<<endl;
    cout<<score;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAX_D (200)
#define MAX_N (200)

int d, n;
int t[MAX_D];
int a[MAX_N], b[MAX_N], c[MAX_N];

int dp[MAX_D + 1][MAX_N];
// dp[ ?????\????????§??????????????? ][ ?????????????????? ] = ????????§????´??????????????¨?

int search(int i, int last)
{
	int &res = dp[i][last];
	
	if (res != -1) return (res);
	
	if (i == d) return (res = 0);
	
	for (int j = 0; j < n; j++){
		if (t[i] < a[j] || b[j] < t[i]) continue;
		int sub = abs(c[last] - c[j]);
		res = max(res, sub + search(i + 1, j));
	}
	
	return res;
}

int main()
{
	scanf("%d %d", &d, &n);
	for (int i = 0; i < d; i++){
		scanf("%d", &t[i]);
	}
	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	}
	
	memset(dp, -1, sizeof(dp));
	
	int ans = 0;
	for (int i = 0; i < n; i++){
		if (t[0] < a[i] || b[i] < t[0]) continue;
		ans = max(ans, search(1, i));
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 1368
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  string s,s2;
  while(cin>>s>>s2,s!="0"){
    int blow[10]={};
    int hitc=0,blowc=0;
    for(int i=0;i<4;i++){
      if(s[i]==s2[i])hitc++;
      else {blow[s[i]-'0']++;blow[s2[i]-'0']++;}
    }
    for(int i=0;i<=10;i++)
      if(blow[i]==2)blowc++;
    cout<<hitc<<" "<<blowc<<endl;
  }
  return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    vector<int64_t> sum(n+1,0);
    //sum[n]=a[0]-a[1]+a[2]+....-a[n]
    rep(i,n){
        if(i%2==0){
            sum[i+1] = sum[i] + a[i];
        }
        else{
            sum[i+1] = sum[i] - a[i];
        }
    }
    rep(i,n){
        int64_t ans;
        if(i%2==0){
         ans= sum[n]-sum[i] - sum[i];
        }
        else{
            ans =-(sum[n]-sum[i]) + sum[i];
        }
        cout<<ans<<" ";
    }
}

Measured memory_bytes: 4580
n=int(input())
p=[]
m=[]

for i in range(n):
    x,y=list(map(int,input().split()))
    p.append(x+y)
    m.append(x-y)

minp=min(p)
maxp=max(p)
minm=min(m)
maxm=max(m)

ans=[maxp-minp,maxm-minm,minm,maxm,minp-maxp]
print(max(ans))

Measured memory_bytes: 24952
use std::io::Read;
use std::cmp;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf);

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    // 入力を受け取る
    let n: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", (n * (n - 1)) / 2);
}

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

int		main(void)
{
	int		arr[32]  = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int		k;
	cin >> k;
	cout << arr[k - 1];
}


Measured memory_bytes: 256
N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))

if N >= M:
    print(0)
    exit()
    
r = abs(X[-1] - X[0])

difference = []

for i in range(M-1):
    difference.append(abs(X[i]-X[i+1]))

difference.sort()

while N-1 > 0:
    r -= difference[-1]
    del difference[-1]
    N -= 1
print(r)


Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int in;
    cin >> in;
    mp[in]++;
  }
  mint ans = 1;
  if(n % 2 == 0){
    for(auto p : mp){
      if(p.first % 2 == 0 || p.second != 2){
        ans = 0;
        break;
      }
      ans *= 2;
    }
  }else{
    for(auto p : mp){
      if((p.first % 2 != 0) || (p.first != 0 && p.second != 2) || (p.first == 0 && p.second != 1)){
        ans = 0;
        break;
      }
      if(p.first != 0) ans *= 2;
    }
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 6612
n = int(input())
lis = [x for x in range(1, n+1, 2)]
ans = 0

for a in lis:
  lis2 = []
  for b in range(1, a+1):
    if a % b == 0:
      lis2.append(b)
  if len(lis2) == 8:
    ans += 1

print(ans)

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
# abc152/abc152_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    P = i2nn()
    min_i = P[0]
    cnt = 0
    for i in range(N):
        if min_i >= P[i]:
            min_i = P[i]
            cnt += 1
    print(cnt)
    return

main()


Measured memory_bytes: 26848
#include<stdio.h>
 
int handan(int i);
 
int main(void)
{
   int x,y;
 
   scanf("%d%d",&x,&y);
 
   x=handan(x);
   y=handan(y);
 
   if(x==y)
      printf("Yes\n");
   else
      printf("No\n");
   return 0;
}
 
int handan(int i)
{
   int a;
 
   if(i==2) a=2;
   else if((i==4)||(i==6)||(i==9)||(i==11)) a=1;
   else a=0;
   return a;
}

Measured memory_bytes: 128
n, *b = map(int, open(0).read().split())
l = []
while 1:
    for i in reversed(range(len(b))):
        if i + 1 == b[i]:
            del b[i]
            l += i + 1,
            break
    else:
        break
if b:
    print(-1)
    exit()
for i in l[::-1]:
    print(i)

Measured memory_bytes: 9048
// https://atcoder.jp/contests/abc148/tasks/abc148_f

#include <bits/stdc++.h>
using namespace std;
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 

const int maxn = 100500;
vector<int> G[maxn];

int tdis[maxn], adis[maxn];

void bfs(int st, int arr[]) {
    queue<int> Q;
    Q.push(st);
    arr[st] = 0;

    while(!Q.empty()) {
        int S = Q.front(); Q.pop();

        for(int adj: G[S]) {
            if(arr[adj] > arr[S]+1) {
                arr[adj] = arr[S]+1;
                Q.push(adj);
            }
        }
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.sync_with_stdio(0);
    cin.tie(0);

    int N, u, v;
    cin >> N >> u >> v;

    for(int i = 1; i <= N-1; i++) {
        int a, b;
        cin >> a >> b;

        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    for(int i = 1; i <= N; i++) {
        tdis[i] = adis[i] = INT_MAX-100;
    }

    bfs(u, tdis);
    bfs(v, adis);

    for(int i = 1; i <= N; i++) {
        cerr << tdis[i] << " ";
    }
    cerr << endl;

    for(int i = 1; i <= N; i++) {
        cerr << adis[i] << " ";
    }
    cerr << endl;
    int ma = 0;
    for(int i = 1; i <= N; i++) {
        if(tdis[i] < adis[i] and adis[i] > ma) {
            ma = adis[i];
        }        
    }

    cout << ma-1 << endl;
}

Measured memory_bytes: 9956