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

bool dfs(int H,int W,vector<string> &s);
int bfs(int H,int W,int sx,int sy,int gx,int gy,vector<string> &a);

int main(){

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

  vector<string> s(H);
  for(int i=0;i<H;i++)
  cin>>s.at(i);

  bool ikeru=dfs(H,W,s);

  if(ikeru){
    int saitan=bfs(H,W,1,1,W,H,s);
    int souwa=H*W;
    int syouheki=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        // if((i==0&&j==0)||(i==H-1)&&(j==W-1))
        // continue;
        if(s.at(i).at(j)=='.')
        syouheki++;
      }
    }
    int ans=syouheki-(saitan+1);
    cout<<ans<<endl;
  }
  else
  cout<<-1<<endl;

}

bool dfs(int H,int W,vector<string> &s){
  vector<vector<bool>> judge(H,vector<bool>(W,0));
  stack<int> x;
  x.push(0);
  stack<int> y;
  y.push(0);
  vector<int> dx={-1,0,1,0};
  vector<int> dy={0,1,0,-1};
  bool ans=false;

  while(!(x.empty())){

    bool check=false;
    for(int i=0;i<4;i++){
      int nx=x.top()+dx.at(i);
      int ny=y.top()+dy.at(i);
      if(nx<0||ny<0||nx>=H||ny>=W){
        continue;
      }
      if((s.at(nx).at(ny)!='#')&&!(judge.at(nx).at(ny))){
        x.push(nx);
        y.push(ny);
        judge.at(nx).at(ny)=1;
        check=true;
      }
    }

    if(!(check)){
      if((x.top()==H-1)&&(y.top()==W-1)){
        ans=true;
      }
      x.pop();
      y.pop();
    }
  }

  return ans;

}

int bfs(int H,int W,int sx,int sy,int gx,int gy,vector<string> &a){
  queue<int> qy;
  queue<int> qx;
  qy.push(sy-1);
  qx.push(sx-1);
  vector<vector<bool>> reached(H,vector<bool>(W,0));
  reached.at(sy-1).at(sx-1)=1;
  vector<vector<int>> num(H,vector<int>(W,10000000));
  num.at(sy-1).at(sx-1)=0;

  vector<int> dy={-1,0,1,0};
  vector<int> dx={0,1,0,-1};

  while(!(qy.empty())){
    int y=qy.front();
    int x=qx.front();

    for(int i=0;i<4;i++){
      int yy=y+dy.at(i);
      int xx=x+dx.at(i);
      if(xx<0||yy<0||xx>=W||yy>=H)
      continue;
      if((a.at(yy).at(xx)!='#')&&!(reached.at(yy).at(xx))){
        num.at(yy).at(xx)=min(num.at(yy).at(xx),num.at(y).at(x)+1);
        reached.at(yy).at(xx)=1;
        qy.push(yy);
        qx.push(xx);
      }
    }
    qy.pop();
    qx.pop();
  }

  int ans=num.at(gy-1).at(gx-1);
  return ans;

}


Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

char c[101][101];
char cT[201][101];

int main()
{
  int h, w;
  cin >> h >> w;

  for (int i = 1; i <= 2 * h; i++) {
    for (int j = 1; j <= w; j++) {
      if (i <= h) cin >> c[i][j];
      cT[i][j] = c[(i + 1) / 2][j];
      if (j == w) cout << cT[i][j] << endl;
      else        cout << cT[i][j];
    }
  }
  // for (int i = 1; i <= 2 * h; i++) {
  //   for (int j = 1; j <= w; j++) {
  //     cT[i][j] = c[(i + 1) / 2][j];
  //
  //     if (j == w) cout << cT[i][j] << endl;
  //     else        cout << cT[i][j];
  //   }
  // }
}


Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-8;
///////////////////////////////////////

