akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    
    sort(a, a+n);
    int d=0; //ダブったカードの数
    rep(i, n-1){
        if(a[i+1] == a[i]) d++;
    }
    if(d%2 == 0){
        cout << n-d << endl;
    }else{
        cout << n-d-1 << endl;
    }
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#define inf 0x3f3f3f
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef double db;
const int mod = 1e9;
const int maxn = 1e2+5;
int n,k,d,a,num[maxn];
int main(){
	cin >> n >> k;
	for(int i = 1;i <= k;i++){
		cin >> d;
		for(int i = 1;i <= d;i++){
			cin >> a;
			num[a]++;
		}
	}
	int ans = 0;
	for(int i = 1;i <= n;i++)
		if(!num[i])
			ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3192
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	int before = 0;
	for (int i = 1; i < n+1; i++) {
		before += (l + i - 1);
	}

	int diff = INF;
	int ans = INF;

	for (int i = 1; i < n+1; i++) {
		int tmp = 0;
		for (int j = 1; j < n+1; j++) {
			if (i == j)continue;

			tmp += (l + j - 1);

		}

		if (diff > abs(before - tmp)) {
			diff = abs(before - tmp);
			ans = tmp;
		}
		
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> A(N);
	int max_value = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		max_value = max(max_value, A[i]);
	}
	vector<int> table(max_value + 1, 0);

	for (int i = 0; i < N; i++) {
		for (int j = A[i]; j <= max_value; j += A[i]) {
			table[j]++;
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (table[A[i]] > 1) {
			ans++;
		}
	}
	cout << N - ans << endl;
}

Measured memory_bytes: 8008
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
    S = 'aaa'
    x = 0
    for n in N:
        x += int(n)
    print('Yes' if x % 9 == 0 else 'No')


if __name__ == '__main__':
    # S = input()
    N = input()
    # N, M = map(int, input().split())
    # As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]
    solve(N)


Measured memory_bytes: 9200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main(void){
  char s2[50], t[50];
  int ls2, lt, i, j, k;
  scanf("%s",s2);
  scanf("%s",t);
  ls2 = strlen(s2);
  lt = strlen(t);
  //printf("%d %d\n",ls2,lt);
  for(i=ls2-lt;i>=0;i--){
    for(j=0;j<lt;j++) if(t[j]!=s2[i+j] && s2[i+j]!='?') break;
    if(j==lt) break;
  }
  //printf("%d %d\n",i, j);
  if(i==-1) printf("UNRESTORABLE");
  else {
    for(k=0;k<ls2;k++){
      if(i<=k && k<i+lt) printf("%c",t[k-i]);
      else if(s2[k]=='?') printf("a");
      else printf("%c",s2[k]);
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
N, W = map(int, input().split())
Items = [tuple(map(int, input().split())) for _ in range(N)]
from collections import defaultdict as dd
Bag = dd(lambda:0)
Bag[0] = 0
for w,v in Items:
    temp = [(key+w,Bag[key]+v) for key in Bag if key + w <= W]
    for key,value in temp:
        Bag[key] = max(Bag[key],value)
ans = max(Bag.values())
print(ans)

Measured memory_bytes: 10020
#include<stdio.h>
int main()
{
	long long int gcd(long long int a,long long int b);
	long long int a,b,gc,p,ans;
	scanf("%lld %lld",&a,&b);
	p=a*b;
	if(a>b)
	{
		gc=gcd(a,b);
	}
	else
	gc=gcd(b,a);
	ans=p/gc;
	printf("%lld",ans);
}
long long int gcd(long long int a,long long int b)
{
	long long int t;
	t=a%b;
	if(t!=0)
	return gcd(b,t);
	else
	return b;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll d;
    cin >> d;
    cout << "Christmas";
    rp(i, 0, 5 - (d - 20)) cout << " Eve";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
#include <queue>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> que;
    int64_t sum = 0;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        que.push(a);
        sum += a;
    }
    for (int i = 0; i < m; ++i) {
        int a = que.top(); que.pop();
        sum -= a;
        a /= 2;
        sum += a;
        que.push(a);
    }
    cout << sum << endl;
}



Measured memory_bytes: 3936
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a, b, c, x, y;
int main() {
   cin >> a >> b >> c >> x >> y;
   
   if (c*2>a+b) {
       cout << a*x+b*y;
   } else {
       if (x>=y) {
           cout << c*2*y+(x-y)*min(2*c,a);
       } else {
           cout << c*2*x+(y-x)*min(2*c,b);
       }
   }
   
}

Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>

using namespace std;
#define N 4
#define NN N*N

static const int dx[4] = {0,-1,0,1};
static const int dy[4] = {1,0,-1,0};
int H[NN][NN];
int state_count;

struct Puzzle
{
  int field[NN],space,MD;
  int cost;

    bool operator < (const Puzzle& p) const {
    for(int i=0; i<NN; i++) {
        if( field[i] == p.field[i] ) continue;
        return field[i] < p.field[i];
    }
    return false;
    }
};

struct State
{
  Puzzle puzzle;
  int f_value;
  bool operator < (const State &s) const{
    return f_value > s.f_value;
  }
};

int getTotalMD(Puzzle pz){
    return 0;
}


bool isSolved(Puzzle pz){
  int i;
  for (int i = 0; i < NN; ++i)if(pz.field[i] != i+1)return false;
  return true;
}

int astar(Puzzle pz){
  priority_queue<State> q;
  pz.MD = getTotalMD(pz);
  pz.cost = 0;
  map<Puzzle,bool> V;
  Puzzle u,v;
  State initial;
  initial.puzzle = pz;
  initial.f_value= getTotalMD(pz);
  q.push(initial);

  while(!q.empty()){
    State st = q.top(); q.pop();state_count++;
    u = st.puzzle;
    if(isSolved(u)) return u.cost;
    V[u] = true;

    int sx = u.space / N;
    int sy = u.space % N;

    for(int r=0; r<4; r++) {
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if( tx<0 || ty<0 || tx>=N || ty>=N ) continue;
        v = u;

        v.MD -= H[tx*N+ty][v.field[tx*N+ty]-1];
        v.MD += H[sx*N+sy][v.field[tx*N+ty]-1];

        swap(v.field[sx*N+sy], v.field[tx*N+ty]);
        v.space = tx*N+ty;
        if( !V[v] ) {
        v.cost++;
        State news;
        news.puzzle = v;
        news.f_value = v.cost + v.MD;
        q.push(news);
        }
    }
    }
    return -1;
}

int main(){
for(int i = 0; i<NN; i++)
  for(int j =0;j < NN;j++)
    H[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for(int i=0;i<NN;i++){
    cin >> in.field[i];
    if(in.field[i] == 0){
      in.field[i] = NN;
      in.space = i;
    }
  }

  cout << astar(in) << endl;
  //cout <<"state_count="<<state_count<<endl;
  return 0;
}


Measured memory_bytes: 257540
A, B, M = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
ans = sorted(aList)[0] + sorted(bList)[0]
for i in range(M):
    x, y, c = map(int, input().split())
    p = aList[x-1] + bList[y-1] - c
    if p < ans:
        ans = p
print(ans)

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

int main(){
 ios_base::sync_with_stdio(false); 
 cin.tie(NULL);
int d,t,s;
cin>>d>>t>>s;

if(d<=t*s){
	cout<<"Yes";
}
else{
	cout<<"No";
}
  return 0;
}


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

int main(){
    int a,b,c;
    cin>>a>>b>>c;

    if(a==b+c)cout<<"Yes"<<endl;
    else if(b==a+c)cout<<"Yes"<<endl;
    else if(c==b+a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

# 四方向
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]
INF = float("inf")

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))

S = input()

s_one = "".join([ "0" if i % 2 == 1 else "1" for i in range(len(S))])
s_two = "".join([ "1" if i % 2 == 1 else "0" for i in range(len(S))])

ans = INF
tmp = 0
for si, oi in zip(S, s_one):
    if si != oi:
        tmp += 1

ans = min(ans, tmp)

tmp = 0
for si, oi in zip(S, s_two):
    if si != oi:
        tmp += 1

ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 4564
#include<bits/stdc++.h>	
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
const int INF=1001001001;
typedef pair<int ,int > P;

const int N_MAX=100, M_MAX=100;
char p[N_MAX+1][M_MAX+1];

int main(){
	string a,b;
	cin >> a;
	cin >> b;
	if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N, W; cin >> N >> W;
    vll w(N+1), v(N+1), vs(N+1);
    ll vsum = 0;
    for(ll i=1; i<N+1; i++){
        cin >> w[i] >> v[i];
        vsum += v[i];
        vs[i] = vsum;
    }
    ll dp[N+1][100001];
    dp[0][0] = 0;
    for(ll i=1; i<100001; i++){
        dp[0][i] = 10000000000;
    }
    for(ll i=0; i<N+1; i++){
        dp[i][0] = 0;
    }
    for(ll i=0; i<N; i++){
        for(ll j=1; j<vsum+1; j++){
            if(v[i+1]>j){dp[i+1][j] = dp[i][j];}
            else{dp[i+1][j] = min(dp[i][j], dp[i][j-v[i+1]]+w[i+1]);}
        }
    }
    ll maxi = 0;
    for(ll i=0; i<N+1; i++){
        for(ll j=0; j<vsum+1; j++){
            if(dp[i][j] <= W&&j>maxi){maxi = j;}
        }
    }
    cout << maxi << endl;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    int mx = 0;
    rep(i, 0, n) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    int l = 0, r = mx;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        int cnt = 0;
        rep(i, 0, n) cnt += (a[i] - 1) / mid;
        if (cnt <= k) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << "\n";
}


Measured memory_bytes: 5128
n=int(input());s=input();a=['SS','WS','SW','WW']
for i in range(n):
    for j in range(4):a[j]+='SW'[::-1 if s[i]=='o' else 1][a[j][i]==a[j][i+1]]
for i in range(4):
    if a[i][1]==a[i][n+1] and a[i][0] == a[i][n]:print(a[i][1:n+1]);exit()
print(-1)

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

using namespace std;

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

const int MAXN = 2e5 + 7;
const ll INF = 1e18;

int n, t;
ll dp[3010][3010];
vector<pii> v;

ll solve(int on, int time) {
	if (time <= 0 || on == n) return 0;
	ll &ans = dp[on][time];
	if (~ans) return ans;
	ans = solve(on + 1, time);
	ans = max(ans, v[on].second + solve(on + 1, time - v[on].first));
	return ans;
}

int main() {	
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		v.push_back(pii(x, y));
	}
	sort(v.begin(), v.end());
	memset(dp, -1, sizeof dp);
	cout << solve(0, t) << '\n';
	return 0;
}

Measured memory_bytes: 71168
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        Diceca dice1 = new Diceca(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        Diceca dice2 = new Diceca(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        boolean a = solv(dice1, dice2, 0);
        System.out.println((a)?"Yes":"No");
    }
    public static boolean solv(Diceca f, Diceca diceca, int count){
        if(diceca.Top == f.Top && diceca.S == f.S && diceca.Bottom == f.Bottom && diceca.E == f.E && diceca.N == f.N && diceca.W == f.W) return true;
        if(count == 6) return false;
        Diceca tmp = new Diceca(diceca.Top, diceca.S, diceca.E, diceca.W, diceca.N, diceca.Bottom);
        tmp.TurnN();
        if(solv(f, tmp, count+1)){
            return true;
        }
        tmp = new Diceca(diceca.Top, diceca.S, diceca.E, diceca.W, diceca.N, diceca.Bottom);
        if(solv(f, tmp, count+1)){
            return true;
        }
        tmp = new Diceca(diceca.Top, diceca.S, diceca.E, diceca.W, diceca.N, diceca.Bottom);
        tmp.TurnE();
        tmp = new Diceca(diceca.Top,diceca.S,diceca.E,diceca.W,diceca.N,diceca.Bottom);
        tmp.TurnW();
        if(solv(f,tmp,count+1)) {
            return true;
        }

        return false;
    }

}
class Diceca {
    int Top;//1
    int Bottom;//6
    int N;//5
    int S;//2
    int W;//4
    int E;//3

    Diceca(int a, int b, int c, int d, int e, int f){
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }

    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }

    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }

    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }

    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
}


