akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

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

		int N = sc.nextInt();
		int[] L = new int[N];

		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}

		Arrays.sort(L);

		int max_length = L[N - 1];

		int sum = 0;
		for (int i = 0; i < L.length - 1; i++) {
			sum += L[i];
		}

		if (sum > max_length) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

using namespace std;

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

int main()
{
    IOS;
    map<ll,ll> mp;
    ll n,k;
    cin>>n>>k;
    ll a[n+1],s[n+1];
    mp[0]=1;
    s[0]=0;
    repf(i,1,n+1) cin>>a[i];
    repf(i,1,n+1) s[i]=s[i-1]+a[i];
    ll ans=0;
    repf(i,1,n+1)
    {
        if(i-k>=0) mp[(s[i-k]-(i-k)+k)%k]--;
        ans+=mp[(s[i]-i+k)%k];
        mp[(s[i]-i+k)%k]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define ar array



void solve(){
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for(int i = 0;i < n; i++){
		cin >> arr[i];
	}	
	vector<bool> dp(k+1,0);
	for(int i = 0;i <= k; i++){
		for(auto e : arr){
			if(i >= e && !dp[i-e]) dp[i]=1;
		}
	}
	cout << (dp[k]?"First\n":"Second\n");
}

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

    int TC = 1;
    while(TC--)
        solve();

    return 0;
}



Measured memory_bytes: 3672
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
l = [0]
r = [0]
ans = 0
for i in range(n-1):
    l.append(gcd(l[i],a[i]))
for i in range(n-1):
    r.append(gcd(r[i],a[n-1-i]))
for i in range(n):
    ans = max(ans,gcd(l[i],r[-i-1]))
print(ans)

Measured memory_bytes: 16164
N = int(input())
A = [int(i) for i in input().split()]
odd, four = 0, 0
for a in A:
    if a & 1 == 1: odd += 1
    if a & 3 == 0: four += 1
# 4の倍数の個数 == 奇数の個数
# すべて偶数
if odd == 0 or four >= odd or (four == odd - 1 and four + odd == N):
    print('Yes')
else:
    print('No')


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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  vector<string> ans;
  rep(i,s.size()) {
    string tmp = s.substr(0, i);
    rep(j,t.size()) {
      if (i+j >= s.size()) break;
      //      printf("[*] (i,j): (%d, %d)\t%c == %c\n", i, j, s[i+j], t[j]);
      if (s[i+j] != '?' && s[i+j] != t[j]) break;
      if (s[i+j] == '?') tmp += t[j];
      else tmp += s[i+j];
      if (j == t.size()-1) {
	tmp += s.substr(i+j+1, s.size()-i-j-1);
	ans.push_back(tmp);
      }
    }
  }
  vector<string> ans2;
  rep(i,ans.size()) {
    string tmp = "";
    rep(j, ans[i].size()) {
      if (ans[i][j] == '?') tmp += 'a';
      else tmp += ans[i][j];
    }
    ans2.push_back(tmp);
  }
  sort(ans2.begin(), ans2.end());
  cout << (ans2.size() > 0 ? ans2[0] : "UNRESTORABLE") << endl;
  return 0;
}


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

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long , long> pll;
typedef vector< pll > vll;
typedef set<ll> sl;
typedef map<string, int> msi;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define inf 0x3f3f3f3f
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))

const ll md = 1000000007;
//void mod(ll &x){if (x >= md) x -= md; if (x < 0) x += md;}

//ll dp[h][w];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll h,w,i,j;
	cin>>h>>w;
	string s[h];
	ll dp[h][w];
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
	for(i=0;i<h;i++){
		cin>>s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(i>0&&j>0&&s[i-1][j]=='.'&&s[i][j-1]=='.')
				dp[i][j] = (dp[i-1][j]%md + dp[i][j-1]%md)%md;
			else if(i>0&&s[i-1][j]=='.')
				dp[i][j] = dp[i-1][j]%md;
			else if(j>0&&s[i][j-1]=='.')
				dp[i][j] = dp[i][j-1]%md;
		}
	}
	cout<<dp[h-1][w-1];
    return 0;
}




Measured memory_bytes: 9088
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 100005;

