akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;
const LL LINF=334LL<<54;


// start, goal, graph, previous vertex on the shortest pass (prev[start]=-1)
typedef pair<LL,int> PLI;
struct Edge{
    int from,to;
    LL cost;
    Edge(int from,int to,LL cost)
        : from(from),to(to),cost(cost) {};
};
typedef vector<vector<Edge>> Graph;

bool Bellman_Ford(const int start, const vector<vector<Edge>> &graph , vector<PLI> &prev){
    int s=graph.size();
    fill(prev.begin(),prev.end(),make_pair(LINF,-1));
    prev[start]=make_pair(0ll,start);
    for(int i=0; i< s; ++i){
        for(int j= 0; j<s;++j){
            for(auto &e : graph[j]){
                if(prev[j].first!= LINF && prev[e.to].first > prev[j].first + e.cost){
                    prev[e.to].first=prev[j].first+e.cost;
                    prev[e.to].second=j;
                    if(i==s-1)return false;
                }
            }
        }
    }

    return true;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,t,r; //vertex,edge
    cin >> n >> m>>r;
    Graph G(n);
    vector<PLI> prev(n); //<cost,prev>

    for(int i=0;i<m;i++){
        int a,b,cost;
        cin >> a >> b >> cost;
        G[a].push_back(Edge(a,b,cost));
        //G[b].push_back(Edge(b,a,cost));
    }

    if(!Bellman_Ford(r,G,prev))cout << "NEGATIVE CYCLE"<<endl;
    else{
        REP(i,n){
            if(prev[i].first==LINF)cout << "INF"<<endl;
            else cout << prev[i].first<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3252
n=int(input())
S=[input() for i in range(n)]
a,b,c=0,0,0
cnt=0
for i in S:
    if i[0]=="B" and i[-1]=="A":c +=1
    elif i[0]=="B":a +=1
    elif i[-1]=="A":b +=1
    for j in range(len(i)-1):
        if i[j]+i[j+1]=="AB":cnt +=1

if c==0:cnt +=min(a,b)
elif a+b==0:cnt +=c-1
elif c!=0 and a+b>0:cnt +=min(a,b)+c
print(cnt)

Measured memory_bytes: 3700
import Data.List

main = do
  [x,y,z,k] <- map read.words<$>getLine
  as <- map read.words<$>getLine
  bs <- map read.words<$>getLine
  cs <- map read.words<$>getLine
  putStr $ solve x y z k as bs cs

solve x y z k as' bs' cs' = unlines.map show$take k ans
  where
  ans = sortBy (flip compare)
    [ as!!(a-1) + bs!!(b-1) + cs!!(c-1)
    | a <- [1..min k x]
    , b <- [1..min (div k a) y]
    , c <- [1..min (div k (a*b)) z] ]
  [as,bs,cs] = map (sortBy $ flip compare) [as',bs',cs']

Measured memory_bytes: 14204
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

int main(){
    ins(a);ins(b);ins(c);
    YES(b-a==c-b);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll ans=0;
    for (int i=0;i<N;++i) ans+=(i+1)*(N-i);
    for (int i=0;i<N-1;++i){
        ll u,v; cin >> u >> v; --u,--v;
        if (u>v) swap(u,v);
        ans-=(u+1)*(N-v);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3644
from itertools import combinations
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a-1, b-1, c, d))

# 全探索
ans = 0
for i, comb in enumerate(combinations(range(n+m-2), r=n-1)):
    # 数列の構成
    A = [1] * n
    idx = 0
    for i in range(n+m-2):
        if i in comb:
            idx += 1
            A[idx] = A[idx-1]
        else:
            A[idx] += 1

    # クエリの判定
    score = 0
    for query in queries:
        a, b, c, d = query
        if A[b] - A[a] == c:
            score += d
    ans = max(ans, score)

print(ans)

Measured memory_bytes: 68548
# a!=b b!=c c!=a
# a+b>c and b+c>a and c+a>b

N = int(input())
L_list = list(map(int, input().split()))
result = 0
setL = list(set(L_list))

countL = []  # setLの要素がL_listに何個ずつ含まれるかを記録。setLの要素の順番と同じ順番
def num_count(dum):
   return L_list.count(dum)
countL = list(map(num_count,setL))
#print(countL)
# print("setL",setL)

for i in range(len(setL)):
    a=setL[i]
    for j in range(i+1,len(setL)):
        b=setL[j]
        for k in range(j+1,len(setL)):
            # print("i=",i,"j=",j,"k=",k)
            c=setL[k]
            if(a+b > c and b+c > a and c+a > b):
                # print("a=",a,"b=",b,"c=",c)
                # print(countL[i]," ",countL[j]," ",countL[k])
                result += countL[i]*countL[j]*countL[k]
print(result)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=400005;
const ll INF=1LL<<55;
ll dp[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S;cin>>S;
    
    for(ll i=1;i<=2*N;i++){
        if(2*N%i!=0||(2*N/i)%2==0) continue;
        
        ll sum=0;
        for(int j=0;j<i/2;j++){
            sum*=2;
            if(S[j]=='1') sum++;
            
            sum%=mod;
        }
        
        string A=S.substr(0,i/2);
        string B=A;
        for(int j=0;j<i/2;j++){
            if(B[j]=='0') B[j]='1';
            else B[j]='0';
        }
        
        string T=A;
        while(T.size()<S.size()){
            T+=B;
            T+=A;
        }
        
        if(T<=S) sum++;
        
        for(int j=1;j<i;j++){
            if(i%j==0){
                sum+=mod-dp[j];
                sum%=mod;
            }
        }
        
        dp[i]=sum;
    }
    
    ll ans=0;
    
    for(ll i=1;i<=2*N;i++){
        ans+=dp[i]*i;
        ans%=mod;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 1148
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[]) {
  string  s;
  int min=1000;
  cin>>s;
  for(int i=0;i<s.size()-2;i++){
    string s1;
    s1.push_back(s[i]);
    s1.push_back(s[i+1]);
    s1.push_back(s[i+2]);
    int tmp = stoi(s1);
    int dif = abs(753 - tmp);
    if(dif<min) min = dif;
  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long int N,M,H,W,x,i,j,k,ans,count,cost,tmp;
    long long int S[300000];
    long long int T[300000];
    long long int U[300000];
    //long long int Ssum[300000];
    //string T,U,V,ans2;
    bool flag;
    count=0;
    ans=std::pow(10,18);
    ans=0;
    flag=false;
        cin >> N;
        //count=0;
    for (i=1;i<100;i++){
        for (j=1;j<100;j++){
            for (k=1;k<100;k++){
                if (i*i+j*j+k*k+i*j+j*k+k*i<10050 && i+j+k<123  ){
                    S[i*i+j*j+k*k+i*j+j*k+k*i]+=1;
                    
                    
                }
                
            }
        }
    }
    //cout << count<<endl;
    for (j=1;j<=N;j++){
        count=0;
 
        cout << S[j]<<endl;
    }
    
    
    
    //cout << ans<<endl;

    return 0;
    
}


Measured memory_bytes: 3696
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  input! {
    n: usize,
    m: i64,
    aa: [i64; n],
  }
  let mut sum = vec![0i64; n + 1];
  for (i, &a) in aa.iter().enumerate() {
    sum[i+1] = (sum[i] + a) % m;
  }
  use std::collections::BTreeMap;
  let mut map = BTreeMap::new();
  for s in &sum {
    if let Some(current) = map.get_mut(&s) {
      *current += 1;
      continue;
    }
    map.insert(s, 1i64);
  }
  let mut ans = 0;
  for &v in map.values() {
    ans += v * (v - 1) / 2;
  }

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


Measured memory_bytes: 8444
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static System.Math;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static int[] x, y, h;

        
        public static void Input()
        {
            var cin = new Solve();
            N = int.Parse(Console.ReadLine());
            x = new int[N];
            y = new int[N];
            h = new int[N];
            for(var i = 0; i < N; i++)
            {
                var input = cin.SplitReader();
                x[i] = input[0];
                y[i] = input[1];
                h[i] = input[2];
            }
            
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            List<Tuple<int, int, int>> c = new List<Tuple<int, int, int>>();
            for(var i = 0; i < N; i++)
            {
                if (h[i] == 0) { continue; }
                for(var cx = 0; cx <= 100; cx++)
                {
                    for(var cy = 0; cy <= 100; cy++)
                    {
                        c.Add(new Tuple<int, int, int>(cx, cy, Abs(x[i] - cx) + Abs(y[i] - cy) + h[i]));
                    }
                }
                break;
            }

            
            for(var i = 0; i < c.Count(); i++)
            {
                bool ok = true;
                int H = c[i].Item3;
                int Cx = c[i].Item1;
                int Cy = c[i].Item2;
                for(var j = 0; j < N; j++)
                {
                    if (Max(0, H - Abs(Cx - x[j]) - Abs(Cy - y[j])) != h[j])
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                {
                    Console.WriteLine($"{Cx} {Cy} {H}");
                    return;
                }
            }

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }
}

    



Measured memory_bytes: 13504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 
int main(void) {
  ll n; cin >> n;
  ll ans = n * (n - 1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int cnt = 0;
		// 整数の入力
		int gohyaku = sc.nextInt();
		// スペース区切りの整数の入力
		int hyaku = sc.nextInt();
		int goju = sc.nextInt();
		// 文字列の入力
		int x = sc.nextInt();
		
        for(int i = 0; i <= gohyaku; i++){
            for(int j = 0; j <= hyaku; j++){
                for(int k = 0; k <= goju; k++){
                    int ans = 500*i + 100*j + 50*k;
                    if(x==ans){
                        cnt++;
                    }
                }
            }
        }
        
        System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main() {
  int n;
  cin>>n;
  int a[n+1];
  int b[n+1];
  for(int i=1;i<=n;i++)
    b[i]=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    b[a[i]]++;
  }
  long long ans=0;
  for(int i=1;i<=n;i++){
    ans+=(long long)b[i]*(b[i]-1)/2;
  }
  for(int i=1;i<=n;i++){
    cout<<ans-(long long)b[a[i]]*(b[a[i]]-1)/2+(long long)(b[a[i]]-1)*(b[a[i]]-2)/2<<endl;
  }
}

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

int main()
{
    double m;
    double min = 1000001.0, max = 0.0;

    while (cin >> m){
        if (max < m){
            max = m;
        }
        if (min > m){
            min = m;
        }
    }
    cout << max - min << endl;

    return 0;
}

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


int main() {

    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    for (int i = 1; i < n; ++i) {
        cnt += min(a[i] - a[i-1], t);
    }
    cout << cnt + t << endl;
    return 0;
}

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

int main(){
int n;
cin >> n;
vector<int> vec(n);

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

sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());

cout << vec.size() << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;     
   cin >> i;
   h = i / 3600;
   m= i / 60 % 60 ;
   s= i % 60 ;
   cout << h << ":" << m << ":" << s <<endl;
   
   return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int INF=1e18;
const int MOD=1e9+7;
int keta(int x){
    int ret=0;
    while(x>0){
        ret++;
        x/=10;
    }
    return ret;
}

signed main(){
    int n;cin>>n;
    int ans=1;
    int a[n];
    REP(i,n){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    REP(i,n){
        if(keta(ans)+keta(a[i])>=21){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
        if(ans>INF||ans<=0){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4400
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b != c) {
		cout << "Yes" << endl;
	} else if (b == c && c != a) {
		cout << "Yes" << endl;
	} else if (c == a && a != b) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;

const int maxn = 1e5 + 100;
int a[maxn], b[maxn], c[maxn];
int cnt1[maxn],cnt2[maxn];
int main() {
	string a, b;
	cin >> a >> b;
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	//system("pause");

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(arr) arr.begin(), arr.end() 
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
int ans=0, n, k;

int main(){
	IOS
	cin >> n >> k;
	while(n--){
		int a;
		cin >> a;
		if(a>=k){
			ans++;
		}
	}	
	cout << ans << '\n';
}


Measured memory_bytes: 3648
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
int main() {
	//0 is always 0
	vector<int> ans;
	vector<int> geko[3];
	int n;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		if (a == 2) {
			ans.push_back(i + 1);
		}
		else if (a < 0) {
			geko[-a].push_back(i+1);
		}
	}
	sort(geko[1].begin(), geko[1].end());
	sort(geko[2].begin(), geko[2].end());
	for (int i = 0;i+1 < geko[2].size();i += 2) {
		ans.push_back(geko[2][i]);
		ans.push_back(geko[2][i + 1]);
	}
	if (geko[2].size() % 2 == 1) {
		if (geko[1].size() != 0) {
			ans.push_back(geko[2][geko[2].size() - 1]);
			ans.push_back(geko[1][0]);
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3160
n=int(input())
a=list(map(int,input().split()))
a=[0]+a+[0]
s=0
for i in range(n+1):
    s+=abs(a[i]-a[i+1])
ans=0
for i in range(1,n+1):
    print(s-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))



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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main() {
    int x;
    cin >> x;
    int now = 0;
    int t = 0;

    while(1) {
        t++;
        now += t;
        if(now == x) {
            cout << t << endl;
            return 0;
        }
        else if(now > x) {
            break;
        }
    }

    cout << t << endl;

    return 0;
}
 

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

using namespace std;
const ll N = 2020202;
int a[2020];

int main()
{
    ll n;
    ll sum = 0;
    ll x;
    cin >> n;

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

    ll half = sum/2;

    bitset<N> dp;
    dp.set(0);

    for(int i=0;i<n;i++)
    {
        dp|=dp<<a[i];
    }
    for(size_t i =0;i<=(size_t)half;i++)
    {
        if(dp.test(i))
            x = i;
    }
    cout << sum - x;

}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cmath>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int a,b,x,v,y;
double l,r,ans;
int main(){
	a=rd(),b=rd(),x=rd();
	if(x*2>=a*a*b){
		v=2*(a*a*b-x),y=a*a*a;
		printf("%.7lf",180.0*atan(v/(double)y)/acos(-1));
	}
	else{
		v=2*x,y=a*b*b;
		printf("%.7lf",180.0*atan(y/(double)v)/acos(-1));
	}
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 2304
import heapq
n, m = map(int, input().split())
a = [i*-1 for i in list(map(int, input().split()))]
heapq.heapify(a)
for i in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, ((-1*x)//2)*-1)
print(sum(a)*-1)

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

int main() {
	// your code goes here
	
    	int n;
    	cin>>n;
    	long long arr[n][3]  ,dp[n][3];
    	for(int i=0 ; i<n ; i++){
    	    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    	    dp[i][0]=0 ; dp[i][1]=0; dp[i][2]=0;
    	}
    	dp[0][0]=arr[0][0]; dp[0][1]= arr[0][1] ; dp[0][2]= arr[0][2];
    	for(int i=1 ; i<n ; i++){
    	    dp[i][0] = arr[i][0] + max( dp[i-1][1] , dp[i-1][2]);
    	    dp[i][1] = arr[i][1] + max( dp[i-1][0] , dp[i-1][2]);
    	    dp[i][2] = arr[i][2] + max( dp[i-1][1] , dp[i-1][0]);
    	}
    	long long ans= max( max(dp[n-1][0] , dp[n-1][1]) , dp[n-1][2]);
    	cout<<ans<<endl;
    	    
	
	return 0;
}


Measured memory_bytes: 8292
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long int ll;
using namespace std;

int main(){
	int n; cin >>n;
	vector<int> x(n);
	for(int i=0;i<n;i++){
		cin >>x[i];
	}
	int m; cin >>m;
	for(int i=0;i<m;i++){
		int a; cin >>a;
		if(a==n&&x[a-1]!=2019){
			x[a-1]++;
		}
		else if(a<n&&x[a-1]+1!=x[a]){
			x[a-1]++;
		}
	}
	for(int i=0;i<n;i++){
		cout << x[i] << endl;
	}
}


Measured memory_bytes: 3096
lens=[1 for _ in range(51)]
nump=[1 for _ in range(51)]
for i in range(50):
    lens[i+1]=2*lens[i]+3
    nump[i+1]=2*nump[i]+1
def level(n):
    return max(lvl for lvl,ln in enumerate(lens) if ln<=n)

def calc():
    table={}
    def _calc(l,x):
        if x==0:
            return 0
        if (l,x) in table:
            return table[(l,x)]
        if x==lens[l]:
            res=nump[l]
        elif x<=lens[l-1]:
            res=_calc(l-1,x-1)
        elif x==lens[l-1]+1:
            res=nump[l-1]
        elif x==lens[l-1]+2:
            res=nump[l-1]+1
        else:
            res=nump[l-1]+1+_calc(l-1,x-lens[l-1]-2)
        table[(l,x)]=res
        return res
    return _calc
whole=calc()
print(whole(*map(int,input().split())))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

int getMin(int x, int y) { return (x<y)? x: y; } 
int arr1[200010],arr2[200010];

signed main() {
 
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	priority_queue<pair<int,int>> arr;
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		cin>>arr1[i];
		
	}
	for(int i=0;i<n;i++)
	{
		cin>>arr2[i];
		arr.push(mp(arr2[i],i));	
	}
	//cout<<arr.size()<<endl;
	int ans=0;
	while(arr.size()!=0)
	{

		pair<int,int> tp=arr.top();
		
		arr.pop();
		
		
		if(arr1[tp.ss]==arr2[tp.ss])
		{
			continue;
		}
		int m=tp.ss;
		int l=tp.ss-1;
		if(l<0)
			l+=n;
		int r=tp.ss+1;
		if(r==n)
			r=0;
		int res=arr2[l]+arr2[r];
		if((arr2[m]-res)<arr1[m])
		{
			cout<<-1<<endl;
			return 0;
		}
		int ptr=(arr2[m]-arr1[m])/res;
		arr2[m]-=(res*ptr);

		ans+=ptr;
		if(arr1[m]!=arr2[m])
		{
			arr.push({arr2[m],m});
		}
	}
	cout<<ans;
	return 0;

 }


Measured memory_bytes: 9072
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn divisor(n: usize) -> Vec<usize> {
    let mut res = Vec::new();
    for i in (1..).take_while(|x| x * x <= n) {
        if n % i == 0 {
            res.push(i);
            if i != n / i {
                res.push(n / i);
            }
        }
    }
    res.sort();
    res
}

fn solve() {
    input! {
        a: u64,
        b: u64
    }

    let gcd_num = gcd(a, b) as usize;

    let mut divides = divisor(gcd_num);

    let mut disjoints = divides.clone();

    for i in divides.into_iter().skip(1) {
        disjoints = disjoints
            .into_iter()
            .filter(|&x| x == i || x % i != 0)
            .collect();
    }

    println!("{:?}", disjoints.len());
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet
// 最大公約数
fn gcd(a: u64, b: u64) -> u64 {
    let mut aa: u64 = if a > b { a } else { b };
    let mut bb: u64 = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

// 最小公倍数
fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}


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

int main() {
    int n;
    cin >> n;
    if (n%2 == 0) cout << n/2 << endl;
    else cout << n/2 + 1 << endl;
    return 0;
}

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


// int dfs(int cur) {
//     ll ans = 0;
//     visited[cur] = true;
//     for (int i = 0; i < n; i++) {
//         if (!visited[i]) {
//             break;
//         }
//         if (i == n - 1) {
//             return 1;
//         }
//     }
//     for (int i = 0; i < g[cur].size(); i++) {
//         int next = g[cur][i];
//         cout << next << endl;
//         if (!visited[next]) {
//             ans += dfs(next);
//         }
//     }
//
//     return ans;
// }

int main() {
    int n, m;
    cin >> n >> m;
    bool g[n][n];
    int v[n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            g[i][j] = false;
        }
        v[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a][b] = g[b][a] = true;
    }

    ll ans = 0;
    do {
        if(v[0] == 0) {
            for (int i = 1; i < n; i++) {
                if (!g[v[i]][v[i - 1]]) {
                    break;
                }
                if (i == n - 1) {
                    ans++;
                }
            }
        } else {
            break;
        }
    } while (next_permutation(v, v + n));

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
char a[1001];
int main()
{
	int i,lena;
	char n;
	cin>>a;
	lena=strlen(a);
	for(i=0;i<lena;i++)
	{
		if(a[i]<='C')
		a[i]+=23;
		else a[i]-=3;
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys
import itertools
import math

def dist(sx, sy, dx, dy):
    return math.sqrt((sx - dx)**2 + (sy - dy)**2)


def solve(N, xs, ys):
    ps = [p for p in itertools.permutations(range(N))]
    total = 0
    for p in ps:
        for i in range(1, N):
            total += dist(xs[p[i]], ys[p[i]], xs[p[i-1]], ys[p[i-1]])
    print(total * 1.0 / len(ps))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    x = [int()] * (N)
    y = [int()] * (N)
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

data class Query(val v: Int, val d: Int, val c: Int)

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val mutableGraph = Array(n, { mutableListOf<Int>() })
  repeat(m) {
    val (rawV1, rawV2) = fastReadInts(2)
    val v1 = rawV1 - 1
    val v2 = rawV2 - 1
    mutableGraph[v1].add(v2)
    mutableGraph[v2].add(v1)
  }
  val graph = mutableGraph.map { it.toIntArray() }

  val q = readLine()!!.toInt()
  val queries = Array(q, {
    val (vRaw, d, c) = fastReadInts(3)
    val v = vRaw - 1
    Query(v, d, c)
  })
  queries.reverse()

  val dp = Array(n, { IntArray(11) })

  fun dfs(v: Int, d: Int, c: Int) {
    if (dp[v][d] > 0) return
    for (k in d downTo 0) {
      if (dp[v][k] > 0) break
      dp[v][k] = c
    }

    if (d == 0) return

    for (u in graph[v]) {
      dfs(u, d - 1, c)
    }
  }

  for (query in queries) {
    dfs(query.v, query.d, query.c)
  }

  for (v in 0 until n) {
    println(dp[v][0])
  }
}


Measured memory_bytes: 80552
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  int h, m, h_, m_, k;

  cin >> h >> m >> h_ >> m_ >> k;

  int start = h * 60 + m;
  int end = h_ * 60 + m_;

  int ans = end - k - start;

  cout << ans;

  return 0;
}

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

int main(){
  ll n, k;
  string s;
  cin >> n >> k >> s;
  
  if(n == 1){
  	cout << '0' << endl;
    return 0;
  }
  
  if(n == 2){
    cout << '1' << endl;
    return 0;
  }
  
  ll ans = 0;
  
  for(ll i=1; i<n; i++){
  	if(s[i-1] == s[i]) ans++;
  }
  
  cerr << ans << endl;
  
  bool all_seen1 = false;
  bool all_seen2 = false;
  
  ll trial, inside, outside;
  ll next_start = 0;
  ll cnt = 0;
  
  for(trial = 1; trial <= k; trial++){
  	for(ll i = next_start+1; i < n; i++){
      if(s[i] != s[next_start]){
        inside = i;
        break;
      }
      if(i == n-1){ 
        all_seen1 = true;
      }
    }
    if(all_seen1) break;
    for(ll i = inside; i < n; i++){
      if(s[i+1] == s[next_start]){
        outside = i;
        break;
      }
      if(i == n-1){ 
        all_seen2 = true;
      }
    }
    if(all_seen2) break;
    cnt++;
    next_start = outside + 1;
    if(next_start == n-1) break;
  }

  ans += 2*cnt;
  if(all_seen2) ans++;
  
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	int n; cin >> n;
	vector<Int> a(n+1),b(n);
	for (int i = 0; i < n+1; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n ; i++) {
		cin >> b[i];
	}
	Int kill = 0,zero=0;

	for (int i = 0; i < n-1; i++) {
		if (b[i] - a[i] >= 0) kill += a[i];//1体目
		else kill += b[i];

		if (b[i] - min(a[i], b[i]) - a[i + 1] >= 0) {//2体目
			kill += a[i + 1];
			a[i + 1] = 0;
		}
		else {
			kill += b[i] - min(a[i], b[i]);
			a[i + 1] -= b[i] - min(a[i], b[i]);
		}

		//b[i + 1] += max(zero, b[i] - a[i]);
	}
	if (b[n - 1] - (a[n - 1] + a[n]) >= 0) kill += (a[n - 1] + a[n]);
	else kill += b[n - 1];

	cout << (Int)kill;

	cout << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans += n / (a+b) * a;
    n %= (a+b);
    ans += min(n, a);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int R0, W0, C, R;
	cin >> R0 >> W0 >> C >> R;
	while (R0 != 0) {
		int ans = 0;
		while (C * W0 > R0) {
			ans++;
			R0 += R;
		}
		cout << ans << endl;
		cin >> R0 >> W0 >> C >> R;
	}
	return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

string s;
string t;

int main() {
    cin >> s;

    for (auto i:s) {
        if (i == '1' || i == '0') t.push_back(i);
        else if(!t.empty()) t.pop_back();
    }

    cout << t << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
L = [0] + list(accumulate(A))
dp = [[0]*(n+1) for i in range(n+1)]
for d in range(1, n+1):
  for i in range(n+1-d):
    dp[i][i+d] = max(A[i] + L[i+d] - L[i+1] - dp[i+1][i+d], A[i+d-1] + L[i+d-1] - L[i] - dp[i][i+d-1])
ans = 2*dp[0][n] - L[n]
print(ans)

Measured memory_bytes: 112720
#include<iostream>
#include<stdlib.h>
using namespace std;

int main () {
  int a,b;
  while(cin>>a>>b,a|b){
    int x,y,m=0;
    int d[a*b]={};int k;cin>>k;
    for(int i=0;i<k;++i){
      cin>>x>>y;x--;y--;
      d[x+y*a]=1;
    }
    int dp[2][a*b];
    for(int i=0;i<2;++i)for(int j=0;j<a*b;++j)dp[i][j]=0;
    dp[1-m][0]=1;
    while(true){
      for(y=0;y<b;++y){
	for(x=0;x<a;++x){
	  if(d[x+y*a])continue;
	  if(dp[m][x+y*a]==0){
	    if(x>=1){dp[m][x+y*a]+=dp[1-m][(x-1)+y*a];}
	    if(y>=1){dp[m][x+y*a]+=dp[1-m][x+(y-1)*a];}
	  }
	}
      }
      bool t = false;
      for(int i=0;i<a*b;++i){if(dp[1-m][i]!=dp[m][i])t=true;dp[1-m][i]=dp[m][i];}
      if(!t){cout<<dp[m][a*b-1]<<endl;break;}
      m=1-m;
    }
  }
}

Measured memory_bytes: 3084
// Program.cpp

#include <bits/stdc++.h>
using namespace std;

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

#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n)           for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

void solve(int TEST_CASE){
	int n, W;
	cin >> n >> W;
	int v[n];
	int w[n];
	int val = 0;
	fr(i,n){
		cin >> w[i] >> v[i];
		val+=v[i];
	}
	vector<int> dp(val+1);
	//dp[i] -> current minimum weight at ith value
	dp[0] = 0;
	fr(i,val){
		dp[i+1] = INF+100;
	}
	fr(i,n){
		vector<int> dp2(val+1);
		fr(i,val){
			dp2[i+1] = dp[i+1];

		}
		dp2[v[i]] = min(w[i],dp[v[i]]);
		frA(j,0,val-v[i]){
			dp2[j+v[i]] = min(dp[v[i]+j],dp[j]+w[i]);
		}
		fr(i,val){
			dp[i+1] = dp2[i+1];
		}
	}
	int max = 0,ans=val+1;
	fr(i,val+1){
		if(dp[i]>W)
			dp[i] = 0;
		if(dp[i]!=0){
			ans = i;
		}
	}
	cout << ans << endl;
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

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

int ctoi(char c)
{
	if ('0' <= c && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

int main()
{
	int sum[1001] = {};
	int count = 0;

	while (1)
	{
		char in[1001];
		int i = 0;
		cin.getline(in, sizeof(in));

		if (in[0] == '0')
		{
			break;
		}

		for (i = 0; in[i] != '\0' ; i++)
		{
			sum[count] = sum[count] + ctoi(in[i]);
			/*if (in[i] == '1')
			{
				sum[count] = sum[count] + 1;
			}
			else if (in[i] == '2')
			{
				sum[count] = sum[count] + 2;
			}
			else if (in[i] == '3')
			{
				sum[count] = sum[count] + 3;
			}
			else if (in[i] == '4')
			{
				sum[count] = sum[count] + 4;
			}
			else if (in[i] == '5')
			{
				sum[count] = sum[count] + 5;
			}
			else if (in[i] == '6')
			{
				sum[count] = sum[count] + 6;
			}
			else if (in[i] == '7')
			{
				sum[count] = sum[count] + 7;
			}
			else if (in[i] == '8')
			{
				sum[count] = sum[count] + 8;
			}
			else if (in[i] == '9')
			{
				sum[count] = sum[count] + 9;
			}*/

		}
		count++;
	}
	for (int s = 0; s < count; s++){
		cout << sum[s] << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
i = list(map(int, input().split()))
#print(i)

h1=i[0]
a1=i[1]
h2=i[2]
a2=i[3]

while True:
  h2 = h2 - a1
  if h2 <= 0:
    print("Yes")
    exit()
  h1 = h1 - a2
  if h1 <= 0:
    print("No")
    exit()

Measured memory_bytes: 9184