akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def update(x, y, new_value, dp):
    if 0 <= x < len(dp) and 0 <= y < len(dp):
        dp[x][y] = min(dp[x][y], new_value)

def main():
    n=int(input())
    a=list(map(int, input().split()))
    b = [0] * n
    for i in range(n):
        b[a[i]-1] = i + 1

    print(" ".join(str(i)  for i in b))

main()


Measured memory_bytes: 18756
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        int draws[] = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).map(v -> v == 1 ? v = 14 : v).toArray();
        if(draws[0] > draws[1]) {
            System.out.println("Alice");
            return;
        } else if (draws[0] < draws[1]) {
            System.out.println("Bob");
            return;
        }
        System.out.println("Draw");
    }

    static class InputReader {
        private BufferedReader reader;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String readLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}

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

int main(){
	
    int n; cin >> n;
    for(int i = 1; i <= 9; i++)
        for(int j = 1; j <= 9; j++)
            if(i*j == n){
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No" << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 998244353
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;

#define endl '\n'
#define int ll


int lcm(int a, int b) {
	int g = __gcd(a,b);
	int ans = a/g;
	ans *= b;
	return ans;
}

int a,b,c,d;
int dp[3001][3001];

int solve(int x, int y) {
	if(x<a || y<b) return 0;
	if(x==a && y==b) return 1;

	if(dp[x][y]!=-1) return dp[x][y];

	// if(x==a) {
	// 	int ans = solve(x, y-1)*x;
	// 	ans %= MOD;
	// 	return dp[x][y] = ans;
	// }

	// if(y==b) {
	// 	int ans = solve(x-1, y)*y;
	// 	ans %= MOD;
	// 	return dp[x][y] = ans;
	// }

	int ans = 0;
	ans -= ((x-1)*(y-1))*solve(x-1,y-1);
	ans %= MOD;

	ans += (x)*solve(x,y-1);
	ans %= MOD;

	ans += (y)*solve(x-1,y);
	ans %= MOD;

	return dp[x][y] = ans;
}

signed main() {
	fast;

	cin>>a>>b>>c>>d;

	for(int i=0;i<=3000;i++)
	for(int j=0;j<=3000;j++) dp[i][j] = -1;

	cout<<solve(c,d);

}

Measured memory_bytes: 74132
import java.util.*;
public class Main{

  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      int[] b = new int[n];
      int[] c = new int[n];

      for(int i = 0; i < n; i++) a[i] = sc.nextInt();
      for(int i = 0; i < n; i++) b[i] = sc.nextInt();
      for(int i = 0; i < n; i++) c[i] = sc.nextInt();

      Arrays.sort(a); Arrays.sort(b); Arrays.sort(c);

      long[] conBC = new long[n];
      for(int i = 0, j = 0; i < n && j < n; i++) {
          int numB = b[i];
          while(j < n && c[j] <= numB)
              j++;
          conBC[i] = n - j;
      }

      long[] prefixSum = new long[n];
      prefixSum[n-1] = conBC[n-1];
      for(int i = n - 2; i >= 0; i--) {
          prefixSum[i] = conBC[i] + prefixSum[i+1];
      }
      long cnt = 0;
      for(int i = 0, j = 0; i < n && j < n; i++) {
          int numA = a[i];
          while(j < n && b[j] <= numA)
              j++;
          if(j < n)
            cnt+= prefixSum[j];
      }

      System.out.println(cnt);
  }
}



Measured memory_bytes: 96024
#include <bits/stdc++.h>
#define REP(i, n) for (long i = 0; i < n; ++i)
#define FOR(i, b, n) for (long i = b; i < n; ++i)

using namespace std;

void solve(long N, vector<long> A) {
  long ans(A.front());
  FOR(i, 1, N)
    ans = __gcd(ans, A[i]);
  cout << ans << endl;
}

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

  long N;
  cin >> N;
  vector<long> A(N);
  REP(i, N)
    cin >> A[i];

  solve(N, move(A));

  return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    //初期値は大きい値
    int ans = s.size();
    
    //i は最初に使う色 (0 or 1)
    for (int i = 0; i < 2; i++){
        //iを最初に使ったときに変えなければならないタイルの数
        int cnt = 0;
        
        for (int j = 0; j < s.size(); j++){
            
            //(char)(0 + '0') -> '0';
            //(char)(1 + '0') -> '1';
            if (j % 2 == 0 && s[j] != (char)(i + '0')) cnt++;
            if (j % 2 != 0 && s[j] == (char)(i + '0')) cnt++;
        }
        
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
    
}

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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string s,t;

string pmatch,rmatch;

int zp[600010];
int zr[600010];


void zalgo(string &str,int* z){
	int n=str.size();
	z[0]=n;
	int i=1,j=0;
	while(i<n){
		while(i+j<n&&str[i+j]==str[j]) j++;
		z[i]=j;
		if(j==0){i++;continue;}
		int k=1;
		while(i+k<n&&k+z[k]<j) z[i+k]=z[k],k++;
		i+=k,j-=k;
	}
}


int main(void){
	cin >> s >> t;
	pmatch=t+"$"+s;
	reverse(s.begin(),s.end());
	reverse(t.begin(),t.end());
	rmatch=t+"$"+s;
	zalgo(pmatch,zp);
	zalgo(rmatch,zr);
	int n=s.size(),m=t.size();

	int ans=0;
	const int o=m+1;

	rep(i,n) if(i+m-1<n&&zp[i+o]+zr[n-m-i+o]==m-1) ans++;

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 2019;
const ll INF = 2*1e18;
const int inf = 1e9+7;
//1, 3, 673, 2019
int main(void){
	ll L,R;
	cin >> L >> R;
	ll ans = inf;
	if(R-L <2019){
		for(ll i=L;i<R;i++){
			for(ll j=L+1;j<=R;j++){
				ans = min(ans,(i*j)%mod);
			}
		}
	}else{
		ans = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N,S,T=int(input()),input(),input()
A=[int(S[i]==T[i])for i in range(N) if not i or S[i-1]!=S[i]]
a,d=6-3*A[0],len(A)-1
if d:
 for i in range(d):
  b,c=A[i+1],A[i]
  a*=3+2*c*b-2*b-c
print(a%(10**9+7))

Measured memory_bytes: 3064
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int>a(n+1);
	vector<int>b(n);
	for (int i = 0; i < n + 1; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= b[i]) {
			ans += b[i];
			a[i] -= b[i];
		}
		else {
			ans += a[i];
			int x = b[i] - a[i];
			ans += min(a[i + 1], x);
			a[i + 1] -= min(a[i + 1], x);
		}
	}
	cout << ans;
}

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

const int N = 2e5 + 50;

int head[N], nxt[N], ver[N], deg[N], cnt;
int n, col[N], eu[N], ev[N], val[N], tot;
bool vis[N];

inline void add(int u, int v)
{
	nxt[++cnt] = head[u];
	ver[cnt] = v;
	head[u] = cnt;
}

inline bool judge(int x) { return deg[x] == 1 && col[x]; }

inline void delete_all_black_leaves()
{
	std::queue<int> Q;
	for (int i = 1; i <= n; ++i) if (judge(i)) Q.push(i), vis[i] = true;
	while (Q.empty() == false)
	{
		int x = Q.front(); Q.pop();
		for (int i = head[x]; i; i = nxt[i])
		{
			int y = ver[i];
			if (!vis[y] && --deg[y] == 1 && col[y])
			{
				Q.push(y);
				vis[y] = true;
			}
		}
	}
}

inline void rebuild()
{
	int nn = 0;
	memset(head, 0, sizeof head);
	memset(deg, 0, sizeof deg);
	cnt = 0;
	for (int i = 1; i < n; ++i)
	{
		int u = eu[i], v = ev[i];
		if (!vis[u] and !vis[v])
		{
			add(u, v), add(v, u);
			++deg[u], ++deg[v];
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		if (!vis[i])
		{
			if ((col[i] && (deg[i] & 1)) || (!col[i] && (((deg[i] ^ 1) & 1))))
			{
				val[i] = 2; ++tot;
			}
		}
	}
}

int d[N], td;

void dfs(int x, int fa = -1)
{
	d[x] = val[x];
	for (int i = head[x]; i; i = nxt[i])
	{
		int y = ver[i];
		if (!vis[y] && y != fa)
		{
			dfs(y, x);
			td = std::max(td, d[x] + d[y]);
			d[x] = std::max(d[x], d[y] + val[x]);
		}
	}
}

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0, neg = 1; char ch; 
	do 
	{
		ch = nc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res * neg;
}

inline int read_color()
{
	char ch;
	do ch = nc(); while (ch != 'B' and ch != 'W');
	return ch == 'B';
}

int main()
{
	n = read();
	for (int i = 1; i < n; ++i)
	{
		int u = read(), v = read();
		add(u, v), add(v, u);
		++deg[u], ++deg[v], eu[i] = u, ev[i] = v;
	}
	for (int i = 1; i <= n; ++i) col[i] = read_color();
	delete_all_black_leaves();
	rebuild();
	int trt = 1, ans = 0;
	for (int i = 1; i <= n; ++i) if (!vis[i]) { trt = i; break; }
	dfs(trt);
	printf("%d", cnt + tot - td);
	return 0;
}


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

using namespace std;

char p[3][3][4];
char pz[9][5];

bool check(char a,char b){
    return (a-32 == b || b-32 == a);
}

int rec(int now,int S){
    if(now == 9) return 1;
    int res = 0;
    int X = now%3, Y = now/3;
    for(int s = 0 ; s < 9 ; s++){
        if(S >> s & 1) continue;
        for(int i = 0 ; i < 4 ; i++){
            for(int j = 0 ; j < 4 ; j++){
                p[Y][X][j] = pz[s][(i+j)%4];
            }
            bool can = true;    
            if(X > 0 && !check(p[Y][X][0],p[Y][X-1][2])){
                can = false;
            }
            if(Y > 0 && !check(p[Y][X][1],p[Y-1][X][3])){
                can = false;            
            }
            if(can) res += rec(now+1,S|(1<<s));
            for(int j = 0 ; j < 4 ; j++){
                p[Y][X][j] = '#';
            }
        }
    }
    return res;
}

int main(){
    int Tc;
    cin >> Tc;
    while(Tc--){
        for(int i = 0 ; i < 9 ; i++){
            for(int j = 0 ; j < 4 ; j++){
                cin >> pz[i][j];
            }
        }
        for(int i = 0 ; i < 3 ; i++){
            for(int j = 0 ; j < 3 ; j++){
                for(int k = 0 ; k < 4 ; k++){
                    p[i][j][k] = '#';
                }
            }
        }
        cout << rec(0,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>

#include <vector>
#include <queue>
#include <tuple>
int v, e;

struct Edge {
  Edge() {}
  Edge(int from, int to, int capacity, int cost, int rev) : from(from), to(to), capacity(capacity), cost(cost), rev(rev) {}
  int from, to;
  int capacity;
  int cost;
  int rev;
};

std::vector<Edge> edges[128];

void addEdge(int from, int to, int capacity, int cost) {
  int n1 = edges[from].size();
  int n2 = edges[to].size();
  edges[from].push_back(Edge(from, to, capacity, cost, n2));
  edges[to].push_back(Edge(to, from, 0, -cost, n1));
}                      

struct Result {
  Result() {}
  Result(int cost, int f) : cost(cost), f(f) {}
  int cost;
  int f;
};

struct NodeInfo {
  NodeInfo() {}
  NodeInfo(int w, int max_f, int prev, int prev_id) : w(w), max_f(max_f), prev(prev), prev_id(prev_id) {}
  int w, max_f, prev, prev_id;
};
NodeInfo nodes[128];
void init_flow() {
  for(int i = 0; i < 128; ++i) {
    nodes[i] = NodeInfo((1<<30), 0, -1, -1);
  }
}

Result flow(int from, int to, int rem) {
  std::priority_queue< std::pair<int, int> > q;
  q.push(std::make_pair(0, from));
  nodes[from].w = 0;
  nodes[from].max_f = rem;
  while( not q.empty() ) {
    int n, weight;
    std::tie(weight, n) = q.top(); q.pop();
    // printf("(n) = (%d)\n", n);
    weight = -weight;
    for(int i = 0; i < (int)edges[n].size(); ++i) {
      Edge edge = edges[n][i];
      if( edge.capacity <= 0 ) continue;
      int nw = weight + edge.cost;
      if( nodes[edge.to].w <= nw ) continue;
      nodes[edge.to] = NodeInfo(nw, std::min(nodes[edge.from].max_f, edge.capacity), n, i);
      q.push(std::make_pair(-nw, edge.to));
    }
  }
  // for(int i = 0; i < v; ++i) {
  //   printf("node info[%d] : (w, max_f, prev, prev_id) = (%d, %d, %d, %d)\n", i, w[i], max_f[i], prev[i], prev_id[i]);
  // }
  int f = nodes[to].max_f;
  if( f == 0 ) return Result(0, 0);
  int m = to;
  int cost = 0;
  while( nodes[m].prev != -1 ) {
    Edge& edge = edges[nodes[m].prev][nodes[m].prev_id];
    edge.capacity -= f;
    edges[m][edge.rev].capacity += f;
    cost += f * edge.cost;
    m = nodes[m].prev;
  }
  return Result(cost, f);
}

int minimum_cost_flow(int from, int to, int rem) {
  int cost = 0;
  for(;;) {
    init_flow();
    Result r = flow(from, to, rem);
    rem  -= r.f;
    cost += r.cost;
    if( rem == 0 ) return cost;
    if( r.f == 0 ) break;
    // printf("(rem, flow rate) = (%d, %d)\n", rem, r.f);
  }
  return -1;
}

int main() {
  int f;
  scanf("%d %d %d", &v, &e, &f);
  for(int i = 0; i < e; ++i) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    addEdge(a, b, c, d);
  }

  printf("%d\n", minimum_cost_flow(0, v - 1, f));
  
  return 0;
}

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


int main(){
	int a, b, c, x, y;
    int p, q, r, r1, r2, s;

    cin >> a >> b >> c >> x >> y;

    p = min(x, y);
    q = max(x, y);
    r = a * x + b * y;
    r1 = c * p * 2 + a * (x - p) + b * (y - p);
    r2 = c * q * 2;

    s = min(r, r1);
    s = min(s, r2);

    cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int A,B,C;
    //char input[LENGTH];
    //fgets(input, LENGTH - 1, stdin);
    scanf("%d" , &A);
    scanf("%d" , &B);
    scanf("%d" , &C);
    //fgets(input, LENGTH - 1, stdin);
    //B = sscanf(input, "%d",  &B);
    //fgets(input, LENGTH - 1, stdin);
    //C = sscanf(input, "%d",  &C);
    if(A <= C){
      if(C <= B){
        printf("Yes");
        return 0;
      }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 1732
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>

int main() {
	int d[101][101] = { 0 };
	int c, r, i, j;
	scanf("%d%d", &c, &r);
	for (i = 0; i < c; i++) {
		for (j = 0; j < r; j++) {
			scanf("%d", &d[i][j]);
			d[i][r] += d[i][j];
			d[c][j] += d[i][j];
		}
		d[c][r] += d[i][r];
	}
	for (i = 0; i < c + 1; i++)
		for (j = 0; j < r + 1; j++)
			printf("%d%c", d[i][j],j<r?' ':'\n');
	return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	vector<int> V;
	int tmp;

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

		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	sort(V.rbegin(),V.rend());

	int ans = 0;
	for(int i = 0; i < K; i++){

		ans += V[i];
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3800
N = int(input())
A = [int(a) for a in input().split(" ")]

sA = []
for i in range(len(A)):
  if i == 0:
    sA.append(A[0])
  else:
    sA.append(sA[i - 1] + A[i])

s = sum(A)
dA = [abs(2 * sA[j] - s) for j in range(len(sA) - 1)]

print(min(dA))

Measured memory_bytes: 37220
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

void func(int N){

	int table[26],second,maximum,max_index;

	for(int i = 0; i < 26; i++)table[i] = 0;

	bool FLG = false;
	char buf[2];

	for(int i = 1; i <= N; i++){
		scanf("%s",buf);
		if(FLG)continue;

		table[buf[0] - 'A']++;

		maximum = 0,second = 0;
		for(int k = 0; k < 26; k++){
			if(table[k] > maximum){
				second = maximum;
				maximum = table[k];
				max_index = k;
			}else if(table[k] > second){
				second = table[k];
			}
		}

		if(maximum > second+N-i){
			printf("%c %d\n",'A'+max_index,i);
			FLG = true;
		}
	}

	if(!FLG)printf("TIE\n");

}

int main(){

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func(N);
	}

    return 0;
}

Measured memory_bytes: 2768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int a[N- 1], b[N - 1];
    vector<int> adj[N];
    int d[N]{};
    for (int i = 0; i < N - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        d[a[i]]++;
        d[b[i]]++;
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
    int l = 0;
    for (int i : d) {
        l = max(l, i);
    }
    int c[N];
    fill(c, c + N, -1);
    deque<int> q;
    q.push_back(0);
    int vis[N]{};
    vis[0] = 1;
    map<int, int> m[N];
    set<int> s[N];
    map<string, int> t;
    while (!q.empty()) {
        int u = q.front();
        q.pop_front();
        int k = 1;
        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j];
            if (m[u].count(v) == 0 && m[v].count(u) == 0) {
                while (s[u].count(k) != 0 || s[v].count(k) != 0) {
                    k++;
                }
                m[u][v] = k;
                m[v][u] = k;
                s[u].insert(k);
                s[v].insert(k);
            }
            if (vis[v] == 0) {
                vis[v] = 1;
                q.push_back(v);
            }
        }
    }
    cout << l << "\n";
    for (int i = 0; i < N - 1; i++) {
        cout << m[a[i]][b[i]] << "\n";
    }
    return 0;
}

Measured memory_bytes: 36096
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define int long long
#define MOD 1000000007
#define PI 2*acos(0)
#define forn(i,n) for(int i = 0; i < n; i++)
using namespace std;
int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n, a; cin >> n;
	map<int, int> c;
	vector<int> v;
	forn(i, n) {
		cin >> a;
		c[a]++;
		if (c[a] == 2)v.pb(a);
	}
	sort(allr(v));
	if (v.size() && c[v[0]] >= 4)
		cout << v[0] * v[0] << '\n';
	else if (v.size() > 1)
		cout << v[0] * v[1] << '\n';
	else
		cout << "0\n";	
	return 0;
}


Measured memory_bytes: 6528
import itertools
dis = [int(input()) for _ in range(5)]
k = int(input())

comb_dis = list(itertools.combinations(dis, 2))
#print(comb_dis)
for i in range(5):
    if abs(comb_dis[i][1] - comb_dis[i][0]) > k:
        print(":(")
        exit()


print("Yay!")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 1000000007;

vector<string> string_list;
ll maze[20][20];
ll h, w;

void init() {
  for (ll i = 0; i < h; i++) {
    string s = string_list[i];
    for (ll j = 0; j < s.size(); j++) {
      maze[j][i] = (s[j] == '#') ? -1 : MAX;
    }
  }
}

ll run(pair<ll, ll> start) {
  if (maze[start.first][start.second] == -1) {
    return -1;
  }
  stack<pair<ll, ll>> s;

  maze[start.first][start.second] = 0;
  s.push(start);

  for (;;) {
    if (s.size() == 0) {
      break;
    }
    auto cur = s.top();
    s.pop();
    ll x = cur.first;
    ll y = cur.second;

    ll next = maze[x][y] + 1;
    // cout << next << endl;

    if (x >= 1) {
      if (maze[x - 1][y] != -1 && maze[x - 1][y] > next) {
        maze[x - 1][y] = next;
        s.push(make_pair(x - 1, y));
      }
    }
    if (x < w - 1) {
      if (maze[x + 1][y] != -1 && maze[x + 1][y] > next) {
        maze[x + 1][y] = next;
        s.push(make_pair(x + 1, y));
      }
    }

    if (y >= 1) {
      if (maze[x][y - 1] != -1 && maze[x][y - 1] > next) {
        maze[x][y - 1] = next;
        s.push(make_pair(x, y - 1));
      }
    }
    if (y < h - 1) {
      if (maze[x][y + 1] != -1 && maze[x][y + 1] > next) {
        maze[x][y + 1] = next;
        s.push(make_pair(x, y + 1));
      }
    }
  }

  ll result = 0;

  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      result = max(result, maze[j][i]);
    }
  }
  return result;
}

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

  for (ll i = 0; i < h; i++) {
    string s;
    cin >> s;
    string_list.emplace_back(s);
  }

  ll ans = 0;
  for (ll i = 0; i < w; i++) {
    for (ll j = 0; j < h; j++) {
      init();
      auto start = make_pair(i, j);
      ll a = run(start);
      if (a == MAX) {
        continue;
      }
      ans = max(ans, a);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int a[n];
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    for(int i=n;i>1;i--){
        cout<< a[i-1]<< " ";
    }
    cout <<a[0]<<endl;
    return 0;
}



Measured memory_bytes: 3084
#include "bits/stdc++.h"
using namespace std;
typedef pair<long long, long long> P;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int main() {
	long long A;
	string B; cin >> A >> B;
	long long C = 100 * (B.at(0) - '0') + 10 * (B.at(2) - '0') + (B.at(3) - '0');
	cout << A * C / 100 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main()
{
    ll n;
    string s;
    cin>>n>>s;
    ll ans=n;
    rep(n-1){
        if(s[i]==s[i+1]){
            ans--;
        }
    }
    cout<<ans;
}

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

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

  if((s.find("N")!=-1)==(s.find("S")!=-1)){
    if((s.find("W")!=-1)==(s.find("E")!=-1))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n = int(input())
monster = list(map(int, input().split()))
yusya = list(map(int, input().split()))
prev = 0
res = 0
for i in range(n):
  if yusya[i] <= monster[i]:
    res += yusya[i]
    continue
  else:
    res += monster[i]
    yusya[i] -= monster[i]
    if yusya[i] <= monster[i+1]:
      monster[i+1] -= yusya[i]
      res += yusya[i]
    else:
      res += monster[i+1]
      monster[i+1] = 0
print(res)

Measured memory_bytes: 19156
#include<stdio.h>
int n,i;
double tot,p;
char s[4];
int main(){
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%lf%s",&p,s);
		if(s[0]=='J'){
			tot+=p;
			continue;
		}
		tot+=p*380000;
	}
	printf("%lf",tot);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

struct road{
  int from;
  int to;
  int distance;
};

int calc_longest(int, int, int, int*, struct road*, int);
void calc_shortestDistance(int, int, int, int*, struct road*, int, int*);

int main(void)
{
  int N, M, K;
  struct road roads[100000];
  int mall[3001];
  int max_distance;
  int longest_d;
  int i;

  scanf("%d %d %d", &N, &M, &K);
  max_distance=0;
  for(i=0; i<M; i++){
    scanf("%d %d %d", &roads[i].from, &roads[i].to, &roads[i].distance);
    if(max_distance<roads[i].distance) max_distance=roads[i].distance;
  }
  for(i=0; i<K; i++){
    scanf("%d", &mall[i]);
  }
  
  longest_d=calc_longest(N, M, K, mall, roads, max_distance);
  printf("%d\n", longest_d);

  return 0;
}

int calc_longest(int N, int M, int K, int* mall, struct road* roads, int max_distance)
{
  int i;
  float longest_d, tmp_d;
  int longest_int;
  int d[3001];

  for(i=1; i<=N; i++) d[i]=max_distance*(M+1);
  calc_shortestDistance(N, M, K, mall, roads, max_distance, d);

  longest_d=0.0f;
  for(i=0; i<M; i++){
    tmp_d=(float)(d[roads[i].from]+d[roads[i].to]+roads[i].distance);
    tmp_d/=2.0f;
    if(longest_d<tmp_d) longest_d=tmp_d;
  }

  longest_int=longest_d+0.5f;
  return longest_int;
}

void calc_shortestDistance(int city_size, int n, int mall_size, int* mall, struct road* roads, int max_distance, int* d)
{
  int is_searched[3001]; //0:is not searched, 1:is searched.
  int min_d, min_city;
  int i;

  for(i=1; i<=city_size; i++) is_searched[i]=0;
  for(i=1; i<=city_size; i++) d[i]=max_distance*n+1;
  for(i=0; i<mall_size; i++) d[mall[i]]=0;

  while(1){
    min_d=max_distance*n+1;
    for(i=1; i<=city_size; i++){
      if(!is_searched[i] && d[i]<min_d){
	min_d=d[i];
	min_city=i;
      }
    }
    if(min_d==max_distance*n+1) break;

    for(i=0; i<n; i++){
      if(roads[i].from==min_city){
	if(d[roads[i].to]>min_d+roads[i].distance) d[roads[i].to]=min_d+roads[i].distance;
      }
      else if(roads[i].to==min_city){
	if(d[roads[i].from]>min_d+roads[i].distance) d[roads[i].from]=min_d+roads[i].distance;
      }
    }
    is_searched[min_city]=1;
  }

  return;
}

Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    cin>>n;
    int w[n+10];
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>w[i];
        sum+=w[i];
    }
    ll sum2=w[0];
    ll mn=sum-w[0];
    for(int j=1;j<n-1;j++)
    {
       sum2+=w[j];
       int num=abs(sum2-(sum-sum2));
        if(num<mn)
            mn=num;
    }
    cout<<mn<<endl;
    return 0;
}


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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

ll dp[1000 * 100 + 4][104];
const ll inf = 1e13;
ll we[104];
ll v[104];

ll solve(ll val, int elem){
    if (val == 0) return 0;
    if (val < 0) return inf;
    ll &ans = dp[val][elem];
    if (ans != -1) return ans;
    ll take = inf;
    ll not_to_take = inf;
    if (elem>=0) take = min(we[elem] + solve(val-v[elem], elem-1), take);
    if (elem>=0) not_to_take = min(solve(val, elem-1), not_to_take);
    return ans = min(take, not_to_take);
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    ll w;
    cin>>n>>w;
    for (int i=0; i<n; i++) cin>>we[i]>>v[i];
    memset(dp, -1, sizeof dp);
    for (ll val = (ll)1000 * (ll)100; val>=0; val--){
        if (solve(val, n) <= w){
            cout<<val<<'\n';
            return 0;
        }
    }
}
/*
NARCO
*/


Measured memory_bytes: 84916
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  for(int i=b*10;i<b*10+10;i++)
  {
      if((i*8)/100==a)
      {
          cout<<i;
          return 0;
      }
  }
  cout<<-1;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        for (int i = x ; i <= 100009 ; i++) {
            if(isPrime(i)) {
                System.out.println(i);
                return;
            }
        }
    }

    static boolean isPrime(int n) {
        for (int i = 2 ; i <= Math.sqrt(n) ; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#define int long long
using namespace std;
main()
{
    //fast
    int tc=1,i,j,k;
//    cin>>tc;
    while(tc--)
    {
       int a,l;
       cin>>a>>l;
       int s=0;
       int aa[a];
       for(i=0;i<a;i++)
       {
           cin>>aa[i];
       }
       int in=-1,ok=1;
       vector<int>ind;
       for(i=0;i+1<a;i++)
       {
           if(aa[i]+aa[i+1]>=l)
            {
                in=i;
                break;
            }
       }
       if(in==-1)
        ok=0;
       for(j=a-1;j-1>in;j--)
        ind.push_back(j);
       for(i=0;i<=in;i++)
        ind.push_back(i+1);
        if(ok)
        {
            cout<<"Possible"<<endl;
            for(auto it : ind)
                cout<<it<<" ";
            cout<<endl;
        }
        else cout<<"Impossible"<<endl;



    }
}




Measured memory_bytes: 5100
import math.Ordering.Double.IeeeOrdering
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val ABs = Array.fill(N)((in.nextDouble, in.nextDouble))
  val As = ABs.map(_._1).sorted
  val Bs = ABs.map(_._2).sorted
  val size = ABs.size
  val odd = size % 2 == 1

  def median(ar: Array[Double]): Double =
    if (odd) ar(size / 2)
    else (ar((size - 1) / 2) + ar(size / 2)) / 2

  println(((median(Bs) - median(As)) * (if (odd) 1 else 2)).toInt + 1)
}

Measured memory_bytes: 83112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

int main(){
  int n;
  cin>>n;
  int cnt[n];
  rep(i,0,n) cnt[i]=0;
  rep(i,0,n){
    int a;
    cin>>a;
    cnt[a]++;
  }
  if(n%2==0){
    bool p=true;
    rep(i,0,n){
      if(i%2==0){
        if(cnt[i]!=0) p=false;
      }
      else{
        if(cnt[i]!=2) p=false;
      }
    }
    if(p) cout<<power(2,n/2)<<endl;
    else cout<<0<<endl;
  }
  else{
    bool p=true;
    rep(i,0,n){
      if(i==0){
        if(cnt[i]!=1) p=false;
      }
      else{
        if(i%2==0){
          if(cnt[i]!=2) p=false;
        }
        else{
          if(cnt[i]!=0) p=false;
        }
      }
    }
    if(p) cout<<power(2,n/2)<<endl;
    else cout<<0<<endl;
  }
}

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


void solve(long long N, long long Y){
  for(long long i = 0; i <= N; i++){
    for(long long j = 0; j <= N-i; j++){
      if(((i*10000) + (j*5000) + ((N-(i+j))*1000)) == Y) {
        cout << i << " " << j << " " << N-(i+j) << endl;
        return;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long Y;
  scanf("%lld",&Y);
    solve(N, Y);
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val % MOD : val % MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

void solve() {
    int N;
    cin >> N;

    vector<mint> S(N + 1);
    for (int i = 1; i <= N; ++i) {
        S[i] = S[i - 1] + mint(i).inverse();
    }
    
    mint ans;
    rep(i, N) {
        int a;
        cin >> a;
        ans += (S[i + 1] + S[N - i] - 1)*a;
    }
    rep(i, N)ans *= (i + 1);
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

m = sum(a) // 2
s = sum(a)
temp = 0
for x in a:
    temp += x
    if temp > m:
        H = temp
        L = temp - x
        break

print(min(H * 2 - s, s - L * 2))

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

int main() {
	string S;
	cin >> S;
	if (S == "RRR"){
		cout << 3 << endl;
	}else if (S == "RRS" || S == "SRR"){
		cout << 2 << endl;
	}else if (S == "RSR" || S == "RSS" || S == "SRS" || S == "SSR"){
		cout << 1 << endl;
	}else {
		cout << 0 << endl;
	}
	return 0;
}

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

#define int long long

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

int M;

signed main() {
    cin >> M;
    cout << 48 - M << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=1LL<<60;
ll S1,S2,a[200005];
ll ABS(ll v){
	return v<0?-v:v;
}
int main(){
	int n;
	scanf("%d",&n);
	rep(k,n)scanf("%lld",&a[k]);
	rep(k,n)S2+=a[k];
	ll ans=INF;
	rep(k,n){
		S1+=a[k];
		S2-=a[k];
		if(k!=n-1)ans=min(ans,ABS(S1-S2));
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int N;

void dfs(string s,char mx){
  if(s.length() == N){
    cout << s << endl;
  }else{
    for(char c='a';c<=mx;c++){
      dfs(s+c,((c == mx) ? (char)(mx+1):mx));
    }
  }
}

int main(){
  cin >> N;
  dfs("",'a');
  return 0;
}


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

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int a,b,c;

	cin>>a>>b>>c;
	
	if(a % b == 0){
		cout<<a/b*c<<endl;
	}else{
		cout<<(a/b+1)*c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3520
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011
#define mod 1000000007
#define inf (1LL << 61)

int n, i;
ll A, B;
ll v[maxN];

int cntA[maxN], cntB[maxN];
int posA, posB;

ll dpA[maxN], dpB[maxN];
ll sumA[maxN], sumB[maxN];

void moddo(ll &a) {
    while (a < 0) a += mod;
    while (a >= mod) a -= mod;
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d%lld%lld", &n, &A, &B);
    for (i = 1; i <= n; i++) scanf("%lld", &v[i]);

    v[0] = -inf;
    v[n + 1] = inf;

    for (i = 1; i <= n + 1; i++) {
        cntA[i] = cntB[i] = 0;

        if (v[i] - v[i - 1] >= A)
            cntA[i] = cntA[i - 1] + 1;

        if (v[i] - v[i - 1] >= B)
            cntB[i] = cntB[i - 1] + 1;
    }

    posA = posB = 0;
    dpA[0] = dpB[0] = sumA[0] = sumB[0] = 1;

    for (i = 1; i <= n; i++) {
        while (posA + 1 <= i - 1 && v[posA +1] + A <= v[i + 1]) posA++;
        while (posB + 1 <= i - 1 && v[posB +1] + B <= v[i + 1]) posB++;

        int l = max(0, i - cntA[i] - 1);
        int r = posB;

        if (l <= r) dpA[i] = sumB[r] - (l > 0 ? sumB[l - 1] : 0);
        sumA[i] = sumA[i - 1] + dpA[i];

        l = max(0, i - cntB[i] - 1);
        r = posA;

        if (l <= r) dpB[i] = sumA[r] - (l > 0 ? sumA[l - 1] : 0);
        sumB[i] = sumB[i - 1] + dpB[i];

        moddo(dpA[i]);
        moddo(dpB[i]);
        moddo(sumA[i]);
        moddo(sumB[i]);
    }

    ll ans = dpA[n] + dpB[n];
    moddo(ans);

    printf("%lld", ans);


    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(abs(a-c)<=d)cout<<"Yes"<<endl;
    else if(abs(b-a)<=d&&abs(c-b)<=d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)
     cout<<c;
    else if(b==c)
     cout<<a;
    else if(a==c)
     cout<<b;
   
    return 0;
}
     
   

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

int main(){
    int n,ans=0;cin>>n;vector<int> A={105,135,165,189,195};
    for(int i=0;i<5;i++){
        if(A.at(i)<=n){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct edge{int to,p;};

const int N = 100010;
vector<edge> G[N];

int col[N];
void dfs(int x, int par){
    for(const auto &e:G[x])if(e.to!=par){
        col[e.to] = (col[x]+e.p)%2;
        dfs(e.to,x);
    }
}

int main(){
    int n;
    scanf(" %d", &n);
    rep(i,n-1){
        int u,v,w;
        scanf(" %d %d %d", &u, &v, &w);
        --u;
        --v;
        w %= 2;
        G[u].pb({v,w});
        G[v].pb({u,w});
    }

    col[0] = 0;
    dfs(0,-1);
    rep(i,n) printf("%d\n", col[i]);
    return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int n;
int c;
struct T{
    int s;
    int t;
    int c;
};
T p[100006];
int cr[35], cn[36];

int solve(int x)
{
    memset(cr, 0, sizeof(cr));
    memset(cn, 0, sizeof(cn));

    for (int i=1; i<=n; i++) {
        int j, cm = -1, cj = -1;
        for (j=0; j<x;j++) {
            if (cr[j] <= p[i].s && (p[i].c == cn[j] || cn[j] == 0)) {
                if (cm == -1 || cm > p[i].s - cr[j]) {
                    cj = j;
                    cm = p[i].s - cr[j];
                }
            }
        }
        if (cm != -1) {
            cr[cj] = p[i].t;
            cn[cj] = p[i].c;
            continue;
        }

        cm = -1, cj = -1;
        for (int j=0; j<x;j++) {
            if (cr[j] <= p[i].s-1) {
                if (cm == -1 || cm > p[i].s - cr[j]) {
                    cj = j;
                    cm = p[i].s - cr[j];
                }
            }
        }
        if (cm != -1) {
            cr[cj] = p[i].t;
            cn[cj] = p[i].c;
        } else {
            return 0;
        }
    }
    return 1;
}

bool cmp(T pa, T pb) {
    if (pa.s == pb.s) {
        return pa.t < pb.t;
    }
    return pa.s < pb.s;
}

int main(){
    scanf("%d%d", &n, &c);
    for (int i=1; i<=n; i++){
        scanf("%d%d%d", &p[i].s, &p[i].t, &p[i].c);
    }
    sort(p+1, p+n+1, cmp);
    for (int i=1; i<=c; i++){
        if (solve(i) == 1) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 1408
N = int(input())
As = list(map(int, input().split()))
mod = (10 ** 9) + 7
mod2 = 2 * mod

sum1 = sum(As) % mod2
squared1 = (sum1 ** 2) % mod2

squared2 = 0

for i in range(N):
    squared2 += (As[i] ** 2) % mod2

print(int((squared1 - squared2) / 2) % mod)

Measured memory_bytes: 31384
while True:
    n, p = map(int, input().split())
    if n == p == 0:
        quit()
    have = [0 for i in range(n)]
    pool = p
    flag = True
    while flag:
        for i in range(n):
            if pool > 0:
                have[i] += 1
                pool -= 1
                if pool == 0 and max(have) == p:
                    print(i)
                    flag = False
            else:
                pool = have[i]
                have[i] = 0


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

// ?£???????????????????????????±?????????????????§?????????+2, ?£????+0 ??????????°?????????????
// ??¬??\???????????????????????§???????????????
// ?£????+0??????????????¨??§????´???????????????°?????????????????????????????§????????????

int main() {
    long long N,P,Q; cin >> N >> P >> Q;
    vector<long long> cs;

    for (int i=0; i<N; ++i) {
        long long c; cin >> c;
        cs.push_back(c + P*i); // ?£??????????P*(k-1)????¶?????????????, k??\????????????,?£???????????????§???P*(k-1)????????????
    }

    sort(cs.rbegin(), cs.rend());

    long long ans = P*Q*N + P*N*(N-1); // ??¨??¨??????
    long long dining_sum = 0;
    for (int i=1; i<=N; ++i) { // i????£?????????????????????¨???
        long long self_catering = P*Q*(N-i) + P*(N-i)*(N-i-1);
        dining_sum += cs[i - 1];
        ans = max(ans, self_catering + dining_sum);
    }

    // ?????´
    for (int i=0; i<N; ++i) ans -= P*i;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7036
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    vi s(3);cin>>s[0]>>s[1]>>s[2];
    sort(ALL(s));
    if(s[0]==5 && s[1]==5 && s[2]==7){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(){
    int s1,h,m,s2;
    scanf("%d",&s1);
    h=s1/3600;
    m=(s1-h*3600)/60;
    s2=s1-h*3600-m*60;
    printf("%d:%d:%d\n",h,m,s2);
    return 0;
}


Measured memory_bytes: 2132
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        self.parent = [i for i in range(n + 1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n + 1)
        # 木の要素数
        self.size = [1] * (n + 1)

        self.score = n * (n - 1) // 2

    # 検索
    def find(self, x):
        if self.parent[x] == x:  # 根ならその番号を返す
            return x
        else:  # 走査していく過程で親を書き換える
            self.parent[x] = self.find(self.parent[x])

            return self.parent[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        parent_x = self.find(x)
        parent_y = self.find(y)

        if(parent_x != parent_y):
            if self.rank[parent_x] == self.rank[parent_y]: 
                # 木の高さが同じなら片方を1増やす
                self.rank[parent_x] += 1  # ここのxとyはどちらでも良い
            elif self.rank[parent_x] < self.rank[parent_y]:  
                # 木の高さを比較し、低いほうから高いほうに辺を張る
                parent_x, parent_y = parent_y, parent_x

            self.score -= self.size[parent_x] * self.size[parent_y]
            self.parent[parent_y] = parent_x
            self.size[parent_x] += self.size[parent_y]

    def getsize(self, x):
        return self.size[self.find(x)]

    def same_check(self, x, y):  # 同じ集合に属するか判定
        return self.find(x) == self.find(y)


def main():
    N, M = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for i in range(M)]

    uni = UnionFind(N)

    score_list = []
    for i in range(M-1, -1, -1):
        inp = AB[i]
        score_list.append(uni.score)
        uni.union(inp[0], inp[1])

    print(*score_list[::-1], sep="\n")

if __name__ == "__main__":
    main()


Measured memory_bytes: 30316