akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int A = nextInt();
		int B = nextInt();
		int M = nextInt();
		int[] a = nextInts();
		int[] b = nextInts();
		int[][] x = new int[M][];
		for(int i=0;i<M;i++){
			x[i]=nextInts();
		}


		long ansA = Long.MAX_VALUE;
		for(int i=0;i<a.length;i++){
			ansA=Math.min(ansA, a[i]);
		}
		long ansB = Long.MAX_VALUE;
		for(int i=0;i<b.length;i++){
			ansB=Math.min(ansB, b[i]);
		}
		long ans = ansA+ansB;


		for(int i=0;i<x.length;i++){
			ans = Math.min(ans, a[x[i][0]-1]+b[x[i][1]-1]-x[i][2]);
		}

		System.out.println(ans);
	}

	public static boolean isExpN(long a,int base){
		int x=1;
		while((int)Math.pow(x, 2) <= a){
			if((int)Math.pow(x, 2) == a){
				return true;
			}
			x*=base;
		}
		return false;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 68236
#include <iostream>
#include <cstdint>
#include <algorithm>

int main() {
  std::int_fast32_t w, h, n;
  std::cin >> w >> h >> n;

  std::int_fast32_t left = 0;
  std::int_fast32_t right = w;
  std::int_fast32_t bottom = 0;
  std::int_fast32_t top = h;
  for (std::int_fast32_t i = 0; i < n; ++i) {
    std::int_fast32_t x, y, a;
    std::cin >> x >> y >> a;
    switch (a) {
    case 1:
      left = std::max(left, x);
      break;
    case 2:
      right = std::min(x, right);
      break;
    case 3:
      bottom = std::max(bottom, y);
      break;
    case 4:
      top = std::min(y, top);
      break;
    }
  }

  std::cout << std::max<std::int_fast32_t>(right - left, 0) * std::max<std::int_fast32_t>(top - bottom, 0) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
	
	string a;
	vector <int> s;
	long long cnt,tmp=0;
	cin>>a;
	long long r=a.size()*(a.size()-1)/2+1;
	for(int i=0;i<a.size();i++) s.push_back(a[i]-'a');
	for(int i=0;i<26;i++){
		cnt=0;
		for(int j=0;j<s.size();j++){
			if(s[j]==i){
				tmp+=cnt;
				cnt++;
			}
		}
	}
	cout<<r-tmp<<endl;
	
	return 0;
	
}

Measured memory_bytes: 1532
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int m;
    cin>>m;
    cout<<24-m+24<<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

  static class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      char c = in.nextChar();
      out.printLine(MiscUtils.isStrictVowel(c) ? "vowel" : "consonant");
    }

  }

  static class MiscUtils {
    private MiscUtils() {
    }

    public static boolean isStrictVowel(char ch) {
      ch = Character.toUpperCase(ch);
      return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';
    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }

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

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

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public char nextChar() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      return (char) c;
    }

    public interface SpaceCharFilter {
      boolean isSpaceChar(int ch);

    }

  }
}



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

vector<ll> idx={1,0,-1,0};
vector<ll> idy={0,1,0,-1};

int main() {
  ll h,w;
  cin >> h >> w;
  vector<string> maze(h);
  for(ll i=0;i<h;i++) {
    cin >> maze[i];
  }
  vector<vector<ll>> ans(h,vector<ll>(w,-1));
  ans[0][0]=1;
  queue<pll> q;
  q.push(pll(0,0));
  while(q.size()) {
    auto p=q.front();
    ll y=p.first;
    ll x=p.second;
    q.pop();
    for(ll i=0;i<4;i++) {
      ll nx=x+idx[i];
      ll ny=y+idy[i];
      if(nx>-1&&nx<w&&ny>-1&&ny<h) {
        if(ans[ny][nx]<0&&maze[ny][nx]=='.') {
          q.push(pll(ny,nx));
          ans[ny][nx]=ans[y][x]+1;
        }
      }
    }
  }
  ll count=0;
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      if(maze[i][j]=='#') {
        count++;
      }
    }
  }
  if(ans[h-1][w-1]<0) {
    cout << -1 << endl;
  }
  else {
    cout << h*w-count-ans[h-1][w-1] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    vector<int> l;
    rrep(i,max(a,b)){
        if (a%i==0 && b%i==0) l.push_back(i);
    }
    sort(ALL(l));
    cout<<l[l.size()-k]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define eps 5e-8
#define IT set<node>::iterator 
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=1e5+5;
struct edge{
	int next,to;
}e[N*4];
int n,m,cnt,head[N];
bool vis[N];
void add(int u,int v){
	cnt++;	e[cnt].to=v;	e[cnt].next=head[u];	head[u]=cnt;
}
void dfs(int u){
	vis[u]=true;
	for(int i=head[u];i;i=e[i].next){
		int j=e[i].to;
		if(!vis[j])	dfs(j);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);	add(v,u);
	}
	int res=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			res++;
			dfs(i);
		}
	}
	printf("%d\n",res-1);
    return 0;
}