Measured memory_bytes: 26440
#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

int main(){
  vector<vector<int>> bingIndex = {{0,1,2}
                                   ,{3,4,5}
                                   ,{6,7,8}
                                   ,{0,3,6}
                                   ,{1,4,7}
                                   ,{2,5,8}
                                   ,{0,4,8}
                                   ,{2,4,6}};
  
  std::vector<int> countNum(9);
  std::unordered_map<int, int> numToIndexMap;
  
  for (int i = 0; i < 9; i++){
    int num;
    cin >> num;
    numToIndexMap[num] = i;
  }
  
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    int num;
    cin >> num; 
    if (numToIndexMap.find(num) != numToIndexMap.end()){
      ++countNum[numToIndexMap[num]];
    }
  }
  
  for (int i = 0; i < 8; i++){
    bool bingo = true;
    for (int j = 0; j < 3; j++){
      if (countNum[bingIndex[i][j]] == 0) {
        bingo = false;
        break;
      }
    }
    
    if (bingo){
      cout << "Yes";
      return 0;
    }
  }
  
  cout << "No";  
  return 0; 
}

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

int main(){
    int N; cin >> N;
    int A[200010];
    for(int i=0; i<N; ++i){
        cin >> A[i];
        A[i] -= i+1;
    }
    sort(A, A+N);
    int P=N/2;
    long S=0;
    for(int i=0; i<N; ++i) S += abs(A[i]-A[P]);
    cout << S << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>

const int N=205;

char str[N]; int n,m,a[N][N],sum[N][N],f[2][N][N][N],ans;

inline bool chk(int u,int d,int l,int r){
	int mat_sz=(d-u+1)*(r-l+1);
	int mat_sum=sum[d][r]-sum[u-1][r]-sum[d][l-1]+sum[u-1][l-1];
	return mat_sum==0||mat_sum==mat_sz;
}

inline int find(int c,int u,int d,int k){
	int lbound=u,rbound=d,res=0;
	while(lbound<rbound){
		int mid=(lbound+rbound)>>1;
		int v1=f[c][u][mid][k],v2=f[c][mid+1][d][k];
		res=std::max(res,std::min(v1,v2));
		if(v1>v2) lbound=mid+1; else rbound=mid;
	}
	return res;
}

inline void dp(int c){
	for(int i=1;i<=n;++i){
		for(int j=i;j<=n;++j){
			for(int k=1;k<=m;++k){
				int las_v=f[c^1][i][j][k],now_v;
				if(las_v!=m){
					now_v=f[c^1][i][j][las_v+1];
					now_v=std::max(now_v,find(c^1,i,j,k));
				}
				else now_v=las_v;
				f[c][i][j][k]=now_v;
			}
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",str+1);
		for(int j=1;j<=m;++j) a[i][j]=(str[j]=='#');
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j) sum[i][j]=sum[i][j-1]+a[i][j];
	}
	for(int j=1;j<=m;++j){
		for(int i=1;i<=n;++i) sum[i][j]+=sum[i-1][j];
	}
	for(int i=1;i<=n;++i){
		for(int j=i;j<=n;++j){
			for(int l=1,r;l<=m;l=r){
				r=l; while(r<=m&&chk(i,j,l,r)) ++r;
				for(int k=l;k<r;++k) f[0][i][j][k]=r-1;
				if(l==r) f[0][i][j][l]=l-1,++r;
			}
		}
	}
	for(int i=1;f[(i&1)^1][1][n][1]<m;++i) dp(i&1),ans=i;
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 65536
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int calc(string &s, int m){
  int res = 0;
  for(auto c : s){
    res = res * 2 + (c == '1');
    res %= m;
  }
  return res;
}

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  for(auto c : s) if(c == '1') cnt++;

  map<int, int> mp;
  for(int i = max(1LL, cnt - 1); i <= cnt + 1; i++) mp[i] = calc(s, i);

  vector<map<int, int> > mpb(n);
  for(int i = 0; i < n; i++){
    for(int j = max(1LL, cnt - 1); j <= cnt + 1; j++){
      if(i == 0) mpb[i][j] = 1 % j;
      else mpb[i][j] = mpb[i - 1][j] * 2 % j;
    }
  }

  REP(i, n){
    if(s[i] == '0') cnt++;
    else cnt--;

    if(cnt == 0){
      cout << 0 << endl;
    }else{
      int now = mp[cnt];
      if(s[i] == '0') now = (now + mpb[n - 1 - i][cnt]) % cnt;
      else now = (now + cnt - mpb[n - 1 - i][cnt]) % cnt;


      int ans = 1;
      while(now){
        int nxt_cnt = __builtin_popcountll(now);
        now = now % nxt_cnt;
        ans++;
      }
      cout << ans << endl;
    }
    if(s[i] == '0') cnt--;
    else cnt++;
  }
}


Measured memory_bytes: 50324
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    int N, max_i = 0, sec_i = 0;
    cin >> N;
    int A[N+1];
    A[0] = 0;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        if(A[i] > A[max_i])max_i = i;
        else if(A[i] > A[sec_i])sec_i = i;
    }
    for(int i = 1; i <= N; i++)
        cout << A[((i == max_i)?sec_i:max_i)] << endl;
    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    map<int64_t, pair<int64_t, pair<int64_t, int64_t>>> m;
    m[0].first = 0;
    for (auto i : irange(0L, n)) {
        auto it = m.upper_bound(a[i]);
        if (it == m.end()) {
            m.rbegin()->second.first = i;
            m[a[i]].first = -1;
            it = --m.end();
        } else {
            --it;
        }
        it->second.second.first += 1;
        it->second.second.second += a[i] - it->first;
    }

    vector<int64_t> ans(n);
    int64_t c = 0, p = 0;
    for (const auto& kv : m | reversed) {
        auto aa = kv.first;
        auto idx = kv.second.first;
        auto ex = kv.second.second.second;

        if (idx >= 0) {
            ans[idx] = c * (p - aa) + ex;
        }

        c += kv.second.second.first;
        p = aa;
    }

    for (auto aa : ans) {
        cout << aa << "\n";
    }
}

