akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 4e3 + 7;

char s[maxn];
vector<int>v[10];

int main() {
    int n;
    while(~sd(n)) {
        scanf("%s",s);
        v[1].clear(),v[2].clear(),v[3].clear();
        int len = strlen(s);
        rep(i,0,len-1) {
            if(s[i] == 'R') v[1].push_back(i);
            else if(s[i] == 'G') v[2].push_back(i);
            else v[3].push_back(i);
        }
        int len1 = v[1].size(),len2 = v[2].size(),len3 = v[3].size();

        LL ans = 0;
        rep(i,0,len1-1) {
            rep(j,0,len2-1) {
                rep(k,0,len3-1) {
                    int x1 = v[1][i] , x2 = v[2][j] , x3 = v[3][k];
                    if(x1 + x2 == 2 * x3 || x1 + x3 == 2 * x2 || x2 + x3 == 2 * x1) continue;
                    ans++;
                }
            }
        }
        plld(ans);
    }
    return 0;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> p(n);
rep(i, n){
  cin >> p[i];
}
vector<ll> q(n);
rep(i, n){
  cin >> q[i];
}
ll a,b;
vector<ll> v;
rep(i,n)v.push_back(i+1);
ll cnt=1;
do {
    if(p==v)a=cnt;
    if(q==v)b=cnt;
    cnt++;
  } while (next_permutation(v.begin(), v.end()));

cout << abs(a-b) << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll mmin=10000000000,mmax=-1;
    for(int i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        mmax=max(mmax,a);
        mmin=min(mmin,b);
    }
   // cout<<mmax<<" "<<mmin<<endl;
    cout<<max(mmin-mmax+1,(ll)0)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include <math.h>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
	public:
	double x,y;
	Point(double x=0,double y=0):x(x),y(y) {}
	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
	Point operator * (double a) {return Point(x*a,y*a);}
	Point operator / (double a) {return Point(x/a,y/a);}
	double absv() {return sqrt(norm());}
	double norm() {return x*x+y*y;}
	bool operator < (const Point &p) const{
		return x != p.x ? x<p.x: y<p.y;
	}
	bool operator == (const Point &p) const{
		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
	}
};
typedef Point Vector;

struct Segment{
Point p1,p2;
};


double dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

//----------------kokomade temple------------


int main(){
int n;
cin>>n;
double a1,a2,a3,a4,a5,a6,a7,a8;
Point p0,p1,p2,p3;
Vector v01,v31,v02,v03,v23,v21,v20;
for(int i=0;i<n;i++){
cin>>a1>>a2>>a3>>a4>>a5>>a6>>a7>>a8;
p0.x=a1,p0.y=a2;
//cout<<a2<<endl;
p1.x=a3,p1.y=a4;
p2.x=a5,p2.y=a6;
p3.x=a7,p3.y=a8;
v01=p0-p1;
v02=p0-p2;
v03=p0-p3;
v23=p2-p3;
v21=p2-p1;
v20=p2-p0;
v31=p3-p1;
if(fabs(cross(v01,v02))<EPS && fabs(cross(v01,v03))<EPS){
if(dot(p0-p3,p0-p2)>EPS && dot(p1-p3,p1-p2)>EPS &&dot(p0-p3,p1-p3)>EPS) cout<<"0"<<endl;
else cout<<"1"<<endl;
//cout<<dot(p0-p3,p0-p2)<<" "<<dot(p1-p3,p1-p2)<<endl;
}
else if(cross(v01,v02)*cross(v01,v03)<=0 && cross(v23,v21)*cross(v23,v20)<=0) cout<<"1"<<endl;
else cout<<"0"<<endl;



}



return 0;
}

Measured memory_bytes: 1220
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    num = int(stdin.readline())

    for _ in xrange(num):
        L = [int(s) for s in stdin.readline().split()][2:]
        print(*(int(i in L) for i in xrange(1, num+1)))


main()

Measured memory_bytes: 4244
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using namespace atcoder;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  dsu d(n);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    d.merge(a, b);
  }

  cout << d.groups().size() - 1 << endl;

  return 0;
}


Measured memory_bytes: 8884
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int a, b, c;
scanf("%d %d %d",&a,&b,&c);
if(abs(a-b)<abs(a-c)){
printf("A");
}
else{
printf("B");
}
printf("\n");
}

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

#define Bye return 0
#define int long long