Measured memory_bytes: 6660
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toLong)
    val divBase = 1000000000L + 7L

    var power: Long = 1

    (1L to datN).foreach { a =>
      power = (power * a) % divBase
    }

    val ans = power
    println(power)
  }
}


Measured memory_bytes: 29764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ll mini = INFLONG;
  ll ans = 0;
  rep(i,n){
    if(i == 0){
      chmin(mini,vec[i]);
      ans++;
    }else{
      if(vec[i] <= mini){
        ans++;
      }
      chmin(mini,vec[i]);
    }
  }
  cout << ans << endl;
}

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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int X;
    cin >> X;
    int total = 0;
    int res = 0;

    for (int a = 0; a <= A; a++)
    {
        for (int b = 0; b <= B; b++)
        {
            for (int c = 0; c <= C; c++)
            {
                total = 500 * a + 100 * b + 50 * c;
                if (total == X)
                    res++;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		long count = 0;
		for(int j = 1; j < n; j++) {
			if(a[j - 1] > a[j]){
				count += a[j - 1] - a[j];
				a[j] = a[j - 1];
			}
		}
		System.out.println(count);
	}
}

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  rep(i,N) cin >> A.at(i);
  int count=0;
  double sum=0;

  rep(i,N){
    sum+=A.at(i);
  }
  rep(i,N){
    if(A.at(i) >= (double)sum/(4*M)){
      count++;
    }
  }
  if(count>=M) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int K;
    cin >> K;
    if (K < 10) {
        cout << K << '\n';
        return 0;
    }
    vector<int> dx{-1, 0, 1};
    queue<ll> lunlun;
    for (int i = 1; i < 10; i++) lunlun.push(i);
    K -= 9;
    while (1) {
        ll l = lunlun.front(); lunlun.pop();
        ll tail = l % 10;
        for (int d : dx) {
            ll ntail = tail + d;
            if (ntail < 0 || ntail >= 10) continue;
            ll nl = l * 10 + tail + d;
            K--;
            if (K == 0) { cout << nl << '\n'; return 0; }
            lunlun.push(nl);
        }
    }
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=998244353;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int cnt[n+1]={};
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(i==0&&a!=0){
            cout<<0<<endl;
            return 0;
        }
        cnt[a]++;
    }
    if(cnt[0]!=1){
        cout<<0<<endl;
        return 0;
    }
    int c=1;
    ll ans=1;
    for(int i=1;i<=n-1;i++){
        if(cnt[i]==0){
            break;
        }
        c+=cnt[i];
        for(int j=0;j<cnt[i];j++){
            ans=(ans*cnt[i-1])%MOD;
        }
    }
    if(c!=n){
        cout<<0<<endl;
    }
    else{
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  map<string, int>mp;
  for(int i=0;i<n;i++)
  {
    string s;
    cin>>s;
    mp[s]++;
  }
  int m=0;
  for (auto it :mp)
  {
    if(it.second>m)
      m = it.second;
  }
  vector<string>vec;
  for (auto it :mp)
  {
    if(it.second==m)
      vec.push_back(it.first);
  }
  sort(vec.begin(),vec.end());
  for(auto it:vec)
    cout<<it<<"\n";


 
  
  return 0;
}

