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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    int n;
    cin >> n;
    double ans = 0.0;
    for (int i = 0; i < n; ++i)
    {
        double x = 0.0;
        string tp;
        cin >> x >> tp;
        if (tp == "JPY")
            ans += x;
        else
            ans += (x * 380000.0 * 1.0);
    }
    printf("%.6f", ans);
    p();
    return 0;
}

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




int main() {
    int A, B; cin >> A >> B;
    if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		 int n,k;
           cin>>n>>k;
           vin a(n);
           int M=0;
           rep(i,0,n){
             cin>>a[i];
             chmax(M,a[i]);
           }
           if(M<k){
            cout<<"IMPOSSIBLE"<<endl;
             return 0;
           }
           int g=a[0];
           rep(i,0,n-1){
            int h=__gcd(a[i],a[i+1]);
             if(h==0){
              chmin(g,a[i+1]);
             }
             else{
				chmin(g,h);
             }
           }
           if(k%g==0)cout<<"POSSIBLE"<<endl;
           else  cout<<"IMPOSSIBLE"<<endl;
           
           
           
           
           
}

Measured memory_bytes: 3724
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
using namespace std;

string shuffle(string s,int n){
	string sBef, sAft;
	sBef = s.substr(n,s.size()-n);
	sAft = s.substr(0,n);
	return sBef + sAft;
}


int main()
{
	int n, temp;
	string W;
	while (1) {
		cin >> W;
		cin >> n;
		if (W == "-")break;
		for (int i = 0; i < n; i++) {
			cin >> temp;
			W = shuffle(W,temp);
		}
		cout << W << endl;
	}

	return 0;
}