void solve(){
    string s1, s2;
    cin>>s1>>s2;

    int l1 = s1.length();
    int l2 = s2.length();

    int dp[l1+1][l2+1];
    int i, j;

    for (i=0; i<=l1; i++)
        for (j=0; j<=l2; j++)
            if(i == 0 || j == 0) dp[i][j] = 0;
            else if(s1[i-1] == s2[j-1])
             dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);

    int index = dp[l1][l2];

    //cout<<index<<endl;

    char res[index+1];
    res[index] = '\0';
    i = l1; j = l2;

    while(i>=0 && j>=0)
        if(s1[i-1] == s2[j-1]){
            res[index-1] = s1[i-1];
            i--; j--;
            index--;

        } else
            if(dp[i][j-1]>dp[i-1][j]) j--;
            else i--;

    cout<<res<<endl;
}

int32_t main() {
    solve();
    Bye;
}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> p(M);
  vector<string> S(M);
  for(int i=0;i<M;i++){
    cin>>p.at(i);
    p.at(i)--;
    cin>>S.at(i);
  }
  
  vector<int> wa(N),ac(N);
  int ans=0,penalty=0;
  
  for(int i=0;i<M;i++){
    if(S.at(i)=="WA")
      wa.at(p.at(i))++;
    else if(ac.at(p.at(i))==0){
      ac.at(p.at(i))=1;
      ans++;
      penalty += wa.at(p.at(i));
    }
  }
  
  cout<<ans<<" "<<penalty<<endl;
}


Measured memory_bytes: 7404
#include<iostream>
#include<cstdio>
using namespace std;
pair<long long,long long> tree[444444],lazy[444444];
long long to,from,n,m,ans;
void update(int beg,int en,int l,int r,int node,long long xs,long long cs)
{
	if (l>=beg && r<=en)
	{
		lazy[node].first+=xs;
		lazy[node].second+=cs;
		return;
	}
	else if (l>en || r<beg) return;
	int mid=(l+r)/2;
	update(beg,en,l,mid,node*2,xs,cs);
	update(beg,en,mid+1,r,node*2+1,xs,cs);
	int leng=min(en,r)-max(beg,l)+1;
	tree[node].first+=(xs*leng);
	tree[node].second+=(cs*leng);
}
pair<long long,long long> sum(int beg,int en,int l,int r,int node)
{
	if (l>=beg && r<=en)
	{
		return make_pair(lazy[node].first*(r-l+1),lazy[node].second*(r-l+1));
	}
	else if (l>en || r<beg) return make_pair(0,0);
	int leng=min(en,r)-max(beg,l)+1;
	pair<long long,long long> res=make_pair(lazy[node].first*leng,lazy[node].second*leng),res1,res2;
	int mid=(l+r)/2;
	res1=sum(beg,en,l,mid,node*2);
	res2=sum(beg,en,mid+1,r,node*2+1);
	res.first+=(res1.first+res2.first);
	res.second+=(res1.second+res2.second);
	return res;
}
long long query(long long i)
{
	pair<long long,long long> res=sum(i,i,1,m,1);
	return res.first*i+res.second;
}
int main()
{
	scanf("%lld%lld%lld",&n,&m,&from);
	for (int i=2;i<=n;i++)
	{
		scanf("%lld",&to);
		if (from<to)
		{
			update(1,from,1,m,1,0,to-from);
			update(from+1,to,1,m,1,-1,to+1);
			update(to+1,m,1,m,1,0,to-from);
		}
		else
		{
			update(1,to,1,m,1,-1,to+1);
			update(to+1,from,1,m,1,0,to-from+m);
			update(from+1,m,1,m,1,-1,to+m+1);
		}
		from=to;
	}
	ans=1e18;
	for (long long i=1;i<=m;i++)
	{
		ans=min(ans,query(i));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;

    int w=100*A,s=0;
    for(int a=0;a*100*A<=F;a++){
        for(int b=0;(a*A+b*B)*100<=F;b++){
            int ww=(a*A+b*B)*100;
            int maxs=min(F-ww,ww/100*E);
            for(int c=0;c*C<=maxs&&c<30;c++){
                int ss=(maxs-c*C)/D*D+c*C;
                if(s*(ww+ss)<ss*(w+s)){
                    w=ww;
                    s=ss;
                }                
            }
        }
    }

    cout<<w+s<<" "<<s<<endl;
}

Measured memory_bytes: 3512
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n;//????????????????????°
		int e;//????????????
		BigDecimal p;//????£???????
		BigDecimal q;//?£??????°???


		//?????????????????????????????§??????????¶??¶??????????????????¢????????§??????????????\
		while(sc.hasNext()){
			Map<Integer,BigDecimal> saleResultMap=new HashMap<Integer,BigDecimal>();
			List<Integer> eDataList=new ArrayList<Integer>();
			n=sc.nextInt();
			if(n==0)break;
			for(int i=0;i<n;i++){
				e=sc.nextInt();
				p=new BigDecimal(sc.nextInt());
				q=new BigDecimal(sc.nextInt());

				if(saleResultMap.get(e)==null){
					saleResultMap.put(e, p.multiply(q));
					eDataList.add(e);
				}else{
					saleResultMap.put(e, saleResultMap.get(e).add(p.multiply(q)));
				}
			}
			boolean existMillionSeller=false;
			for(int eValue:eDataList){
				BigDecimal result=saleResultMap.get(eValue);
				if(result.compareTo(new BigDecimal(1000000))!=-1){
					existMillionSeller=true;
					System.out.println(eValue);
				}
			}
			if(!existMillionSeller)
				System.out.println("NA");
		}

	}
}