Measured memory_bytes: 25584
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	ll sumx = 0;
	ll sumy = 0;
	int p = n-1;
	int q = m-1;
	for( int i = 0; i < n; ++i ){
		ll x; cin >> x;
		sumx += ((2*i-p)*x)%MOD;
		sumx %= MOD;
	}
	for( int i = 0; i < m; ++i ){
		ll y; cin >> y;
		sumy += ((2*i-q)*y)%MOD;
		sumy %= MOD;
	}
	cout << (sumx*sumy)%MOD << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump_line(int *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

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

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

ll N,W;
ll w[128],v[128];
ll dp[128][512];
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    cin >> N >> W;
    rep(i,N) cin>>w[i]>>v[i];
 
    ll sum=0;
    rep(i,N){
        ll ww = w[i]-w[0];
        // 荷物iを複数回使わないように逆に回す
        for(int j=i;j>=0;j--){  // 荷物iを含まないでj個
            for(int k=0;k<=sum;k++){    // 荷物iを含まない時の重さがk
                dp[j+1][k+ww] = max(dp[j+1][k+ww],dp[j][k]+v[i]);
            }
        }
        sum += ww;
    }
 
    ll ans=0;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=sum;j++){
            if(w[0]*i+j>W) continue;
            ans = max(ans,dp[i][j]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int k, x;
    cin >> k >> x;
    for(int i = max(x - k + 1, -1000000); i < min(x + k - 1, 1000000); i++){
        cout << i << " ";
    }
    cout << min(x + k - 1, 1000000) << "\n";
}

Measured memory_bytes: 256
from collections import deque
n,m = map(int,input().split())
load = [list(map(int,input().split())) for _ in range(m)]
goal = [[] for _ in range(n)]
for i in load:
    goal[i[0]-1].append(i[1]-1)
    goal[i[1]-1].append(i[0]-1)

q = deque([0])
ans = [-1 for _ in range(n)]
ans[0] = 0
while q:
    check = q.popleft()
    for j in goal[check]:
        if ans[j] == -1:
            ans[j] = check+1
            q.append(j)
if -1 in ans:
    print("No")
else:
    print("Yes")
    for p in range(1,n):
        print(ans[p])


Measured memory_bytes: 73048
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
  double a,b,C;
  cin >> a >> b >> C ;
  
  double S = 0.5*a*b*sin(C*M_PI / 180.0);
  double L = a+b+sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(C*M_PI / 180.0));
  double h = S*2/a;
  
  cout << std::fixed << std::setprecision(8) << S << endl;
  cout << L << endl;
  cout << h << endl;
}


Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX = 100005;
int N;
int dp[MAX];

void func(int a){
  for(int i=a;i<=N;i*=a){
    for(int j=0;i+j<=N;j++)
      dp[j+i]=min(dp[j+i],dp[j]+1);
  }
}

int main(){
  cin>>N;
  for(int i=0;i<=N;i++)
    dp[i]=i;
  func(6);
  func(9);
  cout<<dp[N]<<endl;
  return 0;
}
  

Measured memory_bytes: 640
#include<stdio.h>

void call(int n){
    int i = 1;
    while ( i <= n ){
        int x = i;
        if ( x % 3 == 0 || x % 10 == 3 ) {
            printf(" %d", i);
        } else {
            while ( x >= 10 ){
                x /= 10;
                if ( x && x % 10 == 3 ) {
                    printf(" %d", i);
                    break;
                }
            }
        }
        i++;
    }
    printf("\n");
}

int main(void){
    int n;
    scanf("%d", &n);
    call(n);
    return 0;
}


Measured memory_bytes: 2060
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;
 
const lint MAX = 1e17;
lint v, e, r;
vector< vector< pair<lint, lint> > > g;
vector<lint> dis;
vector<bool> done;