struct node{
    string a,b;
    bool operator<(const node x)const{
        if(a<x.a)return true;
        return a==x.a&&b<x.b;
    }
    bool operator==(const node x)const{
        return a==x.a&&b==x.b;
    }
};

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    vector<node>v,w;;
    rep(i,0,(1<<n)-1){
        string a,b;
        rep(j,0,n-1){
            if((i>>j)&1)a+=s[j];
            else b+=s[j];
        }
        node x;x.a=a;x.b=b;
        v.pb(x);
    }
    reverse(s.begin(),s.end());
    rep(i,0,(1<<n)-1){
        string a,b;
        rep(j,0,n-1){
            if((i>>j)&1)a+=s[j];
            else b+=s[j];
        }
        node x;x.a=a;x.b=b;
        w.pb(x);
    }
    sort(v.begin(),v.end());sort(w.begin(),w.end());
    ll vpos=0,wpos=0;
    ll ans=0;
    while(vpos<=(1<<n)-1&&wpos<=(1<<n)-1){
        if(w[wpos]<v[vpos]){
            wpos++;
        }else if(v[vpos]<w[wpos]){
            vpos++;
        }else{
            ll xa=1,xb=1;
            while(vpos<=(1<<n)-2&&v[vpos]==v[vpos+1]){
                xa++;vpos++;
            }
            while(wpos<=(1<<n)-2&&w[wpos]==w[wpos+1]){
                xb++;wpos++;
            }
            vpos++;wpos++;
            ans+=xa*xb;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 69356
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
using namespace std;
using ll=long long;
using R=double;

int find2(ll a){
	int count = 0;
	while(a%2!=1){
		a = a/2;
		count++;
	}
	return count;
}

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;

	int front[N]={0};
	int back[N] = {0};
	int A[N];

	int count_f = 0;
	int count_b = 0;

	for(int i = 0; i < N-1; i++){
		if(S[i]=='W'){
			count_f++;
		}
		front[i+1]=count_f;
	}

	for(int i = N-1; i > 0; i--){
		if(S[i]=='E'){
			count_b++;
		}
		back[i-1]=count_b;
	}

	for(int i = 0; i < N; i ++){
		A[i] = front[i]+back[i];
	}

	sort(A,A+N);

	cout << A[0] << endl;
	return 0;

}


Measured memory_bytes: 4228
/*** 𝕒𝕜𝕤𝕙𝕒𝕪𝕜𝕦𝕞𝕒𝕣𝟡𝟡 ***/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=5e5+1;
 
typedef long long ll;
typedef long double ld;

ll blocksize = 2000, n, m, ans = 0;
ll a[N];
ll cont[N];
ll answer[N];

void remove(ll ind)
{
	if(cont[a[ind]] == 1)
		ans--;
    cont[a[ind]]--;
}
void add(ll ind)
{
    cont[a[ind]]++;
    if(cont[a[ind]] == 1)
		ans++;
}
ll getanswer()
{
    return ans;
}
struct Query
{
    ll l, r, ind;
    bool operator<(Query other) const
    {
        return make_pair(l/blocksize, r)<make_pair(other.l/blocksize, other.r);
    }
};

void mosalgo(vector<Query> queries)
{
    // vector<ll> answer(queries.size());
    sort(all(queries));
    ll curl=0, curr=-1;
    for(Query q : queries)
    {
        while(curl>q.l)
        {
            curl--;
            add(curl);
        }
        while(curr<q.r)
        {
            curr++;
            add(curr);
        }
        while(curl<q.l)
        {
            remove(curl);
            curl++;
        }
        while(curr>q.r)
        {
            remove(curr);
            curr--;
        }
        answer[q.ind]=ans;
    }
}

void test_case()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<Query> v;
    for(int i = 0; i < m; i++)
    {
        ll x,y;
        cin >> x >> y;
        x--;y--;
        v.pu({x,y,i});
    }
    mosalgo(v);
    for(int i = 0; i < m; i++)
        cout<<answer[i]<<'\n';

}

int main()
{
    IOS();
   
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 38240
#define loop(i,j,k) for(long long i = j;i < k;i++)

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int64_t n;
    cin >> n;
    int64_t a[300][300],b[300][300];
    loop(i,0,n)loop(j,0,n)b[i][j] = 0;
    loop(i,0,n)loop(j,0,n)cin>>a[i][j];
    loop(k,0,n)loop(i,0,n)loop(j,0,n){if(a[i][j] > a[i][k] + a[k][j]) {
        cout << -1;
        return 0;
    } else if (a[i][j] == a[i][k] + a[k][j] && i != k && j != k) {
        b[i][j] = INT32_MAX / 2;
    }}
    int64_t res = 0;
    loop(i,0,n)loop(j,0,n)if(b[i][j] != INT32_MAX / 2)res += a[i][j];
    cout << res / 2;
}


Measured memory_bytes: 1664
from collections import deque

n=int(input())

tree=[[] for i in range(n)]
for i in range(n-1):
 a,b,c=map(int,input().split())
 tree[a-1].append([b-1,c])
 tree[b-1].append([a-1,c])

q,k=map(int,input().split())
dist=[-1 for i in range(n)]
dist[k-1]=0

que=deque()
que.append(k-1)

while que:
 x=que.popleft()
 for i,c in tree[x]:
  if dist[i]==-1:
   que.append(i)
   dist[i]=dist[x]+c

for i in range(q):
 x,y=map(int,input().split())
 print(dist[x-1]+dist[y-1])

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

int count_one(int bit)
{
    bitset<15> bs(bit);
    return bs.count();
}