Measured memory_bytes: 36776
import java.util.*;

public class Main {
  static int[] par;
  static int[] rank;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    par = new int[n];
    rank = new int[n];
    ArrayList[] list = new ArrayList[m];
    for(int i = 0; i < m; i++) {
      list[i] = new ArrayList<Integer>();
    }
    for(int i = 0; i < n; i++) {
      int k = sc.nextInt();
      for(int j = 0; j < k; j++) {
        int l = sc.nextInt() - 1;
        list[l].add(i);
      }
    }
    init(n);
    for(int i = 0; i < m; i++) {
      for(int j = 0; j < list[i].size() - 1; j++) {
        unite((int)list[i].get(j), (int)list[i].get(j + 1));
      }
    }
    String ans = "NO";
    HashSet<Integer> set = new HashSet<Integer>();
    for(int i = 0; i < n; i++) {
      set.add(find(i));
    }
    if(set.size() == 1) ans = "YES";
    System.out.println(ans);
  }
  static void init(int m) {
      for(int i = 0; i < m; i++) {
        par[i] = i;
        rank[i] = 0;
      }
    }
  static int find(int x) {
      if(par[x] == x) {
        return x;
      } else {
        return par[x] = find(par[x]);
      }
    }
  static void unite(int x, int y) {
      x = find(x);
      y = find(y);
      if(x != y) {
        if(rank[x] < rank[y]) {
          par[x] = y;
        } else {
          par[y] = x;
          if(rank[x] == rank[y]) {
            rank[x]++;
          }
        }
      }
    }
  static boolean same(int x, int y) {
      return find(x) == find(y);
    }
}

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

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

    cout << N * (N-1) / 2 + M * (M-1) / 2 << endl;

    return 0;
}

 

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  std::string S;
  
  std::cin >> S;
  for(int i = 0; i < (int) S.length(); ++i) {
    if(S[i] == (i % 2 == 0 ? 'L' : 'R')) {
      std::cout << "No" << '\n';
      return 0;
    }
  }
  std::cout << "Yes" << '\n';
}


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

int n, a, b, c, dp1[3], dp2[3];

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d", &a, &b, &c);
        dp2[0] = a + max(dp1[1], dp1[2]);
        dp2[1] = b + max(dp1[0], dp1[2]);
        dp2[2] = c + max(dp1[0], dp1[1]);
        swap(dp1, dp2);
    }
    swap(dp2, dp1);

    printf("%d\n", max(dp2[0], max(dp2[1], dp2[2])));
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
    char str1[200], str2[100], str3[100];

    scanf("%s %s", str1, str2);
    
    strcpy(str3, str1);
    
    strcat(str1, str3);
    
    if ( strstr(str1, str2) == NULL ){
        printf("No\n");
    }
    
    else{
        printf("Yes\n");
    }
    
    return 0;

}


Measured memory_bytes: 3152
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		//台形
		Scanner sc =new Scanner(System.in);
		int a =sc.nextInt();//上辺
		int b =sc.nextInt();//底辺
		int h =sc.nextInt();//高さ
		System.out.println((a+b)*h/2);//台形の面積
	}

}