void dijkstra(lint start){
    dis[start] = 0;
    priority_queue< pair<lint, lint>, vector< pair<lint, lint> >, greater< pair<lint, lint> > > dij;
    dij.push(make_pair(0, start));
    while(!dij.empty()){
        pair<lint, lint> tmp = dij.top();
        dij.pop();
        if(done[tmp.second]){
            continue;
        }
        done[tmp.second] = true;
        rep(i, g[tmp.second].size()){
            if(dis[g[tmp.second][i].first] > dis[tmp.second] + g[tmp.second][i].second){
                dis[g[tmp.second][i].first] = dis[tmp.second] + g[tmp.second][i].second;
                dij.push(make_pair(dis[g[tmp.second][i].first], g[tmp.second][i].first));
            }
        }
    }
    return;
}
 
int main(){
    cin >> v >> e >> r;
    g.resize(v);
    rep(i, e){
        lint s, t, d;
        cin >> s >> t >> d;
        g[s].push_back(make_pair(t, d));
    }
    dis.resize(v, MAX);
    done.resize(v, false);
    dijkstra(r);
    rep(i, v){
        if(dis[i] == MAX){
            cout << "INF" << endl;
        }else{
            cout << dis[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 19376
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector< pair<dbl, dbl> > P(N);
	for(int i =0; i < N; i++) cin >> P[i].ff >> P[i].ss;
	vector<dbl> ans(N, 0);
	dbl norm =0;

	for(int i =0; i < N; i++) {
		vector<dbl> A;
		for(int j =0; j < N; j++) if(j != i)
			A.push_back(atan2(P[j].ss-P[i].ss, P[j].ff-P[i].ff));
		sort(begin(A), end(A));
		dbl amax =0;
		for(int j =0; j < N-1; j++) {
			dbl a =A[(j+1)%(N-1)]-A[j];
			while(a < -soclose) a +=2*pi;
			if(a < soclose && j == N-2) a +=2*pi;
			amax =max(amax, a);
		}
		if(amax < pi+soclose) continue;
		ans[i] =amax-pi;
		norm +=ans[i];
	}

	for(int i =0; i < N; i++) cout << ans[i]/norm << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        if (X <= 500 * K) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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


void solve()
{
	int n,k,ans = 0;
	cin >> n >> k;
	int arr[n];

	for(int i=0;i<n;i++){
		cin >> arr[i];
		ans += arr[i];
	}

	if (n == k){
		cout << ans << '\n';
	}
	else{
		ans = 0;
		sort(arr,arr+n);
		for(int i = 0;i<k;i++){
			ans += arr[i];
		}
		cout << ans << '\n';
	}
}



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

	solve();
	return 0;
}

Measured memory_bytes: 3624
N = int(input())
a = [int(i) for i in input().split()]

b=[0]*(N+1)
b[0] = sum(a)-2*sum(a[1::2])
for i in range(1,N+1):
    b[i] = 2*a[i-1] - b[i-1]
print(*b[:N])


Measured memory_bytes: 64996
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }
const int MAX = 1e6 + 1;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  vector<bool> ng(MAX, false);
  ll ans = 0;
  rep(i, n) {
    if (ng[a[i]]) continue;
    for (int j = a[i]; j <= MAX; j += a[i]) {
      ng[j] = true;
    }
    if (i == n - 1) ans++;
    else if (a[i] != a[i + 1]) ans++;
  }
  cout << ans << '\n';


  




  
  return 0;
}


Measured memory_bytes: 5056
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, W[111];

int main() {
	cin >> N;
	for_(i,0,N) cin >> W[i];
	
	int A = accumulate(W, W+N, int(0));
	int ans = A, B = 0;
	for_(i,0,N) {
		A -= W[i];
		B += W[i];
		ans = min(ans, abs(A - B));
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
ll dp[200005][3];
int main(){
int  n;
cin>>n;
V<ll> a(n);
for(int i=0;i<200005;i++)for(int j=0;j<3;j++)dp[i][j]=-inf;
dp[0][0]=0;
int skip=1+(n%2);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
    for(int j=0;j<=skip;j++){
        if(j!=skip){
            chmax(dp[i+1][j+1],dp[i][j]);
        }
        chmax(dp[min(n,i+2)][j],dp[i][j]+a[i]);
    }
}
cout<<max(dp[n][skip],dp[n][skip-1])<<"\n";
}

Measured memory_bytes: 9532
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count=0

for s in range(a+1):
    if s*500 == x:
        count += 1
    for t in range(b+1):
        if s*500 + t*100 == x and t != 0:
            count += 1
        for u in range(c+1):
            if s*500 + t*100 + u*50 == x and u != 0:
                count += 1

print(count)

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (B + C < A)
		C = 0;
	else
		C = (B + C) - A;
	cout << C << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    int i,j,ar[n],dp[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        if(i==0)
        {
            dp[i]=0;
            continue;
        }
        else
        {
            dp[i]=2e9;
        }
        for(j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(ar[i]-ar[i-j]));
            }
            else
            {
                break;
            }
        }
    }
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int v;
		int m = 100001; //もとは10000と書いてた。10000までの数が入力で与えられるので、1増やす
		int[] vcnt0 = new int[m],vcnt1 = new int[m];
		//初期値をすべて0にするにはArrays.fill(配列名,0)とかいう技もある
		int i,cnt = 0;
		for(i = 0;i < n;i ++) {
			v = sc.nextInt(); //もともと配列に入れてたけど別に配列に入れる必要がない
			if(i % 2 == 0) {
				vcnt0[v] += 1; 
			}else {
				vcnt1[v] += 1;
			}
		}
		int max0_0 = 0,max0_1 = 0,max1_0 = 0,max1_1 = 0;//,maxidx0 = 0,maxidx1 = 0;
		//配列のインデックスだけ記録しとけば配列の中身はいつでも参照できる
		for(i = 1;i < m-1;i ++) { //[0]はここでは使ってないから1から
			if(vcnt0[max0_0] < vcnt0[i]) {
				max0_1 = max0_0; 
				max0_0 = i;
			}else if(vcnt0[max0_1] < vcnt0[i]) {
				max0_1 = i;
			}
		}
		for(i = 1;i < m-1;i ++) {
			if(vcnt1[max1_0] < vcnt1[i]) {
				max1_1 = max1_0; 
				max1_0 = i;
			}else if(vcnt1[max1_1] < vcnt1[i]) {
				max1_1 = i;
			}
		}
		if(max0_0 == max1_0) {
			cnt = n - Math.max(vcnt0[max0_0] + vcnt1[max1_1],
					vcnt0[max0_1] + vcnt1[max1_0]);
		}else {
			cnt = n - (vcnt0[max0_0] + vcnt1[max1_0]);
		}
		System.out.println(cnt);
	}
}

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

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

  int sum = 0;
  sum += max(A, B);
  if (sum == A) {
    --A;
  } else {
    --B;
  }
  sum += max(A, B);

  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int x;
    cin>>x;

    for(int i=1;i<100000;i++){
        if((ll)i*(i+1)/2>=x){
            cout<<i<<endl;
            return 0;
        }
    }
    

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll            long long
#define pb            emplace_back
#define fi            first
#define se            second
#define mp            make_pair
//#define int           int64_t
 