int main()
{
    // データの格納
    int n, ans = 0;
    cin >> n;
    int A[n];
    vector<vector<pair<int,int>>> vvp;
    for (int i = 0; i < n; ++i)
    {
        cin >> A[i];
        vector<pair<int,int>> vp(A[i]);
        for (int j = 0; j < A[i]; ++j)
        {
            int x, y;
            cin >> x >> y;
            vp.push_back(make_pair(x, y));
        }
        vvp.push_back(vp);
    }

    // int pattern = (int)pow(2,n);   // 組み合わせ通り数

    // {0b0, 0b1, ..., 0b(pattern-1)} の全探索
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        int cnt = count_one(bit);
        bool ok = true;
        // cout << bitset<15>(bit) << ": " << endl;

        for (int i = 0; i < n; ++i)
        {
            bool honest = ((bit>>i) & 1 == 1) ? true : false;
            // cout << "\thonest: " << boolalpha << honest << endl;

            for (auto && evp : vvp[i])
            {
                if (!ok) { break; }

                int sft = evp.first - 1;
                bool obj = (bit >> sft) % 2;   // 人 x_ij の素性(x_ij)
                bool tst = evp.second;         // 人 i による証言(y_ij)

                if (honest)   // honest == true のみ考えればよい
                {
                    // cout << boolalpha << "\t\tobj: " << obj
                    //      << ", tst: " << tst << endl;
                    if (obj ^ tst) { ok = false; }
                } else {
                    break;
                }
            }
        }

        if (ok)
        {
            // cout << "\tok!\n" << endl;
            ans = max(cnt, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

#初期化
N = int(input())
L = []
for i in range(N):
	x, y, h = getlist()
	L.append([x, y, h])

#探索
for i in range(101):
	for j in range(101):
		D = defaultdict(int)
		for k in range(N):
			if L[k][2] != 0:
				val = abs(L[k][0] - i) + abs(L[k][1] - j) + L[k][2]
				D[val] += 1
		if len(D) == 1:
			judge = "Yes"
			for k in range(N):
				if val - abs(L[k][0] - i) - abs(L[k][1] - j) > L[k][2]:
					judge = "No"
					break
			if judge == "Yes":
				print(i, j, val)

Measured memory_bytes: 3316
let readCharArray () = stdin.ReadLine().ToCharArray()

let rec solve num chars =
    match chars with
    | 'A' :: 'B' :: 'C' :: xx -> solve (num + 1) xx
    | _ :: xx -> solve num xx
    | [] -> num

stdin.ReadLine()

readCharArray ()
|> Array.toList
|> solve 0
|> printfn "%d"


Measured memory_bytes: 29896
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    bool can = true;
    REP(i, S.size()) {
        if (S[i] != T[i]) {
            can = false;
            break;
        }
    }
    if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    string s;
    while(cin>>s)
    {
        int num=0;
        int l=s.length();
        for(int i=1;i<l;i++)
        {
            if(s[i]!=s[i-1])
                num++;
        }
        cout<<num<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define lli long long int

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,d;
	cin>>n>>d;
	int den = 2*d+1;
	int ans = n/den;
	if((n%den)>0)
		ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e5 + 5;
vector<int> g[N];
bool used[N];
int x, y, pc = 0;

void dfs(int node) {
    used[node] = true;
    for (int to : g[node]) {
        if (!used[to]) {
            dfs(to);
        }
        else if (to == y) {
            pc++;
        }
    }
}

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

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

    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int i = 0; i < n; i++) {
        if (g[i].size() % 2) {
            cout << "No";
            return 0;
        }
    }

    for (int i = 0; i < n; i++) {
        if (g[i].size() > 4) {
            cout << "Yes\n";
            return 0;
        }
    }

    int c = 0;

    for (int i = 0; i < n; i++) {
        if (g[i].size() == 4) {
            c++;
        }
    }

    if (c > 2) {
        cout << "Yes\n";
        return 0;
    }
    else if (c == 2) {
        x = 0, y = n - 1;

        while (g[x].size() != 4)
            x++;
        while (g[y].size() != 4)
            y--;

        used[y] = 1;
        dfs(x);

        if (pc == 4) {
            cout << "No\n";
        }
        else {
            cout << "Yes\n";
        }
    }
    else {
        cout << "No\n";
    }

    return 0;
}

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

int N;
int A[ 200100 ];

long long Chk( int b )
{
int i;
long long iSum;

	iSum = 0;
	for( i = 0; i < N; i++ )
	{
		iSum += abs( A[ i ] - b );
	}
	
	return iSum;
}

int main()
{
int i;
long long iSum;
long long iA;
long long iB;

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

	cin >> N;

	for( i = 0; i < N; i++ )
	{
		cin >> A[ i ];

		A[ i ] -= i + 1;
	}

	sort( A, A + N );

	if( N % 2 != 0 )
		cout << Chk( A[ N / 2 ] ) << endl;
	else
	{
		iA = Chk( A[ N / 2 - 1 ] );
		iB = Chk( A[ N / 2 ] );

		cout << min( iA, iB ) << endl;
	}

	return 0;
}




Measured memory_bytes: 1024
// AOJ q0041
// YAMADA Terushige
// 2013.5.18

#include<iostream>
#include<string>
#include<vector>
 
using namespace std;

typedef vector<pair<string,int> > Term;
typedef Term::iterator It;

string calc(Term term){
  if(term.size()==1){
    if(term[0].second==10)
      return term[0].first;
    else return "0";
  }
  for(int i=0;i<term.size();i++){
    for(int j=0;j<term.size();j++){
      if(i==j) continue;
      Term newt;
      for(int k=0;k<term.size();k++){
	if(k!=i && k!=j) newt.push_back(term[k]);
      }
      string ex;
      int val;
      // +
      ex='('+term[i].first+'+'+term[j].first+')';
      val=term[i].second+term[j].second;
      newt.push_back(make_pair(ex,val));
      ex=calc(newt);
      if(ex!="0") return ex;
      newt.pop_back();

      // -
      ex='('+term[i].first+'-'+term[j].first+')';
      val=term[i].second-term[j].second;
      newt.push_back(make_pair(ex,val));
      ex=calc(newt);
      if(ex!="0") return ex;
      newt.pop_back();

      // *
      ex='('+term[i].first+'*'+term[j].first+')';
      val=term[i].second*term[j].second;
      newt.push_back(make_pair(ex,val));
      ex=calc(newt);
      if(ex!="0") return ex;
      newt.pop_back();
    }
  }
  return "0";
}

int main(){

  int a,b,c,d;
  string aa,bb,cc,dd;
  while(1){
    Term term;
    cin >> a >> b >> c >> d;
    if (a==0 && b==0 && c==0 && d==0) break;
    aa='0'+a;
    bb='0'+b;
    cc='0'+c;
    dd='0'+d;
    term.push_back(make_pair(aa,a));
    term.push_back(make_pair(bb,b));
    term.push_back(make_pair(cc,c));
    term.push_back(make_pair(dd,d));

    cout << calc(term) << endl;;
  }


}


Measured memory_bytes: 1212
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  int N;
  char word[100][11];
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    scanf("%s", word[i]);
  }
  
  int l = 0; int k = 0;
  
  for(int i = 0; i < N; i++){
    if(i > 0){
      for(int j = 0; j < i; j++){
        if(strcmp(word[i], word[j]) == 0){
          l += 1;
        }
      }
      
      if(word[i - 1][strlen(word[i - 1]) - 1] == word[i][0]){
        k += 1;
      }
    }
  }
  
  if(l == 0 && k == N - 1){
    printf("%s\n", "Yes");
  }
  else{
    printf("%s\n", "No");
  }
  
  return 0;
}
      