Measured memory_bytes: 9676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  string s;
  cin>>s;
  bool f=false;
  int cnt=0;
  for(int i=2;i<s.size()-1;i++) if(s[i]=='C')cnt++;
  if(cnt==1)f=true;
  int c=0;
  bool q=false;
  for(int i=1;i<s.size();i++)if(s[i]>='a'&&s[i]<='z')c++;
  if(c==s.size()-2) q=true;
  if(s[0]=='A'&&f&&q)
  cout <<"AC"<<endl;
  else cout<<"WA"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    rep(i, 0, max(a, b)){
        cout << min(a, b);
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())
ans = [-1, -1, -1]
for i in range(n+1):
  for j in range(n+1-i):
    k = n-i-j
    if i*10000+j*5000+k*1000 == y and k>=0:
      ans[0] = i
      ans[1] = j
      ans[2] = k
      break
print(ans[0], ans[1], ans[2])

Measured memory_bytes: 40716
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int sum = 0;
        int[] p = new int[n];
        for(int i=0; i<n; i++){
            p[i]=sc.nextInt();
            } 
        Arrays.sort(p);
        for(int i=0; i<k; i++){
            sum=sum+p[i];
        }
            System.out.println(sum);
    }
}

Measured memory_bytes: 38952
<?php

fscanf(STDIN, "%d", $x);

while (1) {
    if (isPrime($x)) {
        echo $x;
        return;
    }

    ++$x;
}

function isPrime($x) {
    if ($x <= 2) {
        return true;
    }

    if ($x % 2 === 0) {
        return false;
    }

    for ($i = 3; $i <= sqrt($x); $i += 2) {
        if ($x % $i === 0) {
            return false;
        }
    }

    return true;
}


Measured memory_bytes: 4604
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N, M, X;
    scan(N, M, X);
    auto CA = new long[][](N);
    foreach (i; 0 .. N)
        CA[i] = aryread();
    long ans = long.max;
    foreach (state; 0 .. (1 << N))
    {
        auto x = new long[](M + 1);
        foreach (i; 0 .. N)
            if (state & (1 << i))
            {
                x[] += CA[i][];
            }
        if (x[1 .. $].all!(a => X <= a))
        {
            ans = ans.min(x[0]);
        }
    }
    writeln(ans == long.max ? -1 : ans);
}


Measured memory_bytes: 3908
import java.util.Scanner;

public class Main {

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

        final int a = sc.nextInt();
        final int b = sc.nextInt();
        final int c = sc.nextInt();

        System.out.println(Math.min(a+b, Math.min(b+c, c+a)));
    }
}


Measured memory_bytes: 21972
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
    while (true) {
        int n, w, d;
        cin >> n >> w >> d;
        if ( w == 0 ) { break; }
        vvi piece;
        piece.pb({w, d});
        rep (i, n) {
            int p, s;
            cin >> p >> s;
            p -= 1;
            int w0 = piece[p][0];
            int d0 = piece[p][1];
            piece.erase(begin(piece)+p);

            s %= (w0+d0);
            int w1, d1, w2, d2;
            w1 = w2 = w0;
            d1 = d2 = d0;
            if ( s < w0 ) {
                w1 = s;
                w2 = w0 - s;
                if ( w1 > w2 ) {
                    swap(w1, w2);
                }
            } else {
                s -= w0;
                d1 = s;
                d2 = d0 - s;
                if ( d1 > d2 ) {
                    swap(d1, d2);
                }
            }
            piece.pb({w1, d1});
            piece.pb({w2, d2});
        }
        vi area(n+1);
        rep (i, n+1) {
            area[i] = piece[i][0] * piece[i][1];
        }
        sort(all(area));
        rep (i, n) {
            printf("%d ", area[i]);
        }
        printf("%d\n", area[n]);
    }
    return 0;
}

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

