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


//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n)        for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define PB push_back
#define vvi vector<vi>
#define vvll vector<vll>
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>

#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define GC getchar
#define PC putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()

//policy based data structure
 /*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

*/
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=111111;


//Main function

int main(){
IOS;
TIE;     
#ifndef ONLINE_JUDGE 
  
    // For getting input from input.txt file 
    freopen("input.txt", "r", stdin); 
  
    // Printing the Output to output.txt file 
    freopen("output.txt", "w", stdout); 
  
#endif   

string s;
cin>>s;
s.push_back('S');
int cnt=0;
for(int i=0;i<3;i++)
{
    if(s[i]=='R')
    {
        cnt++;
    }
    if(s[i]=='R' && s[i+1]=='S')
    {
        break;
    }

}
cout<<cnt<<endl;
}
   


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int main(){
    int n,ans;
    cin>>n;
    for(register int i=1;i<=n;++i){
        int x;
        cin>>x;
        if(m[x]==0) v.push_back(x);
        ++m[x];
    }
    for(register int i=0;i<v.size();++i) if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];
    cout<<ans;
    return 0;
}

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

int main(void) {
    int64_t X;
    int64_t ans;
    int64_t chk;

    cin >> X;

    double tmpy = X;
    double tmpans = sqrt((2*tmpy) + 0.25) - 0.5;

    ans = tmpans;
    if(ans % 2) {
        chk = ((ans + 1)/2) * ans;
//printf("tmpans:%lf ans:%ld chk:%ld\n", tmpans, ans, chk);
    } else {
        chk = (ans/2) * (ans+1);
//printf("tmpans:%lf ans:%ld chk:%ld\n", tmpans, ans, chk);
    }

    if(chk != X ){
        ans++;
    }

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


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp)%INF; if(b%2 == 1) temp=(a*temp)%INF; return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }

int arr[100010],dp[100010];
int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		int n; cin >> n;		
		int i;
		rep(i,1,n) cin >> arr[i];
		dp[2]=abs(arr[2]-arr[1]);
		rep(i,3,n)
		{
			dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
		}
		cout << dp[n] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                int cur = in.nextInt();
                if (set.contains(cur)) set.remove(cur);
                else set.add(cur);
            }
            out.println(set.size());
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException ex) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}



Measured memory_bytes: 30548
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	string S; cin >> S;

	int Q; cin >> Q;
	REP(i, Q) {
		int a; cin >> a;
		int d = 0, m = 0, c = 0;
		int dm = 0;
		int s = 0, t = 0;
		int ans = 0;
		while (t - s < a && t<N) {
			//cout << ans << endl;
			//cout << s << " " << t << endl;
			//cout << d << " " << m << " " << dm << endl;
			if (S[t] == 'D') {
				d++;
			}
			if (S[t] == 'M') {
				dm += d;
				m++;
			}
			if (S[t] == 'C') {
				ans += dm;
			}

			if (t - s + 1 >= a) {
				if (S[s] == 'D') {
					d--;
					dm -= m;
				}
				if (S[s] == 'M') {
					m--;
					//dm -= d;
				}
				s++;
			}
			t++;
		}
		cout << ans << '\n';
	}
}

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int k, x;