Measured memory_bytes: 128
N = gets.chomp.to_i
count = 0
prev_max = 0
nums = gets.chomp.split(" ").map(&:to_i)
nums.each_with_index do |num, i|
    if i == 0
        count += 1
        prev_max = num
    else
        if prev_max <= num
            count += 1
            prev_max = num
        end
    end
end

puts count

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char s[12];
long long int f(char *t){
  long long int i,res=0,x=0;
  int len=strlen(t);
  i=1;
  x=(t[0]-48);
  while(t[i]!='\0'){
    if(t[i]=='+'){
      res+=x;
      x=0;
    }
    else{
      x*=10;
      x+=(t[i]-48);
    }
    i++;
  }
  //printf("%d\n",res);
  return res;
}
int main(){
  long long int ans=0;
  long long int x,res,i,j,k;
  int len;
  char t[22];
  scanf("%s",s);
  len=strlen(s);
  if(len==1){
    printf("%d",s[0]-48);
    return 0;
  }
  for(i=0;i<1<<(len-1);i++){
    x=0;
    for(j=0;j<len;j++){
      t[x]=s[j];
      x++;
      if((i>>j) & 1){
	t[x]='+';x++;
      }
    }
    t[x]='+';
    t[x+1]='\0';
    //printf("%s\n",t);
    ans+=f(t);
  }
 
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

		int D = sc.nextInt();

		if (D == 25) {
			System.out.println("Christmas");
		} else if (D == 24) {
			System.out.println("Christmas Eve");
		} else if (D == 23) {
			System.out.println("Christmas Eve Eve");
		} else {
			System.out.println("Christmas Eve Eve Eve");
		}
	}
}


Measured memory_bytes: 21716
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Map<Integer, List<Obj>> map = new HashMap<Integer, List<Obj>>();
		for (int i = 0; i < m; i++) {
			Obj o = new Obj();
			o.l = sc.nextInt();
			o.r = sc.nextInt();
			o.d = sc.nextInt();

			List<Obj> listL = map.get(o.l);
			if (listL == null) {
				listL = new ArrayList<Obj>();
				map.put(o.l, listL);
			}
			listL.add(o);

			List<Obj> listR = map.get(o.r);
			if (listR == null) {
				listR = new ArrayList<Obj>();
				map.put(o.r, listR);
			}
			listR.add(o);
		}
		sc.close();

		int[] x = new int[n + 1];
		boolean[] f = new boolean[n + 1];

		for (Integer l : map.keySet()) {
			if (f[l]) {
				continue;
			}
			Queue<Integer> que = new ArrayDeque<Integer>();
			que.add(l);
			f[l] = true;
			while (!que.isEmpty()) {
				Integer cur = que.poll();
				List<Obj> list = map.get(cur);
				for (Obj o : list) {
					if (f[o.l]) {
						if (f[o.r]) {
							if (x[o.r] != x[o.l] + o.d) {
								System.out.println("No");
								return;
							}
						} else {
							x[o.r] = x[o.l] + o.d;
							que.add(o.r);
							f[o.r] = true;
						}
					} else {
						if (f[o.r]) {
							x[o.l] = x[o.r] - o.d;
							que.add(o.l);
							f[o.l] = true;
						} else {
							throw new Exception();
						}
					}
				}
			}
		}
		System.out.println("Yes");
	}

	static class Obj {
		int l, r, d;
	}
}


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

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