Measured memory_bytes: 10368
n = int(input())
lst =  []
stimmt = False
for _ in range(n):
    lst.append(list(map(str,input().split())))
for i in range(len(lst)):
    if lst[i][0] == lst[i][1]:
        if i+2 < len(lst):
            if lst[i+1][0] == lst[i+1][1] and lst[i+2][0] == lst[i+2][1]:
                stimmt = True
                break
 
if stimmt:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1e6 + 5;
int arr[N];

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rw", stdin);
#endif
	int n, x, q, l;
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		++arr[x];
		sum += x;
	}
	cin >> q;
	for (int i = 0; i < q	; ++i) {
		cin >> l >> x;
		sum -= 1ll * arr[l] * l;
		sum += 1ll * arr[l] * x;
		arr[x] += arr[l];
		arr[l] = 0;
		cout << sum << '\n';
	}
	return 0;
}


Measured memory_bytes: 4004
w,h,n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    else:
        a4 = min(l[i][1], a4)

print(0) if a2-a1 <= 0 or a4-a3 <= 0 else print((a2-a1)*(a4-a3))


Measured memory_bytes: 3064
#!/usr/bin/env python3
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if (
                l[i] != l[j]
                and l[j] != l[k]
                and l[i] > l[k] - l[j]
                and l[k] < l[i] + l[j]
            ):
                ans += 1
