akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main() {
	int total,num;
	char mark,marks[4]={'S','H','C','D'};
	vector<vector<int> > a(4,vector<int>(13));
	for(int i=0;i<4;++i) {
		for(int j=0;j<13;++j) {
			a[i][j]=0;
		}
	}
	cin >> total;
	for(int i=0;i<total;++i) {
		cin >> mark >> num;
		switch(mark) {
		case 'S' :
			a[0][num-1]=1;
			break;
		case 'H' :
			a[1][num-1]=1;
			break;
		case 'C' :
			a[2][num-1]=1;
			break;
		case 'D' :
			a[3][num-1]=1;
			break;
		}
	}
	for(int i=0;i<4;++i) {
		for(int j=0;j<13;++j) {
			if (a[i][j]==0) {
				printf("%c %d\n",marks[i],j+1);
			}
		}
	}
	return 0;
}

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

int main(){
    int n, b, f, r, v;
    int x[4][3][10] = {0};
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        
        x[b-1][f-1][r-1] += v;
    }
    
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                cout << " " << x[i][j][k];
            }
            cout << endl;
        }
        if(i == 3) break;
        cout << "####################" << endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                         \
  ifstream in("atcoder-problems/nikkei2019_2_qual_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  map<int, int> m;
  rep(i, N) {
    int d;
    cin >> d;
    m[d]++;
    if (i == 0 && d != 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (m[0] > 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  ll mod = 998244353;

  repi(i, 1, m.size()) {
    if (m[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    ll pat = modpow(m[i-1], m[i], mod);
    ans = ans * pat % mod;
  }

  cout << ans << endl;
}

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

typedef long long ll;

int main() {
    int N, M, X, ans = 0;
    cin >> N >> M;
    vector<int> n(100001, 0), even(M, 0), odd(M, 0);
    rep(i, N) {
        cin >> X;
        n[X]++;
    }
    rep(i, 100001) {
        even[i % M] += n[i] / 2 * 2;
        odd[i % M] += n[i] % 2;
    }
    rep(i, M / 2 + 1) {
        if (i == 0 || i + i == M) ans += (even[i] + odd[i]) / 2;
        else {
            int x = even[i] + odd[i];
            int y = even[M - i] + odd[M - i];
            if (x == y) ans += x;
            else if (x < y) {
                ans += x + min(even[M - i], y - x) / 2;
            } else {
                ans += y + min(even[i], x - y) / 2;
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1408
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int bits=200;
string bitsets(int n){
    bitset<20> t;
    t = n;
    string str;//string类
    str = t.to_string();//bitset类成员函数to_string()
    return str;
}
int main(){
	int n,q;
	cin>>n;
	int *A=new int[n];
	for(int i=0;i<n;++i)cin>>A[i];
	
    int max=pow(2,n);
    int *B=new int[max];
	for(int i=1;i<max;++i){
       
		 bitset<20> t;
         t =i;
         int sum=0;
         for(int j=0;j<20;++j){
         	if(t[j]==1)sum+=A[j];
         }
         B[i-1]=sum;
   	}
    
	cin>>q;
	int m;
	for(int i=0;i<q;++i){
		cin>>m;
		int j=0;
		for(;j<max;++j){
			if(B[j]==m){
				cout<<"yes"<<endl;
				break;
			}
			
		}
		if(j==max)cout<<"no"<<endl;
	}
	
   
}


Measured memory_bytes: 7272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    ll h, w, n; cin >> h >> w >> n;
    vector<ll> v;
    rep(i, n){
        ll a; cin >> a;
        rep(j, a) v.push_back(i+1);
    }
    bool rev = false;
    rep(i, v.size()){
        if(!rev){
            // cout << i << endl;
            cout << v[i] << " ";
            if((i+1) % w == 0) rev = true, cout << endl;;
        }
        else{
            // cout << ((i/w+1)*w-1) - (i - i/w*w) << endl;
            cout << v[((i/w+1)*w-1) - (i - i/w*w)] << " ";
            if((i+1) % w == 0) rev = false, cout << endl;
        }
    }
}


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

int main(){
  int x,a,b,z,y;
  cin >> x >> a >> b;
  
  if(a-x>0){
    z=a-x;
  }else{
    z=x-a;
  }
  if(b-x>0){
    y=b-x;
  }else{
    y=x-b;
  }
  if(z>y){
    cout << "B" << endl;
  }else{
    cout << "A" <<endl;
  }
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = [0]
ans = 0
for i in range(n):
    l.append(l[i] + a[i])
c = Counter(l)
for i in c.values():
    ans += i * (i - 1) // 2
print(ans)

Measured memory_bytes: 113224
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    int n;
    cin >> n;
    int a=0,b=0,c=0,d=0;
    rep(i,n){
        string s;
        cin>> s;
        if(s=="AC"){
            a++;
        }else if(s=="WA"){
            b++;
        }else if(s=="TLE"){
            c++;
        }else{
            d++;
        }
    }
    cout<<"AC x ";
    cout<<a<<endl;
    cout<<"WA x ";
    cout<<b<<endl;
    cout<<"TLE x ";
    cout<<c<<endl;
    cout<<"RE x ";
    cout<<d<<endl;
    return 0;
}

Measured memory_bytes: 3636
// AOJ Volume 1 Problem 0151 Grid

#include <stdio.h>
#include <string.h>

int max_len;
int len;

void get_maxlen(int x)
{
    if (x == 0){
        if (len > max_len){
            max_len = len;
        }
        
//        printf("[%d]", len);
        
        len = 0;
        return;
    }
    len++;
}


int main(void)
{
    int map[255][255];
    char in[256];
    int n;
    int x, y;
    int d;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }

        max_len = 0;
        
        for (y = 0; y < n; y++){
            scanf("%s", in);
            for (x = 0; x < n; x++){
                if (in[x] == '0'){
                    map[y][x] = 0;
                }
                else {
                    map[y][x] = 1;
                }
            }
        }

        // ¡
        for (y = 0; y < n; y++){
            get_maxlen(0);
            for (x = 0; x < n; x++){
                get_maxlen(map[y][x]);
            }
            get_maxlen(0);
        }
        
        // c
        for (x = 0; x < n; x++){
            get_maxlen(0);
            for (y = 0; y < n; y++){
                get_maxlen(map[y][x]);
            }
            get_maxlen(0);
        }
        
        
        // EÎß
        for (y = n - 1; y >= 0; y--){
            d = 0;
            x = 0;
            get_maxlen(0);
            do {
                get_maxlen(map[y + d][x + d]);
                d++;
            } while (x + d < n && y + d < n);
            get_maxlen(0);
        }
        for (x = 1; x < n; x++){
            d = 0;
            y = 0;
            get_maxlen(0);
            do {
                get_maxlen(map[y + d][x + d]);
                d++;
            } while (x + d < n && y + d < n);
            get_maxlen(0);
        }
        
        // ¶Îß
        for (x = 0; x < n; x++){
            d = 0;
            y = 0;
            get_maxlen(0);
            do {
                get_maxlen(map[y + d][x - d]);
                d++;
            } while (x - d >= 0 && y + d < n);
            get_maxlen(0);
        }
        for (y = 1; y < n; y++){
            d = 0;
            x = n - 1;
            get_maxlen(0);
            do {
                get_maxlen(map[y + d][x - d]);
                d++;
            } while (x - d < n && y + d < n);
            get_maxlen(0);
        }

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

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

template<typename T>
int32_t partition(vector<T> &A, int32_t p, int32_t r) {
    T x = A[r];
    int32_t i = p - 1;

    for (int32_t j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }

    swap(A[i+1], A[r]);

    return i+1;
}

int main() {
    int32_t n;

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

    int32_t q = partition(A, 0, n-1);

    for (int32_t i = 0; i < n; i++) {
        if (i == q) {
            cout << "[" << A[i] << "]";
        } else {
            cout << A[i];
        }

        if (i == n - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int a,b;cin>>a>>b;
    cout<<(b%a==0 ? a+b:b-a);
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func min(a,b int) int {
	if a<b {
		return a
	}
	return b
}

func main() {
	var l,r int
	fmt.Scan(&l,&r)

	if r-l > 2019 {
		r = l+2019
	}

	ans := 2020

	for i := l; i < r; i++ {
		for j := i+1; j < r+1; j++ {
			ans = min(ans,i*j%2019)
		}
	}

	fmt.Println(ans)
	
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;
long long dp[105][105][105];
int L;int k;string n;
long long f(int l,int st,int flag){
    if(st>k)return 0;
    if(l>=L)return st==k;
    //long long &DP=dp[l][st][flag];
    if(dp[l][st][flag]!=-1)return dp[l][st][flag];
    int upper=flag?n[l]-'0':9;
    long long ans=0;
    rep(i,0,upper)ans+=f(l+1,st+(i!=0),flag&&(i==upper));
    return dp[l][st][flag]=ans;
}
int main(){
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    cin>>k;
    L=n.length();
    memset(dp,-1,sizeof(dp));
    //rep(l,0,L)rep(st,0,k)rep(f,0,1)dp[l][st][f]=-1;
    cout<<f(0,0,1);
}
/* 
Find the number of integers between 1and N(inclusive) that contains exactly Knon-zero digits when written in base ten.
N<1e100 ,k<4
k==1: 1~9,10~90,100~900...
k==2: 11~99,101 110 
 */

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

int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}

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

#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"

typedef long long ll;
typedef long double ld;

const ld pi=3.1415926535897932384626433;
const int mod = 1000000007;
const ll inf=3e18;
int main ()
{
   bolt;
   ll n;
   cin>>n;
   vector <ll> a(n);
   vector <pair <ll,ll> > v1,v2;
   map <ll,ll> mp;
   for (ll i=0;i<n;i++)
   {
      cin>>a[i];
   }
   for (ll i=0;i<n;i+=2)
   {
      mp[a[i]]++;
   }

   for (auto it: mp)
   {
      v1.pb({it.S,it.F});
   }
   sort (v1.begin(),v1.end());
   reverse(v1.begin(),v1.end());

   mp.clear();
   for (ll i=1;i<n;i+=2)
   {
      mp[a[i]]++;

   }
   for (auto it: mp)
   {
      v2.pb({it.S,it.F});
   }
   
   sort (v2.rbegin(),v2.rend());
   if (v1[0].S!=v2[0].S)
   {
      cout<<n-v1[0].F-v2[0].F;
   }
   else
   {
      if (v1.size()==1 and v2.size()!=1)
      {
         cout<<n-v1[0].F-v2[1].F;}

      else if (v1.size()!=1 and v2.size()==1)
      {
         cout<<n-v1[1].F-v2[0].F;
      }
      else if (v1.size()==1 and v2.size()==1)
      {
         cout<<n/2;
      }
      else
      cout<<min(n-v1[0].F-v2[1].F,n-v1[1].F-v2[0].F);
   }
}


Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;


int main(){
  int a,b,c;
  int64_t ans;
  cin >> a >> b >> c;
  if(a+b>=c)ans = b+c;
  else if(b>=c)ans = b+c;
  else ans = a+2*b+1;  
  cout << ans;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using P = pair<int, int>;

// dp1[i][j] := 1~i番目の料理でj分以内に完食できる美味しさの合計の最大値
int dp1[3010][6020];
// dp2[i][j] = i~N番目の料理でj分以内に完食できる美味しさの合計の最大値
int dp2[3010][6020];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    vector<P> ab(n);
    for(int i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 6020; j++) {
            if(j < t) {
                chmax(dp1[i + 1][j + ab[i].first], dp1[i][j] + ab[i].second);
            }
            chmax(dp1[i + 1][j], dp1[i][j]);
        }
    }

    for(int i = n; i >= 1; i--) {
        for(int j = 0; j < 6020; j++) {
            if(j < t) {
                chmax(dp2[i][j + ab[i - 1].first],
                      dp2[i + 1][j] + ab[i - 1].second);
            }
            chmax(dp2[i][j], dp2[i + 1][j]);
        }
    }

    int ans = max(dp1[n][t - 1], dp2[1][t - 1]);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < t; j++) {
            chmax(ans, dp1[i][j] + dp2[i + 2][t - 1 - j] + ab[i].second);
        }
    }

    cout << ans << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n; cin>>n;
    vll v(n);
    ll x = 0;
    for(i = 0; i < n; i++){
        cin>>v[i];
        x ^= v[i];
    }
    for(i = 0; i < n; i++){
        ll a = v[i] ^ x;
        cout << a << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4768
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int x[][3]={0,1,2,0,1,2,0,1,2,0,0,0,1,1,1,2,2,2,0,1,2,0,1,2};
int y[][3]={0,0,0,1,1,1,2,2,2,0,1,2,0,1,2,0,1,2,0,1,2,2,1,0};

int main() {
	char ban[3][3];
	while(cin>>ban[0][0],ban[0][0]!='0'){
		cin>>ban[0][1]>>ban[0][2]>>ban[1][0]>>ban[1][1]>>ban[1][2]>>ban[2][0]>>ban[2][1]>>ban[2][2];
		int i;
		bool win=false;
		for(i=0;i<8;i++){
			if(ban[y[i][0]][x[i][0]]=='b'&&ban[y[i][1]][x[i][1]]=='b'&&ban[y[i][2]][x[i][2]]=='b'){cout<<"b"<<endl;win=true;break;}
			if(ban[y[i][0]][x[i][0]]=='w'&&ban[y[i][1]][x[i][1]]=='w'&&ban[y[i][2]][x[i][2]]=='w'){cout<<"w"<<endl;win=true;break;}
		}
		if(win==false)cout<<"NA"<<endl;
	}
	return 0;
}

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

int main() {
    string t;  cin >> t;
    stack<char> s;
    for (int i = 0; i < (int)t.size(); ++i) {
        if (!s.empty() && s.top() == 'S' && t[i] == 'T') s.pop();
        else s.push(t[i]);
    }
    cout << s.size() << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[55][55][2555];

void mod_add(ll &a, ll b){
	a += b;
	a %= MOD;
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	ll n, score;cin >> n >> score;
	dp[0][0][0] = 1;
	REP(i, n){
		REP(j, i+1)REP(k, score + 1){
			ll nj = j;
			mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k]);
			nj = j + 1;
			mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k]);
			nj = j;
			ll x = 2 * j;
			mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k] * x);
			nj = j - 1;
			x = j * j;
			if(j)mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k] * x);
		}
	}
	cout << dp[n][0][score] << endl;
	return 0;
}


Measured memory_bytes: 55552
#include <bits/stdc++.h>
using namespace std;
bool comparator(pair<long, long> a, pair<long, long> b)
{
    return a.second > b.second;
}

int main()
{
    int n, k, d, t;
    cin >> n >> k;
    vector<pair<long, long>> sushi(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> t >> d;        
        --t;
        sushi[i].first = t;
        sushi[i].second = d;
    }

    sort(sushi.begin(), sushi.end(), comparator);
    
    priority_queue<int, vector<int>, greater<int>> pq;
    long long deli = 0, vari = 0;
    vector<bool>used(n , false);
    for(int i = 0; i < k; ++i)
    {
        deli += sushi[i].second;
        if(!used[sushi[i].first])
        {
            used[sushi[i].first] = true;
            ++vari;
        }
        else
        {
            pq.push(sushi[i].second);
        }
    }
    long long ans = deli + vari*vari;
    for(int i = k; i < n; ++i)
    {
        if(!used[sushi[i].first] && !pq.empty())
        {
            int tp = pq.top();
            pq.pop();
            used[sushi[i].first] = true;
            deli += sushi[i].second - tp;
            ++vari;
        }
        ans = max(ans, deli + vari*vari);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2176
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

#define sq(x) ((x)*(x))

ll INF = 1LL << 60;

ll MOD = 1000000007LL;

struct edge {
    int to; ll dist;
    edge() {} ~edge() {}
    edge(int to, ll dist): to(to), dist(dist) {}
};

struct state {
    int v; ll cost;
    state() {} ~state() {}
    state(int v, ll cost): v(v), cost(cost) {}
    bool operator < (const state& o) const { return cost > o.cost; }
};

int N, M, S, T;
vector<vector<edge>> graph;
vector<tuple<int, int, int>> edges;

vector<ll> min_cost;
vector<ll> num;

void calc(int start, int goal) {
    fill(begin(min_cost), end(min_cost), INF);
    fill(begin(num), end(num), 0);

    min_cost[start] = 0;
    num[start] = 1;

    priority_queue<state> pq;
    pq.emplace(start, 0);
    while (!pq.empty()) {
        state s = pq.top(); pq.pop();
        if (min_cost[s.v] < s.cost) continue;
        for (int i = 0; i < graph[s.v].size(); ++i) {
            edge& e = graph[s.v][i];
            ll cost = s.cost + e.dist;
            if (cost < min_cost[e.to]) {
                min_cost[e.to] = cost;
                num[e.to] = num[s.v];
                pq.emplace(e.to, cost);
            } else if (cost == min_cost[e.to]) {
                num[e.to] = (num[e.to] + num[s.v]) % MOD;
            }
        }
    }
}

int main() {

    cin >> N >> M >> S >> T;
    --S; --T;
    min_cost.resize(N);
    num.resize(N);
    graph.resize(N);
    for (int j = 0; j < M; ++j) {
        int u, v; ll d; cin >> u >> v >> d; --u; --v;
        graph[u].emplace_back(v, d);
        graph[v].emplace_back(u, d);
        edges.emplace_back(u, v, d);
    }

    calc(S, T);
    vector<ll> min_cost1 = min_cost;
    vector<ll> num1 = num;
    calc(T, S);
    vector<ll> min_cost2 = min_cost;
    vector<ll> num2 = num;

    ll dd = min_cost1[T];

    ll ans = sq(num1[T]) % MOD;
    for (int j = 0; j < N; ++j) {
        if (min_cost1[j] + min_cost2[j] == dd && min_cost1[j] == min_cost2[j]) {
            ans = (ans - sq(num1[j]*num2[j]%MOD)%MOD + MOD) % MOD;
        }
    }

    for (auto e : edges) {
        int u, v, d;
        tie(u, v, d) = e;
        if (min_cost1[u] > min_cost1[v]) swap(u, v);
        if (min_cost1[u] + d + min_cost2[v] == dd &&
                min_cost1[u] < (double) dd / 2 && min_cost2[v] < (double) dd / 2) {
            ans = (ans - sq(num1[u]*num2[v]%MOD)%MOD + MOD) % MOD;
        }
    }
    cout << ans << endl;



    return 0;
}




Measured memory_bytes: 22404
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  int a,b;
  cin>>a>>b;
  if((b-1)%(a-1)==0)cout<<(b-1)/(a-1);
  else cout<<(b-1)/(a-1) +1;




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

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

int N, X, Y;
void solve() {
  cin >> N >> X >> Y;
  vector<int> kosuu(N);
  X--; Y--;
  for(int i = 1; i < N; i++){
    kosuu.at(i) = N - i;
  }
  for(int i = 0; i < N - 1; i++){
    for(int j = i + 1; j < N; j++){
      if(j - i > abs(X - i) + abs(Y- j) + 1){
        kosuu.at(j - i)--;
        kosuu.at(abs(X - i) + abs(Y- j) + 1)++;
      }
    }
  }
  for(int i = 1; i < N; i++){
    cout << kosuu.at(i) <<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

using namespace std;

int input[1005];

int main()
{
	int N;
	scanf("%d", &N);
	bool approved = true;

	for (int i = 0; i < N; ++i)
	{
		int temp;
		scanf("%d", &temp);

		if (approved)
		{
			if (temp % 2 == 0)
			{
				if (temp % 3 && temp % 5)
				{
					approved = false;
				}
			}
		}
	}

	if (approved) printf("APPROVED\n");
	else printf("DENIED");

	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int k;
    cin >> k;
    ll ans = 0;
    rep1(i, k) rep1(j, k) rep1(h, k) {
        ans += gcd(gcd(i, j), h);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
n, l = map(int, input().split())

diff = 0
if l+1-1 < 0 and l+n-1 > 0:
    diff = 0
elif l+1-1 < 0:
    diff = l+n-1
else:
    diff = l+1-1

ans = 0
for i in range(1,n+1):
    ans += l+i-1

print(ans-diff)


Measured memory_bytes: 2940
# AtCoder Beginner Contest 115
# C - Christmas Eve

N,K=map(int,input().split())

TREES=[]

for i in range (N):
    TREES.append(int(input()))
# print(TREES)

TREES.sort()
# print(TREES)

diff=[0]
for i in range (1,N):
    if i <K:
        d=abs(TREES[i]-TREES[0])
    else:
        d=abs(TREES[i]-TREES[i-K+1])
    diff.append(d)

# print(diff)
print(min(diff[K-1:]))

Measured memory_bytes: 17724
import java.util.*;
 
 
public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M[] = new int[N];
      int count =0;
      int flag =0;
      for(int n = 0; n<N; n++){
          M[n] = sc.nextInt();
      }
     while (true){
         for(int n = 0; n<N; n++){
             int remainder= M[n] % 2;
             if(remainder == 1){
                 flag =1;
             }
             M[n]= M[n] / 2;
         }
         if(flag==1){
             break;
         }
         count++;
     }
     System.out.println(count);
         }
}

Measured memory_bytes: 21716
N=int(input())
numlist=[int(input()) for _ in range(N)]
numdict={y:x for x,y in enumerate(numlist)}
sorted_list=sorted(numdict.items(),reverse=True)

nextS=lambda Snow,child : Snow+2*child-N

amount_of_child=[1]*N
sum_of_distance_of_child=[0]*N
branch_list=[]

for S,num in sorted_list:
  nS=nextS(S,amount_of_child[num])
  if nS in numdict:
    nextnum=numdict[nS]
    branch_list.append([num+1,nextnum+1])
    amount_of_child[nextnum]+=amount_of_child[num]
    sum_of_distance_of_child[nextnum]+=(sum_of_distance_of_child[num]+amount_of_child[num])
    if amount_of_child[nextnum]==N:
      break
  else:
    print (-1)
    exit()

if sorted_list[-1][0]==sum_of_distance_of_child[sorted_list[-1][1]]:
  for _ in range(N-1):
    x,y=branch_list.pop()
    print(x,y)
else:
  print (-1)
exit()


Measured memory_bytes: 49544
Scanf.scanf "%s" (fun w ->
    let h = Array.make 26 0 in
    String.iter (fun v -> let q = int_of_char v - 97 in h.(q) <- h.(q) + 1) w;
    print_endline @@ if Array.fold_left (lor) 0 h mod 2 = 0 then "Yes" else "No"
)

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

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
int n, mod;
vector<int> g[N], pre[N], suf[N];
int dp[N], sol[N];

int add(int a, int b)
{
	return (a + b) % mod;
}

int sub(int a, int b)
{
	return (a - b + mod) % mod;
}

int mul(int a, int b)
{
	return (1ll * a  * b) % mod;
}

void dfs(int node, int parent)
{
	pre[node].resize(g[node].size());
	suf[node].resize(g[node].size());
	int cur = 1;
	for(int i = 0; i < g[node].size(); i++)
	{
		int child = g[node][i];
		if(child != parent)
		{
			dfs(child, node);
			cur = mul(cur, dp[child]);
		}
		pre[node][i] = cur;
	}
	cur = 1;
	for(int i = (int)g[node].size() - 1; i >= 0; i--)
	{
		int child = g[node][i];
		if(child != parent)
			cur = mul(cur, dp[child]);
		suf[node][i] = cur;
	}
	dp[node] = add(1, cur);
}

//dp[node] = p * s + 1
//dp[child] = (dp[child] - 1) * dp[parent] + 1
void dfs2(int node, int parent)
{
	sol[node] = dp[node];
	for(int i = 0; i < g[node].size(); i++)
	{
		int child = g[node][i];
		if(child != parent)
		{
			//save data
			int dp1 = dp[node], dp2 = dp[child];

			//update dp[node]
			int p = i ? pre[node][i - 1] : 1, s = (i + 1 < g[node].size()) ? suf[node][i + 1] : 1;
			dp[node] = add(mul(dp[parent], mul(p, s)), 1);

			//update child
			dp[child] = add(mul(sub(dp[child], 1), dp[node]), 1);

			//dfs
			dfs2(child, node);

			//undo data
			dp[node] = dp1, dp[child] = dp2;
		}
	}
}


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
	// freopen("", "r", stdin);
	// freopen("", "w", stdout);
#endif
	cin >> n >> mod;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 1);
	dp[0] = 1;
	dfs2(1, 0);
	for(int i = 1; i <= n; i++)
		cout << sub(sol[i], 1) << '\n';
	return 0;
}


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

const int mod = 2019;

int main() {
  string s;
  cin >> s;
  int n = s.size();

  vector<int> dp(n+1, 0);
  vector<int> ct(2019, 0);

  int dig = 1;
  ct[0] = 1;  // Φ
  for ( int i = n-1; i >= 0; i-- ) {
    dp[i] = (dp[i+1] + (s[i]-'0') * dig) % mod;
    ct[dp[i]]++;
    dig = (dig*10) % mod;
  }

  int ans = 0;
  for ( int i = 0; i < mod; i++ ) {
    ans += ct[i]*(ct[i]-1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4352
from collections import defaultdict


data = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))

rows = int(input())

for _ in range(rows):
    b, f, r, v = map(int, input().split())
    data[b][f][r] += v

for b in range(1, 4+1):
    for f in range(1, 3+1):
        print(' ' + ' '.join(str(data[b][f][r]) for r in range(1, 10+1)))
    if b != 4:
        print('#'*20)


Measured memory_bytes: 6004
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;

int main(void){
    ll n ;
    cin >> n ;

    ll count = 0 ;
    ll ans = 0 ;
    
    ll a ;
    ll now ;
   cin >> now ;
   
    for(ll i = 0 ; i < n-1 ; i++ ){
       
        cin >> a ;
        if(a <= now ){
            count ++ ; 

        }else{
            
            if(count > ans){
                ans = count ;
            }
            count = 0 ;
        }
       
        now = a ;
        

    }
    if(count > ans){
                ans = count ;
            }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,M;
struct color{
	double L;
	double a;
	double b;
};
color A[30];
int main(){
	cin>>N>>M;
	double ans = 0;
	for(int i = 0;i < N;i++){
		cin>>A[i].L>>A[i].a>>A[i].b;
	}
	/*rep(i,N){
		cout<<A[i].L<<A[i].a<<A[i].b<<endl;
	}*/
	int cnt;
	for(int i = 0;i <1<<N;i++){
		int B[22]={0};
		cnt = 0;
		//cout <<i<<endl;
		for(int j = 0;j < N;j++){
			if(i>>j&1){
				cnt++;
				B[j] = 1;
			}
		}
		if(cnt==M){
			double sum = 0;
			for(int j = 0;j < N;j++){
				for(int k = j+1;k < N;k++){
					if(B[j]==1&&B[k]==1){
						sum +=pow((A[j].L-A[k].L),2)+pow((A[j].a-A[k].a),2)+pow((A[j].b-A[k].b),2);
						ans = max(ans,sum);
					}
				}
			}
		}
	}
	printf("%.20lf\n",ans);
	return 0;
}

Measured memory_bytes: 1248
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" (
        fun n -> 
                n
)

let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string

let lst2 = List.map2 (fun i elmnt -> (i, elmnt)) (List.range 1 `To n) lst
           |> List.fast_sort (fun (ai, ae) (bi, be) -> compare ae be)
           |> List.map (fun (i, e) -> i)

let () = 
        List.iter (fun elmnt -> Printf.printf "%d " elmnt) lst2;
        Printf.printf "\n"


Measured memory_bytes: 21436
#include <stdio.h>

int main(){
	int house[4][3][10] = { 0 };
	int n,b,f,r,v;
	int i,j,k;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		house[b - 1][f - 1][r - 1]+=v;

	}

	for (i = 0; i < 4; i++){
		for (j = 0; j < 3; j++){
			for (k = 0; k < 10; k++){
				
					printf(" %d", house[i][j][k]);
			
				
			}
			printf("\n");
		}
		if (i != 3){
			printf("####################\n");
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n, d, ans = 0;
				
				cin >> n >> d;
			 while(n--)
				{
				  long long int x, y;

      cin >> x >> y;
								
      long long int dist = x * x + y * y;

      if(dist <= d * 1LL * d) ans++;
    }
				

    cout << ans << "\n";
}

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

long long dp[100010];
int x,n;
vector <int> V;

int main()
{
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> x;
        V.push_back(x);
    }

    dp[0]=0;
    dp[1]=abs(V[0]-V[1]);
    for (int i=2;i<n;i++){
        dp[i]=dp[i-1]+abs(V[i]-V[i-1]);
        dp[i]=min(dp[i], dp[i-2]+abs(V[i]-V[i-2]));
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1528
n, m = map(int, input().split())
x = map(int, input().split())
y = map(int, input().split())

tmp_x = 0
for i, xi in enumerate(x):
    tmp_x += (xi + 1) * (2 * i - (n - 1))
tmp_x = tmp_x % 1000000007

tmp_y = 0
for i, yi in enumerate(y):
    tmp_y += (yi + 1) * (2 * i - (m - 1))
tmp_y = tmp_y % 1000000007

print ((tmp_x * tmp_y) % 1000000007) 

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

#define M 1000000007

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;

vector< vector<lli> > comb(lli n, lli r) {
	vector< vector<lli> > v(n + 1, vector<lli>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % M;
		}
	}
	return v;
}

int main() {
	lli n, k, i, j, x, y, ans;
	vector< vector<lli> >p,q;

	cin >> n >> k;

	p = comb(n, k + 1);

	repj(i,1, k+1) {
		if (n - k + 1 < i) {
			cout << 0 << endl;
			continue;
		}
		j = p[k-1][i-1];
		ans = p[n - k + 1][i];
		ans *= j;
		ans %= M;
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef pair<long long,long long> P;

P ary[300010];
long long N;

bool isok(long long n){
	if(n==0) return true;
	priority_queue<long long> que;
	long long now=n-1;
	long long sum=0;
	for(long long i=0;i<n;i++){
		que.push(ary[i].second);
		sum+=ary[i].second;
	}
	while(sum>ary[now].first*n){
		now++;
		if(now>=N) return false;
		sum-=que.top();que.pop();
		sum+=ary[now].second;
		que.push(ary[now].second);
	}
	return true;
}


int main(){
	cin>>N;
	long long a,b;
	for(long long i=0;i<N;i++){
		cin>>a>>b;
		ary[i]=P(b,a);
	}
	sort(ary,ary+N,greater<P >());
	long long lb=-1,ub=N+1,mid;
	while(ub-lb>1){
		mid=(lb+ub)/2;
		if(isok(mid)){
			lb=mid;
		}
		else{
			ub=mid;
		}
	}
	cout<<lb<<endl;
	return 0;
}

Measured memory_bytes: 13820
n = gets.chomp.to_i

nums = nums = gets.scan(/\d+/).map(&:to_i)

map = Hash.new(0)

nums.each_with_index {|val, idx| map[val+idx] = (map[val+idx]+1)}

ans = 0

nums.each_with_index {|val, idx| ans += map[idx-val]}

puts ans


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

int main(){
    int N;
    cin >> N;
    vector<int> hand(N), w(N), yancle;
    for(int i = 0; i < N; i++) cin >> hand[i];
    for(int i = 0; i < N; i++) cin >> w[i];
    for(int i = 1; i < N; i++) yancle.emplace_back(i);

    int ans = 1e9;
    do{ 
        int res = 0;
        int left = yancle[N-3];
        int mid = yancle[N-2];
        int right = 0;
        for(int n = 0; n < N; n++){
            if(hand[mid] == 0 && hand[right] == 1) res += w[mid];
            if(hand[mid] == 1 && hand[left] == 0) res += w[mid];
            left = mid;
            mid = right;
            if(n < N-1) right = yancle[n];
        }
        ans = min(ans, res);
    }while(next_permutation(yancle.begin(), yancle.end()));

    cout << ans << endl;
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    P(N*N);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
using namespace std;
typedef long long int llint;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a > b) {
		swap(a, b);
	}
	if (c > d) {
		swap(c, d);
	}
	cout << a + c << endl;
	return 0;
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		solver.readK(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readS(String str) {
		S = str;
	}

	String S;

	public void readK(String str) {
		int k = Integer.parseInt(str);
		char rep = S.charAt(k - 1);
		String ans = "";

		for (char c : S.toCharArray()) {
			if (c == rep)
				ans = ans + c;
			else
				ans = ans + "*";
		}
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<ll> x(100010);
vector<bool> used(100010);
vector<P> V[100010];
void dfs(int t){
    if(used[t])return;
    used[t] = true;
    for(auto p:V[t]){
        if(used[p.first]){
            if(x[t] + p.second != x[p.first]){
                //cout << t << " " << x[t] << " " << p.second << " " << x[p.first] << endl;
                cout << "No" << endl;
                exit(0);
            }
        }else{
            x[p.first] = x[t] + p.second;
            dfs(p.first);
        }
    }
    
}
main(){
    int N,M;
    cin >> N >> M;
    rep(i,0,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        V[a].push_back(P(b,c));
        V[b].push_back(P(a,-c));
    }
    rep(i,0,N){
        if(!used[i])dfs(i);
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 12416