namespace NyaGadget
{
	/**
	@brief 素因数分解ライブラリ
	@note
	 nを素因数分解する。
	 ans[i]がnだったとき、素因数分解して得られた積のなかにn個の素数iが含まれていることを表す。
	 例えば n=12 のとき ans[2] = 2, ans[3] = 1 となるので 12 = 2 * 2 * 3 と分かる。
	**/
	void PrimeFactorization(ll n, map<ll, ll>& ans)
	{
		for (ll i = 2; i * i <= n; i++)
		{
			while (n % i == 0)
			{
				ans[i]++;
				n /= i;
			}
		}
		if (n != 1)
			ans[n]++;
	}
}

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define ceil(a, b) ceil((ld) a / (ld) b);                         // div ceiling
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

using namespace NyaGadget;


int main(void)
{
	ll a, b, x; cin >> a >> b >> x;

	if (x < a * a * b / 2)
	{
		double max = a * a * b;
		double y = 2.0 * (double)x / a / b;
		cout << std::setprecision(10) << atan2((double)b, y) * 180.0 / 3.141592653589793;
	}
	else
	{
		double max = a * a * b;
		double y = 2.0 * (double)(max - x) / a / a;


		cout << std::setprecision(10) << atan2(y, (double)a) * 180.0 / 3.141592653589793;
	}
	return 0;
}


Measured memory_bytes: 256
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>
#include <set>
#include <numeric>
#include <memory.h>

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define REP(i,n) FOR(i,0,n)

//#define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

int N;
int a[100010];

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N;
    int mx = 0, mn = 999999;
    REP(i,N) {
        cin >> a[i];
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }

    if (mx > mn + 1) {
        cout << "No" << endl;
        return 0;
    }

    if (mx == mn) {
        if (mx == N - 1 || mx <= N / 2) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        int p = 0, q = 0;
        REP(i,N) {
            if (a[i] == mx) p++;
            else q++;
        }
        if (p == 1) {
            cout << "No" << endl;
            return 0;
        }
        if (p / 2 + q >= mx && mx >= q + 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n, a, b;
    vector<int> lens;
    cin >> n >> a >> b;
    lens.resize(n-1);

    for(int i=0;i<lens.size();i++){
        lens[i] = 0;
    }
    
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            int len = (abs(j-i)<1+abs(a-i)+abs(b-j)?abs(j-i):1+abs(a-i)+abs(b-j));
            lens[len-1]++;
            //cout << i << " " << j << " " << len << endl;
        }
    }

    for(int i=0;i<lens.size();i++){
        if(i==lens.size()-1){
            cout << lens[i] << endl;
            break;
        }
        cout << lens[i] << " ";
    }
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int j=1;
  for(int i=0;i<N;i++){
    if(j*2<j+K){
      j*=2;
    }
    else{
      j+=K;
    }
  }
  cout << j;
}

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

long long int N, a, b, i;
vector<long long> e[114514];

long long nimber(int n, int s){
    if(e[n].empty())return 1;
    long long int ret = 0;
    for(t : e[n]){
        if(t != s)ret ^= nimber(t, n) + 1;
    }
    return ret;
}

