akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	int cnt[n + 1];
	memset(cnt, 0, sizeof cnt);
	fo(i, 0, n)
	cnt[arr[i]]++;
	
	ll ans = 0;
	foe(i, 1, n) {
		int x = cnt[i];
		ans += (1ll * x * (x - 1)) / 2;
	}
	vector <ll> res;
	fo(i, 0, n) {
		ll x = cnt[arr[i]];
		res.pb(ans - ((x * (x - 1)) / 2) + (((x - 1) * (x - 2)) / 2));
	}
	for(auto x : res)
	cout << x << '\n';
}


Measured memory_bytes: 5872
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;

int a[100005];

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	s = s + s;
	for(int i1 = 0;i1 < 2;i1++)
		for(int i2 = 0;i2 < 2;i2++){
			a[0] = i1;
			a[1] = i2;
			for(int i = 2;i <= n + 1;i++){
				if(s[i - 1] == 'o' && a[i - 1] == 0)
					a[i] = 1 - a[i - 2];
				if(s[i - 1] == 'o' && a[i - 1] == 1)
					a[i] = a[i - 2];
				if(s[i - 1] == 'x' && a[i - 1] == 0)
					a[i] = a[i - 2];
				if(s[i - 1] == 'x' && a[i - 1] == 1)
					a[i] = 1 - a[i - 2];
			}
			if(a[n] == a[0] && a[n + 1] == a[1]){
				for(int i = 0;i < n;i++)
					cout << (a[i] ? 'S' : 'W');
				return 0;
			}
		}
	cout << -1;
	return 0;
}

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

typedef unsigned long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//

ll N;
ll K;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K;
    ll A[N];
    LREP(i, 0, N){
        cin >> A[i];
    }
    ll X = 0;
    ll f = 0;
    ll tmp;
    REPR(bit, 40, 0){
        tmp = 0;
        LREP(i, 0, N){
            if(A[i] & (1L << bit)) tmp += 1;
        }
        if(K >= X + (1L << bit) && tmp < N - tmp){
            X += (1L << bit);
            tmp = N - tmp;
        }
        f += (1L << bit) * tmp;
    }

    cout << f << endl;

}


Measured memory_bytes: 1024
import math

def main():
    N = [int(_) for _ in input().split()]
    A = N[0]
    B = N[1]
    h = N[2]
    m = N[3]

    l = m * 6
    s = (((h * 30) % 360) + (30 * m / 60)) % 360

    angle = abs(s - l)
    if angle > 180:
        angle = 360 - angle

    if angle == 180:
        print(A+B)
    elif angle <= 90:
        sin = math.sin(math.radians(angle))
        cos = math.cos(math.radians(angle))
        if A > B:
            result=math.sqrt((B*sin)*(B*sin) + (A-B*cos)*(A-B*cos))
            print(result)
        else:
            result=math.sqrt((A*sin)*(A*sin) + (B-A*cos)*(B-A*cos))
            print(result)
    else:
        angle = 180 - angle
        sin = math.sin(math.radians(angle))
        cos = math.cos(math.radians(angle))
        if A > B:
            result=math.sqrt((B*sin)*(B*sin) + (A+B*cos)*(A+B*cos))
            print(result)
        else:
            result=math.sqrt((A*sin)*(A*sin) + (B+A*cos)*(B+A*cos))
            print(result)
        

if __name__ == "__main__":
    main()


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

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  bool c = false;
  rep(i,1000){
    if(a <= k*i && k*i <= b){
      cout << "OK" << endl;
      c = true;
      break;
    }
  }
  if(c == false){
    cout << "NG" << endl; 
  }

}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e5+10;
int a[N],b[N*2],lis[3];
int n,m,cnt;
bool firstcheck(){
    int cnt=0;
    for (int i=1;i<=n;++i)
        cnt+=a[i]&1;
    return cnt<=2;
}
void get_b(){
    int sum;
    if (cnt==0){
        b[++b[0]]=1; sum=m-1;
        for (int i=1;i<n;++i) b[++b[0]]=a[i],sum-=a[i];
        if (sum==0) return;
        sum-=1; sum/=2;
        for (int i=1;i<=sum/2;++i) b[++b[0]]=2;
        b[++b[0]]=1;
        for (int i=sum/2+1;i<=sum;++i) b[++b[0]]=2;
    }
    else if (cnt==1){
        b[++b[0]]=1;
        for (int i=1;i<n;++i) b[++b[0]]=a[i];
        for (int i=1;i<=(a[n]-1)/2;++i) b[++b[0]]=2;
    }
    else{
        b[++b[0]]=a[1]+1;
        for (int i=2;i<n;++i) b[++b[0]]=a[i];
        for (int i=1;i<=(a[n]-1)/2;++i) b[++b[0]]=2;
    }
}