Measured memory_bytes: 3164
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		ArrayDeque<Integer> ad = new ArrayDeque<>();
		for (int i = 0; i < n / 2; i++) {
			ad.push(sc.nextInt());
			ad.offer(sc.nextInt());
		}
		Iterator<Integer> itr = ad.descendingIterator();
		if (n % 2 == 1) {
			ad.push(sc.nextInt());
			itr = ad.iterator();
		}

		out.print(itr.next());
		while (itr.hasNext()) {
			out.print(" " + itr.next());
		}

		out.println();
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) return true;
		else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) return buffer[ptr++];
		return -1;
	}

	private boolean isPrintableChar(byte c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) throw new NoSuchElementException();
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 49224
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <math.h>
//#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    string s0;
    string s1;
    int n;
    int ans_0 = 0;
    int ans_1 = 0;
    cin >> s0;
    s1 = s0;
    n = s0.size();

    if(s0[0]=='1'){
        s0[0]='0';
        ans_0++;
    }
    for(int i=1; i<n; i++){
        if(s0[i-1]==s0[i]){
            if(s0[i]=='1'){
                s0[i]='0';
            }else{
                s0[i]='1';
            }
            ans_0++;
        }
    }
    if(s1[0]=='0'){
        s1[0]='1';
        ans_1++;
    }
    for(int i=1; i<n; i++){
        if(s1[i-1]==s1[i]){
            if(s1[i]=='1'){
                s1[i]='0';
            }else{
                s1[i]='1';
            }
            ans_1++;
        }
    }
    if(ans_0<ans_1){
        cout << ans_0;
    }else{
        cout << ans_1;
    }
    cout << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

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

  for (ll i = 0; i < 3; i++)
  {
    if (S.at(i) == S.at(i + 1))
      FINALANS("Bad");
  }
  FINALANS("Good");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,p;
  cin >> n >> p;
  string s;
  cin >> s;
  ll ans=0;
  if(10%p==0){
    rep(i,n){
      if((s[i]-'0')%p==0){
        ans +=i+1;
      }
    }
  }
  else{
    ll x=1;
    vl a(n);
    vl k(n+1,0);
    rep(i,n){
      a[i]=((s[n-i-1]-'0')*x)%p;
      x *=10;
      x %=p;
    }
    k[0]=a[0]%p;
    FOR(i,1,n){
      k[i]=(k[i-1]+a[i])%p;
    }
    sort(k.begin(),k.end());
    ll cnt=0;
    rep(i,n){
      if(k[i]==k[i+1]){
        cnt++;
      }
      else{
        ans +=cnt*(cnt+1)/2;
        cnt=0;
      }
    }
    ans +=cnt*(cnt+1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3716
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
  v,val=map(int,input().split())
  cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
  v=q.pop()
  checked[v]=1 #頂点を見たかどうかのフラグを更新す
  for u in g[v]:
    if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
      continue
    cnt[u]+=cnt[v]
    q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Measured memory_bytes: 56160
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N,K;
    cin >> N >> K;
    ll A[200010];
    rep(i,0,N) cin >> A[i];
    rep(i,0,N-K){
        if(A[i] < A[i+K]){
            print("Yes");
        }else{
            print("No");
        }
    }
    

}

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

Measured memory_bytes: 5204
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()

memo = s[0]
cnt = 0
#print(0,"番目の:",memo)
for i in range(1,len(s)):
	if s[i] == memo:
		cnt += 1
		#print("×")
		if memo == "0":
			memo = "1"
		else:
			memo = "0"
	else:
		memo = s[i]
	#print(i,"番目の:",memo)
print(cnt)

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

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

bool solve() {
  int H,W; cin >> H >> W;
  vector<vector<bool>> v(H+2, vector<bool>(W+2,false));
  rep(i, H) {
    string s; cin >> s;
    rep(j, W) {
      v[i+1][j+1] = s[j] == '#';
    }
  }
  rep(i, H) {
    rep(j, W) {
      if (v[i+1][j+1]) {
        if (!(v[i][j+1] ||
              v[i+2][j+1] ||
              v[i+1][j] ||
              v[i+1][j+2])) return false;
      }
    }
  }
  return true;
}

int main() {
  if (solve()) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 12;
const int inf = (int)2e9;
int dp[1 << N];

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 1; i < (1 << N) ; i ++ )
    dp[i] = inf;
  int c, k;
  int b;
  int mask;
  for(int i = 1; i <= m ; i ++ ){
    cin >> c >> k;
    mask = 0;
    for(int j = 0 ; j < k ; j ++ ){
      cin >> b;
      --b;
      mask |= (1 << b);
    }
    for(int j = 0 ; j < (1 << n); j ++ ){
      dp[j | mask] = min(dp[j | mask], dp[j] + c);
    }
  }
  if(dp[(1 << n) - 1] == inf)
    cout << -1;
  else
    cout << dp[(1 << n) - 1];
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S, T;
  cin>>S>>T;
  bool can = false;
  bool tmp;
  for(int i=0;i<S.size();++i) {
    tmp = true;
    for(int j=0;j<S.size();++j) {
      if(S[(i+j)%S.size()]!=T[j]) tmp = false;
    }
    if(tmp) can = true;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3580
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll ma(ll x, ll y){
    if(x>y)return x;
    return y;
}
ll a[100000];
int main(void){
    int n; cin >> n; for(int i = 0;i < n;i++)cin >> a[i];
    ll ans = 0;
    for(int i = 0;i < n;i++){
        ans += a[i]/2;
        a[i] %= 2;
        if(a[i] && i != n-1 && a[i+1] > 0){
            ans++; a[i+1]--;
        }
    }
    cout << ans << endl;
 	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 3005
const int mod=1e9+7;

ll dp[mx][mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string a,b;
    ll i,j,la,lb;
    cin>>a>>b;
    la=a.size();
    lb=b.size();
    
    for(i=0;i<la;i++)
    {
        for(j=0;j<lb;j++)
        {
            if(a[i]==b[j])
            dp[i+1][j+1]=dp[i][j]+1;
            else
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
    }
    
    vector<char> ans;
    i=la;
    j=lb;
    while(i>0&&j>0){
        //if(a[i-1]==b[j-1])
        if(a[i-1]==b[j-1])
        {
            ans.push_back(a[i-1]);
            i--;j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        i--;
        else j--;
    }
   // if(ans.begin()==ans.end())
    //cout<<" ";
    if(ans.begin()!=ans.end()){
    auto it=ans.end();
    it--;
    while(it!=ans.begin())
    {
        cout<<(*it);
        it--;
    }
    cout<<(*it);
    }
}

Measured memory_bytes: 70656
def main():
    N = int(input())
    prices = []
    for _ in range(N):
        prices.append(int(input()))
    prices.sort()
    cost = 0
    for i in range(N - 1):
        cost += prices[i]
    cost += prices[-1] // 2
    print(cost)


if __name__ == '__main__':
    main()

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

int kai(int n){
	if(n==0)return 1;
	else return n*kai(n-1);
}

int main(){
	int N;
	int x[8],y[8];
	float sum=0;
	cin>>N;
	for(int i=0;i<N;i++)cin>>x[i]>>y[i];
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		}
	}
	sum*=(float)kai(N-1)/kai(N);
	cout<<std::setprecision(15)<<sum;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int count = 0;

        for (int i = list[0]; i <= list[1]; i++)
        {
            if (i%list[2]==0)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 18896
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
count = 0
cou = 1
while cou<n:
    cou*=2
    count += 1
sum = 0
for i in range(n-1):
    j = (i+1) // 2
    sum += a[j]

print(sum)

Measured memory_bytes: 94244
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin >> n;
    vi l(n);
    int sum=0;
    rep(i,n)
    {
        cin >> l[i];
        sum+=l[i];
    }
    RSORT(l);
    if(sum-l[0]>l[0])cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

a.sort(reverse=True)
ans = a[0]
cnt = 2
for i in range(1, n-2):
    ans += a[i]
    cnt += 1
    if cnt == n: break
    ans += a[i]
    cnt += 1
    if cnt == n: break

print(ans)



Measured memory_bytes: 31440
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<ll> a(n);
    ll ret = 0, cnt = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] < 0)
            cnt++;
        a[i] = abs(a[i]);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        if (i < cnt % 2)
            ret -= a[i];
        else
            ret += a[i];
    }
    cout << ret << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

ll n;
vector<lvector> G(n);
lvector dist(n,0);
map<P,ll> mp;

void dfs(ll v,ll d=0,ll p=-1) {
  dist[v]=d;
  for(ll u:G[v]) {
    if(u==p) continue;
    dfs(u,d+mp[P(u,v)],v);
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,c,Q,K,x,y;
  cin>>n;G.resize(n);dist.resize(n);
  rep(i,n-1) {
    cin>>a>>b>>c;
    a--,b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    mp[P(a,b)]=c;
    mp[P(b,a)]=c;
  }
  cin>>Q>>K; K--;
  dfs(K);
  lvector ans(Q,0);
  rep(i,Q) {
    cin>>x>>y;
    x--,y--;
    ans[i]=dist[x]+dist[y];
  }
  rep(i,Q) print(ans[i]);
  return 0;
}

Measured memory_bytes: 32256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e3+7;

int a[MAXN][MAXN];
int b[MAXN];
bool vis[MAXN];
queue<int> Q[MAXN];
int main(){
        int n;
        cin>>n;
        for(int i=0;i<n;++i){
                b[i] = 0;
                for(int j=0;j<n-1;++j) {
                        cin>>a[i][j];
                        a[i][j]--;
                        Q[i].push(a[i][j]);
                }
        }
        int ans = 0;
        while(true) {
                bool flag = 0;
                for(int i=0;i<n;++i) {
                        if(Q[i].empty())        continue;
                        if(Q[Q[i].front()].front()==i) {
                                b[i] = b[Q[i].front()] = max(b[i],b[Q[i].front()]) + 1;
                                Q[Q[i].front()].pop();
                                Q[i].pop();
                                flag = 1;
                        }
                }
                if(!flag) {
                        cout<<-1<<endl;
                        return 0;
                }
                int num = 0;
                for(int i=0;i<n;++i)
                        num += Q[i].size();
                if(num==0)      break;
        }
        for(int i=0;i<n;++i)
                ans = max(ans, b[i]);
        cout<<ans<<endl;
        return 0;
}




Measured memory_bytes: 8576
import java.util.*;

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

        int N = sc.nextInt();
        int W = sc.nextInt();
        long w0;
        ArrayList<Integer>[] v = new ArrayList[4];
        for (int i = 0; i < 4; ++i)
        {
            v[i] = new ArrayList<Integer>(N);
        }

        w0 = sc.nextInt();
        v[0].add(sc.nextInt());

        for (int i = 1; i < N; ++i)
        {
            int w = sc.nextInt();
            v[w - (int)w0].add(sc.nextInt());
        }

        for (int i = 0; i < 4; ++i)
        {
            v[i].sort(Comparator.reverseOrder());
        }

        int max_v = 0;
        for (int i = 0; i <= v[0].size(); ++i)
        {
            long ww0 = w0 * (long)i;
            if (ww0 > W)
            {
                break;
            }
            int vv0 = 0;
            for (int k = 0; k < i; ++k)
            {
                vv0 += v[0].get(k);
            }

            for (int j = 0; j <= v[1].size(); ++j)
            {
                long ww01 = ww0 + (w0 + 1) * (long)j;
                int vv01 = vv0;
                if (ww01 > W)
                {
                    break;
                }
                for (int k = 0; k < j; ++k)
                {
                    vv01 += v[1].get(k);
                }

                for (int l = 0; l <= v[2].size(); ++l)
                {
                    long ww012 = ww01 + (w0 + 2) * (long)l;
                    int vv012 = vv01;
                    if (ww012 > W)
                    {
                        break;
                    }
                    for (int k = 0; k < l; ++k)
                    {
                        vv012 += v[2].get(k);
                    }

                    for (int ll = 0; ll <= v[3].size(); ++ll)
                    {
                        long ww0123 = ww012 + (w0 + 3) * (long)ll;
                        int vv0123 = vv012;
                        if (ww0123 > W)
                        {
                            break;
                        }
                        for (int k = 0; k < ll; ++k)
                        {
                            vv0123 += v[3].get(k);
                        }


                        max_v = Math.max(max_v, vv0123);
                    }
                }
            }
        }

        System.out.println(max_v);
    }

}


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

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

int main(){
	int n;
	while( cin >> n , n ){
		string f[256];
		int ans = 0;

		for(int i=0 ; i < n ; i++ ){
			cin >> f[i];
		}
		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n ; x++ ){
				if( f[y][x] == '1' ){
					for(int i=0 ; i < 4 ; i++ ){
						int mx = x + dx[i];
						int my = y + dy[i];
						int cnt = 1;
						while( mx >= 0 && my >= 0 && mx < n && my < n && f[my][mx] == '1' ){
							mx += dx[i];
							my += dy[i];
							cnt++;
						}
						ans = max( ans , cnt );
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
#include <iostream>
#include <string> 
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int P1 = A/B;
  int P2 = A%B;
  double A1 = A;
  double B1 = B;
  double P3 = A1/B1;
  cout << P1 << " " << P2 << " " <<  fixed << setprecision(5) << P3 << endl; 
}


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

int collatz(int n);

int main(void){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    cout<<collatz(n)<<endl;
  }
  return 0;
}

int collatz(int n){
  int retval=0;
  while(n!=1){
    if(n%2==0){
      n=n/2;
    }
    else{
      n=3*n+1;
    }
    retval+=1;
  }
  return retval;
}



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

int main() {
    int n, k; cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (ans < k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const double EPS = 1e-9;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> se;
    int sum = a;
    while (true) {
        if (se.count(sum)) break;
        se.insert(sum);
        sum += a;
        sum %= b;
    }
    cout << (se.count(c) ? "YES" : "NO") << endl;
}


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

int main() {
	int x, y;
	
	while(1){
		cin >> x >> y;
		if (x == 0 && y ==0) break;
		if (x < y) cout << x << " " << y << endl;
		if (x > y) cout << y << " " << x << endl;
		if (x == y) cout << x << " " << y << endl;
		
	}
	
	
	return 0;
}

Measured memory_bytes: 3084
import collections
N,K = map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
c_most = c.most_common()
if len(c) <= K:
    print(0)
else:
    print(sum([c_most[-i][1] for i in range(1,len(c)-K+1)]))

Measured memory_bytes: 39344
# ALDS1_7_B: Binary Tree

class Node
  class << self
    def bind(parent, left, right)
      parent.set_children(left, right)
      left.set_parent(parent, :left)
      right.set_parent(parent, :right)
    end
  end

  attr_accessor :id, :left, :right
  attr_reader :depth, :height

  def initialize(id)
    @id = id
    @depth = @height = 0
  end

  def update_tree
    update_depths
    update_heights
  end

  def parent
    root? ? NIL : @parent
  end

  def sibling
    return NIL if root?
    on_left? ? @parent.right : @parent.left
  end

  def children
    [@left, @right].select { |n| not n.nil_node? }
  end

  def degree
    children.size
  end

  def type
    case
    when root? then 'root'
    when degree == 0 then 'leaf'
    else 'internal node'
    end
  end

  def root?
    @parent.nil?
  end

  def nil_node?
    self == NIL
  end

  def on_left?
    @position == :left
  end

  def set_children(left, right)
    @left  = left
    @right = right
  end

  def set_parent(parent, position)
    @parent   = parent
    @position = position
  end

  protected
    attr_writer :depth, :height

    def update_depths(depth = 0)
      return if nil_node?
      @depth = depth
      @left.update_depths @depth + 1
      @right.update_depths @depth + 1
    end

    def update_heights
      return -1 if nil_node?
      lh = @left.update_heights
      rh = @right.update_heights
      @height = (lh < rh ? rh : lh) + 1
    end
end

Node.const_set :NIL, Node.new(-1)

n_nodes = gets.to_i
tree = Array.new(n_nodes).map.with_index do |_, i|
  Node.new(i)
end

n_nodes.times do
  id, left_id, right_id = gets.split.map &:to_i
  left  = left_id  == -1 ? Node::NIL : tree[left_id]
  right = right_id == -1 ? Node::NIL : tree[right_id]
  Node.bind tree[id], left, right
end

tree.find { |node| node.root? }.update_tree

tree.each do |n|
  puts "node #{n.id}: parent = #{n.parent.id}, " <<
       "sibling = #{n.sibling.id}, " <<
       "degree = #{n.degree}, depth = #{n.depth}, " <<
       "height = #{n.height}, #{n.type}"
end

Measured memory_bytes: 8696
#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 510
#define MOD 1000000007
#define ll long long
using namespace std;
ll f[MAXN][MAXN],cig[MAXN][MAXN],n,c;
ll A[MAXN],B[MAXN];
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
	    if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}

int main(){
	n=read(),c=read();
	for(ll i=1;i<=n;i++)
		A[i]=read();
	for(ll i=1;i<=n;i++)
		B[i]=read();
	for(ll i=1;i<=n;i++){
		for(ll j=A[i];j<=B[i];j++){
			ll cnt=1;
			cig[i][0]+=cnt;
			for(ll k=1;k<=c;k++){
				cnt=(cnt*j)%MOD;
				cig[i][k]=(cig[i][k]+cnt)%MOD;
			}
		}
	}
	f[0][0]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=0;j<=c;j++)
			for(ll k=0;k<=j;k++)
				f[i][j]=(f[i][j]+f[i-1][j-k]*cig[i][k])%MOD;
	cout<<f[n][c]<<endl;
	return 0;
}

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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;
    
vi gr[100100];
int ans[100100];
int visi[100100];
deque<int> d;
map<ii, int> m;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    string s; cin >> s;
    k--;
    s[k] += 'a'-'A';   
    cout << s << endl;


    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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

const int mod = 1000000007;


int main(){
  string s;
  cin >> s;
  vector<int> dp(13, 0);

  dp[0] = 1;
  int mul = 1;

  for(int i = s.length() - 1; i >= 0; --i){
    vector<int> nextDP(13, 0);

    if(s[i] == '?'){
      for(int j = 0; j < 10; ++j){
        for(int k = 0; k < 13; ++k){
          nextDP[(j * mul + k) % 13] += dp[k];
          nextDP[(j * mul + k) % 13] %= mod;
        }
      }
    } else {
      int k = s[i] - '0';
      for(int j = 0; j < 13; ++j){
        nextDP[(k * mul + j) % 13] += dp[j];
        nextDP[(k * mul + j) % 13] %= mod;
       }
    }

    mul *= 10;
    mul %= 13;
    for(int j = 0; j < 13; ++j){
      dp[j] = nextDP[j];
    }
  }

  cout << dp[5] << endl;

}


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

int N, K, D[10], ans;

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

    for(int i = 0; i < K; i++) {
        int num;
        scanf("%d", &num);
        D[num] = 1;
    }

    for(ans = N; ans < 100000; ans++) {
        int cur = ans;

        while(cur) {
            if(D[cur % 10] == 1) break;
            cur /= 10;
        }

        if(cur == 0) {
            printf("%d\n", ans);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let x: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut sum: usize = 0;
    let mut history: Vec<usize> = Vec::new();
    let mut positions: Vec<usize> = vec![0; m];
    let mut current = x;
    sum += current;
    history.push(current);
    positions[current] = 1;
    let mut count: usize = 2;
    while count <= n {
        current = (current * current) % m;
        if positions[current] != 0 {
            let loops = count - positions[current];
            let rest = n - count + 1;
            let mut sum_of_loop = 0;
            for i in (positions[current] - 1)..(count - 1) {
                sum_of_loop += history[i];
            }
            sum += sum_of_loop * (rest / loops);
            for i in (positions[current] - 1)..(positions[current] - 1 + rest % loops) {
                sum += history[i];
            }
            break;
        }
        sum += current;
        history.push(current);
        positions[current] = count;
        count += 1;
    }
    sum.to_string()
}


Measured memory_bytes: 3188
/*
Hanit Banga
Problem: Boxes and Candies
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb(x) push_back(x)

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

const int N = 1e5 + 5;

ll a[N];

int main()
{
	int n;
	ll x;

	cin >> n >> x;

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

	ll ans = 0;

	for (int i = 1; i < n; ++i)
	{
		if (a[i-1] + a[i] > x)
		{
			ans += a[i] + a[i-1] - x;

			a[i] = max(0ll, x - a[i-1]);

			if (a[i] + a[i-1] > x)
				a[i-1] = x;
		}
	}

	cout << ans;
}

Measured memory_bytes: 1024
// 2014/07/17 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int H, W;
		cin >> H >> W;

		if(H==0 && W==0)
			break;

		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=998244353;
const int INF = 1001001001;
#define size 200010

int main(){
    int N; cin>>N;
    N = N % 10;
    if(N == 3) AA("bon");
    else if(N==0 || N==1 || N==6 || N==8)AA("pon");
    else AA("hon");
    return 0;
}

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

int main()
{
   int n,i,p,k=0,r,c=0;
   cin>>n; 
    
    int a[3];
    p=n;
    
    while(p!=0)
{
r=p%10;
    a[k++]=r;
    p/=10;
}

for(i=0;i<3;i++)
{
    if(a[i]==7)
c++;
}
    
if(c==0)
    cout<<"No"<<endl;
else
    cout<<"Yes"<<endl;
   
}

Measured memory_bytes: 3596
import Control.Monad
import Data.List

main=do
    [h,w]<-map read.words<$>getLine
    as<-replicateM h getLine
    prints (w+2) $ replicate (w+1) '#' ++ concatMap (\s->"##"++s) as ++ replicate (w+3) '#'

prints _ [] = return ()
prints w s = do
    putStrLn $ take w s
    prints w $ drop w s


Measured memory_bytes: 1404
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

const int nmax = 40, abmax = 10, INF = 1e9;
ll dp[nmax + 1][nmax * abmax + 1][nmax * abmax + 1];

int main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<tuple<int, int, int>> list(n);
  for (int i = 0; i < n; i++) {
    cin >> get<0>(list[i]) >> get<1>(list[i]) >> get<2>(list[i]);
  }
  
  for (int i = 0; i <= nmax; i++) {
    for (int j = 0; j <= nmax * abmax; j++) {
      for (int k = 0; k <= nmax * abmax; k++) {
        dp[i][j][k] = INF;
      }
    }
  }
  
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= nmax * abmax; j++) {
      for (int k = 0; k <= nmax * abmax; k++) {
        if (dp[i][j][k] == INF) {
          continue;
        }
        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
        dp[i + 1][j + get<0>(list[i])][k + get<1>(list[i])] = min(dp[i + 1][j + get<0>(list[i])][k + get<1>(list[i])], dp[i][j][k] + get<2>(list[i]));
      }
    }
  }
  
  ll res = INF;
  for (int i = 1; i < nmax; i++) {
    int a = i * ma, b = i * mb;
    if (a > nmax * abmax || b > nmax * abmax) {
      continue;
    }
    res = min(res, dp[n][a][b]);
  }
  if (res == INF) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 51712
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <numeric> 
#include <bits/stdc++.h>
typedef long long ll;
typedef std::pair<std::pair<int,int>,int>pi;
using namespace std;

int main() {
    int n; cin >> n;
    map<int,int>mp;
    for(int i = 1; i <= n; i++){
        mp[i] = 0;
    }
    
    for(int i = 1; i < n; i++){
        int x; cin>>x;
        mp[x]++;
    }
    for(int i = 1; i <=n; i++){
        cout << mp[i] << endl;
    }
    
}



Measured memory_bytes: 13004
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll a[10010], mark[1000010], cnt[1000010];

vector <ll> prime;

ll bigMod(ll a, ll b)
{
    if(b==0) return 1;

    ll tmp=bigMod(a, b/2);

    if(b%2==0) return (tmp*tmp)%mod;
    else return (((tmp*tmp)%mod)*a)%mod;
}

int main()
{
    ll i, j, k, m, n, l;

    for(i=2; i<=1000000; i++)
    {
        if(mark[i]==0)
        {
            prime.push_back(i);
            for(j=2*i; j<=1000000; j+=i) mark[j]=1;
        }
    }
    //cout<< prime.size() <<endl;

    scanf("%lld", &n);
    ll res=0;
    for(i=0; i<n; i++)
    {
        scanf("%lld", &a[i]);
        res+=bigMod(a[i], mod-2);
        res%=mod;
    }

    for(i=0; i<n; i++)
    {
        ll x=a[i];
        for(j=0; prime[j]*prime[j]<=a[i]; j++)
        {
            ll tmp=0;
            while(x%prime[j]==0) x=x/prime[j], tmp++;
            cnt[prime[j]]=max(cnt[prime[j]], tmp);
            //cout<<prime[j]<<" "<<cnt[prime[j]]<<endl;
        }
        if(x!=1) cnt[x]=max(cnt[x], 1LL);
    }
    //cout<<res<<endl;
    ll lcm=1;

    for(i=2; i<=1000000; i++) lcm*=bigMod(i, cnt[i]), lcm%=mod;
    //cout<<lcm<<endl;
    res*=lcm;

    res%=mod;

    printf("%lld\n", res);

    return 0;
}


Measured memory_bytes: 16500
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o B.exe B.cpp 
Execute: ./B
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int x, y;
	cin >> x >> y;
	
	bool result = false; 
	
	// i is number of cranes, j is number of turtles 
	for(int i = 0; i <= x; i++) {
		for(int j = 0; j <= x; j++) {
			if(i + j == x && 2*i + 4*j == y) {
				cout << "Yes" << endl; 
				return 0; 
			}
		}
	}
	
	cout << "No" << endl; 
	
	return 0; 
} 


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

int main() {
	string S;
	bool check = false;
	cin >> S;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] == 'A' && S[i + 1] == 'C') check = true;
	}
	if (check) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define rep(i,n) for(int (i) = 0;i < (int)(n);(i)++)
int main(){
    int n,b,f,r,v;
    cin >> n;
    vector<vector<vector<int> > > house(4,vector<vector<int> >(3,vector<int>(10)));
    // int house[4][3][10];
    // rep(i,120) house[i/30][i/10][i%10] = 0;
     
    rep(i,n){
        cin >> b >> f >> r >> v;
        house[b-1][f-1][r-1] += v;
    }
    rep(i,4){
        rep(j,3){
            rep(k,10){
                cout << " "<< house[i][j][k];
            }
            cout << endl;
        }
        if(i < 3) cout << "####################" << endl;
    }
    return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s,t;
    cin >> s;
    rep(i, s.size()){
        rep(j, s.size()){
            t = s;
            t.erase(i,j);
            if (t == "keyence") {
                YES;
                return 0;
            }
        }
    }
    NO;
    return 0;
}


Measured memory_bytes: 256
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int f[N];
int main(){
fcin;
    for(int x = 1 ; x<=200 ;x++){
        for(int y = 1 ; y<=200;y++){
            for(int z = 1 ; z<=200; z++){
                int n = x*x + y*y + z*z + x*y + y*z + z*x ;
                f[n]++;
            }
        }
    }
    int t;
    cin >> t;
    for(int i = 1 ; i <= t ; i++){
        cout << f[i] << "\n";
    }

}

Measured memory_bytes: 4120
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n;
        while ((n = scan.nextInt()) != 0) {
            int[] s = new int[n];
            double m = 0;
            for (int i = 0; i < n; i++) {
                s[i] = scan.nextInt();
                m += s[i];
            }
            m /= n;
            double sum = 0;
            for(int i = 0; i < s.length; i++){
            	sum += (s[i] - m) * (s[i] - m);
            }
            System.out.println(Math.sqrt(sum/n));
        }
    }
}

Measured memory_bytes: 23732
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.1415926535897932384626433832795028841971693993751058209749445923078164062862089;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
	int x=0;
	char ch=' ';
	bool flag=false;
	while(!isdigit(ch))
	{
		if(ch=='-')flag=true;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return flag?-x:x;
}
const int MAX_N=2050;
const int MAX_V=40050;
int n,m;
int a[MAX_N];
bool b[MAX_N][MAX_N];
int ans[MAX_N];
int ansSz;
bool inAns[MAX_N];
int lastNotCoPrime[MAX_N];
int minOnSuff[MAX_N];
int comp[MAX_V];
vec g[MAX_V];
int C;
int bestForCol[MAX_N];
map <int,int> primeId;
int getId(int p)
{
	if(primeId.count(p)>0)return primeId[p];
	primeId[p]=m;
	m++;
	return m-1;
}
void dfs(int v)
{
	comp[v]=C;
	rep(i,0,g[v].size())
	{
		int u=g[v][i];
		if(comp[u]!=-1)continue;
		if(u<n && inAns[u])continue;
		dfs(u);
	}
}
void color()
{
	rep(i,0,m)
	{
		comp[i]=-1;
	}
	C=0;
	rep(i,0,n)
	{
		if(inAns[i])continue;
		if(comp[i]!=-1)continue;
		dfs(i);
		C++;
	}
}
int main()
{
	cin>>n;
	m=n;
	rep(i,0,n)
	{
		cin>>a[i];
		int x=a[i];
		For(y,2,sqrt(x))
		{
			if(x%y!=0)continue;
			int id=getId(y);
			g[i].pb(id);
			g[id].pb(i);
			while(x%y==0)x/=y;
		}
		if(x!=1)
		{
			int id=getId(x);
			g[i].pb(id);
			g[id].pb(i);
		}
	}
	rep(i,0,n)
	{
		rep(j,i+1,n)
		{
			if(__gcd(a[i],a[j])>1)
			{
				b[i][j]=b[j][i]=1;
			}
		}
	}
	rep(i,0,n)lastNotCoPrime[i]=-1;
	rep(i,0,n)minOnSuff[i]=INF;
	while(ansSz!=n)
	{
		color();
		rep(i,0,C)bestForCol[i]=-1;
		rep(i,0,n)
		{
			if(inAns[i])continue;
			if(minOnSuff[lastNotCoPrime[i]+1]<a[i])continue;
			if(bestForCol[comp[i]]==-1 || a[bestForCol[comp[i]]]>a[i])
			{
				bestForCol[comp[i]]=i;
			}
		}
		int id=-1;
		rep(i,0,C)
		{
			if(bestForCol[i]==-1)continue;
			if(id==-1 || a[id]<a[bestForCol[i]])id=bestForCol[i]; 
		}
		if(id==-1)throw;
		inAns[id]=1;
		ans[ansSz++]=a[id];
		rep(i,0,ansSz)minOnSuff[i]=min(minOnSuff[i],a[id]);
		rep(i,0,n)if(b[id][i])lastNotCoPrime[i]=ansSz-1;
	}
	rep(i,0,n)cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>

int main() {
  int a;
  int b;

  std::cin >> a >> b;

  int d;
  d = a / b;
  int r;
  r = a % b;
  double f;
  f = double(a) / double(b);

  printf("%d %d %.5f", d, r, f);

  return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>


#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define DOUT(obj,n) cout << fixed << setprecision(n) << obj << endl

#define PI 3.14159265359

using namespace std;
typedef long long unsigned int ll;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll all = a + b;
	ll sum = (n / all)*a;
	n %= all;
	if (n <= a) {
		cout << sum + n;
	}
	else if (all >= n) {
		cout <<  sum + a;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

from collections import deque 
from functools import reduce

# input = sys.stdin.readline

x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

list.sort(p, reverse=True)
list.sort(q, reverse=True)
list.sort(r, reverse=True)

p_np = np.zeros(999999)
q_np = np.zeros(999999)

if len(p) > x:
    p_np[:x] = p[:x]
else:
    l_p = len(p)
    p_np[:l_p] = p[:]

if len(q) > y:
    q_np[:y] = q[:y]
else:
    l_q = len(q)
    q_np[:l_q] = q[:]
ap_np = np.hstack((p_np[:x], q_np[:y]))
ap_np.sort()
ap_cnt = 0

for i, ri in enumerate(r):
    if i >= x + y:
        break
    if (r[i] > ap_np[i]):
        ap_np[i] = r[i]
print(int(ap_np.sum()))

Measured memory_bytes: 32176
# https://atcoder.jp/contests/abc079/tasks/abc079_c

a,b,c,d=list(input())
op=['+','-']

def calc():
    for op1 in op:
        for op2 in op:
            for op3 in op:
                res=a+op1+b+op2+c+op3+d
                if eval(res)==7:
                    return res

print(calc()+'=7')

Measured memory_bytes: 2940