int main(){
    scanf("%lld", &N);
    for(; i < N - 1; ++i){
        scanf("%lld%lld", &a, &b);
        e[a].push_back(b);
        e[b].push_back(a);
    }
    if(nimber(1, 1))puts("Alice");
    else puts("Bob");
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> heights;
    vector<int> DP;
    heights.resize(n);
    DP.assign(n, -1);
    for(int i=0; i<n; i++)
    {
        cin>>heights[i];
    }

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

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define reps(i, s, n) for(int i = (s); i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, s, n) for(int i = (n) - 1; i >= (s); i--)
#define INF ~(1 << 31)
#define INFL ~(1LL << 63)

int main()
{
    int d, t, s;
    cin >> d >> t >> s;

    if(s * t >= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    int cnt[10][10] = {0};
    for (int i = 1; i <= n; i++)
    {
        int k = i;
        int num1 = k % 10;
        while (true)
        {
            //DBG(i);
            if (k >= 1 && k <= 9)
            {
                //DBG(i);
                break;
            }
            k = k / 10;
        }
        int num2 = k;
        cnt[num2][num1]++;
    }
    ll ans = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            ans += 1ll * cnt[i][j] * cnt[j][i];
            //DBG(ans);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import copy

def main():
    while True:
        n,m,t,p = map(int,input().split())
        if not n and not m and not t and not p:
            return

        dlist,clist = [],[]
        
        for _ in range(t):
            d,c = map(int,input().split())
            dlist.append(d)
            clist.append(c)

        coorlist = [tuple(map(int,input().split())) for _ in range(p)]

        oldm = [[1 for _ in range(m)] for _ in range(n)]

        for d,c in zip(dlist,clist):
            if d == 1: # →
                if 2*c <= n:
                    newm = [[0 for _ in range(m)] for _ in range(n-c)]
                    for i in range(c):
                        for j in range(m):
                            newm[i][j] = oldm[c+i][j] + oldm[c-1-i][j]
                    for i in range(c,n-c):
                        for j in range(m):
                            newm[i][j] = oldm[c+i][j]
                    n = n-c
                else:
                    newm = [[0 for _ in range(m)] for _ in range(c)]
                    for i in range(n-c):
                        for j in range(m):
                            newm[i][j] = oldm[c+i][j] + oldm[c-1-i][j]
                    for i in range(n-c,c):
                        for j in range(m):
                            newm[i][j] = oldm[c-1-i][j]
                    n = c
            else: # ↑
                if 2*c <= m:
                    newm = [[0 for _ in range(m-c)] for _ in range(n)]
                    for i in range(n):
                        for j in range(c):
                            newm[i][j] = oldm[i][c+j] + oldm[i][c-1-j]
                    for i in range(n):
                        for j in range(c,m-c):
                            newm[i][j] = oldm[i][c+j]
                    m = m-c
                else:
                    newm = [[0 for _ in range(c)] for _ in range(n)]
                    for i in range(n):
                        for j in range(m-c):
                            newm[i][j] = oldm[i][c+j] + oldm[i][c-1-j]
                    for i in range(n):
                        for j in range(m-c,c):
                            newm[i][j] = oldm[i][c-1-j]
                    m = c
            oldm = newm

        ans = 0
        for c in coorlist:
            print(oldm[c[0]][c[1]])

def visualize(mmap):
    print("------------------")
    for j in range(len(mmap[0])):
        print('|', end="")
        for i in range(len(mmap)):
            print(mmap[i][len(mmap[0])-1-j], '|', end="")
        print()
    print("------------------")


if __name__ == '__main__':
    main()



Measured memory_bytes: 6364
#include <stdio.h>
#include <string.h>
int main(){
    
    int arr[3][3]={0};
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            scanf("%d", &arr[i][j]);
        }
    }
    int X;
    scanf("%d", &X);
    int numb[X]={0};
    
    for (int k=0;k<X;k++){
        scanf("%d", &numb[k]);
        for(int l=0;l<3;l++){
            for(int m=0;m<3;m++){
                if(numb[k] == arr[l][m]){
                    arr[l][m] = 0;
                }
            }
        }
    }
    if(arr[0][0]==0 && arr[0][1]==0 && arr[0][2]==0){
        printf("Yes");
    } else if(arr[1][0]==0 && arr[1][1]==0 && arr[1][2]==0){
        printf("Yes");
    } else if(arr[2][0]==0 && arr[2][1]==0 && arr[2][2]==0){
        printf("Yes");
    } else if(arr[0][0]==0 && arr[1][0]==0 && arr[2][0]==0){
        printf("Yes");
    } else if(arr[0][1]==0 && arr[1][1]==0 && arr[2][1]==0){
        printf("Yes");
    } else if(arr[0][2]==0 && arr[1][2]==0 && arr[2][2]==0){
        printf("Yes");
    } else if(arr[0][0]==0 && arr[1][1]==0 && arr[2][2]==0){
        printf("Yes");
    } else if(arr[0][2]==0 && arr[1][1]==0 && arr[2][0]==0){
        printf("Yes");
    } else {
        printf("No");    
    }
    
    return 0;
}
 

Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    // input
    int n;
    cin >> n;
 
    int a[n];
    int maximum = 0;
    int maximum2 = 0;
    bool isMaximums = false;
    REP(i,n){
        cin >> a[i];
        maximum = max(maximum,a[i]);
    }

    int max_cnt = 0;
    REP(i,n){
        if(a[i] == maximum){
            ++max_cnt;
            if(max_cnt > 1){
                isMaximums = true;
                break;
            }
        } else {
            maximum2 = max(maximum2,a[i]);
        }
    }

    // logic
    REP(i,n){
        if(maximum > a[i] || isMaximums) cout << maximum << endl;
        else cout << maximum2 << endl;
    }
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define MOD (1000003LL)
typedef long long Int;

typedef pair<pair<int, int>, int> ST;
int n;
vector<int> g[60000];
map<ST, int> memo;
set<pair<int, int> > es;

void add(int p, int q) {
    if (p > q) swap(p, q);
    g[p].push_back(q);
    es.insert(mp(p, q));
}

Int rec(int p, int q, int x, int y) {
    if (p+1 == q) return x == y;
    const ST sig(mp(p, q), x*2+y);
    if (memo.count(sig)) return memo[sig];
    const int r = *(lower_bound(g[p].begin(), g[p].end(), q)-1);
    Int ans = 0;
    rep (k, 2) ans = (ans + rec(p, r, x, k) * rec(r, q, 1-k, y)) % MOD;
    if (x && y && es.count(mp(p, q))) {
        rep (k, 2) ans = (ans + rec(p, r, 0, k) * rec(r, q, 1-k, 0)) % MOD;
    }
    return memo[sig] = ans;
}

int main() {
    for (;;) {
        int m, a, b;
        scanf("%d%d", &n, &m);
        if (n == 0) return 0;
        rep (i, 60000) g[i].clear();
        es.clear();
        rep (_, m) {
            scanf("%d%d", &a, &b);
            add(a-1, b-1);
        }
        rep (i, n) add(i, (i+1)%n);
        rep (i, n) sort(g[i].begin(), g[i].end());
        memo.clear();
        printf("%d\n", (int)rec(0, n-1, 1, 1));
    }
}

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

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

	int divisors = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0) {
			divisors++;
		}
	}
	cout << divisors << endl;
}