int main(){
    scanf("%d%d",&m,&n);
    for (int i=1;i<=n;++i) scanf("%d",a+i);
    if (!firstcheck()){printf("Impossible\n"); return 0;}
    cnt=0;
    for (int i=1;i<=n;++i){
        if ((a[i]&1)) 
            lis[++cnt]=i;
    }
    if (lis[1]) swap(a[n],a[lis[1]]);
    if (lis[2]) swap(a[1],a[lis[2]]);
    for (int i=1;i<=n;++i) printf("%d ",a[i]); printf("\n");

    get_b();
    printf("%d\n",b[0]);
    for (int i=1;i<=b[0];++i) printf("%d ",b[i]); printf("\n");
}

Measured memory_bytes: 764
#include <stdio.h>

int F[50];

int fibonacci(int x){
  if(x == 0 || x == 1) return F[x] = 1;
  if(F[x] != NULL)return F[x];
  return F[x] = fibonacci(x - 1) + fibonacci(x - 2);
}

int main(){
  int x;
  
  scanf("%d",&x);
  printf("%d\n",fibonacci(x));

  return 0;
}



Measured memory_bytes: 2056
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long 
using namespace std; 

const long long N = 1e6 + 100, OO = 1e18, M = 1e9 + 7, M2 = 998244353, sq = 31622, lg = 23;
typedef pair <int, int> pii;

int32_t main() {
	use_fast;
	se(10);
	int n;
	cin >> n;
	double ans = 0;
	if(n % 2 == 0)
		ans = n / 2;
	else
		ans = (n + 1) / 2;
	double f = n;
	ans /= f;
	cout << ans << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

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

int main() {
  int N;
  cin >> N;
  int A[N-1];
  for (int i=0; i<N-1; i++) cin >> A[i];
  
  int sub_num[N] = {0};
  for (int i=0; i<N-1; i++) {
    sub_num[A[i]-1]++;
  }
  
  for (int i=0; i<N; i++) {
    cout << sub_num[i] << endl;
  }
} 

Measured memory_bytes: 5156
import java.util.Scanner;

public class Main {
	Scanner sc;
	int[][] map;
	int width, height;

	private Main(){
		sc = new Scanner( System.in );
	}

	private void visit( int x, int y ){
		if( x < 0 || y < 0 || x >= width || y >= height || map[ x ][ y ] == 0){ return; }
		map[ x ][ y ] = 0;
		visit( x - 1, y - 1 );
		visit( x - 1, y     );
		visit( x - 1, y + 1 );
		visit( x    , y - 1 );
		visit( x    , y + 1 );
		visit( x + 1, y - 1 );
		visit( x + 1, y     );
		visit( x + 1, y + 1 );

	}

	private void run(){
		while( true ){
			width = sc.nextInt();
			height = sc.nextInt();
			int counter = 0;
			map = new int[ width ][ height ];
			if( width == 0 && height == 0){ break; }
			for( int y = 0; y < height; y++ ){
				for(int x = 0; x < width; x++ ){
					map[ x ][ y ] = sc.nextInt();
				}
			}

			for( int y = 0; y < height; y++ ){
				for( int x = 0; x < width; x++ ){
					if( map[ x ][ y ] == 1 ){
						counter++;
						visit( x, y );
					}
				}
			}
			System.out.println( counter );
		}
	}

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

}

Measured memory_bytes: 13000
N = int(input())
A = list(map(int,input().split()))
counter = 1
flag = 0
for i in range(N-1):
  if A[i+1] > A[i]:
    if flag < 0:
      counter +=1
      flag = 0
    else:
      flag +=1
  elif A[i+1] < A[i]:
    if flag > 0:
      counter += 1
      flag = 0
    else:
      flag -=1

print(counter)

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
using namespace std;

int main(void)
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    
    vector<int> a_v, b_v, c_v;
    
    int tmp;
    for (int i = 0; i < a; i++) { cin >> tmp; a_v.push_back(tmp); } 
    for (int i = 0; i < b; i++) { cin >> tmp; b_v.push_back(tmp); } 
    for (int i = 0; i < c; i++) { cin >> tmp; c_v.push_back(tmp); } 
    sort(a_v.begin(), a_v.end(), greater<int>());
    sort(b_v.begin(), b_v.end(), greater<int>());
    sort(c_v.begin(), c_v.end(), greater<int>());
    a_v.resize(x);
    b_v.resize(y);
    c_v.resize(min(c, x+y));
    
    vector<int> all = a_v;
    all.insert(all.end(), b_v.begin(), b_v.end());
    all.insert(all.end(), c_v.begin(), c_v.end());
    sort(all.begin(), all.end(), greater<int>());
    all.resize(x+y);
    cout << accumulate(all.begin(), all.end(), 0LL) << endl;

    return 0;
}


Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define LLFOR(i, a, b) for(long long i = (a); i < (b); ++i)
#define LLRFOR(i, a, b) for(long long i = (a); i >= (b); i--)
#define SORT(v, n) sort(v, v+n)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define LLREP(i, n) for(long long i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)
#define LLRREP(i, n) for(long long i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define ret return

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