int main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i = 0; i < n; i++){
   cin >> c[i];
   for(int j = 0; j < m; j++){
     cin >> a[i][j];
   }
  }
  
  int ans = 12345678;
  
  for(int bit = 0; bit < (1<<n); bit++){
  	int cost = 0;
  	bool judge = true;
    vector<int> ability(m);
    
    for(int i = 0; i < n; i++){
      if(bit & (1<<i)){
        for(int j = 0; j < m; j++){
          ability[j] += a[i][j];
        }
        cost += c[i];
      }
    }
    
    for(int j = 0; j < m; j++){
      if(ability[j] < x) judge = false;
    }
    
    if(judge){
      ans = min(ans, cost);
    }
  }
  
  if(ans == 12345678){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 3616
// Problem : B - Golden Coins
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Author - Sumit 
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
 
template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
 
void solve(){
    int n;
    cin>>n;
    int ans=0;
    int x=n/500;
    ans+=(x*1000);
    n=n%500;
    // debug2(n,ans);
    int y=n/5;
    ans+=(y*5);
    debug(ans);
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	a := readInt()
	b := int(math.Round(readFloat64() * 100))
	fmt.Println(a * b / 100)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

using namespace std;

int main(){
    char a[3];
    cin>>a[0]>>a[1]>>a[2];
    if(a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
# 自分の得意な言語で
# Let's チャレンジ！！
ANS=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
input_line = input()
# lines = input_line.split()
input_num = int(input_line)
print(ANS[input_num-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int arr[5];
    for (int i=0; i<5; i++) cin>>arr[i];
    int tar;
    cin>>tar;
    for (int i=0; i<5; i++){
        for (int j=i+1; j<5; j++){
            if (abs(arr[i]-arr[j])>tar){
                cout<<":(\n";
                return 0;
            }
        }
    }
    cout<<"Yay!\n";
}

Measured memory_bytes: 256
#include <stdio.h>

void triangle_judge(int a, int b, int c);

int main(void)
{
    int data_set;
    int a[1000], b[1000], c[1000];
    scanf("%d", &data_set);
    for (int i = 0; i < data_set; ++i) {
        scanf("%d %d %d", &a[i], &b[i], &c[i]);
    }
    for (int i = 0; i < data_set; ++i) {
        triangle_judge(a[i], b[i], c[i]);
    }
    return 0;
}

void triangle_judge(int a, int b, int c)
{
    if (a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}

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

int main() {
  int N;
  cin >> N;
  int minimum = 10000;
  int temp = 0;
  
  for (int i = 1; i <= N / 2 + 1; i++) {
    int c = 0, d = 0;
    int s = i, t = N - i;
    for (int j = 0; j < 6; j++) {
      c += s % 10;
      d += t % 10;
      s /= 10;
      t /= 10;
    }
    temp = c + d;
    if (temp < minimum) {
      minimum = temp;
    }
  }
  cout << minimum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int const NMAX = 1e5;
int const KMAX = 100;
int const INF = 1e9;

int nStones;
int hopLim;
int ans;
int dp[1+NMAX][1+KMAX];
int heights[1+NMAX];

int costOfHop(int from, int to) {
  return abs(heights[from]-heights[to]);
}

int main() {
  cin >> nStones >> hopLim;
  for(int i=1; i<=nStones; i++) {
    cin >> heights[i];  
  }

  //We make the following notation = dp[i][0] = min(dp[i][1], dp[i][2], .. dp[i][hopLim])
  for(int i=1; i<=nStones; i++){
    dp[i][0] = INF;
  }

  //solve 1st problem
  dp[1][0] = 0;

  //solve 2nd problem
  dp[2][1] = costOfHop(1, 2);
  for(int i=2; i<=min(hopLim, nStones); i++){
    dp[2][i] = INF;
  }
  dp[2][0] = dp[2][1];

  for(int i=3; i<=nStones; i++) { 
    int lim = min(hopLim, i-1); 
    for(int j=1; j<=lim; j++) {       
        dp[i][j] = dp[i-j][0] + costOfHop(i-j, i);
        dp[i][0] = min(dp[i][0], dp[i][j]);
    }
  }
  
  cout << dp[nStones][0];
  return 0;
}

Measured memory_bytes: 40064
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int[] a = inintar(3);
		Arrays.sort(a);
		out.println(a[2] - a[0]);

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}
	
	public char[] incharar() {
		return in.next().toCharArray();
	}

}

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

int main() {
    const int INF = 1e9;
	const int MAX_N = 100 + 10;
	const int MAX_V = 10000 + 10;
    int N, W, v[MAX_N], w[MAX_N], dp[MAX_N][MAX_V];
    cin >> N >> W;
    int sum = 0;
    for (int i = 1; i <= N; ++i){
    	cin >> v[i] >> w[i];
        sum += v[i];
    }

    dp[0][0] = 0;
    for (int j = 1; j <= sum; ++j){
    	dp[0][j] = INF;
    }

    for (int i = 1; i <= N; ++i){
    	for (int j = 0; j <= sum; ++j){
            // cout << i << ":" << j << endl;
    		if (j-v[i] < 0) dp[i][j] = dp[i-1][j];
    		else dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
    	}
    }

    int ans = 0;
    for (int j = 0; j <= sum; ++j){
        if (dp[N][j] <= W) ans = j;
    }
    cout << ans << endl;


}


Measured memory_bytes: 7028
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
const int N = 100005 + 10;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 1e9+7;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(12);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here


//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

void solve()
{
    int x,n;
    cin>>x>>n;
    int a[n];
    map<int,bool>mp;
    for(int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]=1;
    }
    int minh=1e9;
    int mini;
    for(int i=-1000;i<=1000;i++){
        if(mp[i]==0){
            if(abs(i-x)<minh){
                minh=abs(i-x);
                mini=i;
            }
        }
    }
    cout<<mini;
    return;
}

Measured memory_bytes: 3792
import java.util.*;
class Main{
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
      	int numMonster = s.nextInt();
      	int numSpMoves = s.nextInt();
      	if(numSpMoves>numMonster){
      	    System.out.println("0");
      	    return;
      	}
      	List<Integer> monsterList = new ArrayList<Integer>(numMonster);
      	for(int i=0;i<numMonster;i++){
        	monsterList.add(s.nextInt());
        }
      	Collections.sort(monsterList);
      	for (int i=0;i<numSpMoves ;i++ ){
      	    monsterList.remove(numMonster-i-1);
      	} 
      	long numAttack = 0;
      	for(int i=0;i<monsterList.size();i++){
      	    numAttack+=monsterList.get(i);
      	}
      	System.out.println(numAttack);
    }
}

Measured memory_bytes: 88760
package main

import "fmt"

func main(){
	var N, M int 
	var ans int

	fmt.Scan(&N, &M)
	
	var A []int = make([]int, N) 

	for i := 0 ; i < N ; i++ {
		fmt.Scan(&A[i])
	}

	for i := 0 ; i < N ; i++ {
		ans += A[i]
	}

	cnt := 0
	for _, e := range A {
		if 4 * M * e >= ans {cnt++}
	}

	if cnt >= M {
		fmt.Println("Yes")
	}else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
from itertools import product

N, M = map(int, input().split())
k = []
S = []
for _ in range(M):
    ks = list(map(int, input().split()))
    k.append(ks[0])
    S.append(ks[1:])
p = list(map(int, input().split()))

onoff = list(product([0, 1], repeat = N))

ans = 0
for i in onoff:
    cnt = 0
    for ind, s in enumerate(S):
        state = 0
        for o in s:
            state += i[o-1]
        if state % 2 == p[ind]:
            cnt += 1
    if cnt == M:
        ans += 1

print(ans)


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

int main()
{
	int monsterHealth, attacksDone, specialAttack;
	long attackPower = 0;
	long specialAttacks[100000];
	scanf("%d""%d",&monsterHealth, &attacksDone);

	for (int i = 0; i < attacksDone; i++)
	{
		scanf("%d", &specialAttack);
		specialAttacks[i] = specialAttack;
	}

	for (int i = 0; i < attacksDone; i++)
	{
		attackPower += specialAttacks[i];
	}

	if (attackPower >= monsterHealth)
	{
		printf("Yes \n");
	}
	else
	{
		printf("No \n");
	}

	return 0;
}


Measured memory_bytes: 896
import math

def is_prime(x):
  if x <= 0 or x%1 != 0:
    return False
  elif x == 1:
    return False
  elif x == 2:
    return True
  elif x%2 == 0:
    return False
  else:
    for i in range(3, int(math.sqrt(x)//1)+1, 2):
      if x%i == 0:
        return False
    return True

S = [0] * (10**5+1)
for i in range(1, 10**5+1):
  if is_prime(i) and is_prime((i+1)/2):
    S[i] += 1
  S[i] += S[i-1]

Q = int(input())
for _ in range(Q):
  l, r = map(int, input().split())
  print(S[r] - S[l-1])

Measured memory_bytes: 11780
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
    i = 0
    waru = 1
    while a > 0:
        if a % (waru * 2) != 0:
            a -= waru
            bit[i] += 1
        waru *= 2
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % MOD)

Measured memory_bytes: 124484
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
vl a,b,c;
ll k,x,y,z;
int main(){FAST;
cin>>x>>y>>z>>k;
for(ll i=0;i<x;i++){
	ll temp;cin>>temp;
	a.pb(temp);
}
for(ll i=0;i<y;i++){
	ll temp;cin>>temp;
	b.pb(temp);
}
for(ll i=0;i<z;i++){
	ll temp;cin>>temp;
	c.pb(temp);
}
sort(rall(c));
vl v;
for(ll i=0;i<x;i++){
	for(ll j=0;j<y;j++){
		ll sum = a[i]+b[j];
		v.pb(sum);
	}
}
sort(rall(v));
vl vv;
for(ll i=0;i<min(k,x*y);i++){
	for(ll j=0;j<z;j++){
		vv.pb(v[i]+c[j]);
	}
}
sort(rall(vv));
for(ll i=0;i<k;i++)
	cout<<vv[i]<<'\n';
return 0;
}


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

const int maxn = (int) 2e5 + 20;

#define LL long long

int n, a, b, c, d;
string s;

void work()
{
    cin >>n >>a >>b >>c >>d;
    cin >>s;
    a--, b--, c--, d--;

    int is_jump = 1, is_change = 0;
    for(int i = a + 1; i <= d; i++)
    {
        if(s[i - 1] == '#' && s[i] == '#')
            is_jump = 0;
    }

    for(int i = b + 1; i <= min(c, d) + 1; i ++)
    {
        if(s[i - 2] == '.' && s[i - 1] == '.' && s[i] == '.')
            is_change = 1;
    }

    if(is_jump)
    {
        if((a < b) == (c < d))
        {
            puts("Yes");
            return ;
        }
        else
        {
            if(is_change)
            {
                puts("Yes");
                return ;
            }
        }
    }
    puts("No");
    return ;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 640
s = gets.chomp
mod = 10**9+7
dp = (s.size+1).times.map{Array.new(4, 0)}
dp[0][0] = 1

s.size.times{|i|
  #そのまま次に渡す
  if s[i]=="?"
    4.times{|j| dp[i+1][j] += dp[i][j]*3}
  else
    4.times{|j| dp[i+1][j] += dp[i][j]}
  end
  
  #添え字を増やして渡す
  if s[i]=="A"
    dp[i+1][1] += dp[i][0]
  elsif s[i]=="B"
    dp[i+1][2] += dp[i][1]
  elsif s[i]=="C"
    dp[i+1][3] += dp[i][2]
  else
    3.times{|j|
      dp[i+1][j+1] += dp[i][j]
    }
  end
  
  #mod
  4.times{|j|
    dp[i+1][j] %= mod
  }
}

p dp[s.size][3]%mod


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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int n, x, y, b, p;
    cin >> n;

    for ( int i = 0; i < n; ++i ) {
        cin >> x >> y >> b >> p;
        if ( b >= 5 && p >= 2 ) {
            x *= b;
            y *= p;
            x += y;
            x *= 0.8;
        } else if ( b < 5 && p >= 2 ) {
            y *= p;
            if ( ( x * 5 + y ) * 0.8 > x * b + y ) {
                x *= b;
                x += y;
            } else {
                x *= 5;
                x += y;
                x *= 0.8;
            }
        } else if ( b >= 5 && p < 2 ) {
            x *= b;
            if ( ( x + y * 2 ) * 0.8 > x + y * p ) {
                y *= p;
                x += y;
            } else {
                y *= 2;
                x += y;
                x *= 0.8;
            }
        } else {
            x *= b;
            y *= p;
            x += y;
        }
        cout << x << endl;
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<int> A;
int ans=0;
int n,m,q;
int a[60],b[60],c[60],d[60];

void dfs(int x){
    A.push_back(x);
    if(A.size()==n){
        int tmp=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) tmp+=d[i];
        }
        ans=max(ans,tmp);
        return;
    }
    for(int i=A.back();i<=m;i++){
        dfs(i);
        A.pop_back();
    }
}

int main(){
    cin>>n>>m>>q;
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--,b[i]--;
    }

    for(int i=1;i<=m;i++){
        A.clear();
        dfs(i);
    }

    cout<<ans<<endl;
}



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

int main() {
  long long N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }

  long long sat = 0;
  for (int i = 0; i < N; i++) {
    sat += B.at(A.at(i) - 1);
    if (i > 0) {
      if (A.at(i-1) + 1 == A.at(i))
        sat += C.at(A.at(i-1) - 1);
    }
  }
  
  cout << sat << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int partition(int ,int);
int A[100000];
int main(){
	int n,i,j;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	
	j=partition(0,n-1);
	
	for(i=0;i<n;i++){
		if(i==j) printf("[%d] ",A[i]);
		else if(i==n-1) printf("%d",A[i]);
		else printf("%d ",A[i]);
	}
	printf("\n");
	
	return 0;
}

int partition(int p,int r){
	int i,x,j,tmp;
	
	x=A[r];
	i=p-1;
	
	for(j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			tmp=A[i];
			A[i]=A[j];
			A[j]=tmp;
		}
	}
	tmp=A[i+1];
	A[i+1]=A[r];
	A[r]=tmp;
	
	return i+1;
}


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

int main(){
    cout<<fixed<<setprecision(12);
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    double X=pow(x1-x2,2);
    double Y=pow(y1-y2,2);
    cout<< sqrt( X+Y ) <<endl;
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//inline int min(int a, int b) { return a > b ? b : a; }

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

	int k; cin >> k; int sch = 0;
	char ol = 0, ne;
	for (int i = 0; i < n; i++)
	{
		cin >> ne;
		if (ol != ne)
			sch++;
		ol = ne;
	}
	int vsp = n - sch + 2 * k;
	ans = min(vsp, n - 1);

	cout << ans;
	system("pause");
	return 0;
}

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

signed main(){
    int t = 1; //cin >> t;
    while(t--){
    	int n;  cin >> n;
    	map<int,int> mp;
    	while(n--)
    	{
    		int x; cin >> x;
    		if(mp[x] == 0)
    			mp[x] = 1;
    		else mp[x] = 0;
    	}
    	int ans =  0;
    	for(auto x:mp)
    		if(x.second)
    			ans++;
    	cout << ans;
    	
    }    
}

Measured memory_bytes: 9768
#include "vector"
#include "set"
#include "map"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 998244353

typedef vector<int> vi;
typedef pair<int, int> pii;


template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& j: v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os <<j;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

vector<ll> f;
void set_f(int n) {
    f.resize(n+1);
    f[0] = 1;
    for (int i=1; i<= n; i++) {
        f[i] = (f[i-1] * i) % MOD;
    }
}

ll pw(ll x, int n) {
    if (n == 1) {
        return x;
    }
    if (n%2 == 0) {
        return pw((x*x) % MOD, n/2);
    }
    return (pw(x, n-1) * x) % MOD;
}

ll dv(ll a, ll b) {
    return (a * pw(b, MOD - 2)) % MOD;
}

ll c_n_k(int n, int k) {
    return dv(dv(f[n], f[k]), f[n-k]);
}

void solve() {
    int n;
    ll a, b, k;
    cin >> n >> a >> b >> k;

    set_f(n);

    ll ans = 0;
    for (int x = 0; x <= n; x++) {
        if ((k - a * x) % b == 0 && k >= a * x && ((k - a * x) / b <= n)) {
            int y = (k - a * x) / b;

            ans = (ans + c_n_k(n, x) * c_n_k(n, y)) % MOD;
        }
    }

    cout << ans;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);


    if (0) {
        int tests;
        cin >> tests;
        while (tests--) {
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> arr(n, vector<int>(3));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for (int i = 1; i < n; i++) {
		dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	int ans = max({ dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] });
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	int n = s.size();
	bool flag = true;
	REP(i,n/2){
		if(s[i]!=s[n-i-1]) flag = false;
	}
	REP(i,n/4){
		if(s[i]!=s[n/2-i-1]) flag = false;
	}

	cout << (flag ? "Yes" : "No") << '\n';
	return 0;
}



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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  LL N, a, b;
  cin >> N;
  LL sp = sqrt(N);
  for(LL i = sp; i > 0; i--) {
    a = i;
    if(N%a != 0) {
      continue;
    }
    else {
      b = N/a;
      break;
    }
  }
  LL ans = a + b -2;
  cout << ans << endl;
  return 0;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string s;

  cin >> s;

  int Al,Zl;

  for(int i=0;i<s.size();i++){    
    if(s.at(i)=='A'){
      Al = i + 1;
      break;
    }    
  }//前から数えて一番手前のAの位置を記録

  reverse(s.begin(),s.end());

  for(int i=0;i<s.size();i++){    
    if(s.at(i)=='Z'){
      Zl = s.size() - i;//s.size() - (i + 1) +1
      break;
    }    
  }//最も後ろのZの位置を記録（反転して前から調べ、その位置を記録した後、元の順番では前から何番目かに換算している）
  

    cout << Zl - Al + 1 << endl;//得られた情報を文字数に変換する
  

  return 0;
}

Measured memory_bytes: 640