Measured memory_bytes: 3136
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	a := scanString()

	c := make(map[rune]int, 0)

	for _, e := range a {
		c[e]++
	}

	ans := 1 + len(a)*(len(a)-1)/2

	for _, e := range c {
		ans -= (e-1)*e/2
	}

	fmt.Println(ans)
}

Measured memory_bytes: 1408
suits = ['S','H','C','D']
  
table = [[False]*14 for i in range(4)]
  
N = int(input())
  
for loop in range(N):
  
    mark,num = input().split()
    num = int(num)
  
    if mark == 'S':
        table[0][num] = True
    elif mark == 'H':
        table[1][num] = True
    elif mark == 'C':
        table[2][num] = True
    else:
        table[3][num] = True
  
for i in range(4):
    for k in range(1,14):
        if table[i][k] == False:
            print("%s %d"%(suits[i],k))


Measured memory_bytes: 5604
S=list(input())
T=list(input())

for i in range(len(S)):
    S_temp=S[len(S)-1]
    for j in range(len(S) - 1, 0, -1):
        S[j]=S[j-1]
    S[0]=S_temp
    if "".join(S)=="".join(T):
        print("Yes")
        exit()

print("No")

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

// ************* All the directives ***********************
#define bk back()              // back function for vector
#define co cout <<             // std output
#define ci cin >>              // std input
#define ft front()             // front function for vector
#define gl getline             // string input
#define mp make_pair           // function to get a pair
#define pb push_back           // push_back function for vector
#define ss stringstream        // use string as a stream instead of std input/output
#define wt while(t--)          // while loop for t test-cases

// ************* All the typedefs *************************
typedef pair<int, string> pis     ;    // pair of integer-string
typedef pair<int, int> pii        ;    // pair of integer-integer
typedef map<string, int> msi      ;    // map of string-int
typedef map<int, string> mis      ;    // map of int-string
typedef multimap<int, string> mmis;    // multimap of int-string
typedef list<int> li              ;    // list of integers
typedef queue<int, li> qul        ;    // queue of integers
typedef queue<int> qu             ;    // queue of integers (with deque underlying)
typedef vector<int> vi            ;    // vector of integers
typedef vector<pii> vpii          ;    // vector of pairs(int-int)
typedef vi::iterator itvi         ;    // iterator to vector of integers
typedef msi::iterator itmsi       ;    // iterator to map of string-int
typedef vector<char> vc           ;    // vector of chars
typedef long long ll              ;    // long long
typedef vector<ll> vll            ;    // vector of long long
// ************** Insert code here ************************