print(ans)


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(ll i = 0; i<n; i++)
#define rep_s(i, start, n) for(ll i= start;  i<n; i++)
#define rep_down(i, n) for(ll i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(ll i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
#define print(ans) cout << ans << endl;
#define MOD 1000000007
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*

for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}

using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}

int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll keta_num(ll num){
  ll total = 0;
  while(num){
    num /= 10;
    total++;
  }
}


ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll fibonacchi(ll num){
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while(count<num){
    f2 = f0+f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
*/
int main(void){
  ll N, M, A, B, C, D, E, F, G, K,L, W, H, P, Q, R, V, X, Y;
  string S, T;
  cin >> N;
  ll ans = 0;
  rep(i, N){
    if((i+1)%3 != 0 && (i+1) %5 != 0){
      ans += i+1;
      
    }
  }
 
  cout << ans << endl;

}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
constexpr lint MOD = 1000000007;
int N, A, B, C, D;

vector<lint> factorial;
vector<lint> facInv;

template <typename T>
T power(T x, T n, T mod)
{
    T ans = 1;
    while (n>0)
    {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}

void cPrecal(int n)
{
    factorial = facInv = vector<lint>(n + 1, 1);
    for (int i = 1; i <= n; i++)
    {
        factorial[i] = factorial[i - 1] * i % MOD;
        facInv[i] = power(factorial[i], MOD - 2, MOD);
    }
}

lint nCr(int n, int r)
{
    if (n<r || r<0) return 0;
    else return (factorial[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}

lint coeff(int K, int X, int i)
{
    return (((facInv[X] * factorial[N - i + K * X]) % MOD) * facInv[N - i] % MOD) * power(facInv[K], (lint)X, MOD) % MOD;
}

int main()
{
    cin >> N >> A >> B >> C >> D;
    cPrecal(N+1);
    vector<lint> dp(N + 1);
    dp[0] = 1;
    for (int K = A; K <= B; K++)
    {
        for (int i = N; i >= 0; i--)
        {
            for (int X = C; ((i - K * X) >= 0 && X <= D); X++)
            {
                dp[i] = (dp[i] + coeff(K, X, i) * dp[i - K * X]) % MOD;
            }
        }
    }
    cout << dp[N] << endl;
}


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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  
  int a;
  double s1 = h / w, s2 = 0 - s1, r = w * h / 2;
  if((w / 2) == x && (h / 2) == y)
    a = 1;
  else
    a = 0;
  
  cout << r << " " << a << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()



signed main()
{
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    int a;
    cin >> a >> s;
    if(a < 3200)
        cout << "red" << endl;
    else
        cout << s << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

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

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

int main(){
	int n;
	cin >> n;
	// input
	for( int t = 0; t < n; t++ ){
		int puzzle[9][9];
		int row[9][9] = {{0}}, col[9][9] = {{0}}, rect[9][9] = {{0}};
		for( int i = 0; i < 9; i++ ){
			for( int j = 0; j < 9; j++ ){
				cin >> puzzle[i][j];
				if( row[i][puzzle[i][j]-1] == 1 ) row[i][puzzle[i][j]-1] = -1;
				else if( row[i][puzzle[i][j]-1] == 0 ) row[i][puzzle[i][j]-1] = 1;
				if( col[j][puzzle[i][j]-1] == 1 ) col[j][puzzle[i][j]-1] = -1;
				else if( col[j][puzzle[i][j]-1] == 0 ) col[j][puzzle[i][j]-1] = 1;
				if( rect[i/3*3+j/3][puzzle[i][j]-1] == 1 ) rect[i/3*3+j/3][puzzle[i][j]-1] = -1;
				else if( rect[i/3*3+j/3][puzzle[i][j]-1] == 0 ) rect[i/3*3+j/3][puzzle[i][j]-1] = 1;
			}
		}

		// output
		if( t != 0 ) cout << endl;
		for( int i = 0; i < 9; i++ ){
			for( int j = 0; j < 9; j++ ){
				if( row[i][puzzle[i][j]-1] == -1 || col[j][puzzle[i][j]-1] == -1 || rect[i/3*3+j/3][puzzle[i][j]-1] == -1 ) cout << "*";
				else cout << " ";
				cout << puzzle[i][j];
			}
			cout << endl;
		}
	}
}

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

string T;

int main(void) {
	cin >> T;

	for (int i = 0; i < (int)T.length(); ++i) {
		if (T[i] == '?')
			T[i] = 'D';
	}

	cout << T << '\n';
	return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,q; cin >> n >> k >> q;
  vector<int> player(n,k);
  vector<int> ans(n,0);
  for(int i = 0; i < q; i++){
    int a; cin >> a;
    ans.at(a - 1)++;
  }
  for(int i = 0; i < n; i++){
    player.at(i) += ans.at(i) - q;
    if(player.at(i) > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  
}


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

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

const int inf = 1'000'000'000;

int main() {
  int n;
  cin >> n;
  std::vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x % 2 == 0) {
      vec.push_back(x);
    }
  }
  bool can = true;
  for (int i : vec) {
      if (i % 3 != 0 && i % 5 != 0) {
        can = false;
      }
  }
  if (can) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int a_1000 = (a / 1000) % 10;
  int a_100 = (a / 100) % 10;
  int a_10 = (a / 10) % 10;
  int a_1 = a % 10;
  if ((a_1000 == a_100 && a_100 == a_10) || (a_100 == a_10 && a_10 == a_1)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
n = int(input())

bn = list( map(int, input().split()) )

an = [10**6]*n

for i in range(n-1):

    an[i]   = min(an[i], bn[i])
    an[i+1] = bn[i]
#    print((an[i],an[i+1]))


#print(an)
print( sum(an) )



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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, q;
  cin >> n >> q;

  vector<P> enter, leave;

  rep(i, n) {
    ll s, t, x;
    cin >> s >> t >> x;
    s -= x;
    t -= x;
    enter.emplace_back(s, x);
    leave.emplace_back(t, x);
  }

  sort(all(enter));
  sort(all(leave));

  vll d(q);
  rep(i, q) {
    cin >> d[i];
  }

  multiset<ll> stop;

  ll ei = 0;
  ll li = 0;

  for (ll time : d) {
    while (ei < n) {
      if (enter[ei].first > time) {
        break;
      }
      stop.insert(enter[ei].second);
      ei++;
    }
    while (li < n) {
      if (leave[li].first > time) {
        break;
      }
      auto itr = stop.find(leave[li].second);
      stop.erase(itr);
      li++;
    }
    if (stop.begin() != stop.end()) {
      cout << *stop.begin() << endl;
    } else {
      cout << -1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 18524
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    int R;
    cin >> R;
    cout << 2 * 3.14 * R << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

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

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  // vector<int> p(n);
  int min_p;
  int ans = n;
  cin >> min_p;
  repd(i,1,n){
    int tmp_p;
    cin >> tmp_p;
    if (tmp_p > min_p){
      ans--;
    }else{
      min_p = tmp_p;
    }

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

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

typedef vector<ld> Point;
typedef vector<ld> Vec;
struct sophia {
	Point c; ld r;
};
vector<ld> cc(Point s, Vec v, sophia c) {
	ld a1=0, a2 = 0, a3 = 0;
	rep(i, 3) {
		a1 += pow(v[i], 2);
		a2 += 2 * v[i] * (s[i] - c.c[i]);
		a3 += pow(s[i] - c.c[i], 2);
	}
	a3 -= pow(c.r, 2);
	ld d = a2 * a2 - 4 * a1*a3;
	if (d< 0)return {};
	vector<ld> ret;
	ld t1 = -a2 + sqrt(d); t1 /= 2*a1;
	ld t2 = -a2 - sqrt(d); t2 /= 2 * a1;
	if (t2 > 0)ret.push_back(t2);
	else if (t1 > 0)ret.push_back(t1);
	return ret;
}
ld norm(Vec v) {
	ld ret = 0;
	rep(i, 3) {
		ret += pow(v[i], 2);
	}
	return ret;
}
ld dot(Vec a,Vec b) {
	ld ret = 0;
	rep(i, 3) {
		ret += a[i] * b[i];
	}
	return ret;
}
Vec hanten(Point cur, Vec v, sophia c) {
	Vec n(3);
	rep(i, 3) {
		n[i] = cur[i] - c.c[i];
	}
	ld a1 = norm(n);
	ld a2 = -2 * dot(n, v);
	ld t= a2 / a1;
	Vec ret(3);
	rep(i, 3) {
		ret[i] = v[i] + t * n[i];
	}
	return ret;
}

int n;
void solve() {
	Vec v(3);
	rep(i, 3) {
		cin >> v[i];
	}
	Point cur(3, 0);
	vector<sophia> s(n);
	rep(i, n) {
		s[i].c.resize(3);
		rep(j, 3) {
			cin >> s[i].c[j];
		}
		cin >> s[i].r;
	}
	Point ans;
	int pre = -1;
	while (true) {
		ld mi = INF; int chk = -1;
		rep(i, n) {
			if (pre == i)continue;
			vector<ld> ts = cc(cur, v, s[i]);
			if (ts.size()) {
				if (ts[0] < mi) {
					mi = ts[0];
					chk = i;
				}
			}
		}
		if (chk < 0) {
			break;
		}
		rep(i, 3) {
			cur[i] += mi * v[i];
		}
		Vec nexv = hanten(cur, v, s[chk]);
		v = nexv;
		ans = cur;
		pre = chk;
	}
	rep(i, 3) {
		if (i > 0)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(5);
	//init();
	while (cin >> n, n) {
		solve();
	}

	//cout << "finish" << endl;
	//stop
		return 0;
}



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

int main(){
    //input
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a > b && a > c){
        cout << a * int(pow(2,k)) + b + c << endl;
    }else if(b > a && b > c){
        cout << b * int(pow(2,k)) + a + c << endl;
    }else{
        cout << c * int(pow(2,k)) + a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e7 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,i,ans;
ll cnt[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n;
    for (i = 1;i <= n;i++){
        ll p = n/i,sm = i,bg = n - n%i;
        ans += (sm + bg)*p/2;
    }
    cout<<ans;
}



Measured memory_bytes: 3656
s=input()
t=list(map(int,input().split()))
s=int(s)
t.reverse()
for i in range(s-1):
  if t[i]<t[i+1]:
    t[i+1]=t[i+1]-1
t.reverse()
a=0
for j in range(s-1):
  if t[j]>t[j+1]:
    a=-1
if a==-1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 14396
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

int main () {
  int N;
  cin >> N;
  int p[20010];
  for (auto i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }
  int a[20010];
  int b[20010];
  int C = 20001;
  for (auto i = 0; i < N; i++) {
    a[p[i]] = C * p[i] + i + 1;
    b[p[i]] = C * C - C * p[i] + 1;
  }
  for (auto i = 0; i < N; i++) {
    cout << a[i];
    if (i < N-1) cout << " ";
  }
  cout << endl;
  for (auto i = 0; i < N; i++) {
    cout << b[i];
    if (i < N-1) cout << " ";
  }
  cout << endl;
}


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 m = sc.nextInt();
      int[] pos = new int[m];
      for(int i = 0; i < m; i++)
        pos[i] = sc.nextInt();
      Arrays.sort(pos);
      ArrayList<int[]> dist = new ArrayList<>();
      for(int i = 1; i < pos.length; i++) {
        dist.add(new int[]{pos[i-1], pos[i]});
      }
      Collections.sort(dist, (d1, d2) -> (d2[1] - d2[0]) - (d1[1] - d1[0]));
      ArrayList<int[]> intervals = new ArrayList<>();
      for(int i = 0; i < n - 1&& i < dist.size(); i++) {
        intervals.add(dist.get(i));
      }
      Collections.sort(intervals, (itv1, itv2) -> itv1[0] - itv2[0]);
      int cnt = 0;
      int start = pos[0];

      for(int i = 0; i < intervals.size(); i++) {
        int[] itv = intervals.get(i);
        cnt += itv[0] - start;
        start = itv[1];
      }
      
      cnt += pos[pos.length - 1] - start;
      System.out.println(cnt);
  }
}

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

int main() {
  int a , b;
  cin >> a >> b;
  int c = a*b;
  int d = c%2;
  
  if (d == 0) {
    cout << "Even" << endl;
  }
  
  if (d == 1) {
    cout << "Odd" << endl;
  }
    
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    double x, ans = 0.0;
    string u;
    for (int i = 0; i < n; ++i) {
        cin >> x >> u;
        ans += (u == "JPY") ? x : x * 380000.0;
    }

    cout << fixed << ans << endl;

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N = 13, M = 1e9 + 7;
  vector<int> DP(N);
  DP.at(0) = 1;
  char c;
  while (cin >> c) {
    vector<int> V(N);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
        if (c == '?' || c == '0' + j) {
          (V.at((i * 10 + j) % 13) += DP.at(i)) %= M;
        }
      }
    }
    DP = V;
  }

  cout << DP.at(5) << "\n";
}

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

template <typename Iterator>
auto findMaximumSum (Iterator begin , Iterator end) -> long long
{
    long long res = * begin;
    auto tmp = res;
    for (auto ite = begin + 1; ite != end; ++ ite)
    {
        tmp += * ite;
        res = std::max (res , tmp);
    }
    return res;
}

auto main () -> int
{
    int n;
    while (std::cin >> n && n)
    {
        std::vector <int> a (n);
        for (auto && elem : a)
        {
            std::cin >> elem;
        }
        long long ans = a [0];
        for (auto ite = a.begin (); ite != a.end (); ++ ite)
        {
            auto tmp = findMaximumSum (ite , a.end ());
            ans = std::max (ans , tmp);
        }
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;
const int maxn=100005;

int main()
{
    int n,x;
    int a[maxn];
    while(scanf("%d%d",&n,&x)==2){
        int t;
        for(int i=0;i<n;i++){
            scanf("%d",&t);
            a[i]=abs(x-t);
        }
        int ans=a[0];
        for(int i=1;i<n;i++){
            ans=__gcd(ans,a[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, K;
    cin >> n >> K;
    vector<int> T(n);
    vector<int> D(n);

    vector<vector<int>> X(n);
    for (int i = 0; i < n; ++i) {
        cin >> T[i] >> D[i];
        --T[i];
        X[T[i]].push_back(D[i]);
    }
    for (auto& V : X) {
        sort(V.begin(), V.end(), greater<int>());
    }

    sort(X.begin(), X.end(), greater<vector<int>>());
    while (!X.empty() && X.back().empty()) {
        X.pop_back();
    }

    priority_queue<int, vector<int>, greater<int>> pq;

    long long res = 0;
    long long sum = 0;
    for (int i = 0; i < X.size(); ++i) {
        if (i + 1 > K) {
            break;
        }

        sum += X[i].front();

        for (int j = 1; j < X[i].size(); ++j) {
            sum += X[i][j];
            pq.push(X[i][j]);
        }
        while (i + 1 + pq.size() > K) {
            sum -= pq.top();
            pq.pop();
        }

        res = max(res, (i + 1) * 1LL * (i + 1) + sum);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
#define ll long long
#define INF 10000000
ll cnt_digits(ll n){
  ll cnt = 0;
  while(n > 0){
    n /= 10;
    cnt++;
  }
  return cnt;
}
int main(){
  ll n;
  cin >> n;
  ll ans = cnt_digits(n);
  for(ll i=1; i*i<=n; i++){
    if(n % i != 0) continue;
    ll tmp = n/i;
    ll cur = max(cnt_digits(i),cnt_digits(tmp));
    if(ans > cur) ans = cur;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int A[N][M];
  int B[M];
 
  for (int i = 0; i < M; i++) 
    cin >> B[i];
 
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      cin >> A[i][j];
 
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    int sum = C;
    for (int j = 0; j < M; j++)
    
      sum += A[i][j] * B[j];
    
    if (sum > 0)  count++; 
  }
 
  cout << count << endl;
 
  return 0;
}

Measured memory_bytes: 256