ll n, A[MAXN], B[MAXN];

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

    for (int i = 0; i < n; i++) {
        scanf("%lld", &B[i]);
    }

    for (int i = 0; i < n; i++) {
        A[n - 1] += (i % 2 == 0 ? 1 : -1) * B[i];
    }

    for (int i = 0; i < n; i++) {
        A[i] = 2 * B[i] - A[(i - 1 + n) % n];
    }

    for (int i = 0; i < n; i++) {
        printf("%lld ", A[(i - 1 + n) % n]);
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    if(A + B - 1 > N){
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans;
    int rest = N - A;
    int now = 0;
    for(int i = 0; i < A; ++i){
        if(rest > 0){
            int temp = min(rest + 1, B);
            for(int j = 0; j < temp; ++j){
                ans.push_back(now + temp - j);
            }
            now += temp;
            rest -= temp - 1;
        } else {
            ans.push_back(now + 1);
            now++;
        }
    } 
    if(ans.size() != N){
        cout << "-1" << endl;
        return 0;
    }
    for(int i = 0; i < N; ++i){
        cout << ans[i];
        if(i != N - 1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3440
A, B, C, X, Y = map(int, input().split())

ans = 10**10
for ab in range(max(X, Y) * 2 + 10):
    price = C * ab + max(0, X - ab // 2) * A + max(0, Y - ab // 2) * B
    ans = min(ans, price)

print(ans)


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

int main(){
  uint32_t N;

  cin >> N;

  pair<int, int>  past_1(-1,-1), past_2(-1,-1);
  int tmp1, tmp2;
  cin >> tmp1 >> tmp2;
  past_2 = make_pair(tmp1, tmp2);
  cin >> tmp1 >> tmp2;
  past_1 = make_pair(tmp1, tmp2);


  for( uint32_t i = 2; i < N; ++i ){
    cin >> tmp1 >> tmp2;
    if( past_1.first == past_1.second && past_2.first == past_2.second && tmp1 == tmp2 ){
      cout << "Yes" << endl;
      return 0;
    }
    past_2 = past_1;
    past_1.first = tmp1;
    past_1.second = tmp2;
  }

  cout << "No" << endl;
}

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

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

  int n, x;
  cin >> n >> x;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a.begin() + 1, a.end());
  
  vector<long long> b(n + 1);
  b[0] = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = b[i - 1] + (long long)a[i];
  }

  if (b[n] < x) {
    cout << n - 1 << '\n';
    return 0;
  } else if (b[n] == x) {
    cout << n << '\n';
    return 0;
  }

  auto it = upper_bound(b.begin(), b.end(), x);
  int ind = it - b.begin();
  cout << ind - 1 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
 
const int MAXN = 2e5 + 5;

map<string, int> mp;

int N, ans;
 
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for(int i=1; i<=N; i++) {
		string s; cin >> s;
		mp[s]++;
		ans = max(ans, mp[s]);
	}
	for(auto i : mp) {
		if(i.se == ans) cout << i.fi << endl;
	}
}


Measured memory_bytes: 23808
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int w,h, a,b;

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

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

typedef long long ll;

ll mod=1e9+7;
ll modpow(ll x, ll n, ll m)
{
    ll res=1;
    while (n>0) {
        if (n&1) res=res*x%m;
        x=x*x%m;
        n>>=1;
    }
    return res;
}

ll f[200010], invf[200010];

ll comb(ll n, ll k, ll m)
{
    return f[n]*invf[k]%m*invf[n-k]%m;
}

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

    f[0]=invf[0]=1;
    for(int i=1; i<=h+w; ++i) {
        f[i]=i*f[i-1]%mod;
        invf[i]=modpow(f[i], mod-2, mod);
    }

    ll res=0;
    for(int i=0; i<h-a; ++i)
        res=(res+comb(b-1+i, i, mod)*comb(w-b-1+h-1-i, w-b-1, mod))%mod;
    cout<<res<<endl;
}


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

int main()
{
  size_t n,a,b;cin>>n>>a>>b;
  size_t ave = (a + b)/2;
  if (ave * 2 == a + b)
  {
    cout <<  ave - a << endl;
  }
  else
  {
    cout << min(a-1, n-b) + 1 +(b-a-1)/2 << endl;
  }
  
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  rep(i,M) cin >> A[i];
  rep(i,M) N -= A[i];
  if (N >= 0) cout << N << endl;
  else cout << -1 << endl;
  return 0;
}

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

using namespace std;

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef set<int> si;
typedef set<vi> svi;
typedef set<ll> sll;
typedef set<vll> svll;
typedef set<pii> spii;
typedef set<vpii> svpii;
typedef set<pll> spll;
typedef set<vpll> svpll;
typedef vector<si> vsi;
typedef vector<sll> vsll;
typedef vector<spii> vspii;
typedef vector<spll> vspll;
#define ft first
#define sc second
#define pb push_back
#define ins insert
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define sortarr(a,n) sort(a,a+n)
#define tt ll tc; cin >> tc; while(tc--)
#define rep(var,start,end,interval) for(ll var=start;(interval>0 and var<end) or (interval<0 and var>end);var+=interval)
#define each(x,v) for(auto x : v)
#define takearr0(a,n) rep(z,0,n,1) cin >> a[z];
#define takearr1(a,n) rep(z,1,n+1,1) cin >> a[z];

const ll max_n = 2e5 + 5;

string s;
ll n = 0;

int main()
{
	io;
	cin >> s;
	each(c,s) n += c-'0';
	if(n%9)
		cout << "No\n";
	else
		cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;

int main() {
  ll a, speed1;
  ll b, speed2;
  std::cin >> a >> speed1;
  std::cin >> b >> speed2;
  ll t;
  std::cin >> t;
  if(speed1 <= speed2) 
    std::cout << "NO";
  else if(t < fabs(a - b) / (speed1 - speed2)) {
    std::cout << "NO";
  } else
    std::cout << "YES";
}


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

public class Main {

    private static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException exp) {
                    throw new RuntimeException(exp);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {    //throws FileNotFoundException {
        InputStream inputStream = System.in;    //new FileInputStream("input.txt");
        OutputStream outputStream = System.out; //new FileOutputStream("output.txt");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task newTask = new Task();
        newTask.solve(in, out);

        out.close();
    }

    private static class Task {
        //.constant
        private final int INF = Integer.MAX_VALUE;
        private final int MOD = (int)1e9 + 7;

        //.data
        private int[][] gr = new int[300][300];
        private int n = 0;

        private long f() {
            long sum = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    boolean flag = true;
                    for (int k = 0; k < n; ++k) {
                        if (i != j && j != k && i != k) {
                            if (gr[i][j] > gr[i][k] + gr[k][j]) {
                                return -1;
                            }
                            if (gr[i][j] == gr[i][k] + gr[k][j]) {
                                flag = false;
                            }
                        }
                    }
                    if (flag && i < j) {
                        sum += gr[i][j];
                    }
                }
            }
            return sum;
        }

        //.code
        public void solve(InputReader in, PrintWriter out) {
            n = in.nextInt();
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    gr[i][j] = in.nextInt();
                }
            }

            out.println(f());

        }//end

    }

}