using namespace std;
 
typedef pair<int, int> pii;
const int N = (int)2003;
 
int n, u, v, low[N], high[N], cnt[N], d[N];
vector<int> a[N], maxa[N];
string s;
 
void dfs(int u, int p) {
    maxa[u].clear(), high[u] = 0, cnt[u] = (s[u] == '1');
    int mxa = 0, dis, sum = 0, mx = 0;
    for(int v: a[u]) {
        if(v == p) continue;
        d[v] = d[u] + 1; dfs(v, u);
        cnt[u] += cnt[v], high[u] += (high[v] += cnt[v]);
        low[v] += cnt[v], mxa = max(mxa, low[v]);
        maxa[u].pb(high[v]);
    }
    low[u] = high[u];
    sort(maxa[u].begin(), maxa[u].end(), greater<int>());
    if(maxa[u].size() == 0) return;
    if(maxa[u].size() == 1) {
        for(int v: a[u]) {
            if(v == p) continue;
            low[u] = low[v];
        }
        return;
    }
    mxa = max(mxa, maxa[u][1]);
    for(int v: a[u]) {
        if(v == p) continue;
        dis = min(high[v], mxa - ((mxa - low[v]) & 1));
        mx = max(mx, dis); sum += dis;
    }
    low[u] = max((sum & 1), mx * 2 - sum);
}
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define FileName      "test"
    if(fopen(FileName".inp", "r")) {
       freopen(FileName".inp", "r", stdin);
       freopen(FileName".out", "w", stdout);
    }
    cin >> n >> s; s = ' ' + s;
    for(int i = 2; i <= n; ++i) {
        cin >> u >> v;
        a[u].pb(v), a[v].pb(u);
    }
    int res = 1e9;
    for(int i = 1; i <= n; ++i) {
        d[i] = 0; dfs(i, i);
        if(low[i] == 0 && high[i] % 2 == 0) res = min(res, high[i] / 2);
    }
    if(res == 1e9) res = -1;
    cout << res;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;cin >> n;
    ll k;cin >> k;
    vi a(n);rep(i,n)cin >> a[i];

    map<int,int> mp;
    int next = 1;
    vi seq;
    for(int i=0;i<n+1;i++){
        if(mp[next] == 0){
            mp[next] = 1;
            seq.push_back(next);
            next = a[next-1];
        }else{
            mp[next] = 2;
            break;
        }
    }

    ll loop_size = 0;
    for(int i=0;i<n;i++){
        if(mp[seq[i]] == 2){
            loop_size = seq.size() - i;
            break;
        }
    }

    // debug
    // cout << "size: " << seq.size() << endl;
    // cout << "loop size: " << loop_size << endl;
    // cout << "seq: ";
    // for(auto i : seq){
    //     cout << i << " ";
    // }
    // cout << endl;
    

    ll left_size = seq.size() - loop_size;
    // cout << "left size: " << left_size << endl;
    if(k<=left_size){
        cout << seq[k] << endl;
    }else{
        k -= left_size;
        cout << seq[k % loop_size + left_size] << endl;
    } 
    return 0;
}