int main(void){

    int n;

    cin >> n;

    vi v(n, -1);
    vi wrong(n, -1);
    int j=0;
    for (auto i=0; i<n; i++){
        cin >> v[i];
        if (v[i] != i+1){
            wrong[j++] = i;
        }
    }

    if (j==2 or j==0){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    return 0;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  ll x; cin >> x;
  ll t = 100;
  for (int i = 1; i <= 3760; ++i){
    t += t / 100;
    if (t >= x){
      cout << i; return 0;
    }
  }
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;

void solve() {
	cin >> N >> K;
	if((N + 1) / 2 >= K) cout << "YES\n";
	else cout << "NO\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <cmath>
#include <cfloat>

#define REP(i,N) for(int i=0;i<N;i++)
#define debug(x) cout<<#x<<": "<<x<<endl

using namespace std;

typedef long long ll;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const int INF = INT_MAX/3;
const int MOD = 1000000007;
const double dINF = DBL_MAX/3;
///////////////////////////////////


int main() {
  string O, E;
  cin >> O >> E;

  string S;

  REP (i, O.length()) {
    S += O.substr(i, 1);
    if (i <= E.length()){
      S += E.substr(i, 1);
    }
  }

  printf("%s\n", S.c_str());

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_4_C
    {
        static void Main(string[] args)
        {
            int a, b;
            char op;
            List<string> dataSet;

            while (true)
            {
                dataSet = Console.ReadLine().Split().ToList();

                a = int.Parse(dataSet[0]);
                // op = char.Parse(dataSet[1]);
                op = dataSet[1][0];
                b = int.Parse(dataSet[2]);

                switch (op)
                {
                    case '+':
                        Console.WriteLine(a + b);
                        break;
                    case '-':
                        Console.WriteLine(a - b);
                        break;
                    case '*':
                        Console.WriteLine(a * b);
                        break;
                    case '/':
                        Console.WriteLine(a / b);
                        break;
                    case '?':
                        Environment.Exit(0);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}



Measured memory_bytes: 16260
def dfs(nums, length, min_lim):
    ans = 0
    if length == n:
        score_ret = 0
        for a,b,c,d in req:
            if nums[b] - nums[a] == c:
                score_ret += d
        return score_ret
    else:
        for nu in range(min_lim, m + 1):
            new_nums = nums + [nu]
            score = dfs(new_nums, length + 1, nu)
            ans = max(ans, score)
    return ans

n,m,q = map(int,input().split())

req = [list(map(int, input().split())) for _ in range(q)]
ans = dfs([-1], 0, 1)
print(ans)

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

int	main()
{
  int	n, flag = 0;
  
  cin >> n;
  for (int i = 0; i * 7 <= n; i++)
  {
    if (flag == 1)
      break;
    for (int j = 0; j * 4 + i * 7 <= n; j++)
    {
      if (j * 4 + i * 7 == n)
      {
        flag = 1;
        break ;
      }
    }
  }
  if (flag == 1)
    cout << "Yes\n";
  else
    cout << "No\n";
  return (0);
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll l, r;
    cin >> l >> r;
    vector<vector<vvl>> dp(61, vector<vvl>(2, vvl(2, vl(2, -1))));
    function<ll(int, int, int, int)> dfs = [&](int p, int x, int y, int z) {
        if (p == -1)
            return 1LL;
        if (dp[p][x][y][z] != -1)
            return dp[p][x][y][z];
        ll ret = 0;
        for (int i = 0; i < 2; ++i) {     // pth bit of x
            for (int j = 0; j < 2; ++j) { // pth bit of y
                if (i > j)                // omit the cases x > y
                    continue;
                if (!x && i == 0 && (l & (1LL << p)))
                    continue;
                if (!y && j == 1 && !(r & (1LL << p)))
                    continue;
                if (!z && i != j)
                    continue;
                int xx = x || (i && (!((1LL << p) & l)));
                int yy = y || (!j && ((1LL << p) & r));
                int zz = z || (i & j);
                ret += dfs(p - 1, xx, yy, zz);
            }
        }
        return dp[p][x][y][z] = ret % MOD;
    };
    cout << dfs(60, 0, 0, 0) << "\n";
    return 0;
}

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

int main(void){
  double a,b,h,m;
  double c,t;
  
  scanf("%lf %lf %lf %lf", &a, &b, &h, &m);
  
  h=30.0*h + 0.5*m;
  m=6.0*m;
  
  t=fabs(m-h);
  t=t*(3.14159265358979/180.0);
  
  c=sqrt(a*a+b*b - 2*a*b*cos(t));
         
  printf("%.12lf", c);
  
  return 0;
}

Measured memory_bytes: 2600
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int> A(N), B(N), C(N - 1);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N - 1; i++) cin >> C[i];

	int ret = 0;
	for (int i = 0; i < N; i++) {
		int cui = A[i];
		ret += B[cui - 1];
		if (i) {
			if (cui == A[i - 1] + 1) ret += C[A[i - 1] - 1];
		}
	}

	cout << ret << endl;
}

Measured memory_bytes: 3620
import numpy as np

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

tastes = np.array([L+(i+1)-1 for i in range(N)])

if 0 in tastes:
    print(tastes.sum())
else:
    if np.sign(tastes[0]) == 1:
        print(tastes[1:].sum())
    else:
        print(tastes[:-1].sum())

Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        int x;
        cin >> x;
        a[x-1]=i+1;
    }
    rep(i,n){
        cout << a[i] << ' ';
    }
    


}

/*



 */



Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %lld\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

// 1 2 3

int N;
vector<ll> A;
ll sum;

int main(void) {
    scanf("%d", &N);
    A.push_back(0);
    REP(i, 0, N) {
    	ll a;
    	scanf("%lld", &a);
    	A.push_back(a);
    }
    A.push_back(0);

    

    REP(i, 1, A.size()+1) sum += abs(A[i] - A[i-1]);

    REP(i, 1, N+1) {
    	ll tmp = sum;
    	tmp -= abs(A[i] - A[i-1]);
    	tmp -= abs(A[i+1] - A[i]);
    	tmp += abs(A[i+1] - A[i-1]);
    	printf("%lld\n", tmp);
    }
 

	return 0;
}


Measured memory_bytes: 2164