Measured memory_bytes: 35404
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ




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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  ll t ;
  cin >> t ;
  vector<ll> tim(n) ;
  ll ans = t ;
  REP(i,n){
    cin >> tim.at(i) ;
  }
  REP(i,n){
    if(i!=0){
      if(tim.at(i)<=t+tim.at(i-1)){
        ans += tim.at(i)-tim.at(i-1) ;
      }
      else{
        ans += t ;
      }
    }
  }
  
  cout <<ans <<endl ;
      
  
  
  
  
  
  return 0 ;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define eb          emplace_back
#define mp          make_pair
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(i=a;i<b;i++)
#define all(v)      v.begin(),v.end()
#define allr(v)     v.rbegin(),v.rend()
#define mod         1e9+7
#define CIN(V,s,n)  for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}
#define SbS         sortbysec
#define fast        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);   for(ll i=0;i<V.size();i++) V[i] = 0;

// map<ll,vector<ll> > M;
// map<ll,vector<ll> >:: iterator it;
// it = M.begin();
// it.F will be ll
// it.S will be vector<ll>

using namespace std;

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}

int main()
{
ll t=1;
//cin >> t;
while(t--)
{
    ll a,b,c,d,n,m,i,j,k,h,l,l2,w,q=1,u,v,temp=0,cn=0,cp=0,c0=0,max1=0;
    cin >> n;
    vector<pair<ll,ll> > DP;
    for(i=0;i<n;i++)
    {
        cin >> a >> b;
        DP.pb(mp(b,a));
    }
    sort(all(DP));
    if(n==1)
    {
        if(DP[0].S <= DP[0].F)
        {
            cout << "Yes";
        }
        else
            cout << "No";
    }
    else
    {
        ll j1 = 0;
        for(i=0;i<n;i++)
        {
            j1 += DP[i].S;
            if(j1 > DP[i].F)
            {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
    }

}
    return 0;
}


Measured memory_bytes: 6256
import numpy as np

N = input()
K = int(input())

n = len(N)
dp0 = np.zeros((n, K+1), np.int64)
dp1 = np.zeros((n, K+1), np.int64)

dp0[0, 0] = 1
dp0[0, 1] = int(N[0]) - 1
dp1[0, 1] = 1
for i, d in enumerate(N[1:]):
    dp0[i+1] += dp0[i]
    dp0[i+1, 1:] += dp0[i, :-1] * 9
    if int(d) == 0:
        dp1[i+1] = dp1[i]
    elif int(d) == 1:
        dp0[i+1] += dp1[i]
        dp1[i+1, 1:] = dp1[i, :-1]
    elif int(d) >= 2:
        dp0[i+1] += dp1[i]
        dp0[i+1, 1:] += dp1[i, :-1] * (int(d) - 1)
        dp1[i+1, 1:] = dp1[i, :-1]

print(dp0[-1, K] + dp1[-1, K])


Measured memory_bytes: 12496
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')



N, M, Q = Is()
ABCD = TIR(Q)
ans = -INF

def dfs(A):
    global ans
    if len(A) == N:
        score = 0
        for a, b, c, d in ABCD:
            if A[b - 1] - A[a - 1] == c:
                score += d
        ans = max(ans, score)
    else:
        ret = 0
        amax = max(A) if len(A) != 0 else 1
        for i in range(amax, M+1):
            dfs(A + [i])

dfs([])
print(ans)


Measured memory_bytes: 73716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF (int)(1e9)
using namespace std;

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

const int MAX_N = (int)1e5 + 5;
int dp[MAX_N];

// O(N * K)
int allSearch(int N, int K, vector<int> h){
	rep (i, N) dp[i] = INF;

	dp[0] = 0;
	rep (i, N){
		for (int k = 1; k <= K; ++k){
			if (i + k < N){
				dp[i+k] = min(dp[i+k], dp[i] + abs(h[i+k] - h[i]));
			} // end if
		} // end for
	} // end rep
	int res = dp[N-1];
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;
	vector<int> h(N, 0);
	rep (i, N){
		cin >> h[i];
	} // end rep

	int res = allSearch(N,K,h);

	cout << res << endl;

	return 0;
}

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

int n;
int ans = 0;
int used[1000005];

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		if (n - i > 0 && n - i != i &&
			!used[n - i] && !used[i]) {
				used[i] = 1;
				used[n - i] = 1;
				ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int A[200009]={0};
int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
int main() {
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int n=s.size();
    long long int r=0,sum=0;
    A[0]++;
    int so=1;
    for(int i=0;i<n;i++)
    {
    	//s*=10;
    	r+=(s[i]-'0')*so;
    	r%=2019;
    	A[r]++;
    	so*=10;
    	so%=2019;
    	//cout<<r<<"\n";
	}
	for(int i=0; i<2019; i++)
	{
		if(A[i]>=2)
		//cout<<A[i]<<" ";
		sum+=(A[i]*(long long int)(A[i]-1))/2;
		
	}
	cout<<sum;
}

Measured memory_bytes: 3636
import sys
from math import atan, degrees, pi

[astr, bstr, cstr] = sys.stdin.readline().split(" ")
a = float(astr)
b = float(bstr)
x = float(cstr)

theta = float(0)
threshold = a * a * b / 2

if threshold < x:  # 角より上
    theta = (2 * (a * a * b - x)) / (a*a*a)
else:
    theta = (a * b * b) / x / 2

rad = atan(theta)
print(degrees(rad))


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
int N,x=0,max=0;
string s;
cin >> N >> s;
for(int i=0;i<N;i++){
if(s[i]=='I'){
x++;
}else{
x--;
}
if(max<x){
max=x;
}
}
cout << max << endl;

return 0;
}


Measured memory_bytes: 256
function main(input) {
  var temp = input.split('\n');

  for (var i =0; i < temp.length; i++) {
    var data = temp[i].split(' ');
    var x = parseInt(data[0]);
    var y = parseInt(data [1]);
    if(x == 0 && y ==0){
      break;
    }
    if (x < y) {
      console.log(x+' '+y);
    } else {
      console.log(y+' '+x);
    }
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


Measured memory_bytes: 18840
import sys

def main():
  input = sys.stdin.readline
  N, M, X, Y = map(int, input().split())
  Xi = [X] + list(map(int, input().split()))
  Yi = [Y] + list(map(int, input().split()))
  
  Xi, Yi = sorted(Xi), sorted(Yi)
  if Xi[-1] < Yi[0]:
    print('No War')
  else:
    print('War')


if __name__ == '__main__':
  main()

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

#define debug(x) cerr << #x << ": " << x << endl

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (4 * i + 7 * j == n) {
        cout << "Yes\n";
        return 0;
      }
    }
  } 
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n; cin>>n;
    cout<<n/3<<endl;
}

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

int main() {
  char a;
  cin>>a;
  if(a=='a'||a=='e'||a=='i'||a=='u'||a=='o') {
    cout<<"vowel"<<endl;
  }
  else {
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    char s[5];
    int i=0;
    cin>>s;
        if((s[i]=='A' && s[i+1]=='A' && s[i+2]=='A')||(s[i]=='B' && s[i+1]=='B' && s[i+2]=='B'))
            cout<<"No";
        else
            cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back
void sieve(vector<int> &x, int k)
{

    for (int i = 1; i <= k; i++)
    {
        x[i] = i;
    }
    int i = 2;
    while (i < k)
    {
        if (x[i] == i)
        {
            for (int j = i; j <= k; j = j + i)
            {
                if (x[j] == j)
                {
                    x[j] = i;
                }
            }
        }
        i++;
    }
}
set<int> prime(int k, vector<int> &x)
{
    set<int> ans;
    while (k != 1)
    {
        ans.insert(x[k]);
        k = k / x[k];
    }
    return ans;
}

int main()
{

    int n;
    cin >> n;
    vector<int> y;
    int m = 0;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        y.pb(t);
        m = max(m, t);
    }
    vector<int> x(m + 1);
    sieve(x, m);
    map<int, int> ans;
    int flag = 0;
    /*for (int i = 0; i < x.size(); i++)
    {
        cout << x[i] << " ";
    }*/

    for (int i = 0; i < n; i++)
    {
        set<int> p = prime(y[i], x);
        for (auto t : p)
        {
            ans[t]++;
            if (ans[t] > 1)
            {
                flag = 1;
            }
            if (ans[t] == n)
            {
                flag = 2;
                break;
            }
        }
    }
    if (flag == 0)
    {
        cout << "pairwise coprime" << endl;
    }
    else if (flag == 1)
    {
        cout << "setwise coprime" << endl;
    }
    else
    {
        cout << "not coprime" << endl;
    }
}

Measured memory_bytes: 14740
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S;
int num[30];
vector<int> pos[30];

int solve(char c){
	string s=S;
	int cnt=0;
	while(true){
		string t;
		set<char> U;
		REP(i,s.size()){
			U.insert(s[i]);
		}
		for(int i=0;i<s.size()-1;i++){
			if(s[i]==c||(i<s.size()-1&&s[i+1]==c)){
				t+=c;
			}
			else{
				t+=s[i];
			}
		}
		if(U.size()==1){
			return cnt;
		}
		s=t;
		cnt++;
	}
}

signed main(){
	cin>>S;
	int N=S.size();
	REP(i,N){
		num[S[i]-'a']++;
		pos[S[i]-'a'].push_back(i);
	}
	int M=0;
	char c;
	int ans=INF;
	REP(i,26){
		ans=min(ans,solve('a'+i));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node
{
    string s;
}a[55];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i].s;
    for(char ch='a';ch<='z';ch++)
    {
        int ans=1e9;
        for(int i=0;i<n;i++)
        {
            int k=0;
            for(int j=0;j<a[i].s.size();j++)
                if(a[i].s[j]==ch) k++;
            ans=min(ans,k);
        }
        for(int j=0;j<ans;j++)
            printf("%c",ch);
    }
    printf("\n");
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define P pair<int ,int>
using namespace std;

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

    int s = 0 ,e = 1;
    ll ans = n;
    int sum = a[0];
    while(s<(n-1)){
        while(e<n){
            if((sum^a[e]) != sum + a[e]) break;
            ans += (e - s);
            sum += a[e];
            e++;
        }
        sum -= a[s];
        s++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(int argc,char* argv[]){
  int number,input,index,count=0;
  vector<int> values;
  cin >> number;
  vector<int>::iterator it;
  for(int i=0;i<number;i++){
    cin >> input;
    values.push_back(input);
  }
  for(int i=0;i<number-1;i++){
    it = min_element(values.begin()+i, values.end());
    index = distance(values.begin(), it);
    if(i!=index){
      swap(values[i],values[index]);
      count++;
    }
  }
  for(int i=0;i<number;i++){
    if(i==number-1) cout << values[i] << endl;
    else cout << values[i] << " ";
  }
  cout << count << endl;
}

Measured memory_bytes: 3116
using System;

public class Hello
{
    public static void Main()
    {
        var c = 0;
        var p = int.Parse(Console.ReadLine().Trim());
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == "=") { Console.WriteLine(p); break; }
            else if (s == "+") c = 0;
            else if (s == "-") c = 1;
            else if (s == "*") c = 2;
            else if (s == "/") c = 3;
            else
            {
                var p2 = int.Parse(s);
                if (c == 0) p += p2;
                else if (c == 1) p -= p2;
                else if (c == 2) p *= p2;
                else p /= p2;
            }
        }
    }
}


Measured memory_bytes: 15984
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
 
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    map<int,int> ma;
    vector<bool> b(N,false);
    REP(i,N-1){
        ma[A[i]]++;
        b[A[i]-1]=true;
    }
    REP(i,N){
        if(b[i]==true){
            cout<<ma[i+1]<<endl;
        } else {
            cout<<0<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 17032
using System;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] l = new int[65536 * 2];
        for (int i = 0; i < l.Length; i++)
        {
            int[] a = Convert.ToString(i, 2).Reverse().Select(x => x == '1' ? 1 : 0).ToArray();
            int current = 1;
            int resasd = 0;
            for (int j = 0; j < a.Length; j++)
            {
                resasd += current * a[j];
                current <<= 1;
                current *= -1;
            }
            l[i] = resasd;
        }
        long res = 0;
        while (true)
        {
            int[] a = Convert.ToString(res, 2).Reverse().Select(x => x == '1' ? 1 : 0).ToArray();
            long current = 1;
            long resasd = 0;
            for (int j = 0; j < a.Length; j++)
            {
                resasd += current * a[j];
                current <<= 1;
                current *= -1;
            }
            if (resasd - 43690 <= n && n <= resasd + 87381)
            {
                long target = n - resasd;
                for (int i = 0; i < l.Length; i++)
                {
                    if(l[i] == target)
                    {
                        Console.WriteLine(string.Join("", Convert.ToString(res + i, 2).Select(x => x == '1' ? 1 : 0)));
                        return;
                    }
                }
                int[] mle = new int[int.MaxValue];
            }
            res += 65536 * 2;
        }
        //Console.WriteLine(string.Join(",", l));
    }
}

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

int main(){
    int k;
    cin >> k;
    queue<ll> list;
    for(int i=1;i<10;i++){
        list.push(i);
    }
    ll s=0;
    for(int i=0;i<k;i++){
        s = list.front();
        list.pop();
        ll p = s%10;
        for(ll i=-1;i<=1;i++){
            ll r = p + i;
            if(r<0 || r>9) continue;
            list.push(s*10+r);
        }
    }
    cout << s << endl;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    char c; cin>>c;
    if('A'<=c&&c<='Z')cout<<'A'<<endl;
    else cout<<'a'<<endl;
}

Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val s = readLine()!!.toCharArray()

    var sum = 0L
    var cnt = 1L
    var max = 1L
    var change = 0
    for (i in 1 until s.size) {
        when {
            s[i] == s[i-1] && s[i] == '>'-> {
                max += 1L
            }
            s[i] != s[i-1] && s[i] == '>' -> {
                sum += cnt * (cnt + 1L) / 2L
                max = 1L
                change += 1
            }
            s[i] == s[i-1] && s[i] == '<' -> {
                cnt += 1L
            }
            s[i] != s[i-1] && s[i] == '<' -> {
                sum += max * (max + 1L) / 2L
                if (change > 0) {
                    sum -= if (max > cnt) cnt else max
                }
                cnt = 1L
                change += 1
            }
        }
    }
    if (s.last() == '>') {
        sum += max * (max + 1L) / 2L
        if (change > 0) {
            sum -= if (max > cnt) cnt else max
        }
    } else {
        sum += cnt * (cnt + 1L) / 2L
    }
    println(sum)
}

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