Measured memory_bytes: 13844
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    vs32 a(n);
    rep (i, n) cin >> a[i];

    sort(a.begin(), a.end());

    int ansn = a[n - 1];
    int ansr;
    auto it = lower_bound(a.begin(), a.end(), ansn / 2);
    if (it == a.begin() || *it == ansn / 2 || (n % 2 == 1 && *it == CEIL(ansn, 2)))
    {
        ansr = *it;
    }
    else
    {
        if (abs(*(it - 1) - ansn / 2) <= abs(*it - ansn / 2)) ansr = *(it - 1);
        else ansr = *it;
    }

    cout << ansn << " " << ansr << "\n";
    return 0;
}



Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = a * b;
        if(ans % 2 == 0){
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21716
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    vector<long long> a(4);
    cin>>a[0];
    for(int i=1;i<4;++i){
        cin>>a[i];
        a[i] = min(a[i],2*a[i-1]);
    }
    long long n;cin>>n;
    n*=4;
    long long res = 0;
    for(int i=0;i<3;++i){
        res += a[i]*(n%2);
        n>>=1;
    }
    cout<<res+a[3]*n<<endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    string s, t;
    
    int cnt=0, M=0;
    for(int i=1; i<S.length(); i++){
            s = S.substr(0,i);
            t = S.substr(i,S.length()-i);
            //cout << s <<" "<< t << endl;
            cnt=0;
            for(char ch='a'; ch<='z'; ch++){
                if(s.find(ch)!=string::npos && t.find(ch)!=string::npos)
                    cnt++;
            }
            if(cnt>M) M=cnt;
    }
    
    cout << M << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int length1 = sc.nextInt();
   int b = sc.nextInt();
   String ccc = sc.next();
   
if(b ==1){
 String c1 = ccc.substring(0,1);
 String c2 = ccc.substring(1,length1);
  
  String cs = c1.toLowerCase();
  String cans1 = cs+c2;
  
  System.out.println(cans1);
}
   
else  if(b == length1){
 String c1 = ccc.substring(0,b-1);
 String c2 = ccc.substring(b-1,b);
  
  String cs = c2.toLowerCase();
  
  String cans2 = c1+cs;
  
  System.out.println(cans2);
}
   
 else{
  String c1 = ccc.substring(0,b-1);
 String c2 = ccc.substring(b-1,b);
  String c3 = ccc.substring(b,length1);
  
  String cs = c2.toLowerCase();
  
  String cans3 = c1+cs+c3;
  
  System.out.println(cans3);
}  
   
 }
}

