akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n;
  cin >> n;
  vector<int> xs(n + 1);
  for (int i = 0; i < n + 1; i++) {
    cin >> xs[i];
  }

  vector<int> cs(n + 1);
  for (int x : xs) cs[x]++;

  vector<int> indexes;
  for (int i = 0; i < n + 1; i++) {
    if(cs[xs[i]] == 2) {
      indexes.push_back(i);
    }
  }
  int i1 = indexes[0];
  int i2 = indexes[1];
  int m = n + 1 - (i2 - i1) - 1;
  // cout << "m: " << m << endl;

  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }

  auto c_fn = [&](int a, int b) -> FiniteField {
    if (a < b) return 0;
    auto v = factorials[a] * inverse_factorials[b] * inverse_factorials[a - b];
    // cout << "a: " << a << " b: " << b << " v: " << v.Value() << endl;
    return v;
  };

  for (int k = 1; k <= n + 1; k++) {
    if (k == 1) {
      cout << FiniteField(n).Value() << endl;
    } else {
      FiniteField ans = 0;
      if (k <= n - 1) ans += c_fn(n - 1, k);
      if (k <= n) ans += c_fn(n - 1, k - 1) * 2 - c_fn(m, k - 1);
      ans += c_fn(n - 1, k - 2);
      cout << ans.Value() << "\n";
    }
  }
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {	
		Scanner scanner = new Scanner(System.in);
		long a = scanner.nextLong();
		long max = a;
		long b = scanner.nextLong();
		max = Math.max(max, b);
		long c = scanner.nextLong();
		max = Math.max(max, c);
		System.out.println(a+b+c-max);
		scanner.close();
	}
}


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

int main() {
  cin.tie(nullptr);
  // ios::sync_with_stdio(false);
  
  int N, M, A, B = 1e9+7;
  cin >> N >> M;

  vector<int> vec(N + 1, -1);
  vec.at(0) = 1;
  vec.at(1) = 1;

  for (int i = 0; i < M; i++) {
    cin >> A;
    vec.at(A) = 0;
  }

  for (int i = 2; i < N + 1; i++) {
    if (vec.at(i) != 0) vec.at(i) = (vec.at(i - 2) + vec.at(i - 1)) % B;
  }

  cout << vec.at(N) << endl;
}

Measured memory_bytes: 640
import java.util.*;


public class Main{
	
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		
		// input
		final int NUM = scan.nextInt();
		int a = scan.nextInt() - 1;
		int b = scan.nextInt() - 1;
		int c = scan.nextInt() - 1;
		int d = scan.nextInt() - 1;
		char[] road = scan.next().toCharArray();
		
		// search
		if(c < d){
			String answer = "Yes";
			boolean memory = false;
			for(int i = a; i <= d; i++){
				if(road[i] == '#' && memory == true){
					answer = "No";
				} else if (road[i] == '#'){
					memory = true;
				} else {
					memory = false;
				}
			}
			System.out.println(answer);
		} else {
			String answer = "Yes";
			boolean memory = false;
			for(int i = a; i <= c; i++){
				if(road[i] == '#' && memory == true){
					answer = "No";
				} else if (road[i] == '#'){
					memory = true;
				} else {
					memory = false;
				}
			}
			if(answer.equals("Yes")){
				answer = "No";
				for(int i = b; i <= d ; i++){
					if(road[i-1] == '.' && road[i] == '.' && road[i+1] == '.' ){
						answer = "Yes";
					}
				}
			}
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 28548
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	int a = Integer.parseInt(reader.readLine());
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	for(int i = 0;i<a;i++){
		String p = reader.readLine();
		switch(p){
			case "AC":
				ac++;
				break;
			case "WA":
				wa++;
				break;
			case "TLE":
				tle++;
				break;
			case "RE":
				re++;
				break;
		}
	}
	System.out.println("AC x "+ac);
	System.out.println("WA x "+wa);
	System.out.println("TLE x "+tle);
	System.out.println("RE x "+re);
	}
}


Measured memory_bytes: 42544
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << max(A*B, C*D);
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigDecimal a = new BigDecimal(sc.next());
        BigDecimal b = new BigDecimal(sc.next());
        System.out.println(a.multiply(b).setScale(0, BigDecimal.ROUND_DOWN));
    }
}


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