typedef long long int ll;

int main(){

  int n,m,nans=1,mans=1;
  cin >> n >>m;
  for(int i=0;i<=1;i++){
    if(n<=1)break;
    nans = nans*(n-i);
  }
  if(n>=2)nans = nans/2;
  else nans=0;
  for(int i=0;i<=1;i++){
    if(m<=1)break;
    mans = mans*(m-i);
  }
  if(m>=2)mans = mans/2;
  else mans = 0;
  cout << nans+mans <<endl;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    vector<vector<ll>> pos(('z' - 'a') + 1);
    REP(i, s.size()){
        pos[s.at(i) - 'a'].push_back(i);
    }
    ll ans = s.size();
    REP(i, pos.size()){
        if(pos[i].size() == 0){ continue; }
        ll tmp = max(0LL, pos[i][0]);
        for(ll j = 1; j < pos[i].size(); ++j){
            tmp = max(tmp, pos[i][j] - pos[i][j - 1] - 1LL);
        }
        tmp = max(tmp, (ll)s.size() - pos[i].back() - 1LL);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 207
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};


//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    ll x, k, d;
    cin>>x>>k>>d;
    ll div = x/d;
//    dbg(div);
    if(abs(div) > k)
    {
        if(x < 0)
            k*= -1;
        x -= k*d;
        cout<<abs(x);
    }
    else
    {
        ll fid = k - abs(div);
//        dbg(fid);
        if(fid&1)
            (div < 0 ?div--:div++);
        cout<<abs(x-div*d);
    }
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
ll n,k;
void MAIN() {
	cin>>n>>k;
	cout<<min(n%k,k-n%k);
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

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

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

	int A[100] = { 0 };
	int B[100];

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

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			A[i] = B[i];
		}
		else if (i == N - 1) {
			A[i] = B[i-1];
		}
		else {
			A[i] = min(B[i], B[i - 1]);
		}
	}

	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum = sum + A[i];
	}
	cout << sum << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n;
    cin >> n;
    bool ok = false;
    rep(i, 3) {
        if (n % 10 == 7) ok = true;
        n /= 10;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int main(){


string str;
 long long n,i,j;
 cin>>n>>str;
        vector<long long> R,G;
        unordered_map<long long,bool> B;

        for(i=0;i<n;i++){
        if( str[i] == 'R')
            R.emplace_back(i);
        else if( str[i] == 'G')
            G.emplace_back(i);
        else
            B[i]=true;
        }

      long long  m=B.size();

        long long  ans=R.size()*G.size()*m;

        for(auto a:R)
        for(auto b:G)
        {
            if( (a+b)%2==0 and B[(a+b)/2] )
                ans--;
            if( B[2*a-b])
                ans--;
            if( B[2*b-a])
                ans--;
        }
        cout<<ans;

 return 0;
 }






Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll A[200005],B[200005];

int main(){

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

cin>>N;
rep1(i,N+1) cin>>A[i]>>B[i];
sort(A+1,A+N+1);
sort(B+1,B+N+1);
if(N%2){
	ll Xmin=A[(N+1)/2];
	ll Xmax=B[(N+1)/2];
	cout<<Xmax-Xmin+1<<endl;
}else{
	long double Xmin=(A[N/2]+A[(N/2)+1])/2.0;
	long double Xmax=(B[N/2]+B[(N/2)+1])/2.0;
	ll ans=2*(Xmax-Xmin)+1;
	cout<<ans<<endl;
}

}
    


Measured memory_bytes: 6776
#include <iostream>
#include <string>
using namespace std;
int main() {
    string S;
    cin >> S;
    for (S.erase(S.length()-2, 2); !S.empty(); S.erase(S.length()-2, 2)) {
        int len = S.length();
        if (S.substr(0, len/2) == S.substr(len/2, len/2)) {
            cout << len << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<b&&a!=1){cout<<"Bob"<<endl;}
    else if(b<a&&b!=1){cout<<"Alice"<<endl;}
    else if(a<b&&a==1){cout<<"Alice"<<endl;}
    else if(b<a&&b==1){cout<<"Bob"<<endl;}
    else{cout<<"Draw"<<endl;}
    return 0;
}

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

class Main{
  public static final int WHITE = 0;
  public static final int BLACK = 2;
  public static final int GRAY =1;
  public static final int INFTY = (int)Double.POSITIVE_INFINITY;
  static int n;
  static int M[][];
  static int d[];
  static StringBuilder bl = new StringBuilder();
  static Queue<Integer>  queue = new ArrayDeque<Integer>();
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    M = new int[n][n];
    d  = new int[n];
    int u,v,k;
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        M[i][j] = 0;
      }
    }

    for(int i =0; i<n; i++){
      u = sc.nextInt();
      k = sc.nextInt();
      for(int j = 0; j<k; j++){
        v = sc.nextInt();
        M[u-1][v-1] = 1;
      }
    }
    bfs(0);
  }

  static void bfs(int s){
    queue.add(s);
    for(int i = 0; i<n; i++){
      d[i] = -1;
    }
    d[s] = 0;
    int u;
    while(queue.peek() != null){
      u = queue.peek();
      queue.remove();
      for(int v = 0; v<n; v++){
        if(M[u][v] == 0)continue;
        if( d[v] != -1)continue;
        d[v] = d[u]+1;
        queue.add(v);
      }
    }

    for(int i = 0; i<n; i++){
      bl.append(i+1).append(" ").append(d[i]).append("\n");
    }
    System.out.print(bl);
  }

}