Measured memory_bytes: 21716
@S=<>=~/./g;
@T=<>=~/./g;
for(0..$#S){
	$||=$A{$S[$_]}&&$T[$_]!~$A{$S[$_]}||$B{$T[$_]}&&$S[$_]!~$B{$T[$_]};
	$A{$S[$_]}=$T[$_];
	$B{$T[$_]}=$S[$_];
}
print$|?No:Yes


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

using namespace std;

#define INF 1ll << 62
#define pb push_back
#define ii pair<int,int>
#define OK cout<<"OK"<<endl
#define debug(x) cout << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long

signed main () {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;

	cin >> n;

	for(int i = 0; i*4 <= n; i++) {
		int no = n;
		no -= 4*i;
		if(no % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1 << 60LL;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 型による変数のオーバーフローに気をつけろ！！
// 悩んだら図やグラフを書け！！悩む前から書け！！

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

	string s;
	cin >> s;

	bool a = false;
	bool b = false;
	bool c = false;

	for (int i = 0; i < 3; i++) {
		if (s[i] == 'a') a = true;
		if (s[i] == 'b') b = true;
		if (s[i] == 'c') c = true;
	}

	if (a && b && c) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second


int n;
vector<int>simen;
vector<int>ki_simen;
const int MAX_N = 1e6;
int dp[MAX_N + 1];
int dp2[MAX_N + 1];

void init() {

    for (int i = 1; i * (i + 1) * (i + 2) / 6 <= MAX_N; i++) {
        int now = i * (i + 1) * (i + 2) / 6;
        simen.pb(now);
        if (now % 2)
            ki_simen.pb(now);
    }
}


void solve() {
    rep(i, MAX_N+ 1)dp[i] = MAX_N;
    dp[0] = 0;

    rep(i, simen.size()) {
        rep(j, MAX_N+1) {
            if (j + simen[i] <= MAX_N)
                dp[j + simen[i]] = min(dp[j + simen[i]], dp[j] + 1);
            else break;
        }
    }


    rep(i, MAX_N+ 1)dp2[i] = MAX_N;
    dp2[0] = 0;
    rep(i, ki_simen.size()) {
        rep(j, MAX_N+1) {
            if (j + ki_simen[i] <= MAX_N)
                dp2[j + ki_simen[i]] = min(dp2[j + ki_simen[i]], dp2[j] + 1);
            else break;
        }
    }
}

int main() {

    init();       
    solve();

    while (cin >> n, n) {
        cout << dp[n] << " " << dp2[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 10828
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {i : [] for i in range(n)}
edge_ls = []
for i in range(m):
    a, b, c = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append((b, c))
    edge_ls.append((a, b, c))

INF = float("inf")
d = [-INF for i in range(n)]
d[0] = 0
res = True
before_ls = [i for i in range(n)]
for i in range(n):
    flg = False
    for _from, _to, cost in edge_ls:
        if d[_to] < d[_from] + cost and d[_from] != -INF:
            d[_to] = d[_from] + cost
            before_ls[_to] = _from
            if i == n - 1 and _to == n-1:
                flg = True
if flg:
    print("inf")
else:
    print(d[-1])

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int r;
    cin >> r;
    if(r < 1200){
        print("ABC");
        return 0;
    } else if(r < 2800){
        print("ARC");
        return 0;
    } else {
        print("AGC");
        return 0;
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int a=-1,b=-1,c=-1,moun;
    for(int i=0;i<10;i++){
        cin>>moun;
        if(moun>a){
            c=b;
            b=a;
            a=moun;
        }else if(moun>b){
            c=b;
            b=moun;
        }else if(moun>c)
            c=moun;
    }
    cout<<a<<endl<<b<<endl<<c<<endl;
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n),f(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> f[i];
    sort(ALL(a));
    sort(RALL(f));

    auto isok = [&](const ll &x){
        bool ret = true;
        ll k2 = k;
        REP(i,a.size()) {
            ll c = a[i] * f[i] - x;
            if (c > 0) {
                if (c % f[i] == 0) k2 -= c / f[i];
                else k2 -= c / f[i] + 1;

                if (k2 < 0) {
                    ret = false;
                    break;
                }
            }
        }
        return ret;
    };

    // めぐる式2分探索
    ll ng = -1, ok = a.back() * f.front()+1;
    while(abs(ok-ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isok(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
        // cerr << ng << " " << ok << endl;
    }
    
    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            var d = a / b;
            var r = a % b;
            double A = a;
            double B = b;
            double f;
            f = A / B;
            Console.WriteLine("{0} {1} {2:F5}", d, r,f);
        }
    }
}

Measured memory_bytes: 9656
def insertion(S):
    Sc = S
    Scc = Sc.replace("()", "")
    while Scc != Sc:
        Sc = Scc
        Scc = Scc.replace("()", "")

    # Sc は ((((... or ))))... or ...))))((((...
    # print(Sc)
    if len(Sc) == 0:
        Sl, Sr = "", ""
    elif Sc[0] != Sc[-1]:
        pos = Sc.find(")(")
        Sl = insertion(Sc[:pos+1])[0]
        Sr = insertion(Sc[pos+1:])[2]
    elif Sc[0] == '(':
        Sl = ""
        Sr = ')' * len(Sc)
    else:
        Sl = '(' * len(Sc)
        Sr = ""

    return Sl, S, Sr

N = int(input())
s = insertion(input())
print(s[0]+s[1]+s[2])


Measured memory_bytes: 3064
#include <iostream>
#include <map>

using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  std::cin >> n;
  int a[n];
  rep(i, n) std::cin >> a[i];

  std::map<int, ll> mp;
  rep(i, n) { mp[a[i]]++; }

  ll sum = 0;
  for (auto p : mp) { sum += p.second * (p.second - 1) / 2; }

  rep(k, n) { std::cout << sum - (mp[a[k]] - 1) << '\n'; }
  return 0;
}


Measured memory_bytes: 10240
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, a[N], cnt[N];
vector < int > g[N];
int main (){
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= sqrt(i); ++j){
            if (i % j == 0){
                int a = j, b = i / j;
                g[a].pb(i);
                if (b != a) g[b].pb(i);
            }
        }
    }
    vector < int > ans;
    for (int i = n; i >= 1; --i){
        int res = 0;
        for (int to : g[i]) res += cnt[to];
        if (res % 2 != a[i]){
            for (int to : g[i]){
                if (cnt[to] == 0){
                    cnt[to] = 1;
                    ans.pb(to);
                    break;
                }
            }
        }
    }
    printf ("%d\n", sz(ans));
    for (int to : ans) printf ("%d ", to);
}

Measured memory_bytes: 24948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 202010;
const int MX = 200000;
#define x first
#define y second
#define pb push_back
#define mp make_pair

int n , m, dp[310][310][310],l,r,x;

vector<pii> ad[310];

int calc(int r , int g , int b){
	int idx = max(r,max(g,b));
	if(idx == n+1)return 1;
	int &ret = dp[r][g][b];
	if(ret != -1)return ret;
	bool valid = true;
	for (int i = 0; i < ad[idx].size(); ++i){
		int v = ad[idx][i].y;
		int cnt = (r>=v)+(g>=v)+(b>=v);
		if(cnt != ad[idx][i].x){
			ret = 0;
			return ret;
		}
	}
	ret = (1ll*calc(idx+1,g,b)+calc(r,idx+1,b)+calc(r,g,idx+1))%MOD;
	return ret;
}
int fast(int a , int b){
	if(!b)return 1ll;
	int res = fast(a,b/2);
	res = (1ll*res*res)%MOD;
	if(b&1)return (1ll*res*a)%MOD;
	return res;
}
int main() {
	memset(dp,-1,sizeof dp);
	scanf("%d%d",&n,&m);
	for (int i = 0; i < m; ++i){
		scanf("%d%d%d",&l,&r,&x);
		ad[r].pb(mp(x,l));
	}
	ll res = (1ll*calc(0,0,0)*fast(3,MOD-2))%MOD;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 116608