int MAX(int a,int b){if(a>b){return a;}return b;}
int MIN(int a,int b){if(a<b){return a;}return b;}
int GCD(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){int c=GCD(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int POW(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
ll LLMAX(ll a,ll b){if(a>b){return a;}return b;}
ll LLMIN(ll a,ll b){if(a<b){return a;}return b;}
ll llGCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
ll llLCM(ll a,ll b){ll c=llGCD(a,b);a/=c;return a*b;}
ll llnCr(ll a,ll b){ll i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
ll llnHr(ll a,ll b){return llnCr(a+b-1,b);}
ll llpow(ll a,ll b){ll i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
   ios::sync_with_stdio(false);
   
   int a, b, cnt = 0;
   cin >> a >> b;
   FOR(i, a, b+1){
      string str = to_string(i);
      if(str[0]==str[4] && str[1]==str[3]) cnt++;
   }

   cout << cnt << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+1;
vector<int>graph[N];
int dp[N];
int visited[N]={0};
void dfs(int node){
    visited[node]=1;
    //cout<<node<<" ";
    for(auto i=graph[node].begin();i!=graph[node].end();i++){
        if(!visited[*i]) {
            dfs(*i);
        }
            dp[node]=max(dp[node],1+dp[*i]);



    }




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

    for(int i=0;i<m;i++){
   int u,v;
        cin>>u>>v;
        graph[u].push_back(v);
    }
//   for(int i=1;i<=n;i++){
//       cout<<graph[i].size()<<endl;
//   }

    //dfs(2);

    for(int i=1;i<=n;i++){

            dfs(i);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
//for(int i=1;i<=n;i++){
//    cout<<visited[i]<<" ";
//
//}
//    cout<<endl;

    return 0;
} 


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

int main() {
   
   int N,K;
   
   std::cin >> N >> K;
   
   std::vector<int> P(N, 0);
   
   for (int i = 0; i < N; i++) {
      std::cin >> P[i];
   }
   
   std::sort(P.begin(), P.end());
   
   int ans = 0;
   
   for (int i = 0; i < K; i++) {
      ans += P[i];
   }
   
   std::cout << ans << std::endl;
   
   return 0;
   
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

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

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int n;
        cin>>n;
        int x = (n/1000) + (n%1000 > 0);
        cout<<(1000*x - n);
    }
    
    return 0;
}

Measured memory_bytes: 3648
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();
        String S = sc.next();
        String T = sc.next();
        
        char[] A = new char[100];
        char[] B = new char[100];
        String ans = new String("");

        for(int i=0;i<N;i++) {
        	ans= ans + S.substring(i,i+1);
        	ans= ans + T.substring(i,i+1);
        }
        System.out.println(ans);	
        
        
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int c[200010];
int main() {
  int N,K,A,ans = 0;
  cin >> N >> K;
  for(int i = 0;i < N;i++){
    cin >> A;
    c[A]++;
  }
  vector<int> v;
  for(int i = 1;i <= 200000;i++)if(c[i])v.push_back(c[i]);
  sort(v.begin(),v.end());
  if(v.size() > K)for(int i = 0;i < v.size()-K;i++)ans+=v[i];
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    string ammariokikunaimojiretsu;
    ll bidamanokosuwokazoeruyo=0;
    cin>>ammariokikunaimojiretsu;
    rep(takagamittsudakenoiterator, 3){
        if(ammariokikunaimojiretsu[takagamittsudakenoiterator]=='1') bidamanokosuwokazoeruyo++;
    }
    cout<<bidamanokosuwokazoeruyo<<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7;
const double eps = 1e-9;

int main()
{
	ll n, m;
	cin >> n >> m;
	if (m % n == 0)
		return cout << m / n, 0;
	vector<ll> dv;
	for (ll i = 1; i <= sqrt(m); i++)
	{
		if (m % i == 0) {
			dv.pb(i);
			dv.pb(m / i);
		}
	}
	sort(all(dv));
	for (int i = dv.size() - 1; i >= 0; i--)
	{
		if (m / dv[i] >= n)
			return cout << dv[i], 0;
	}
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int len = S.size();

    int bucket[26] = {0};
    for (int i=0; i<len; ++i) ++bucket[(int)(S[i] - 'a')];
    int ans = -1;
    for (int i=0; i<26; ++i) {
        if (!bucket[i]) {
            ans = i;
            break;
        }
    }
    if (ans >= 0) cout << (char)(ans + (int)'a') << endl;
    else cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
ll GCD(ll a,ll b) { return b ? GCD(b, a%b) : a; }
int main(){
  ll n;cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  vector<ll> left(n+1,0),right(n+1,0);
  rep(i,n) left[i+1]=GCD(left[i],v[i]);
  for(ll i=n-1;i>=0;i--) right[i]=GCD(right[i+1],v[i]);
  ll ans=0;
  rep(i,n) ans=max(ans,GCD(left[i],right[i+1]));
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	h, a := readInt2()
	fmt.Println(math.Ceil(float64(h) / float64(a)))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}


void solve(){
	int a, b;
	cin>>a>>b;
	cout<<max(a+b, max(a*b, a-b))<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll k,a,b;
  cin >> k >> a >> b;
  ll res = 0;
  if(a <= b && k > a)res = -1;
  else{
    res++;
    if(k > a){
    ll add = 0;
    if((k - a) % (a - b) != 0)add = 1;
    res += ((k - a) / (a - b) + add) * 2;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


int n, m;

vector<vector<int> > es;
const int maxn = (int) 1e5 + 10;
int q;
int qs[maxn][3];

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  es = vector<vector<int> >(n);
  for (int i = 0; i < m; ++i) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s, --t;
    es[s].pb(t), es[t].pb(s);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%d", qs[i], qs[i] + 1, qs[i] + 2);
    --qs[i][0];
  }
  return 1;
}

int col[maxn];
int maxd[maxn];

void update(int v, int d, int c) {
  if (maxd[v] >= d) {
    return;
  }
  maxd[v] = d;
  if (!col[v]) {
    col[v] = c;
  }
  for (int u : es[v]) {
    update(u, d - 1, c);
  }
}

void solve() {
  for (int i = 0; i < n; ++i) {
    col[i] = 0;

    maxd[i] = -1;
  }

  for (int i = q - 1; i >= 0; --i) {
    update(qs[i][0], qs[i][1], qs[i][2]);
  }

  for (int i = 0; i < n; ++i) {
    printf("%d\n", col[i]);
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N; str S, SS;cin>>N>>S>>SS;
    ll ans=1;
    int flag=0;
    for(int i=0; i<N;i++){
      char s = S[i]; char ss = SS[i];
      // cout<<i<<" ";
      if(i==0){
        if(s!=ss){ans*=6LL; flag=0; i++;}
        else{ans *= 3LL; flag=1;}
      }else{
        if(s!=ss){
          if(flag==0) ans*= 3LL;
          if(flag==1) ans*= 2LL;
          flag=0; i++;
        }else{
          if(flag==0) ans*= 1LL;
          if(flag==1) ans*= 2LL;
          flag=1;
        }
      }
      ans %= MOD;
      // cout<<i<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


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

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

void dfs(int cur, vector<int> *g, bool *visited, int len, map<int, int> &mp) {//cout<<cur<<" "<<mp.size()<<endl;
    visited[cur] = true;

    if(g[cur].size() == 1) {//cout<<"len1 "<<cur<<endl;
        mp[cur] = len;
    }

    for(int i=0; i<g[cur].size(); i++) {
        int next = g[cur][i];
        if(visited[next]) continue;
        dfs(next, g, visited, len+1, mp);
    }//cout<<"return "<<cur<<endl;
}

int main() {
    int n, tak, aok; cin >> n >> tak >> aok;
    vector<int> g[n];
    int u, v;
    for(int i=0; i<n-1; i++) {
        cin >> u >> v;
        g[u-1].pb(v-1);
        g[v-1].pb(u-1);
    }

    bool vistak[n]={0}, visaok[n]={0};
    map<int, int> mptak;
    dfs(tak-1, g, vistak, 0, mptak);
    map<int, int> mpaok;
    dfs(aok-1, g, visaok, 0, mpaok);
//cout<<"-----------"<<mptak.size()<<" "<<mpaok.size()<<endl;
    int maxlen = -1;
    for(auto t=mptak.begin(), a=mpaok.begin(); t!=mptak.end()&&a!=mpaok.end(); t++,a++) {
        //cout << t->first<<" "<<t->second<<"  "<<a->first<<" " <<a->second<<endl;
        if(t->second < a->second) maxlen = max(maxlen, a->second);
    }
    cout << maxlen-1 << endl;

    return 0;
}


Measured memory_bytes: 14464
N, X = map(int, input().split())
A = list(map(int, input().split()))

answer = 0
if A[0] > X:
    answer += A[0] - X
    A[0] = X
    
for i in range(N-1):
    diff = A[i] + A[i+1] - X
    if diff > 0:
        answer += diff
        A[i+1] -= diff

print(answer)


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

using namespace std;

struct State {
  int x, y, d;
  long long l;
  State(){}
  State(int x, int y, int d, long long l):x(x), y(y), d(d), l(l){}
};
  
int H, W;
long long L;
int sx, sy, sd;
char maze[101][101];

int dist[4][101][101];

const string dir = "NESW";

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

State bfs()
{
  queue<State> que; que.push(State(sx, sy, sd, L));
  memset(dist, -1, sizeof(dist));
  dist[sd][sy][sx] = 0;
  while(!que.empty()) {
    State p = que.front(); que.pop();
    if(p.l == 0LL) return p;    
    int nx = p.x+dx[p.d], ny = p.y+dy[p.d];
    long long nl = p.l;
    if(0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != '#') {
      nl--;
      if(dist[p.d][ny][nx] != -1) {
	nl %= (dist[p.d][p.y][p.x]+1 - dist[p.d][ny][nx]);
	memset(dist, -1, sizeof(dist));
      }
      dist[p.d][ny][nx] = dist[p.d][p.y][p.x] + 1;
      que.push(State(nx, ny, p.d, nl));
    } else {
      dist[(p.d+1)%4][p.y][p.x] = dist[p.d][p.y][p.x];
      que.push(State(p.x, p.y, (p.d+1)%4, nl));
    }
  }
}

int main()
{
  while(cin >> H >> W >> L, H) {
    memset(maze, 0, sizeof(maze));
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
	cin >> maze[i][j];
	if(dir.find(maze[i][j]) != string::npos) {
	  sy = i, sx = j, sd = dir.find(maze[i][j]);
	}
      }
    }
    State s = bfs();
    cout << s.y+1 << " " << s.x+1 << " " << dir[s.d] << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    string s, s1;
    cin >> s >> s1;
    int mini = min(s.length(), s1.length());

    int i = 0;
    while(i < mini){
        cout << s[i] << s1[i];
        i++;
    }
    if(s.length() == s1.length()){
        return 0;
    }else if(s.length() > s1.length()){
        for(int j = i; j < s.length(); ++j){
            cout << s[i];
        }
    }else{
        for(int j = i; j < s1.length(); ++j){
            cout << s1[i];
        }
    }
    return 0;

}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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 pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 998244353;

lnt dp[3010][3010][3];

int main(){
	summon_tourist;

	lnt N, S, A[3000]; cin >> N >> S;
	REP(i, N) cin >> A[i];
	dp[0][0][0] = 1;
	REP(i, N) REP(j, S+1) REP(k, 3){
		if(k == 0){
			// まだ始めない
			dp[i+1][j][k] += dp[i][j][k];
			// 始める
			dp[i][j][1] += dp[i][j][k];
			dp[i][j][1] %= MOD;
		} else if(k == 1){
			// 使わない
			dp[i+1][j][k] += dp[i][j][k];
			dp[i+1][j][k] %= MOD;
			// 使う
			if(j+A[i] <= S){
				dp[i+1][j+A[i]][k] += dp[i][j][k];
				dp[i+1][j+A[i]][k] %= MOD;
			}
			// 終わらす
			dp[i+1][j][2] += dp[i+1][j][k];
		} else {
			dp[i+1][j][k] += dp[i][j][k];
			dp[i+1][j][k] %= MOD;
		}
	}
	cout << dp[N][S][2] << ln;
}

Measured memory_bytes: 211968
#![allow(unused_imports)]
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}
impl<T: Iterator> IteratorExt for T {}

fn main() {
    let (h, w, m) = read!(usize, usize, usize);
    let mut map_h = vec![0; h + 1];
    let mut map_w = vec![0; w + 1];

    let mut map = HashSet::new();
    for _ in 0..m {
        let (hi, wi) = read!(usize, usize);
        map_h[hi] += 1;
        map_w[wi] += 1;
        map.insert((hi, wi));
    }

    let mut candidate_h = vec![];
    let mut max_h = 0;
    for i in 1..=h {
        if max_h < map_h[i] {
            candidate_h = vec![i];
            max_h = map_h[i];
        }
        else if max_h == map_h[i] {
            candidate_h.push(i);
        }
    }

    let mut candidate_w = vec![];
    let mut max_w = 0;
    for i in 1..=w {
        if max_w < map_w[i] {
            candidate_w = vec![i];
            max_w = map_w[i];
        }
        else if max_w == map_w[i] {
            candidate_w.push(i);
        }
    }

    for ch in &candidate_h {
        for cw in &candidate_w {
            if let None = map.get(&(*ch, *cw)) {
                println!("{}", max_h + max_w);
                return;
            }
        }
    }
    println!("{}", max_h + max_w - 1);
}


Measured memory_bytes: 17740
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const long long int mod=1e9+7;
int main()
{
    long long int ant,n,m,ant2;
    while(scanf("%lld%lld",&n,&m)==2)
    {
        ant=1;
        if(abs(n-m)>=2)
        {
            printf("0\n");
            continue;
        }
        if(n==m)
        {
            for(long long int i=n;i>=1;i--)
           {
            ant=(ant*i)%mod;
           }
           ant=(2*ant*ant)%mod;
           printf("%lld\n",ant);
           continue;
        }
        else
        {
            ant=1;ant2=1;
            for(long long int i=n;i>=1;i--)
            {
                ant=(ant*i)%mod;
            }
            for(long long int j=m;j>=1;j--)
            {
                ant2=(ant2*j)%mod;

            }
            ant=(ant*ant2)%mod;
            printf("%lld\n",ant);
        }
    }
}


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

//Optimizations
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;

//for sorting
#define all(a) a.begin(),a.end()

//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f

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

//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb  push_back
#define vb vector<bool>

//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second

//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar

//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)

//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue

//general
#define E empty()

const int MAXN=0;

int main(){

    string s; cin >> s;
    int res = 0;
    int cur = 0;
    for(char c : s){
        if(c == 'R')
            cur++;
        else{
            res = max(res, cur);
            cur = 0;
        }
    }
    res = max(res, cur);
    cout << res << endl;

}


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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define zeroend __builtin_ctz
#define ones __builtin_popcount
#define ends "\n"
#define space ' '
typedef long long ll;
typedef pair<int, int> pii;

/*
void solve(int i, int j, string s){
	if(i==0)
		ans.insert(s2.substr(0, j)+s);
	else if(j==0)
		ans.insert(s1.substr(0, i)+s);
	else if(s1[i-1]==s2[j-1])
		solve(i-1, j-1, s1[i-1]+s);
	else{
		if(dp[i-1][j]<=dp[i][j-1])
			solve(i-1, j, s1[i-1]+s);
		if(dp[i-1][j]>=dp[i][j-1])
			solve(i, j-1, s2[j-1]+s);
	}
}*/


/*
	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];

	for(int i=1; i<n; ++i){
		for(int j=0; j<i; ++j){
			if(a[j]>a[i]&&low[i]<high[j]+1)
				low[i]=high[j]+1;
			else if(a[j]<a[i]&&high[i]<low[j]+1)
				high[i]=low[j]+1;
		}
		ans=max({ans, low[i], high[i]});
	}

	cout << ans << ends;


*/

const int N = 1e5, M = 1e9+7;

ll dp[N];
//set<string> ans;
//vector<int> low(N, 1), high(N, 1);
ll a[N];

int n, k;

int main(){
	cin >> n >> k;
	for(int i=0; i<n; ++i)
		cin >> a[i];

	dp[0]=0;

	for(int i=1; i<n; ++i){
		dp[i]=1e9;
		for(int j=i-1; j>=0 && j>=i-k; --j)
			dp[i]=min(dp[i], abs(a[i]-a[j])+dp[j]);
	}

	cout << dp[n-1] << ends;
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  string S; cin >>S;
  int ans=700;
  rep(i,0,3) {
    if (S[i]=='o') ans+=100;
  }
  cout <<ans <<endl;
  return 0;
}


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

int main(){
  int n; cin>>n;
  vector<long long> d(n);
  for(int i=0; i<n; ++i)cin>>d[i];

  if(d[0]!=0 || count(d.begin(), d.end(), 0)!=1)cout<<0<<endl;
  else{
    sort(d.begin(), d.end());
    int m=d[n-1];
    vector<long long>num(m+1, 0);
    for(int i=0; i<n; ++i)++num[d[i]];
    
    bool flg=false;
    for(int i=0; i<m+1; ++i)if(num[i]==0)flg=true;

    if(flg)cout<<0<<endl;
    else{
      long long ans=1LL;
      for(int i=1; i<=m; ++i){
        for(int j=0; j<num[i]; ++j)ans=ans*num[i-1]%(long long)998244353;
      }
      cout<<ans<<endl;
    }
  }
}

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

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

constexpr lint INF = 1LL << 60;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n), ys(n), ps(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> xs[i] >> ys[i] >> ps[i];
    }

    auto xds = vec(n, vec(1 << n, INF));
    auto yds = xds;

    for (int i = 0; i < n; ++i) {
        for (int b = 0; b < (1 << n); ++b) {
            {
                auto& cost = xds[i][b];
                cost = std::abs(xs[i]);
                for (int j = 0; j < n; ++j) {
                    if ((b >> j) & 1) cost = std::min(cost, std::abs(xs[i] - xs[j]));
                }
            }

            {
                auto& cost = yds[i][b];
                cost = std::abs(ys[i]);
                for (int j = 0; j < n; ++j) {
                    if ((b >> j) & 1) cost = std::min(cost, std::abs(ys[i] - ys[j]));
                }
            }
        }
    }

    std::vector<lint> ans(n + 1, INF);

    for (int b = 0; b < (1 << n); ++b) {
        std::vector<int> is;
        for (int i = 0; i < n; ++i) {
            if ((b >> i) & 1) is.push_back(i);
        }

        int k = is.size();
        for (int c = 0; c < (1 << k); ++c) {
            int xb = 0, yb = 0;
            int j = 0;

            for (int i = 0; i < n; ++i) {
                if (((b >> i) & 1) == 0) continue;
                if ((c >> j) & 1) {
                    xb |= (1 << i);
                } else {
                    yb |= (1 << i);
                }
                ++j;
            }

            lint cost = 0;
            for (int i = 0; i < n; ++i) {
                lint dist = std::min(xds[i][xb], yds[i][yb]);
                cost += dist * ps[i];
            }

            ans[k] = std::min(ans[k], cost);
        }
    }

    for (auto a : ans) std::cout << a << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 10948
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
const int maxn=55;
int n,m,q;
int a[maxn],b[maxn],c[maxn],d[maxn],ans[maxn];
LL asd=0;
void dfs(int de,int per)
{
	if(de==n+1)
	{
		LL tot=0;
		for(int i=1;i<=q;++i)
		{
			if(ans[b[i]]-ans[a[i]]==c[i])tot+=d[i];
		}
		asd=max(asd,tot);
		return;
	}
	for(int i=per;i<=m;++i)
	{
		ans[de]=i;
		dfs(de+1,i);
	}
}
int main()
{
	n=read();m=read();q=read();
	for(int i=1;i<=q;++i)
	{
		a[i]=read();b[i]=read();c[i]=read();d[i]=read();
	}
	for(int i=1;i<=m;++i)
	{
		dfs(1,i);
	}
	printf("%lld\n",asd);
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXV = 3e5;
num fact[MAXV], ifact[MAXV];

void precomp() {
	fact[0] = 1;
	for (int i = 1; i < MAXV; i++) {
		fact[i] = fact[i-1] * i;
	}
	ifact[MAXV-1] = fact[MAXV-1].inv();
	for (int i = MAXV-2; i >= 0; i--) {
		ifact[i] = ifact[i+1] * (i+1);
	}
}

num binom(int a, int b) {
	assert(a >= b && b >= 0);
	return fact[a] * ifact[b] * ifact[a-b];
}

num grid(int a, int b) {
	return binom(a+b-2, a-1);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	precomp();
	int X, Y, A, B; cin >> X >> Y >> A >> B;
	num ans = grid(X, Y);
	for (int y = 1; y <= B; y++) {
		ans -= grid(X-A, y) * grid(A, Y-y+1);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 2560
N = int(input())

while 11 <= N:
    if N % 4 == 0 or N % 7 == 0 or N % 11 == 0:
        print("Yes")
        exit()

    else:
        N -= 11

if N % 4 == 0 or N % 7 == 0:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
    long long n, a, b, amari;
    cin >> n >> a >> b;
    if (a == 0) {
        cout << 0 << endl;
        return 0;
    }
    amari = n % (a+b);
    if (amari < a) {
        cout << a*(n/(a+b)) + amari << endl;
    } else {
        cout << a*(n/(a+b)) + a << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if (A>=K)
    {
        cout << K;
    }
    else if ((A+B)>=K)
    {
        cout << A;
    }
    else
    {
        cout << A-(K-(A+B));
    }
    
    
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
using namespace std;



int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; ++i) cin >> s[i];


    int ans = 0, numHeadB = 0, numTailA = 0, numSame = 0;
    for (int i = 0; i < N; i++){
        if( s[i].front() == 'B' ) ++numHeadB;
        if( s[i].back() == 'A' ) ++numTailA;
        if( s[i].front() == 'B' and s[i].back() == 'A' ) ++numSame;
        for( int j = 1; j < s[i].length(); ++j){
            if( s[i][j-1] == 'A' and s[i][j] == 'B') ++ans;
        }
    }
    
    if( numSame == 0 and numHeadB == 0 and numTailA == 0 ) ans += 0;
    else if( numHeadB + numTailA == 2*numSame ) ans += numSame-1;
    else ans += min(numHeadB, numTailA);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define db double
#define pb push_back
#define p_q priority_queue
 
using namespace std;
 
const int N = 3e3, Mod = 998244353, INF = 1e9;

ll dp[100001], a, b, n, m, maxx;
vector <ll> g[100001];

ll dfs (ll u) { 
    
    if (g[u].size() == 0) return 0;
    if (dp[u] != -1) return dp[u];
   
    
    for (int i = 0; i < g[u].size(); i ++) {
        dp[u] = max (dp[u], dfs (g[u][i]) + 1);
        
    }
    
    return dp[u];
    
}
 
int main() {
 
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
 	
 	
	cin >> n >> m;
	for (int i = 1; i <= m; i ++) {
	    cin >> a >> b;
	    g[a].pb(b);
	  
	}
	for (int i = 1; i <= n; i ++) dp[i] = -1;
	
	for (int i = 1; i <= n; i ++) {
	 
	    maxx = max (dfs(i), maxx);
	    
	}
	cout << maxx;
}

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

int main(){

	char s[101], p[101];
	char t[201];


		
	scanf( "%s", s );
	scanf( "%s", p );


	strcpy( t, s );
	strcpy( &t[strlen(s)], s);

	if( strstr( t, p ) != NULL )
		printf( "Yes\n" );
	else
		printf( "No\n" );	


	return 0;

}

Measured memory_bytes: 532
import math
n, l = map(int, input().split())
t = []
for i in range(1, n+1):
    t.append(l+i-1)
fab = []
sum_t = sum(t)
tmp = 0
if n+l > 0:
    for i in range(n):
        fab.append(sum_t-t[i])
    ans = []
    for i in range(n):
        ans.append(math.fabs(sum_t-fab[i]))
    print(int(sum_t-min(ans)))

else:
    for i in range(n-1):
        tmp += t[i]
    print(tmp)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long H, long long W, long long h, long long w) {
    cout << H * W - h * W - w * H + w * h << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long H;
  cin >> H;
  long long W;
  cin >> W;
  long long h;
  cin >> h;
  long long w;
  cin >> w;
  solve(H, W, h, w);
  return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		a = a==1?14:a;
		b = b==1?14:b;
		if (a>b) System.out.println("Alice");
		if (a<b) System.out.println("Bob");
		if (a==b) System.out.println("Draw");
	}
}


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

int main()
{
       long long N;
       long long Sum_t[200000]={0};

       cin>>N;
       cin>>Sum_t[0];
       for(int i=1;i<N;i++)
       {
             cin>>Sum_t[i];
             Sum_t[i]=Sum_t[i-1]+Sum_t[i];
        }

       long long min=abs(Sum_t[N-1]-2*Sum_t[0]);
        for(int i=1;i<N-1;i++)
        {
                long long temp=abs(Sum_t[N-1]-2*Sum_t[i]);
                if(temp<min) min=temp;
         }
   
        cout<<min;
        return 0;
}

Measured memory_bytes: 1792