Measured memory_bytes: 28056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)

int main(){
	int A,B;
	cin >> A >> B;
	if(A>=13) cout << B;
	else if(A>=6) cout << B/2;
	else cout << 0;
}

Measured memory_bytes: 256
while true
    h, w = gets.chomp.split.map(&:to_i)
    break if [h, w] == [0, 0]

    keyboard = ""
    h.times{keyboard += gets.chomp}
    x, y, hit = 0, 0, 0
    gets.chomp.split("").each{|c|
        z = keyboard.index(c)
        y2, x2 = z.divmod(w)
        hit += (x - x2).abs + (y - y2).abs + 1
        x, y = x2, y2
    }
    puts hit
end


Measured memory_bytes: 7096
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        if (c > (a + b)) {
            System.out.println(2 * b + a + 1);
        } else {
            System.out.println(b + c);
        }
    }
}

Measured memory_bytes: 21844
n = int(input())
x = list(map(int, input().split()))
x.append(90)
y = 1000
k =0
for i in range(len(x)-1):
    if x[i] < x[i+1]:
        k += int(y/x[i])
        y -= x[i]*int(y/x[i])
    elif x[i] > x[i+1]:
        y += x[i]*k
        k = 0
    
print(y)


Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n[3];
  cin >> n[0] >> n[1] >> n[2];
	int cnt = 0;
  while(!((n[0]==n[1])&&(n[1]==n[2]))){
    sort(n,n+3);
    if(n[1]>=n[0]+2){
      n[0]+=2;
      cnt ++;
    }else if(n[1]==n[0]){
      n[1]++;
      n[0]++;
      cnt++;
    }else{
      n[0]+=2;
      cnt++;
    }
  }
        cout << cnt;
        }

Measured memory_bytes: 256