signed main()
{
    cin >> k >> x;

    if (k * 500 >= x){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


void bubbleSort(int A[101],int N){
  int flag=1,t=0,k=0;
  while(flag==1){

    flag=0;

    for(int j=N-1;j>=1;j--){
      if(A[j]<A[j-1]){
        t=A[j];
        A[j]=A[j-1];
        A[j-1]=t;
        flag=1;
        k++;
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i==N-1){
        printf("%d\n",A[i]);
        break;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",k);
}


int main(void){
  int N,A[101]={};

  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  bubbleSort(A,N);


  return 0;
}



Measured memory_bytes: 2148
#include<cstdio>
#include<algorithm>
using namespace std;
int n,t,qz[100005]={2000000000},c[100005],what=0,qzh[100005],ans,fk[100005];
struct sd{int v,num;bool operator < (const sd &fu) const {return v<fu.v||(v==fu.v&&num<fu.v);};}in[100005];
int main(){
	scanf("%d%d",&n,&t);for(int i=1;i<=n;++i) {scanf("%d",&in[i].v);in[i].num=i;fk[i]=in[i].v;}
	for(int i=1;i<=n;++i) qz[i]=min(qz[i-1],in[i].v);
	sort(in+1,in+1+n);
	for(int i=n;i;--i) what=max(what,in[i].v-qz[in[i].num]);
	int last=0;
	for(int i=n;i;--i) if(in[i].v!=in[i+1].v&&last<in[i].num) {
		int cc=0x7fffffff;qzh[last]=0;
		for(int j=last+1;j<=in[i].num;++j) {
			qzh[j]=qzh[j-1];if(in[i].v-fk[j]==what) ++qzh[j];
		}
		int en;
		for(en=i;in[en].v==in[en-1].v&&in[en-1].num>last;--en) cc=min(cc,i-en+1+qzh[in[en-1].num]);
		cc=min(cc,min(qzh[in[i].num],i-en+1));ans+=cc;
		last=in[i].num;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
from collections import defaultdict
N, M = map(int, input().split())
es = defaultdict(list)
for i in range(M):
  a, b = map(int, input().split())
  es[a-1] += [b-1]
  es[b-1] += [a-1]

for e in es.keys():
  if len(es[e])%2==1:
    print('NO')
    break
else:
  print('YES')

Measured memory_bytes: 59512
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
ans=0
n=2**h
m=2**w
for x in range(n):
    for y in range(m):
        count=0
        for i in range(h):
            for j in range(w):
                if (x>>i)&1 and (y>>j)&1 and c[i][j]=="#":
                    count+=1
        if count==k:
            ans+=1
print(ans)


Measured memory_bytes: 68592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int strSize = 0;
		str = br.readLine();
		StringBuilder sb = new StringBuilder(str);
		strSize = str.length();
		for(int i = 0; i < strSize; ++i){
			char judge = sb.charAt(i);
			if(Character.isLowerCase(judge)){
				char tmp = Character.toUpperCase(judge);
				sb.setCharAt(i, tmp);
			}
			else if(Character.isUpperCase(judge)){
				char tmp = Character.toLowerCase(judge);
				sb.setCharAt(i, tmp);
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 24164
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(n,10*n+1):
    m =list(map(int,str(i)))
    no = 0
    for j in range(len(m)):
        if m[j] in a:
            no = 1
            break
    if no == 0:
        print(i)
        break

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[10000005];
ll h[100005];
int main() {
	int n, k;
	cin >> n >> k;
	
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < n; i++) {
		dp[i] = 1e13;
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		for (int j = max(i - k, 0); j < i; j++) {
			dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto Ns = readln.split.to!(ulong[]);
  writeln(Ns[0] * Ns[1] / gcd(Ns[0], Ns[1]));
}


Measured memory_bytes: 256
n = int(input())
c = []
s = []
f = []
for _ in range(n-1):
    p,q,r = map(int,input().split())
    c.append(p)
    s.append(q)
    f.append(r)
a = [0]*n
for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        if t <= s[j]:
            t = s[j]
        elif t%f[j] != 0:
            t += f[j]-t%f[j]
        t += c[j]
    a[i] = t
print('\n'.join(map(str, a)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code


int main()
{
  int n;
  cin>>n;
  int f[n];
  rep(i, 0, n)
  {
    int a = 0;
    repb(j, 9, 0)
    {
      int z;
      cin>>z;
      a |= (z << j);
    }
    f[i] = a;
  }
  //cout<<f[0]<<endl;
  int p[n][15];
  rep(i, 0, n)
  {
    repn(j, 0, 10)
    {
      cin>>p[i][j];
    }
  }
  int ans = INT_MIN;
  rep(i, 1, (1<<10))
  {
    int cans = 0;
    rep(j, 0, n)
    {
      int curr = i & f[j];
      int co = 0;
      while(curr != 0)
      {
        if(curr&1 == 1) co++;
        curr = curr >> 1;
      }
      cans += p[j][co];
    }
    ans = max(cans, ans);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
l = list(map(int,input().split()))
N = l[0]
Y = l[1]

l = list()

for i in range(N+1):
    a = i
    if (Y - 1000*N -9000*a) % 4000 == 0:
        b = (Y - 1000*N -9000*a) // 4000 
        c = N - a - b
        if a >= 0 and b >= 0 and c >= 0:
            l.append([a,b,c])
            break

if len(l) ==0:
    print("-1 -1 -1")
else:
    ans = l[0]
    print(ans[0],ans[1],ans[2])

Measured memory_bytes: 64412
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int X; cin >> X;
    cout << 10-X/200 << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3624
N = int(input())
*A, = map(int, input().split())
ac = [0]*(N+1)
for i in range(1, N+1):
    ac[i] = ac[i-1]+A[i-1]
ans = float("inf")
for i in range(1, N):
    ans = min(ans, abs(ac[i]-(ac[N]-ac[i])))
print(ans)


Measured memory_bytes: 31520
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 10000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll n, ans = 0;
   cin >> n;
   vector<ll> a(n, 0LL), c(n, 0LL);
   for (ll i = 0LL; i < n; i++)
   {
      cin >> a[i];
      c[i] = a[i] - i - 1LL;
   }
   sort(c.begin(), c.end());
   for(ll i = 0; i < n; i++)
      ans += abs(c[i]-c[n/2LL]);
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3328
def dfs(i, f, s, l):
    if i == l-1:
        return sum(list(map(int, f.split("+"))))
    
    return dfs(i+1, f+s[i+1], s, l) + dfs(i+1, f+"+"+s[i+1], s, l)

def main():
    s = input()
    l = len(s)

    print(dfs(0, s[0], s, l))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int cal(int *a,int n){
    int l,r;
    l=r=n/2;
    while(l>0&&r<n-1){
        if(a[l]==a[l-1])return a[l];
        if(a[r]==a[r+1])return a[r];
        l--;
        r++;
    }
    return a[0];
}
int main(){
    int n;
    scanf("%d",&n);
    int a[200005];
    n=2*n-1;
    for(int i = 0;i<n;i++)
        scanf("%d",&a[i]);
    int Min=0,Max=n;
    while(Max>Min+1){
        int mid=(Max+Min)/2;
        int aa[200005];
        for(int i = 0;i<n;i++){
            if(a[i]>mid)aa[i]=1;
            else aa[i]=0;
            //printf("%d ",aa[i]);
        }
       // printf("\n");
       // printf("%d\n",cal(aa,n));
        if(cal(aa,n)){
            Min=mid;
        }
        else{
            Max=mid;
        }
    }
    printf("%d\n",Max);
}
/*

b[i]*K!/(i)!*(K-i)!
*/

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if(isPrimeNum(num)) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

	// 素数判定
	public static boolean isPrimeNum(int n) {
		if(n == 2) {
			return true;
		}
		if(n < 2 || n % 2 == 0) {
			return false;
		}
		for(int i = 3; i <= Math.sqrt(n); i += 2) { //「合成数xはp<=√xを満たす素因子pをもつ」
			if(n % i == 0) {
				return false;
			}
		}
		return true;
	}
}


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

int main() {
	string s;
	cin >> s;
	int count = 1;

	for (int i = 0; i < 4; i++) {
		if (s[i] == s[i + 1]) {
			count = 0;
		}
	}

	if (count == 0) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

void solve() {
    char c;
    cin >> c;
    cout << (c >= 'A' && c <= 'Z' ? "A" : "a") << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
        solve();
    return 0;
}



Measured memory_bytes: 3648
import java.util.*;

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

     public void execute() {
         Scanner sc = new Scanner(System.in);
         int a = sc.nextInt();
         int b = sc.nextInt();
         int q = sc.nextInt();

         long[] s = new long[a];
         for (int i = 0; i < a; i++) {
             s[i] = sc.nextLong();
         }
         Arrays.sort(s);

         long[] t = new long[b];
         for (int i = 0; i < b; i++) {
             t[i] = sc.nextLong();
         }
         Arrays.sort(t);

         for (int i = 0; i < q; i++) {
             long x = sc.nextLong();

             long d = Long.MAX_VALUE;

             d = Math.min(d, search(s, t, x));
             d = Math.min(d, search(t, s, x));

             System.out.println(d);
         }
     }

     private long search (long[] s, long[] t, long x) {
         long d = Long.MAX_VALUE;

         D[] xs = dist(s, x);

         D[] s0t = dist(t, xs[0].p);
         d = Math.min(d, xs[0].d + s0t[0].d);

         if (s0t[1] != null) {
             d = Math.min(d, xs[0].d + s0t[1].d);
         }

         if (xs[1] != null) {
             D[] s1t = dist(t, xs[1].p);
             d = Math.min(d, xs[1].d + s1t[0].d);

             if (s1t[1] != null) {
                 d = Math.min(d, xs[1].d + s1t[1].d);
             }
         }
         return d;
     }

     private D[] dist(long[] m, long x) {

         D[] d = new D[2];
         int r = ~(Arrays.binarySearch(m, x));

         if (r == 0) {
             d[0] = new D(Math.abs(x - m[r]), m[r]);
             d[1] = null;
         } else if (r == m.length) {
             d[0] = new D(Math.abs(x - m[r - 1]), m[r - 1]);
             d[1] = null;
         } else {
             d[0] = new D(Math.abs(x - m[r]), m[r]);
             d[1] = new D(Math.abs(x - m[r - 1]), m[r - 1]);
         }

         return d;
     }

     class D {
         long d;
         long p;

         D (long d, long p) {
             this.d = d;
             this.p = p;
         }
     }
 }

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

int main(){
  int N, A, neg = 0, m = 2000000000;
  int64_t S = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> A;
    if (A < 0){
      neg += 1;
    }
    m = min(m, abs(A));
    S += abs(A);
  }
  if (neg % 2 == 1){
    cout << S - 2 * m << endl;
  }
  else{
    cout << S << endl;
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
def tentou(lis):
    res = 0
    for i in range(len(lis)-1):
        for j in range(i+1, len(lis)):
            if lis[i] > lis[j]:
                res += 1
    return res
x = tentou(a)
y = tentou(a+a) - 2*x
print((x*k%mod + y*k*(k-1)//2 %mod)%mod)

Measured memory_bytes: 73664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    FOR(i,1,10){
        if(n%i==0){
            if(n/i<=9){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


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

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
m = []
for i in range(H):
    r = list(input())
    if r == ['.'] * W:continue
    m.append(r)

k = []
for i in range(W):
    if [m[j][i] for j in range(len(m))] == ['.'] * len(m):
        k.append(i)

ans = []    
for r in m:
    t = []
    for i,l in enumerate(r):
        if  not i in k:
            t.append(l)
    ans.append(t)
for l in ans:
    print(''.join(l))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#include <debug.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod=1000000007;
void debug_out() { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
} 
#ifdef LOCAL
#define bug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define bug(...) 42
#endif
double startTime;
double time(){
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
} 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //startTime = (double)clock();
     string n;
     cin>>n;
     startTime = (double)clock();
     if(n[0]=='7'||n[1]=='7'||n[2]=='7'){
     	cout<<"Yes"<<endl;
     }   
     else {
     	cout<<"No"<<endl;
     }
    //cout<<"Time : "<<time()<<endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()




int main() {
	string s;
	cin >> s;
	ll ans = INF;
	rep(i, s.size() - 2) {
		ll tmp = stoi(s.substr(i, 3));
		ans = min(ans, abs(tmp - 753));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    int a,b,t;
    cin >> a >> b >> t;
    cout << (t / a )* b;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){

 unsigned int n,a,b,i,no_of_passed=0,no_overseas=0;
 string s;
 cin>>n>>a>>b;
 cin>>s;

 for(i=0;i<n;i++){
   
   if(s[i]=='c')
    {cout<<"No";}
   else{
	   
	   if(s[i]=='a'){
		   
		   if(no_of_passed<(a+b)){no_of_passed++;cout<<"Yes";}
		   else cout<<"No";
		   }
		   
	   else{
		   if(no_of_passed<(a+b)&&no_overseas+1<=b){
			   no_of_passed++;no_overseas++;cout<<"Yes";
			   }
		   else cout<<"No";
		   }
	   
	   }
	   cout<<'\n';
 }


}


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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

map<string, bool> memo;

bool is_cat(string s) {
	if (memo.count(s)) return memo[s];
	if (!s.size()) return true;
	if (s.size() < 3) return false;
	if (s[0] != 'm' || s.back() != 'w') return false;
	
	int n = s.size();

	for (int i = 1; i < n - 1; i++) {
		if (s[i] != 'e') continue;

		string x = s.substr(1, i - 1);
		string y = s.substr(i + 1, n - (i + 2));
		
//		printf("%s => m + %s + e + %s + w\nm+%s+e+%s+w;\n\n", s.c_str(), x.c_str(), y.c_str(),
//				x.c_str(), y.c_str());

		if (is_cat(x) && is_cat(y)) {
			return memo[s] = true;
		}
	}

	return memo[s] = false;
}

int main(void) {
	string s;
	cin >> s;

	cout << (is_cat(s) ? "Cat" : "Rabbit") << endl;

	return 0;
}

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

using namespace std;

#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i < int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long

int v[100500];
int w[200500];

long long dp[100500];

int32_t main() {
    std::iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, W;
    cin >> n >> W;
    forn (i, n)
        cin >> w[i] >> v[i];

    dp[0] = 0;
    for (int i = 1; i <= W; i++) {
        dp[i] = -1e18;
    }

    forn(i, n)
    for (int j = W; j >= 1; j--)
        if (j >= w[i])
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);

    long long ans = 0;
    forn(i, W + 1)
        ans = max(ans, dp[i]);

    cout << ans;

    return 0;
}

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

using namespace std;

int N, M, K, L;
int parent[200005];
int power[200005];

void initset(int n){
    for (int i=1;i<=n;i++){
        parent[i] = i;
        power[i] = 0;
    }
}

int root (int x ) {
    if ( x == parent [ x ]) return x ;
        return parent[x] = root ( parent [x]) ; //path compression
}
bool is_connected ( int x , int y ) {
    return root ( x ) == root ( y ) ;
}

void connect ( int x , int y ) {
    int root_x = root ( x );
    int root_y = root ( y );
    if (power[root_x] > power[root_y]) parent[root_y] = root_x;
    else {parent[root_x] = root_y; if (power[root_x] == power[root_y]) power[root_y]++;}
}

int main() {
    cin >> N >> M;
    initset(N + M + 5);
    for (int i=0; i<N;i++){
        cin >> K;

        for (int j=0; j<K;++j){
            cin >> L;
            connect(i+1, N+L);
    }
    }
    
    for (int i=1;i<=N;i++){
        if(!is_connected(i,1)){
            cout << "NO\n";
            return 0;
        }        // for (int i=1;i<=N;++i)cout<<root(i)<<' ';cout<<'\n';
    }


    cout << "YES\n";

    return 0;
}

Measured memory_bytes: 1792
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, K = (int(i) for i in input().split())
    h = [0] + [int(i) for i in input().split()]
    memo = [float('inf')] * (N+1)

    memo[1] = 0
    for j in range(2, N+1):
        for i in range(j-K, j):
            if i < 0:
                continue
            memo[j] = min(memo[j], memo[i] + abs(h[j] - h[i]))

    print(memo[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 54092
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int s = sc.nextInt();
        int w = sc.nextInt();


		if(s <= w ){
			// 出力
			System.out.println("unsafe");
		}else{
			System.out.println("safe");
		}
		
	}
}

Measured memory_bytes: 35620
#include <stdio.h>

int main(int argc, char *argv[]){
    int num, len;
    scanf("%d %d", &num,&len);

    int numbers[num];
    int numbers_add[num-len+1];
    int tempsum = 0;
    for(int i = 0; i < num; i++){
        scanf("%d", numbers+i);
        if(i < len-1){
            tempsum+=numbers[i];
        }else if(i == len-1){
            tempsum+=numbers[i];
            numbers_add[i-len+1] = tempsum;
        }else if(i < num){
            tempsum+=numbers[i];
            tempsum-=numbers[i-len];
            numbers_add[i-len+1] = tempsum;
        }
    }
    /*
    int numbers_add[num-len+1];
    for(int i = 0; i < num-len+1; i++){
        numbers_add[i] = 0;
        for(int j = 0; j < len; j++){
            numbers_add[i] += numbers[i+j];
        }
    }
    */
    int max_id = 0;
    for(int i = 0; i < num-len+1; i++){
        if(numbers_add[i] > numbers_add[max_id]){
            max_id = i;
        }
    }

    double ex_val = 0;
    for(int i = max_id; i < max_id+len; i++){
        ex_val += (double)(numbers[i]+1)/2;
    }

    printf("%lf", ex_val);
    return 0;
}

Measured memory_bytes: 1664
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i64,
    }

    let ans = if n < 105 {
        0
    } else if n < 135 {
        1
    } else if n < 165 {
        2
    } else if n < 189 {
        3
    } else if n < 195 {
        4
    } else {
        5
    };

    println!("{}", ans);
}




Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

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,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,X; cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    for (int i=0;i<N;++i){
        cin >> C[i];
        for (int j=0;j<M;++j) cin >> A[i][j];
    }
    int ans=INF;
    for (int mask=0;mask<(1<<N);++mask){
        int cnt=0;
        vector<int> sum(M,0);
        for (int i=0;i<N;++i) if (mask&1<<i){
            cnt+=C[i];
            for (int j=0;j<M;++j) sum[j]+=A[i][j];
        }
        int ok=1;
        for (int i=0;i<M;++i) if (sum[i]<X) ok=0;
        if (ok) chmin(ans,cnt);
    }
    cout << (ans==INF?-1:ans) << '\n';
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int64_t N;
cin >> N;
vector<int64_t> vec(N);
int maxi = -1,maxi2 = -2;
for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
    if (vec.at(i) > maxi) maxi = vec.at(i);
    else if (vec.at(i) <= maxi && vec.at(i) > maxi2) maxi2 = vec.at(i);
}
for (int i = 0;i < N;i++) {
    if (vec.at(i) == maxi) cout << maxi2 << endl;
    else cout << maxi << endl;
}


return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

	static int n;
	static long[][] dp;
	static int[][] matchingArray;

	static final long DIVIDE_NUMBER = 1000000007;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		matchingArray = new int[n][n];

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

			for (int j = 0; j < n; j++) {

				matchingArray[i][j] = scan.nextInt();
			}
		}

		int allPattern = (int) Math.pow(2, n);

		dp = new long[n + 1][allPattern];

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

			for (int j = 0; j < allPattern; j++) {

				dp[i][j] = Long.MAX_VALUE;
			}
		}

		dp[0][0] = 1;

		long answer = dpMethod(n, allPattern - 1);

		println(answer);
	}

	public static long dpMethod(int targetN, int pattern) {

		if (dp[targetN][pattern] != Long.MAX_VALUE) {

			return dp[targetN][pattern];

		} else {

			long result = 0;

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

				if (matchingArray[targetN - 1][i] == 1) {

					if ((pattern >>> i & 1) == 1) {

						result += dpMethod(targetN - 1, pattern ^ 1 << i);
					}
				}
			}

			result = result % DIVIDE_NUMBER;
			dp[targetN][pattern] = result;
			return result;
		}
	}

	public static void println(Object target) {
		System.out.println(target);
	}
}


Measured memory_bytes: 386260
N, A, B = tuple(map(int, input().split()))
S = input()
count = 0
abroad_rank = 1
for c in S:
    if c == "a":
        if count < A + B:
            count += 1
            print("Yes")
        else:
            print("No")
    elif c == "b":
        if count < A + B and abroad_rank <= B:
            count += 1
            abroad_rank += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")


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

int stack[1000];
int top=-1;

void push(int v){
	top++;
	stack[top]=v;
}

int pop(){
	if (top < 0){
		return -1;
	}
	top--;
	return stack[top+1];
}

int main(){
	
	string str;
	while (cin >> str){
		if (str == "+"){
			push(pop()+pop());
		}else if(str == "*"){
			push(pop()*pop());
		}else if(str == "-"){
			int n1=pop();
			int n2=pop();
			push(n2-n1);
		}else{
			push(atoi(str.c_str()));
		}
	}
	cout << pop() << endl;
	return 0;
}




Measured memory_bytes: 3144
n,m = map(int,input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]

for i in range(n-m+1):
	for j in range(n-m+1):
		ans = "Yes"
		for k in range(m):
			sA = A[i+k][j:j+m]
			sB = B[k]
			# print(sA,sB)
			if sA != sB:
				ans = "No"
				break
		if ans == 'Yes':
			break
	if ans == "Yes":
		break
print(ans)

Measured memory_bytes: 3064
import sys
from itertools import combinations_with_replacement

def solve():
    input = sys.stdin.readline
    N, M, Q = map(int, input().split())
    E = [[int(c) for c in input().split()] for _ in range(Q)]
    maxPoint = 0
    for l in combinations_with_replacement(range(1, M + 1), N):
        point = 0
        #print(l)
        for a, b, c, d in E:
            if l[b-1] - l[a-1] == c: point += d
        maxPoint = max(maxPoint, point)
    print(maxPoint)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	}

	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
}


Measured memory_bytes: 35888
n,k=map(int,input().split())
*q,=map(int,input().split())

ans=0
for i in range(1,k+1): # iは抜き取り回数
    if i<n:
        for left in range(0,i+1): # 左からleft個目まで抜き取る
            tmp=0
            tmpq=[]
            right=i-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(k-i, len(tmpq))])
            ans=max(ans,tmp)
    else:
        for left in range(0,n+1):
            tmp=0
            tmpq=[]
            right=n-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(i-n, len(tmpq))])
            ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 74204
/*Rabbi Zidni Ilma*/
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)


int main()
{
	ll n,x,t,ans;
	scanf("%lld %lld %lld",&n,&x,&t);
	ans=t*ceil(n/(double)x);
	printf("%lld\n",ans);
}

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

using namespace std;

int main(){
	int n, z, w;
	cin>>n>>z>>w;
	vector<int> v(n);
	for(int i=0; i<n; i++) cin>>v[i];
	if(n==1) cout<<abs(w-v[0])<<endl;
	else cout<<max(abs(w-v[n-1]), abs(v[n-1]-v[n-2]))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

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

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"

const int N = 2e5;
const int INF = 2e9;

int n, a[N], b[N], c[N], dp[N][5];

int main () {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i = 1; i <= n; ++i) {
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i];
		dp[i][3] = max(dp[i - 1][2], dp[i - 1][1]) + c[i];
    }	
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
	return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
long int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int main()
{
    long int ans=0;
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int k=1; k<=n; k++)
            {
                ans+=gcd(i,gcd(j,k));
            }
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
int main(){
  ll N,K; cin>>N>>K;
  ll time=N-K;
  ll count=0;
  ll c=0;
  rep1(i,time){
    ll b=K+i;
    ll r=N%b;
    ll p=N/b;
    count+=(b-K)*p;
    count+=max(c,r-K+1);
  }
  if(K==0){
    count-=time;
  }
  cout<<count<<endl;
}
      
      
      

Measured memory_bytes: 256
def main():
    N, M, K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    time = 0
    i = 0
    while (time + A[i] <= K):
        time += A[i]
        i += 1
        if i == N:
            break

    i2 = i-1#i2はAの一番下の変数を指すポインタ
    h = 0
    while (time + B[h] <= K):
        time += B[h]
        h += 1
        i += 1
        if h == M:
            break
    max = i
    #iは冊数

    i3 = i#今後比べていくときの合計冊数
    #print(time,i)
    if h == M:
        return max

    for j in range(i2+1):
        if i2 < 0:
            return max
        time -= A[i2]
        i3 -= 1
        while (time + B[h] <= K):
            time += B[h]
            h += 1
            i3 += 1
            if h == M:
                break
        #print(time,i3)

        if i3 > max:
            max = i3

        i2 -= 1
        if h == M:
            return max

    return max

print(main())


Measured memory_bytes: 39996