using namespace std;
const long long mod=1000000007;

void modify(long long &a)
{
    if(a>=mod) a%=mod;
}

long long fastpow(long long b,long long e)
{
    long long res=1;
    while(e)
    {
        if(e&1) res*=b;
        modify(res);
        b*=b;
        modify(b);
        e/=2;
    }
    return res;
}

long long choose(long long n,long long k)
{
    long long res=1;
    for(long long i=n-k+1;i<=n;i++)
    {
        res*=i;
        modify(res);
    }
    for(long long i=1;i<=k;i++)
    {
        res*=fastpow(i,mod-2);
        modify(res);
    }
    return res;
}

int main()
{
    long long n,m,k;
    cin >> n >> m >> k;
    long long c=choose(n*m-2,k-2);
    long long res=0;
    for(long long i=1;i<m;i++)
    {
        long long now=c;
        now*=n;
        modify(now);
        now*=n;
        modify(now);
        now*=i;
        modify(now);
        now*=(m-i);
        modify(now);
        res+=now;
        modify(res);
    }
    for(long long i=1;i<n;i++)
    {
        long long now=c;
        now*=m;
        modify(now);
        now*=m;
        modify(now);
        now*=i;
        modify(now);
        now*=(n-i);
        modify(now);
        res+=now;
        modify(res);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n

MOD = 10**9 + 7

# モジュラ逆数戦法
def prepare(n, MOD):

    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return fn, invs


fact, invs = prepare(n, MOD)

print(fact * invs[x] * invs[y] % MOD)

Measured memory_bytes: 38340
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    bool alph[30];
    for (int i = 0; i < 26; ++i) {
		alph[i] = true;
	}
    for(int i = 0; i<S.size(); i++){
        alph[S[i]-'a'] = false;
    }
    for(int i = 0; i < 26; i++){
        if(alph[i]) {
            char c = i+'a';
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


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


ll solve() {
    ll N, X, x, g;
    cin >> N >> X;
    auto gcd = [](ll a, ll b) {
        while ( b != 0 ) {
            ll t = b;
            b = a % b;
            a = t;
        }
        return a;
    };    
    for ( int i = 0; i < N; i++ ) {
        cin >> x;
        if ( i == 0 ) g = abs(x - X);
        else {
            g = gcd(g, abs(x - X));
        }
    }
    return g;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unistd.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    ll N;cin>>N;
    vector<int> A(N);
    ll S=0;
    REP(i, N){
        cin >> A[i];
        S+=A[i];
    }
    ll C=N*(N+1)/2;
    if(S%C!=0){
        cout<<"NO"<<endl;
        return 0;
    }
    C=S/C;
    ll cnt=0;
    //cout<<C<<endl;
    REP(i,N){
        if(C+A[i]-A[(i+1)%N]<0||(C+A[i]-A[(i+1)%N])%N!=0){
            cout<<"NO"<<endl;
            return 0;
        }
        ll k=(C+A[i]-A[(i+1)%N])/N;
        cnt+=k;
    }
    //cout<<cnt<<endl;
    if(cnt==C){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var red = new List<int[]>();
            var blue = new List<int[]>();
            for (int i = 0; i < N; i++)
            {
                var input = ReadArrayInt();
                red.Add(new int[] { input[0], input[1] });
            }
            for (int i = 0; i < N; i++)
            {
                var input = ReadArrayInt();
                blue.Add(new int[] { input[0], input[1] });
            }
            red = red.OrderByDescending(x => x[1]).ToList();
            blue = blue.OrderBy(x => x[0]).ToList();

            var cnt = 0;

            foreach(var b in blue)
            {
                for (int i = 0; i < red.Count; i++)
                {
                    if (red[i][0] < b[0] && red[i][1] < b[1])
                    {
                        red.RemoveAt(i);
                        cnt++;
                        break;
                    }
                }
            }

            Console.WriteLine(cnt);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int N;
int D[100010];

int main(){
    cin >> N;
    for(int i=1;i<=N;i++) cin >> D[i];
    sort(D+1,D+N+1);
    cout << D[N/2+1]-D[N/2] << endl;   
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    VL cnt(n);
    int d;
    FOR(i, 0, n) {
        int in; cin >> in;
        if (i == 0)d = in;
        ++cnt[in];
    }

    bool zero = false;
    ll ans = (cnt[0] == 1 && d == 0 ? 1 : 0), now = (cnt[0] == 1 && d == 0 ? 1 : 0);
    FOR(i, 1, n) {
        if (cnt[i] == 0) {
            zero = true;
            continue;
        }
        else if (zero)ans *= 0;

        FOR(j, 0, cnt[i])(ans *= now) %= MOD;
        now = cnt[i];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), h = sc.nextInt(), m = sc.nextInt();
		double mAngle = m / 60. * 360;
		double hAngle = h / 12. * 360 + mAngle / 360 * 30;
		double diff = Math.abs(mAngle - hAngle);
		double C = Math.min(diff, 360 - diff);
		double c = Math.sqrt(a*a+b*b-2*a*b*Math.cos(C * Math.PI / 180));
		System.out.println(c);
	}
}


Measured memory_bytes: 36024
/*input
8
8 2 7 3 4 5 6 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=2505;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int32_t main(){
    int n;
    cin>>n;
    map<int,int> mp;
    REP(i,n){
        int x;
        cin>>x;
        mp[x]=i+1;
    }
    REP(i,n){
        int j=i+1;
        cout<<mp[j]<<' ';
    }
}


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

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)
        cout<<1<<endl;
    else if(a!=b&&b!=c&&c!=a)
        cout<<3<<endl;
    else
        cout<<2<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
di = {}
for i in range(len(alp)):
    di[alp[i]] = i
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
# N = N % len(S)

ans = []
for s in S:
    ans.append(alp[di[s]+N])

print(''.join(ans))

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            long k = long.Parse(Console.ReadLine()); 
            char ans = '0';

                for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != '1')
                {
                    Console.WriteLine(s[i]);
                    return;
                   
                }
                if (i+1==k)
                {
                    Console.WriteLine(1);
                    return;
                }
                
            }
            
        }

        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#define MAXSIZE 3000
using namespace std;
int main(){
  int a,b,c,count=0;
  std::cin >> a>>b>>c;
  for(int i=a;i<=b;i++){
    if(0==c%i){
      count++;
    }
  }
  std::cout << count << '\n';
}

Measured memory_bytes: 3100
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)

#include <algorithm>
using namespace std;
#include <cmath>
#include <string>
#include<tuple>
#include<map>
#define elif else if
typedef long long ll;

// template<class Container, class T>
// void at_wrap(Container& c, T v)
// {
//   try {
//     cout<< c->first <<  " " << get<0>(c->second )<< " " << get<1>(c->second )  <<endl;
//     //std::cout << c.at(v) << std::endl;
//   }
//   catch(std::out_of_range&) {
//     std::cout << "exception std::out_of_range" << std::endl;
//   }
// }


int main(){
  int H,W,D;
  cin>>H>>W>>D;
  //int A[305][305];
  //tuple<int,int>crd;
  int px[90001],py[90001];

  //map<int,tuple<int,int>>magical={};
  rep1(i,H+1){
    rep1(j,W+1){
      int a;
      cin>>a;
      //magical[a] = make_tuple(i,j);
      px[a] = i;
      py[a]  =j;
    }
  }
  //
  // cout<<magical.size()<<endl;
  // //at_wrap(magical,5);
  // cout<<get<0>(magical[5])<<endl;

  // for(auto i = magical.begin(); i!= magical.end();++i ){
  //   cout<< i->first <<  " " << get<0>(i->second )<< " " << get<1>(i->second )  <<endl;
  // }
  int Q;
  cin>>Q;
  //塁積和
  int d[90005] = {0};

  for(int i = D+1;i<=H*W;i++){
    d[i] = d[i-D] + abs(px[i] - px[i-D] ) + abs(py[i]-py[i-D]);
  }

  //rep1(i,H*W+1)cout<<i<<" "<<d[i]<<endl;

  rep(i,Q){
    int L,R;
    cin>>L>>R;
    cout<<d[R]-d[L]<<endl;

  }

  //
  // rep(i,Q){
  //   int L,R;
  //   cin>>L>>R;
  //   int tmp = R-L;
  //   tmp /= D;
  //   int ans = 0;
  //   rep(i,tmp){
  //     int dx = abs( get<0>(magical[L]) - get<0>(magical[L + D]) );
  //     int dy = abs( get<1>(magical[L]) - get<1>(magical[L + D]) );
  //     ans += dx+ dy;
  //     L += D;
  //   }
  //   cout<<ans<<endl;
  //
  // }
  //

  //  for (const auto& [key, value] : magical){
  //     cout << key << " => " << value << endl;
  // }
  // rep1(i,magical.size()+1){
  //   cout<<magical[i]<<endl;
  //
  // }
  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<cstdio>
#define INF 10000000
using namespace std;
int main(){
  int n,m,p,a,b;
  double cost[30][1024],ticket[10],edge[30][30];
  bool done[30];
  while(cin >>n>>m>>p>>a>>b,n||m||p||a||b){
    for(int i=0; i<m; i++) done[i] = false;
    for(int i=0; i<m; i++) for(int j=0; j<30; j++) edge[i][j] = -1;
    for(int i=0; i<m; i++) for(int j=0; j<(1<<n); j++) cost[i][j] = INF;
    for(int i=0; i<n; i++) cin >>ticket[i];
    for(int i=0; i<p; i++){
      int x,y; double z;
      cin >>x>>y>>z;x--;y--;
      edge[x][y] = edge[y][x] = z;
    }
    a--;b--;
    cost[a][0] = 0;
    for(;;){
      int next=-1;double n_c=INF;
      for(int i=0; i<m; i++){
	if(done[i]) continue;
	for(int j=0; j<(1<<n); j++){
	  if(n_c > cost[i][j]){
	    n_c = cost[i][j];
	    next = i;
	  }
	}
      }
      if(next == -1) break;
      done[next] = true;
      for(int i=0; i<m; i++){
	if(edge[next][i] == -1 || done[i]) continue;
	for(int j=0; j<(1<<n); j++){
	  if(cost[next][j] == INF) continue;
	  for(int k=0; k<n; k++){
	    if((j&(1<<k)) == 0) cost[i][j|(1<<k)] = min(cost[i][j|(1<<k)],cost[next][j]+edge[next][i]/ticket[k]);
	  }
	}
      }
    }
    double ans = INF;
    for(int i=0; i<(1<<n); i++) ans = min(ans,cost[b][i]);
    if(ans == INF) cout <<"Impossible"<<endl;
    else printf("%.3lf\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1528
#include<stdio.h>


int main(){
	int W[10],K[10],i,j,c;
	
	for(i=0;i<10;i++){
		scanf("%d",&W[i]);
	}
	for(i=0;i<10;i++){
		scanf("%d",&K[i]);
	}
	for(i=0;i<10;i++){
		for(j=i;j<10;j++){
			if(W[i]<W[j]){
				c=W[i];
				W[i]=W[j];
				W[j]=c;
			}
			if(K[i]<K[j]){
				c=K[i];
				K[i]=K[j];
				K[j]=c;
			}
		}
	}
	printf("%d %d\n",W[0]+W[1]+W[2],K[0]+K[1]+K[2]);
	return 0;
}

Measured memory_bytes: 0
S = input()
T = input()
for k in range(len(S)-len(T),-1,-1):
    f = 1
    for i in range(len(T)):
        if S[k+i] != "?" and S[k+i] != T[i]:
            f = 0
            break
    if f == 1:
        print(S[:k].replace("?","a")+T+S[k+len(T):].replace("?","a"))
        exit(0)
print("UNRESTORABLE")


Measured memory_bytes: 61256
#pragma GCC optimize("O3")
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int N;
    vector<string> S;
    int ac=0;
    int tle=0;
    int wa=0;
    int re=0;

    cin  >> N;
    REP(i, N){
        string si;
        cin >> si;
        if (si == "AC"){
            ac += 1;
        }
        if (si == "TLE"){
            tle += 1;
        }
        if (si == "WA"){
            wa += 1;
        }
        if (si == "RE"){
            re += 1;
        }
    }
    cout << "AC x "  << ac  << endl;
    cout << "WA x "  << wa  << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x "  << re  << endl;


    return 0;
}


Measured memory_bytes: 3232
n = int(input())
dp = [[0]*10 for _ in range(10)]
for d in range(1,n+1):
  s = str(d)
  dp[int(s[0])][int(s[-1])] += 1
  
ans = 0
for i in range(1,10):
  for j in range(1,10):
    ans += dp[i][j]*dp[j][i]
print(ans)

Measured memory_bytes: 3064
n,m=map(int,input().split())

hoge=[]
huga=[]
for i in range(n):
  hoge.append(list(input()))
  
for i in range(m):
  huga.append(list(input()))
ans=0
for i in range(1+n-m):
  for j in range(1+n-m):
    flag=0
    for k in range(m):
      for l in range(m):
        if(hoge[i+k][j+l]!=huga[k][l]):
          flag+=1
    if(flag==0):
      ans+=1
if(ans==0):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int k;
	cin >> k;
	int d = k;
	int ans = 1;
	while(d % 360 != 0){
		d += k;
		ans ++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
        a+=1;
      }
    }else{
      if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
        a+=1;
      }
    }
  }
  if(a==s.size()){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

typedef pair <int, int> P;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    vector < vector <P> > testimony(n);

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        for (int j = 0; j < a; j++) {
            int x, y;
            cin >> x >> y;
            testimony[i].push_back(P(x - 1, y));
        }
    }

    int ans = 0;
    for (int i = 1; i < (1 << n); i++) {
        if (ans >= __builtin_popcount(i)) continue;

        bool possible = true;

        for (int j = 0; j < n; j++) {
            if (!(i & (1 << j))) continue;

            for (P p : testimony[j]) {
                if (((i >> p.first) & 1) != p.second) {
                    possible = false;
                    break;
                }
            }

            if (!possible) break;
        }

        if (!possible) continue;
        ans = __builtin_popcount(i);
    }

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

Measured memory_bytes: 384
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
s1 = arr.inject(:+)
s2 = 0
min = s1
arr.each do |a|
	s1 -= a
	s2 += a 
	abs = (s1-s2).abs 
	min = abs if min > abs 
end
puts min


Measured memory_bytes: 14216
fun main() {
    val builder = StringBuilder()

    val (x, y) = readInputLine().split(" ").map { it.toInt() }

    for (i in 0..x) {
        if (i * 2 + (x - i) * 4 == y) {
            println("Yes")
            return
        }
    }

    println("No")

//    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36308
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define MXN 100010
int dp[MXN], child_cnt[MXN];
vector<int> adj[MXN], adj_reverse[MXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N; cin>>N;
	int M; cin>>M;
	for(int i=1; i<=M; i++)
	{
		int x, y; cin>>x>>y;
		adj[x].push_back(y);
		adj_reverse[y].push_back(x);
		child_cnt[x]++;
	}

	queue<int> Queue;
	for(int i=1; i<=N; i++) if(!child_cnt[i]) Queue.push(i);

	while(!Queue.empty())
	{
		int node = Queue.front();
		Queue.pop();
		dp[node] = 0;
		for(auto x:adj[node])
			if(dp[x]+1>dp[node]) dp[node] = dp[x]+1;
		for(auto x:adj_reverse[node])
		{
			child_cnt[x]--;
			if(!child_cnt[x]) Queue.push(x);
		}
	}

	int mx =0;
	for(int i=1; i<=N; i++) if(dp[i]>mx) mx = dp[i];
	cout << mx << '\n';

	return 0;
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int main() {
	ll x, y, z;
	cin >> x >> y >> z;
	ll n = x + y + z;
	vl a(n), b(n), c(n);
	rep(i, n) cin >> a[i] >> b[i] >> c[i];
	vi idx(n);
	rep(i, n) idx[i] = i;
	sort(all(idx), [&](int l, int r) {return a[l] - b[l] < a[r] - b[r];});
	vl XA(n), YB(n), ZC(n);
	priority_queue<pll,vector<pll>,greater<pll> > qBC;
	ll sumA = 0LL, sumB = 0LL, sumC = 0LL;
	rep(i, y) sumB += b[idx[i]];
	YB[y-1] = sumB;
	rep(i, y) qBC.push({b[idx[i]]-c[idx[i]], (ll)i});
	REP(k, y, n-x) {
		pll p = qBC.top();
		ll tmp = b[idx[k]] - c[idx[k]];
		if(p.fi > tmp) sumC += c[idx[k]];
		else {
			qBC.pop();
			qBC.push({b[idx[k]]-c[idx[k]], k});
			sumB -= b[idx[p.se]];
			sumB += b[idx[k]];
			sumC += c[idx[p.se]];
		}
		YB[k] = sumB;
		ZC[k] += sumC;
	}

	priority_queue<pll,vector<pll>,greater<pll> > qAC;
	sumC = 0LL;
	REPR(i, n, n-x) sumA += a[idx[i]];
	XA[n-x-1] = sumA;
	REPR(i, n, n-x) qAC.push({a[idx[i]]-c[idx[i]], (ll)i});
	REPR(k, n-x, y) {
		pll p = qAC.top();
		ll tmp = a[idx[k]] - c[idx[k]];
		if(p.fi > tmp) sumC += c[idx[k]];
		else {
			qAC.pop();
			qAC.push({a[idx[k]]-c[idx[k]], k});
			sumA -= a[idx[p.se]];
			sumA += a[idx[k]];
			sumC += c[idx[p.se]];
		}
		XA[k-1] = sumA;
		ZC[k-1] += sumC;
	}
	ll ans = 0LL;
	rep(i, n) ans = max(ans, XA[i]+YB[i]+ZC[i]);
	cout << ans << endl;
	dumpV(XA);
	dumpV(YB);
	dumpV(ZC);
	return 0;
}

Measured memory_bytes: 7796
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int countList[] = new int[n+1];
		int count = 0;

		for(int i=0;i<n-1;i++){
			String ss = s.substring(i,i+2);
			if(ss.equals("AC")){
				count++;
				countList[i+1]=count;
				// System.out.println(i + " "+count);
			}else{
				countList[i+1]=count;
				// System.out.println(i + " "+count);
			}
		}

		for(int i=0;i<q;i++){
			int l = sc.nextInt();
			int r = sc.nextInt();
			int total = countList[r-1] -countList[l-1];
			// System.out.print(countList[r-1] + " ");
			// System.out.print(countList[l-1] + " ");
			System.out.println(total);
		}


 
	}
}


Measured memory_bytes: 67880
import math
n, m = map(int, input().split())

mx = max(n, m)
mn = min(n, m)

if n == m:
    print((2*math.factorial(n)*math.factorial(m))%(10**9+7))
elif n==m-1 or n==m+1:
    print((math.factorial(n)*math.factorial(m))%(10**9+7))
else:
    print(0)

Measured memory_bytes: 11140
#include <iostream>

using namespace std;

int main()
{
	int n, k, s;
	cin >> n >> k >> s;

	if (k == 0) {
		if (s > 999999900) {
			for (int i = 0; i < n - 1; i++) {
				cout << s - 1 << " ";
			}
			cout << s - 1 << endl;
		}
		else {
			for (int i = 0; i < n - 1; i++) {
				cout << s + 100 << " ";
			}
			cout << s + 100 << endl;
		}		
		return 0;
	}

	if (n == k) {
		for (int i = 0; i < k - 1; i++) {
			cout << s << " ";
		}
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s << " ";
		}
		if (s > 999999900) {
			for (int i = k; i < n - 1; i++) {
				cout << s - 1 << " ";
			}
			cout << s - 1 << endl;
		}
		else {
			for (int i = k; i < n - 1; i++) {
				cout << s + 100 << " ";
			}
			cout << s + 100 << endl;
		}

	}
	
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
int main(){
  ll n;
  cin >> n;
  ll x;
  if(n%11>6)
    x=2;
  else if(n%11)
    x =1;
  else
    x = 0;
  cout << 2*(n/11) + x << endl;


  return 0;
}


Measured memory_bytes: 384
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int a,b,c,d;
  cin>>a>>b>>c>>d;

  cout<<(a-c)*(b-d)<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;


int main(){
    int N, M;

    cin >> N;
    vector<string> s(N);
    rep(i, N) cin >> s[i];

    cin >> M;
    vector<string> t(M);
    rep(i, M) cin >> t[i];

    map<string, int> mp;
    rep(i, N){
        mp[s[i]]++;
    }
    rep(i, M){
        mp[t[i]]--;
    }
    int maxi = 0;
    for(auto m : mp){
        maxi = max(maxi, m.second);
    }
    cout << maxi << endl;
    return 0;

}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll n, r;

	scanf("%lld", &n);
	r = (ll)sqrt(n) + 1;

	for (ll i = r; i >= 1; i--)
	{
		if (!(n%i))
		{
			printf("%lld", i + (n / i) - 2);
			return 0;
		}
	}
}


Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
needed_minus = 0
for i in range(N):
    if a[i] > b[i]:
        needed_minus += a[i] - b[i]
    elif a[i] % 2 != b[i] % 2:
        needed_minus += 1
if needed_minus > sum(b) - sum(a):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 10544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	long double n;
	cin>>n;
	ll a=(n+1)/2;
	cout <<a/n;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3740
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#define INF 100000000

#define MAX_N 10000
#define MAX_M 100

typedef long long int ll;
using namespace std;



int main(){

	int a,b;

	char op;

	while(true){
	
		scanf("%d %c %d", &a, &op, &b);

		if(op == '+')
			printf("%d\n", a+b);
		else if(op == '-')
			printf("%d\n", a-b);
		else if(op == '*')
			printf("%d\n", a*b);
		else if(op == '/')
			printf("%d\n", a/b);
		else break;
	
	}

	return 0;

}

Measured memory_bytes: 1192
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
char str[1100005];
int cnt[30];
typedef long long LL;
int main(void)
{
    while(scanf("%s",str)!=EOF)
    {
        memset(cnt,0,sizeof(cnt));
        LL l;
        l = strlen(str);
        for(int i = 0;i < l;i++)
        {
            cnt[str[i]-'a']++;
        }
        LL sum = l*(l-1)/2LL;
        for(int i = 0;i < 26;i++)
            sum -= (LL)cnt[i]*(LL)(cnt[i]-1)/2LL;
        printf("%lld\n",sum+1LL);
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int a,b,c;
    cin >> a >> b;
    if(a >= 13) {
        c = b;
    } else if(a >= 6) {
        c = b/2;
    } else {
        c = 0;
    }

    cout << c << endl;
}


Measured memory_bytes: 256
pub trait FromLn {
	fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
	let mut buf = String::new();
	let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
	T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
	let mut vs = vec![];
	for _ in 0..n { vs.push(readln()); }
	vs
}
macro_rules! fromln_primitives {
	($($t:ty),*) => { $(
		impl FromLn for $t {
			fn fromln(s: &str) -> $t {
				s.parse().unwrap()
			}
		}
	)* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
	fn fromln(s: &str) -> Vec<T> {
		s.split_whitespace().map(T::fromln).collect()
	}
}
impl FromLn for Vec<char> {
	fn fromln(s: &str) -> Vec<char> {
		s.chars().collect()
	}
}
macro_rules! fromln_tuple {
	($($t:ident),*) => {
		impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
			fn fromln(s: &str) -> ($($t),*) {
				let mut it = s.split_whitespace();
				let t = ($($t::fromln(it.next().unwrap())),*);
				assert_eq!(it.next(), None);
				t
			}
		}
	}
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);

fn main() {
    let (a, b, c): (i32, i32, i32) = readln();
    let x = a * 100 + b * 10 + c;
    let ans = match x % 4 {
        0 => "YES",
        _ => "NO"
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

ll N,M,Q;
ll a[100];
ll b[100];
ll c[100];
ll d[100];

ll ans = 0;

void dfs (vector<int> A)
{
    if (A.size() == N) {
        ll sum = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                sum += d[i];
            }
        }
        ans = max(ans, sum);
        return;
    }

    int s = (A.size() == 0) ? 1 : A.back();
    for (int i = s; i <= M; i++) {
        vector<int> At = A;
        At.push_back(i);
        dfs(At);
    }
}

int main ()
{

    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    ans = 0;
    vector<int> A;
    dfs (A);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
using System;

namespace _0063
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0;
            while (true)
            {
                string a = Console.ReadLine();
                if (a == null) { break; }
                //string b = a;
                //string b1 = a.Reverse().ToString ;
           //     Array.Reverse(b);
             //     if (a == b1) { n++; }
                char[] chars = a.ToCharArray();
                Array.Reverse(chars);
                var ret = new string(chars);
                if (a == ret) { n++; }
            }
            Console.WriteLine(n);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 8968
class Node:
    def __init__(self, node):
        self.node = node
        self.parent = -1
        self.depth = 0
        self.type = ""
        self.children = []

    def __str__(self):
        if self.parent == -1:
            self.type = "root"
        elif len(self.children) == 0:
            self.type = "leaf"
        else:
            self.type = "internal node"
        return "node {}: parent = {}, depth = {}, {}, {}".format(
            self.node, self.parent, self.depth, self.type, self.children)


def dfs(tree, v, p, d):
    from collections import deque
    que = deque()
    tree[v].parent = p
    tree[v].depth = d
    que.extend(tree[v].children)
    while len(que) > 0:
        c = que.pop()
        if tree[c].parent == -1:
            dfs(tree, c, v, d + 1)


def resolve():
    n = int(input())
    tree = [Node(i) for i in range(n)]
    V = [list(map(int, input().split())) for _ in range(n)]
    hasChild = set()
    childrens = set()
    for a, k, *c in V:
        if len(c) > 0:
            tree[a].children = c
            hasChild.add(a)
            childrens.update(c)
    root = hasChild - childrens
    if len(root) > 0:
        dfs(tree, root.pop(), -1, 0)
    print(*tree, sep="\n")


resolve()



Measured memory_bytes: 58696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  
  if(a%2==1 && b%2==1 && c%2==1){
  cout << min(a*b, min(b*c, c*a)) << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
package main

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

func main() {
	list := getStdinIntArr64()
	N := uint64(list[0])
	divitors := make([]uint64, N+1)

	var i uint64 = 0
	var j uint64 = 0
	for i = 1; i <= N; i++ {
		for j = i; j <= N; j += i {
			divitors[j]++
		}
	}

	var k uint64 = 1
	var ans uint64 = 0
	for ; k <= N; k++ {
		ans += k * divitors[k]
	}
	fmt.Printf("%d\n", ans)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 82824
A = [int(input()) for i in range(5)]
li = 6
m = 10
for i in range(5):
    v = A[i] % 10
    if not v == 0:
        if v < m:
            m = v
            li = i

ans = 0
for i in range(5):
    if i == li or A[i] % 10 == 0:
        ans += A[i]
    else:
        ans += (A[i] // 10 + 1) * 10

print(ans)

Measured memory_bytes: 3064
N,K=map(int,input().split())
sum=0
#N面サイコロ、得点K
#K-1以下の得点ならコインを振り続ける
for i in range(1,N+1):
  target=i
  count=0
  while(target<K):
    target*=2
    count+=1
  sum+=(1/N)*(0.5**count)
print(sum)
  
  
  
  

Measured memory_bytes: 39024
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
counter = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0
}
n = int(input())
for _ in range(n):
    counter[input()] += 1

for v, c in counter.items():
    print(v, 'x', c)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
ll n;
set<ll> st;
int main(){
	scanf("%lld", &n);
	for(ll i=1; i*i <= n; i++) if(n % i == 0){
		ll k = n/i;
		rep(o,2){
			if(k == 1) continue;
			ll t = n;
			while(t % k == 0) t /= k;
			if(t % k == 1) st.insert(k);
			k = n / k;
		}
	}
	n--;
	for(ll i=1; i*i <= n; i++) if(n % i == 0){
		st.insert(i); st.insert(n/i);
	}
	printf("%lu\n", st.size() - 1);
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	N=int(input())
	A=list(map(int,input().split()))
	
	L=[0]*N
	R=[0]*N
	M=[0]*N
	
	L[0] = A[0]
	R[N-1]=A[N-1]
	
	for i in range(1,N):
		L[i]=gcd(A[i],L[i-1])
	for i in range(N-2,0,-1):
		R[i]=gcd(A[i],R[i+1])
	
	M[0]=R[1]
	M[N-1]=L[N-2]
	
	for i in range(1,N-1):
		M[i]=gcd(L[i-1],R[i+1])
	
	print(max(M))
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
if __name__ == '__main__':
	main()


Measured memory_bytes: 83820